PAPI 7.1.0.0
Loading...
Searching...
No Matches
ppc64_events.c File Reference
Include dependency graph for ppc64_events.c:

Go to the source code of this file.

Functions

void perfctr_initialize_native_table ()
 
void perfctr_ppc64_setup_gps (int total, ntv_event_group_info_t *group_info)
 
int perfctr_ppc64_setup_native_table ()
 
int check_native_name ()
 
static FILE * open_file (const char *fname)
 
static ntv_event_tcopy_buffer (ntv_event_t events[], int maxevents)
 
static ntv_event_info_tparse_eventfile (FILE *evfile)
 
static int any_counter_invalid (int event_id[], int size)
 
static ntv_event_group_info_tparse_groupfile (FILE *grp_file)
 
ntv_event_info_tperfctr_get_native_evt_info (void)
 
ntv_event_group_info_tperfctr_get_native_group_info (void)
 

Variables

hwd_groups_t group_map [MAX_GROUPS]
 
native_event_entry_t native_table [PAPI_MAX_NATIVE_EVENTS]
 

Function Documentation

◆ any_counter_invalid()

static int any_counter_invalid ( int  event_id[],
int  size 
)
static

Definition at line 395 of file ppc64_events.c.

396{
397 int j;
398 for ( j = 0; j < size; j++ ) {
399 if ( event_id[j] >= PAPI_MAX_NATIVE_EVENTS )
400 return 1;
401 }
402 return 0;
403}
Here is the caller graph for this function:

◆ check_native_name()

int check_native_name ( )

Definition at line 168 of file ppc64_events.c.

169{
170 enum native_name foo;
171 int itemCount = 0;
172 int i;
173
174 /* This should ensure that the cardinality of native_name is the same
175 as that of native_name_map which may be true iff native_name
176 expresses the same data as native_name_map and there is a 1:1
177 mapping from one onto the other, though there is no guarantee of
178 order. */
180 SUBDBG( "%i is the number of elements apparently in native_name, "
181 "but really should be %i, according to native_name_map.\n",
184 ( "Inconsistent cardinality between native_name and native_name_map "
185 "detected in preliminary check\n" );
186 return PAPI_EBUG;
187 }
188
189 /* The following is sanity checking only. It attempts to verify some level
190 of consistency between native_name and native_name_map and native_table.
191 This should imply that native_name is a subset of native_name_map. */
192 for ( foo = PAPI_NATIVE_MASK; foo < NATNAME_GUARD; foo++ ) {
193 for ( i = 0; i < MAX_NATNAME_MAP_INDEX; i++ ) {
194 /* Now, if the event we are on is the native event we seek... */
195 if ( ( native_name_map[i].index | PAPI_NATIVE_MASK ) == foo ) {
196 itemCount++;
197 break;
198 }
199 }
200 }
201 if ( itemCount != MAX_NATNAME_MAP_INDEX ) {
202 SUBDBG( "Inconsistency between native_name_map and native_name. "
203 "%i events matched, but really should be %i\n", itemCount,
206 ( "Inconsistent cardinality between native_name and native_name_map\n" );
207 return PAPI_EBUG;
208 }
209
210 return PAPI_OK;
211}
int i
PPC64_native_map_t native_name_map[PAPI_MAX_NATIVE_EVENTS]
Definition: aix.c:46
#define PAPI_EBUG
Definition: f90papi.h:176
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NATIVE_MASK
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
void PAPIERROR(char *format,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_buffer()

static ntv_event_t * copy_buffer ( ntv_event_t  events[],
int  maxevents 
)
static

Definition at line 279 of file ppc64_events.c.

280{
281 ntv_event_t *cur_wev, *start_wev;
282 start_wev = ( ntv_event_t * ) malloc( sizeof ( ntv_event_t ) * maxevents );
283 cur_wev = start_wev;
284
285 int cnt;
286 for ( cnt = 0; cnt < maxevents; cnt++, cur_wev++ ) {
287 cur_wev->event_num = events[cnt].event_num;
288 strcpy( cur_wev->symbol, events[cnt].symbol );
289 cur_wev->short_description =
290 ( char * ) malloc( strlen( events[cnt].short_description ) );
291 strcpy( cur_wev->short_description, events[cnt].short_description );
292 cur_wev->description =
293 ( char * ) malloc( strlen( events[cnt].description ) );
294 strcpy( cur_wev->description, events[cnt].description );
295 }
296 return start_wev;
297}
char events[MAX_EVENTS][BUFSIZ]
char * short_description
char symbol[PAPI_MAX_STR_LEN]
unsigned int event_num
char * description
Here is the caller graph for this function:

◆ open_file()

static FILE * open_file ( const char *  fname)
static

Definition at line 214 of file ppc64_events.c.

215{
216 char *cpu;
217 char *dot = ".";
218 char *dot_dot = "..";
219#ifdef _POWER5p
220 cpu = "power5+";
221#elif defined(_POWER5)
222 cpu = "power5";
223#elif defined(_PPC970)
224 cpu = "ppc970";
225#else
226 cpu = "";
227#endif
228 char *dir = ( char * ) getenv( "PAPI_EVENTFILE_PATH" );
229#ifdef PAPI_DATADIR
230 if ( dir == NULL ) {
231 dir = PAPI_DATADIR;
232 }
233#endif
234 /* If dir is still NULL, assume current dir holds event_data dir */
235 if ( dir == NULL )
236 dir = dot;
237
238 char *relative_pathname = ( char * ) malloc( strlen( "/" ) +
239 strlen( "event_data" ) +
240 strlen( "/" ) + strlen( cpu ) +
241 strlen( "/" ) +
242 strlen( fname ) + 1 );
243 strcpy( relative_pathname, "/" );
244 strcat( relative_pathname, "event_data" );
245 strcat( relative_pathname, "/" );
246 strcat( relative_pathname, cpu );
247 strcat( relative_pathname, "/" );
248 strcat( relative_pathname, fname );
249 /* Add a little extra space to the malloc for the case where dir = "." since
250 * we may be trying dir = ".." later on. */
251 char *pathname =
252 ( char * ) malloc( strlen( dir ) + strlen( relative_pathname ) + 4 );
253 int keep_trying;
254 if ( strcmp( dir, dot ) == 0 )
255 keep_trying = 2;
256 else
257 keep_trying = 3;
258 FILE *file = NULL;
259 while ( file == NULL && keep_trying-- ) {
260 strcpy( pathname, dir );
261 strcat( pathname, relative_pathname );
262 file = fopen( pathname, "r" );
263 if ( strcmp( dir, dot ) == 0 ) {
264 dir = dot_dot;
265 } else {
266 dir = dot;
267 }
268 SUBDBG( "Attempt to open event data file %s %s successful.\n", pathname,
269 ( file == NULL ) ? "was not" : "was" );
270 memset( pathname, '\0', sizeof ( pathname ) );
271 }
272
273 free( pathname );
274 free( relative_pathname );
275 return ( file );
276}
const char FILE * file
Definition: pscanf.h:13
Here is the caller graph for this function:

◆ parse_eventfile()

static ntv_event_info_t * parse_eventfile ( FILE *  evfile)
static

Definition at line 300 of file ppc64_events.c.

301{
302 int counter = 0, num_events = 0;
303 int i, len, cc;
304 int event;
305 int line_counter_flag = 0;
306 char line_data[1024];
308 ntv_event_info_t *ntv_evt_info =
309 ( ntv_event_info_t * ) malloc( sizeof ( ntv_event_info_t ) );
310 ntv_evt_info->maxpmcs = 0;
311 char data[1024];
312 while ( fgets( data, 1022, evfile ) ) {
313 if ( feof( evfile ) )
314 continue;
315 if ( strlen( data ) < 2 )
316 continue;
317
318 if ( strncmp( data, "$$$$", 4 ) == 0 ) {
319 line_counter_flag = 0;
320 ntv_evt_info->maxevents[counter - 1] = num_events;
321 ntv_evt_info->wev[counter - 1] = copy_buffer( events, num_events );
322 ntv_event_t *temp = ntv_evt_info->wev[counter - 1];
323 temp++;
324 }
325 switch ( line_counter_flag ) {
326 case 0:
327 if ( sscanf( data, "{ counter %u", &counter ) == 1 ) {
328 line_counter_flag = 1;
329 num_events = 0;
330 ntv_evt_info->maxpmcs++;
331 }
332 break;
333 case 1:
334 if ( sscanf( data, "#%u", &event ) != 1 ) {
335 fprintf( stderr, "EVS file format error 1 (%s)\n", data );
336 return NULL;
337 }
338 if ( event >= PAPI_MAX_NATIVE_EVENTS ) {
339 fprintf( stderr, "EVS file format error 1 (%s)\n", data );
340 return NULL;
341 }
342 events[num_events].event_num = event;
343 len = strlen( data );
344 int symb_found = 0;
345 for ( i = cc = 0; i < len; i++ ) {
346 if ( data[i] == ',' )
347 cc++;
348 if ( cc == 5 && !symb_found ) {
349 strcpy( line_data, &data[i + 1] );
350 int j = 0;
351 while ( line_data[j] != ',' )
352 j++;
353 strncpy( events[num_events].symbol, line_data, j );
354 events[num_events].symbol[j] = 0;
355 symb_found = 1;
356 i += j;
357 } else if ( cc == 6 ) {
358 len = strlen( &data[i + 1] );
359 events[num_events].short_description =
360 ( char * ) malloc( len );
361 strcpy( events[num_events].short_description,
362 &data[i + 1] );
363 events[num_events].short_description[len - 1] = 0;
364 break;
365 }
366 }
367 line_counter_flag = 2;
368 break;
369 case 2:
370 line_counter_flag = 3;
371 break;
372 case 3:
373 len = strlen( data );
374 events[num_events].description = ( char * ) malloc( len );
375 strcpy( events[num_events].description, data );
376 events[num_events].description[len - 1] = 0;
377 line_counter_flag = 1;
378 num_events++;
379 break;
380 }
381 }
382 if ( counter == 0 ) {
383 free( ntv_evt_info );
384 ntv_evt_info = NULL;
385 }
386 if ( counter == MAX_COUNTERS ) {
387 ntv_evt_info->maxevents[counter - 1] = num_events;
388 ntv_evt_info->wev[counter - 1] = copy_buffer( events, num_events );
389 }
390 fclose( evfile );
391 return ntv_evt_info;
392}
static int num_events
FILE * stderr
int fclose(FILE *__stream)
#define MAX_COUNTERS
Definition: perfctr-x86.h:8
static ntv_event_t * copy_buffer(ntv_event_t events[], int maxevents)
Definition: ppc64_events.c:279
int maxevents[MAX_COUNTERS]
ntv_event_t * wev[MAX_COUNTERS]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_groupfile()

static ntv_event_group_info_t * parse_groupfile ( FILE *  grp_file)
static

Definition at line 406 of file ppc64_events.c.

407{
408 char data[1024];
409 unsigned int mmcr0, mmcr1H, mmcr1L, mmcra;
410 int g, state = 0;
411 ntv_event_group_info_t *group_info =
413 malloc( sizeof ( ntv_event_group_info_t ) );
414 group_info->maxgroups = 0;
415 int event_num[MAX_COUNTERS];
416 while ( fgets( data, 1022, grp_file ) ) {
417 if ( feof( grp_file ) || ( strlen( data ) < 2 ) )
418 continue;
419
420 switch ( state ) {
421 case 0:
422#if defined(_POWER5) || defined(_POWER5p)
423 if ( sscanf
424 ( data, "#%u,%u,%u,%u,%u,%u,%u", &g, &event_num[0],
425 &event_num[1], &event_num[2], &event_num[3], &event_num[4],
426 &event_num[5] ) == 7 ) {
427 state = 1;
428 if ( any_counter_invalid( event_num, 6 ) ) {
429 fprintf( stderr, "ERROR: Maximum events exceeded\n" );
430 return NULL;
431 }
432 }
433#else
434 if ( sscanf
435 ( data, "#%u,%u,%u,%u,%u,%u,%u,%u,%u", &g, &event_num[0],
436 &event_num[1], &event_num[2], &event_num[3], &event_num[4],
437 &event_num[5], &event_num[6], &event_num[7] ) == 9 ) {
438 state = 1;
439 if ( any_counter_invalid( event_num, 8 ) ) {
440 fprintf( stderr, "ERROR: Maximum events exceeded\n" );
441 return NULL;
442 }
443 }
444#endif
445 if ( state == 1 ) {
446 group_info->event_groups[group_info->maxgroups] =
447 ( event_group_t * ) malloc( sizeof ( event_group_t ) );
448 group_info->event_groups[group_info->maxgroups]->group_id = g;
449 int j = 0;
450 for ( ; j < MAX_COUNTERS; j++ )
451 group_info->event_groups[group_info->maxgroups]->events[j] =
452 event_num[j];
453 }
454 break;
455 case 1:
456 // unused hex event codes
457 state = 2;
458 break;
459 case 2:
460 /* get mmcr values */
461 if ( sscanf( data, "%#x,%#x,%#x,%#x", &mmcr0, &mmcr1H, &mmcr1L, &mmcra )
462 != 4 ) {
463 fprintf( stderr, "GPS file format error 1 (%s)\n", data );
464 return NULL;
465 }
466 state = 3;
467 group_info->event_groups[group_info->maxgroups]->mmcr0 = mmcr0;
468 group_info->event_groups[group_info->maxgroups]->mmcr1L = mmcr1L;
469 group_info->event_groups[group_info->maxgroups]->mmcr1U = mmcr1H;
470 group_info->event_groups[group_info->maxgroups]->mmcra = mmcra;
471 group_info->maxgroups++;
472 break;
473 case 3:
474 // unused group name
475 state = 0;
476 }
477 }
478 fclose( grp_file );
479 return group_info;
480}
bool state
Definition: papi_hl.c:155
static int any_counter_invalid(int event_id[], int size)
Definition: ppc64_events.c:395
unsigned int mmcr1U
unsigned int mmcr1L
unsigned int mmcr0
unsigned int mmcra
unsigned int events[MAX_COUNTERS]
event_group_t * event_groups[MAX_GROUPS]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ perfctr_get_native_evt_info()

ntv_event_info_t * perfctr_get_native_evt_info ( void  )

Definition at line 483 of file ppc64_events.c.

484{
485 ntv_event_info_t *evt_info = NULL;
486 FILE *evt_file = open_file( "events" );
487 if ( evt_file != NULL ) {
488 evt_info = parse_eventfile( evt_file );
489 }
490 return evt_info;
491
492}
static FILE * open_file(const char *fname)
Definition: ppc64_events.c:214
static ntv_event_info_t * parse_eventfile(FILE *evfile)
Definition: ppc64_events.c:300
Here is the call graph for this function:
Here is the caller graph for this function:

◆ perfctr_get_native_group_info()

ntv_event_group_info_t * perfctr_get_native_group_info ( void  )

Definition at line 495 of file ppc64_events.c.

496{
498 FILE *grp_file = NULL;
499 if ( ( grp_file = open_file( "groups" ) ) != NULL ) {
500 groups = parse_groupfile( grp_file );
501 }
502 return groups;
503}
static const pmg_power_group_t * groups
static ntv_event_group_info_t * parse_groupfile(FILE *grp_file)
Definition: ppc64_events.c:406
Here is the call graph for this function:
Here is the caller graph for this function:

◆ perfctr_initialize_native_table()

void perfctr_initialize_native_table ( )

Definition at line 27 of file ppc64_events.c.

28{
29 int i, j;
30 memset( native_table, 0,
32 for ( i = 0; i < PAPI_MAX_NATIVE_EVENTS; i++ ) {
33 for ( j = 0; j < MAX_COUNTERS; j++ )
34 native_table[i].resources.counter_cmd[j] = -1;
35 }
36}
native_event_entry_t native_table[PAPI_MAX_NATIVE_EVENTS]
Definition: ppc64_events.c:23
Definition: perfctr-x86.h:134
Here is the caller graph for this function:

◆ perfctr_ppc64_setup_gps()

void perfctr_ppc64_setup_gps ( int  total,
ntv_event_group_info_t group_info 
)

Definition at line 41 of file ppc64_events.c.

42{
43 int i, j, gnum;
44
45 for ( i = 0; i < total; i++ ) {
46 for ( j = 0; j < MAX_COUNTERS; j++ ) {
47 if ( native_table[i].resources.selector & ( 1 << j ) ) {
48 for ( gnum = 0; gnum < group_info->maxgroups; gnum++ ) {
49 if ( native_table[i].resources.counter_cmd[j] ==
50 group_info->event_groups[gnum]->events[j] ) {
51 native_table[i].resources.group[gnum / 32] |=
52 1 << ( gnum % 32 );
53 }
54 }
55 }
56 }
57 }
58
59 for ( gnum = 0; gnum < group_info->maxgroups; gnum++ ) {
60 group_map[gnum].mmcr0 = group_info->event_groups[gnum]->mmcr0;
61 group_map[gnum].mmcr1L = group_info->event_groups[gnum]->mmcr1L;
62 group_map[gnum].mmcr1U = group_info->event_groups[gnum]->mmcr1U;
63 group_map[gnum].mmcra = group_info->event_groups[gnum]->mmcra;
64 for ( i = 0; i < MAX_COUNTERS; i++ )
65 group_map[gnum].counter_cmd[i] =
66 group_info->event_groups[gnum]->events[i];
67 }
68}
hwd_groups_t group_map[MAX_GROUPS]
Definition: ppc64_events.c:17
static int total
Definition: rapl_overflow.c:9
X86_register_t resources
Definition: perfctr-x86.h:137
Here is the caller graph for this function:

◆ perfctr_ppc64_setup_native_table()

int perfctr_ppc64_setup_native_table ( )

Definition at line 73 of file ppc64_events.c.

74{
75 int pmc, ev, i, j, index;
76 /* This is for initialisation-testing of consistency between
77 native_name_map and our events file */
78 int itemCount = 0;
79 index = 0;
82 if ( info == NULL ) {
84 return PAPI_ECMP;
85 }
86 ntv_event_t *wevp;
87 for ( pmc = 0; pmc < info->maxpmcs; pmc++ ) {
88 wevp = info->wev[pmc];
89 for ( ev = 0; ev < info->maxevents[pmc]; ev++, wevp++ ) {
90 for ( i = 0; i < index; i++ ) {
91 if ( strcmp( wevp->symbol, native_table[i].name ) == 0 ) {
92 native_table[i].resources.selector |= 1 << pmc;
94 wevp->event_num;
95 break;
96 }
97 }
98 if ( i == index ) {
99 //native_table[i].index=i;
100 native_table[i].resources.selector |= 1 << pmc;
103 ( char * ) malloc( strlen( wevp->symbol ) + 1 );
104 strcpy( native_table[i].name, wevp->symbol );
106 index++;
107 for ( j = 0; j < MAX_NATNAME_MAP_INDEX; j++ ) {
108 /* It appears that here, if I'm right, that the events
109 file entry matches the event from native_name_map, */
110 /* This here check is to ensure that native_name_map in fact
111 has MAX_NATNAME_MAP_INDEX elements, or rather that it never
112 tries to access one that has not been initialised. */
113 if ( native_name_map[j].name == NULL ) {
114 SUBDBG( "native_name_map has a NULL at position %i\n",
115 j );
117 ( "Inconsistency between events_map file and events header." );
118 return PAPI_EBUG;
119 }
120 if ( strcmp( native_table[i].name, native_name_map[j].name )
121 == 0 ) {
123 itemCount++;
124 break;
125 }
126 }
127 /* If we never set native_name_map[j], then there is an
128 inconsistency between native_name_map and native_table */
129 if ( ( !( j < MAX_NATNAME_MAP_INDEX ) ) ||
130 native_name_map[j].index != i ) {
131 SUBDBG
132 ( "No match found between native_name_map and native_table. "
133 "Values was %s at position %i in native_table.\n",
134 native_table[i].name, i );
136 ( "Inconsistency between native_name_map and events file." );
137 return PAPI_EBUG;
138 }
139 }
140 }
141 }
142 /* given the previous evidence that native_name_map is a superset of
143 native_table, ensuring this match in their cardinality shows them to
144 be equivalent. */
145 if ( itemCount != MAX_NATNAME_MAP_INDEX ) {
146 SUBDBG( "%i events found in native_table, but really should be %i\n",
147 itemCount, MAX_NATNAME_MAP_INDEX );
149 ( "Inconsistent cardinality between native_name_map and events file",
150 itemCount, MAX_NATNAME_MAP_INDEX );
151 return PAPI_EBUG;
152 }
153
155 if ( gp_info == NULL ) {
158 return PAPI_ECMP;
159 }
160
161 perfctr_ppc64_setup_gps( index, gp_info );
162 _papi_hwi_system_info.sub_info.num_native_events = index;
163
164 return check_native_name( );
165}
#define PAPI_ECMP
Definition: f90papi.h:214
#define EVENT_INFO_FILE_ERROR
Definition: perfctr-ppc64.h:72
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
void perfctr_ppc64_setup_gps(int total, ntv_event_group_info_t *group_info)
Definition: ppc64_events.c:41
int check_native_name()
Definition: ppc64_events.c:168
ntv_event_group_info_t * perfctr_get_native_group_info(void)
Definition: ppc64_events.c:495
void perfctr_initialize_native_table()
Definition: ppc64_events.c:27
ntv_event_info_t * perfctr_get_native_evt_info(void)
Definition: ppc64_events.c:483
const char * name
Definition: rocs.c:225
unsigned int selector
Definition: perfctr-x86.h:74
char * description
Definition: perfctr-x86.h:136
char name[PAPI_MAX_STR_LEN]
Definition: perfctr-x86.h:135
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ group_map

Initial value:
= { {0}
, {0}
, {0}
, {0}
, {0}
}

Definition at line 17 of file ppc64_events.c.

◆ native_table

Definition at line 23 of file ppc64_events.c.