PAPI 7.1.0.0
Loading...
Searching...
No Matches
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 HANDLE_STRING_ERROR   {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);}
 
#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 long long map_index_to_counter (hwd_control_state_t *ctl, int index)
 
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 long long max_pkg_energy_count
 
static long long max_component_energy_count
 
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.

Author
PAPI team UTK/ICL

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 85 of file linux-powercap.c.

◆ COMPONENT_ENERGY

#define COMPONENT_ENERGY   10

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

◆ COMPONENT_MAX_ENERGY_RANGE

#define COMPONENT_MAX_ENERGY_RANGE   11

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

◆ COMPONENT_MAX_POWER_A

#define COMPONENT_MAX_POWER_A   12

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

◆ COMPONENT_NAME

#define COMPONENT_NAME   16

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

◆ COMPONENT_NUM_EVENTS

#define COMPONENT_NUM_EVENTS   7

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

◆ COMPONENT_POWER_LIMIT_A

#define COMPONENT_POWER_LIMIT_A   13

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

◆ COMPONENT_TIME_WINDOW_A

#define COMPONENT_TIME_WINDOW_A   14

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

◆ HANDLE_STRING_ERROR

#define HANDLE_STRING_ERROR   {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);}

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

◆ PKG_ENABLED

#define PKG_ENABLED   8

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

◆ PKG_ENERGY

#define PKG_ENERGY   0

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

◆ PKG_MAX_ENERGY_RANGE

#define PKG_MAX_ENERGY_RANGE   1

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

◆ PKG_MAX_POWER_A

#define PKG_MAX_POWER_A   2

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

◆ PKG_MAX_POWER_B

#define PKG_MAX_POWER_B   5

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

◆ PKG_NAME

#define PKG_NAME   9

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

◆ PKG_NUM_EVENTS

#define PKG_NUM_EVENTS   10

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

◆ PKG_POWER_LIMIT_A

#define PKG_POWER_LIMIT_A   3

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

◆ PKG_POWER_LIMIT_B

#define PKG_POWER_LIMIT_B   6

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

◆ PKG_TIME_WINDOW_A

#define PKG_TIME_WINDOW_A   4

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

◆ PKG_TIME_WINDOW_B

#define PKG_TIME_WINDOW_B   7

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

◆ POWERCAP_MAX_COUNTERS

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

Definition at line 94 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 127 of file linux-powercap.c.

128{
129 char *retval = strncpy( dst, src, size );
130 if ( size>0 ) dst[size-1] = '\0';
131 return( retval );
132}
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 488 of file linux-powercap.c.

489{
490 SUBDBG( "Enter: ctx: %p\n", ctx );
491 ( void ) ctx;
492 ( void ) code;
493 ( void ) option;
494
495 return PAPI_OK;
496}
#define PAPI_OK
Definition: f90papi.h:73
#define SUBDBG(format, args...)
Definition: papi_debug.h:64

◆ _powercap_init_component()

static int _powercap_init_component ( int  cidx)
static

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

167{
168 int retval = PAPI_OK;
169 int num_sockets = -1;
170 int s = -1, e = -1, c = -1;
171 long unsigned int strErr;
172
173 char events_dir[128];
174 char event_path[128];
175 char *strCpy;
176
177 DIR *events;
178
179 // get hw info
180 const PAPI_hw_info_t *hw_info;
182
183 // check if intel processor
185 strCpy=strncpy(_powercap_vector.cmp_info.disabled_reason, "Not an Intel processor", PAPI_MAX_STR_LEN);
186 if (strCpy == NULL) HANDLE_STRING_ERROR;
188 goto fn_fail;
189 }
190
191 // store number of sockets for adding events
192 num_sockets = hw_info->sockets;
193
194 num_events = 0;
195 for(s = 0; s < num_sockets; s++) {
196
197 // Find the directory corresponding to the socket number. There may be other top-level entries in there
198 // besides packages, such as "psys", that mess up the numbering, so we conduct an exhaustive search.
199 int s_dir, found = 0;
200 for(s_dir = 0; ; s_dir++) {
201 strErr=snprintf(event_path, sizeof(event_path), "/sys/class/powercap/intel-rapl:%d/%s", s_dir, pkg_sys_names[PKG_NAME]);
202 event_path[sizeof(event_path)-1]=0;
203 if (strErr > sizeof(event_path)) HANDLE_STRING_ERROR;
204
205 int event_fd;
206 event_fd = open(event_path, pkg_sys_flags[PKG_NAME]);
207 if (event_fd == -1) { break; }
208
209 int sz = pread(event_fd, read_buff, PAPI_MAX_STR_LEN, 0);
210 read_buff[sz] = '\0';
212
213 if (strncmp(read_buff, "package-", strlen("package-")) == 0 && strtol(read_buff + strlen("package-"), NULL, 10) == s) {
214 found = 1;
215 break;
216 }
217 }
218 if (!found) { continue; }
219
220 // compose string of a pkg directory path
221 strErr=snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d/", s_dir);
222 events_dir[sizeof(events_dir)-1]=0;
223 if (strErr > sizeof(events_dir)) HANDLE_STRING_ERROR;
224
225 // open directory to make sure it exists
226 events = opendir(events_dir);
227
228 // not a valid pkg/component directory so continue
229 if (events == NULL) { continue; }
230 closedir(events); // opendir has mallocs; so clean up.
231
232 // loop through pkg events and create powercap event entries
233 for (e = 0; e < PKG_NUM_EVENTS; e++) {
234
235 // compose string to individual event
236 strErr=snprintf(event_path, sizeof(event_path), "%s%s", events_dir, pkg_sys_names[e]);
237 event_path[sizeof(event_path)-1]=0;
238 if (strErr > sizeof(event_path)) HANDLE_STRING_ERROR;
239 // not a valid pkg event path so continue
240
241 if (access(event_path, R_OK) == -1) { continue; }
242
243 strErr=snprintf(powercap_ntv_events[num_events].name, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d", pkg_event_names[e], s);
246 //snprintf(powercap_ntv_events[num_events].description, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d", pkg_event_names[e], s);
247 //snprintf(powercap_ntv_events[num_events].units, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d", pkg_event_names[e], s);
250
252
253 event_fds[num_events] = open(event_path, O_SYNC|pkg_sys_flags[e]);
254
256 int sz = pread(event_fds[num_events], read_buff, PAPI_MAX_STR_LEN, 0);
257 read_buff[sz] = '\0';
258 strErr=snprintf(powercap_ntv_events[num_events].description, sizeof(powercap_ntv_events[num_events].description), "%s", read_buff);
260 if (strErr > sizeof(powercap_ntv_events[num_events].description)) HANDLE_STRING_ERROR;
261 }
262
264 int sz = pread(event_fds[num_events], read_buff, PAPI_MAX_STR_LEN, 0);
265 read_buff[sz] = '\0';
267 }
268
269 num_events++;
270 }
271
272 // reset component count for each socket
273 c = 0;
274 strErr=snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d:%d/", s_dir, c);
275 events_dir[sizeof(events_dir)-1]=0;
276 if (strErr > sizeof(events_dir)) HANDLE_STRING_ERROR;
277 while((events = opendir(events_dir)) != NULL) {
278 closedir(events); // opendir has mallocs; so clean up.
279
280 // loop through pkg events and create powercap event entries
281 for (e = 0; e < COMPONENT_NUM_EVENTS; e++) {
282
283 // compose string to individual event
284 strErr=snprintf(event_path, sizeof(event_path), "%s%s", events_dir, component_sys_names[e]);
285 event_path[sizeof(event_path)-1]=0;
286 if (strErr > sizeof(event_path)) HANDLE_STRING_ERROR;
287
288 // not a valid pkg event path so continue
289 if (access(event_path, R_OK) == -1) { continue; }
290
291 strErr=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);
294 //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);
295 //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);
298
300
301 event_fds[num_events] = open(event_path, O_SYNC|component_sys_flags[e]);
302
304 int sz = pread(event_fds[num_events], read_buff, PAPI_MAX_STR_LEN, 0);
305 read_buff[sz] = '\0';
306 strErr=snprintf(powercap_ntv_events[num_events].description, sizeof(powercap_ntv_events[num_events].description), "%s", read_buff);
308 if (strErr > sizeof(powercap_ntv_events[num_events].description)) HANDLE_STRING_ERROR;
309 }
310
312 int sz = pread(event_fds[num_events], read_buff, PAPI_MAX_STR_LEN, 0);
313 read_buff[sz] = '\0';
315 }
316
317 num_events++;
318 }
319
320 // test for next component
321 c++;
322
323 // compose string of an pkg directory path
324 strErr=snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d:%d/", s_dir, c);
325 events_dir[sizeof(events_dir)-1]=0;
326 if (strErr > sizeof(events_dir)) HANDLE_STRING_ERROR;
327 }
328 }
329
330 /* Export the total number of events available */
334
335 /* Export the component id */
337
338 fn_exit:
339 _papi_hwd[cidx]->cmp_info.disabled = retval;
340 return retval;
341 fn_fail:
342 goto fn_exit;
343}
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:188
int close(int fd)
Definition: appio.c:179
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
double s
Definition: byte_profile.c:36
struct papi_vectors * _papi_hwd[]
#define PAPI_VENDOR_INTEL
Definition: f90papi.h:275
#define PAPI_ENOSUPP
Definition: f90papi.h:244
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_DATATYPE_UINT64
Definition: f90papi.h:278
char events[MAX_EVENTS][BUFSIZ]
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
static _powercap_native_event_entry_t powercap_ntv_events[(2 *(PKG_NUM_EVENTS+(3 *COMPONENT_NUM_EVENTS)))]
static char read_buff[PAPI_MAX_STR_LEN]
papi_vector_t _powercap_vector
static char * component_event_names[COMPONENT_NUM_EVENTS]
static int num_events
#define PKG_NUM_EVENTS
#define PKG_NAME
#define PKG_MAX_ENERGY_RANGE
static long long max_component_energy_count
static int component_events[COMPONENT_NUM_EVENTS]
static char * pkg_event_names[PKG_NUM_EVENTS]
static int event_fds[POWERCAP_MAX_COUNTERS]
static char * pkg_sys_names[PKG_NUM_EVENTS]
static mode_t pkg_sys_flags[PKG_NUM_EVENTS]
static int pkg_events[PKG_NUM_EVENTS]
#define COMPONENT_MAX_ENERGY_RANGE
#define COMPONENT_NAME
#define COMPONENT_NUM_EVENTS
static char * component_sys_names[COMPONENT_NUM_EVENTS]
static long long max_pkg_energy_count
static mode_t component_sys_flags[COMPONENT_NUM_EVENTS]
#define HANDLE_STRING_ERROR
static int event_fd
uint16_t type
static int cidx
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
const char * name
Definition: rocs.c:225
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
Hardware info structure.
Definition: papi.h:774
int sockets
Definition: papi.h:778
int vendor
Definition: papi.h:781
int type
int return_type
char name[PAPI_MAX_STR_LEN]
char description[PAPI_MAX_STR_LEN]
_powercap_register_t resources
unsigned int selector
PAPI_hw_info_t hw_info
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
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 350 of file linux-powercap.c.

351{
353 memset( control, 0, sizeof ( _powercap_control_state_t ) );
354
355
356 /* if an event is a counter, set its corresponding flag to 1 */
357 int i;
358 for (i = 0; i < num_events; i++) {
360 control->need_difference[i] = 1;
361 }
362 }
363
364 return PAPI_OK;
365}
int i
#define PKG_ENERGY
#define COMPONENT_ENERGY
long long need_difference[POWERCAP_MAX_COUNTERS]

◆ _powercap_init_thread()

static int _powercap_init_thread ( hwd_context_t ctx)
static

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

158{
159 ( void ) ctx;
160 return PAPI_OK;
161}

◆ _powercap_ntv_code_to_descr()

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

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

579{
580 int index = EventCode;
581
582 if ( index < 0 && index >= num_events )
583 return PAPI_ENOEVNT;
584 _local_strlcpy( name, powercap_ntv_events[index].description, len );
585 return PAPI_OK;
586}
#define PAPI_ENOEVNT
Definition: f90papi.h:139
static char * _local_strlcpy(char *dst, const char *src, size_t size)
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 588 of file linux-powercap.c.

589{
590 int index = EventCode;
591
592 if ( index < 0 || index >= num_events )
593 return PAPI_ENOEVNT;
594
598
600 return PAPI_OK;
601}
#define PAPI_MIN_STR_LEN
Definition: f90papi.h:208
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
char units[PAPI_MIN_STR_LEN]
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 564 of file linux-powercap.c.

565{
566 int index = EventCode & PAPI_NATIVE_AND_MASK;
567
568 if ( index >= 0 && index < num_events ) {
570 return PAPI_OK;
571 }
572 return PAPI_ENOEVNT;
573}
#define PAPI_NATIVE_AND_MASK
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 541 of file linux-powercap.c.

542{
543 int index;
544 switch ( modifier ) {
545
546 case PAPI_ENUM_FIRST:
547 *EventCode = 0;
548 return PAPI_OK;
549 case PAPI_ENUM_EVENTS:index = *EventCode;
550 if (index < num_events - 1) {
551 *EventCode = *EventCode + 1;
552 return PAPI_OK;
553 } else {
554 return PAPI_ENOEVNT;
555 }
556
557 default:return PAPI_EINVAL;
558 }
559}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_EINVAL
Definition: f90papi.h:115

◆ _powercap_read()

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

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

400{
401 SUBDBG("Enter _powercap_read\n");
402
403 (void) flags;
405 _powercap_context_t* context = ( _powercap_context_t* ) ctx;
406
407 long long start_val = 0;
408 long long curr_val = 0;
409 int c, i;
410
411 for( c = 0; c < control->active_counters; c++ ) {
412 i = map_index_to_counter(ctl, c);
413 start_val = context->start_value[i];
414 curr_val = read_powercap_value(i);
415
416 SUBDBG("%d, start value: %lld, current value %lld\n", i, start_val, curr_val);
417
418 if(start_val) {
419
420 /* Make sure an event is a counter. */
421 if (control->need_difference[i] == 1) {
422
423 /* Wraparound. */
424 if(start_val > curr_val) {
425 SUBDBG("Wraparound!\nstart value:\t%lld,\tcurrent value:%lld\n", start_val, curr_val);
427 curr_val += (max_pkg_energy_count - start_val);
428 } else if( powercap_ntv_events[i].type == COMPONENT_ENERGY ) {
429 curr_val += (max_component_energy_count - start_val);
430 } else {
431 curr_val += (0x100000000 - start_val);
432 }
433 }
434
435 /* Normal subtraction. */
436 else if (start_val < curr_val) {
437 SUBDBG("Normal subtraction!\nstart value:\t%lld,\tcurrent value:%lld\n", start_val, curr_val);
438 curr_val -= start_val;
439 }
440 SUBDBG("Final value: %lld\n", curr_val);
441
442 }
443 }
444 control->count[c]=curr_val;
445 }
446
447 *events = ( ( _powercap_control_state_t* ) ctl )->count;
448
449 return PAPI_OK;
450}
static long long map_index_to_counter(hwd_control_state_t *ctl, int index)
static long long read_powercap_value(int index)
long long start_value[POWERCAP_MAX_COUNTERS]
long long count[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 531 of file linux-powercap.c.

532{
533 ( void ) ctx;
534 ( void ) ctl;
535 return PAPI_OK;
536}

◆ _powercap_set_domain()

static int _powercap_set_domain ( hwd_control_state_t ctl,
int  domain 
)
static

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

522{
523 ( void ) ctl;
524 if ( PAPI_DOM_ALL != domain )
525 return PAPI_EINVAL;
526
527 return PAPI_OK;
528}
#define PAPI_DOM_ALL
Definition: f90papi.h:261

◆ _powercap_shutdown_component()

static int _powercap_shutdown_component ( void  )
static

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

473{
474 int i;
475
476 /* Read counters into expected slot */
477 for(i=0;i<num_events;i++) {
478 close(event_fds[i]);
479 }
480 return PAPI_OK;
481}
Here is the call graph for this function:

◆ _powercap_shutdown_thread()

static int _powercap_shutdown_thread ( hwd_context_t ctx)
static

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

390{
391 ( void ) ctx;
392 SUBDBG( "Enter\n" );
393 return PAPI_OK;
394}

◆ _powercap_start()

static int _powercap_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

368{
369 _powercap_context_t* context = ( _powercap_context_t* ) ctx;
370 (void) ctl;
371
372 int b;
373 for( b = 0; b < num_events; b++ ) {
375 }
376
377 return PAPI_OK;
378}
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 380 of file linux-powercap.c.

381{
382 (void) ctx;
383 (void) ctl;
384 return PAPI_OK;
385}

◆ _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 499 of file linux-powercap.c.

502{
503 (void) ctx;
504 int i, index;
505
507 control->active_counters = count;
508
509 if (count==0) return PAPI_OK;
510
511 for( i = 0; i < count; i++ ) {
512 index = native[i].ni_event;
513 control->which_counter[i]=index;
514 native[i].ni_position = i;
515 }
516
517 return PAPI_OK;
518
519}
static long count
static int native
long long which_counter[POWERCAP_MAX_COUNTERS]

◆ _powercap_write()

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

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

453{
454 /* write values */
455 ( void ) ctx;
457
458 int c, i;
459
460 for(c=0;c<control->active_counters;c++) {
461 i = map_index_to_counter(ctl, c);
464 }
465 }
466
467 return PAPI_OK;
468}
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
#define PKG_POWER_LIMIT_B
static int write_powercap_value(int index, long long value)
#define PKG_POWER_LIMIT_A
Here is the call graph for this function:

◆ map_index_to_counter()

static long long map_index_to_counter ( hwd_control_state_t ctl,
int  index 
)
static

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

120{
122
123 return control->which_counter[index];
124}
Here is the caller graph for this function:

◆ read_powercap_value()

static long long read_powercap_value ( int  index)
static

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

135{
136 int sz = pread(event_fds[index], read_buff, PAPI_MAX_STR_LEN, 0);
137 read_buff[sz] = '\0';
138
139 return atoll(read_buff);
140}
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 142 of file linux-powercap.c.

143{
144 snprintf(write_buff, sizeof(write_buff), "%lld", value);
145 int sz = pwrite(event_fds[index], write_buff, PAPI_MAX_STR_LEN, 0);
146 if(sz == -1) {
147 perror("Error in pwrite(): ");
148 }
149 return 1;
150}
static char write_buff[PAPI_MAX_STR_LEN]
Here is the caller graph for this function:

Variable Documentation

◆ _powercap_vector

papi_vector_t _powercap_vector

Definition at line 113 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 90 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 92 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 91 of file linux-powercap.c.

◆ event_fds

int event_fds[POWERCAP_MAX_COUNTERS]
static

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

◆ max_component_energy_count

long long max_component_energy_count
static

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

◆ max_pkg_energy_count

long long max_pkg_energy_count
static

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

◆ num_events

int num_events =0
static

Definition at line 58 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 74 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 76 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 75 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 96 of file linux-powercap.c.

◆ read_buff

char read_buff[PAPI_MAX_STR_LEN]
static

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

◆ write_buff

char write_buff[PAPI_MAX_STR_LEN]
static

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