diff --git a/libcpuid/libcpuid.h b/libcpuid/libcpuid.h index 9104475..2599cde 100644 --- a/libcpuid/libcpuid.h +++ b/libcpuid/libcpuid.h @@ -391,6 +391,7 @@ typedef enum { ERR_HANDLE = -12, /*!< "Bad handle" */ ERR_INVMSR = -13, /*!< "Invalid MSR" */ ERR_INVCNB = -14, /*!< "Invalid core number" */ + ERR_HANDLE_R = -15, /*!< "Error on handle read" */ } cpu_error_t; /** diff --git a/libcpuid/rdmsr.c b/libcpuid/rdmsr.c index 65657e0..40d928c 100644 --- a/libcpuid/rdmsr.c +++ b/libcpuid/rdmsr.c @@ -396,6 +396,59 @@ static int perfmsr_measure(struct msr_driver_t* handle, int msr) } #ifndef MSRINFO_DEFINED + +#define IA32_THERM_STATUS 0x19C +#define IA32_TEMPERATURE_TARGET 0x1a2 +#define IA32_PACKAGE_THERM_STATUS 0x1b1 +#define MSR_PERF_STATUS 0x198 +#define MSR_TURBO_RATIO_LIMIT 429 +#define PLATFORM_INFO_MSR 206 +#define PLATFORM_INFO_MSR_low 8 +#define PLATFORM_INFO_MSR_high 15 + +int get_bits_value(unsigned long val, int highbit, int lowbit) +{ + unsigned long data = val; + int bits = highbit - lowbit + 1; + if(bits < 64){ + data >>= lowbit; + data &= (1ULL<fd, &data, sizeof data, reg) != sizeof data) + { + *error_indx = 1; + return set_error(ERR_HANDLE_R); + } + + bits = highbit - lowbit + 1; + if (bits < 64) + { + /* Show only part of register */ + data >>= lowbit; + data &= (1ULL << bits) - 1; + } + + /* Make sure we get sign correct */ + if (data & (1ULL << (bits - 1))) + { + data &= ~(1ULL << (bits - 1)); + data = -data; + } + + *error_indx = 0; + return (data); +} + int cpu_msrinfo(struct msr_driver_t* handle, cpu_msrinfo_request_t which) { uint64_t r;