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

Use get_bits_value() inside cpu_rdmsr_range()

This commit is contained in:
Xorg 2016-05-18 16:32:40 +02:00
parent c9926ab6f7
commit 9ce0158b88

View file

@ -420,35 +420,30 @@ static int perfmsr_measure(struct msr_driver_t* handle, int msr)
#define MSR_PSTATE_S 0xC0010063
#define MSR_PSTATE_0 0xC0010064
static int get_bits_value(uint64_t val, int highbit, int lowbit)
static uint64_t get_bits_value(uint64_t val, int highbit, int lowbit)
{
uint64_t data = val;
int bits = highbit - lowbit + 1;
if(bits < 64){
data >>= lowbit;
data &= (1ULL<<bits) - 1;
const uint8_t bits = highbit - lowbit + 1;
if(bits < 64) {
/* Show only part of register */
data >>= lowbit;
data &= (1ULL << bits) - 1;
}
return (int) data;
return data;
}
static 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);
if(bits < 64)
{
/* Show only part of register */
*result >>= lowbit;
*result &= (1ULL << bits) - 1;
}
*result = get_bits_value(*result, highbit, lowbit);
return 0;
}