PAPI 7.1.0.0
Loading...
Searching...
No Matches
linux_cpu_utils.h File Reference
Include dependency graph for linux_cpu_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int linux_cpu_get_vendor (char *vendor)
 
int linux_cpu_get_name (char *name)
 
int linux_cpu_get_attribute (CPU_attr_e attr, int *value)
 
int linux_cpu_get_attribute_at (CPU_attr_e attr, int loc, int *value)
 
int linux_cpu_set_affinity (int cpu)
 
int linux_cpu_get_num_supported (void)
 
int linux_cpu_store_affinity (void)
 
int linux_cpu_load_affinity (void)
 

Function Documentation

◆ linux_cpu_get_attribute()

int linux_cpu_get_attribute ( CPU_attr_e  attr,
int value 
)

Definition at line 120 of file linux_cpu_utils.c.

121{
122 int status = CPU_SUCCESS;
123
124#define TOPOKEY_NUM_KEY 4
125#define VERKEY_NUM_KEY 4
126
127 int topo_idx = TOPOKEY_NUM_KEY;
128 int ver_idx = VERKEY_NUM_KEY;
129
130 const char *topokey[TOPOKEY_NUM_KEY] = {
131 "sockets",
132 "nodes",
133 "threads",
134 "cores",
135 };
136
137 const char *verkey_x86[VERKEY_NUM_KEY] = {
138 "cpu family", /* cpuid_family */
139 "model", /* cpuid_model */
140 "stepping", /* cpuid_stepping */
141 "vendor_id", /* vendor id */
142 };
143
144 const char *verkey_ibm[VERKEY_NUM_KEY] = {
145 "none", /* cpuid_family */
146 "none", /* cpuid_model */
147 "revision", /* cpuid_stepping */
148 "vendor_id", /* vendor id */
149 };
150
151 const char *verkey_arm[VERKEY_NUM_KEY] = {
152 "CPU architecture", /* cpuid_family */
153 "CPU part", /* cpuid_model */
154 "CPU variant", /* cpuid_stepping */
155 "CPU implementer", /* vendor id */
156 };
157
158 const char *verkey_dum[VERKEY_NUM_KEY] = {
159 "none",
160 "none",
161 "none",
162 "none",
163 };
164
165 const char **verkey_ptr = NULL;
166
167 int vendor_id = get_vendor_id();
168
169 if (vendor_id == VENDOR_INTEL_X86 || vendor_id == VENDOR_AMD) {
170 verkey_ptr = verkey_x86;
171 } else if (vendor_id == VENDOR_IBM) {
172 verkey_ptr = verkey_ibm;
173 } else if (vendor_id == VENDOR_ARM_ARM ||
174 vendor_id == VENDOR_ARM_BROADCOM ||
175 vendor_id == VENDOR_ARM_CAVIUM ||
176 vendor_id == VENDOR_ARM_FUJITSU ||
177 vendor_id == VENDOR_ARM_HISILICON ||
178 vendor_id == VENDOR_ARM_APM ||
179 vendor_id == VENDOR_ARM_QUALCOMM) {
180 verkey_ptr = verkey_arm;
181 } else {
182 verkey_ptr = verkey_dum;
183 }
184
185 switch(attr) {
187 --topo_idx;
188 // fall through
190 --topo_idx;
191 // fall through
193 --topo_idx;
194 // fall through
196 --topo_idx;
197 status = get_topology_info(topokey[topo_idx], value);
198 break;
200 --ver_idx;
201 // fall through
203 --ver_idx;
204 // fall through
206 --ver_idx;
207 // fall through
209 --ver_idx;
210 status = get_versioning_info(verkey_ptr[ver_idx], value);
211 break;
214 break;
215 default:
216 status = CPU_ERROR;
217 }
218
219 return status;
220}
#define CPU_ERROR
Definition: cpu_utils.h:5
#define CPU_SUCCESS
Definition: cpu_utils.h:4
@ CPU_ATTR__CPUID_MODEL
Definition: cpu_utils.h:14
@ CPU_ATTR__CACHE_MAX_NUM_LEVELS
Definition: cpu_utils.h:17
@ CPU_ATTR__NUM_THREADS
Definition: cpu_utils.h:11
@ CPU_ATTR__CPUID_FAMILY
Definition: cpu_utils.h:13
@ CPU_ATTR__NUM_NODES
Definition: cpu_utils.h:9
@ CPU_ATTR__CPUID_STEPPING
Definition: cpu_utils.h:15
@ CPU_ATTR__NUM_CORES
Definition: cpu_utils.h:10
@ CPU_ATTR__NUM_SOCKETS
Definition: cpu_utils.h:8
@ CPU_ATTR__VENDOR_ID
Definition: cpu_utils.h:12
#define PAPI_MAX_MEM_HIERARCHY_LEVELS
Definition: f90papi.h:103
static int get_vendor_id(void)
static int get_topology_info(const char *key, int *value)
#define VENDOR_ARM_CAVIUM
#define VENDOR_ARM_HISILICON
#define VENDOR_ARM_BROADCOM
#define VENDOR_INTEL_X86
#define VENDOR_ARM_ARM
#define VERKEY_NUM_KEY
#define VENDOR_AMD
#define TOPOKEY_NUM_KEY
#define VENDOR_ARM_QUALCOMM
static int get_versioning_info(const char *key, int *value)
#define VENDOR_IBM
#define VENDOR_ARM_FUJITSU
#define VENDOR_ARM_APM
Here is the call graph for this function:
Here is the caller graph for this function:

