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

Author:
Vince Weaver vweaver1@eecs.utk.edu

Definition in file linux-stealtime.c.


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.

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

static int _stealtime_init_component ( int  cidx  )  [static]

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

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

static int _stealtime_init_control_state ( hwd_control_state_t ctl  )  [static]

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

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

static int _stealtime_init_thread ( hwd_context_t ctx  )  [static]

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

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

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

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

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

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.

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

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

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

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

static int _stealtime_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
) [static]

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

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

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.

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

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.

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

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.

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

static int _stealtime_shutdown_component ( void   )  [static]

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

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

static int _stealtime_shutdown_thread ( hwd_context_t ctx  )  [static]

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

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

static int _stealtime_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
) [static]

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

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

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.

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

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.

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

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

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

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

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 17 Nov 2016 for PAPI by  doxygen 1.6.1