libmsr  0.3.0
A friendlier interface to accessing MSRs on Intel platforms
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Macros | Functions
cpuid.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
Include dependency graph for cpuid.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MASK_RANGE(m, n)   ((((uint64_t)1<<((m)-(n)+1))-1)<<(n))
 Create a mask from bit m to n (63 >= m >= n >= 0).
 
#define MASK_VAL(x, m, n)   (((uint64_t)(x)&MASK_RANGE((m),(n)))>>(n))
 Return the value of x after applying bitmask (m,n) (63 >= m >= n >= 0).
 

Functions

void cpuid (uint64_t leaf, uint64_t *rax, uint64_t *rbx, uint64_t *rcx, uint64_t *rdx)
 Get processor identification and feature information to the 32-bit EAX, EBX, ECX, and EDX registers.
 
void cpuid_detect_core_conf (uint64_t *coresPerSocket, uint64_t *hyperThreads, uint64_t *sockets, int *HTenabled)
 Determine platform configuration (i.e. number of sockets, number of cores/socket, number of logical processors, etc.).
 
void cpuid_get_model (uint64_t *model)
 Retrieve the CPU model number.
 
void cpuidInput_rax_rcx (uint64_t leafa, uint64_t leafc, uint64_t *rax, uint64_t *rbx, uint64_t *rcx, uint64_t *rdx)
 Get max number of physical processor cores on the platform.
 
bool cpuid_mperf_and_aperf_avail (void)
 Check availability of p-state hardware coordination feedback, indicating presence of IA32_APERF and IA32_MPERF.
 
bool cpuid_timestamp_counter_avail (void)
 Check availability of the time-stamp counter.
 
int cpuid_num_pmc (void)
 Determine which performance monitoring counters (PMCs) are available.
 
int cpuid_num_perfevtsel (void)
 Determine which performance event select MSRs (PerfEvtSelX) are available.
 
bool cpuid_perf_global_ctrl_EN_PMC (void)
 Determine if performance monitoring capabilities are available.
 
bool cpuid_perf_global_ctrl_EN_FIXED_CTRnum (void)
 Check availability of the three fixed-function performance counters: Instr_Retired.Any, CPU_CLK_Unhalted.Core, and CPU_CLK_Unhalted.Ref.
 
bool cpuid_misc_enable_TurboModeDisable (void)
 Check if Turbo mode is disabled.
 
bool cpuid_misc_enable_xTPRMessageDisable (void)
 Check if xTPR messages are disabled.
 
bool cpuid_misc_enable_XDbitDisable (void)
 Check if XD bit is disabled.
 
bool cpuid_enable_ExtendedClockMod (void)
 Check if extended on-demand clock modulation is enabled.
 
bool cpuid_therm_status_enable_ThermalThresholds (void)
 Check if Thermal Threshold #1 status and log and Thermal Threshold #2 status and log are enabled in IA32_THERM_STATUS.
 
bool cpuid_therm_status_enable_PowerLimitNotify (void)
 Check if power limitation status and log are enabled in IA32_THERM_STATUS.
 
bool cpuid_therm_status_enable_DigitalReadout (void)
 Check if digital readout is enabled in IA32_THERM_STATUS.
 
bool cpuid_therm_interrupt_enable_PowerLimitNotify (void)
 Check if power limit notification enable is enabled in IA32_THERM_INTERRUPT.
 
bool cpuid_pkg_therm_enable_status_and_interrupt (void)
 Check if IA32_PACKAGE_THERM_STATUS and IA32_PACKAGE_THERM_INTERRUPT are enabled on the platform.
 
uint64_t cpuid_MaxLeaf (void)
 Get highest EAX value (i.e., leaf) supported by the platform.
 
void cpuid_printVendorID (void)
 Print platform vendor ID.
 
int cpuid_pkg_MaxPhysicalProcessorCores (void)
 Get max number of addressable IDs attributable to processor cores in the physical package.
 
int cpuid_pkg_MaxLogicalProcessors (void)
 Get max number of addressable IDs for logical processors in a physical package.
 
int cpuid_num_fixed_counters (void)
 Get number of fixed-function performance counters on the platform.
 
int cpuid_width_fixed_counters (void)
 Get bit width of fixed-function performance counters on the platform.
 

Macro Definition Documentation

#define MASK_RANGE (   m,
 
)    ((((uint64_t)1<<((m)-(n)+1))-1)<<(n))

Create a mask from bit m to n (63 >= m >= n >= 0).

Example: MASK_RANGE(4,2) –> (((1<<((4)-(2)+1))-1)<<(2)) (((1<< 3)-1)<<(2)) (( 4-1)<<(2)) ( 3)<<(2)) ( 24) = b11000

#define MASK_VAL (   x,
  m,
 
)    (((uint64_t)(x)&MASK_RANGE((m),(n)))>>(n))

Return the value of x after applying bitmask (m,n) (63 >= m >= n >= 0).

Example: MASK_RANGE(17,4,2) –> 17&24 = b10001 & b11000 = b10000

Function Documentation

void cpuid ( uint64_t  leaf,
uint64_t *  rax,
uint64_t *  rbx,
uint64_t *  rcx,
uint64_t *  rdx 
)

Get processor identification and feature information to the 32-bit EAX, EBX, ECX, and EDX registers.

Parameters
[in]leafLevel of basic processor information to be returned.
[out]raxEAX register contents.
[out]rbxEBX register contents.
[out]rcxECX register contents.
[out]rdxEDX register contents.
void cpuid_detect_core_conf ( uint64_t *  coresPerSocket,
uint64_t *  hyperThreads,
uint64_t *  sockets,
int *  HTenabled 
)

Determine platform configuration (i.e. number of sockets, number of cores/socket, number of logical processors, etc.).

Parameters
[out]coresPerSocketNumber of cores per socket (including hyperthreads, if enabled).
[out]hyperThreadsNumber of threads including hyperthreads.
[out]socketsNumber of sockets.
[out]HTenabledHyperthreading enabled/disabled.
bool cpuid_enable_ExtendedClockMod ( void  )

Check if extended on-demand clock modulation is enabled.

Returns
True if extended on-demand clock modulation is enabled, else false.
void cpuid_get_model ( uint64_t *  model)

Retrieve the CPU model number.

Parameters
[out]modelCPU model number.
uint64_t cpuid_MaxLeaf ( void  )

Get highest EAX value (i.e., leaf) supported by the platform.

Returns
Highest EAX leaf supported by the platform.
bool cpuid_misc_enable_TurboModeDisable ( void  )

Check if Turbo mode is disabled.

Returns
True if Turbo mode is disabled, else false.
bool cpuid_misc_enable_XDbitDisable ( void  )

Check if XD bit is disabled.

Returns
True if XD bit is disabled, else false.
bool cpuid_misc_enable_xTPRMessageDisable ( void  )

Check if xTPR messages are disabled.

Returns
True if xTPR messages are disabled, else false.
bool cpuid_mperf_and_aperf_avail ( void  )

Check availability of p-state hardware coordination feedback, indicating presence of IA32_APERF and IA32_MPERF.

Returns
True if IA32_APERF and IA32_MPERF are available, else false.
int cpuid_num_fixed_counters ( void  )

Get number of fixed-function performance counters on the platform.

Returns
Number of available fixed-function performance counters.
int cpuid_num_perfevtsel ( void  )

Determine which performance event select MSRs (PerfEvtSelX) are available.

If greater than 3, then up to PerfEvtSel3 is usable. If greater than 2, then up to PerfEvtSel2 is usable. If greater than 1, then up to PerfEvtSel1 is usable. If greater than 0, then only PerfEvtSel0 is usable. If equal to 0, then no PerfEvtSel MSRs are usable.

Returns
Number of PerfEvtSel MSRs are available.
int cpuid_num_pmc ( void  )

Determine which performance monitoring counters (PMCs) are available.

If greater than 3, then up to PMC3 is usable. If greater than 2, then up to PMC2 is usable. If greater than 1, then up to PMC1 is usable. If greater than 0, then only PMC0 is usable. If equal to 0, then no PMCs are usable.

Returns
Number of PMCs are available.
bool cpuid_perf_global_ctrl_EN_FIXED_CTRnum ( void  )

Check availability of the three fixed-function performance counters: Instr_Retired.Any, CPU_CLK_Unhalted.Core, and CPU_CLK_Unhalted.Ref.

Returns
True if IA32_FIXED_CTR0, IA32_FIXED_CTR1, and IA32_FIXED_CTR2 exist, else false.
bool cpuid_perf_global_ctrl_EN_PMC ( void  )

Determine if performance monitoring capabilities are available.

Returns
True if architectural performance monitoring capabilities are supported, else false.
int cpuid_pkg_MaxLogicalProcessors ( void  )

Get max number of addressable IDs for logical processors in a physical package.

Returns
Max number of logical processors in the package.
int cpuid_pkg_MaxPhysicalProcessorCores ( void  )

Get max number of addressable IDs attributable to processor cores in the physical package.

Returns
Max number of processor cores in the package.
bool cpuid_pkg_therm_enable_status_and_interrupt ( void  )

Check if IA32_PACKAGE_THERM_STATUS and IA32_PACKAGE_THERM_INTERRUPT are enabled on the platform.

Returns
True if package-level thermal status and interrupt register are enabled, else false.
void cpuid_printVendorID ( void  )

Print platform vendor ID.

bool cpuid_therm_interrupt_enable_PowerLimitNotify ( void  )

Check if power limit notification enable is enabled in IA32_THERM_INTERRUPT.

Returns
True if power limitation status and log are enabled, else false.
bool cpuid_therm_status_enable_DigitalReadout ( void  )

Check if digital readout is enabled in IA32_THERM_STATUS.

Returns
True if digital readout is enabled, else false.
bool cpuid_therm_status_enable_PowerLimitNotify ( void  )

Check if power limitation status and log are enabled in IA32_THERM_STATUS.

Returns
True if power limitation status and log are enabled, else false.
bool cpuid_therm_status_enable_ThermalThresholds ( void  )

Check if Thermal Threshold #1 status and log and Thermal Threshold #2 status and log are enabled in IA32_THERM_STATUS.

Returns
True if TT#1 and TT#2 status and log are enabled, else false.
bool cpuid_timestamp_counter_avail ( void  )

Check availability of the time-stamp counter.

Returns
True if the time-stamp counter is available, else false.
int cpuid_width_fixed_counters ( void  )

Get bit width of fixed-function performance counters on the platform.

Returns
Bit width of fixed-function performance counters.
void cpuidInput_rax_rcx ( uint64_t  leafa,
uint64_t  leafc,
uint64_t *  rax,
uint64_t *  rbx,
uint64_t *  rcx,
uint64_t *  rdx 
)

Get max number of physical processor cores on the platform.

Parameters
[in]leafaInitial value for EAX.
[in]leafcInitial value for ECX.
[out]raxEAX register contents.
[out]rbxEBX register contents.
[out]rcxECX register contents.
[out]rdxEDX register contents.