mirror of
https://github.com/anrieff/libcpuid
synced 2024-12-16 16:35:45 +00:00
Set cpu_rdmsr_range() and get_bits_value() as public functions
This commit is contained in:
parent
9ce0158b88
commit
1d5ac6f23f
4 changed files with 48 additions and 14 deletions
|
@ -30,3 +30,5 @@ cpu_clock_by_ic @26
|
|||
cpuid_get_total_cpus @27
|
||||
cpu_msr_driver_open_core @28
|
||||
cpuid_get_vendor @29
|
||||
cpu_rdmsr_range @30
|
||||
get_bits_value @31
|
||||
|
|
|
@ -882,6 +882,36 @@ typedef enum {
|
|||
multiplied by 100. */
|
||||
} cpu_msrinfo_request_t;
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @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
|
||||
* @param result - a pointer to a 64-bit integer, where the MSR value is stored
|
||||
*
|
||||
* @returns zero if successful, and some negative number on error.
|
||||
* The error message can be obtained by calling \ref cpuid_error.
|
||||
* @see cpu_error_t
|
||||
*/
|
||||
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
|
||||
|
|
|
@ -27,3 +27,5 @@ cpu_clock_by_ic
|
|||
cpuid_get_total_cpus
|
||||
cpu_msr_driver_open_core
|
||||
cpuid_get_vendor
|
||||
cpu_rdmsr_range
|
||||
get_bits_value
|
||||
|
|
|
@ -420,7 +420,20 @@ static int perfmsr_measure(struct msr_driver_t* handle, int msr)
|
|||
#define MSR_PSTATE_S 0xC0010063
|
||||
#define MSR_PSTATE_0 0xC0010064
|
||||
|
||||
static uint64_t get_bits_value(uint64_t val, int highbit, int lowbit)
|
||||
int cpu_rdmsr_range(struct msr_driver_t* handle, uint32_t msr_index, uint8_t highbit,
|
||||
uint8_t lowbit, uint64_t* result)
|
||||
{
|
||||
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;
|
||||
|
@ -434,19 +447,6 @@ static uint64_t get_bits_value(uint64_t val, int highbit, int lowbit)
|
|||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int cpu_msrinfo(struct msr_driver_t* handle, cpu_msrinfo_request_t which)
|
||||
{
|
||||
uint64_t r;
|
||||
|
|
Loading…
Reference in a new issue