PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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

int read_stealtime (struct STEALTIME_context *context, int starting)
 
int _stealtime_init_component (int cidx)
 
int _stealtime_init_thread (hwd_context_t *ctx)
 
int _stealtime_shutdown_component (void)
 
int _stealtime_shutdown_thread (hwd_context_t *ctx)
 
int _stealtime_init_control_state (hwd_control_state_t *ctl)
 
int _stealtime_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
int _stealtime_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _stealtime_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _stealtime_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
 
int _stealtime_reset (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int _stealtime_write (hwd_context_t *ctx, hwd_control_state_t *ctrl, long long *from)
 
int _stealtime_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
int _stealtime_set_domain (hwd_control_state_t *cntrl, int domain)
 
int _stealtime_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
int _stealtime_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
int _stealtime_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
 
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

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

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

436 {
437  ( void ) ctx;
438  ( void ) code;
439  ( void ) option;
440 
441  return PAPI_OK;
442 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _stealtime_init_component ( int  cidx)

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

136 {
137 
138  (void)cidx;
139 
140  FILE *fff;
141  char buffer[BUFSIZ],*result,string[BUFSIZ];
142  int i;
143 
144  /* Make sure /proc/stat exists */
145  fff=fopen("/proc/stat","r");
146  if (fff==NULL) {
148  "Cannot open /proc/stat",PAPI_MAX_STR_LEN);
149  return PAPI_ESYS;
150  }
151 
152  num_events=0;
153  while(1) {
154  result=fgets(buffer,BUFSIZ,fff);
155  if (result==NULL) break;
156 
157  /* /proc/stat line with cpu stats always starts with "cpu" */
158 
159  if (!strncmp(buffer,"cpu",3)) {
160  num_events++;
161  }
162  else {
163  break;
164  }
165 
166  }
167 
168  fclose(fff);
169 
170  if (num_events<1) {
172  "Cannot find enough CPU lines in /proc/stat",
174  return PAPI_ESYS;
175  }
176 
177  event_info=calloc(num_events,sizeof(struct counter_info));
178  if (event_info==NULL) {
179  return PAPI_ENOMEM;
180  }
181 
182 
183  sysconf(_SC_CLK_TCK);
184  event_info[0].name=strdup("TOTAL");
185  event_info[0].description=strdup("Total amount of steal time");
186  event_info[0].units=strdup("us");
187 
188  for(i=1;i<num_events;i++) {
189  sprintf(string,"CPU%d",i);
190  event_info[i].name=strdup(string);
191  sprintf(string,"Steal time for CPU %d",i);
192  event_info[i].description=strdup(string);
193  event_info[i].units=strdup("us");
194  }
195 
196  // printf("Found %d CPUs\n",num_events-1);
197 
201 
202  return PAPI_OK;
203 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
#define PAPI_ENOMEM
Definition: fpapi.h:107
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
fclose(thread_wqfd)
void
Definition: iozone.c:18627
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
FILE * fff[MAX_EVENTS]
static struct counter_info * event_info
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:632
int i
Definition: fileop.c:140
static int cidx
Definition: event_info.c:40
#define PAPI_ESYS
Definition: fpapi.h:108
char * buffer
Definition: iozone.c:1366
papi_vector_t _stealtime_vector

Here is the call graph for this function:

int _stealtime_init_control_state ( hwd_control_state_t ctl)

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

264 {
265 
266  struct STEALTIME_control_state *control =
267  (struct STEALTIME_control_state *)ctl;
268 
269  control->values=NULL;
270  control->which_counter=NULL;
271  control->num_events=0;
272 
273  return PAPI_OK;
274 }
return PAPI_OK
Definition: linux-nvml.c:458
int _stealtime_init_thread ( hwd_context_t ctx)

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

214 {
215  struct STEALTIME_context *context=(struct STEALTIME_context *)ctx;
216 
217  context->start_count=calloc(num_events,sizeof(long long));
218  if (context->start_count==NULL) return PAPI_ENOMEM;
219 
220  context->current_count=calloc(num_events,sizeof(long long));
221  if (context->current_count==NULL) return PAPI_ENOMEM;
222 
223  context->value=calloc(num_events,sizeof(long long));
224  if (context->value==NULL) return PAPI_ENOMEM;
225 
226  return PAPI_OK;
227 }
#define PAPI_ENOMEM
Definition: fpapi.h:107
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
long long * current_count
long long * start_count
int _stealtime_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

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

499 {
500 
501  int event=EventCode;
502 
503  if (event >=0 && event < num_events) {
504  strncpy( name, event_info[event].description, len );
505  return PAPI_OK;
506  }
507 
508  return PAPI_ENOEVNT;
509 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int num_events
device[deviceId] domain[domainId] event
Definition: linux-cuda.c:306
return PAPI_OK
Definition: linux-nvml.c:458
static struct counter_info * event_info
char * name
Definition: iozone.c:23648
int _stealtime_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

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

515 {
516 
517  int index = EventCode;
518 
519  if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
520 
521  strncpy( info->symbol, event_info[index].name,
522  sizeof(info->symbol));
523 
524  strncpy( info->long_descr, event_info[index].description,
525  sizeof(info->symbol));
526 
527  strncpy( info->units, event_info[index].units,
528  sizeof(info->units));
529 
530  return PAPI_OK;
531 
532 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int num_events
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
return PAPI_OK
Definition: linux-nvml.c:458
static struct counter_info * event_info
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:970
int _stealtime_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

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

481 {
482 
483  int event=EventCode;
484 
485  if (event >=0 && event < num_events) {
486  strncpy( name, event_info[event].name, len );
487  return PAPI_OK;
488  }
489 
490  return PAPI_ENOEVNT;
491 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int num_events
device[deviceId] domain[domainId] event
Definition: linux-cuda.c:306
return PAPI_OK
Definition: linux-nvml.c:458
static struct counter_info * event_info
char * name
Definition: iozone.c:23648
int _stealtime_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)

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

542 {
543 
544  if ( modifier == PAPI_ENUM_FIRST ) {
545  if (num_events==0) return PAPI_ENOEVNT;
546  *EventCode = 0;
547  return PAPI_OK;
548  }
549 
550  if ( modifier == PAPI_ENUM_EVENTS ) {
551  int index;
552 
553  index = *EventCode;
554 
555  if ( (index+1) < num_events ) {
556  *EventCode = *EventCode + 1;
557  return PAPI_OK;
558  } else {
559  return PAPI_ENOEVNT;
560  }
561  }
562 
563  return PAPI_EINVAL;
564 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
return PAPI_EINVAL
Definition: linux-nvml.c:408
int _stealtime_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)

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

370 {
371  ( void ) flags;
372 
373  struct STEALTIME_control_state *control;
374  struct STEALTIME_context *context;
375 
376  int i;
377 
378  control = (struct STEALTIME_control_state *)ctl;
379  context = (struct STEALTIME_context *)ctx;
380 
381  read_stealtime( context, 0 );
382 
383  for(i=0;i<control->num_events;i++) {
384  control->values[i]=
385  context->value[control->which_counter[i]];
386  }
387 
388  *events = control->values;
389 
390  return PAPI_OK;
391 
392 }
long long flags
Definition: iozone.c:12330
int read_stealtime(struct STEALTIME_context *context, int starting)
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int i
Definition: fileop.c:140
char events[MAX_EVENTS][BUFSIZ]

Here is the call graph for this function:

int _stealtime_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

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

402 {
403 
404  /* re-initializes counter_start values to current */
405 
406  _stealtime_start(ctx,ctrl);
407 
408  return PAPI_OK;
409 }
int _stealtime_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
return PAPI_OK
Definition: linux-nvml.c:458

Here is the call graph for this function:

int _stealtime_set_domain ( hwd_control_state_t cntrl,
int  domain 
)

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

457 {
458  ( void ) cntrl;
459  int found = 0;
460  if ( PAPI_DOM_USER & domain ) {
461  found = 1;
462  }
463  if ( PAPI_DOM_KERNEL & domain ) {
464  found = 1;
465  }
466  if ( PAPI_DOM_OTHER & domain ) {
467  found = 1;
468  }
469  if ( !found )
470  return PAPI_EINVAL;
471 
472  return PAPI_OK;
473 }
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_DOM_OTHER
Definition: fpapi.h:23
#define PAPI_DOM_KERNEL
Definition: fpapi.h:22
void
Definition: iozone.c:18627
return PAPI_EINVAL
Definition: linux-nvml.c:408
long long found
Definition: libasync.c:735
#define PAPI_DOM_USER
Definition: fpapi.h:21
int _stealtime_shutdown_component ( void  )

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

235 {
236 
237  if (event_info!=NULL) free(event_info);
238 
239  return PAPI_OK;
240 }
return PAPI_OK
Definition: linux-nvml.c:458
static struct counter_info * event_info
free(dummyfile[xx])

Here is the call graph for this function:

int _stealtime_shutdown_thread ( hwd_context_t ctx)

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

247 {
248 
249  struct STEALTIME_context *context=(struct STEALTIME_context *)ctx;
250 
251  if (context->start_count!=NULL) free(context->start_count);
252  if (context->current_count!=NULL) free(context->current_count);
253 
254  return PAPI_OK;
255 }
return PAPI_OK
Definition: linux-nvml.c:458
free(dummyfile[xx])
long long * current_count
long long * start_count

Here is the call graph for this function:

int _stealtime_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

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

321 {
322 
323  (void)ctl;
324 
325  // struct STEALTIME_control_state *control;
326  struct STEALTIME_context *context;
327 
328  //control = (struct STEALTIME_control_state *)ctl;
329  context = (struct STEALTIME_context *)ctx;
330 
331  read_stealtime( context, 1 );
332 
333  /* no need to update control, as we assume only one EventSet */
334  /* is active at once, so starting things at the context level */
335  /* is fine, since stealtime is system-wide */
336 
337  return PAPI_OK;
338 }
int read_stealtime(struct STEALTIME_context *context, int starting)
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627

Here is the call graph for this function:

Here is the caller graph for this function:

int _stealtime_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

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

346 {
347 
348  (void) ctl;
349 
350  // struct STEALTIME_control_state *control;
351  struct STEALTIME_context *context;
352 
353  //control = (struct STEALTIME_control_state *)ctl;
354  context = (struct STEALTIME_context *)ctx;
355 
356  read_stealtime( context, 0 );
357 
358  return PAPI_OK;
359 
360 }
int read_stealtime(struct STEALTIME_context *context, int starting)
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627

Here is the call graph for this function:

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

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

285 {
286 
287  struct STEALTIME_control_state *control;
288 
289  ( void ) ctx;
290  int i, index;
291 
292  control= (struct STEALTIME_control_state *)ctl;
293 
294  if (count!=control->num_events) {
295  // printf("Resizing %d to %d\n",control->num_events,count);
296  control->which_counter=realloc(control->which_counter,
297  count*sizeof(int));
298  control->values=realloc(control->values,
299  count*sizeof(long long));
300 
301  }
302 
303 
304  for ( i = 0; i < count; i++ ) {
305  index = native[i].ni_event;
306  control->which_counter[i]=index;
307  native[i].ni_position = i;
308  }
309 
310  control->num_events=count;
311 
312  return PAPI_OK;
313 }
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
void
Definition: iozone.c:18627
int i
Definition: fileop.c:140
int _stealtime_write ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long long from 
)

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

417 {
418  ( void ) ctx;
419  ( void ) ctrl;
420  ( void ) from;
421 
422  return PAPI_OK;
423 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int read_stealtime ( struct STEALTIME_context context,
int  starting 
)

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

73  {
74 
75  FILE *fff;
76  char buffer[BUFSIZ],*result;
77  int i,count;
78  struct statinfo our_stat;
79 
80  int hz=sysconf(_SC_CLK_TCK);
81 
82 
83  fff=fopen("/proc/stat","r");
84  if (fff==NULL) {
85  return PAPI_ESYS;
86  }
87 
88  for(i=0;i<num_events;i++) {
89  result=fgets(buffer,BUFSIZ,fff);
90  if (result==NULL) break;
91 
92  count=sscanf(buffer,"%*s %lld %lld %lld %lld %lld %lld %lld %lld %lld",
93  &our_stat.user,
94  &our_stat.nice,
95  &our_stat.system,
96  &our_stat.idle,
97  &our_stat.iowait,
98  &our_stat.irq,
99  &our_stat.softirq,
100  &our_stat.steal,
101  &our_stat.guest);
102  if (count<=7) {
103  fclose(fff);
104  return PAPI_ESYS;
105  }
106 
107  if (starting) {
108  context->start_count[i]=our_stat.steal;
109  }
110  context->current_count[i]=our_stat.steal;
111 
112  /* convert to us */
113  context->value[i]=(context->current_count[i]-context->start_count[i])*
114  (1000000/hz);
115  }
116 
117 
118  fclose(fff);
119 
120  return PAPI_OK;
121 
122 }
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
fclose(thread_wqfd)
FILE * fff[MAX_EVENTS]
int i
Definition: fileop.c:140
long long * current_count
#define PAPI_ESYS
Definition: fpapi.h:108
char * buffer
Definition: iozone.c:1366
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)
long long * start_count

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

papi_vector_t _stealtime_vector

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

struct counter_info* event_info =NULL
static

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

int num_events = 0
static

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