PAPI  5.0.1.0
papi_internal.h
Go to the documentation of this file.
00001 /****************************/
00002 /* THIS IS OPEN SOURCE CODE */
00003 /****************************/
00016 #ifndef _PAPI_INTERNAL_H
00017 #define _PAPI_INTERNAL_H
00018 
00019 /* AIX's C compiler does not recognize the inline keyword */
00020 #ifdef _AIX
00021 #define inline
00022 #endif 
00023 
00024 #include "papi_debug.h"
00025 
00026 #define DEADBEEF 0xdedbeef
00027 extern int papi_num_components;
00028 extern int _papi_num_compiled_components;
00029 extern int init_level;
00030 extern int _papi_hwi_errno;
00031 extern int _papi_hwi_num_errors;
00032 extern char **_papi_errlist;
00033 
00034 
00035 /********************************************************/
00036 /* This block provides general strings used in PAPI     */
00037 /* If a new string is needed for PAPI prompts           */
00038 /* it should be placed in this file and referenced by   */
00039 /* label.                                               */
00040 /********************************************************/
00041 #define PAPI_ERROR_CODE_str      "Error Code"
00042 #define PAPI_SHUTDOWN_str         "PAPI_shutdown: PAPI is not initialized"
00043 #define PAPI_SHUTDOWN_SYNC_str  "PAPI_shutdown: other threads still have running EventSets"
00044 
00045 
00046 /* some members of structs and/or function parameters may or may not be
00047    necessary, but at this point, we have included anything that might 
00048    possibly be useful later, and will remove them as we progress */
00049 
00050 /* Signal used for overflow delivery */
00051 
00052 #define PAPI_INT_MPX_SIGNAL SIGPROF
00053 #define PAPI_INT_SIGNAL SIGPROF
00054 #define PAPI_INT_ITIMER ITIMER_PROF
00055 
00056 #define PAPI_INT_ITIMER_MS 1
00057 #if defined(linux)
00058 #define PAPI_NSIG _NSIG
00059 #else
00060 #define PAPI_NSIG 128
00061 #endif
00062 
00063 /* Multiplex definitions */
00064 
00065 #define PAPI_INT_MPX_DEF_US 10000   /*Default resolution in us. of mpx handler */
00066 
00067 /* Commands used to compute derived events */
00068 
00069 #define NOT_DERIVED      0x0    
00070 #define DERIVED_ADD      0x1    
00071 #define DERIVED_PS       0x2    
00072 #define DERIVED_ADD_PS   0x4    
00073 #define DERIVED_CMPD     0x8    
00074 #define DERIVED_SUB      0x10   
00075 #define DERIVED_POSTFIX  0x20   
00077 /* Thread related: thread local storage */
00078 
00079 #define LOWLEVEL_TLS        PAPI_NUM_TLS+0
00080 #define NUM_INNER_TLS       1
00081 #define PAPI_MAX_TLS        (NUM_INNER_TLS+PAPI_NUM_TLS)
00082 
00083 /* Thread related: locks */
00084 
00085 #define INTERNAL_LOCK       PAPI_NUM_LOCK+0 /* papi_internal.c */
00086 #define MULTIPLEX_LOCK      PAPI_NUM_LOCK+1 /* multiplex.c */
00087 #define THREADS_LOCK        PAPI_NUM_LOCK+2 /* threads.c */
00088 #define HIGHLEVEL_LOCK      PAPI_NUM_LOCK+3 /* papi_hl.c */
00089 #define MEMORY_LOCK     PAPI_NUM_LOCK+4 /* papi_memory.c */
00090 #define COMPONENT_LOCK          PAPI_NUM_LOCK+5 /* per-component */
00091 #define GLOBAL_LOCK             PAPI_NUM_LOCK+6 /* papi.c for global variable (static and non) initialization/shutdown */
00092 #define CPUS_LOCK       PAPI_NUM_LOCK+7 /* cpus.c */
00093 #define NAMELIB_LOCK            PAPI_NUM_LOCK+8 /* papi_pfm4_events.c */
00094 
00095 /* extras related */
00096 
00097 #define NEED_CONTEXT        1
00098 #define DONT_NEED_CONTEXT   0
00099 
00100 #define PAPI_EVENTS_IN_DERIVED_EVENT    8
00101 
00102 
00103 /* these vestigial pointers are to structures defined in the components
00104     they are opaque to the framework and defined as void at this level
00105     they are remapped to real data in the component routines that use them */
00106 #define hwd_context_t       void
00107 #define hwd_control_state_t void
00108 #define hwd_reg_alloc_t     void
00109 #define hwd_register_t      void
00110 #define hwd_siginfo_t       void
00111 #define hwd_ucontext_t      void
00112 
00113 /* DEFINES END HERE */
00114 
00115 #ifndef NO_CONFI
00116 #include "config.h"
00117 #endif
00118 
00119 #include OSCONTEXT
00120 #include "papi_preset.h"
00121 
00122 #ifndef inline_static
00123 #define inline_static inline static
00124 #endif
00125 
00126 typedef struct _EventSetDomainInfo {
00127    int domain;
00128 } EventSetDomainInfo_t;
00129 
00130 typedef struct _EventSetGranularityInfo {
00131    int granularity;
00132 } EventSetGranularityInfo_t;
00133 
00134 typedef struct _EventSetOverflowInfo {
00135    int flags;
00136    int event_counter;
00137    PAPI_overflow_handler_t handler;
00138    long long *deadline;
00139    int *threshold;
00140    int *EventIndex;
00141    int *EventCode;
00142 } EventSetOverflowInfo_t;
00143 
00144 typedef struct _EventSetAttachInfo {
00145   unsigned long tid;
00146 } EventSetAttachInfo_t;
00147 
00148 typedef struct _EventSetCpuInfo {
00149   unsigned int cpu_num;
00150 } EventSetCpuInfo_t;
00151 
00152 typedef struct _EventSetInheritInfo
00153 {
00154     int inherit;
00155 } EventSetInheritInfo_t;
00156 
00158 typedef struct _EventSetProfileInfo {
00159    PAPI_sprofil_t **prof;
00160    int *count;     
00161    int *threshold;
00162    int *EventIndex;
00163    int *EventCode;
00164    int flags;
00165    int event_counter;
00166 } EventSetProfileInfo_t;
00167 
00176 typedef struct _EventInfo {
00177    unsigned int event_code;     
00178    int pos[PAPI_EVENTS_IN_DERIVED_EVENT];   
00179    char *ops;                   
00180    int derived;                 
00181 } EventInfo_t;
00182 
00188 typedef struct _NativeInfo {
00189    int ni_event;                
00191    int ni_position;             
00193    int ni_owners;               
00195    hwd_register_t *ni_bits;     
00197 } NativeInfo_t;
00198 
00199 
00200 /* Multiplex definitions */
00201 
00207 typedef struct _papi_info {
00208    long long event_type;
00209    int domain;
00210    int granularity;
00211 } PapiInfo;
00212 
00213 typedef struct _masterevent {
00214    int uses;
00215    int active;
00216    int is_a_rate;
00217    int papi_event;
00218    PapiInfo pi;
00219    long long count;
00220    long long cycles;
00221    long long handler_count;
00222    long long prev_total_c;
00223    long long count_estimate;
00224    double rate_estimate;
00225    struct _threadlist *mythr;
00226    struct _masterevent *next;
00227 } MasterEvent;
00228 
00230 typedef struct _threadlist {
00231 #ifdef PTHREADS
00232     pthread_t thr;
00233 #else
00234     unsigned long int tid;
00235 #endif
00236 
00237    long long total_c;
00239    MasterEvent *cur_event;
00241    MasterEvent *head;
00243    struct _threadlist *next;
00244 } Threadlist;
00245 
00246 /* Ugh, should move this out and into all callers of papi_internal.h */
00247 #include "sw_multiplex.h"
00248 
00251 struct _ThreadInfo;
00252 struct _CpuInfo;
00253 
00256 typedef struct _EventSetInfo {
00257   struct _ThreadInfo *master;  
00258   struct _CpuInfo    *CpuInfo; 
00260   int state;                   
00263   EventInfo_t *EventInfoArray; 
00269   hwd_control_state_t *ctl_state; 
00273   unsigned long int tid;       
00276   int EventSetIndex;           
00278   int CmpIdx;              
00280   int NumberOfEvents;          
00282   long long *hw_start;         
00286   long long *sw_stop;          
00290   int NativeCount;             
00293   NativeInfo_t *NativeInfoArray;  
00295   hwd_register_t *NativeBits;     
00298   EventSetDomainInfo_t domain;
00299   EventSetGranularityInfo_t granularity;
00300   EventSetOverflowInfo_t overflow;
00301   EventSetMultiplexInfo_t multiplex;
00302   EventSetAttachInfo_t attach;
00303   EventSetCpuInfo_t cpu;
00304   EventSetProfileInfo_t profile;
00305   EventSetInheritInfo_t inherit;
00306 } EventSetInfo_t;
00307 
00309 typedef struct _dynamic_array {
00310    EventSetInfo_t **dataSlotArray;      
00311    int totalSlots;              
00312    int availSlots;              
00313    int fullSlots;               
00314    int lowestEmptySlot;         
00315 } DynamicArray_t;
00316 
00317 /* Component option types for _papi_hwd_ctl. */
00318 
00319 typedef struct _papi_int_attach {
00320    unsigned long tid;
00321    EventSetInfo_t *ESI;
00322 } _papi_int_attach_t;
00323 
00324 typedef struct _papi_int_cpu {
00325    unsigned int cpu_num;
00326    EventSetInfo_t *ESI;
00327 } _papi_int_cpu_t;
00328 
00329 typedef struct _papi_int_multiplex {
00330    int flags;
00331    unsigned long ns;
00332    EventSetInfo_t *ESI;
00333 } _papi_int_multiplex_t;
00334 
00335 typedef struct _papi_int_defdomain {
00336    int defdomain;
00337 } _papi_int_defdomain_t;
00338 
00339 typedef struct _papi_int_domain {
00340    int domain;
00341    int eventset;
00342    EventSetInfo_t *ESI;
00343 } _papi_int_domain_t;
00344 
00345 typedef struct _papi_int_granularity {
00346    int granularity;
00347    int eventset;
00348    EventSetInfo_t *ESI;
00349 } _papi_int_granularity_t;
00350 
00351 typedef struct _papi_int_overflow {
00352    EventSetInfo_t *ESI;
00353    EventSetOverflowInfo_t overflow;
00354 } _papi_int_overflow_t;
00355 
00356 typedef struct _papi_int_profile {
00357    EventSetInfo_t *ESI;
00358    EventSetProfileInfo_t profile;
00359 } _papi_int_profile_t;
00360 
00361 typedef PAPI_itimer_option_t _papi_int_itimer_t;
00362 /* These shortcuts are only for use code */
00363 #undef multiplex_itimer_sig
00364 #undef multiplex_itimer_num
00365 #undef multiplex_itimer_us
00366 
00367 typedef struct _papi_int_inherit
00368 {
00369     EventSetInfo_t *ESI;
00370     int inherit;
00371 } _papi_int_inherit_t;
00372 
00374 typedef struct _papi_int_addr_range { /* if both are zero, range is disabled */
00375    EventSetInfo_t *ESI;
00376    int domain;
00377    caddr_t start;                
00378    caddr_t end;                  
00379    int start_off;                
00380    int end_off;                  
00382 } _papi_int_addr_range_t;
00383 
00384 typedef union _papi_int_option_t {
00385    _papi_int_overflow_t overflow;
00386    _papi_int_profile_t profile;
00387    _papi_int_domain_t domain;
00388    _papi_int_attach_t attach;
00389    _papi_int_cpu_t cpu;
00390    _papi_int_multiplex_t multiplex;
00391    _papi_int_itimer_t itimer;
00392     _papi_int_inherit_t inherit;
00393     _papi_int_granularity_t granularity;
00394     _papi_int_addr_range_t address_range;
00395 } _papi_int_option_t;
00396 
00399 typedef struct {
00400    hwd_siginfo_t *si;
00401    hwd_ucontext_t *ucontext;
00402 } _papi_hwi_context_t;
00403 
00405 typedef struct _papi_mdi {
00406    DynamicArray_t global_eventset_map;  
00407    pid_t pid;                   
00408    PAPI_hw_info_t hw_info;      
00409    PAPI_exe_info_t exe_info;    
00410    PAPI_shlib_info_t shlib_info;    
00411    PAPI_preload_info_t preload_info; 
00412 } papi_mdi_t;
00413 
00414 extern papi_mdi_t _papi_hwi_system_info;
00415 extern int _papi_hwi_error_level;
00416 /* extern const hwi_describe_t _papi_hwi_err[PAPI_NUM_ERRORS]; */
00417 /*extern volatile int _papi_hwi_using_signal;*/
00418 extern int _papi_hwi_using_signal[PAPI_NSIG];
00419 
00421 typedef struct _papi_os_option {
00422    char name[PAPI_MAX_STR_LEN];     
00423    char version[PAPI_MAX_STR_LEN];  
00424    int os_version;                  
00425    int itimer_sig;                  
00426    int itimer_num;                  
00427    int itimer_ns;                   
00428    int itimer_res_ns;               
00429    int clock_ticks;                 
00430    unsigned long reserved[8];       /* For future expansion */
00431 } PAPI_os_info_t;
00432 
00433 extern PAPI_os_info_t _papi_os_info; /* For internal PAPI use only */
00434 
00435 #include "papi_lock.h"
00436 #include "threads.h"
00437 #include "cpus.h"
00438 
00439 EventSetInfo_t *_papi_hwi_lookup_EventSet( int eventset );
00440 int _papi_hwi_is_sw_multiplex( EventSetInfo_t * ESI );
00441 hwd_context_t *_papi_hwi_get_context( EventSetInfo_t * ESI, int *is_dirty );
00442 
00443 extern int _papi_hwi_error_level;
00444 extern PAPI_debug_handler_t _papi_hwi_debug_handler;
00445 void PAPIERROR( char *format, ... );
00446 int _papi_hwi_assign_eventset( EventSetInfo_t * ESI, int cidx );
00447 void _papi_hwi_free_EventSet( EventSetInfo_t * ESI );
00448 int _papi_hwi_create_eventset( int *EventSet, ThreadInfo_t * handle );
00449 int _papi_hwi_lookup_EventCodeIndex( const EventSetInfo_t * ESI,
00450                      unsigned int EventCode );
00451 int _papi_hwi_remove_EventSet( EventSetInfo_t * ESI );
00452 void _papi_hwi_map_events_to_native( EventSetInfo_t *ESI);
00453 int _papi_hwi_add_event( EventSetInfo_t * ESI, int EventCode );
00454 int _papi_hwi_remove_event( EventSetInfo_t * ESI, int EventCode );
00455 int _papi_hwi_read( hwd_context_t * context, EventSetInfo_t * ESI,
00456             long long *values );
00457 int _papi_hwi_cleanup_eventset( EventSetInfo_t * ESI );
00458 int _papi_hwi_convert_eventset_to_multiplex( _papi_int_multiplex_t * mpx );
00459 int _papi_hwi_init_global( void );
00460 int _papi_hwi_init_global_internal( void );
00461 int _papi_hwi_init_os(void);
00462 void _papi_hwi_init_errors(void);
00463 PAPI_os_info_t *_papi_hwi_get_os_info(void);
00464 void _papi_hwi_shutdown_global_internal( void );
00465 void _papi_hwi_dummy_handler( int EventSet, void *address, long long overflow_vector,
00466                   void *context );
00467 int _papi_hwi_get_preset_event_info( int EventCode, PAPI_event_info_t * info );
00468 int _papi_hwi_derived_type( char *tmp, int *code );
00469 
00470 int _papi_hwi_query_native_event( unsigned int EventCode );
00471 int _papi_hwi_get_native_event_info( unsigned int EventCode,
00472                                      PAPI_event_info_t * info );
00473 int _papi_hwi_native_name_to_code( char *in, int *out );
00474 int _papi_hwi_native_code_to_name( unsigned int EventCode, char *hwi_name,
00475                                    int len );
00476 
00477 
00478 int _papi_hwi_invalid_cmp( int cidx );
00479 int _papi_hwi_component_index( int event_code );
00480 int _papi_hwi_native_to_eventcode(int cidx, int event_code);
00481 int _papi_hwi_eventcode_to_native(int event_code);
00482 
00483 #endif /* PAPI_INTERNAL_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines