PAPI  5.0.1.0
linux-lustre.c File Reference

A component for the luster filesystem. More...

Include dependency graph for linux-lustre.c:

Go to the source code of this file.

Data Structures

struct  STEALTIME_reg_alloc_t
struct  string_list
struct  lustre_fs
struct  LUSTRE_control_state_t
struct  LUSTRE_context_t

Defines

#define LUSTRE_MAX_COUNTERS   100
#define LUSTRE_MAX_COUNTER_TERMS   LUSTRE_MAX_COUNTERS

Typedefs

typedef counter_info LUSTRE_register_t
typedef counter_info LUSTRE_native_event_entry_t
typedef counter_info LUSTRE_reg_alloc_t

Functions

static counter_infoaddCounter (const char *name, const char *desc, const char *unit)
static int addLustreFS (const char *name, const char *procpath_general, const char *procpath_readahead)
static int init_lustre_counters (void)
static void read_lustre_counter ()
static void host_finalize (void)
static int detect_lustre ()
int _lustre_init_component ()
int _lustre_init_thread (hwd_context_t *ctx)
int _lustre_shutdown_component (void)
int _lustre_shutdown_thread (hwd_context_t *ctx)
int _lustre_init_control_state (hwd_control_state_t *ctl)
int _lustre_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
int _lustre_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
int _lustre_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
int _lustre_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
int _lustre_reset (hwd_context_t *ctx, hwd_control_state_t *ctrl)
int _lustre_write (hwd_context_t *ctx, hwd_control_state_t *ctrl, long long *from)
int _lustre_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
int _lustre_set_domain (hwd_control_state_t *cntrl, int domain)
int _lustre_ntv_code_to_name (unsigned int EventCode, char *name, int len)
int _lustre_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
int _lustre_ntv_enum_events (unsigned int *EventCode, int modifier)

Variables

const char proc_base_path [] = "/proc/fs/lustre/"
static counter_infolustre_native_table [100]
static int num_events = 0
static lustre_fsroot_lustre_fs = NULL
papi_vector_t _lustre_vector

Detailed Description

Author:
Haihang You (in collaboration with Michael Kluge, TU Dresden) you@eecs.utk.edu
Heike Jagode jagode@eecs.utk.edu
Vince Weaver vweaver1@eecs.utk.edu

Definition in file linux-lustre.c.


Define Documentation

Definition at line 58 of file linux-lustre.c.

#define LUSTRE_MAX_COUNTERS   100

Definition at line 57 of file linux-lustre.c.


Typedef Documentation

Definition at line 61 of file linux-lustre.c.

Definition at line 62 of file linux-lustre.c.

Definition at line 60 of file linux-lustre.c.


Function Documentation

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

Definition at line 621 of file linux-lustre.c.

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

    return PAPI_OK;
}

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

{

    int ret = PAPI_OK;

    /* See if lustre filesystem exists */
    ret=detect_lustre();
    if (ret!=PAPI_OK) {
       strncpy(_lustre_vector.cmp_info.disabled_reason,
           "No lustre filesystems found",PAPI_MAX_STR_LEN);
       return ret;
    }

    ret=init_lustre_counters();

    _lustre_vector.cmp_info.num_native_events=num_events;

    return ret;
}

Here is the call graph for this function:

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

{
    LUSTRE_control_state_t *lustre_ctl = (LUSTRE_control_state_t *)ctl;

    memset(lustre_ctl->start_count,0,sizeof(long long)*LUSTRE_MAX_COUNTERS);
    memset(lustre_ctl->current_count,0,sizeof(long long)*LUSTRE_MAX_COUNTERS);

    return PAPI_OK;
}

Definition at line 429 of file linux-lustre.c.

{
  (void) ctx;

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

Definition at line 683 of file linux-lustre.c.

{

  int event=EventCode;

  if (event >=0 && event < num_events) {
    strncpy( name, lustre_native_table[event]->description, len );
    return PAPI_OK;
  }
  return PAPI_ENOEVNT;
}
int _lustre_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 666 of file linux-lustre.c.

{

  int event=EventCode;

  if (event >=0 && event < num_events) {
     strncpy( name, lustre_native_table[event]->name, len );
     return PAPI_OK;
  }
  return PAPI_ENOEVNT;
}
int _lustre_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)

Definition at line 700 of file linux-lustre.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 = *EventCode;

        if ( lustre_native_table[index + 1] ) {
            *EventCode = *EventCode + 1;
            return PAPI_OK;
        } else {
            return PAPI_ENOEVNT;
        }
    } 
        

    return PAPI_EINVAL;
}
int _lustre_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)

Definition at line 556 of file linux-lustre.c.

{
    (void) ctx;
    ( void ) flags;

    LUSTRE_control_state_t *lustre_ctl = (LUSTRE_control_state_t *)ctl;
    int i;

    read_lustre_counter(  );

    for(i=0;i<lustre_ctl->num_events;i++) {
       lustre_ctl->current_count[i]=
                 lustre_native_table[lustre_ctl->which_counter[i]]->value;
       lustre_ctl->difference[i]=lustre_ctl->current_count[i]-
                                         lustre_ctl->start_count[i];
    }

    *events = lustre_ctl->difference;

    return PAPI_OK;

}

Here is the call graph for this function:

int _lustre_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Definition at line 587 of file linux-lustre.c.

{

  /* re-initializes counter_start values to current */

  _lustre_start(ctx,ctrl);

  return PAPI_OK;
}

Here is the call graph for this function:

int _lustre_set_domain ( hwd_control_state_t cntrl,
int  domain 
)

Definition at line 642 of file linux-lustre.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 441 of file linux-lustre.c.

{

    host_finalize(  );

    return PAPI_OK;
}

Here is the call graph for this function:

Definition at line 453 of file linux-lustre.c.

{
    ( void ) ctx;

    return PAPI_OK;
}
int _lustre_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 506 of file linux-lustre.c.

{
    ( void ) ctx;

    LUSTRE_control_state_t *lustre_ctl = (LUSTRE_control_state_t *)ctl;
    int i;

    read_lustre_counter(  );

    for(i=0;i<lustre_ctl->num_events;i++) {
       lustre_ctl->current_count[i]=
                 lustre_native_table[lustre_ctl->which_counter[i]]->value;
    }

    memcpy( lustre_ctl->start_count,
        lustre_ctl->current_count,
        LUSTRE_MAX_COUNTERS * sizeof ( long long ) );

    return PAPI_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _lustre_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 532 of file linux-lustre.c.

{

    (void) ctx;
    LUSTRE_control_state_t *lustre_ctl = (LUSTRE_control_state_t *)ctl;
    int i;

    read_lustre_counter(  );

    for(i=0;i<lustre_ctl->num_events;i++) {
       lustre_ctl->current_count[i]=
                 lustre_native_table[lustre_ctl->which_counter[i]]->value;
    }

    return PAPI_OK;

}

Here is the call graph for this function:

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

Definition at line 481 of file linux-lustre.c.

{
    LUSTRE_control_state_t *lustre_ctl = (LUSTRE_control_state_t *)ctl;
    ( void ) ctx;
    int i, index;

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

    lustre_ctl->num_events=count;

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

Definition at line 602 of file linux-lustre.c.

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

    return PAPI_OK;
}
static counter_info* addCounter ( const char *  name,
const char *  desc,
const char *  unit 
) [static]

add a counter to the list of available counters

Parameters:
namethe short name of the counter
desca longer description
unitthe unit for this counter

Definition at line 103 of file linux-lustre.c.

{
    counter_info *cntr;

    cntr = malloc( sizeof ( counter_info ) );

    if ( cntr == NULL ) {
       SUBDBG("can not allocate memory for new counter\n" );
       return NULL;
    }

    cntr->idx=num_events;
    cntr->name = strdup( name );
    cntr->description = strdup( desc );
    cntr->unit = strdup( unit );
    cntr->value = 0;

    lustre_native_table[num_events]=cntr;

    num_events++;

    return cntr;
}

Here is the caller graph for this function:

static int addLustreFS ( const char *  name,
const char *  procpath_general,
const char *  procpath_readahead 
) [static]

adds a Lustre fs to the fs list and creates the counters for it

Parameters:
namefs name
procpath_generalpath to the 'stats' file in /proc/fs/lustre/... for this fs
procpath_readaheadpath to the 'readahead' file in /proc/fs/lustre/... for this fs

Definition at line 134 of file linux-lustre.c.

{
    lustre_fs *fs, *last;
    char counter_name[512];
    FILE *fff;

    SUBDBG("Adding lustre fs\n");

    fs = malloc( sizeof ( lustre_fs ) );
    if ( fs == NULL ) {
       SUBDBG("can not allocate memory for new Lustre FS description\n" );
       return PAPI_ENOMEM;
    }

    fs->proc_file=strdup(procpath_general);
    fff = fopen( procpath_general, "r" );
    if ( fff == NULL ) {
      SUBDBG("can not open '%s'\n", procpath_general );
      free(fs);
      return PAPI_ESYS;
    }
    fclose(fff);

    fs->proc_file_readahead = strdup(procpath_readahead);
    fff = fopen( procpath_readahead, "r" );
    if ( fff == NULL ) {
      SUBDBG("can not open '%s'\n", procpath_readahead );
      free(fs);
      return PAPI_ESYS;
    }
    fclose(fff);

    sprintf( counter_name, "%s_llread", name );
    fs->read_cntr = addCounter( counter_name, 
                    "bytes read on this lustre client", 
                    "bytes" );

    sprintf( counter_name, "%s_llwrite", name );
    fs->write_cntr = addCounter( counter_name, 
                     "bytes written on this lustre client",
                     "bytes" );

    sprintf( counter_name, "%s_wrong_readahead", name );
    fs->readahead_cntr = addCounter( counter_name, 
                     "bytes read but discarded due to readahead",
                     "bytes" );

    fs->next = NULL;

    /* Insert into the linked list */
    /* Does this need locking? */
    if ( root_lustre_fs == NULL ) {
        root_lustre_fs = fs;
    } else {
        last = root_lustre_fs;

        while ( last->next != NULL )
            last = last->next;

        last->next = fs;
    }
    free(fs);
    return PAPI_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int detect_lustre ( ) [static]

see if lustre filesystem is supported by kernel

Definition at line 373 of file linux-lustre.c.

{
        char lustre_directory[BUFSIZ];
    DIR *proc_dir;

    sprintf(lustre_directory,"%s/llite",proc_base_path);

    proc_dir = opendir( proc_base_path );
    if ( proc_dir == NULL ) {
      SUBDBG("we are not able to read %s\n",lustre_directory);
       return PAPI_ESYS;
    }

    closedir(proc_dir);

    return PAPI_OK;
}

Here is the caller graph for this function:

static void host_finalize ( void  ) [static]

frees all allocated resources

Definition at line 338 of file linux-lustre.c.

{
        int i;
    lustre_fs *fs, *next_fs;
    counter_info *cntr;

    for(i=0;i<num_events;i++) {
       cntr=lustre_native_table[i];
       if ( cntr != NULL ) {
          free( cntr->name );
          free( cntr->description );
          free( cntr->unit );
          free( cntr );       
       }
       lustre_native_table[i]=NULL;
    }

    fs = root_lustre_fs;

    while ( fs != NULL ) {
        next_fs = fs->next;
        free(fs->proc_file);
        free(fs->proc_file_readahead);
        free( fs );
        fs = next_fs;
    }

    root_lustre_fs = NULL;
}

Here is the caller graph for this function:

static int init_lustre_counters ( void  ) [static]

goes through proc and tries to discover all mounted Lustre fs

Definition at line 206 of file linux-lustre.c.

{
        char lustre_dir[PATH_MAX];
    char path[PATH_MAX];
    char path_readahead[PATH_MAX],path_stats[PATH_MAX];
    char *ptr;
    char fs_name[100];
    int idx = 0;
    int tmp_fd;
    DIR *proc_dir;
    struct dirent *entry;

    sprintf(lustre_dir,"%s/llite",proc_base_path);

    proc_dir = opendir( lustre_dir );
    if ( proc_dir == NULL ) {
       SUBDBG("Cannot open %s\n",lustre_dir);
       return PAPI_ESYS;
    }

    entry = readdir( proc_dir );

    while ( entry != NULL ) {
       memset( path, 0, PATH_MAX );
       snprintf( path, PATH_MAX - 1, "%s/%s/stats", lustre_dir,
                  entry->d_name );
       SUBDBG("checking for file %s\n", path);

       if ( ( tmp_fd = open( path, O_RDONLY ) ) != -1 ) {
          close( tmp_fd );

          /* erase \r and \n at the end of path */
          /* why is this necessary?             */

          idx = strlen( path );
          idx--;

          while ( path[idx] == '\r' || path[idx] == '\n' )
            path[idx--] = 0;

          /* Lustre paths are of type server-UUID */

          idx = 0;

          ptr = strstr(path,"llite/") + 6;

          while ( *ptr && *ptr != '-' && idx < 100 ) {
             fs_name[idx] = *ptr;
         ptr++;
         idx++;
          }

          SUBDBG("found Lustre FS: %s\n", fs_name);

          snprintf( path_stats, PATH_MAX - 1, 
            "%s/%s/stats", 
            lustre_dir,
            entry->d_name );
          SUBDBG("Found file %s\n", path_stats);

          snprintf( path_readahead, PATH_MAX - 1, 
            "%s/%s/read_ahead_stats", 
            lustre_dir,
            entry->d_name );
          SUBDBG("Now checking for file %s\n", path_readahead);


          strcpy( ptr, "read_ahead_stats" );
          addLustreFS( fs_name, path_stats, path_readahead );

       }
       entry = readdir( proc_dir );
    }
    closedir( proc_dir );

    return PAPI_OK;

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void read_lustre_counter ( ) [static]

updates all Lustre related counters

Definition at line 289 of file linux-lustre.c.

{
    lustre_fs *fs = root_lustre_fs;
    FILE *fff;
    char buffer[BUFSIZ];

    while ( fs != NULL ) {

      /* read values from stats file */
      fff=fopen(fs->proc_file,"r" );
      if (fff != NULL) {
          while(1) {
            if (fgets(buffer,BUFSIZ,fff)==NULL) break;
    
            if (strstr( buffer, "write_bytes" )) {
              sscanf(buffer,"%*s %*d %*s %*s %*d %*d %lld",&fs->write_cntr->value);
              SUBDBG("Read %lld write_bytes\n",fs->write_cntr->value);
            }
    
            if (strstr( buffer, "read_bytes" )) {
              sscanf(buffer,"%*s %*d %*s %*s %*d %*d %lld",&fs->read_cntr->value);
              SUBDBG("Read %lld read_bytes\n",fs->read_cntr->value);
            }
          }
          fclose(fff);
      }

      fff=fopen(fs->proc_file_readahead,"r");
      if (fff != NULL) {
          while(1) {
            if (fgets(buffer,BUFSIZ,fff)==NULL) break;
    
            if (strstr( buffer, "read but discarded")) {
               sscanf(buffer,"%*s %*s %*s %lld",&fs->readahead_cntr->value);
               SUBDBG("Read %lld discared\n",fs->readahead_cntr->value);
               break;
            }
          }
          fclose(fff);
      }
      fs = fs->next;
    }
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 90 of file linux-lustre.c.

Definition at line 84 of file linux-lustre.c.

int num_events = 0 [static]

Definition at line 85 of file linux-lustre.c.

const char proc_base_path[] = "/proc/fs/lustre/"

Definition at line 81 of file linux-lustre.c.

lustre_fs* root_lustre_fs = NULL [static]

Definition at line 88 of file linux-lustre.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines