PAPI  5.0.1.0
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 435 of file linux-stealtime.c.

{
    ( void ) ctx;
    ( void ) code;
    ( void ) option;

    return PAPI_OK;
}
int _stealtime_init_component ( int  cidx)

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

{

  (void)cidx;

    FILE *fff;
    char buffer[BUFSIZ],*result,string[BUFSIZ];
    int i;

    /* Make sure /proc/stat exists */
    fff=fopen("/proc/stat","r");
    if (fff==NULL) {
       strncpy(_stealtime_vector.cmp_info.disabled_reason,
           "Cannot open /proc/stat",PAPI_MAX_STR_LEN);
       return PAPI_ESYS;
    }

    num_events=0;
    while(1) {
      result=fgets(buffer,BUFSIZ,fff);
      if (result==NULL) break;

      /* /proc/stat line with cpu stats always starts with "cpu" */

      if (!strncmp(buffer,"cpu",3)) {
         num_events++;
      }
      else {
        break;
      }

    }

    fclose(fff);

    if (num_events<1) {
       strncpy(_stealtime_vector.cmp_info.disabled_reason,
           "Cannot find enough CPU lines in /proc/stat",
           PAPI_MAX_STR_LEN);
       return PAPI_ESYS;
    }

    event_info=calloc(num_events,sizeof(struct counter_info));
    if (event_info==NULL) {
       return PAPI_ENOMEM;
    }

    
    sysconf(_SC_CLK_TCK);
    event_info[0].name=strdup("TOTAL");
    event_info[0].description=strdup("Total amount of steal time");
    event_info[0].units=strdup("us");

    for(i=1;i<num_events;i++) {
       sprintf(string,"CPU%d",i);
       event_info[i].name=strdup(string);
       sprintf(string,"Steal time for CPU %d",i);
       event_info[i].description=strdup(string);
       event_info[i].units=strdup("us");
        }

    //  printf("Found %d CPUs\n",num_events-1);

    _stealtime_vector.cmp_info.num_native_events=num_events;
    _stealtime_vector.cmp_info.num_cntrs=num_events;
    _stealtime_vector.cmp_info.num_mpx_cntrs=num_events;

    return PAPI_OK;
}

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

{

    struct STEALTIME_control_state *control = 
      (struct STEALTIME_control_state *)ctl;

    control->values=NULL;
    control->which_counter=NULL;
    control->num_events=0;

    return PAPI_OK;
}

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

{
  struct STEALTIME_context *context=(struct STEALTIME_context *)ctx;

  context->start_count=calloc(num_events,sizeof(long long));
  if (context->start_count==NULL) return PAPI_ENOMEM;

  context->current_count=calloc(num_events,sizeof(long long));
  if (context->current_count==NULL) return PAPI_ENOMEM;

  context->value=calloc(num_events,sizeof(long long));
  if (context->value==NULL) return PAPI_ENOMEM;

  return PAPI_OK;
}
int _stealtime_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

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

{

  int event=EventCode;

  if (event >=0 && event < num_events) {
    strncpy( name, event_info[event].description, len );
    return PAPI_OK;
  }

  return PAPI_ENOEVNT;
}
int _stealtime_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

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

{

  int index = EventCode;

  if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;

  strncpy( info->symbol, event_info[index].name,
           sizeof(info->symbol));

  strncpy( info->long_descr, event_info[index].description,
           sizeof(info->symbol));

  strncpy( info->units, event_info[index].units,
           sizeof(info->units));

  return PAPI_OK;

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

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

{

  int event=EventCode;

  if (event >=0 && event < num_events) {
     strncpy( name, event_info[event].name, len );
     return PAPI_OK;
  }

  return PAPI_ENOEVNT;
}
int _stealtime_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)

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

{

     if ( modifier == PAPI_ENUM_FIRST ) {
    if (num_events==0) return PAPI_ENOEVNT;
    *EventCode = 0;
    return PAPI_OK;
     }

     if ( modifier == PAPI_ENUM_EVENTS ) {
        int index;

        index = *EventCode;

    if ( (index+1) < num_events ) {
       *EventCode = *EventCode + 1;
       return PAPI_OK;
    } else {
       return PAPI_ENOEVNT;
    }
     } 
        
     return PAPI_EINVAL;
}
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.

{
    ( void ) flags;

    struct STEALTIME_control_state *control;
    struct STEALTIME_context *context;

    int i;
    
    control = (struct STEALTIME_control_state *)ctl;
    context = (struct STEALTIME_context *)ctx;

    read_stealtime( context, 0 );

    for(i=0;i<control->num_events;i++) {
       control->values[i]=
                 context->value[control->which_counter[i]];
    }

    *events = control->values;

    return PAPI_OK;

}

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.

{

  /* re-initializes counter_start values to current */

  _stealtime_start(ctx,ctrl);

  return PAPI_OK;
}

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.

{
    ( void ) cntrl;
    int found = 0;
    if ( PAPI_DOM_USER & domain ) {
        found = 1;
    }
    if ( PAPI_DOM_KERNEL & domain ) {
        found = 1;
    }
    if ( PAPI_DOM_OTHER & domain ) {
        found = 1;
    }
    if ( !found )
        return PAPI_EINVAL;

    return PAPI_OK;
}

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

{

   if (event_info!=NULL) free(event_info);

   return PAPI_OK;
}

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

{

  struct STEALTIME_context *context=(struct STEALTIME_context *)ctx;

  if (context->start_count!=NULL) free(context->start_count);
  if (context->current_count!=NULL) free(context->current_count);

  return PAPI_OK;
}

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

{

  (void)ctl;

  //    struct STEALTIME_control_state *control;
    struct STEALTIME_context *context;
    
    //control = (struct STEALTIME_control_state *)ctl;
    context = (struct STEALTIME_context *)ctx;

    read_stealtime( context, 1 );

    /* no need to update control, as we assume only one EventSet  */
    /* is active at once, so starting things at the context level */
    /* is fine, since stealtime is system-wide                    */

    return PAPI_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

{

  (void) ctl;

  //    struct STEALTIME_control_state *control;
    struct STEALTIME_context *context;
    
    //control = (struct STEALTIME_control_state *)ctl;
    context = (struct STEALTIME_context *)ctx;

    read_stealtime( context, 0 );

    return PAPI_OK;

}

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.

{

    struct STEALTIME_control_state *control;

    ( void ) ctx;
    int i, index;

    control= (struct STEALTIME_control_state *)ctl;

    if (count!=control->num_events) {
      //       printf("Resizing %d to %d\n",control->num_events,count);
       control->which_counter=realloc(control->which_counter,
                      count*sizeof(int));
       control->values=realloc(control->values,
                   count*sizeof(long long));
       
    }


    for ( i = 0; i < count; i++ ) {
       index = native[i].ni_event;
       control->which_counter[i]=index;
       native[i].ni_position = i;
    }

    control->num_events=count;

    return PAPI_OK;
}
int _stealtime_write ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long long *  from 
)

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

{
    ( void ) ctx;
    ( void ) ctrl;
    ( void ) from;

    return PAPI_OK;
}
int read_stealtime ( struct STEALTIME_context context,
int  starting 
)

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

                                                                     {

  FILE *fff;
  char buffer[BUFSIZ],*result;
  int i,count;
  struct statinfo our_stat;

  int hz=sysconf(_SC_CLK_TCK);


  fff=fopen("/proc/stat","r");
  if (fff==NULL) {
     return PAPI_ESYS; 
  }

  for(i=0;i<num_events;i++) {
    result=fgets(buffer,BUFSIZ,fff);
    if (result==NULL) break;

    count=sscanf(buffer,"%*s %lld %lld %lld %lld %lld %lld %lld %lld %lld",
         &our_stat.user,
         &our_stat.nice,
         &our_stat.system,
         &our_stat.idle,
         &our_stat.iowait,
         &our_stat.irq,
         &our_stat.softirq,
         &our_stat.steal,
         &our_stat.guest);
    if (count<=7) {
       fclose(fff);
       return PAPI_ESYS;
    }

    if (starting) {
       context->start_count[i]=our_stat.steal;
    }
    context->current_count[i]=our_stat.steal;

    /* convert to us */
    context->value[i]=(context->current_count[i]-context->start_count[i])*
      (1000000/hz);
  }
  

  fclose(fff);

  return PAPI_OK;

}

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.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines