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

Author:
Vince Weaver vweaver1@eecs.utk.edu

Definition in file linux-stealtime.c.


Function Documentation

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

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

00445 {
00446     ( void ) ctx;
00447     ( void ) code;
00448     ( void ) option;
00449 
00450     return PAPI_OK;
00451 }

int _stealtime_init_component ( int  cidx  ) 

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

00136 {
00137 
00138   (void)cidx;
00139 
00140     FILE *fff;
00141     char buffer[BUFSIZ],*result,string[BUFSIZ];
00142     int i;
00143 
00144     /* Make sure /proc/stat exists */
00145     fff=fopen("/proc/stat","r");
00146     if (fff==NULL) {
00147        strncpy(_stealtime_vector.cmp_info.disabled_reason,
00148            "Cannot open /proc/stat",PAPI_MAX_STR_LEN);
00149        return PAPI_ESYS;
00150     }
00151 
00152     num_events=0;
00153     while(1) {
00154       result=fgets(buffer,BUFSIZ,fff);
00155       if (result==NULL) break;
00156 
00157       /* /proc/stat line with cpu stats always starts with "cpu" */
00158 
00159       if (!strncmp(buffer,"cpu",3)) {
00160          num_events++;
00161       }
00162       else {
00163         break;
00164       }
00165 
00166     }
00167 
00168     fclose(fff);
00169 
00170     if (num_events<1) {
00171        strncpy(_stealtime_vector.cmp_info.disabled_reason,
00172            "Cannot find enough CPU lines in /proc/stat",
00173            PAPI_MAX_STR_LEN);
00174        return PAPI_ESYS;
00175     }
00176 
00177     event_info=calloc(num_events,sizeof(struct counter_info));
00178     if (event_info==NULL) {
00179        return PAPI_ENOMEM;
00180     }
00181 
00182     
00183     sysconf(_SC_CLK_TCK);
00184     event_info[0].name=strdup("TOTAL");
00185     event_info[0].description=strdup("Total amount of steal time");
00186     event_info[0].units=strdup("us");
00187 
00188     for(i=1;i<num_events;i++) {
00189        sprintf(string,"CPU%d",i);
00190        event_info[i].name=strdup(string);
00191        sprintf(string,"Steal time for CPU %d",i);
00192        event_info[i].description=strdup(string);
00193        event_info[i].units=strdup("us");
00194         }
00195 
00196     //  printf("Found %d CPUs\n",num_events-1);
00197 
00198     _stealtime_vector.cmp_info.num_native_events=num_events;
00199     _stealtime_vector.cmp_info.num_cntrs=num_events;
00200     _stealtime_vector.cmp_info.num_mpx_cntrs=num_events;
00201 
00202     return PAPI_OK;
00203 }

int _stealtime_init_control_state ( hwd_control_state_t ctl  ) 

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

00273 {
00274 
00275     struct STEALTIME_control_state *control = 
00276       (struct STEALTIME_control_state *)ctl;
00277 
00278     control->values=NULL;
00279     control->which_counter=NULL;
00280     control->num_events=0;
00281 
00282     return PAPI_OK;
00283 }

int _stealtime_init_thread ( hwd_context_t ctx  ) 

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

00214 {
00215   struct STEALTIME_context *context=(struct STEALTIME_context *)ctx;
00216 
00217   context->start_count=calloc(num_events,sizeof(long long));
00218   if (context->start_count==NULL) return PAPI_ENOMEM;
00219 
00220   context->current_count=calloc(num_events,sizeof(long long));
00221   if (context->current_count==NULL) return PAPI_ENOMEM;
00222 
00223   context->value=calloc(num_events,sizeof(long long));
00224   if (context->value==NULL) return PAPI_ENOMEM;
00225 
00226   return PAPI_OK;
00227 }

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

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

00508 {
00509 
00510   int event=EventCode;
00511 
00512   if (event >=0 && event < num_events) {
00513     strncpy( name, event_info[event].description, len );
00514     return PAPI_OK;
00515   }
00516 
00517   return PAPI_ENOEVNT;
00518 }

int _stealtime_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

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

00524 {
00525 
00526   int index = EventCode;
00527 
00528   if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
00529 
00530   strncpy( info->symbol, event_info[index].name,
00531            sizeof(info->symbol));
00532 
00533   strncpy( info->long_descr, event_info[index].description,
00534            sizeof(info->symbol));
00535 
00536   strncpy( info->units, event_info[index].units,
00537            sizeof(info->units));
00538 
00539   return PAPI_OK;
00540 
00541 }

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

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

00490 {
00491 
00492   int event=EventCode;
00493 
00494   if (event >=0 && event < num_events) {
00495      strncpy( name, event_info[event].name, len );
00496      return PAPI_OK;
00497   }
00498 
00499   return PAPI_ENOEVNT;
00500 }

int _stealtime_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)

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

00551 {
00552 
00553      if ( modifier == PAPI_ENUM_FIRST ) {
00554     if (num_events==0) return PAPI_ENOEVNT;
00555     *EventCode = 0;
00556     return PAPI_OK;
00557      }
00558 
00559      if ( modifier == PAPI_ENUM_EVENTS ) {
00560         int index;
00561 
00562         index = *EventCode;
00563 
00564     if ( (index+1) < num_events ) {
00565        *EventCode = *EventCode + 1;
00566        return PAPI_OK;
00567     } else {
00568        return PAPI_ENOEVNT;
00569     }
00570      } 
00571         
00572      return PAPI_EINVAL;
00573 }

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

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

00379 {
00380     ( void ) flags;
00381 
00382     struct STEALTIME_control_state *control;
00383     struct STEALTIME_context *context;
00384 
00385     int i;
00386     
00387     control = (struct STEALTIME_control_state *)ctl;
00388     context = (struct STEALTIME_context *)ctx;
00389 
00390     read_stealtime( context, 0 );
00391 
00392     for(i=0;i<control->num_events;i++) {
00393        control->values[i]=
00394                  context->value[control->which_counter[i]];
00395     }
00396 
00397     *events = control->values;
00398 
00399     return PAPI_OK;
00400 
00401 }

Here is the call graph for this function:

int _stealtime_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

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

00411 {
00412 
00413   /* re-initializes counter_start values to current */
00414 
00415   _stealtime_start(ctx,ctrl);
00416 
00417   return PAPI_OK;
00418 }

Here is the call graph for this function:

int _stealtime_set_domain ( hwd_control_state_t cntrl,
int  domain 
)

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

00466 {
00467     ( void ) cntrl;
00468     int found = 0;
00469     if ( PAPI_DOM_USER & domain ) {
00470         found = 1;
00471     }
00472     if ( PAPI_DOM_KERNEL & domain ) {
00473         found = 1;
00474     }
00475     if ( PAPI_DOM_OTHER & domain ) {
00476         found = 1;
00477     }
00478     if ( !found )
00479         return PAPI_EINVAL;
00480 
00481     return PAPI_OK;
00482 }

int _stealtime_shutdown_component ( void   ) 

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

00235 {
00236        int i;
00237        int num_events = _stealtime_vector.cmp_info.num_native_events;
00238        if (event_info!=NULL) {
00239                for (i=0; i<num_events; i++){
00240                        free(event_info[i].name);
00241                        free(event_info[i].description);
00242                        free(event_info[i].units);
00243                }
00244                free(event_info);
00245        }
00246 
00247    return PAPI_OK;
00248 }

int _stealtime_shutdown_thread ( hwd_context_t ctx  ) 

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

00255 {
00256 
00257   struct STEALTIME_context *context=(struct STEALTIME_context *)ctx;
00258 
00259   if (context->start_count!=NULL) free(context->start_count);
00260   if (context->current_count!=NULL) free(context->current_count);
00261   if (context->value!=NULL) free(context->value);
00262 
00263   return PAPI_OK;
00264 }

int _stealtime_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

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

00330 {
00331 
00332   (void)ctl;
00333 
00334   //    struct STEALTIME_control_state *control;
00335     struct STEALTIME_context *context;
00336     
00337     //control = (struct STEALTIME_control_state *)ctl;
00338     context = (struct STEALTIME_context *)ctx;
00339 
00340     read_stealtime( context, 1 );
00341 
00342     /* no need to update control, as we assume only one EventSet  */
00343     /* is active at once, so starting things at the context level */
00344     /* is fine, since stealtime is system-wide                    */
00345 
00346     return PAPI_OK;
00347 }

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 354 of file linux-stealtime.c.

00355 {
00356 
00357   (void) ctl;
00358 
00359   //    struct STEALTIME_control_state *control;
00360     struct STEALTIME_context *context;
00361     
00362     //control = (struct STEALTIME_control_state *)ctl;
00363     context = (struct STEALTIME_context *)ctx;
00364 
00365     read_stealtime( context, 0 );
00366 
00367     return PAPI_OK;
00368 
00369 }

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 290 of file linux-stealtime.c.

00294 {
00295 
00296     struct STEALTIME_control_state *control;
00297 
00298     ( void ) ctx;
00299     int i, index;
00300 
00301     control= (struct STEALTIME_control_state *)ctl;
00302 
00303     if (count!=control->num_events) {
00304       //       printf("Resizing %d to %d\n",control->num_events,count);
00305        control->which_counter=realloc(control->which_counter,
00306                       count*sizeof(int));
00307        control->values=realloc(control->values,
00308                    count*sizeof(long long));
00309        
00310     }
00311 
00312 
00313     for ( i = 0; i < count; i++ ) {
00314        index = native[i].ni_event;
00315        control->which_counter[i]=index;
00316        native[i].ni_position = i;
00317     }
00318 
00319     control->num_events=count;
00320 
00321     return PAPI_OK;
00322 }

int _stealtime_write ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long long *  from 
)

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

00426 {
00427     ( void ) ctx;
00428     ( void ) ctrl;
00429     ( void ) from;
00430 
00431     return PAPI_OK;
00432 }

int read_stealtime ( struct STEALTIME_context context,
int  starting 
)

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

00073                                                                      {
00074 
00075   FILE *fff;
00076   char buffer[BUFSIZ],*result;
00077   int i,count;
00078   struct statinfo our_stat;
00079 
00080   int hz=sysconf(_SC_CLK_TCK);
00081 
00082 
00083   fff=fopen("/proc/stat","r");
00084   if (fff==NULL) {
00085      return PAPI_ESYS; 
00086   }
00087 
00088   for(i=0;i<num_events;i++) {
00089     result=fgets(buffer,BUFSIZ,fff);
00090     if (result==NULL) break;
00091 
00092     count=sscanf(buffer,"%*s %lld %lld %lld %lld %lld %lld %lld %lld %lld",
00093          &our_stat.user,
00094          &our_stat.nice,
00095          &our_stat.system,
00096          &our_stat.idle,
00097          &our_stat.iowait,
00098          &our_stat.irq,
00099          &our_stat.softirq,
00100          &our_stat.steal,
00101          &our_stat.guest);
00102     if (count<=7) {
00103        fclose(fff);
00104        return PAPI_ESYS;
00105     }
00106 
00107     if (starting) {
00108        context->start_count[i]=our_stat.steal;
00109     }
00110     context->current_count[i]=our_stat.steal;
00111 
00112     /* convert to us */
00113     context->value[i]=(context->current_count[i]-context->start_count[i])*
00114       (1000000/hz);
00115   }
00116   
00117 
00118   fclose(fff);
00119 
00120   return PAPI_OK;
00121 
00122 }

Here is the caller graph for this function:


Variable Documentation

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.


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1