PAPI  5.6.0.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

static int read_stealtime (struct STEALTIME_context *context, int starting)
 
static int _stealtime_init_component (int cidx)
 
static int _stealtime_init_thread (hwd_context_t *ctx)
 
static int _stealtime_shutdown_component (void)
 
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

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

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

446 {
447  ( void ) ctx;
448  ( void ) code;
449  ( void ) option;
450 
451  return PAPI_OK;
452 }
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627
static int _stealtime_init_component ( int  cidx)
static

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

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

Here is the call graph for this function:

static int _stealtime_init_control_state ( hwd_control_state_t ctl)
static

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

274 {
275 
276  struct STEALTIME_control_state *control =
277  (struct STEALTIME_control_state *)ctl;
278 
279  control->values=NULL;
280  control->which_counter=NULL;
281  control->num_events=0;
282 
283  return PAPI_OK;
284 }
return PAPI_OK
Definition: linux-nvml.c:497
static int _stealtime_init_thread ( hwd_context_t ctx)
static

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

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

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

509 {
510 
511  int event=EventCode;
512 
513  if (event >=0 && event < num_events) {
514  strncpy( name, event_info[event].description, len );
515  return PAPI_OK;
516  }
517 
518  return PAPI_ENOEVNT;
519 }
#define PAPI_ENOEVNT
Definition: papi.h:260
return PAPI_OK
Definition: linux-nvml.c:497
static struct counter_info * event_info
static int num_events
char * name
Definition: iozone.c:23648
static int _stealtime_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)
static

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

525 {
526 
527  int index = EventCode;
528 
529  if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
530 
531  strncpy( info->symbol, event_info[index].name,sizeof(info->symbol));
532  info->symbol[sizeof(info->symbol)-1] = '\0';
533 
534  strncpy( info->long_descr, event_info[index].description,sizeof(info->symbol));
535  info->long_descr[sizeof(info->symbol)-1] = '\0';
536 
537  strncpy( info->units, event_info[index].units,sizeof(info->units));
538  info->units[sizeof(info->units)-1] = '\0';
539 
540  return PAPI_OK;
541 
542 }
#define PAPI_ENOEVNT
Definition: papi.h:260
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:969
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:966
return PAPI_OK
Definition: linux-nvml.c:497
static struct counter_info * event_info
static int num_events
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:975
static int _stealtime_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)
static

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

491 {
492 
493  int event=EventCode;
494 
495  if (event >=0 && event < num_events) {
496  strncpy( name, event_info[event].name, len );
497  return PAPI_OK;
498  }
499 
500  return PAPI_ENOEVNT;
501 }
#define PAPI_ENOEVNT
Definition: papi.h:260
return PAPI_OK
Definition: linux-nvml.c:497
static struct counter_info * event_info
static int num_events
char * name
Definition: iozone.c:23648
static int _stealtime_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)
static

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

552 {
553 
554  if ( modifier == PAPI_ENUM_FIRST ) {
555  if (num_events==0) return PAPI_ENOEVNT;
556  *EventCode = 0;
557  return PAPI_OK;
558  }
559 
560  if ( modifier == PAPI_ENUM_EVENTS ) {
561  int index;
562 
563  index = *EventCode;
564 
565  if ( (index+1) < num_events ) {
566  *EventCode = *EventCode + 1;
567  return PAPI_OK;
568  } else {
569  return PAPI_ENOEVNT;
570  }
571  }
572 
573  return PAPI_EINVAL;
574 }
#define PAPI_ENOEVNT
Definition: papi.h:260
return PAPI_OK
Definition: linux-nvml.c:497
return PAPI_EINVAL
Definition: linux-nvml.c:436
static int num_events
static int _stealtime_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)
static

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

380 {
381  ( void ) flags;
382 
383  struct STEALTIME_control_state *control;
384  struct STEALTIME_context *context;
385 
386  int i;
387 
388  control = (struct STEALTIME_control_state *)ctl;
389  context = (struct STEALTIME_context *)ctx;
390 
391  read_stealtime( context, 0 );
392 
393  for(i=0;i<control->num_events;i++) {
394  control->values[i]=
395  context->value[control->which_counter[i]];
396  }
397 
398  *events = control->values;
399 
400  return PAPI_OK;
401 
402 }
long long flags
Definition: iozone.c:12330
static int read_stealtime(struct STEALTIME_context *context, int starting)
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627
char events[MAX_EVENTS][BUFSIZ]
int i
Definition: fileop.c:140

Here is the call graph for this function:

static int _stealtime_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)
static

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

412 {
413 
414  /* re-initializes counter_start values to current */
415 
416  _stealtime_start(ctx,ctrl);
417 
418  return PAPI_OK;
419 }
return PAPI_OK
Definition: linux-nvml.c:497
static int _stealtime_start(hwd_context_t *ctx, hwd_control_state_t *ctl)

Here is the call graph for this function:

static int _stealtime_set_domain ( hwd_control_state_t cntrl,
int  domain 
)
static

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

467 {
468  ( void ) cntrl;
469  int found = 0;
470  if ( PAPI_DOM_USER & domain ) {
471  found = 1;
472  }
473  if ( PAPI_DOM_KERNEL & domain ) {
474  found = 1;
475  }
476  if ( PAPI_DOM_OTHER & domain ) {
477  found = 1;
478  }
479  if ( !found )
480  return PAPI_EINVAL;
481 
482  return PAPI_OK;
483 }
#define PAPI_DOM_KERNEL
Definition: papi.h:300
return PAPI_OK
Definition: linux-nvml.c:497
#define PAPI_DOM_USER
Definition: papi.h:298
void
Definition: iozone.c:18627
return PAPI_EINVAL
Definition: linux-nvml.c:436
long long found
Definition: libasync.c:735
#define PAPI_DOM_OTHER
Definition: papi.h:301
static int _stealtime_shutdown_component ( void  )
static

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

236 {
237  int i;
239  if (event_info!=NULL) {
240  for (i=0; i<num_events; i++){
241  free(event_info[i].name);
242  free(event_info[i].description);
243  free(event_info[i].units);
244  }
245  free(event_info);
246  }
247 
248  return PAPI_OK;
249 }
return PAPI_OK
Definition: linux-nvml.c:497
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
static struct counter_info * event_info
int i
Definition: fileop.c:140
free(dummyfile[xx])
static int num_events
char * name
Definition: iozone.c:23648
papi_vector_t _stealtime_vector

Here is the call graph for this function:

static int _stealtime_shutdown_thread ( hwd_context_t ctx)
static

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

256 {
257 
258  struct STEALTIME_context *context=(struct STEALTIME_context *)ctx;
259 
260  if (context->start_count!=NULL) free(context->start_count);
261  if (context->current_count!=NULL) free(context->current_count);
262  if (context->value!=NULL) free(context->value);
263 
264  return PAPI_OK;
265 }
return PAPI_OK
Definition: linux-nvml.c:497
free(dummyfile[xx])
long long * current_count
long long * start_count

Here is the call graph for this function:

static int _stealtime_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

331 {
332 
333  (void)ctl;
334 
335  // struct STEALTIME_control_state *control;
336  struct STEALTIME_context *context;
337 
338  //control = (struct STEALTIME_control_state *)ctl;
339  context = (struct STEALTIME_context *)ctx;
340 
341  read_stealtime( context, 1 );
342 
343  /* no need to update control, as we assume only one EventSet */
344  /* is active at once, so starting things at the context level */
345  /* is fine, since stealtime is system-wide */
346 
347  return PAPI_OK;
348 }
static int read_stealtime(struct STEALTIME_context *context, int starting)
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627

Here is the call graph for this function:

Here is the caller graph for this function:

static int _stealtime_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

356 {
357 
358  (void) ctl;
359 
360  // struct STEALTIME_control_state *control;
361  struct STEALTIME_context *context;
362 
363  //control = (struct STEALTIME_control_state *)ctl;
364  context = (struct STEALTIME_context *)ctx;
365 
366  read_stealtime( context, 0 );
367 
368  return PAPI_OK;
369 
370 }
static int read_stealtime(struct STEALTIME_context *context, int starting)
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627

Here is the call graph for this function:

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

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

295 {
296 
297  struct STEALTIME_control_state *control;
298 
299  ( void ) ctx;
300  int i, index;
301 
302  control= (struct STEALTIME_control_state *)ctl;
303 
304  if (count!=control->num_events) {
305  // printf("Resizing %d to %d\n",control->num_events,count);
306  control->which_counter=realloc(control->which_counter,
307  count*sizeof(int));
308  control->values=realloc(control->values,
309  count*sizeof(long long));
310 
311  }
312 
313 
314  for ( i = 0; i < count; i++ ) {
315  index = native[i].ni_event;
316  control->which_counter[i]=index;
317  native[i].ni_position = i;
318  }
319 
320  control->num_events=count;
321 
322  return PAPI_OK;
323 }
return PAPI_OK
Definition: linux-nvml.c:497
int count
Definition: iozone.c:22422
void
Definition: iozone.c:18627
int i
Definition: fileop.c:140
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 }
return PAPI_OK
Definition: linux-nvml.c:497
int count
Definition: iozone.c:22422
fclose(thread_wqfd)
FILE * fff[MAX_EVENTS]
int i
Definition: fileop.c:140
#define PAPI_ESYS
Definition: papi.h:255
long long * current_count
static int num_events
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.