PAPI 7.1.0.0
Loading...
Searching...
No Matches
ppc/tests/powercap_limit.c File Reference
Include dependency graph for ppc/tests/powercap_limit.c:

Go to the source code of this file.

Macros

#define MAX_powercap_EVENTS   64
 Tests basic functionality of powercap component.
 

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 ppc/tests/powercap_limit.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 18 of file ppc/tests/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;
25 int num_events=0;
26 int code;
28 int r,i;
29 int quiet = 1, passed = 0;
30
31 const PAPI_component_info_t *cmpinfo = NULL;
32 PAPI_event_info_t evinfo;
33
34 if (argc >= 2) quiet = atoi(argv[1]);
35
36 /* PAPI Initialization */
38 if ( retval != PAPI_VER_CURRENT )
39 fprintf( stderr, "PAPI_library_init failed\n" );
40
41 numcmp = PAPI_num_components();
42
43 for( cid=0; cid<numcmp; cid++ ) {
44 if ( ( cmpinfo = PAPI_get_component_info( cid ) ) == NULL )
45 fprintf(stderr, "PAPI_get_component_info failed\n");
46
47 if ( strstr( cmpinfo->name,"powercap_ppc" ) ) {
48 powercap_cid=cid;
49 if ( !quiet ) fprintf(stdout, "Found powercap_ppc component at cid %d\n",powercap_cid );
50 if ( cmpinfo->disabled ) {
51 if ( !quiet ) {
52 printf( "powercap_ppc component disabled: %s\n",
53 cmpinfo->disabled_reason );
54 }
55 fprintf(stderr, "powercap_ppc component disabled\n");
56 }
57 break;
58 }
59 }
60
61 /* Component not found */
62 if ( cid==numcmp )
63 fprintf(stderr, "No powercap_ppc component found\n" );
64
65 /* Skip if component has no counters */
66 if ( cmpinfo->num_cntrs==0 )
67 fprintf(stderr, "No counters in the powercap_ppc component\n" );
68
69 /* Create EventSet */
71 if ( retval != PAPI_OK )
72 fprintf(stderr, "PAPI_create_eventset()\n");
73
74 /* Add all events */
75 code = PAPI_NATIVE_MASK;
76 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, powercap_cid );
77 while ( r == PAPI_OK ) {
79 if ( retval != PAPI_OK )
80 fprintf(stdout, "Error from PAPI_event_code_to_name\n");
81
82 retval = PAPI_get_event_info( code,&evinfo );
83 if ( retval != PAPI_OK )
84 fprintf(stderr, "Error getting event info\n");
85
87
88 if (retval != PAPI_OK)
89 break; /* We've hit an event limit */
90 num_events++;
91
92 r = PAPI_enum_cmp_event(&code, PAPI_ENUM_EVENTS, powercap_cid);
93 }
94
96
97 values=calloc(num_events,sizeof(long long));
98 if ( values==NULL ) { fprintf(stdout, "No memory for values"); return -1; }
99
100 if ( !quiet ) fprintf(stdout, "\nBefore actual test...\n" );
101
102 long long Pmin = 424242, Pmax = 42, Pcurrent = 42, Ptarget, Pold;
103
105 int iPcurrent = -1;
106 for ( i = 0; i < num_events; ++i ) {
107 if (!quiet && strstr( event_names[i], "POWER"))
108 fprintf( stdout, "%-45s > %lldW\n",
109 event_names[i], values[i]);
110
111 if ( strstr( event_names[i], "MIN_POWER"))
112 Pmin = values[i];
113
114 if ( strstr( event_names[i], "MAX_POWER"))
115 Pmax = values[i];
116
117 if ( strstr( event_names[i], "CURRENT_POWER")) {
118 iPcurrent = i;
119 Pcurrent = values[i];
120 }
121 }
122
123
124 if (Pmin <= Pmax) {
125 Pold = Pcurrent;
126 /* Let's try to cap at 40% */
127 Ptarget = Pmin + 0.4 * (Pmax - Pmin);
128 /* Ok, current cap was 40%, so let's make it 60% */
129 if (Pold == Ptarget) Ptarget = Pmin + 0.6 * (Pmax - Pmin);
130
131 if ( !quiet )
132 fprintf(stdout, "Current capping is Pcurrent = %lld W.\nCapping with Ptarget = %lld W\n", Pold, Ptarget);
133
134 values[iPcurrent] = Ptarget;
135
136 long long before = PAPI_get_real_nsec();
137 long long after = before;
138
140
141 if (!quiet) fprintf(stdout, "Changing the power capping might take some time.\nThe test will time out after 10 seconds.\n");
142 do {
143 /* Give everyone some time to realize it */
144 usleep(100000);
145 after = PAPI_get_real_nsec();
147 if (!quiet) fprintf(stdout, ".");
148 } while (values[iPcurrent] != Ptarget && (after-before) < 10e10);
149
150 if (values[iPcurrent] != Ptarget) {
151 /* test failure */
152 if (!quiet) fprintf(stdout, "\nPcurrent read = %lld W, target was %lld W\n", values[iPcurrent], Ptarget);
153 } else {
154 /* we have a success here */
155 if (!quiet) fprintf(stdout, "\nPcurrent read = %lld W, target was %lld W\n", values[iPcurrent], Ptarget);
156 /* let's clean behind us, revert to previous capping */
157 values[iPcurrent] = Pold;
159 if (!quiet) fprintf(stdout, "Reverting back to previous capping P = %lld W\n", Pold);
160
161 do {
162 usleep(100000);
164 } while (values[iPcurrent] != Pold);
165 passed = 1;
166 }
167 }
168 else {
169 passed = 0;
170 fprintf(stderr, "Power capping values read seems wrong: Pmin = %lld W; Pmax = %lld W; Pcurrent = %lld W\n",
171 Pmin, Pmax, Pcurrent);
172 }
173
175
176 if (passed)
177 fprintf(stdout, "TEST SUCCESS\n");
178 else
179 fprintf(stdout, "TEST FAILED\n");
180
181 /* Done, clean up */
183 if ( retval != PAPI_OK )
184 fprintf(stdout, "PAPI_cleanup_eventset()\n");
185
187 if ( retval != PAPI_OK )
188 fprintf(stdout, "PAPI_destroy_eventset()\n");
189
190 return 0;
191}
static const char * event_names[2]
Definition: Gamum.c:27
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Convert a numeric hardware event code to a name.
get information about a specific software component
Get the event's name and description info.
Get real time counter value in nanoseconds.
initialize the PAPI library.
Get the number of components available on the system.
Read hardware counters from an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Write counter values into counters.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
#define PAPI_NATIVE_MASK
FILE * stdout
FILE * stderr
#define MAX_powercap_EVENTS
Tests basic functionality of powercap component.
int quiet
Definition: rapl_overflow.c:19
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
int retval
Definition: zero_fork.c:53