PAPI 7.1.0.0
Loading...
Searching...
No Matches
linux-stealtime.c File Reference

A component that gather info on VM stealtime. More...

Include dependency graph for linux-stealtime.c:

Go to the source code of this file.

Data Structures

struct  STEALTIME_reg_alloc_t
 
struct  STEALTIME_control_state
 
struct  STEALTIME_context
 
struct  statinfo
 

Functions

static int read_stealtime (struct STEALTIME_context *context, int starting)
 
static int _stealtime_shutdown_component (void)
 
static int _stealtime_init_component (int cidx)
 
static int _stealtime_init_thread (hwd_context_t *ctx)
 
static int _stealtime_shutdown_thread (hwd_context_t *ctx)
 
static int _stealtime_init_control_state (hwd_control_state_t *ctl)
 
static int _stealtime_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
static int _stealtime_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _stealtime_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _stealtime_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
 
static int _stealtime_reset (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
static int _stealtime_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
static int _stealtime_set_domain (hwd_control_state_t *cntrl, int domain)
 
static int _stealtime_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
static int _stealtime_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
static int _stealtime_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
 
static int _stealtime_ntv_enum_events (unsigned int *EventCode, int modifier)
 

Variables

static int num_events = 0
 
static struct counter_infoevent_info =NULL
 
papi_vector_t _stealtime_vector
 

Detailed Description

Function Documentation

◆ _stealtime_ctl()

static int _stealtime_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)
static

Definition at line 456 of file linux-stealtime.c.

457{
458 ( void ) ctx;
459 ( void ) code;
460 ( void ) option;
461
462 return PAPI_OK;
463}
#define PAPI_OK
Definition: f90papi.h:73

◆ _stealtime_init_component()

static int _stealtime_init_component ( int  cidx)
static

Definition at line 137 of file linux-stealtime.c.

138{
139 int retval = PAPI_OK;
140 (void)cidx;
141
142 FILE *fff;
143 char buffer[BUFSIZ],*result,string[BUFSIZ];
144 int i;
145
146 /* Make sure /proc/stat exists */
147 fff=fopen("/proc/stat","r");
148 if (fff==NULL) {
150 "Cannot open /proc/stat",PAPI_MAX_STR_LEN);
153 goto fn_fail;
154 }
155
156 num_events=0;
157 while(1) {
158 result=fgets(buffer,BUFSIZ,fff);
159 if (result==NULL) break;
160
161 /* /proc/stat line with cpu stats always starts with "cpu" */
162
163 if (!strncmp(buffer,"cpu",3)) {
164 num_events++;
165 }
166 else {
167 break;
168 }
169
170 }
171
172 fclose(fff);
173
174 if (num_events<1) {
176 "Cannot find enough CPU lines in /proc/stat",
180 goto fn_fail;
181 }
182
183 event_info=calloc(num_events,sizeof(struct counter_info));
184 if (event_info==NULL) {
187 goto fn_fail;
188 }
189
190
191 sysconf(_SC_CLK_TCK);
192 event_info[0].name=strdup("TOTAL");
193 event_info[0].description=strdup("Total amount of steal time");
194 event_info[0].units=strdup("us");
195
196 for(i=1;i<num_events;i++) {
197 sprintf(string,"CPU%d",i);
198 event_info[i].name=strdup(string);
199 sprintf(string,"Steal time for CPU %d",i);
200 event_info[i].description=strdup(string);
201 event_info[i].units=strdup("us");
202 }
203
204 // printf("Found %d CPUs\n",num_events-1);
205
209
210 fn_exit:
211 _papi_hwd[cidx]->cmp_info.disabled = retval;
212 return retval;
213 fn_fail:
214 goto fn_exit;
215}
volatile int result
int i
struct papi_vectors * _papi_hwd[]
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_ENOMEM
Definition: f90papi.h:16
FILE * fff[MAX_EVENTS]
static int _stealtime_shutdown_component(void)
static int num_events
papi_vector_t _stealtime_vector
static struct counter_info * event_info
int fclose(FILE *__stream)
static int cidx
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
char * description
Definition: linux-lustre.c:34
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ _stealtime_init_control_state()

static int _stealtime_init_control_state ( hwd_control_state_t ctl)
static

Definition at line 284 of file linux-stealtime.c.

285{
286
287 struct STEALTIME_control_state *control =
288 (struct STEALTIME_control_state *)ctl;
289
290 control->values=NULL;
291 control->which_counter=NULL;
292 control->num_events=0;
293
294 return PAPI_OK;
295}

◆ _stealtime_init_thread()

static int _stealtime_init_thread ( hwd_context_t ctx)
static

Definition at line 225 of file linux-stealtime.c.

226{
227 struct STEALTIME_context *context=(struct STEALTIME_context *)ctx;
228
229 context->start_count=calloc(num_events,sizeof(long long));
230 if (context->start_count==NULL) return PAPI_ENOMEM;
231
232 context->current_count=calloc(num_events,sizeof(long long));
233 if (context->current_count==NULL) return PAPI_ENOMEM;
234
235 context->value=calloc(num_events,sizeof(long long));
236 if (context->value==NULL) return PAPI_ENOMEM;
237
238 return PAPI_OK;
239}
long long * start_count
long long * current_count

◆ _stealtime_ntv_code_to_descr()

static int _stealtime_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)
static

Definition at line 519 of file linux-stealtime.c.

520{
521
522 int event=EventCode;
523
524 if (event >=0 && event < num_events) {
525 strncpy( name, event_info[event].description, len );
526 return PAPI_OK;
527 }
528
529 return PAPI_ENOEVNT;
530}
#define PAPI_ENOEVNT
Definition: f90papi.h:139
const char * name
Definition: rocs.c:225

◆ _stealtime_ntv_code_to_info()

static int _stealtime_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)
static

Definition at line 535 of file linux-stealtime.c.

536{
537
538 int index = EventCode;
539
540 if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
541
542 strncpy( info->symbol, event_info[index].name,sizeof(info->symbol));
543 info->symbol[sizeof(info->symbol)-1] = '\0';
544
545 strncpy( info->long_descr, event_info[index].description,sizeof(info->symbol));
546 info->long_descr[sizeof(info->symbol)-1] = '\0';
547
548 strncpy( info->units, event_info[index].units,sizeof(info->units));
549 info->units[sizeof(info->units)-1] = '\0';
550
551 return PAPI_OK;
552
553}
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963

◆ _stealtime_ntv_code_to_name()

static int _stealtime_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)
static

Definition at line 501 of file linux-stealtime.c.

502{
503
504 int event=EventCode;
505
506 if (event >=0 && event < num_events) {
507 strncpy( name, event_info[event].name, len );
508 return PAPI_OK;
509 }
510
511 return PAPI_ENOEVNT;
512}

◆ _stealtime_ntv_enum_events()

static int _stealtime_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)
static

Definition at line 562 of file linux-stealtime.c.

563{
564
565 if ( modifier == PAPI_ENUM_FIRST ) {
566 if (num_events==0) return PAPI_ENOEVNT;
567 *EventCode = 0;
568 return PAPI_OK;
569 }
570
571 if ( modifier == PAPI_ENUM_EVENTS ) {
572 int index;
573
574 index = *EventCode;
575
576 if ( (index+1) < num_events ) {
577 *EventCode = *EventCode + 1;
578 return PAPI_OK;
579 } else {
580 return PAPI_ENOEVNT;
581 }
582 }
583
584 return PAPI_EINVAL;
585}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_EINVAL
Definition: f90papi.h:115

◆ _stealtime_read()

static int _stealtime_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)
static

Definition at line 389 of file linux-stealtime.c.

391{
392 ( void ) flags;
393
394 struct STEALTIME_control_state *control;
395 struct STEALTIME_context *context;
396
397 int i;
398
399 control = (struct STEALTIME_control_state *)ctl;
400 context = (struct STEALTIME_context *)ctx;
401
402 read_stealtime( context, 0 );
403
404 for(i=0;i<control->num_events;i++) {
405 control->values[i]=
406 context->value[control->which_counter[i]];
407 }
408
409 *events = control->values;
410
411 return PAPI_OK;
412
413}
char events[MAX_EVENTS][BUFSIZ]
static int read_stealtime(struct STEALTIME_context *context, int starting)
Here is the call graph for this function:

◆ _stealtime_reset()

static int _stealtime_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)
static

Definition at line 422 of file linux-stealtime.c.

423{
424
425 /* re-initializes counter_start values to current */
426
427 _stealtime_start(ctx,ctrl);
428
429 return PAPI_OK;
430}
static int _stealtime_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
Here is the call graph for this function:

◆ _stealtime_set_domain()

static int _stealtime_set_domain ( hwd_control_state_t cntrl,
int  domain 
)
static

Definition at line 477 of file linux-stealtime.c.

478{
479 ( void ) cntrl;
480 int found = 0;
481 if ( PAPI_DOM_USER & domain ) {
482 found = 1;
483 }
484 if ( PAPI_DOM_KERNEL & domain ) {
485 found = 1;
486 }
487 if ( PAPI_DOM_OTHER & domain ) {
488 found = 1;
489 }
490 if ( !found )
491 return PAPI_EINVAL;
492
493 return PAPI_OK;
494}
#define PAPI_DOM_USER
Definition: f90papi.h:174
#define PAPI_DOM_OTHER
Definition: f90papi.h:21
#define PAPI_DOM_KERNEL
Definition: f90papi.h:254

◆ _stealtime_shutdown_component()

static int _stealtime_shutdown_component ( void  )
static

Definition at line 246 of file linux-stealtime.c.

247{
248 int i;
250 if (event_info!=NULL) {
251 for (i=0; i<num_events; i++){
252 free(event_info[i].name);
253 free(event_info[i].description);
254 free(event_info[i].units);
255 }
256 free(event_info);
257 }
258
259 return PAPI_OK;
260}
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
Here is the caller graph for this function:

◆ _stealtime_shutdown_thread()

static int _stealtime_shutdown_thread ( hwd_context_t ctx)
static

Definition at line 266 of file linux-stealtime.c.

267{
268
269 struct STEALTIME_context *context=(struct STEALTIME_context *)ctx;
270
271 if (context->start_count!=NULL) free(context->start_count);
272 if (context->current_count!=NULL) free(context->current_count);
273 if (context->value!=NULL) free(context->value);
274
275 return PAPI_OK;
276}

◆ _stealtime_start()

static int _stealtime_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 341 of file linux-stealtime.c.

342{
343
344 (void)ctl;
345
346 // struct STEALTIME_control_state *control;
347 struct STEALTIME_context *context;
348
349 //control = (struct STEALTIME_control_state *)ctl;
350 context = (struct STEALTIME_context *)ctx;
351
352 read_stealtime( context, 1 );
353
354 /* no need to update control, as we assume only one EventSet */
355 /* is active at once, so starting things at the context level */
356 /* is fine, since stealtime is system-wide */
357
358 return PAPI_OK;
359}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _stealtime_stop()

static int _stealtime_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 366 of file linux-stealtime.c.

367{
368
369 (void) ctl;
370
371 // struct STEALTIME_control_state *control;
372 struct STEALTIME_context *context;
373
374 //control = (struct STEALTIME_control_state *)ctl;
375 context = (struct STEALTIME_context *)ctx;
376
377 read_stealtime( context, 0 );
378
379 return PAPI_OK;
380
381}
Here is the call graph for this function:

◆ _stealtime_update_control_state()

static int _stealtime_update_control_state ( hwd_control_state_t ctl,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)
static

Definition at line 302 of file linux-stealtime.c.

306{
307
308 struct STEALTIME_control_state *control;
309
310 ( void ) ctx;
311 int i, index;
312
313 control= (struct STEALTIME_control_state *)ctl;
314
315 if (count!=control->num_events) {
316 // printf("Resizing %d to %d\n",control->num_events,count);
317 control->which_counter=realloc(control->which_counter,
318 count*sizeof(int));
319 control->values=realloc(control->values,
320 count*sizeof(long long));
321
322 }
323
324
325 for ( i = 0; i < count; i++ ) {
326 index = native[i].ni_event;
327 control->which_counter[i]=index;
328 native[i].ni_position = i;
329 }
330
331 control->num_events=count;
332
333 return PAPI_OK;
334}
static long count
static int native

◆ read_stealtime()

static int read_stealtime ( struct STEALTIME_context context,
int  starting 
)
static

Definition at line 74 of file linux-stealtime.c.

74 {
75
76 FILE *fff;
77 char buffer[BUFSIZ],*result;
78 int i,count;
79 struct statinfo our_stat;
80
81 int hz=sysconf(_SC_CLK_TCK);
82
83
84 fff=fopen("/proc/stat","r");
85 if (fff==NULL) {
86 return PAPI_ESYS;
87 }
88
89 for(i=0;i<num_events;i++) {
90 result=fgets(buffer,BUFSIZ,fff);
91 if (result==NULL) break;
92
93 count=sscanf(buffer,"%*s %lld %lld %lld %lld %lld %lld %lld %lld %lld",
94 &our_stat.user,
95 &our_stat.nice,
96 &our_stat.system,
97 &our_stat.idle,
98 &our_stat.iowait,
99 &our_stat.irq,
100 &our_stat.softirq,
101 &our_stat.steal,
102 &our_stat.guest);
103 if (count<=7) {
104 fclose(fff);
105 return PAPI_ESYS;
106 }
107
108 if (starting) {
109 context->start_count[i]=our_stat.steal;
110 }
111 context->current_count[i]=our_stat.steal;
112
113 /* convert to us */
114 context->value[i]=(context->current_count[i]-context->start_count[i])*
115 (1000000/hz);
116 }
117
118
119 fclose(fff);
120
121 return PAPI_OK;
122
123}
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _stealtime_vector

papi_vector_t _stealtime_vector

Definition at line 55 of file linux-stealtime.c.

◆ event_info

struct counter_info* event_info =NULL
static

Definition at line 52 of file linux-stealtime.c.

◆ num_events

int num_events = 0
static

Definition at line 50 of file linux-stealtime.c.