◆ linux_cpu_get_attribute_at()

int linux_cpu_get_attribute_at ( CPU_attr_e  attr,
int  loc,
int value 
)

Definition at line 223 of file linux_cpu_utils.c.

224{
225 int status = CPU_SUCCESS;
226
227 switch(attr) {
243 status = get_cache_info(attr, loc, value);
244 break;
246 status = get_mem_info(loc, value);
247 break;
249 status = get_thread_affinity(loc, value);
250 break;
251 default:
252 status = CPU_ERROR;
253 }
254
255 return status;
256}
@ CPU_ATTR__CACHE_INST_TOT_SIZE
Definition: cpu_utils.h:21
@ CPU_ATTR__HWTHREAD_NUMA_AFFINITY
Definition: cpu_utils.h:34
@ CPU_ATTR__CACHE_UNIF_TOT_SIZE
Definition: cpu_utils.h:29
@ CPU_ATTR__CACHE_DATA_ASSOCIATIVITY
Definition: cpu_utils.h:28
@ CPU_ATTR__CACHE_INST_LINE_SIZE
Definition: cpu_utils.h:22
@ CPU_ATTR__NUMA_MEM_SIZE
Definition: cpu_utils.h:36
@ CPU_ATTR__CACHE_UNIF_LINE_SIZE
Definition: cpu_utils.h:30
@ CPU_ATTR__CACHE_DATA_NUM_LINES
Definition: cpu_utils.h:27
@ CPU_ATTR__CACHE_UNIF_ASSOCIATIVITY
Definition: cpu_utils.h:32
@ CPU_ATTR__CACHE_INST_PRESENT
Definition: cpu_utils.h:18
@ CPU_ATTR__CACHE_DATA_PRESENT
Definition: cpu_utils.h:19
@ CPU_ATTR__CACHE_DATA_LINE_SIZE
Definition: cpu_utils.h:26
@ CPU_ATTR__CACHE_INST_ASSOCIATIVITY
Definition: cpu_utils.h:24
@ CPU_ATTR__CACHE_INST_NUM_LINES
Definition: cpu_utils.h:23
@ CPU_ATTR__CACHE_UNIF_NUM_LINES
Definition: cpu_utils.h:31
@ CPU_ATTR__CACHE_DATA_TOT_SIZE
Definition: cpu_utils.h:25
@ CPU_ATTR__CACHE_UNIF_PRESENT
Definition: cpu_utils.h:20
static int get_thread_affinity(int thread, int *value)
static int get_mem_info(int node, int *value)
static int get_cache_info(CPU_attr_e attr, int level, int *value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ linux_cpu_get_name()

int linux_cpu_get_name ( char *  name)

Definition at line 89 of file linux_cpu_utils.c.

90{
91 const char *namekey_x86 = "model name";
92 const char *namekey_ibm = "model";
93 const char *namekey_arm = "model name";
94 const char *namekey_dum = "none";
95
96 const char *namekey_ptr = NULL;
97
98 int vendor_id = get_vendor_id();
99
100 if (vendor_id == VENDOR_INTEL_X86 || vendor_id == VENDOR_AMD) {
101 namekey_ptr = namekey_x86;
102 } else if (vendor_id == VENDOR_IBM) {
103 namekey_ptr = namekey_ibm;
104 } else if (vendor_id == VENDOR_ARM_ARM ||
105 vendor_id == VENDOR_ARM_BROADCOM ||
106 vendor_id == VENDOR_ARM_CAVIUM ||
107 vendor_id == VENDOR_ARM_FUJITSU ||
108 vendor_id == VENDOR_ARM_HISILICON ||
109 vendor_id == VENDOR_ARM_APM ||
110 vendor_id == VENDOR_ARM_QUALCOMM) {
111 namekey_ptr = namekey_arm;
112 } else {
113 namekey_ptr = namekey_dum;
114 }
115
116 return get_naming_info(namekey_ptr, name);
117}
static int get_naming_info(const char *key, char *value)
const char * name
Definition: rocs.c:225
Here is the call graph for this function:
Here is the caller graph for this function:

◆ linux_cpu_get_num_supported()

int linux_cpu_get_num_supported ( void  )

Definition at line 270 of file linux_cpu_utils.c.

271{
272 return sysconf(_SC_NPROCESSORS_CONF);
273}
Here is the caller graph for this function:

◆ linux_cpu_get_vendor()

int linux_cpu_get_vendor ( char *  vendor)

Definition at line 52 of file linux_cpu_utils.c.

53{
54 const char *namekey_x86 = "vendor_id";
55 const char *namekey_ia64 = "vendor";
56 const char *namekey_ibm = "platform";
57 const char *namekey_mips = "system type";
58 const char *namekey_arm = "CPU implementer";
59 const char *namekey_dum = "none";
60
61 const char *namekey_ptr = NULL;
62
63 int vendor_id = get_vendor_id();
64
65 if (vendor_id == VENDOR_INTEL_X86 || vendor_id == VENDOR_AMD) {
66 namekey_ptr = namekey_x86;
67 } else if (vendor_id == VENDOR_INTEL_IA64) {
68 namekey_ptr = namekey_ia64;
69 } else if (vendor_id == VENDOR_IBM) {
70 namekey_ptr = namekey_ibm;
71 } else if (vendor_id == VENDOR_MIPS) {
72 namekey_ptr = namekey_mips;
73 } else if (vendor_id == VENDOR_ARM_ARM ||
74 vendor_id == VENDOR_ARM_BROADCOM ||
75 vendor_id == VENDOR_ARM_CAVIUM ||
76 vendor_id == VENDOR_ARM_FUJITSU ||
77 vendor_id == VENDOR_ARM_HISILICON ||
78 vendor_id == VENDOR_ARM_APM ||
79 vendor_id == VENDOR_ARM_QUALCOMM) {
80 namekey_ptr = namekey_arm;
81 } else {
82 namekey_ptr = namekey_dum;
83 }
84
85 return get_naming_info(namekey_ptr, vendor);
86}
#define VENDOR_MIPS
#define VENDOR_INTEL_IA64
Here is the call graph for this function:
Here is the caller graph for this function:

◆ linux_cpu_load_affinity()

int linux_cpu_load_affinity ( void  )

Definition at line 287 of file linux_cpu_utils.c.

288{
289 return sched_setaffinity(0, sizeof(cpu_set_t), &saved_affinity);
290}
static cpu_set_t saved_affinity
Here is the caller graph for this function:

◆ linux_cpu_set_affinity()

int linux_cpu_set_affinity ( int  cpu)

Definition at line 259 of file linux_cpu_utils.c.

260{
261 cpu_set_t cpuset;
262
263 CPU_ZERO(&cpuset);
264 CPU_SET(cpu, &cpuset);
265
266 return sched_setaffinity(0, sizeof(cpuset), &cpuset);
267}
Here is the caller graph for this function:

◆ linux_cpu_store_affinity()

int linux_cpu_store_affinity ( void  )

Definition at line 278 of file linux_cpu_utils.c.

279{
280 if (!CPU_COUNT(&saved_affinity))
281 return sched_getaffinity(0, sizeof(cpu_set_t), &saved_affinity);
282
283 return CPU_SUCCESS;
284}
Here is the caller graph for this function: