PAPI  5.7.0.0
powercap_limit.c File Reference
Include dependency graph for powercap_limit.c:

Go to the source code of this file.

Macros

#define MAX_powercap_EVENTS   64
 Tests basic functionality of powercap component. More...
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ MAX_powercap_EVENTS

#define MAX_powercap_EVENTS   64
Author
Philip Vaccaro Test case for powercap component

Definition at line 16 of file powercap_limit.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 18 of file powercap_limit.c.

19 {
20  (void) argv;
21  (void) argc;
22  int retval,cid,powercap_cid=-1,numcmp;
23  int EventSet = PAPI_NULL;
24  long long values[MAX_powercap_EVENTS];
25  int limit_map[MAX_powercap_EVENTS];
26  int num_events=0, num_limits=0;
27  int code;
28  char event_names[MAX_powercap_EVENTS][PAPI_MAX_STR_LEN];
29  int r,i;
30 
31  const PAPI_component_info_t *cmpinfo = NULL;
32 
33  /* PAPI Initialization */
35  if ( retval != PAPI_VER_CURRENT )
36  test_fail( __FILE__, __LINE__,"PAPI_library_init()\n",retval );
37 
38  if ( !TESTS_QUIET ) printf( "Trying all powercap events\n" );
39 
40  numcmp = PAPI_num_components();
41 
42  for( cid=0; cid<numcmp; cid++ ) {
43 
44  if ( ( cmpinfo = PAPI_get_component_info( cid ) ) == NULL )
45  test_fail( __FILE__, __LINE__,"PAPI_get_component_info()\n", 0 );
46 
47  if ( strstr( cmpinfo->name,"powercap" ) ) {
48  powercap_cid=cid;
49  if ( !TESTS_QUIET ) printf( "Found powercap component at cid %d\n",powercap_cid );
50  if ( cmpinfo->disabled ) {
51  if ( !TESTS_QUIET ) {
52  printf( "powercap component disabled: %s\n",
53  cmpinfo->disabled_reason );
54  }
55  test_skip( __FILE__,__LINE__,"powercap component disabled",0 );
56  }
57  break;
58  }
59  }
60 
61  /* Component not found */
62  if ( cid==numcmp )
63  test_skip( __FILE__,__LINE__,"No powercap component found\n",0 );
64 
65  /* Skip if component has no counters */
66  if ( cmpinfo->num_cntrs==0 )
67  test_skip( __FILE__,__LINE__,"No counters in the powercap component\n",0 );
68 
69  /* Create EventSet */
71  if ( retval != PAPI_OK )
72  test_fail( __FILE__, __LINE__, "PAPI_create_eventset()",retval );
73 
74  /* Add all package limit events */
75  code = PAPI_NATIVE_MASK;
76  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, powercap_cid );
77 
78 
79  /* find all package power events */
80  while ( r == PAPI_OK ) {
81  retval = PAPI_event_code_to_name( code, event_names[num_events] );
82  if ( retval != PAPI_OK )
83  test_fail( __FILE__, __LINE__,"PAPI_event_code_to_name()", retval );
84 
86  if (retval != PAPI_OK)
87  break; /* We've hit an event limit */
88 
89  if (!(strstr(event_names[num_events],"SUBZONE")) && (strstr(event_names[num_events],"POWER_LIMIT"))) {
90 
91  limit_map[num_limits] = num_events;
92  num_limits++;
93  }
94  num_events++;
95  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, powercap_cid );
96  }
97 
98 
99  /* start collecting power data */
101  if ( retval != PAPI_OK )
102  test_fail( __FILE__, __LINE__, "PAPI_start()",retval );
103 
104  /* initial read of package limits */
106  if ( retval != PAPI_OK )
107  test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
108 
109 
110  printf("\nCURRENT LIMITS\n");
111  for( i=0; i<num_limits; i++ ) {
112  printf("EVENT: %s\tLIMIT: %0.2lf Watts\n", event_names[limit_map[i]], ((double)values[limit_map[i]]*1e-6));
113  values[limit_map[i]] = values[limit_map[i]] - (10 * 1e6); //minus 10 Watts
114  }
115  usleep(10000);
116 
117  printf("\nSETTING LIMITS 10 WATTS BELOW CURRENT LIMITS\n");
119  if ( retval != PAPI_OK )
120  test_fail( __FILE__, __LINE__, "PAPI_write()",retval );
121 
122  usleep(10000);
123 
124  printf("\nREADING LIMITS TO MAKE SURE THEY ARE SET\n");
126  if ( retval != PAPI_OK )
127  test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
128  usleep(10000);
129 
130  printf("\nNEW LIMITS\n");
131  for( i=0; i<num_limits; i++ ) {
132  printf("EVENT: %s\tLIMIT: %0.2lf Watts\n", event_names[limit_map[i]], ((double)values[limit_map[i]]*1e-6));
133  values[limit_map[i]] = values[limit_map[i]] + (10 * 1e6); //plus 10 Watts
134  }
135 
136  printf("\nRESET LIMITS BEFORE EXITING...");
138  if ( retval != PAPI_OK )
139  test_fail( __FILE__, __LINE__, "PAPI_write()",retval );
140  usleep(10000);
141 
142  printf("\nREADING RESET LIMITS TO MAKE SURE THEY ARE SET\n");
144  if ( retval != PAPI_OK )
145  test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
146  usleep(10000);
147 
148  printf("\nRESET LIMITS\n");
149  for( i=0; i<num_limits; i++ ) {
150  printf("EVENT: %s\tLIMIT: %0.2lf Watts\n", event_names[limit_map[i]], ((double)values[limit_map[i]]*1e-6));
151  }
152 
153  printf("done\n");
154 
156  if ( retval != PAPI_OK )
157  test_fail( __FILE__, __LINE__, "PAPI_stop()",retval );
158 
159  /* Done, clean up */
161  if ( retval != PAPI_OK )
162  test_fail( __FILE__, __LINE__,"PAPI_cleanup_eventset()",retval );
163 
165  if ( retval != PAPI_OK )
166  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset()",retval );
167 
168  test_pass( __FILE__ );
169 
170  return 0;
171 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define PAPI_NATIVE_MASK
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:637
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
int PAPI_write(int EventSet, long long *values)
Definition: papi.c:2813
static int num_events
int PAPI_num_components(void)
Definition: papi.c:4387
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet
int retval
Definition: zero_fork.c:53
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_library_init(int version)
Definition: papi.c:500
#define PAPI_NULL
Definition: fpapi.h:13
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:630
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1357
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int TESTS_QUIET
Definition: test_utils.c:18
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define MAX_powercap_EVENTS
Tests basic functionality of powercap component.
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int i
Definition: fileop.c:140
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
Here is the call graph for this function: