1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-10 22:59:13 +00:00

Add function cpu_msr_driver_open_core()

This function is similar to cpu_msr_driver_open(), but with core number as parameter
For Linux, core number was always 0. To be able to get all core temp/voltage, we need to set the core number.
This commit is contained in:
Xorg 2015-09-29 09:40:33 +02:00
parent 4e3b633bee
commit 79fcdba98e
4 changed files with 31 additions and 1 deletions

View file

@ -28,3 +28,4 @@ cpu_msrinfo @24
cpu_msr_driver_close @25
cpu_clock_by_ic @26
cpuid_get_total_cpus @27
cpu_msr_driver_open_core @28

View file

@ -390,6 +390,7 @@ typedef enum {
ERR_EXTRACT = -11, /*!< "Cannot extract RDMSR driver (read only media?)" */
ERR_HANDLE = -12, /*!< "Bad handle" */
ERR_INVMSR = -13, /*!< "Invalid MSR" */
ERR_INVCNB = -14, /*!< "Invalid core number" */
} cpu_error_t;
/**
@ -804,6 +805,21 @@ void cpuid_free_cpu_list(struct cpu_list_t* list);
struct msr_driver_t;
struct msr_driver_t* cpu_msr_driver_open(void);
/**
* @brief Similar to \ref cpu_msr_driver_open, but accept one parameter
*
* This function works on Linux only
*
* @param core_num specify the core number for MSR.
* The first core number is 0.
* The last core number is \ref cpuid_get_total_cpus - 1.
*
* @returns a handle to the driver on success, and NULL on error.
* The error message can be obtained by calling \ref cpuid_error.
* @see cpu_error_t
*/
struct msr_driver_t* cpu_msr_driver_open_core(int core_num);
/**
* @brief Reads a Model-Specific Register (MSR)
*

View file

@ -25,3 +25,4 @@ cpu_msrinfo
cpu_msr_driver_close
cpu_clock_by_ic
cpuid_get_total_cpus
cpu_msr_driver_open_core

View file

@ -69,12 +69,24 @@ struct msr_driver_t { int fd; };
static int rdmsr_supported(void);
struct msr_driver_t* cpu_msr_driver_open(void)
{
return cpu_msr_driver_open_core(0);
}
struct msr_driver_t* cpu_msr_driver_open_core(int core_num)
{
char msr[32];
struct msr_driver_t* handle;
if(core_num < 0 && cpuid_get_total_cpus() <= core_num)
{
set_error(ERR_INVCNB);
return NULL;
}
if (!rdmsr_supported()) {
set_error(ERR_NO_RDMSR);
return NULL;
}
int fd = open("/dev/cpu/0/msr", O_RDONLY);
sprintf(msr, "/dev/cpu/%i/msr", core_num);
int fd = open(msr, O_RDONLY);
if (fd < 0) {
if (errno == EIO) {
set_error(ERR_NO_RDMSR);