From 85bac12db478bbfe4fa0a72765779bb7d1cc387c Mon Sep 17 00:00:00 2001 From: Xorg Date: Wed, 18 May 2016 20:46:47 +0200 Subject: [PATCH] Drop get_bits_value() --- libcpuid/exports.def | 1 - libcpuid/libcpuid.h | 13 ------------- libcpuid/libcpuid.sym | 1 - libcpuid/rdmsr.c | 30 ++++++++---------------------- 4 files changed, 8 insertions(+), 37 deletions(-) diff --git a/libcpuid/exports.def b/libcpuid/exports.def index 8905d58..72b78e8 100644 --- a/libcpuid/exports.def +++ b/libcpuid/exports.def @@ -31,4 +31,3 @@ cpuid_get_total_cpus @27 cpu_msr_driver_open_core @28 cpuid_get_vendor @29 cpu_rdmsr_range @30 -get_bits_value @31 diff --git a/libcpuid/libcpuid.h b/libcpuid/libcpuid.h index 163e4b8..67f822b 100644 --- a/libcpuid/libcpuid.h +++ b/libcpuid/libcpuid.h @@ -885,8 +885,6 @@ typedef enum { /** * @brief Similar to \ref cpu_rdmsr, but extract a range of bits * - * It is similar to use \ref cpu_rdmsr then \ref get_bits_value. - * * @param handle - a handle to the MSR reader driver, as created by * cpu_msr_driver_open * @param msr_index - the numeric ID of the MSR you want to read @@ -901,17 +899,6 @@ typedef enum { int cpu_rdmsr_range(struct msr_driver_t* handle, uint32_t msr_index, uint8_t highbit, uint8_t lowbit, uint64_t* result); -/** - * @brief Extract a range of bits from MSR value - * - * @param val - a 64-bit integer, where the MSR value is stored - * @param highbit - the high bit in range, must be inferior to 64 - * @param lowbit - the low bit in range, must be equal or superior to 0 - * - * @returns bits between highbit and lowbit - */ -uint64_t get_bits_value(uint64_t val, int highbit, int lowbit); - /** * @brief Reads extended CPU information from Model-Specific Registers. * @param handle - a handle to an open MSR driver, @see cpu_msr_driver_open diff --git a/libcpuid/libcpuid.sym b/libcpuid/libcpuid.sym index 30ff700..d0c61e4 100644 --- a/libcpuid/libcpuid.sym +++ b/libcpuid/libcpuid.sym @@ -28,4 +28,3 @@ cpuid_get_total_cpus cpu_msr_driver_open_core cpuid_get_vendor cpu_rdmsr_range -get_bits_value diff --git a/libcpuid/rdmsr.c b/libcpuid/rdmsr.c index e663a25..8c2f322 100644 --- a/libcpuid/rdmsr.c +++ b/libcpuid/rdmsr.c @@ -456,11 +456,6 @@ int cpu_rdmsr_range(struct msr_driver_t* handle, uint32_t msr_index, uint8_t hig return set_error(ERR_NOT_IMP); } -uint64_t get_bits_value(uint64_t val, int highbit, int lowbit) -{ - return set_error(ERR_NOT_IMP); -} - int cpu_msrinfo(struct msr_driver_t* driver, cpu_msrinfo_request_t which) { return set_error(ERR_NOT_IMP); @@ -506,28 +501,21 @@ static int perfmsr_measure(struct msr_driver_t* handle, int msr) int cpu_rdmsr_range(struct msr_driver_t* handle, uint32_t msr_index, uint8_t highbit, uint8_t lowbit, uint64_t* result) { + const uint8_t bits = highbit - lowbit + 1; + if(highbit > 63 || lowbit > highbit) return set_error(ERR_INVRANGE); if(cpu_rdmsr(handle, msr_index, result)) return set_error(ERR_HANDLE_R); - *result = get_bits_value(*result, highbit, lowbit); - return 0; -} - -uint64_t get_bits_value(uint64_t val, int highbit, int lowbit) -{ - uint64_t data = val; - const uint8_t bits = highbit - lowbit + 1; - if(bits < 64 && highbit < 64 && lowbit < highbit) { /* Show only part of register */ - data >>= lowbit; - data &= (1ULL << bits) - 1; + *result >>= lowbit; + *result &= (1ULL << bits) - 1; } - return data; + return 0; } int cpu_msrinfo(struct msr_driver_t* handle, cpu_msrinfo_request_t which) @@ -583,11 +571,9 @@ int cpu_msrinfo(struct msr_driver_t* handle, cpu_msrinfo_request_t which) { // https://github.com/ajaiantilal/i7z/blob/5023138d7c35c4667c938b853e5ea89737334e92/helper_functions.c#L59 - cpu_rdmsr_range(handle, IA32_THERM_STATUS, 63, 0, &val); - digital_readout = get_bits_value(val, 23, 16); - thermal_status = get_bits_value(val, 32, 31); - cpu_rdmsr_range(handle, IA32_TEMPERATURE_TARGET, 63, 0, &val); - PROCHOT_temp = get_bits_value(val, 23, 16); + cpu_rdmsr_range(handle, IA32_THERM_STATUS, 23, 16, &digital_readout); + cpu_rdmsr_range(handle, IA32_THERM_STATUS, 32, 31, &thermal_status); + cpu_rdmsr_range(handle, IA32_TEMPERATURE_TARGET, 23, 16, &PROCHOT_temp); // These bits are thermal status : 1 if supported, 0 else if(thermal_status)