Interfaces to learn the number and characteristics of "processors" for a given system/node.
Definitions
Processor
It's a logical processor. This may mean HT or core inside a physical CPU package. It depends on a given OS kernel. HT is the finest granularity processing unit at hardware level.
Possible-Processors
Maximum number of processors that can be attached to this OS.
Available-Processors
The number of processors that are currently configured or available under this OS. Please note that all the processors may not be enabled or used by OS.
Online-Processors
The number of processors that are currently enabled/under use/online under this OS.
Kernel implementation
This file includes additional data structures and functions for processing processors data - for kernel-mode programs.
This file will also implement Linux kernel-mode processors interfaces.
- See also
- lib/processor.h
User-space implementation
This file includes additional data structures and function for caching processors data - for user-mode programs.
This file will also implement Linux user-mode processors interfaces.
TestCases
Configuration
Get sysfs file system data for following configurations:
- Single CPU
- SMP
- SMP with multicore CPUs
- NUMA
- Configurations with Intel, AMD processors
- Developer VMs
Procedure
- Point the directory for sysfs file system data for the above configurations using environment variable 'M0_PROCESSORS_INFO_DIR'.
- Create expected reults file.
- Run unit test and compare the processor info structure with expected results.
◆ M0_PROCESSORS_INVALID_ID
#define M0_PROCESSORS_INVALID_ID ((uint32_t)-1) |
◆ PROCESSORS_CACHE1_LEVEL_FILE
#define PROCESSORS_CACHE1_LEVEL_FILE "cache/index0/level" |
◆ PROCESSORS_CACHE1_SHCPUMAP_FILE
#define PROCESSORS_CACHE1_SHCPUMAP_FILE "cache/index0/shared_cpu_map" |
◆ PROCESSORS_CACHE1_SIZE_FILE
#define PROCESSORS_CACHE1_SIZE_FILE "cache/index0/size" |
◆ PROCESSORS_CACHE2_LEVEL_FILE
#define PROCESSORS_CACHE2_LEVEL_FILE "cache/index1/level" |
◆ PROCESSORS_CACHE2_SHCPUMAP_FILE
#define PROCESSORS_CACHE2_SHCPUMAP_FILE "cache/index1/shared_cpu_map" |
◆ PROCESSORS_CACHE2_SIZE_FILE
#define PROCESSORS_CACHE2_SIZE_FILE "cache/index1/size" |
◆ PROCESSORS_CACHE3_LEVEL_FILE
#define PROCESSORS_CACHE3_LEVEL_FILE "cache/index2/level" |
◆ PROCESSORS_CACHE3_SHCPUMAP_FILE
#define PROCESSORS_CACHE3_SHCPUMAP_FILE "cache/index2/shared_cpu_map" |
◆ PROCESSORS_CACHE3_SIZE_FILE
#define PROCESSORS_CACHE3_SIZE_FILE "cache/index2/size" |
◆ PROCESSORS_COREID_FILE
#define PROCESSORS_COREID_FILE "topology/core_id" |
◆ PROCESSORS_CPU_DIR
#define PROCESSORS_CPU_DIR "cpu/" |
◆ PROCESSORS_CPU_DIR_PREFIX
#define PROCESSORS_CPU_DIR_PREFIX "cpu/cpu" |
◆ PROCESSORS_CPU_STR
#define PROCESSORS_CPU_STR "cpu" |
◆ PROCESSORS_INFO_ENV
#define PROCESSORS_INFO_ENV "M0_PROCESSORS_INFO_DIR" |
◆ PROCESSORS_MAX_FILE
#define PROCESSORS_MAX_FILE "cpu/kernel_max" |
◆ PROCESSORS_NODE_DIR
#define PROCESSORS_NODE_DIR "node/" |
◆ PROCESSORS_NODE_STR
#define PROCESSORS_NODE_STR "node" |
◆ PROCESSORS_ONLINE_FILE
#define PROCESSORS_ONLINE_FILE "cpu/online" |
◆ PROCESSORS_PHYSID_FILE
#define PROCESSORS_PHYSID_FILE "topology/physical_package_id" |
◆ PROCESSORS_POSS_FILE
#define PROCESSORS_POSS_FILE "cpu/possible" |
◆ PROCESSORS_PRESENT_FILE
#define PROCESSORS_PRESENT_FILE "cpu/present" |
◆ PROCESSORS_SYSFS_DIR
#define PROCESSORS_SYSFS_DIR "/sys/devices/system" |
◆ m0_processor_nr_t
A processor number/identifier.
Definition at line 62 of file processor.h.
◆ anonymous enum
Enumerator |
---|
PROCESSORS_RANGE_SET_SEPARATOR | |
PROCESSORS_RANGE_SEPARATOR | |
PROCESSORS_L1 | |
PROCESSORS_L2 | |
MAX_LINE_LEN | |
Definition at line 102 of file processor.c.
◆ map
Enumerator |
---|
PROCESSORS_POSS_MAP | |
PROCESSORS_AVAIL_MAP | |
PROCESSORS_ONLN_MAP | |
Definition at line 112 of file processor.c.
◆ getcpu_thr_func()
◆ getcpu_thr_init()
◆ m0_processor_describe()
Obtain information on the processor with a given id.
- Parameters
-
id | -> id of the processor for which information is requested. |
pd | -> processor descripto structure. Memory for this should be allocated by the calling function. Interface does not allocate memory. |
- Return values
-
0 | if a matching processor is found |
-EINVAL | if id does not match with any of the processors or NULL memory pointer for 'pd' is passed. |
- Precondition
- Memory must be allocated for pd. Interface donot allocated memory.
-
m0_processors_init() must be called before calling this function.
- Postcondition
- d->pd_id == id or none
Concurrency: This is read only data. Interface by itself does not do any locking. When used in kernel-mode, the interface may call some functions that may use some kind of locks.
Definition at line 1120 of file processor.c.
◆ m0_processor_id_get()
Return the id of the processor on which the calling thread is running.
- Returns
- logical processor id (as supplied by the system) on which the calling thread is running, if the call is unsupported. It will return M0_PROCESSORS_INVALID_ID, if this call is not supported.
Definition at line 1139 of file processor.c.
◆ m0_processor_is_vm()
M0_INTERNAL bool m0_processor_is_vm |
( |
void |
| ) |
|
Obtain information on the processor environment by checking the hypervisor feature flag.
- Return values
-
0 | if the processor is a physical machine. 1 if the processor is a virtual machine. |
Definition at line 1171 of file processor.c.
◆ m0_processor_nr_max()
Maximum processors this system can handle.
Definition at line 1093 of file processor.c.
◆ m0_processors_available()
M0_INTERNAL void m0_processors_available |
( |
struct m0_bitmap * |
map | ) |
|
Return the bitmap of available processors.
- Precondition
- map->b_nr >= m0_processor_nr_max()
-
m0_processors_init() must be called before calling this function.
-
The calling function must allocate memory for 'map' and initialize it.
- Note
- This function does not take any locks.
Definition at line 1106 of file processor.c.
◆ m0_processors_fini()
M0_INTERNAL void m0_processors_fini |
( |
void |
| ) |
|
Close the processors interface. This function will destroy any cached data. After calling this interface no meaningful data should be assumed.
Concurrency: Not MT-safe. Assumes no threads are using processor interface.
Definition at line 1084 of file processor.c.
◆ m0_processors_init()
M0_INTERNAL int m0_processors_init |
( |
void |
| ) |
|
Initialize processors interface. This will allow the interface to cache/populate the data, if necessary. The data is cached for user mode. The data may not be cached for kernel mode as kernel already has the data.
The calling function should not assume hot-plug CPU facility. If the underlying OS supports the hot-plug CPU facility, the calling program will have to re-initalize the interface (at least in user-mode) after registering for platform specific CPU change notification.
To re-initalize the interface, m0_processors_fini() must be called first, before initializing it again.
- Postcondition
- Interface initialized.
Concurrency: The interface should not be initialized twice or simultaneously. It's not MT-safe and can be called only once. It can be called again after calling m0_processors_fini().
Definition at line 1062 of file processor.c.
◆ m0_processors_online()
M0_INTERNAL void m0_processors_online |
( |
struct m0_bitmap * |
map | ) |
|
Return the bitmap of online processors.
- Precondition
- map->b_nr >= m0_processor_nr_max()
-
m0_processors_init() must be called before calling this function.
-
The calling function must allocate memory for 'map' and initialize it.
- Note
- This function does not take any locks.
Definition at line 1113 of file processor.c.
◆ m0_processors_possible()
M0_INTERNAL void m0_processors_possible |
( |
struct m0_bitmap * |
map | ) |
|
Return the bitmap of possible processors.
- Precondition
- map->b_nr >= m0_processor_nr_max()
-
m0_processors_init() must be called before calling this function.
-
The calling function must allocate memory for 'map' and initialize it.
- Note
- This function does not take any locks.
Definition at line 1099 of file processor.c.
◆ number_read()
static uint32_t number_read |
( |
const char * |
filename | ) |
|
|
static |
Reads a file. Returns an unsigned number.
- Parameters
-
- Returns
- non-negative number, if successful; M0_PROCESSORS_INVALID_ID, upon failure.
Definition at line 289 of file processor.c.
◆ processor_cache_destroy()
static void processor_cache_destroy |
( |
void |
| ) |
|
|
static |
◆ processor_coreid_get()
Read "cpu/cpu<id>/toplology/core_id" file under sysfs. Read the core id string convert it into a number.
- Precondition
- Assumes the directory has been changed to approriate CPU info dir.
- Parameters
-
id | -> id of the processor for which information is requested. |
- Returns
- "core" id for a given processor, on success. M0_PROCESSORS_INVALID_ID, on failure.
Definition at line 403 of file processor.c.
◆ processor_getcpu_check()
static int processor_getcpu_check |
( |
bool * |
success | ) |
|
|
static |
Checks source of processor id. It runs threads on every online processor and compares processors index with value returned by m0_processor_id_get(). On some systems sched_getcpu() may be broken and return zero on any processor. If it happens the syscall getcpu() is used as workaround.
- Parameters
-
[out] | success | -> Result of the check. |
- See also
- https://jts.seagate.com/browse/MOTR-2500.
Definition at line 960 of file processor.c.
◆ processor_getcpu_fini()
static void processor_getcpu_fini |
( |
void |
| ) |
|
|
static |
◆ processor_getcpu_init()
static int processor_getcpu_init |
( |
void |
| ) |
|
|
static |
◆ processor_info_get()
Collect all the information needed to describe a single processor. This function will scan,parse directories and files under "sysfs". This data is cached.
This function will be called from processors_summary_get().
- Parameters
-
id | -> id of the processor for which information is requested. |
pn | -> A linked list node containing processor information. |
- Precondition
- Memory to 'pn' must be allocated by the calling function
- Postcondition
- pn structure will be filled with processor information
- See also
- processors_summary_get()
Definition at line 744 of file processor.c.
◆ processor_is_cache_shared()
static bool processor_is_cache_shared |
( |
const char * |
mapstr | ) |
|
|
static |
Read string bitmap and check if the other CPUs share the resource.
- Parameters
-
mapstr | -> a string representing a bitmap |
- Return values
-
true | if the processor shares the map |
false | if the processor does not the map |
Definition at line 437 of file processor.c.
◆ processor_l1_cacheid_get()
Fetch L1 cache id for a given processor.
- Precondition
- Assumes the directory has been changed to approriate CPU info dir.
- Parameters
-
id | -> id of the processor for which information is requested. |
- Returns
- id of L1 cache for the given processor, on success. M0_PROCESSORS_INVALID_ID, on failure.
Definition at line 582 of file processor.c.
◆ processor_l1_size_get()
Fetch L1 cache size for a given processor.
- Precondition
- Assumes the directory has been changed to approriate CPU info dir.
- Parameters
-
id | -> id of the processor for which information is requested. |
- Returns
- size of L1 cache for the given processor.
Definition at line 475 of file processor.c.
◆ processor_l2_cacheid_get()
Fetch L2 cache id for a given processor.
- Precondition
- Assumes the directory has been changed to approriate CPU info dir.
- Parameters
-
id | -> id of the processor for which information is requested. |
- Returns
- id of L2 cache for the given processor, on success. M0_PROCESSORS_INVALID_ID, on failure.
Definition at line 644 of file processor.c.
◆ processor_l2_size_get()
Fetch L2 cache size for a given processor.
- Precondition
- Assumes the directory has been changed to approriate CPU info dir.
- Parameters
-
id | -> id of the processor for which information is requested. |
- Returns
- size of L2 cache for the given processor, on success. M0_PROCESSORS_INVALID_ID, on failure.
Definition at line 522 of file processor.c.
◆ processor_map_set()
static void processor_map_set |
( |
struct m0_bitmap * |
map, |
|
|
const char * |
mapstr |
|
) |
| |
|
static |
This function converts a bitmap string into a bitmap of m0_bitmap type.
- Precondition
- map != NULL
-
mapstr != NULL
- Parameters
-
map | -> m0 bitmap structure that will store the bitmap. Memory for this parameter should be allocated before calling. |
mapstr | -> bitmap string |
- See also
- processor_map_type_set()
Definition at line 193 of file processor.c.
◆ processor_map_type_set()
static int processor_map_type_set |
( |
enum map |
map_type | ) |
|
|
static |
Read map files under sysfs. Read the present cpu string and convert it into a bitmap.
- Precondition
- Assumes the directory has been changed to approriate CPU info dir.
- See also
- processor_map_set()
Definition at line 235 of file processor.c.
◆ processor_maxsz_get()
static void processor_maxsz_get |
( |
| ) |
|
|
static |
◆ processor_numanodeid_get()
Fetch NUMA node id for a given processor.
- Precondition
- Assumes the directory has been changed to approriate CPU info dir.
- Parameters
-
id | -> id of the processor for which information is requested. |
- Returns
- id of the NUMA node to which the processor belongs. If the machine is not configured as NUMA, returns 0.
Definition at line 332 of file processor.c.
◆ processor_physid_get()
Read "cpu/cpu<id>/toplology/physical_package_id" file under sysfs. Read the physical package id string convert it into a number.
- Precondition
- Assumes the directory has been changed to approriate CPU info dir.
- Parameters
-
id | -> id of the processor for which information is requested. |
- Returns
- "phys" id for a given processor, on success. M0_PROCESSORS_INVALID_ID, on failure.
Definition at line 421 of file processor.c.
◆ processor_pipelineid_get()
Fetch pipeline id for a given processor. Curently pipeline id is same as processor id.
- Parameters
-
id | -> id of the processor for which information is requested. |
- Returns
- id of pipeline for the given processor.
Definition at line 724 of file processor.c.
◆ processors_m0bitmap_copy()
static void processors_m0bitmap_copy |
( |
struct m0_bitmap * |
dst, |
|
|
const struct m0_bitmap * |
src |
|
) |
| |
|
static |
Copy m0_bitmap.
- Parameters
-
dst | -> Destination bitmap |
src | -> Source bitmap. |
Definition at line 931 of file processor.c.
◆ processors_summary_get()
static int processors_summary_get |
( |
| ) |
|
|
static |
Parse "sysfs" (/sys/devices/system) directory to fetch the summary of processors on this system.
To facilitate testing, this function will fetch the directory string from environment variable M0_PROCESSORS_INFO_DIR. This environment variable should be used only for unit testing. Under normal operation, a default value of "sysfs" directory is used.
- Precondition
- M0_PROCESSORS_INFO_DIR/default directory must exist.
- Postcondition
- A global variable of type processor_sys_summary will be filled in
- See also
- lib/processor.h
-
void m0_processors_init()
Definition at line 816 of file processor.c.
◆ processor_init
bool processor_init = false |
|
static |
◆ sys_cpus