16#define MAX_powercap_EVENTS 64
18int main (
int argc,
char **argv )
22 int retval,cid,powercap_cid=-1,numcmp;
29 int quiet = 1, passed = 0;
34 if (argc >= 2)
quiet = atoi(argv[1]);
39 fprintf(
stderr,
"PAPI_library_init failed\n" );
43 for( cid=0; cid<numcmp; cid++ ) {
45 fprintf(
stderr,
"PAPI_get_component_info failed\n");
47 if ( strstr( cmpinfo->
name,
"powercap_ppc" ) ) {
49 if ( !
quiet ) fprintf(
stdout,
"Found powercap_ppc component at cid %d\n",powercap_cid );
52 printf(
"powercap_ppc component disabled: %s\n",
55 fprintf(
stderr,
"powercap_ppc component disabled\n");
63 fprintf(
stderr,
"No powercap_ppc component found\n" );
67 fprintf(
stderr,
"No counters in the powercap_ppc component\n" );
72 fprintf(
stderr,
"PAPI_create_eventset()\n");
80 fprintf(
stdout,
"Error from PAPI_event_code_to_name\n");
84 fprintf(
stderr,
"Error getting event info\n");
98 if (
values==NULL ) { fprintf(
stdout,
"No memory for values");
return -1; }
100 if ( !
quiet ) fprintf(
stdout,
"\nBefore actual test...\n" );
102 long long Pmin = 424242, Pmax = 42, Pcurrent = 42, Ptarget, Pold;
108 fprintf(
stdout,
"%-45s > %lldW\n",
127 Ptarget = Pmin + 0.4 * (Pmax - Pmin);
129 if (Pold == Ptarget) Ptarget = Pmin + 0.6 * (Pmax - Pmin);
132 fprintf(
stdout,
"Current capping is Pcurrent = %lld W.\nCapping with Ptarget = %lld W\n", Pold, Ptarget);
134 values[iPcurrent] = Ptarget;
137 long long after = before;
141 if (!
quiet) fprintf(
stdout,
"Changing the power capping might take some time.\nThe test will time out after 10 seconds.\n");
148 }
while (
values[iPcurrent] != Ptarget && (after-before) < 10e10);
150 if (
values[iPcurrent] != Ptarget) {
152 if (!
quiet) fprintf(
stdout,
"\nPcurrent read = %lld W, target was %lld W\n",
values[iPcurrent], Ptarget);
155 if (!
quiet) fprintf(
stdout,
"\nPcurrent read = %lld W, target was %lld W\n",
values[iPcurrent], Ptarget);
159 if (!
quiet) fprintf(
stdout,
"Reverting back to previous capping P = %lld W\n", Pold);
164 }
while (
values[iPcurrent] != Pold);
170 fprintf(
stderr,
"Power capping values read seems wrong: Pmin = %lld W; Pmax = %lld W; Pcurrent = %lld W\n",
171 Pmin, Pmax, Pcurrent);
177 fprintf(
stdout,
"TEST SUCCESS\n");
179 fprintf(
stdout,
"TEST FAILED\n");
184 fprintf(
stdout,
"PAPI_cleanup_eventset()\n");
188 fprintf(
stdout,
"PAPI_destroy_eventset()\n");
static const char * event_names[2]
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.
static long long values[NUM_EVENTS]
Return codes and api definitions.
#define MAX_powercap_EVENTS
Tests basic functionality of powercap component.
char name[PAPI_MAX_STR_LEN]
char disabled_reason[PAPI_HUGE_STR_LEN]