Skip to content

Commit

Permalink
Merge pull request #43 from X0rg/master
Browse files Browse the repository at this point in the history
Changes for MSR
  • Loading branch information
anrieff committed May 19, 2016
2 parents 14d6a9d + b067c68 commit 7c7a0fe
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 83 deletions.
1 change: 1 addition & 0 deletions libcpuid/cpuid_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ const char* cpuid_error(void)
{ ERR_INVMSR , "Invalid MSR"},
{ ERR_INVCNB , "Invalid core number"},
{ ERR_HANDLE_R , "Error on handle read"},
{ ERR_INVRANGE , "Invalid given range"},
};
unsigned i;
for (i = 0; i < COUNT_OF(matchtable); i++)
Expand Down
1 change: 1 addition & 0 deletions libcpuid/exports.def
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ cpu_clock_by_ic @26
cpuid_get_total_cpus @27
cpu_msr_driver_open_core @28
cpuid_get_vendor @29
cpu_rdmsr_range @30
22 changes: 20 additions & 2 deletions libcpuid/libcpuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ typedef enum {
ERR_INVMSR = -13, /*!< "Invalid MSR" */
ERR_INVCNB = -14, /*!< "Invalid core number" */
ERR_HANDLE_R = -15, /*!< "Error on handle read" */
ERR_INVRANGE = -16, /*!< "Invalid given range" */
} cpu_error_t;

/**
Expand Down Expand Up @@ -831,7 +832,7 @@ struct msr_driver_t* cpu_msr_driver_open(void);
/**
* @brief Similar to \ref cpu_msr_driver_open, but accept one parameter
*
* This function works on Linux only
* This function works on certain operating system (GNU/Linux, FreeBSD)
*
* @param core_num specify the core number for MSR.
* The first core number is 0.
Expand All @@ -841,7 +842,7 @@ struct msr_driver_t* cpu_msr_driver_open(void);
* The error message can be obtained by calling \ref cpuid_error.
* @see cpu_error_t
*/
struct msr_driver_t* cpu_msr_driver_open_core(int core_num);
struct msr_driver_t* cpu_msr_driver_open_core(unsigned core_num);

/**
* @brief Reads a Model-Specific Register (MSR)
Expand Down Expand Up @@ -891,6 +892,23 @@ typedef enum {
multiplied by 100. */
} cpu_msrinfo_request_t;

/**
* @brief Similar to \ref cpu_rdmsr, but extract a range of bits
*
* @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 Reads extended CPU information from Model-Specific Registers.
* @param handle - a handle to an open MSR driver, @see cpu_msr_driver_open
Expand Down
1 change: 1 addition & 0 deletions libcpuid/libcpuid.sym
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ cpu_clock_by_ic
cpuid_get_total_cpus
cpu_msr_driver_open_core
cpuid_get_vendor
cpu_rdmsr_range
Loading

0 comments on commit 7c7a0fe

Please sign in to comment.