PAPI 7.1.0.0
Loading...
Searching...
No Matches
sde_lib_internal.h
Go to the documentation of this file.
1
9#if !defined(PAPI_SDE_LIB_INTERNAL_H)
10#define PAPI_SDE_LIB_INTERNAL_H
11
12#include <stdio.h>
13#include <string.h>
14#include <stdlib.h>
15#include <stdint.h>
16#include <stdbool.h>
17#include <errno.h>
18#include <signal.h>
19#include <time.h>
20#include <dlfcn.h>
21#include <assert.h>
22#include "sde_lib.h"
23
24#define EXP_CONTAINER_ENTRIES 52
25#define EXP_CONTAINER_MIN_SIZE 2048
26
27#define PAPISDE_HT_SIZE 512
28
29#define is_readonly(_X_) (PAPI_SDE_RO == ((_X_)&0x0F))
30#define is_readwrite(_X_) (PAPI_SDE_RW == ((_X_)&0x0F))
31#define is_delta(_X_) (PAPI_SDE_DELTA == ((_X_)&0xF0))
32#define is_instant(_X_) (PAPI_SDE_INSTANT == ((_X_)&0xF0))
33
34typedef struct sde_counter_s sde_counter_t;
35typedef struct sde_sorting_params_s sde_sorting_params_t;
36typedef struct papisde_list_entry_s papisde_list_entry_t;
37typedef struct papisde_library_desc_s papisde_library_desc_t;
38typedef struct papisde_control_s papisde_control_t;
39typedef struct recorder_data_s recorder_data_t;
40
42extern papisde_control_t *_papisde_global_control;
43
44// _SDE_HASH_BUCKET_COUNT_ should not be a power of two, and even better it should be a prime.
45#if defined(SDE_HASH_SMALL) // 7.4KB storage
46 #define _SDE_HASH_BUCKET_COUNT_ 61
47 #define _SDE_HASH_BUCKET_WIDTH_ 5
48#else // 124KB storage (5222 elements)
49 #define _SDE_HASH_BUCKET_COUNT_ 373
50 #define _SDE_HASH_BUCKET_WIDTH_ 14
51#endif
52
53// defining SDE_HASH_IS_FUZZY to 1 will make the comparisons operation of the hash table
54// (which is used in the "counting sets") faster, but inaccurate. As a result, some input
55// elements might collide onto the same hash table entry, even if they are different.
56// If speed is more important than accurate counting for your library, then setting
57// SDE_HASH_IS_FUZZY to 1 is recommented.
58#define SDE_HASH_IS_FUZZY 0
59
60typedef struct cset_hash_decorated_object_s {
61 uint32_t count;
62 uint32_t type_id;
63 size_t type_size;
64 void *ptr;
66
67/*
68typedef struct sde_list_object_s sde_list_object_t;
69struct sde_list_object_s {
70 sde_hash_decorated_object_t object;
71 sde_list_object_t *next;
72};
73*/
74
75typedef struct cset_hash_bucket_s {
76 uint32_t occupied;
80
81typedef struct cset_hash_table_s {
83 cset_list_object_t *overflow_list;
85
86
87/* Hash table entry */
89 sde_counter_t *item;
90 papisde_list_entry_t *next;
91};
92
95 long long total_entries;
96 long long used_entries;
97 size_t typesize;
99 long long sorted_entries;
100};
101
102typedef struct cntr_class_basic_s {
103 void *data;
105
106typedef struct cntr_class_callback_s {
108 void *param;
110
111typedef struct cntr_class_recorder_s {
112 recorder_data_t *data;
114
115typedef struct cntr_class_cset_s {
118
119typedef struct cntr_class_group_s {
120 papisde_list_entry_t *group_head;
121 uint32_t group_flags;
123
124typedef union cntr_class_specific_u{
131
133 uint32_t glb_uniq_id;
134 char *name;
136 uint32_t cntr_class;
138 long long int previous_data;
143 papisde_library_desc_t *which_lib;
144};
145
147 sde_counter_t *recording;
148 int (*cmpr_func_ptr)(const void *p1, const void *p2);
149};
150
154 CNTR_CLASS_BASIC = 0x3, // both previous types combined.
159 CNTR_CLASS_GROUP = 0x2000
161
162#define IS_CNTR_REGISTERED(_CNT) ( CNTR_CLASS_REGISTERED == (_CNT)->cntr_class )
163#define IS_CNTR_CREATED(_CNT) ( CNTR_CLASS_CREATED == (_CNT)->cntr_class )
164#define IS_CNTR_BASIC(_CNT) ( CNTR_CLASS_BASIC & (_CNT)->cntr_class )
165#define IS_CNTR_CALLBACK(_CNT) ( CNTR_CLASS_CB == (_CNT)->cntr_class )
166#define IS_CNTR_RECORDER(_CNT) ( CNTR_CLASS_RECORDER == (_CNT)->cntr_class )
167#define IS_CNTR_CSET(_CNT) ( CNTR_CLASS_CSET == (_CNT)->cntr_class )
168#define IS_CNTR_PLACEHOLDER(_CNT) ( CNTR_CLASS_PLACEHOLDER == (_CNT)->cntr_class )
169#define IS_CNTR_GROUP(_CNT) ( CNTR_CLASS_GROUP == (_CNT)->cntr_class )
170
171/* This type describes one library. This is the type of the handle returned by papi_sde_init(). */
174 papisde_list_entry_t lib_counters[PAPISDE_HT_SIZE];
175 uint32_t disabled;
176 papisde_library_desc_t *next;
177};
178
179/* One global variable of this type holds pointers to all other SDE meta-data */
181 uint32_t num_reg_events; /* This number only increases, so it can be used as a uniq id */
182 uint32_t num_live_events; /* This number decreases at unregister() */
183 uint32_t disabled;
184 papisde_library_desc_t *lib_list_head;
186 papisde_list_entry_t all_reg_counters[PAPISDE_HT_SIZE];
187};
188
189int sdei_setup_counter_internals( papi_handle_t handle, const char *event_name, int cntr_mode, int cntr_type, enum CNTR_CLASS cntr_class, cntr_class_specific_t cntr_union );
190int sdei_delete_counter(papisde_library_desc_t* lib_handle, const char *name);
191int sdei_inc_ref_count(sde_counter_t *counter);
192int sdei_read_counter_group( sde_counter_t *counter, long long int *rslt_ptr );
193void sdei_counting_set_to_list( void *cset_handle, cset_list_object_t **list_head );
194int sdei_read_and_update_data_value( sde_counter_t *counter, long long int previous_value, long long int *rslt_ptr );
195int sdei_hardware_write( sde_counter_t *counter, long long int new_value );
197
198papisde_control_t *sdei_get_global_struct(void);
199sde_counter_t *ht_lookup_by_id(papisde_list_entry_t *hash_table, uint32_t uniq_id);
200sde_counter_t *ht_lookup_by_name(papisde_list_entry_t *hash_table, const char *name);
201sde_counter_t *ht_delete(papisde_list_entry_t *hash_table, int ht_key, uint32_t uniq_id);
202void ht_insert(papisde_list_entry_t *hash_table, int ht_key, sde_counter_t *sde_counter);
203int ht_to_array(papisde_list_entry_t *hash_table, sde_counter_t **rslt_array);
204uint32_t ht_hash_name(const char *str);
205uint32_t ht_hash_id(uint32_t uniq_id);
206papi_handle_t do_sde_init(const char *name_of_library, papisde_control_t *gctl);
207sde_counter_t *allocate_and_insert(papisde_control_t *gctl, papisde_library_desc_t* lib_handle, const char *name, uint32_t uniq_id, int cntr_mode, int cntr_type, enum CNTR_CLASS cntr_class, cntr_class_specific_t cntr_union);
208void exp_container_to_contiguous(recorder_data_t *exp_container, void *cont_buffer);
209int exp_container_insert_element(recorder_data_t *exp_container, size_t typesize, const void *value);
210void exp_container_init(sde_counter_t *handle, size_t typesize);
211void papi_sde_counting_set_to_list(void *cset_handle, cset_list_object_t **list_head);
212int cset_insert_elem(cset_hash_table_t *hash_ptr, size_t element_size, size_t hashable_size, const void *element, uint32_t type_id);
213int cset_remove_elem(cset_hash_table_t *hash_ptr, size_t hashable_size, const void *element, uint32_t type_id);
214cset_list_object_t *cset_to_list(cset_hash_table_t *hash_ptr);
215int cset_delete(cset_hash_table_t *hash_ptr);
216
217#pragma GCC visibility push(default)
218
219int sde_ti_reset_counter( uint32_t );
220int sde_ti_read_counter( uint32_t, long long int * );
221int sde_ti_write_counter( uint32_t, long long );
222int sde_ti_name_to_code( const char *, uint32_t * );
223int sde_ti_is_simple_counter( uint32_t );
225int sde_ti_set_counter_overflow( uint32_t, int );
226char * sde_ti_get_event_name( int );
227char * sde_ti_get_event_description( int );
228int sde_ti_get_num_reg_events( void );
229int sde_ti_shutdown( void );
230
231#pragma GCC visibility pop
232
233/*************************************************************************/
234/* Hashing code below copied verbatim from the "fast-hash" project: */
235/* https://github.com/ztanml/fast-hash */
236/*************************************************************************/
237
238// Compression function for Merkle-Damgard construction.
239#define mix(h) ({ \
240 (h) ^= (h) >> 23; \
241 (h) *= 0x2127599bf4325c37ULL; \
242 (h) ^= (h) >> 47; })
243
244
245static inline uint64_t fasthash64(const void *buf, size_t len, uint64_t seed)
246{
247 const uint64_t m = 0x880355f21e6d1965ULL;
248 const uint64_t *pos = (const uint64_t *)buf;
249 const uint64_t *end = pos + (len / 8);
250 const uint32_t *pos2;
251 uint64_t h = seed ^ (len * m);
252 uint64_t v;
253
254 while (pos != end) {
255 v = *pos++;
256 h ^= mix(v);
257 h *= m;
258 }
259
260 pos2 = (const uint32_t*)pos;
261 v = 0;
262
263 switch (len & 7) {
264 case 7: v ^= (uint64_t)pos2[6] << 48;
265 /* fall through */
266 case 6: v ^= (uint64_t)pos2[5] << 40;
267 /* fall through */
268 case 5: v ^= (uint64_t)pos2[4] << 32;
269 /* fall through */
270 case 4: v ^= (uint64_t)pos2[3] << 24;
271 /* fall through */
272 case 3: v ^= (uint64_t)pos2[2] << 16;
273 /* fall through */
274 case 2: v ^= (uint64_t)pos2[1] << 8;
275 /* fall through */
276 case 1: v ^= (uint64_t)pos2[0];
277 h ^= mix(v);
278 h *= m;
279 }
280
281 return mix(h);
282}
283
284#endif // !defined(PAPI_SDE_LIB_INTERNAL_H)
static papi_handle_t handle
Definition: Gamum.c:21
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
const char * name
Definition: rocs.c:225
int
Definition: sde_internal.h:89
SDE prototypes and macros.
void * papi_handle_t
Definition: sde_lib.h:100
long long int(* papi_sde_fptr_t)(void *)
Definition: sde_lib.h:98
int sde_ti_read_counter(uint32_t, long long int *)
int cset_delete(cset_hash_table_t *hash_ptr)
int sde_ti_is_simple_counter(uint32_t)
Definition: sde_lib_ti.c:325
CNTR_CLASS
@ CNTR_CLASS_GROUP
@ CNTR_CLASS_CREATED
@ CNTR_CLASS_CSET
@ CNTR_CLASS_CB
@ CNTR_CLASS_PLACEHOLDER
@ CNTR_CLASS_REGISTERED
@ CNTR_CLASS_BASIC
@ CNTR_CLASS_RECORDER
int sdei_setup_counter_internals(papi_handle_t handle, const char *event_name, int cntr_mode, int cntr_type, enum CNTR_CLASS cntr_class, cntr_class_specific_t cntr_union)
Definition: sde_lib_misc.c:156
#define _SDE_HASH_BUCKET_COUNT_
int cset_insert_elem(cset_hash_table_t *hash_ptr, size_t element_size, size_t hashable_size, const void *element, uint32_t type_id)
int sdei_read_and_update_data_value(sde_counter_t *counter, long long int previous_value, long long int *rslt_ptr)
Definition: sde_lib_misc.c:490
static uint64_t fasthash64(const void *buf, size_t len, uint64_t seed)
papisde_control_t * _papisde_global_control
Definition: sde_lib.c:37
int sde_ti_name_to_code(const char *, uint32_t *)
Definition: sde_lib_ti.c:204
uint32_t ht_hash_name(const char *str)
void exp_container_to_contiguous(recorder_data_t *exp_container, void *cont_buffer)
int sde_ti_is_counter_set_to_overflow(uint32_t)
Definition: sde_lib_ti.c:343
void sdei_counting_set_to_list(void *cset_handle, cset_list_object_t **list_head)
Definition: sde_lib_misc.c:135
papi_handle_t do_sde_init(const char *name_of_library, papisde_control_t *gctl)
Definition: sde_lib_misc.c:91
void ht_insert(papisde_list_entry_t *hash_table, int ht_key, sde_counter_t *sde_counter)
sde_counter_t * allocate_and_insert(papisde_control_t *gctl, papisde_library_desc_t *lib_handle, const char *name, uint32_t uniq_id, int cntr_mode, int cntr_type, enum CNTR_CLASS cntr_class, cntr_class_specific_t cntr_union)
Definition: sde_lib_misc.c:112
int ht_to_array(papisde_list_entry_t *hash_table, sde_counter_t **rslt_array)
int exp_container_insert_element(recorder_data_t *exp_container, size_t typesize, const void *value)
int sde_ti_reset_counter(uint32_t)
Definition: sde_lib_ti.c:169
sde_counter_t * ht_delete(papisde_list_entry_t *hash_table, int ht_key, uint32_t uniq_id)
int sdei_inc_ref_count(sde_counter_t *counter)
Definition: sde_lib_misc.c:236
int cset_remove_elem(cset_hash_table_t *hash_ptr, size_t hashable_size, const void *element, uint32_t type_id)
int sde_ti_set_counter_overflow(uint32_t, int)
Definition: sde_lib_ti.c:360
sde_counter_t * ht_lookup_by_name(papisde_list_entry_t *hash_table, const char *name)
sde_counter_t * ht_lookup_by_id(papisde_list_entry_t *hash_table, uint32_t uniq_id)
uint32_t ht_hash_id(uint32_t uniq_id)
int sdei_set_timer_for_overflow(void)
Definition: sde_lib.c:60
int sde_ti_get_num_reg_events(void)
Definition: sde_lib_ti.c:433
int sdei_read_counter_group(sde_counter_t *counter, long long int *rslt_ptr)
Definition: sde_lib_misc.c:390
int sdei_delete_counter(papisde_library_desc_t *lib_handle, const char *name)
Definition: sde_lib_misc.c:260
#define EXP_CONTAINER_ENTRIES
char * sde_ti_get_event_name(int)
Definition: sde_lib_ti.c:399
char * sde_ti_get_event_description(int)
Definition: sde_lib_ti.c:416
void papi_sde_counting_set_to_list(void *cset_handle, cset_list_object_t **list_head)
int sde_ti_write_counter(uint32_t, long long)
Definition: sde_lib_ti.c:136
#define _SDE_HASH_BUCKET_WIDTH_
int sdei_hardware_write(sde_counter_t *counter, long long int new_value)
Definition: sde_lib_misc.c:556
#define PAPISDE_HT_SIZE
#define mix(h)
cset_list_object_t * cset_to_list(cset_hash_table_t *hash_ptr)
papisde_control_t * sdei_get_global_struct(void)
Definition: sde_lib_misc.c:34
int sde_ti_shutdown(void)
Definition: sde_lib_ti.c:446
void exp_container_init(sde_counter_t *handle, size_t typesize)
papi_sde_fptr_t callback
cset_hash_table_t * data
papisde_list_entry_t * group_head
recorder_data_t * data
cset_list_object_t * overflow_list
papisde_library_desc_t * lib_list_head
papisde_list_entry_t all_reg_counters[PAPISDE_HT_SIZE]
papisde_list_entry_t lib_counters[PAPISDE_HT_SIZE]
papisde_library_desc_t * next
papisde_list_entry_t * next
sde_counter_t * item
void * ptr_array[EXP_CONTAINER_ENTRIES]
long long used_entries
long long sorted_entries
long long total_entries
uint32_t glb_uniq_id
long long int previous_data
papisde_library_desc_t * which_lib
cntr_class_specific_t u
int(* cmpr_func_ptr)(const void *p1, const void *p2)
sde_counter_t * recording
cntr_class_recorder_t cntr_recorder
cntr_class_cset_t cntr_cset
cntr_class_callback_t cntr_cb
cntr_class_group_t cntr_group
cntr_class_basic_t cntr_basic