39{
40 int retval,cid,rapl_cid=-1,numcmp;
43 int i,code,enum_retval;
45 long long start_time,write_start_time,write_end_time,read_start_time,read_end_time;
47 union { long long ll; double dbl; } event_value_union;
49 FILE *fileout;
50
51
54 fprintf(
stderr,
"PAPI_library_init failed\n");
55 exit(1);
56 }
57
58
60 for(cid=0; cid<numcmp; cid++) {
62 fprintf(
stderr,
"PAPI_get_component_info failed\n");
63 exit(1);
64 }
65 if (strstr(cmpinfo->
name,
"libmsr")) {
66 rapl_cid=cid;
67 printf("Found libmsr component at cid %d\n", rapl_cid);
70 exit(1);
71 }
72 break;
73 }
74 }
75
76
77 if (cid==numcmp) {
78 fprintf(
stderr,
"No libmsr component found\n");
79 exit(1);
80 }
81
82
85 while ( enum_retval ==
PAPI_OK ) {
88 printf("Error translating %#x\n",code);
89 exit(1);
90 }
97 exit(1);
98 }
100 }
102 printf("Error! No libmsr events found!\n");
103 exit(1);
104 }
105
106
107 char fileoutname[]="libmsr_write_test_output.txt";
108 fileout=fopen( fileoutname ,"w" );
109 if ( fileout==NULL) { fprintf(
stderr,
"Could not open %s\n",fileoutname ); exit(1); }
110
111
114 fprintf(
stderr,
"Error creating eventset!\n");
115 }
116
120 }
121
123
124
127
130
131
132 fprintf( fileout, "ACTION TIME-STAMP TIME-FOR-UNIT-WORK TIME-OVERHEAD-RW\t" );
134 fprintf( fileout,
"%s ",
events[
i]+9 );
135 fprintf( fileout, "\n" );
136
137
140 fprintf( fileout,
"INIT %8.3f %8.3f ", ((
double)(
PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 );
141 fprintf( fileout, "%8.3e ", 0.0);
143 event_value_union.ll =
values[
i];
144 fprintf( fileout, "%8.3f ", event_value_union.dbl );
145 }
146 fprintf( fileout, "\n" );
147
148 int rpt=0;
149 int limit1base=10;
150 int limit2base=10;
151 while(rpt++<200) {
152
153
154 if ( rpt % 10 == 0 ) {
156 event_value_union.ll =
values[
i];
157 if ( !strcmp(
events[
i],
"libmsr:::PKG_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=limit1base+(rpt/2);
158 else if ( !strcmp(
events[
i],
"libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=1.0;
159 else if ( !strcmp(
events[
i],
"libmsr:::PKG_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=limit2base+(rpt/2);
160 else if ( !strcmp(
events[
i],
"libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=1.0;
161 else if ( !strcmp(
events[
i],
"libmsr:::PKG_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=limit1base+(rpt/2);
162 else if ( !strcmp(
events[
i],
"libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=1.0;
163 else if ( !strcmp(
events[
i],
"libmsr:::PKG_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=limit2base+(rpt/2);
164 else if ( !strcmp(
events[
i],
"libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=1.0;
166 values[
i]=event_value_union.ll;
167 }
168
173
174 fprintf( fileout,
"SET %8.3f %8.3f ", ((
double)(
PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 );
175 fprintf( fileout, "%8.3e ", ((double)(write_end_time-write_start_time))/1.0e9 );
177 event_value_union.ll =
values[
i];
178 fprintf( fileout, "%8.3f ", event_value_union.dbl );
179 }
180 fprintf( fileout, "\n" );
181 }
182
183
184
188
189
190
195 fprintf( fileout,
"READ %8.3f %8.3f ", ((
double)(
PAPI_get_real_nsec()-start_time))/1.0e9, work_time/1.0e9 );
196 fprintf( fileout, "%8.3e ", ((double)(read_end_time-read_start_time))/1.0e9 );
198 event_value_union.ll =
values[
i];
199 fprintf( fileout, "%8.3f ", event_value_union.dbl );
200 }
201 fprintf( fileout, "\n" );
202 }
203
205 return 0;
206}
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI 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 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.
char event_name[2][PAPI_MAX_STR_LEN]
static long long values[NUM_EVENTS]
char events[MAX_EVENTS][BUFSIZ]
char filenames[MAX_EVENTS][BUFSIZ]
int ompcpuloadprimes(int limit)
char name[PAPI_MAX_STR_LEN]
char disabled_reason[PAPI_HUGE_STR_LEN]