PAPI  5.0.1.0
papi_vector.c
Go to the documentation of this file.
00001 /*
00002  * File:    papi_vector.c
00003  * Author:  Kevin London
00004  *          london@cs.utk.edu
00005  * Mods:    Haihang You
00006  *         you@cs.utk.edu
00007  * Mods:    <Your name here>
00008  *          <Your email here>
00009  */
00010 
00011 #include "papi.h"
00012 #include "papi_internal.h"
00013 #include "papi_vector.h"
00014 #include "papi_memory.h"
00015 
00016 #include <string.h>
00017 
00018 #ifdef _AIX
00019 
00020 /* needed because the get_virt_usec() code uses a hardware context */
00021 /* which is a pmapi definition on AIX.                             */
00022 #include <pmapi.h>
00023 #endif
00024 
00025 
00026 void
00027 _vectors_error(  )
00028 {
00029     SUBDBG( "function is not implemented in the component!\n" );
00030     exit( PAPI_ECMP );
00031 }
00032 
00033 int
00034 vec_int_ok_dummy(  )
00035 {
00036     return PAPI_OK;
00037 }
00038 
00039 int
00040 vec_int_one_dummy(  )
00041 {
00042     return 1;
00043 }
00044 
00045 int
00046 vec_int_dummy(  )
00047 {
00048     return PAPI_ECMP;
00049 }
00050 
00051 void *
00052 vec_void_star_dummy(  )
00053 {
00054     return NULL;
00055 }
00056 
00057 void
00058 vec_void_dummy(  )
00059 {
00060     return;
00061 }
00062 
00063 long long
00064 vec_long_long_dummy(  )
00065 {
00066     return PAPI_ECMP;
00067 }
00068 
00069 long long
00070 vec_long_long_context_dummy( hwd_context_t *ignored )
00071 {
00072         (void) ignored;
00073 
00074     return PAPI_ECMP;
00075 }
00076 
00077 char *
00078 vec_char_star_dummy(  )
00079 {
00080     return NULL;
00081 }
00082 
00083 long
00084 vec_long_dummy(  )
00085 {
00086     return PAPI_ECMP;
00087 }
00088 
00089 long long vec_virt_cycles(void)
00090 {
00091   return ((long long) _papi_os_vector.get_virt_usec() * 
00092       _papi_hwi_system_info.hw_info.cpu_max_mhz);
00093 }
00094 
00095 long long vec_real_nsec_dummy(void)
00096 {
00097   return ((long long) _papi_os_vector.get_real_usec() * 1000);
00098 
00099 }
00100 
00101 long long vec_virt_nsec_dummy(void)
00102 {
00103   return ((long long) _papi_os_vector.get_virt_usec() * 1000);
00104 
00105 }
00106 
00107 
00108 int
00109 _papi_hwi_innoculate_vector( papi_vector_t * v )
00110 {
00111     if ( !v )
00112         return ( PAPI_EINVAL );
00113 
00114     /* component function pointers */
00115     if ( !v->dispatch_timer )
00116         v->dispatch_timer =
00117             ( void ( * )( int, hwd_siginfo_t *, void * ) ) vec_void_dummy;
00118     if ( !v->get_overflow_address )
00119         v->get_overflow_address =
00120             ( void *( * )( int, char *, int ) ) vec_void_star_dummy;
00121     if ( !v->start )
00122         v->start = ( int ( * )( hwd_context_t *, hwd_control_state_t * ) )
00123             vec_int_dummy;
00124     if ( !v->stop )
00125         v->stop = ( int ( * )( hwd_context_t *, hwd_control_state_t * ) )
00126             vec_int_dummy;
00127     if ( !v->read )
00128         v->read = ( int ( * )
00129                     ( hwd_context_t *, hwd_control_state_t *, long long **,
00130                       int ) ) vec_int_dummy;
00131     if ( !v->reset )
00132         v->reset = ( int ( * )( hwd_context_t *, hwd_control_state_t * ) )
00133             vec_int_dummy;
00134     if ( !v->write )
00135         v->write =
00136             ( int ( * )( hwd_context_t *, hwd_control_state_t *, long long[] ) )
00137             vec_int_dummy;
00138     if ( !v->cleanup_eventset ) 
00139         v->cleanup_eventset = ( int ( * )( hwd_control_state_t * ) ) vec_int_ok_dummy;
00140     if ( !v->stop_profiling )
00141         v->stop_profiling =
00142             ( int ( * )( ThreadInfo_t *, EventSetInfo_t * ) ) vec_int_dummy;
00143     if ( !v->init_component )
00144         v->init_component = ( int ( * )( int ) ) vec_int_ok_dummy;
00145     if ( !v->init_thread )
00146         v->init_thread = ( int ( * )( hwd_context_t * ) ) vec_int_ok_dummy;
00147     if ( !v->init_control_state )
00148         v->init_control_state =
00149             ( int ( * )( hwd_control_state_t * ptr ) ) vec_void_dummy;
00150     if ( !v->update_control_state )
00151         v->update_control_state = ( int ( * )
00152                                     ( hwd_control_state_t *, NativeInfo_t *,
00153                                       int, hwd_context_t * ) ) vec_int_dummy;
00154     if ( !v->ctl )
00155         v->ctl = ( int ( * )( hwd_context_t *, int, _papi_int_option_t * ) )
00156             vec_int_dummy;
00157     if ( !v->set_overflow )
00158         v->set_overflow =
00159             ( int ( * )( EventSetInfo_t *, int, int ) ) vec_int_dummy;
00160     if ( !v->set_profile )
00161         v->set_profile =
00162             ( int ( * )( EventSetInfo_t *, int, int ) ) vec_int_dummy;
00163 
00164     if ( !v->set_domain )
00165         v->set_domain =
00166             ( int ( * )( hwd_control_state_t *, int ) ) vec_int_dummy;
00167     if ( !v->ntv_enum_events )
00168         v->ntv_enum_events = ( int ( * )( unsigned int *, int ) ) vec_int_dummy;
00169     if ( !v->ntv_name_to_code )
00170         v->ntv_name_to_code =
00171             ( int ( * )( char *, unsigned int * ) ) vec_int_dummy;
00172     if ( !v->ntv_code_to_name )
00173         v->ntv_code_to_name =
00174             ( int ( * )( unsigned int, char *, int ) ) vec_int_dummy;
00175     if ( !v->ntv_code_to_descr )
00176         v->ntv_code_to_descr =
00177             ( int ( * )( unsigned int, char *, int ) ) vec_int_ok_dummy;
00178     if ( !v->ntv_code_to_bits )
00179         v->ntv_code_to_bits =
00180             ( int ( * )( unsigned int, hwd_register_t * ) ) vec_int_dummy;
00181     if ( !v->ntv_code_to_info )
00182         v->ntv_code_to_info =
00183             ( int ( * )( unsigned int, PAPI_event_info_t * ) ) vec_int_dummy;
00184 
00185     if ( !v->allocate_registers )
00186         v->allocate_registers =
00187             ( int ( * )( EventSetInfo_t * ) ) vec_int_ok_dummy;
00188 
00189     if ( !v->shutdown_thread )
00190         v->shutdown_thread = ( int ( * )( hwd_context_t * ) ) vec_int_dummy;
00191     if ( !v->shutdown_component )
00192         v->shutdown_component = ( int ( * )( void ) ) vec_int_ok_dummy;
00193     if ( !v->user )
00194         v->user = ( int ( * )( int, void *, void * ) ) vec_int_dummy;
00195     return PAPI_OK;
00196 }
00197 
00198 
00199 int
00200 _papi_hwi_innoculate_os_vector( papi_os_vector_t * v )
00201 {
00202     if ( !v )
00203         return ( PAPI_EINVAL );
00204 
00205     if ( !v->get_real_cycles )
00206         v->get_real_cycles = vec_long_long_dummy;
00207     if ( !v->get_real_usec )
00208         v->get_real_usec = vec_long_long_dummy;
00209     if ( !v->get_real_nsec )
00210         v->get_real_nsec = vec_real_nsec_dummy;
00211     if ( !v->get_virt_cycles )
00212         v->get_virt_cycles = vec_virt_cycles;
00213     if ( !v->get_virt_usec )
00214         v->get_virt_usec = vec_long_long_dummy;
00215     if ( !v->get_virt_nsec )
00216         v->get_virt_nsec = vec_virt_nsec_dummy;
00217 
00218     if ( !v->update_shlib_info )
00219         v->update_shlib_info = ( int ( * )( papi_mdi_t * ) ) vec_int_dummy;
00220     if ( !v->get_system_info )
00221         v->get_system_info = ( int ( * )(  ) ) vec_int_dummy;
00222 
00223     if ( !v->get_memory_info )
00224         v->get_memory_info =
00225             ( int ( * )( PAPI_hw_info_t *, int ) ) vec_int_dummy;
00226 
00227     if ( !v->get_dmem_info )
00228         v->get_dmem_info = ( int ( * )( PAPI_dmem_info_t * ) ) vec_int_dummy;
00229 
00230     return PAPI_OK;
00231 }
00232 
00233 /* not used?  debug only? */
00234 #if 0
00235 static void *
00236 vector_find_dummy( void *func, char **buf )
00237 {
00238     void *ptr = NULL;
00239 
00240     if ( vec_int_ok_dummy == ( int ( * )(  ) ) func ) {
00241         ptr = ( void * ) vec_int_ok_dummy;
00242         if ( buf != NULL )
00243             *buf = papi_strdup( "vec_int_ok_dummy" );
00244     } else if ( vec_int_one_dummy == ( int ( * )(  ) ) func ) {
00245         ptr = ( void * ) vec_int_one_dummy;
00246         if ( buf != NULL )
00247             *buf = papi_strdup( "vec_int_one_dummy" );
00248     } else if ( vec_int_dummy == ( int ( * )(  ) ) func ) {
00249         ptr = ( void * ) vec_int_dummy;
00250         if ( buf != NULL )
00251             *buf = papi_strdup( "vec_int_dummy" );
00252     } else if ( vec_void_dummy == ( void ( * )(  ) ) func ) {
00253         ptr = ( void * ) vec_void_dummy;
00254         if ( buf != NULL )
00255             *buf = papi_strdup( "vec_void_dummy" );
00256     } else if ( vec_void_star_dummy == ( void *( * )(  ) ) func ) {
00257         ptr = ( void * ) vec_void_star_dummy;
00258         if ( buf != NULL )
00259             *buf = papi_strdup( "vec_void_star_dummy" );
00260     } else if ( vec_long_long_dummy == ( long long ( * )(  ) ) func ) {
00261         ptr = ( void * ) vec_long_long_dummy;
00262         if ( buf != NULL )
00263             *buf = papi_strdup( "vec_long_long_dummy" );
00264     } else if ( vec_char_star_dummy == ( char *( * )(  ) ) func ) {
00265         ptr = ( void * ) vec_char_star_dummy;
00266         *buf = papi_strdup( "vec_char_star_dummy" );
00267     } else if ( vec_long_dummy == ( long ( * )(  ) ) func ) {
00268         ptr = ( void * ) vec_long_dummy;
00269         if ( buf != NULL )
00270             *buf = papi_strdup( "vec_long_dummy" );
00271     } else {
00272         ptr = NULL;
00273     }
00274     return ( ptr );
00275 }
00276 
00277 
00278 static void
00279 vector_print_routine( void *func, char *fname, int pfunc )
00280 {
00281     void *ptr = NULL;
00282     char *buf = NULL;
00283 
00284     ptr = vector_find_dummy( func, &buf );
00285     if ( ptr ) {
00286         printf( "DUMMY: %s is mapped to %s.\n",
00287                 fname, buf );
00288         papi_free( buf );
00289     } else if ( ( !ptr && pfunc ) )
00290         printf( "function: %s is mapped to %p.\n",
00291                 fname, func );
00292 }
00293 
00294 static void
00295 vector_print_table( papi_vector_t * v, int print_func )
00296 {
00297 
00298     if ( !v )
00299         return;
00300 
00301     vector_print_routine( ( void * ) v->dispatch_timer,
00302                           "_papi_hwd_dispatch_timer", print_func );
00303     vector_print_routine( ( void * ) v->get_overflow_address,
00304                           "_papi_hwd_get_overflow_address", print_func );
00305     vector_print_routine( ( void * ) v->start, "_papi_hwd_start", print_func );
00306     vector_print_routine( ( void * ) v->stop, "_papi_hwd_stop", print_func );
00307     vector_print_routine( ( void * ) v->read, "_papi_hwd_read", print_func );
00308     vector_print_routine( ( void * ) v->reset, "_papi_hwd_reset", print_func );
00309     vector_print_routine( ( void * ) v->write, "_papi_hwd_write", print_func );
00310     vector_print_routine( ( void * ) v->cleanup_eventset, 
00311                           "_papi_hwd_cleanup_eventset", print_func );
00312 
00313     vector_print_routine( ( void * ) v->stop_profiling,
00314                           "_papi_hwd_stop_profiling", print_func );
00315     vector_print_routine( ( void * ) v->init_component,
00316                           "_papi_hwd_init_component", print_func );
00317     vector_print_routine( ( void * ) v->init_thread, "_papi_hwd_init_thread", print_func );
00318     vector_print_routine( ( void * ) v->init_control_state,
00319                           "_papi_hwd_init_control_state", print_func );
00320     vector_print_routine( ( void * ) v->ctl, "_papi_hwd_ctl", print_func );
00321     vector_print_routine( ( void * ) v->set_overflow, "_papi_hwd_set_overflow",
00322                           print_func );
00323     vector_print_routine( ( void * ) v->set_profile, "_papi_hwd_set_profile",
00324                           print_func );
00325     vector_print_routine( ( void * ) v->set_domain, "_papi_hwd_set_domain",
00326                           print_func );
00327     vector_print_routine( ( void * ) v->ntv_enum_events,
00328                           "_papi_hwd_ntv_enum_events", print_func );
00329     vector_print_routine( ( void * ) v->ntv_name_to_code,
00330                           "_papi_hwd_ntv_name_to_code", print_func );
00331     vector_print_routine( ( void * ) v->ntv_code_to_name,
00332                           "_papi_hwd_ntv_code_to_name", print_func );
00333     vector_print_routine( ( void * ) v->ntv_code_to_descr,
00334                           "_papi_hwd_ntv_code_to_descr", print_func );
00335     vector_print_routine( ( void * ) v->ntv_code_to_bits,
00336                           "_papi_hwd_ntv_code_to_bits", print_func );
00337     vector_print_routine( ( void * ) v->ntv_code_to_info,
00338                           "_papi_hwd_ntv_code_to_info", print_func );
00339 
00340     vector_print_routine( ( void * ) v->allocate_registers,
00341                           "_papi_hwd_allocate_registers", print_func );
00342 
00343     vector_print_routine( ( void * ) v->shutdown_thread, "_papi_hwd_shutdown_thread",
00344                           print_func );
00345     vector_print_routine( ( void * ) v->shutdown_component,
00346                           "_papi_hwd_shutdown_component", print_func );
00347     vector_print_routine( ( void * ) v->user, "_papi_hwd_user", print_func );
00348 }
00349 
00350 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines