PAPI 7.1.0.0
Loading...
Searching...
No Matches
sde_lib_misc.c File Reference

This is a collection of internal utility functions that are needed to support SDEs. More...

Include dependency graph for sde_lib_misc.c:

Go to the source code of this file.

Macros

#define _SDE_AGGREGATE(_TYPE, _RSLT_TYPE)
 

Functions

static int aggregate_value_in_group (long long int *data, long long int *rslt, int cntr_type, int group_flags)
 
static int cast_and_store (void *data, long long int previous_value, void *rslt_ptr, int cntr_type)
 
static int free_counter_resources (sde_counter_t *counter)
 
static papisde_library_desc_t * find_library_by_name (const char *library_name, papisde_control_t *gctl)
 
static void insert_library_handle (papisde_library_desc_t *lib_handle, papisde_control_t *gctl)
 
papisde_control_t * sdei_get_global_struct (void)
 
papi_handle_t do_sde_init (const char *name_of_library, papisde_control_t *gctl)
 
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)
 
void sdei_counting_set_to_list (void *cset_handle, cset_list_object_t **list_head)
 
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)
 
int sdei_inc_ref_count (sde_counter_t *counter)
 
int sdei_delete_counter (papisde_library_desc_t *lib_handle, const char *name)
 
int sdei_read_counter_group (sde_counter_t *counter, long long int *rslt_ptr)
 
int sdei_read_and_update_data_value (sde_counter_t *counter, long long int previous_value, long long int *rslt_ptr)
 
int sdei_hardware_write (sde_counter_t *counter, long long int new_value)
 

Variables

int _sde_be_verbose = 0
 
int _sde_debug = 0
 

Detailed Description

Author
Anthony Danalis adana.nosp@m.lis@.nosp@m.icl.u.nosp@m.tk.e.nosp@m.du

Definition in file sde_lib_misc.c.

Macro Definition Documentation

◆ _SDE_AGGREGATE

#define _SDE_AGGREGATE (   _TYPE,
  _RSLT_TYPE 
)
Value:
do{\
switch(group_flags){\
case PAPI_SDE_SUM:\
*(_RSLT_TYPE *)rslt = (_RSLT_TYPE) ((_TYPE)(*(_RSLT_TYPE *)rslt) + (_TYPE)(*((_RSLT_TYPE *)data)) );\
break;\
case PAPI_SDE_MAX:\
if( *(_RSLT_TYPE *)rslt < *((_RSLT_TYPE *)data) )\
*(_RSLT_TYPE *)rslt = *((_RSLT_TYPE *)data);\
break;\
case PAPI_SDE_MIN:\
if( *(_RSLT_TYPE *)rslt > *((_RSLT_TYPE *)data) )\
*(_RSLT_TYPE *)rslt = *((_RSLT_TYPE *)data);\
break;\
default:\
SDEDBG("Unsupported counter group flag: %d\n",group_flags);\
return -1;\
} \
}while(0)
#define PAPI_SDE_MIN
Definition: sde_lib.h:35
#define PAPI_SDE_MAX
Definition: sde_lib.h:34
#define PAPI_SDE_SUM
Definition: sde_lib.h:33

Definition at line 448 of file sde_lib_misc.c.

Function Documentation

◆ aggregate_value_in_group()

static int aggregate_value_in_group ( long long int data,
long long int rslt,
int  cntr_type,
int  group_flags 
)
static

Definition at line 467 of file sde_lib_misc.c.

467 {
468 switch(cntr_type){
470 _SDE_AGGREGATE(long long int, long long int);
471 return SDE_OK;
472 case PAPI_SDE_int:
473 // We need to cast the result to "long long" so it is expanded to 64bit to take up all the space
474 _SDE_AGGREGATE(int, long long int);
475 return SDE_OK;
476 case PAPI_SDE_double:
477 _SDE_AGGREGATE(double, double);
478 return SDE_OK;
479 case PAPI_SDE_float:
480 // We need to cast the result to "double" so it is expanded to 64bit to take up all the space
481 _SDE_AGGREGATE(float, double);
482 return SDE_OK;
483 default:
484 SDEDBG("Unsupported counter type: %d\n",cntr_type);
485 return -1;
486 }
487}
#define PAPI_SDE_double
Definition: sde_lib.h:30
#define PAPI_SDE_float
Definition: sde_lib.h:31
#define PAPI_SDE_long_long
Definition: sde_lib.h:28
#define SDEDBG(format, args...)
Definition: sde_lib.h:58
#define PAPI_SDE_int
Definition: sde_lib.h:29
#define SDE_OK
Definition: sde_lib.h:39
#define _SDE_AGGREGATE(_TYPE, _RSLT_TYPE)
Definition: sde_lib_misc.c:448
Here is the caller graph for this function:

◆ allocate_and_insert()

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 at line 112 of file sde_lib_misc.c.

112 {
113
114 // make sure to calloc() the structure, so all the fields which we do not explicitly set remain zero.
115 sde_counter_t *item = (sde_counter_t *)calloc(1, sizeof(sde_counter_t));
116 if( NULL == item )
117 return NULL;
118
119 item->u = cntr_union;
120 item->cntr_class = cntr_class;
121 item->cntr_type = cntr_type;
122 item->cntr_mode = cntr_mode;
123 item->glb_uniq_id = uniq_id;
124 item->name = strdup( name );
125 item->description = strdup( name );
126 item->which_lib = lib_handle;
127
128 (void)ht_insert(lib_handle->lib_counters, ht_hash_name(name), item);
129 (void)ht_insert(gctl->all_reg_counters, ht_hash_id(uniq_id), item);
130
131 return item;
132}
const char * name
Definition: rocs.c:225
uint32_t ht_hash_name(const char *str)
void ht_insert(papisde_list_entry_t *hash_table, int ht_key, sde_counter_t *sde_counter)
uint32_t ht_hash_id(uint32_t uniq_id)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cast_and_store()

static int cast_and_store ( void *  data,
long long int  previous_value,
void *  rslt_ptr,
int  cntr_type 
)
inlinestatic

Definition at line 524 of file sde_lib_misc.c.

524 {
525 void *tmp_ptr;
526
527 switch(cntr_type){
529 *(long long int *)rslt_ptr = *((long long int *)data) - previous_value;
530 SDEDBG(" value LL=%lld (%lld-%lld)\n", *(long long int *)rslt_ptr, *((long long int *)data), previous_value);
531 return SDE_OK;
532 case PAPI_SDE_int:
533 // We need to cast the result to "long long" so it is expanded to 64bit to take up all the space
534 *(long long int *)rslt_ptr = (long long int) (*((int *)data) - (int)previous_value);
535 SDEDBG(" value LD=%lld (%d-%d)\n", *(long long int *)rslt_ptr, *((int *)data), (int)previous_value);
536 return SDE_OK;
537 case PAPI_SDE_double:
538 tmp_ptr = &previous_value;
539 *(double *)rslt_ptr = (*((double *)data) - *((double *)tmp_ptr));
540 SDEDBG(" value LF=%lf (%lf-%lf)\n", *(double *)rslt_ptr, *((double *)data), *((double *)tmp_ptr));
541 return SDE_OK;
542 case PAPI_SDE_float:
543 // We need to cast the result to "double" so it is expanded to 64bit to take up all the space
544 tmp_ptr = &previous_value;
545 *(double *)rslt_ptr = (double)(*((float *)data) - (float)(*((double *)tmp_ptr)) );
546 SDEDBG(" value F=%lf (%f-%f)\n", *(double *)rslt_ptr, *((float *)data), (float)(*((double *)tmp_ptr)) );
547 return SDE_OK;
548 default:
549 SDEDBG("Unsupported counter type: %d\n",cntr_type);
550 return -1;
551 }
552
553}
int
Definition: sde_internal.h:89
Here is the caller graph for this function:

◆ do_sde_init()

papi_handle_t do_sde_init ( const char *  name_of_library,
papisde_control_t *  gctl 
)

Definition at line 91 of file sde_lib_misc.c.

91 {
92
93 papisde_library_desc_t *tmp_lib;
94
95 SDEDBG("Registering library: '%s'\n",name_of_library);
96
97 // If the library is already initialized, return the handle to it
98 tmp_lib = find_library_by_name(name_of_library, gctl);
99 if( NULL != tmp_lib ){
100 return tmp_lib;
101 }
102
103 // If the library is not already initialized, then initialize it.
104 tmp_lib = ( papisde_library_desc_t* ) calloc( 1, sizeof( papisde_library_desc_t ) );
105 tmp_lib->libraryName = strdup(name_of_library);
106
107 insert_library_handle(tmp_lib, gctl);
108
109 return tmp_lib;
110}
static papisde_library_desc_t * find_library_by_name(const char *library_name, papisde_control_t *gctl)
Definition: sde_lib_misc.c:53
static void insert_library_handle(papisde_library_desc_t *lib_handle, papisde_control_t *gctl)
Definition: sde_lib_misc.c:79
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_library_by_name()

papisde_library_desc_t * find_library_by_name ( const char *  library_name,
papisde_control_t *  gctl 
)
static

This helper function checks to see if a given library has already been initialized and exists in the global structure of the component.

Parameters
[in]apointer to the global structure.
[in]astring containing the name of the library.
Returns
a pointer to the library handle.

Definition at line 53 of file sde_lib_misc.c.

53 {
54
55 if( (NULL == gctl) || (NULL == library_name) )
56 return NULL;
57
58 papisde_library_desc_t *tmp_lib = gctl->lib_list_head;
59 // Check to see if this library has already been initialized.
60 while(NULL != tmp_lib){
61 char *tmp_name = tmp_lib->libraryName;
62 SDEDBG("Checking library: '%s' against registered library: '%s'\n", library_name, tmp_lib->libraryName);
63 // If we find the same library already registered, we do not create a new entry.
64 if( (NULL != tmp_name) && !strcmp(tmp_name, library_name) )
65 return tmp_lib;
66
67 tmp_lib = tmp_lib->next;
68 }
69
70 return NULL;
71}
Here is the caller graph for this function:

◆ free_counter_resources()

int free_counter_resources ( sde_counter_t *  counter)
inlinestatic

Definition at line 351 of file sde_lib_misc.c.

351 {
352 int i, ret_val = SDE_OK;
353
354 if( NULL == counter )
355 return SDE_OK;
356
357 if( 0 == counter->ref_count ){
358 switch(counter->cntr_class){
360 SDEDBG(" + Freeing Created Counter Data.\n");
361 free(counter->u.cntr_basic.data);
362 break;
364 SDEDBG(" + Freeing Recorder Data.\n");
365 free(counter->u.cntr_recorder.data->sorted_buffer);
366 for(i=0; i<EXP_CONTAINER_ENTRIES; i++){
367 free(counter->u.cntr_recorder.data->ptr_array[i]);
368 }
369 free(counter->u.cntr_recorder.data);
370 break;
371 case CNTR_CLASS_CSET:
372 SDEDBG(" + Freeing CountingSet Data.\n");
373 ret_val = cset_delete(counter->u.cntr_cset.data);
374 break;
375 }
376
377 SDEDBG(" -> Freeing Counter '%s'.\n",counter->name);
378 free(counter->name);
379 free(counter->description);
380 free(counter);
381 }
382
383 return ret_val;
384}
int i
int cset_delete(cset_hash_table_t *hash_ptr)
@ CNTR_CLASS_CREATED
@ CNTR_CLASS_CSET
@ CNTR_CLASS_RECORDER
#define EXP_CONTAINER_ENTRIES
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert_library_handle()

void insert_library_handle ( papisde_library_desc_t *  lib_handle,
papisde_control_t *  gctl 
)
static

This helper function simply adds a library handle to the beginning of the list of libraries in the global structure. It's only reason of existence is to hide the structure of the linked list in case we want to change it in the future.

Parameters
[in]apointer to the library handle.
[in]apointer to the global structure.

Definition at line 79 of file sde_lib_misc.c.

79 {
80 SDEDBG("insert_library_handle(): inserting new handle for library: '%s'\n",lib_handle->libraryName);
81 lib_handle->next = gctl->lib_list_head;
82 gctl->lib_list_head = lib_handle;
83
84 return;
85}
Here is the caller graph for this function:

◆ sdei_counting_set_to_list()

void sdei_counting_set_to_list ( void *  cset_handle,
cset_list_object_t **  list_head 
)

Definition at line 135 of file sde_lib_misc.c.

136{
137 sde_counter_t *tmp_cset;
138
139 if( NULL == list_head )
140 return;
141
142 tmp_cset = (sde_counter_t *)cset_handle;
143 if( (NULL == tmp_cset) || !IS_CNTR_CSET(tmp_cset) || (NULL == tmp_cset->u.cntr_cset.data) ){
144 SDE_ERROR("sdei_counting_set_to_list(): 'cset_handle' is clobbered.");
145 return;
146 }
147
148 *list_head = cset_to_list(tmp_cset->u.cntr_cset.data);
149
150 return;
151}
static void SDE_ERROR(const char *format,...)
Definition: sde_lib.h:60
cset_list_object_t * cset_to_list(cset_hash_table_t *hash_ptr)
#define IS_CNTR_CSET(_CNT)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdei_delete_counter()

int sdei_delete_counter ( papisde_library_desc_t *  lib_handle,
const char *  name 
)

Definition at line 260 of file sde_lib_misc.c.

260 {
261 sde_counter_t *tmp_item;
262 papisde_control_t *gctl;
263 uint32_t item_uniq_id;
264 int ret_val = SDE_OK;
265
266 gctl = sdei_get_global_struct();
267
268 // Look for the counter entry in the hash-table of the library
269 tmp_item = ht_lookup_by_name(lib_handle->lib_counters, name);
270 if( NULL == tmp_item ){
271 ret_val = SDE_EINVAL;
272 goto fn_exit;
273 }
274
275 if( CNTR_CLASS_GROUP == tmp_item->cntr_class ){
276 papisde_list_entry_t *curr, *prev;
277 // If we are dealing with a goup, then we need to recurse down all its children and
278 // delete them (this might mean free them, or just decrement their ref_count).
279 curr = tmp_item->u.cntr_group.group_head;
280 prev = curr;
281 while(NULL != curr){
282 int counter_is_dead = 0;
283 sde_counter_t *tmp_cntr = curr->item;
284 if( NULL == tmp_cntr ){
285 ret_val = SDE_EMISC;
286 goto fn_exit;
287 }
288
289 // If this counter is going to be freed, we need to remove it from this group.
290 if( 0 == tmp_cntr->ref_count )
291 counter_is_dead = 1;
292
293 // recursively delete all the elements of the group.
294 int ret_val = sdei_delete_counter(lib_handle, tmp_cntr->name);
295 if( SDE_OK != ret_val )
296 goto fn_exit;
297
298 if( counter_is_dead ){
299 if( curr == tmp_item->u.cntr_group.group_head ){
300 // if we were removing with the head, change the head, we can't free() it.
301 tmp_item->u.cntr_group.group_head = curr->next;
302 prev = curr->next;
303 curr = curr->next;
304 }else{
305 // if we are removing an element, first bridge the previous to the next.
306 prev->next = curr->next;
307 free(curr);
308 curr = prev->next;
309 }
310 }else{
311 // if we are not removing anything, just move the pointers.
312 prev = curr;
313 curr = curr->next;
314 }
315 }
316 }
317
318 item_uniq_id = tmp_item->glb_uniq_id;
319
320 // If the reference count is not zero, then we don't remove it from the hash tables
321 if( 0 == tmp_item->ref_count ){
322 // Delete the entry from the library hash-table (which hashes by name)
323 tmp_item = ht_delete(lib_handle->lib_counters, ht_hash_name(name), item_uniq_id);
324 if( NULL == tmp_item ){
325 ret_val = SDE_EMISC;
326 goto fn_exit;
327 }
328
329 // Delete the entry from the global hash-table (which hashes by id) and free the memory
330 // occupied by the counter (not the hash-table entry 'papisde_list_entry_t', the 'sde_counter_t')
331 tmp_item = ht_delete(gctl->all_reg_counters, ht_hash_id(item_uniq_id), item_uniq_id);
332 if( NULL == tmp_item ){
333 ret_val = SDE_EMISC;
334 goto fn_exit;
335 }
336
337 // We free the counter only once, although it is in two hash-tables,
338 // because it is the same structure that is pointed to by both hash-tables.
339 free_counter_resources(tmp_item);
340
341 // Decrement the number of live events.
342 (gctl->num_live_events)--;
343 }else{
344 (tmp_item->ref_count)--;
345 }
346
347fn_exit:
348 return ret_val;
349}
#define SDE_EMISC
Definition: sde_lib.h:44
#define SDE_EINVAL
Definition: sde_lib.h:40
sde_counter_t * ht_delete(papisde_list_entry_t *hash_table, int ht_key, uint32_t uniq_id)
sde_counter_t * ht_lookup_by_name(papisde_list_entry_t *hash_table, const char *name)
@ CNTR_CLASS_GROUP
static int free_counter_resources(sde_counter_t *counter)
Definition: sde_lib_misc.c:351
int sdei_delete_counter(papisde_library_desc_t *lib_handle, const char *name)
Definition: sde_lib_misc.c:260
papisde_control_t * sdei_get_global_struct(void)
Definition: sde_lib_misc.c:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdei_get_global_struct()

papisde_control_t * sdei_get_global_struct ( void  )

sdei_get_global_struct() checks if the global structure has been allocated and allocates it if has not.

Returns
a pointer to the global structure.

Definition at line 34 of file sde_lib_misc.c.

34 {
35 // Allocate the global control structure, unless it has already been allocated by another library
36 // or the application code calling PAPI_name_to_code() for an SDE.
38 SDEDBG("sdei_get_global_struct(): global SDE control struct is being allocated.\n");
39 _papisde_global_control = (papisde_control_t *)calloc( 1, sizeof( papisde_control_t ) );
40 }
42}
papisde_control_t * _papisde_global_control
Definition: sde_lib.c:37
Here is the caller graph for this function:

◆ sdei_hardware_write()

int sdei_hardware_write ( sde_counter_t *  counter,
long long int  new_value 
)

Definition at line 556 of file sde_lib_misc.c.

556 {
557 double tmp_double;
558 void *tmp_ptr;
559
560 switch(counter->cntr_type){
562 *((long long int *)(counter->u.cntr_basic.data)) = new_value;
563 break;
564 case PAPI_SDE_int:
565 *((int *)(counter->u.cntr_basic.data)) = (int)new_value;
566 break;
567 case PAPI_SDE_double:
568 tmp_ptr = &new_value;
569 tmp_double = *((double *)tmp_ptr);
570 *((double *)(counter->u.cntr_basic.data)) = tmp_double;
571 break;
572 case PAPI_SDE_float:
573 // The pointer has to be 64bit. We can cast the variable to safely convert between bit-widths later on.
574 tmp_ptr = &new_value;
575 tmp_double = *((double *)tmp_ptr);
576 *((float *)(counter->u.cntr_basic.data)) = (float)tmp_double;
577 break;
578 default:
579 SDEDBG("Unsupported counter type: %d\n",counter->cntr_type);
580 return -1;
581 }
582
583 return SDE_OK;
584}
Here is the caller graph for this function:

◆ sdei_inc_ref_count()

int sdei_inc_ref_count ( sde_counter_t *  counter)

Definition at line 236 of file sde_lib_misc.c.

236 {
237 papisde_list_entry_t *curr;
238 if( NULL == counter )
239 return SDE_OK;
240
241 // If the counter is a group, recursivelly increment the ref_count of all its children.
242 if(CNTR_CLASS_GROUP == counter->cntr_class){
243 curr = counter->u.cntr_group.group_head;
244 do{
245 sde_counter_t *tmp_cntr = curr->item;
246 // recursively increment the ref_count of all the elements in the group.
247 int ret_val = sdei_inc_ref_count(tmp_cntr);
248 if( SDE_OK != ret_val )
249 return ret_val;
250 curr = curr->next;
251 }while(NULL != curr);
252 }
253
254 // Increment the ref_count of the counter itself, INCLUDING the case where the counter is a group.
255 (counter->ref_count)++;
256
257 return SDE_OK;
258}
int sdei_inc_ref_count(sde_counter_t *counter)
Definition: sde_lib_misc.c:236
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdei_read_and_update_data_value()

int sdei_read_and_update_data_value ( sde_counter_t *  counter,
long long int  previous_value,
long long int rslt_ptr 
)

Definition at line 490 of file sde_lib_misc.c.

490 {
491 int ret_val;
492 long long int tmp_int;
493 void *tmp_data;
494
495 char *event_name = counter->name;
496
497 if( IS_CNTR_BASIC(counter) ){
498 SDEDBG("Reading %s by accessing data pointer.\n", event_name);
499 tmp_data = counter->u.cntr_basic.data;
500 }else if( IS_CNTR_CALLBACK(counter) ){
501 SDEDBG("Reading %s by calling registered function pointer.\n", event_name);
502 tmp_int = counter->u.cntr_cb.callback(counter->u.cntr_cb.param);
503 tmp_data = &tmp_int;
504 }else{
505 SDEDBG("sdei_read_and_update_data_value(): Event %s has neither a variable nor a function pointer associated with it.\n", event_name);
506 return -1;
507 }
508
509 if( is_instant(counter->cntr_mode) ){
510 /* Instant counter means that we don't subtract the previous value (which we read at PAPI_Start()) */
511 previous_value = 0;
512 } else if( is_delta(counter->cntr_mode) ){
513 /* Do nothing here, this is the default mode */
514 } else{
515 SDEDBG("Unsupported mode (%d) for event: %s\n",counter->cntr_mode, event_name);
516 return -1;
517 }
518
519 ret_val = cast_and_store(tmp_data, previous_value, rslt_ptr, counter->cntr_type);
520 return ret_val;
521}
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define IS_CNTR_BASIC(_CNT)
#define is_delta(_X_)
#define is_instant(_X_)
#define IS_CNTR_CALLBACK(_CNT)
static int cast_and_store(void *data, long long int previous_value, void *rslt_ptr, int cntr_type)
Definition: sde_lib_misc.c:524
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdei_read_counter_group()

int sdei_read_counter_group ( sde_counter_t *  counter,
long long int rslt_ptr 
)

This function assumes that all counters in a group (including recursive subgroups) have the same type.

Definition at line 390 of file sde_lib_misc.c.

390 {
391 papisde_list_entry_t *curr;
392 long long int final_value = 0;
393
394 if( NULL == counter ){
395 SDE_ERROR("sdei_read_counter_group(): Counter parameter is NULL.\n");
396 return SDE_EINVAL;
397 }
398
399 if( !IS_CNTR_GROUP(counter) ){
400 SDE_ERROR("sdei_read_counter_group(): Counter '%s' is not a counter group.\n",counter->name);
401 return SDE_EINVAL;
402 }
403 curr = counter->u.cntr_group.group_head;
404
405 do{
406 long long int tmp_value = 0;
407 int ret_val;
408
409 sde_counter_t *tmp_cntr = curr->item;
410 if( NULL == tmp_cntr ){
411 SDE_ERROR("sdei_read_counter_group(): List of counters in counter group '%s' is clobbered.\n",counter->name);
412 return SDE_EINVAL;
413 }
414
415 int read_succesfully = 1;
416 // We can _not_ have a recorder inside a group.
417 if( IS_CNTR_RECORDER(tmp_cntr) || IS_CNTR_CSET(tmp_cntr) || IS_CNTR_PLACEHOLDER(tmp_cntr) ){
418 SDE_ERROR("sdei_read_counter_group(): Counter group contains counter: %s with class: %d.\n",tmp_cntr->name, tmp_cntr->cntr_class);
419 }else{
420 // We allow counter groups to contain other counter groups recursively.
421 if( IS_CNTR_GROUP(tmp_cntr) ){
422 ret_val = sdei_read_counter_group( tmp_cntr, &tmp_value );
423 if( ret_val != SDE_OK ){
424 // If something went wrong with one counter group, ignore it silently.
425 read_succesfully = 0;
426 }
427 }else{ // If we are here it means that we are trying to read a real counter.
428 ret_val = sdei_read_and_update_data_value( tmp_cntr, tmp_cntr->previous_data, &tmp_value );
429 if( SDE_OK != ret_val ){
430 SDE_ERROR("sdei_read_counter_group(): Error occured when reading counter: %s.\n",tmp_cntr->name);
431 read_succesfully = 0;
432 }
433 }
434
435 if( read_succesfully )
436 aggregate_value_in_group(&tmp_value, &final_value, tmp_cntr->cntr_type, counter->u.cntr_group.group_flags);
437 }
438
439 curr = curr->next;
440 }while(NULL != curr);
441
442 *rslt_ptr = final_value;
443 return SDE_OK;
444}
#define IS_CNTR_RECORDER(_CNT)
#define IS_CNTR_PLACEHOLDER(_CNT)
#define IS_CNTR_GROUP(_CNT)
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
int sdei_read_counter_group(sde_counter_t *counter, long long int *rslt_ptr)
Definition: sde_lib_misc.c:390
static int aggregate_value_in_group(long long int *data, long long int *rslt, int cntr_type, int group_flags)
Definition: sde_lib_misc.c:467
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdei_setup_counter_internals()

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 at line 156 of file sde_lib_misc.c.

157{
158 papisde_library_desc_t *lib_handle;
159 sde_counter_t *tmp_item;
160 uint32_t counter_uniq_id;
161 char *full_event_name;
162 int ret_val = SDE_OK;
163 int needs_overflow = 0;
164
165 lib_handle = (papisde_library_desc_t *) handle;
166 if( (NULL == lib_handle) || (NULL == lib_handle->libraryName) ){
167 SDE_ERROR("sdei_setup_counter_internals(): 'handle' is clobbered. Unable to register counter.");
168 return SDE_EINVAL;
169 }
170
171 size_t str_len = strlen(lib_handle->libraryName)+strlen(event_name)+2+1; // +2 for "::" and +1 for '\0'
172 full_event_name = (char *)malloc(str_len*sizeof(char));
173 snprintf(full_event_name, str_len, "%s::%s", lib_handle->libraryName, event_name);
174
175 SDEDBG("%s: Counter: '%s' will be added in library: %s.\n", __FILE__, full_event_name, lib_handle->libraryName);
176
177 if( !is_instant(cntr_mode) && !is_delta(cntr_mode) ){
178 SDE_ERROR("Unknown mode %d. SDE counter mode must be either Instant or Delta.",cntr_mode);
179 free(full_event_name);
180 return SDE_ECMP;
181 }
182
183 // Look if the event is already registered.
184 tmp_item = ht_lookup_by_name(lib_handle->lib_counters, full_event_name);
185
186 if( NULL != tmp_item ){
187 if( !IS_CNTR_PLACEHOLDER(tmp_item) ){
188 // If it is registered and it is _not_ a placeholder then ignore it silently.
189 SDEDBG("%s: Counter: '%s' was already in library: %s.\n", __FILE__, full_event_name, lib_handle->libraryName);
190 free(full_event_name);
191 return SDE_OK;
192 }
193 // If we are here, then it IS a placeholder, so check if we need to start overflowing.
194 if( tmp_item->overflow && ( (CNTR_CLASS_REGISTERED == cntr_class) || (CNTR_CLASS_CB == cntr_class) ) ){
195 needs_overflow = 1;
196 }
197
198 // Since the counter is a placeholder update the mode, the type, and the union that contains the 'data'.
199 SDEDBG("%s: Updating placeholder for counter: '%s' in library: %s.\n", __FILE__, full_event_name, lib_handle->libraryName);
200
201 tmp_item->u = cntr_union;
202 tmp_item->cntr_class = cntr_class;
203 tmp_item->cntr_mode = cntr_mode;
204 tmp_item->cntr_type = cntr_type;
205 free(full_event_name);
206
207 return SDE_OK;
208 }
209
210 // If neither the event, nor a placeholder exists, then use the current
211 // number of registered events as the index of the new one, and increment it.
212 papisde_control_t *gctl = sdei_get_global_struct();
213 counter_uniq_id = gctl->num_reg_events++;
214 gctl->num_live_events++;
215
216 SDEDBG("%s: Counter %s has unique ID = %d\n", __FILE__, full_event_name, counter_uniq_id);
217
218 tmp_item = allocate_and_insert( gctl, lib_handle, full_event_name, counter_uniq_id, cntr_mode, cntr_type, cntr_class, cntr_union );
219
220 if(NULL == tmp_item) {
221 SDEDBG("%s: Counter not inserted in SDE %s\n", __FILE__, lib_handle->libraryName);
222 free(full_event_name);
223 return SDE_ECMP;
224 }
225
226 free(full_event_name);
227
228 // Check if we need to worry about overflow (cases r[4-6])
229 if( needs_overflow ){
230 ret_val = sdei_set_timer_for_overflow();
231 }
232
233 return ret_val;
234}
static papi_handle_t handle
Definition: Gamum.c:21
int sdei_set_timer_for_overflow(void)
Definition: sde_lib.c:60
#define SDE_ECMP
Definition: sde_lib.h:42
@ CNTR_CLASS_CB
@ CNTR_CLASS_REGISTERED
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
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _sde_be_verbose

int _sde_be_verbose = 0

Definition at line 19 of file sde_lib_misc.c.

◆ _sde_debug

int _sde_debug = 0

Definition at line 20 of file sde_lib_misc.c.