PAPI  5.7.0.0
linux-emon.c File Reference

This file has the source code for a component that enables PAPI-C to access hardware power data for BG/Q through the EMON interface. More...

Include dependency graph for linux-emon.c:

Go to the source code of this file.

Data Structures

struct  EMON_register_t
 
struct  EMON_native_event_entry_t
 
struct  EMON_reg_alloc_t
 
struct  EMON_overflow_t
 
struct  EMON_control_state_t
 
struct  EMON_context_t
 

Macros

#define EMON_DEFINE_GLOBALS
 
#define EMON_MAX_COUNTERS   8
 
#define EMON_TOTAL_EVENTS   8
 
#define EMONDBG(fmt, args...)   do { printf("%s:%d\t"fmt, __func__, __LINE__, ##args); } while(0)
 

Functions

static void _check_EMON_error (char *emon2func, int err)
 
int EMON_init_thread (hwd_context_t *ctx)
 
int EMON_init_component (int cidx)
 
int EMON_init_control_state (hwd_control_state_t *ptr)
 
static int _emon_accessor (EMON_control_state_t *this_state)
 
int EMON_start (hwd_context_t *ctx, hwd_control_state_t *ptr)
 
int EMON_stop (hwd_context_t *ctx, hwd_control_state_t *ptr)
 
int EMON_read (hwd_context_t *ctx, hwd_control_state_t *ptr, long long **events, int flags)
 
int EMON_shutdown_thread (hwd_context_t *ctx)
 
int EMON_shutdown_component (void)
 
int EMON_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
int EMON_cleanup_eventset (hwd_control_state_t *ctrl)
 
int EMON_update_control_state (hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
int EMON_set_domain (hwd_control_state_t *cntrl, int domain)
 
int EMON_reset (hwd_context_t *ctx, hwd_control_state_t *ptr)
 
int EMON_ntv_enum_events (unsigned int *EventCode, int modifier)
 
int EMON_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
int EMON_ntv_name_to_code (const char *name, unsigned int *code)
 
int EMON_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
int EMON_ntv_code_to_bits (unsigned int EventCode, hwd_register_t *bits)
 
int EMON_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
 

Variables

papi_vector_t _emon2_vector
 
static EMON_native_event_entry_t EMON_native_table []
 
papi_vector_t _emon_vector
 

Detailed Description

Author
Heike Jagode jagod.nosp@m.e@ee.nosp@m.cs.ut.nosp@m.k.ed.nosp@m.u BGPM / emon component

Definition in file linux-emon.c.

Macro Definition Documentation

◆ EMON_DEFINE_GLOBALS

#define EMON_DEFINE_GLOBALS

Definition at line 24 of file linux-emon.c.

◆ EMON_MAX_COUNTERS

#define EMON_MAX_COUNTERS   8

Definition at line 28 of file linux-emon.c.

◆ EMON_TOTAL_EVENTS

#define EMON_TOTAL_EVENTS   8

Definition at line 29 of file linux-emon.c.

◆ EMONDBG

#define EMONDBG (   fmt,
  args... 
)    do { printf("%s:%d\t"fmt, __func__, __LINE__, ##args); } while(0)

Definition at line 34 of file linux-emon.c.

Function Documentation

◆ _check_EMON_error()

static void _check_EMON_error ( char *  emon2func,
int  err 
)
static

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

89 {
90  ( void ) emon2func;
91  if ( err < 0 ) {
92  printf( "Error: EMON API function '%s' returned %d.\n",
93  emon2func, err );
94  }
95 }
Here is the caller graph for this function:

◆ _emon_accessor()

static int _emon_accessor ( EMON_control_state_t this_state)
static

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

215 {
216  union {
217  long long ll;
218  double fp;
219  } return_value;
220  return_value.fp = -1;
221 
222  double volts[14],amps[14];
223  double cpu = 0;
224  double dram = 0;
225  double link_chip = 0;
226  double network = 0;
227  double optics = 0;
228  double pci = 0;
229  double sram = 0;
230  unsigned k_const;
231 
232  EMONDBG( "_emon_accessor, enter this_state = %x\n", this_state);
233  return_value.fp = EMON_GetPower_impl( volts, amps );
234  EMONDBG("_emon_accessor, after EMON_GetPower %lf \n", return_value.fp);
235  if ( -1 == return_value.fp ) {
236  PAPIERROR("EMON_GetPower() failed!\n");
237  return ( PAPI_ESYS );
238  }
239 
240  this_state->counters[7] = return_value.ll;
241 
242 /* We just stuff everything in counters, there is no extra overhead here */
243  k_const = domain_info[0].k_const; /* Chip Core Voltage */
244  cpu += volts[0] * amps[0] * k_const;
245  cpu += volts[1] * amps[1] * k_const;
246 
247  k_const = domain_info[1].k_const; /* Chip Core Voltage */
248  dram += volts[2] * amps[2] * k_const;
249  dram += volts[3] * amps[3] * k_const;
250 
251  k_const = domain_info[2].k_const; /* Chip Core Voltage */
252  optics += volts[4] * amps[4] * k_const;
253  optics += volts[5] * amps[5] * k_const;
254 
255  k_const = domain_info[3].k_const; /* Chip Core Voltage */
256  pci += volts[6] * amps[6] * k_const;
257  pci += volts[7] * amps[7] * k_const;
258 
259  k_const = domain_info[4].k_const; /* Chip Core Voltage */
260  network += volts[8] * amps[8] * k_const;
261  network += volts[9] * amps[9] * k_const;
262 
263  k_const = domain_info[5].k_const; /* Chip Core Voltage */
264  link_chip += volts[10] * amps[10] * k_const;
265  link_chip += volts[11] * amps[11] * k_const;
266 
267  k_const = domain_info[6].k_const; /* Chip Core Voltage */
268  sram += volts[12] * amps[12] * k_const;
269  sram += volts[13] * amps[13] * k_const;
270 
271  this_state->counters[0] = *(long long*)&cpu;
272  this_state->counters[1] = *(long long*)&dram;
273  this_state->counters[2] = *(long long*)&optics;
274  this_state->counters[3] = *(long long*)&pci;
275  this_state->counters[4] = *(long long*)&link_chip;
276  this_state->counters[5] = *(long long*)&network;
277  this_state->counters[6] = *(long long*)&sram;
278 
279  EMONDBG("CPU = %lf\n", *(double*)&this_state->counters[0]);
280  EMONDBG("DRAM = %lf\n", *(double*)&this_state->counters[1]);
281  EMONDBG("Optics = %lf\n", *(double*)&this_state->counters[2]);
282  EMONDBG("PCI = %lf\n", *(double*)&this_state->counters[3]);
283  EMONDBG("Link Chip = %lf\n", *(double*)&this_state->counters[4]);
284  EMONDBG("Network = %lf\n", *(double*)&this_state->counters[5]);
285  EMONDBG("SRAM = %lf\n", *(double*)&this_state->counters[6]);
286  EMONDBG("TOTAL = %lf\n", *(double*)&this_state->counters[7] );
287 
288  return ( PAPI_OK );
289 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
static FILE * fp
#define PAPI_ESYS
Definition: fpapi.h:108
void PAPIERROR(char *format,...)
long long counters[EMON_MAX_COUNTERS]
Definition: linux-emon.c:74
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EMON_cleanup_eventset()

int EMON_cleanup_eventset ( hwd_control_state_t ctrl)

Definition at line 379 of file linux-emon.c.

380 {
381  EMONDBG( "EMON_cleanup_eventset\n" );
382 
383  EMON_control_state_t * this_state = ( EMON_control_state_t * ) ctrl;
384  ( void ) this_state;
385 
386  return ( PAPI_OK );
387 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34

◆ EMON_ctl()

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

Definition at line 364 of file linux-emon.c.

365 {
366  EMONDBG( "EMON_ctl\n" );
367 
368  ( void ) ctx;
369  ( void ) code;
370  ( void ) option;
371  return ( PAPI_OK );
372 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34

◆ EMON_init_component()

int EMON_init_component ( int  cidx)

Definition at line 177 of file linux-emon.c.

178 {
179  int ret = 0;
181  EMONDBG( "EMON_init_component cidx = %d\n", cidx );
182  /* Setup connection with the fpga:
183  * NOTE: any other threads attempting to call into the EMON API
184  * will be turned away. */
185  ret = EMON_SetupPowerMeasurement();
186  _check_EMON_error("EMON_SetupPowerMeasurement", ret );
187 
189 
192 
193 
194  return ( PAPI_OK );
195 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
papi_vector_t _emon2_vector
Definition: linux-emon.c:86
static void _check_EMON_error(char *emon2func, int err)
Definition: linux-emon.c:88
static int cidx
long long ret
Definition: iozone.c:1346
#define EMON_TOTAL_EVENTS
Definition: linux-emon.c:29
Here is the call graph for this function:

◆ EMON_init_control_state()

int EMON_init_control_state ( hwd_control_state_t ptr)

Definition at line 203 of file linux-emon.c.

204 {
205  EMONDBG( "EMON_init_control_state\n" );
206 
207  EMON_control_state_t * this_state = ( EMON_control_state_t * ) ptr;
208  memset( this_state, 0, sizeof ( EMON_control_state_t ) );
209 
210  return PAPI_OK;
211 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34

◆ EMON_init_thread()

int EMON_init_thread ( hwd_context_t ctx)

Definition at line 163 of file linux-emon.c.

164 {
165  EMONDBG( "EMON_init_thread\n" );
166 
167  ( void ) ctx;
168  return PAPI_OK;
169 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34

◆ EMON_ntv_code_to_bits()

int EMON_ntv_code_to_bits ( unsigned int  EventCode,
hwd_register_t bits 
)

Definition at line 552 of file linux-emon.c.

553 {
554  EMONDBG( "EMON_ntv_code_to_bits\n" );
555  ( void ) EventCode;
556  ( void ) bits;
557  return ( PAPI_OK );
558 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34

◆ EMON_ntv_code_to_descr()

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

Definition at line 530 of file linux-emon.c.

531 {
532  EMONDBG( "EMON_ntv_code_to_descr\n" );
533  int index;
534  ( void ) name;
535  ( void ) len;
536 
537  index = ( EventCode ) ;
538 
539  if ( index >= EMON_TOTAL_EVENTS || index < 0 ) {
540  return PAPI_ENOEVNT;
541  }
542  strncpy( name, EMON_native_table[index].description, len );
543 
544  return ( PAPI_OK );
545 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
static EMON_native_event_entry_t EMON_native_table[]
Definition: linux-emon.c:101
#define EMON_TOTAL_EVENTS
Definition: linux-emon.c:29
#define PAPI_ENOEVNT
Definition: fpapi.h:112

◆ EMON_ntv_code_to_info()

int EMON_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

Definition at line 561 of file linux-emon.c.

562 {
563 
564  int index = EventCode;
565 
566  if ( ( index < 0) || (index >= EMON_TOTAL_EVENTS )) return PAPI_ENOEVNT;
567 
568  strncpy( info->symbol, EMON_native_table[index].name,
569  sizeof(info->symbol));
570 
571  strncpy( info->long_descr, EMON_native_table[index].description,
572  sizeof(info->symbol));
573 
574  //strncpy( info->units, rapl_native_events[index].units,
575  //sizeof(info->units));
576 
577  info->data_type = EMON_native_table[index].return_type;
578 
579  return PAPI_OK;
580 }
#define PAPI_OK
Definition: fpapi.h:105
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:970
int return_type
Definition: linux-emon.c:54
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:967
static EMON_native_event_entry_t EMON_native_table[]
Definition: linux-emon.c:101
#define EMON_TOTAL_EVENTS
Definition: linux-emon.c:29
#define PAPI_ENOEVNT
Definition: fpapi.h:112
char * name
Definition: linux-emon.c:52
char * description
Definition: linux-emon.c:53

◆ EMON_ntv_code_to_name()

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

Definition at line 496 of file linux-emon.c.

497 {
498  EMONDBG( "EMON_ntv_code_to_name\n" );
499  int index;
500  ( void ) name;
501  ( void ) len;
502 
503  index = ( EventCode );
504 
505  if ( index >= EMON_TOTAL_EVENTS || index < 0 ) {
506  return PAPI_ENOEVNT;
507  }
508 
509  strncpy( name, EMON_native_table[index].name, len );
510  return ( PAPI_OK );
511 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
static EMON_native_event_entry_t EMON_native_table[]
Definition: linux-emon.c:101
#define EMON_TOTAL_EVENTS
Definition: linux-emon.c:29
#define PAPI_ENOEVNT
Definition: fpapi.h:112

◆ EMON_ntv_enum_events()

int EMON_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)

Definition at line 462 of file linux-emon.c.

463 {
464  EMONDBG( "EMON_ntv_enum_events, EventCode = %#x\n", *EventCode );
465 
466  switch ( modifier ) {
467  case PAPI_ENUM_FIRST:
468  *EventCode = 0;
469 
470  return ( PAPI_OK );
471  break;
472 
473  case PAPI_ENUM_EVENTS:
474  {
475  int index = ( *EventCode );
476 
477  if ( index < EMON_TOTAL_EVENTS ) {
478  *EventCode = *EventCode + 1;
479  return ( PAPI_OK );
480  } else {
481  return ( PAPI_ENOEVNT );
482  }
483 
484  break;
485  }
486  default:
487  return ( PAPI_EINVAL );
488  }
489  return ( PAPI_EINVAL );
490 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
#define EMON_TOTAL_EVENTS
Definition: linux-emon.c:29
#define PAPI_ENOEVNT
Definition: fpapi.h:112

◆ EMON_ntv_name_to_code()

int EMON_ntv_name_to_code ( const char *  name,
unsigned int *  code 
)

Definition at line 517 of file linux-emon.c.

518 {
519  int index;
520 
521  for ( index = 0; index < EMON_TOTAL_EVENTS; index++ ) {
522  if ( 0 == strcmp( name, EMON_native_table[index].name ) ) {
523  *code = index;
524  }
525  }
526  return ( PAPI_OK );
527 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
static EMON_native_event_entry_t EMON_native_table[]
Definition: linux-emon.c:101
#define EMON_TOTAL_EVENTS
Definition: linux-emon.c:29

◆ EMON_read()

int EMON_read ( hwd_context_t ctx,
hwd_control_state_t ptr,
long long **  events,
int  flags 
)

Definition at line 324 of file linux-emon.c.

326 {
327  EMONDBG( "EMON_read\n" );
328  ( void ) ctx;
329  ( void ) flags;
330  int ret;
331  EMON_control_state_t * this_state = ( EMON_control_state_t * ) ptr;
332 
333  ret = _emon_accessor( this_state );
334  *events = this_state->counters;
335  return ret;
336 }
static int _emon_accessor(EMON_control_state_t *this_state)
Definition: linux-emon.c:214
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
char events[MAX_EVENTS][BUFSIZ]
long long ret
Definition: iozone.c:1346
long long counters[EMON_MAX_COUNTERS]
Definition: linux-emon.c:74
Here is the call graph for this function:

◆ EMON_reset()

int EMON_reset ( hwd_context_t ctx,
hwd_control_state_t ptr 
)

Definition at line 443 of file linux-emon.c.

444 {
445  EMONDBG( "EMON_reset\n" );
446  ( void ) ctx;
447  int retval;
448  EMON_control_state_t * this_state = ( EMON_control_state_t * ) ptr;
449  ( void ) this_state;
450  ( void ) retval;
451 
452  memset( this_state->counters, 0x0, sizeof(long long) * EMON_MAX_COUNTERS);
453 
454  return ( PAPI_OK );
455 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
int retval
Definition: zero_fork.c:53
#define EMON_MAX_COUNTERS
Definition: linux-emon.c:28
long long counters[EMON_MAX_COUNTERS]
Definition: linux-emon.c:74

◆ EMON_set_domain()

int EMON_set_domain ( hwd_control_state_t cntrl,
int  domain 
)

Definition at line 427 of file linux-emon.c.

428 {
429  EMONDBG( "EMON_set_domain\n" );
430  ( void ) cntrl;
431 
432  if ( PAPI_DOM_ALL != domain )
433  return ( PAPI_EINVAL );
434 
435  return ( PAPI_OK );
436 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
#define PAPI_DOM_ALL
Definition: fpapi.h:25

◆ EMON_shutdown_component()

int EMON_shutdown_component ( void  )

Definition at line 352 of file linux-emon.c.

353 {
354  EMONDBG( "EMON_shutdown_component\n" );
355 
356  return ( PAPI_OK );
357 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34

◆ EMON_shutdown_thread()

int EMON_shutdown_thread ( hwd_context_t ctx)

Definition at line 343 of file linux-emon.c.

344 {
345  EMONDBG( "EMON_shutdown_thread\n" );
346 
347  ( void ) ctx;
348  return ( PAPI_OK );
349 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34

◆ EMON_start()

int EMON_start ( hwd_context_t ctx,
hwd_control_state_t ptr 
)

Definition at line 295 of file linux-emon.c.

296 {
297  EMONDBG( "EMON_start\n" );
298  ( void ) ctx;
299  ( void ) ptr;
300  /*EMON_control_state_t * this_state = ( EMON_control_state_t * ) ptr;*/
301 
302  return ( PAPI_OK );
303 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34

◆ EMON_stop()

int EMON_stop ( hwd_context_t ctx,
hwd_control_state_t ptr 
)

Definition at line 310 of file linux-emon.c.

311 {
312  EMONDBG( "EMON_stop\n" );
313  ( void ) ctx;
314  EMON_control_state_t * this_state = ( EMON_control_state_t * ) ptr;
315 
316  return _emon_accessor( this_state );
317 }
static int _emon_accessor(EMON_control_state_t *this_state)
Definition: linux-emon.c:214
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
Here is the call graph for this function:

◆ EMON_update_control_state()

int EMON_update_control_state ( hwd_control_state_t ptr,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)

Definition at line 394 of file linux-emon.c.

397 {
398  EMONDBG( "EMON_update_control_state: count = %d\n", count );
399 
400  ( void ) ctx;
401  int index, i;
402  EMON_control_state_t * this_state = ( EMON_control_state_t * ) ptr;
403  ( void ) ptr;
404 
405 
406 
407  // otherwise, add the events to the eventset
408  for ( i = 0; i < count; i++ ) {
409  index = ( native[i].ni_event ) ;
410 
411  native[i].ni_position = i;
412 
413  EMONDBG("EMON_update_control_state: ADD event: i = %d, index = %d\n", i, index );
414  }
415 
416  // store how many events we added to an EventSet
417  this_state->count = count;
418 
419  return ( PAPI_OK );
420 }
#define PAPI_OK
Definition: fpapi.h:105
#define EMONDBG(fmt, args...)
Definition: linux-emon.c:34
static int native
static long count
int i
Definition: fileop.c:140

Variable Documentation

◆ _emon2_vector

papi_vector_t _emon2_vector

Definition at line 86 of file linux-emon.c.

◆ _emon_vector

papi_vector_t _emon_vector

Definition at line 585 of file linux-emon.c.

◆ EMON_native_table

EMON_native_event_entry_t EMON_native_table[]
static

This table contains the native events So with the EMON interface, we get every domain at a time.

Definition at line 101 of file linux-emon.c.