19{
20 (void) argv;
21 (void) argc;
22 int retval,cid,powercap_cid=-1,numcmp;
26 int code;
29 int quiet = 1, passed = 0;
30
33
34 if (argc >= 2)
quiet = atoi(argv[1]);
35
36
39 fprintf(
stderr,
"PAPI_library_init failed\n" );
40
42
43 for( cid=0; cid<numcmp; cid++ ) {
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 );
52 printf( "powercap_ppc component disabled: %s\n",
54 }
55 fprintf(
stderr,
"powercap_ppc component disabled\n");
56 }
57 break;
58 }
59 }
60
61
62 if ( cid==numcmp )
63 fprintf(
stderr,
"No powercap_ppc component found\n" );
64
65
67 fprintf(
stderr,
"No counters in the powercap_ppc component\n" );
68
69
72 fprintf(
stderr,
"PAPI_create_eventset()\n");
73
74
80 fprintf(
stdout,
"Error from PAPI_event_code_to_name\n");
81
84 fprintf(
stderr,
"Error getting event info\n");
85
87
89 break;
91
93 }
94
96
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;
108 fprintf(
stdout,
"%-45s > %lldW\n",
110
113
116
120 }
121 }
122
123
124 if (Pmin <= Pmax) {
125 Pold = Pcurrent;
126
127 Ptarget = Pmin + 0.4 * (Pmax - Pmin);
128
129 if (Pold == Ptarget) Ptarget = Pmin + 0.6 * (Pmax - Pmin);
130
132 fprintf(
stdout,
"Current capping is Pcurrent = %lld W.\nCapping with Ptarget = %lld W\n", Pold, Ptarget);
133
134 values[iPcurrent] = Ptarget;
135
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
144 usleep(100000);
148 }
while (
values[iPcurrent] != Ptarget && (after-before) < 10e10);
149
150 if (
values[iPcurrent] != Ptarget) {
151
152 if (!
quiet) fprintf(
stdout,
"\nPcurrent read = %lld W, target was %lld W\n",
values[iPcurrent], Ptarget);
153 } else {
154
155 if (!
quiet) fprintf(
stdout,
"\nPcurrent read = %lld W, target was %lld W\n",
values[iPcurrent], Ptarget);
156
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
184 fprintf(
stdout,
"PAPI_cleanup_eventset()\n");
185
188 fprintf(
stdout,
"PAPI_destroy_eventset()\n");
189
190 return 0;
191}
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]
#define MAX_powercap_EVENTS
Tests basic functionality of powercap component.
char name[PAPI_MAX_STR_LEN]
char disabled_reason[PAPI_HUGE_STR_LEN]