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

Go to the source code of this file.

Macros

#define MAX_powercap_EVENTS   64
 Tests basic functionality of powercap component.
 
#define MATRIX_SIZE   1024
 

Functions

void run_test (int quiet)
 
int main (int argc, char **argv)
 

Variables

static double a [MATRIX_SIZE][MATRIX_SIZE]
 
static double b [MATRIX_SIZE][MATRIX_SIZE]
 
static double c [MATRIX_SIZE][MATRIX_SIZE]
 

Macro Definition Documentation

◆ MATRIX_SIZE

#define MATRIX_SIZE   1024

Definition at line 30 of file tests/powercap_basic.c.

◆ MAX_powercap_EVENTS

#define MAX_powercap_EVENTS   64
Author
PAPI team UTK/ICL Test case for powercap component

Definition at line 16 of file tests/powercap_basic.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 72 of file tests/powercap_basic.c.

73{
74 (void) argv;
75 (void) argc;
76 int retval,cid,powercap_cid=-1,numcmp;
77 int EventSet = PAPI_NULL;
78 long long *values;
79 int num_events=0;
80 int code;
82 char event_descrs[MAX_powercap_EVENTS][PAPI_HUGE_STR_LEN];
85 int r,i;
86
87 const PAPI_component_info_t *cmpinfo = NULL;
88 PAPI_event_info_t evinfo;
89 long long before_time,after_time;
90 double elapsed_time;
91
92 /* Set TESTS_QUIET variable */
93 tests_quiet( argc, argv );
94
95 /* Currently unimplemented? */
96#if 0
97 int do_wrap = 0;
98 if ( argc > 1 ) {
99 if ( strstr( argv[1], "-w" ) ) {
100 do_wrap = 1;
101 }
102 }
103#endif
104
105 /* PAPI Initialization */
107 if ( retval != PAPI_VER_CURRENT )
108 test_fail( __FILE__, __LINE__,"PAPI_library_init failed\n",retval );
109
110 if ( !TESTS_QUIET ) printf( "Trying all powercap events\n" );
111
112 numcmp = PAPI_num_components();
113
114 for( cid=0; cid<numcmp; cid++ ) {
115
116 if ( ( cmpinfo = PAPI_get_component_info( cid ) ) == NULL )
117 test_fail( __FILE__, __LINE__,"PAPI_get_component_info failed\n", 0 );
118
119 if ( strstr( cmpinfo->name,"powercap" ) ) {
120 powercap_cid=cid;
121 if ( !TESTS_QUIET ) printf( "Found powercap component at cid %d\n",powercap_cid );
122 if ( cmpinfo->disabled ) {
123 if ( !TESTS_QUIET ) {
124 printf( "powercap component disabled: %s\n",
125 cmpinfo->disabled_reason );
126 }
127 test_skip( __FILE__,__LINE__,"powercap component disabled",0 );
128 }
129 break;
130 }
131 }
132
133 /* Component not found */
134 if ( cid==numcmp )
135 test_skip( __FILE__,__LINE__,"No powercap component found\n",0 );
136
137 /* Skip if component has no counters */
138 if ( cmpinfo->num_cntrs==0 )
139 test_skip( __FILE__,__LINE__,"No counters in the powercap component\n",0 );
140
141 /* Create EventSet */
143 if ( retval != PAPI_OK )
144 test_fail( __FILE__, __LINE__, "PAPI_create_eventset()",retval );
145
146 /* Add all events */
147 code = PAPI_NATIVE_MASK;
148 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, powercap_cid );
149 while ( r == PAPI_OK ) {
151 if ( retval != PAPI_OK )
152 test_fail( __FILE__, __LINE__,"Error from PAPI_event_code_to_name", retval );
153
154 retval = PAPI_get_event_info( code,&evinfo );
155 if ( retval != PAPI_OK )
156 test_fail( __FILE__, __LINE__, "Error getting event info\n",retval );
157
158 strncpy( event_descrs[num_events],evinfo.long_descr,PAPI_HUGE_STR_LEN );
159 strncpy( units[num_events],evinfo.units,PAPI_MIN_STR_LEN );
160 // buffer must be null terminated to safely use strstr operation on it below
163 retval = PAPI_add_event( EventSet, code );
164
165 if ( retval != PAPI_OK )
166 break; /* We've hit an event limit */
167 num_events++;
168
169 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, powercap_cid );
170 }
171
172 values=calloc( num_events,sizeof( long long ) );
173 if ( values==NULL )
174 test_fail( __FILE__, __LINE__,"No memory",retval );
175
176 if ( !TESTS_QUIET ) printf( "\nStarting measurements...\n\n" );
177
178 /* Start Counting */
181 if ( retval != PAPI_OK )
182 test_fail( __FILE__, __LINE__, "PAPI_start()",retval );
183
184 /* Run test */
186
187 /* Stop Counting */
190 if ( retval != PAPI_OK )
191 test_fail( __FILE__, __LINE__, "PAPI_stop()",retval );
192
193 elapsed_time=( ( double )( after_time-before_time ) )/1.0e9;
194
195 if ( !TESTS_QUIET ) {
196 printf( "\nStopping measurements, took %.3fs, gathering results...\n\n", elapsed_time );
197
198 printf( "\n" );
199 printf( "scaled energy measurements:\n" );
200 for( i=0; i<num_events; i++ ) {
201 if ( strstr( event_names[i],"ENERGY_UJ" ) ) {
202 if ( data_type[i] == PAPI_DATATYPE_UINT64 ) {
203 printf( "%-45s%-20s%4.6f J (Average Power %.1fW)\n",
204 event_names[i], event_descrs[i],
205 ( double )values[i]/1.0e6,
206 ( ( double )values[i]/1.0e6 )/elapsed_time );
207 }
208 }
209 }
210
211 printf( "\n" );
212 printf( "energy counts:\n" );
213 for( i=0; i<num_events; i++ ) {
214 if ( strstr( event_names[i],"ENERGY_UJ" ) ) {
215 if ( data_type[i] == PAPI_DATATYPE_UINT64 ) {
216 printf( "%-45s%-20s%12lld\t%#08llx\n", event_names[i],
217 event_descrs[i],
218 values[i], values[i] );
219 }
220 }
221 }
222
223 printf( "\n" );
224 printf( "long term time window values:\n" );
225 for( i=0; i<num_events; i++ ) {
226 if ( strstr( event_names[i],"TIME_WINDOW_A_US" ) ) {
227 if ( data_type[i] == PAPI_DATATYPE_UINT64 ) {
228 printf( "%-45s%-20s%4f (secs)\n",
229 event_names[i], event_descrs[i],
230 ( double )values[i]/1.0e6 );
231 }
232 }
233 }
234
235 printf( "\n" );
236 printf( "short term time window values:\n" );
237 for( i=0; i<num_events; i++ ) {
238 if ( strstr( event_names[i],"TIME_WINDOW_B_US" ) ) {
239 if ( data_type[i] == PAPI_DATATYPE_UINT64 ) {
240 printf( "%-45s%-20s%4f (secs)\n",
241 event_names[i], event_descrs[i],
242 ( double )values[i]/1.0e6 );
243 }
244 }
245 }
246
247 printf( "\n" );
248 printf( "long term power limit:\n" );
249 for( i=0; i<num_events; i++ ) {
250 if ( strstr( event_names[i],"POWER_LIMIT_A_UW" ) ) {
251 if ( data_type[i] == PAPI_DATATYPE_UINT64 ) {
252 printf( "%-45s%-20s%4f (watts)\n",
253 event_names[i], event_descrs[i],
254 ( double )values[i]/1.0e6 );
255 }
256 }
257 }
258
259 printf( "\n" );
260 printf( "short term power limit:\n" );
261 for( i=0; i<num_events; i++ ) {
262 if ( strstr( event_names[i],"POWER_LIMIT_B_UW" ) ) {
263 if ( data_type[i] == PAPI_DATATYPE_UINT64 ) {
264 printf( "%-45s%-20s%4f (watts)\n",
265 event_names[i], event_descrs[i],
266 ( double )values[i]/1.0e6 );
267 }
268 }
269 }
270
271 }
272
273 /* Done, clean up */
274 free(values);
275
277 if ( retval != PAPI_OK )
278 test_fail( __FILE__, __LINE__,"PAPI_cleanup_eventset()",retval );
279
281 if ( retval != PAPI_OK )
282 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset()",retval );
283
284 test_pass( __FILE__ );
285
286 return 0;
287}
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.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#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_MIN_STR_LEN
Definition: f90papi.h:208
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_DATATYPE_UINT64
Definition: f90papi.h:278
#define PAPI_HUGE_STR_LEN
Definition: f90papi.h:120
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
int TESTS_QUIET
Definition: test_utils.c:18
#define PAPI_NATIVE_MASK
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int data_type[MAX_EVENTS]
Definition: powercap_plot.c:16
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
static long long after_time
Definition: rapl_overflow.c:15
static long long before_time
Definition: rapl_overflow.c:15
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
#define MAX_powercap_EVENTS
Tests basic functionality of powercap component.
void run_test(int quiet)
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ run_test()

void run_test ( int  quiet)

Definition at line 36 of file tests/powercap_basic.c.

37{
38 double s;
39 int i,j,k;
40
41 if ( !quiet ) printf( "Doing a naive %dx%d MMM...\n",MATRIX_SIZE,MATRIX_SIZE );
42
43 for( i=0; i<MATRIX_SIZE; i++ ) {
44 for( j=0; j<MATRIX_SIZE; j++ ) {
45 a[i][j]=( double )i*( double )j;
46 b[i][j]=( double )i/( double )( j+5 );
47 }
48 }
49
50 for( j=0; j<MATRIX_SIZE; j++ ) {
51 for( i=0; i<MATRIX_SIZE; i++ ) {
52 s=0;
53 for( k=0; k<MATRIX_SIZE; k++ ) {
54 s+=a[i][k]*b[k][j];
55 }
56 c[i][j] = s;
57 }
58 }
59
60 s=0.0;
61 for( i=0; i<MATRIX_SIZE; i++ ) {
62 for( j=0; j<MATRIX_SIZE; j++ ) {
63 s+=c[i][j];
64 }
65 }
66
67 if ( !quiet ) printf( "Matrix multiply sum: s=%lf\n",s );
68}
double s
Definition: byte_profile.c:36
int quiet
Definition: rapl_overflow.c:19
static double a[MATRIX_SIZE][MATRIX_SIZE]
static double b[MATRIX_SIZE][MATRIX_SIZE]
#define MATRIX_SIZE
static double c[MATRIX_SIZE][MATRIX_SIZE]
Here is the caller graph for this function:

Variable Documentation

◆ a

double a[MATRIX_SIZE][MATRIX_SIZE]
static

Definition at line 31 of file tests/powercap_basic.c.

◆ b

double b[MATRIX_SIZE][MATRIX_SIZE]
static

Definition at line 32 of file tests/powercap_basic.c.

◆ c

double c[MATRIX_SIZE][MATRIX_SIZE]
static

Definition at line 33 of file tests/powercap_basic.c.