1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-12-16 16:35:45 +00:00

Drop get_bits_value()

This commit is contained in:
Xorg 2016-05-18 20:46:47 +02:00
parent 801d4c982a
commit 85bac12db4
4 changed files with 8 additions and 37 deletions

View file

@ -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

View file

@ -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

View file

@ -28,4 +28,3 @@ cpuid_get_total_cpus
cpu_msr_driver_open_core
cpuid_get_vendor
cpu_rdmsr_range
get_bits_value

View file

@ -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)