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