PAPI  5.3.0.0
linux-bgq-common.c
Go to the documentation of this file.
00001 /****************************/
00002 /* THIS IS OPEN SOURCE CODE */
00003 /****************************/
00004 
00021 #include "linux-bgq-common.h"
00022 
00023 /*******************************************************************************
00024  ********  BEGIN FUNCTIONS USED INTERNALLY SPECIFIC TO THIS COMPONENT **********
00025  ******************************************************************************/
00026 
00027 int _check_BGPM_error( int err, char* bgpmfunc )
00028 {
00029     char  buffer[PAPI_MAX_STR_LEN];
00030     int retval;
00031     
00032     if ( err < 0 ) {
00033         sprintf( buffer, "Error: ret value is %d for BGPM API function '%s'.",
00034                 err, bgpmfunc);
00035         retval =  _papi_hwi_publish_error( buffer );
00036         return retval;
00037     }
00038     
00039     return PAPI_OK;
00040 }
00041 
00042 
00043 /*
00044  * Returns all event values from the BGPM eventGroup
00045  */
00046 long_long
00047 _common_getEventValue( unsigned event_id, int EventGroup )
00048 {   
00049     uint64_t value;
00050     int retval;
00051     
00052     retval = Bgpm_ReadEvent( EventGroup, event_id, &value );
00053     retval = _check_BGPM_error( retval, "Bgpm_ReadEvent" );
00054     if ( retval < 0 ) return retval;
00055 
00056     return ( ( long_long ) value ); 
00057 }
00058 
00059 
00060 /*
00061  * Delete BGPM eventGroup and create an new empty one
00062  */
00063 int
00064 _common_deleteRecreate( int *EventGroup_ptr )
00065 {
00066 #ifdef DEBUG_BGQ
00067     printf( _AT_ " _common_deleteRecreate: *EventGroup_ptr=%d\n", *EventGroup_ptr);
00068 #endif
00069     int retval;
00070     
00071     // delete previous bgpm eventset
00072     retval = Bgpm_DeleteEventSet( *EventGroup_ptr );
00073     retval = _check_BGPM_error( retval, "Bgpm_DeleteEventSet" );
00074     if ( retval < 0 ) return retval;
00075 
00076     // create a new empty bgpm eventset
00077     *EventGroup_ptr = Bgpm_CreateEventSet();
00078     retval = _check_BGPM_error( *EventGroup_ptr, "Bgpm_CreateEventSet" );
00079     if ( retval < 0 ) return retval;
00080 
00081 #ifdef DEBUG_BGQ
00082     printf( _AT_ " _common_deleteRecreate: *EventGroup_ptr=%d\n", *EventGroup_ptr);
00083 #endif
00084     return PAPI_OK;
00085 }
00086 
00087 
00088 /*
00089  * Rebuild BGPM eventGroup with the events as it was prior to deletion 
00090  */
00091 int
00092 _common_rebuildEventgroup( int count, int *EventGroup_local, int *EventGroup_ptr )
00093 {
00094 #ifdef DEBUG_BGQ
00095     printf( "_common_rebuildEventgroup\n" );
00096 #endif  
00097     int i, retval;
00098     
00099     // rebuild BGPM EventGroup
00100     for ( i = 0; i < count; i++ ) {
00101         retval = Bgpm_AddEvent( *EventGroup_ptr, EventGroup_local[i] );
00102         retval = _check_BGPM_error( retval, "Bgpm_AddEvent" );
00103         if ( retval < 0 ) return retval;
00104 
00105 #ifdef DEBUG_BGQ
00106         printf( "_common_rebuildEventgroup: After emptying EventGroup, event re-added: %d\n",
00107                 EventGroup_local[i] );
00108 #endif
00109     }
00110     return PAPI_OK;
00111 }
00112 
00113 
00114 /*
00115  * _common_set_overflow_BGPM
00116  *
00117  * since update_control_state trashes overflow settings, this puts things
00118  * back into balance for BGPM 
00119  */
00120 int
00121 _common_set_overflow_BGPM( int EventGroup, 
00122                            int evt_idx,
00123                            int threshold, 
00124                            void (*handler)(int, uint64_t, uint64_t, const ucontext_t *) )
00125 {
00126     int retval;
00127     uint64_t threshold_for_bgpm;
00128     
00129     /* convert threadhold value assigned by PAPI user to value that is
00130      * programmed into the counter. This value is required by Bgpm_SetOverflow() */ 
00131     threshold_for_bgpm = BGPM_PERIOD2THRES( threshold );
00132     
00133 #ifdef DEBUG_BGQ
00134     printf("_common_set_overflow_BGPM\n");
00135     
00136     int i;
00137     int numEvts = Bgpm_NumEvents( EventGroup );
00138     for ( i = 0; i < numEvts; i++ ) {
00139         printf("_common_set_overflow_BGPM: %d = %s\n", i, Bgpm_GetEventLabel( EventGroup, i) );
00140     }
00141 #endif  
00142     
00143     
00144     retval = Bgpm_SetOverflow( EventGroup, 
00145                                evt_idx,
00146                                threshold_for_bgpm );
00147     retval = _check_BGPM_error( retval, "Bgpm_SetOverflow" );
00148     if ( retval < 0 ) return retval;
00149 
00150     retval = Bgpm_SetEventUser1( EventGroup, 
00151                                  evt_idx,
00152                                  1024 );
00153     retval = _check_BGPM_error( retval, "Bgpm_SetEventUser1" );
00154     if ( retval < 0 ) return retval;
00155 
00156     /* user signal handler for overflow case */
00157     retval = Bgpm_SetOverflowHandler( EventGroup, 
00158                                       handler );
00159     retval = _check_BGPM_error( retval, "Bgpm_SetOverflowHandler" );    
00160     if ( retval < 0 ) return retval;
00161 
00162     return PAPI_OK;
00163 }
00164 
00165 
00166 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines