PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
27int _check_BGPM_error( int err, char* bgpmfunc )
28{
29 char buffer[PAPI_MAX_STR_LEN];
30 int retval;
31
32 if ( err < 0 ) {
33 sprintf( buffer, "Error: ret value is %d for BGPM API function '%s'.",
34 err, bgpmfunc);
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 */
63int
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 */
91int
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 */
120int
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
int i
static long count
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int threshold
int _common_set_overflow_BGPM(int EventGroup, int evt_idx, int threshold, void(*handler)(int, uint64_t, uint64_t, const ucontext_t *))
int _common_deleteRecreate(int *EventGroup_ptr)
int _common_rebuildEventgroup(int count, int *EventGroup_local, int *EventGroup_ptr)
long_long _common_getEventValue(unsigned event_id, int EventGroup)
int _check_BGPM_error(int err, char *bgpmfunc)
This file is part of the source code for a component that enables PAPI-C to access hardware monitorin...
#define _AT_
#define long_long
Definition: papi.h:559
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:21
int retval
Definition: zero_fork.c:53