Update core_voltage.cpp

This commit is contained in:
daleclack 2024-09-12 14:44:07 +08:00
parent edd24e476f
commit b8935b09b5
1 changed files with 45 additions and 0 deletions

45
cpp/core_voltage.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
int main(int argc, char *argv[])
{
double voltage = 0.0, current_voltage = 0.0;
char buffer[128];
while (1)
{
// Open Pipe to get output
FILE *pipe = popen("echo \"scale=2; $(rdmsr 0x198 -u --bitfield 47:32)/8192\" | bc", "r");
// Check if Pipe is open
if (!pipe)
{
std::cout << "Error executing command" << std::endl;
// return -1;
}
else
{
// Read from Pipe
while (!feof(pipe))
{
fgets(buffer, sizeof buffer, pipe);
}
current_voltage = atof(buffer);
if (current_voltage > voltage)
{
std::cout << "Current Max Core Voltage: " << current_voltage << "V" << std::endl;
voltage = current_voltage;
}
}
pclose(pipe);
// std::cout << buffer << std::endl;
// Wait for one second
sleep(1);
}
return 0;
}