PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
linux-bgq-common.c
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
4 
21 #include "linux-bgq-common.h"
22 
23 /*******************************************************************************
24  ******** BEGIN FUNCTIONS USED INTERNALLY SPECIFIC TO THIS COMPONENT **********
25  ******************************************************************************/
26 
27 int _check_BGPM_error( int err, char* bgpmfunc )
28 {
30  int retval;
31 
32  if ( err < 0 ) {
33  sprintf( buffer, "Error: ret value is %d for BGPM API function '%s'.",
34  err, bgpmfunc);
35  retval = _papi_hwi_publish_error( buffer );
36  return retval;
37  }
38 
39  return PAPI_OK;
40 }
41 
42 
43 /*
44  * Returns all event values from the BGPM eventGroup
45  */
47 _common_getEventValue( unsigned event_id, int EventGroup )
48 {
49  uint64_t value;
50  int retval;
51 
52  retval = Bgpm_ReadEvent( EventGroup, event_id, &value );
53  retval = _check_BGPM_error( retval, "Bgpm_ReadEvent" );
54  if ( retval < 0 ) return retval;
55 
56  return ( ( long_long ) value );
57 }
58 
59 
60 /*
61  * Delete BGPM eventGroup and create an new empty one
62  */
63 int
64 _common_deleteRecreate( int *EventGroup_ptr )
65 {
66 #ifdef DEBUG_BGQ
67  printf( _AT_ " _common_deleteRecreate: *EventGroup_ptr=%d\n", *EventGroup_ptr);
68 #endif
69  int retval;
70 
71  // delete previous bgpm eventset
72  retval = Bgpm_DeleteEventSet( *EventGroup_ptr );
73  retval = _check_BGPM_error( retval, "Bgpm_DeleteEventSet" );
74  if ( retval < 0 ) return retval;
75 
76  // create a new empty bgpm eventset
77  *EventGroup_ptr = Bgpm_CreateEventSet();
78  retval = _check_BGPM_error( *EventGroup_ptr, "Bgpm_CreateEventSet" );
79  if ( retval < 0 ) return retval;
80 
81 #ifdef DEBUG_BGQ
82  printf( _AT_ " _common_deleteRecreate: *EventGroup_ptr=%d\n", *EventGroup_ptr);
83 #endif
84  return PAPI_OK;
85 }
86 
87 
88 /*
89  * Rebuild BGPM eventGroup with the events as it was prior to deletion
90  */
91 int
92 _common_rebuildEventgroup( int count, int *EventGroup_local, int *EventGroup_ptr )
93 {
94 #ifdef DEBUG_BGQ
95  printf( "_common_rebuildEventgroup\n" );
96 #endif
97  int i, retval;
98 
99  // rebuild BGPM EventGroup
100  for ( i = 0; i < count; i++ ) {
101  retval = Bgpm_AddEvent( *EventGroup_ptr, EventGroup_local[i] );
102  retval = _check_BGPM_error( retval, "Bgpm_AddEvent" );
103  if ( retval < 0 ) return retval;
104 
105 #ifdef DEBUG_BGQ
106  printf( "_common_rebuildEventgroup: After emptying EventGroup, event re-added: %d\n",
107  EventGroup_local[i] );
108 #endif
109  }
110  return PAPI_OK;
111 }
112 
113 
114 /*
115  * _common_set_overflow_BGPM
116  *
117  * since update_control_state trashes overflow settings, this puts things
118  * back into balance for BGPM
119  */
120 int
121 _common_set_overflow_BGPM( int EventGroup,
122  int evt_idx,
123  int threshold,
124  void (*handler)(int, uint64_t, uint64_t, const ucontext_t *) )
125 {
126  int retval;
127  uint64_t threshold_for_bgpm;
128 
129  /* convert threadhold value assigned by PAPI user to value that is
130  * programmed into the counter. This value is required by Bgpm_SetOverflow() */
131  threshold_for_bgpm = BGPM_PERIOD2THRES( threshold );
132 
133 #ifdef DEBUG_BGQ
134  printf("_common_set_overflow_BGPM\n");
135 
136  int i;
137  int numEvts = Bgpm_NumEvents( EventGroup );
138  for ( i = 0; i < numEvts; i++ ) {
139  printf("_common_set_overflow_BGPM: %d = %s\n", i, Bgpm_GetEventLabel( EventGroup, i) );
140  }
141 #endif
142 
143 
144  retval = Bgpm_SetOverflow( EventGroup,
145  evt_idx,
146  threshold_for_bgpm );
147  retval = _check_BGPM_error( retval, "Bgpm_SetOverflow" );
148  if ( retval < 0 ) return retval;
149 
150  retval = Bgpm_SetEventUser1( EventGroup,
151  evt_idx,
152  1024 );
153  retval = _check_BGPM_error( retval, "Bgpm_SetEventUser1" );
154  if ( retval < 0 ) return retval;
155 
156  /* user signal handler for overflow case */
157  retval = Bgpm_SetOverflowHandler( EventGroup,
158  handler );
159  retval = _check_BGPM_error( retval, "Bgpm_SetOverflowHandler" );
160  if ( retval < 0 ) return retval;
161 
162  return PAPI_OK;
163 }
164 
165 
166 
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int _common_deleteRecreate(int *EventGroup_ptr)
int _check_BGPM_error(int err, char *bgpmfunc)
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
#define printf
Definition: papi_test.h:125
void double value
Definition: iozone.c:18781
err
Definition: linux-cuda.c:323
int i
Definition: fileop.c:140
int _common_rebuildEventgroup(int count, int *EventGroup_local, int *EventGroup_ptr)
#define _AT_
long_long _common_getEventValue(unsigned event_id, int EventGroup)
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:16
int threshold
This file is part of the source code for a component that enables PAPI-C to access hardware monitorin...
int _common_set_overflow_BGPM(int EventGroup, int evt_idx, int threshold, void(*handler)(int, uint64_t, uint64_t, const ucontext_t *))
char * buffer
Definition: iozone.c:1366
int _papi_hwi_publish_error(char *error)
#define long_long
Definition: papi.h:550
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
ssize_t retval
Definition: libasync.c:338