|
libmsr
0.3.0
A friendlier interface to accessing MSRs on Intel platforms
|
#include <errno.h>#include <fcntl.h>#include <linux/ioctl.h>#include <linux/types.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include "msr_core.h"#include "memhdlr.h"#include "msr_counters.h"#include "cpuid.h"#include "libmsr_error.h"#include "libmsr_debug.h"
Macros | |
| #define | _XOPEN_SOURCE 500 |
Functions | |
| uint64_t | num_cores (void) |
| Retrieve the number of cores existing on the platform. | |
| uint64_t | num_sockets (void) |
| Retrieve the number of sockets existing on the platform. | |
| uint64_t | num_devs (void) |
| Retrieve total number of logical processors existing on the platform. | |
| uint64_t | cores_per_socket (void) |
| Retrieve number of cores per socket existing on the platform. | |
| int | allocate_batch (int batchnum, size_t bsize) |
| Allocate space for new batch operation. | |
| int | free_batch (int batchnum) |
| Deallocate memory for specific set of batch operations. | |
| int | create_batch_op (off_t msr, uint64_t cpu, uint64_t **dest, const int batchnum) |
| Create new batch operation. | |
| void | core_config (uint64_t *coresPerSocket, uint64_t *threadsPerCore, uint64_t *sysSockets, int *HTenabled) |
| Detect platform configuration. | |
| int | sockets_assert (const unsigned *socket, const int location, const char *file) |
| Validate specific socket exists in the platform configuration. | |
| int | threads_assert (const unsigned *thread, const int location, const char *file) |
| Validate specific thread exists in the platform configuration. | |
| int | cores_assert (const unsigned *core, const int location, const char *file) |
| Validate specific core exists in the platform configuration. | |
| int | stat_module (char *filename, int *kerneltype, int *dev_idx) |
| Check status of a file. | |
| int | init_msr (void) |
| Open the MSR module file descriptors exposed in the /dev filesystem. | |
| int | finalize_msr (void) |
| Close the MSR module file descriptors exposed in the /dev filesystem. | |
| int | write_msr_by_coord (unsigned socket, unsigned core, unsigned thread, off_t msr, uint64_t val) |
| Write a new value to an MSR based on the coordinates of a core or thread. | |
| int | read_msr_by_coord (unsigned socket, unsigned core, unsigned thread, off_t msr, uint64_t *val) |
| Read current value of an MSR based on the coordinates of a core or thread. | |
| int | read_msr_by_coord_batch (unsigned socket, unsigned core, unsigned thread, off_t msr, uint64_t **val, int batchnum) |
| Perform batch read of multiple MSR based on the coordinates of a core or thread. | |
| int | read_batch (const int batchnum) |
| Do batch read operation. | |
| int | write_batch (const int batchnum) |
| Do batch write operation. | |
| int | load_socket_batch (off_t msr, uint64_t **val, int batchnum) |
| Load batch operations for a socket. | |
| int | load_core_batch (off_t msr, uint64_t **val, int batchnum) |
| Load batch operations for a core. | |
| int | load_thread_batch (off_t msr, uint64_t **val, int batchnum) |
| Load batch operations for a thread. | |
| int | read_msr_by_idx (int dev_idx, off_t msr, uint64_t *val) |
| Read current value of an MSR based on the index of a core or thread. | |
| int | write_msr_by_idx (int dev_idx, off_t msr, uint64_t val) |
| Write new value to an MSR based on the index of a core or thread. | |
| int | write_msr_by_idx_and_verify (int dev_idx, off_t msr, uint64_t val) |
| Verify successful MSR write by following operation immediately with a read. | |
| #define _XOPEN_SOURCE 500 |
| int allocate_batch | ( | int | batchnum, |
| size_t | bsize | ||
| ) |
Allocate space for new batch operation.
| [in] | batchnum | libmsr_data_type_e data type of batch operation. |
| [in] | bsize | Size of batch operation. |
| void core_config | ( | uint64_t * | coresPerSocket, |
| uint64_t * | threadsPerCore, | ||
| uint64_t * | sockets, | ||
| int * | HTenabled | ||
| ) |
Detect platform configuration.
| [out] | coresPerSocket | Number of cores per socket. |
| [out] | threadsPerCore | Number of threads per core. |
| [out] | sockets | Number of sockets. |
| [out] | HTenabled | Indicates if hyperthreading is enabled/disabled. |
| int cores_assert | ( | const unsigned * | core, |
| const int | location, | ||
| const char * | file | ||
| ) |
Validate specific core exists in the platform configuration.
| [in] | core | Unique core identifier. |
| [in] | location | Line number in source file where error occurred (use standard predefined macro LINE). |
| [in] | file | Name of source file where error occurred (use standard predefined macro FILE). |
| uint64_t cores_per_socket | ( | void | ) |
Retrieve number of cores per socket existing on the platform.
| int create_batch_op | ( | off_t | msr, |
| uint64_t | cpu, | ||
| uint64_t ** | dest, | ||
| const int | batchnum | ||
| ) |
Create new batch operation.
| [in] | msr | Address of MSR for which operation will take place. |
| [in] | cpu | CPU where batch operation will take place. |
| [in] | dest | Stores data resulting from rdmsr or necessary for wrmsr. |
| [in] | batchnum | libmsr_data_type_e data type of batch operation. |
| int finalize_msr | ( | void | ) |
Close the MSR module file descriptors exposed in the /dev filesystem.
| int free_batch | ( | int | batchnum | ) |
Deallocate memory for specific set of batch operations.
| [in] | batchnum | libmsr_data_type_e data type of batch operation. |
| int init_msr | ( | void | ) |
Open the MSR module file descriptors exposed in the /dev filesystem.
| int load_core_batch | ( | off_t | msr, |
| uint64_t ** | val, | ||
| const int | batchnum | ||
| ) |
Load batch operations for a core.
| [in] | msr | Address of register to load. |
| [in] | val | Pointer to batch storage array. |
| [in] | batchnum | libmsr_data_type_e data type of batch operation. |
| int load_socket_batch | ( | off_t | msr, |
| uint64_t ** | val, | ||
| const int | batchnum | ||
| ) |
Load batch operations for a socket.
| [in] | msr | Address of register to load. |
| [in] | val | Pointer to batch storage array. |
| [in] | batchnum | libmsr_data_type_e data type of batch operation. |
| int load_thread_batch | ( | off_t | msr, |
| uint64_t ** | val, | ||
| const int | batchnum | ||
| ) |
Load batch operations for a thread.
| [in] | msr | Address of register to load. |
| [in] | val | Pointer to batch storage array. |
| [in] | batchnum | libmsr_data_type_e data type of batch operation. |
| uint64_t num_cores | ( | void | ) |
Retrieve the number of cores existing on the platform.
| uint64_t num_devs | ( | void | ) |
Retrieve total number of logical processors existing on the platform.
| uint64_t num_sockets | ( | void | ) |
Retrieve the number of sockets existing on the platform.
| int read_batch | ( | const int | batchnum | ) |
Do batch read operation.
| [in] | batchnum | libmsr_data_type_e data type of batch operation. |
| int read_msr_by_coord | ( | unsigned | socket, |
| unsigned | core, | ||
| unsigned | thread, | ||
| off_t | msr, | ||
| uint64_t * | val | ||
| ) |
Read current value of an MSR based on the coordinates of a core or thread.
A user can request to read from core 4 on socket 1, instead of having to map this core to a continuous value based on the the number of cores on socket 0. For a dual socket system with 8 cores, socket 0 would have cores 0-7, core 0 on socket 1 would be mapped to index 8.
| [in] | socket | Unique socket/package identifier. |
| [in] | core | Unique core identifier. |
| [in] | thread | Unique thread identifier. |
| [in] | msr | Address of register to read. |
| [out] | val | Value read from MSR. |
| int read_msr_by_coord_batch | ( | unsigned | socket, |
| unsigned | core, | ||
| unsigned | thread, | ||
| off_t | msr, | ||
| uint64_t ** | val, | ||
| int | batchnum | ||
| ) |
Perform batch read of multiple MSR based on the coordinates of a core or thread.
| [in] | socket | Unique socket/package identifier. |
| [in] | core | Unique core identifier. |
| [in] | thread | Unique thread identifier. |
| [in] | msr | Address of register to read. |
| [out] | val | Value read from MSR. |
| [in] | batchnum | libmsr_data_type_e data type of batch operation. |
| int read_msr_by_idx | ( | int | dev_idx, |
| off_t | msr, | ||
| uint64_t * | val | ||
| ) |
Read current value of an MSR based on the index of a core or thread.
A user can request to read from index 8, which is core 0 on socket 1 in a dual socket system with 8 cores per socket. This index is a continuous value based on the the number of cores on socket 0.
| [in] | dev_idx | Unique device identifier. |
| [in] | msr | Address of register to read. |
| [out] | val | Value read from MSR. |
| int sockets_assert | ( | const unsigned * | socket, |
| const int | location, | ||
| const char * | file | ||
| ) |
Validate specific socket exists in the platform configuration.
| [in] | socket | Unique socket/package identifier. |
| [in] | location | Line number in source file where error occurred (use standard predefined macro LINE). |
| [in] | file | Name of source file where error occurred (use standard predefined macro FILE). |
| int stat_module | ( | char * | filename, |
| int * | kerneltype, | ||
| int * | dev_idx | ||
| ) |
Check status of a file.
| [in] | filename | File to check status of. |
| [in] | kerneltype | OS privilege level (ring 0-ring 3). |
| [in] | dev_idx | Unique logical processor index. |
| int threads_assert | ( | const unsigned * | thread, |
| const int | location, | ||
| const char * | file | ||
| ) |
Validate specific thread exists in the platform configuration.
| [in] | thread | Unique thread identifier. |
| [in] | location | Line number in source file where error occurred (use standard predefined macro LINE). |
| [in] | file | Name of source file where error occurred (use standard predefined macro FILE). |
| int write_batch | ( | const int | batchnum | ) |
Do batch write operation.
| [in] | batchnum | libmsr_data_type_e data type of batch operation. |
| int write_msr_by_coord | ( | unsigned | socket, |
| unsigned | core, | ||
| unsigned | thread, | ||
| off_t | msr, | ||
| uint64_t | val | ||
| ) |
Write a new value to an MSR based on the coordinates of a core or thread.
A user can request to write to core 4 on socket 1, instead of having to map this core to a continuous value based on the the number of cores on socket 0. For a dual socket system with 8 cores, socket 0 would have cores 0-7, core 0 on socket 1 would be mapped to index 8.
| [in] | socket | Unique socket/package identifier. |
| [in] | core | Unique core identifier. |
| [in] | thread | Unique thread identifier. |
| [in] | msr | Address of register to write. |
| [in] | val | Value to write to MSR. |
| int write_msr_by_idx | ( | int | dev_idx, |
| off_t | msr, | ||
| uint64_t | val | ||
| ) |
Write new value to an MSR based on the index of a core or thread.
A user can request to read from index 8, which is core 0 on socket 1 in a dual socket system with 8 cores per socket. This index is a continuous value based on the the number of cores on socket 0.
| [in] | dev_idx | Unique device identifier. |
| [in] | msr | Address of register to read. |
| [out] | val | Value read from MSR. |
| int write_msr_by_idx_and_verify | ( | int | dev_idx, |
| off_t | msr, | ||
| uint64_t | val | ||
| ) |
Verify successful MSR write by following operation immediately with a read.
| [in] | dev_idx | Unique device identifier. |
| [in] | msr | Address of register to read. |
| [out] | val | Value read from MSR. |
1.8.2