PAPI  5.7.0.0
linux-powercap.c File Reference

powercap component More...

Include dependency graph for linux-powercap.c:

Go to the source code of this file.

Data Structures

struct  _powercap_register_t
 
struct  _powercap_native_event_entry_t
 
struct  _powercap_reg_alloc_t
 
struct  _powercap_control_state_t
 
struct  _powercap_context_t
 

Macros

#define PKG_ENERGY   0
 
#define PKG_MAX_ENERGY_RANGE   1
 
#define PKG_MAX_POWER_A   2
 
#define PKG_POWER_LIMIT_A   3
 
#define PKG_TIME_WINDOW_A   4
 
#define PKG_MAX_POWER_B   5
 
#define PKG_POWER_LIMIT_B   6
 
#define PKG_TIME_WINDOW_B   7
 
#define PKG_ENABLED   8
 
#define PKG_NAME   9
 
#define PKG_NUM_EVENTS   10
 
#define COMPONENT_ENERGY   10
 
#define COMPONENT_MAX_ENERGY_RANGE   11
 
#define COMPONENT_MAX_POWER_A   12
 
#define COMPONENT_POWER_LIMIT_A   13
 
#define COMPONENT_TIME_WINDOW_A   14
 
#define COMPONENT_ENABLED   15
 
#define COMPONENT_NAME   16
 
#define COMPONENT_NUM_EVENTS   7
 
#define POWERCAP_MAX_COUNTERS   (2 * (PKG_NUM_EVENTS + (3 * COMPONENT_NUM_EVENTS)))
 

Functions

static char * _local_strlcpy (char *dst, const char *src, size_t size)
 
static long long read_powercap_value (int index)
 
static int write_powercap_value (int index, long long value)
 
static int _powercap_init_thread (hwd_context_t *ctx)
 
static int _powercap_init_component (int cidx)
 
static int _powercap_init_control_state (hwd_control_state_t *ctl)
 
static int _powercap_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _powercap_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _powercap_shutdown_thread (hwd_context_t *ctx)
 
static int _powercap_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
 
static int _powercap_write (hwd_context_t *ctx, hwd_control_state_t *ctl, long long *values)
 
static int _powercap_shutdown_component (void)
 
static int _powercap_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
static int _powercap_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
static int _powercap_set_domain (hwd_control_state_t *ctl, int domain)
 
static int _powercap_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _powercap_ntv_enum_events (unsigned int *EventCode, int modifier)
 
static int _powercap_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
static int _powercap_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
static int _powercap_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
 

Variables

static char read_buff [PAPI_MAX_STR_LEN]
 
static char write_buff [PAPI_MAX_STR_LEN]
 
static int num_events =0
 
static int pkg_events [PKG_NUM_EVENTS] = {PKG_ENERGY, PKG_MAX_ENERGY_RANGE, PKG_MAX_POWER_A, PKG_POWER_LIMIT_A, PKG_TIME_WINDOW_A, PKG_MAX_POWER_B, PKG_POWER_LIMIT_B, PKG_TIME_WINDOW_B, PKG_ENABLED, PKG_NAME}
 
static char * pkg_event_names [PKG_NUM_EVENTS] = {"ENERGY_UJ", "MAX_ENERGY_RANGE_UJ", "MAX_POWER_A_UW", "POWER_LIMIT_A_UW", "TIME_WINDOW_A_US", "MAX_POWER_B_UW", "POWER_LIMIT_B_UW", "TIME_WINDOW_B", "ENABLED", "NAME"}
 
static char * pkg_sys_names [PKG_NUM_EVENTS] = {"energy_uj", "max_energy_range_uj", "constraint_0_max_power_uw", "constraint_0_power_limit_uw", "constraint_0_time_window_us", "constraint_1_max_power_uw", "constraint_1_power_limit_uw", "constraint_1_time_window_us", "enabled", "name"}
 
static mode_t pkg_sys_flags [PKG_NUM_EVENTS] = {O_RDONLY, O_RDONLY, O_RDONLY, O_RDWR, O_RDONLY, O_RDONLY, O_RDWR, O_RDONLY, O_RDONLY, O_RDONLY}
 
static int component_events [COMPONENT_NUM_EVENTS] = {COMPONENT_ENERGY, COMPONENT_MAX_ENERGY_RANGE, COMPONENT_MAX_POWER_A, COMPONENT_POWER_LIMIT_A, COMPONENT_TIME_WINDOW_A, COMPONENT_ENABLED, COMPONENT_NAME}
 
static char * component_event_names [COMPONENT_NUM_EVENTS] = {"ENERGY_UJ", "MAX_ENERGY_RANGE_UJ", "MAX_POWER_A_UW", "POWER_LIMIT_A_UW", "TIME_WINDOW_A_US", "ENABLED", "NAME"}
 
static char * component_sys_names [COMPONENT_NUM_EVENTS] = {"energy_uj", "max_energy_range_uj", "constraint_0_max_power_uw", "constraint_0_power_limit_uw", "constraint_0_time_window_us", "enabled", "name"}
 
static mode_t component_sys_flags [COMPONENT_NUM_EVENTS] = {O_RDONLY, O_RDONLY, O_RDONLY, O_RDWR, O_RDONLY, O_RDONLY, O_RDONLY}
 
static _powercap_native_event_entry_t powercap_ntv_events [(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
 
static int event_fds [POWERCAP_MAX_COUNTERS]
 
papi_vector_t _powercap_vector
 

Detailed Description

Author
Philip Vaccaro

To work, the powercap kernel module must be loaded.

Definition in file linux-powercap.c.

Macro Definition Documentation

◆ COMPONENT_ENABLED

#define COMPONENT_ENABLED   15

Definition at line 79 of file linux-powercap.c.

◆ COMPONENT_ENERGY

#define COMPONENT_ENERGY   10

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

◆ COMPONENT_MAX_ENERGY_RANGE

#define COMPONENT_MAX_ENERGY_RANGE   11

Definition at line 75 of file linux-powercap.c.

◆ COMPONENT_MAX_POWER_A

#define COMPONENT_MAX_POWER_A   12

Definition at line 76 of file linux-powercap.c.

◆ COMPONENT_NAME

#define COMPONENT_NAME   16

Definition at line 80 of file linux-powercap.c.

◆ COMPONENT_NUM_EVENTS

#define COMPONENT_NUM_EVENTS   7

Definition at line 82 of file linux-powercap.c.

◆ COMPONENT_POWER_LIMIT_A

#define COMPONENT_POWER_LIMIT_A   13

Definition at line 77 of file linux-powercap.c.

◆ COMPONENT_TIME_WINDOW_A

#define COMPONENT_TIME_WINDOW_A   14

Definition at line 78 of file linux-powercap.c.

◆ PKG_ENABLED

#define PKG_ENABLED   8

Definition at line 63 of file linux-powercap.c.

◆ PKG_ENERGY

#define PKG_ENERGY   0

Definition at line 55 of file linux-powercap.c.

◆ PKG_MAX_ENERGY_RANGE

#define PKG_MAX_ENERGY_RANGE   1

Definition at line 56 of file linux-powercap.c.

◆ PKG_MAX_POWER_A

#define PKG_MAX_POWER_A   2

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

◆ PKG_MAX_POWER_B

#define PKG_MAX_POWER_B   5

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

◆ PKG_NAME

#define PKG_NAME   9

Definition at line 64 of file linux-powercap.c.

◆ PKG_NUM_EVENTS

#define PKG_NUM_EVENTS   10

Definition at line 66 of file linux-powercap.c.

◆ PKG_POWER_LIMIT_A

#define PKG_POWER_LIMIT_A   3

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

◆ PKG_POWER_LIMIT_B

#define PKG_POWER_LIMIT_B   6

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

◆ PKG_TIME_WINDOW_A

#define PKG_TIME_WINDOW_A   4

Definition at line 59 of file linux-powercap.c.

◆ PKG_TIME_WINDOW_B

#define PKG_TIME_WINDOW_B   7

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

◆ POWERCAP_MAX_COUNTERS

#define POWERCAP_MAX_COUNTERS   (2 * (PKG_NUM_EVENTS + (3 * COMPONENT_NUM_EVENTS)))

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

Function Documentation

◆ _local_strlcpy()

static char* _local_strlcpy ( char *  dst,
const char *  src,
size_t  size 
)
static

Definition at line 113 of file linux-powercap.c.

114 {
115  char *retval = strncpy( dst, src, size );
116  if ( size>0 ) dst[size-1] = '\0';
117  return( retval );
118 }
int retval
Definition: zero_fork.c:53
Here is the caller graph for this function:

◆ _powercap_ctl()

static int _powercap_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)
static

Definition at line 403 of file linux-powercap.c.

404 {
405  SUBDBG( "Enter: ctx: %p\n", ctx );
406  ( void ) ctx;
407  ( void ) code;
408  ( void ) option;
409 
410  return PAPI_OK;
411 }
#define PAPI_OK
Definition: fpapi.h:105
#define SUBDBG(format, args...)
Definition: papi_debug.h:63

◆ _powercap_init_component()

static int _powercap_init_component ( int  cidx)
static

Definition at line 152 of file linux-powercap.c.

153 {
154 
155  int num_sockets = -1;
156  int s = -1, e = -1, c = -1;
157 
158  char events_dir[128];
159  char event_path[128];
160 
161  DIR *events;
162 
163  // get hw info
164  const PAPI_hw_info_t *hw_info;
166 
167  // check if intel processor
168  if ( hw_info->vendor!=PAPI_VENDOR_INTEL ) {
169  strncpy(_powercap_vector.cmp_info.disabled_reason, "Not an Intel processor", PAPI_MAX_STR_LEN);
170  return PAPI_ENOSUPP;
171  }
172 
173  // store number of sockets for adding events
174  num_sockets = hw_info->sockets;
175 
176  num_events = 0;
177  for(s = 0; s < num_sockets; s++) {
178 
179  // compose string of a pkg directory path
180  snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d/", s);
181 
182  // open directory to make sure it exists
183  events = opendir(events_dir);
184 
185  // not a valid pkg/component directory so continue
186  if (events == NULL) { continue; }
187  closedir(events); // opendir has mallocs; so clean up.
188 
189  // loop through pkg events and create powercap event entries
190  for (e = 0; e < PKG_NUM_EVENTS; e++) {
191 
192  // compose string to individual event
193  snprintf(event_path, sizeof(event_path), "%s%s", events_dir, pkg_sys_names[e]);
194  // not a valid pkg event path so continue
195  if (access(event_path, F_OK) == -1) { continue; }
196 
198  //snprintf(powercap_ntv_events[num_events].description, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d", pkg_event_names[e], s);
199  //snprintf(powercap_ntv_events[num_events].units, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d", pkg_event_names[e], s);
202 
204 
205  event_fds[num_events] = open(event_path, O_SYNC|pkg_sys_flags[e]);
206 
208  int sz = pread(event_fds[num_events], read_buff, PAPI_MAX_STR_LEN, 0);
209  read_buff[sz] = '\0';
210  snprintf(powercap_ntv_events[num_events].description, sizeof(powercap_ntv_events[num_events].description), "%s", read_buff);
211  }
212 
213  num_events++;
214  }
215 
216  // reset component count for each socket
217  c = 0;
218  snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d:%d/", s, c);
219  while((events = opendir(events_dir)) != NULL) {
220  closedir(events); // opendir has mallocs; so clean up.
221 
222  // loop through pkg events and create powercap event entries
223  for (e = 0; e < COMPONENT_NUM_EVENTS; e++) {
224 
225  // compose string to individual event
226  snprintf(event_path, sizeof(event_path), "%s%s", events_dir, component_sys_names[e]);
227 
228  // not a valid pkg event path so continue
229  if (access(event_path, F_OK) == -1) { continue; }
230 
231  snprintf(powercap_ntv_events[num_events].name, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d_SUBZONE%d", component_event_names[e], s, c);
232  //snprintf(powercap_ntv_events[num_events].description, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d_SUBZONE%d", component_event_names[e], s, c);
233  //snprintf(powercap_ntv_events[num_events].units, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d_SUBZONE%d", component_event_names[e], s, c);
236 
238 
239  event_fds[num_events] = open(event_path, O_SYNC|component_sys_flags[e]);
240 
242  int sz = pread(event_fds[num_events], read_buff, PAPI_MAX_STR_LEN, 0);
243  read_buff[sz] = '\0';
244  snprintf(powercap_ntv_events[num_events].description, sizeof(powercap_ntv_events[num_events].description), "%s", read_buff);
245  }
246 
247  num_events++;
248  }
249 
250  // test for next component
251  c++;
252 
253  // compose string of an pkg directory path
254  snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d:%d/", s, c);
255  }
256  }
257 
258  /* Export the total number of events available */
262 
263  /* Export the component id */
265 
266  return PAPI_OK;
267 }
#define PAPI_OK
Definition: fpapi.h:105
static char * pkg_event_names[PKG_NUM_EVENTS]
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:637
static const char * name
Definition: fork_overflow.c:31
Hardware info structure.
Definition: papi.h:781
#define PAPI_ENOSUPP
Definition: fpapi.h:123
static int num_events
static int component_events[COMPONENT_NUM_EVENTS]
static int event_fds[POWERCAP_MAX_COUNTERS]
static char read_buff[PAPI_MAX_STR_LEN]
static mode_t component_sys_flags[COMPONENT_NUM_EVENTS]
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
double c
Definition: multiplex.c:22
char events[MAX_EVENTS][BUFSIZ]
#define COMPONENT_NAME
static int cidx
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:184
static char * component_sys_names[COMPONENT_NUM_EVENTS]
_powercap_register_t resources
unsigned int selector
static int pkg_events[PKG_NUM_EVENTS]
static char * component_event_names[COMPONENT_NUM_EVENTS]
#define PKG_NUM_EVENTS
static mode_t pkg_sys_flags[PKG_NUM_EVENTS]
double s
Definition: byte_profile.c:36
int type
#define PKG_NAME
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
PAPI_hw_info_t hw_info
#define PAPI_VENDOR_INTEL
Definition: papi.h:349
int vendor
Definition: papi.h:788
papi_vector_t _powercap_vector
int return_type
static _powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
#define COMPONENT_NUM_EVENTS
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
int sockets
Definition: papi.h:785
static char * pkg_sys_names[PKG_NUM_EVENTS]
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
int sz
Definition: fileop.c:80
Here is the call graph for this function:

◆ _powercap_init_control_state()

static int _powercap_init_control_state ( hwd_control_state_t ctl)
static

Definition at line 274 of file linux-powercap.c.

275 {
277  memset( control, 0, sizeof ( _powercap_control_state_t ) );
278 
279 
280  /* if an event is a counter, set its corresponding flag to 1 */
281  int i;
282  for (i = 0; i < num_events; i++) {
283  if ((powercap_ntv_events[i].type == PKG_ENERGY) || (powercap_ntv_events[i].type == COMPONENT_ENERGY)) {
284  control->need_difference[i] = 1;
285  }
286  }
287 
288  return PAPI_OK;
289 }
#define PAPI_OK
Definition: fpapi.h:105
#define COMPONENT_ENERGY
static int num_events
#define PKG_ENERGY
static _powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
long long need_difference[POWERCAP_MAX_COUNTERS]
int i
Definition: fileop.c:140

◆ _powercap_init_thread()

static int _powercap_init_thread ( hwd_context_t ctx)
static

Definition at line 143 of file linux-powercap.c.

144 {
145  ( void ) ctx;
146  return PAPI_OK;
147 }
#define PAPI_OK
Definition: fpapi.h:105

◆ _powercap_ntv_code_to_descr()

static int _powercap_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)
static

Definition at line 491 of file linux-powercap.c.

492 {
493  int index = EventCode;
494 
495  if ( index < 0 && index >= num_events )
496  return PAPI_ENOEVNT;
497  _local_strlcpy( name, powercap_ntv_events[index].description, len );
498  return PAPI_OK;
499 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
static int num_events
static char * _local_strlcpy(char *dst, const char *src, size_t size)
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static _powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
Here is the call graph for this function:

◆ _powercap_ntv_code_to_info()

static int _powercap_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)
static

Definition at line 501 of file linux-powercap.c.

502 {
503  int index = EventCode;
504 
505  if ( index < 0 || index >= num_events )
506  return PAPI_ENOEVNT;
507 
508  _local_strlcpy( info->symbol, powercap_ntv_events[index].name, sizeof( info->symbol ));
509  _local_strlcpy( info->long_descr, powercap_ntv_events[index].description, sizeof( info->long_descr ) );
510  _local_strlcpy( info->units, powercap_ntv_events[index].units, sizeof( info->units ) );
511 
513  return PAPI_OK;
514 }
#define PAPI_OK
Definition: fpapi.h:105
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:976
static int num_events
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:970
char name[PAPI_MAX_STR_LEN]
static char * _local_strlcpy(char *dst, const char *src, size_t size)
char units[PAPI_MIN_STR_LEN]
char description[PAPI_MAX_STR_LEN]
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:967
#define PAPI_ENOEVNT
Definition: fpapi.h:112
int return_type
static _powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
Here is the call graph for this function:

◆ _powercap_ntv_code_to_name()

static int _powercap_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)
static

Definition at line 477 of file linux-powercap.c.

478 {
479  int index = EventCode & PAPI_NATIVE_AND_MASK;
480 
481  if ( index >= 0 && index < num_events ) {
483  return PAPI_OK;
484  }
485  return PAPI_ENOEVNT;
486 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
static int num_events
static char * _local_strlcpy(char *dst, const char *src, size_t size)
#define PAPI_ENOEVNT
Definition: fpapi.h:112
#define PAPI_NATIVE_AND_MASK
static _powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
Here is the call graph for this function:

◆ _powercap_ntv_enum_events()

static int _powercap_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)
static

Definition at line 454 of file linux-powercap.c.

455 {
456  int index;
457  switch ( modifier ) {
458 
459  case PAPI_ENUM_FIRST:
460  *EventCode = 0;
461  return PAPI_OK;
462  case PAPI_ENUM_EVENTS:index = *EventCode;
463  if (index < num_events - 1) {
464  *EventCode = *EventCode + 1;
465  return PAPI_OK;
466  } else {
467  return PAPI_ENOEVNT;
468  }
469 
470  default:return PAPI_EINVAL;
471  }
472 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
static int num_events
#define PAPI_ENOEVNT
Definition: fpapi.h:112

◆ _powercap_read()

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

Definition at line 322 of file linux-powercap.c.

324 {
325  SUBDBG("Enter _powercap_read\n");
326 
327  (void) flags;
329  _powercap_context_t* context = ( _powercap_context_t* ) ctx;
330 
331  long long start_val = 0;
332  long long curr_val = 0;
333  int c;
334 
335  for( c = 0; c < num_events; c++ ) {
336  start_val = context->start_value[c];
337  curr_val = read_powercap_value(c);
338 
339  SUBDBG("%d, start value: %lld, current value %lld\n", c, start_val, curr_val);
340 
341  if(start_val) {
342 
343  /* Make sure an event is a counter. */
344  if (control->need_difference[c] == 1) {
345 
346  /* Wraparound. */
347  if(start_val > curr_val) {
348  SUBDBG("Wraparound!\nstart value:\t%lld,\tcurrent value:%lld\n", start_val, curr_val);
349  curr_val += (0x100000000 - start_val);
350  }
351  /* Normal subtraction. */
352  else if (start_val < curr_val) {
353  SUBDBG("Normal subtraction!\nstart value:\t%lld,\tcurrent value:%lld\n", start_val, curr_val);
354  curr_val -= start_val;
355  }
356  SUBDBG("Final value: %lld\n", curr_val);
357 
358  }
359  }
360  control->count[c]=curr_val;
361  }
362 
363  *events = ( ( _powercap_control_state_t* ) ctl )->count;
364 
365  return PAPI_OK;
366 }
#define PAPI_OK
Definition: fpapi.h:105
static int num_events
long long start_value[POWERCAP_MAX_COUNTERS]
double c
Definition: multiplex.c:22
char events[MAX_EVENTS][BUFSIZ]
static long long read_powercap_value(int index)
long long count[POWERCAP_MAX_COUNTERS]
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
long long need_difference[POWERCAP_MAX_COUNTERS]
Here is the call graph for this function:

◆ _powercap_reset()

static int _powercap_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

445 {
446  ( void ) ctx;
447  ( void ) ctl;
448  return PAPI_OK;
449 }
#define PAPI_OK
Definition: fpapi.h:105

◆ _powercap_set_domain()

static int _powercap_set_domain ( hwd_control_state_t ctl,
int  domain 
)
static

Definition at line 434 of file linux-powercap.c.

435 {
436  ( void ) ctl;
437  if ( PAPI_DOM_ALL != domain )
438  return PAPI_EINVAL;
439 
440  return PAPI_OK;
441 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
#define PAPI_DOM_ALL
Definition: fpapi.h:25

◆ _powercap_shutdown_component()

static int _powercap_shutdown_component ( void  )
static

Definition at line 387 of file linux-powercap.c.

388 {
389  int i;
390 
391  /* Read counters into expected slot */
392  for(i=0;i<num_events;i++) {
393  close(event_fds[i]);
394  }
395  return PAPI_OK;
396 }
#define PAPI_OK
Definition: fpapi.h:105
int close(int fd)
Definition: appio.c:175
static int num_events
static int event_fds[POWERCAP_MAX_COUNTERS]
int i
Definition: fileop.c:140
Here is the call graph for this function:

◆ _powercap_shutdown_thread()

static int _powercap_shutdown_thread ( hwd_context_t ctx)
static

Definition at line 313 of file linux-powercap.c.

314 {
315  ( void ) ctx;
316  SUBDBG( "Enter\n" );
317  return PAPI_OK;
318 }
#define PAPI_OK
Definition: fpapi.h:105
#define SUBDBG(format, args...)
Definition: papi_debug.h:63

◆ _powercap_start()

static int _powercap_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 291 of file linux-powercap.c.

292 {
293  _powercap_context_t* context = ( _powercap_context_t* ) ctx;
294  (void) ctl;
295 
296  int b;
297  for( b = 0; b < num_events; b++ ) {
298  context->start_value[b]=read_powercap_value(b);
299  }
300 
301  return PAPI_OK;
302 }
#define PAPI_OK
Definition: fpapi.h:105
static int num_events
long long start_value[POWERCAP_MAX_COUNTERS]
static long long read_powercap_value(int index)
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
Here is the call graph for this function:

◆ _powercap_stop()

static int _powercap_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 304 of file linux-powercap.c.

305 {
306  (void) ctx;
307  (void) ctl;
308  return PAPI_OK;
309 }
#define PAPI_OK
Definition: fpapi.h:105

◆ _powercap_update_control_state()

static int _powercap_update_control_state ( hwd_control_state_t ctl,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)
static

Definition at line 414 of file linux-powercap.c.

417 {
418  (void) ctx;
419  int i, index;
420 
422  if (count==0) return PAPI_OK;
423 
424  for( i = 0; i < count; i++ ) {
425  index = native[i].ni_event;
426  control->which_counter[i]=index;
427  native[i].ni_position = i;
428  }
429 
430  return PAPI_OK;
431 
432 }
#define PAPI_OK
Definition: fpapi.h:105
long long which_counter[POWERCAP_MAX_COUNTERS]
static int native
static long count
int i
Definition: fileop.c:140

◆ _powercap_write()

static int _powercap_write ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long *  values 
)
static

Definition at line 368 of file linux-powercap.c.

369 {
370  /* write values */
371  ( void ) ctx;
373 
374  int i;
375 
376  for(i=0;i<num_events;i++) {
379  }
380  }
381 
382  return PAPI_OK;
383 }
#define PAPI_OK
Definition: fpapi.h:105
static int num_events
long long which_counter[POWERCAP_MAX_COUNTERS]
static int write_powercap_value(int index, long long value)
#define PKG_POWER_LIMIT_A
int type
static _powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int i
Definition: fileop.c:140
#define PKG_POWER_LIMIT_B
Here is the call graph for this function:

◆ read_powercap_value()

static long long read_powercap_value ( int  index)
static

Definition at line 120 of file linux-powercap.c.

121 {
122  int sz = pread(event_fds[index], read_buff, PAPI_MAX_STR_LEN, 0);
123  read_buff[sz] = '\0';
124 
125  return atoll(read_buff);
126 }
static int event_fds[POWERCAP_MAX_COUNTERS]
static char read_buff[PAPI_MAX_STR_LEN]
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
int sz
Definition: fileop.c:80
Here is the caller graph for this function:

◆ write_powercap_value()

static int write_powercap_value ( int  index,
long long  value 
)
static

Definition at line 128 of file linux-powercap.c.

129 {
130  snprintf(write_buff, sizeof(write_buff), "%lld", value);
131  int sz = pwrite(event_fds[index], write_buff, PAPI_MAX_STR_LEN, 0);
132  if(sz == -1) {
133  perror("Error in pwrite(): ");
134  }
135  return 1;
136 }
static char write_buff[PAPI_MAX_STR_LEN]
static int event_fds[POWERCAP_MAX_COUNTERS]
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
int sz
Definition: fileop.c:80
Here is the caller graph for this function:

Variable Documentation

◆ _powercap_vector

papi_vector_t _powercap_vector

Definition at line 106 of file linux-powercap.c.

◆ component_event_names

char* component_event_names[COMPONENT_NUM_EVENTS] = {"ENERGY_UJ", "MAX_ENERGY_RANGE_UJ", "MAX_POWER_A_UW", "POWER_LIMIT_A_UW", "TIME_WINDOW_A_US", "ENABLED", "NAME"}
static

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

◆ component_events

◆ component_sys_flags

mode_t component_sys_flags[COMPONENT_NUM_EVENTS] = {O_RDONLY, O_RDONLY, O_RDONLY, O_RDWR, O_RDONLY, O_RDONLY, O_RDONLY}
static

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

◆ component_sys_names

char* component_sys_names[COMPONENT_NUM_EVENTS] = {"energy_uj", "max_energy_range_uj", "constraint_0_max_power_uw", "constraint_0_power_limit_uw", "constraint_0_time_window_us", "enabled", "name"}
static

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

◆ event_fds

int event_fds[POWERCAP_MAX_COUNTERS]
static

Definition at line 92 of file linux-powercap.c.

◆ num_events

int num_events =0
static

Definition at line 52 of file linux-powercap.c.

◆ pkg_event_names

char* pkg_event_names[PKG_NUM_EVENTS] = {"ENERGY_UJ", "MAX_ENERGY_RANGE_UJ", "MAX_POWER_A_UW", "POWER_LIMIT_A_UW", "TIME_WINDOW_A_US", "MAX_POWER_B_UW", "POWER_LIMIT_B_UW", "TIME_WINDOW_B", "ENABLED", "NAME"}
static

Definition at line 68 of file linux-powercap.c.

◆ pkg_events

◆ pkg_sys_flags

mode_t pkg_sys_flags[PKG_NUM_EVENTS] = {O_RDONLY, O_RDONLY, O_RDONLY, O_RDWR, O_RDONLY, O_RDONLY, O_RDWR, O_RDONLY, O_RDONLY, O_RDONLY}
static

Definition at line 70 of file linux-powercap.c.

◆ pkg_sys_names

char* pkg_sys_names[PKG_NUM_EVENTS] = {"energy_uj", "max_energy_range_uj", "constraint_0_max_power_uw", "constraint_0_power_limit_uw", "constraint_0_time_window_us", "constraint_1_max_power_uw", "constraint_1_power_limit_uw", "constraint_1_time_window_us", "enabled", "name"}
static

Definition at line 69 of file linux-powercap.c.

◆ powercap_ntv_events

_powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
static

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

◆ read_buff

char read_buff[PAPI_MAX_STR_LEN]
static

Definition at line 49 of file linux-powercap.c.

◆ write_buff

char write_buff[PAPI_MAX_STR_LEN]
static

Definition at line 50 of file linux-powercap.c.