Motr  M0
Processor Information

Data Structures

struct  m0_processor_descr
 
struct  processor_sys_summary
 
struct  processor_node
 
struct  processor_global
 
struct  getcpu_thr_data
 

Macros

#define M0_PROCESSORS_INVALID_ID   ((uint32_t)-1)
 
#define PROCESSORS_INFO_ENV   "M0_PROCESSORS_INFO_DIR"
 
#define PROCESSORS_SYSFS_DIR   "/sys/devices/system"
 
#define PROCESSORS_CPU_DIR   "cpu/"
 
#define PROCESSORS_NODE_DIR   "node/"
 
#define PROCESSORS_MAX_FILE   "cpu/kernel_max"
 
#define PROCESSORS_POSS_FILE   "cpu/possible"
 
#define PROCESSORS_PRESENT_FILE   "cpu/present"
 
#define PROCESSORS_ONLINE_FILE   "cpu/online"
 
#define PROCESSORS_CACHE1_LEVEL_FILE   "cache/index0/level"
 
#define PROCESSORS_CACHE2_LEVEL_FILE   "cache/index1/level"
 
#define PROCESSORS_CACHE3_LEVEL_FILE   "cache/index2/level"
 
#define PROCESSORS_CACHE1_SHCPUMAP_FILE   "cache/index0/shared_cpu_map"
 
#define PROCESSORS_CACHE2_SHCPUMAP_FILE   "cache/index1/shared_cpu_map"
 
#define PROCESSORS_CACHE3_SHCPUMAP_FILE   "cache/index2/shared_cpu_map"
 
#define PROCESSORS_CACHE1_SIZE_FILE   "cache/index0/size"
 
#define PROCESSORS_CACHE2_SIZE_FILE   "cache/index1/size"
 
#define PROCESSORS_CACHE3_SIZE_FILE   "cache/index2/size"
 
#define PROCESSORS_COREID_FILE   "topology/core_id"
 
#define PROCESSORS_PHYSID_FILE   "topology/physical_package_id"
 
#define PROCESSORS_CPU_DIR_PREFIX   "cpu/cpu"
 
#define PROCESSORS_NODE_STR   "node"
 
#define PROCESSORS_CPU_STR   "cpu"
 

Typedefs

typedef uint32_t m0_processor_nr_t
 

Enumerations

enum  {
  PROCESSORS_RANGE_SET_SEPARATOR = ',', PROCESSORS_RANGE_SEPARATOR = '-', PROCESSORS_L1 = 1, PROCESSORS_L2 = 2,
  MAX_LINE_LEN = 256
}
 
enum  map { PROCESSORS_POSS_MAP = 0, PROCESSORS_AVAIL_MAP = 1, PROCESSORS_ONLN_MAP = 2 }
 

Functions

M0_INTERNAL int m0_processors_init (void)
 
M0_INTERNAL void m0_processors_fini (void)
 
M0_INTERNAL m0_processor_nr_t m0_processor_nr_max (void)
 
M0_INTERNAL void m0_processors_possible (struct m0_bitmap *map)
 
M0_INTERNAL void m0_processors_available (struct m0_bitmap *map)
 
M0_INTERNAL void m0_processors_online (struct m0_bitmap *map)
 
M0_INTERNAL m0_processor_nr_t m0_processor_id_get (void)
 
M0_INTERNAL int m0_processor_describe (m0_processor_nr_t id, struct m0_processor_descr *pd)
 
M0_INTERNAL bool m0_processor_is_vm (void)
 
static void processor_map_set (struct m0_bitmap *map, const char *mapstr)
 
static int processor_map_type_set (enum map map_type)
 
static uint32_t number_read (const char *filename)
 
static void processor_maxsz_get ()
 
static uint32_t processor_numanodeid_get (m0_processor_nr_t id)
 
static uint32_t processor_coreid_get (m0_processor_nr_t id)
 
static uint32_t processor_physid_get (m0_processor_nr_t id)
 
static bool processor_is_cache_shared (const char *mapstr)
 
static size_t processor_l1_size_get (m0_processor_nr_t id)
 
static size_t processor_l2_size_get (m0_processor_nr_t id)
 
static uint32_t processor_l1_cacheid_get (m0_processor_nr_t id)
 
static uint32_t processor_l2_cacheid_get (m0_processor_nr_t id)
 
static uint32_t processor_pipelineid_get (m0_processor_nr_t id)
 
static int processor_info_get (m0_processor_nr_t id, struct processor_node *pn)
 
static void processor_cache_destroy (void)
 
static int processors_summary_get ()
 
static void processors_m0bitmap_copy (struct m0_bitmap *dst, const struct m0_bitmap *src)
 
static int getcpu_thr_init (struct getcpu_thr_data *data)
 
static void getcpu_thr_func (struct getcpu_thr_data *data)
 
static int processor_getcpu_check (bool *success)
 
static int processor_getcpu_init (void)
 
static void processor_getcpu_fini (void)
 

Variables

static struct processor_sys_summary sys_cpus
 
static bool processor_init = false
 

Detailed Description

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:

Procedure

Macro Definition Documentation

◆ M0_PROCESSORS_INVALID_ID

#define M0_PROCESSORS_INVALID_ID   ((uint32_t)-1)

Definition at line 59 of file processor.h.

◆ PROCESSORS_CACHE1_LEVEL_FILE

#define PROCESSORS_CACHE1_LEVEL_FILE   "cache/index0/level"

Definition at line 82 of file processor.c.

◆ PROCESSORS_CACHE1_SHCPUMAP_FILE

#define PROCESSORS_CACHE1_SHCPUMAP_FILE   "cache/index0/shared_cpu_map"

Definition at line 86 of file processor.c.

◆ PROCESSORS_CACHE1_SIZE_FILE

#define PROCESSORS_CACHE1_SIZE_FILE   "cache/index0/size"

Definition at line 90 of file processor.c.

◆ PROCESSORS_CACHE2_LEVEL_FILE

#define PROCESSORS_CACHE2_LEVEL_FILE   "cache/index1/level"

Definition at line 83 of file processor.c.

◆ PROCESSORS_CACHE2_SHCPUMAP_FILE

#define PROCESSORS_CACHE2_SHCPUMAP_FILE   "cache/index1/shared_cpu_map"

Definition at line 87 of file processor.c.

◆ PROCESSORS_CACHE2_SIZE_FILE

#define PROCESSORS_CACHE2_SIZE_FILE   "cache/index1/size"

Definition at line 91 of file processor.c.

◆ PROCESSORS_CACHE3_LEVEL_FILE

#define PROCESSORS_CACHE3_LEVEL_FILE   "cache/index2/level"

Definition at line 84 of file processor.c.

◆ PROCESSORS_CACHE3_SHCPUMAP_FILE

#define PROCESSORS_CACHE3_SHCPUMAP_FILE   "cache/index2/shared_cpu_map"

Definition at line 88 of file processor.c.

◆ PROCESSORS_CACHE3_SIZE_FILE

#define PROCESSORS_CACHE3_SIZE_FILE   "cache/index2/size"

Definition at line 92 of file processor.c.

◆ PROCESSORS_COREID_FILE

#define PROCESSORS_COREID_FILE   "topology/core_id"

Definition at line 94 of file processor.c.

◆ PROCESSORS_CPU_DIR

#define PROCESSORS_CPU_DIR   "cpu/"

Definition at line 74 of file processor.c.

◆ PROCESSORS_CPU_DIR_PREFIX

#define PROCESSORS_CPU_DIR_PREFIX   "cpu/cpu"

Definition at line 97 of file processor.c.

◆ PROCESSORS_CPU_STR

#define PROCESSORS_CPU_STR   "cpu"

Definition at line 100 of file processor.c.

◆ PROCESSORS_INFO_ENV

#define PROCESSORS_INFO_ENV   "M0_PROCESSORS_INFO_DIR"

Definition at line 71 of file processor.c.

◆ PROCESSORS_MAX_FILE

#define PROCESSORS_MAX_FILE   "cpu/kernel_max"

Definition at line 77 of file processor.c.

◆ PROCESSORS_NODE_DIR

#define PROCESSORS_NODE_DIR   "node/"

Definition at line 75 of file processor.c.

◆ PROCESSORS_NODE_STR

#define PROCESSORS_NODE_STR   "node"

Definition at line 99 of file processor.c.

◆ PROCESSORS_ONLINE_FILE

#define PROCESSORS_ONLINE_FILE   "cpu/online"

Definition at line 80 of file processor.c.

◆ PROCESSORS_PHYSID_FILE

#define PROCESSORS_PHYSID_FILE   "topology/physical_package_id"

Definition at line 95 of file processor.c.

◆ PROCESSORS_POSS_FILE

#define PROCESSORS_POSS_FILE   "cpu/possible"

Definition at line 78 of file processor.c.

◆ PROCESSORS_PRESENT_FILE

#define PROCESSORS_PRESENT_FILE   "cpu/present"

Definition at line 79 of file processor.c.

◆ PROCESSORS_SYSFS_DIR

#define PROCESSORS_SYSFS_DIR   "/sys/devices/system"

Definition at line 73 of file processor.c.

Typedef Documentation

◆ m0_processor_nr_t

typedef uint32_t m0_processor_nr_t

A processor number/identifier.

Definition at line 62 of file processor.h.

Enumeration Type Documentation

◆ anonymous enum

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

enum map
Enumerator
PROCESSORS_POSS_MAP 
PROCESSORS_AVAIL_MAP 
PROCESSORS_ONLN_MAP 

Definition at line 112 of file processor.c.

Function Documentation

◆ getcpu_thr_func()

static void getcpu_thr_func ( struct getcpu_thr_data data)
static

Definition at line 943 of file processor.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getcpu_thr_init()

static int getcpu_thr_init ( struct getcpu_thr_data data)
static

Definition at line 938 of file processor.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_processor_describe()

M0_INTERNAL int m0_processor_describe ( m0_processor_nr_t  id,
struct m0_processor_descr pd 
)

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
0if a matching processor is found
-EINVALif 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_processor_id_get()

M0_INTERNAL m0_processor_nr_t m0_processor_id_get ( void  )

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
0if 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()

M0_INTERNAL m0_processor_nr_t m0_processor_nr_max ( void  )

Maximum processors this system can handle.

Definition at line 1093 of file processor.c.

Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ number_read()

static uint32_t number_read ( const char *  filename)
static

Reads a file. Returns an unsigned number.

Parameters
filename-> file to read
Returns
non-negative number, if successful; M0_PROCESSORS_INVALID_ID, upon failure.

Definition at line 289 of file processor.c.

Here is the caller graph for this function:

◆ processor_cache_destroy()

static void processor_cache_destroy ( void  )
static

Cache clean-up.

See also
m0_processors_fini
processors_summary_get

Definition at line 780 of file processor.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_coreid_get()

static uint32_t processor_coreid_get ( m0_processor_nr_t  id)
static

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_getcpu_fini()

static void processor_getcpu_fini ( void  )
static

Definition at line 1046 of file processor.c.

Here is the caller graph for this function:

◆ processor_getcpu_init()

static int processor_getcpu_init ( void  )
static

Definition at line 1023 of file processor.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_info_get()

static int processor_info_get ( m0_processor_nr_t  id,
struct processor_node pn 
)
static

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
trueif the processor shares the map
falseif the processor does not the map

Definition at line 437 of file processor.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_l1_cacheid_get()

static uint32_t processor_l1_cacheid_get ( m0_processor_nr_t  id)
static

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_l1_size_get()

static size_t processor_l1_size_get ( m0_processor_nr_t  id)
static

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_l2_cacheid_get()

static uint32_t processor_l2_cacheid_get ( m0_processor_nr_t  id)
static

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_l2_size_get()

static size_t processor_l2_size_get ( m0_processor_nr_t  id)
static

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_maxsz_get()

static void processor_maxsz_get ( )
static

Read "cpu/kernel_max" file under sysfs. Read the kernel_max cpu string and convert it into a number.

Precondition
Assumes the directory has been changed to approriate CPU info dir.
See also
processor_map_set()
processor_map_type_set()

Definition at line 315 of file processor.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_numanodeid_get()

static uint32_t processor_numanodeid_get ( m0_processor_nr_t  id)
static

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.

Here is the caller graph for this function:

◆ processor_physid_get()

static uint32_t processor_physid_get ( m0_processor_nr_t  id)
static

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processor_pipelineid_get()

static uint32_t processor_pipelineid_get ( m0_processor_nr_t  id)
inlinestatic

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.

Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ processor_init

bool processor_init = false
static

Definition at line 180 of file processor.c.

◆ sys_cpus

struct processor_sys_summary sys_cpus
static

Definition at line 179 of file processor.c.