PAPI 7.1.0.0
Loading...
Searching...
No Matches
sde_lib_ti.h File Reference

Go to the source code of this file.

Functions

int sde_ti_read_counter (uint32_t counter_id, long long int *rslt_ptr)
 
int sde_ti_write_counter (uint32_t counter_id, long long value)
 
int sde_ti_reset_counter (uint32_t counter_id)
 
int sde_ti_name_to_code (const char *event_name, uint32_t *event_code)
 
int sde_ti_is_simple_counter (uint32_t counter_id)
 
int sde_ti_is_counter_set_to_overflow (uint32_t counter_id)
 
int sde_ti_set_counter_overflow (uint32_t counter_id, int threshold)
 
char * sde_ti_get_event_name (int event_id)
 
char * sde_ti_get_event_description (int event_id)
 
int sde_ti_get_num_reg_events (void)
 
int sde_ti_shutdown (void)
 

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_ti.h.

Function Documentation

◆ sde_ti_get_event_description()

char * sde_ti_get_event_description ( int  event_id)

Definition at line 416 of file sde_lib_ti.c.

416 {
417
418 papisde_control_t *gctl = _papisde_global_control;
419 if( NULL == gctl )
420 return NULL;
421
422 sde_counter_t *counter = ht_lookup_by_id(gctl->all_reg_counters, event_id);
423 if( NULL == counter )
424 return NULL;
425
426 return counter->description;
427}
papisde_control_t * _papisde_global_control
Definition: sde_lib.c:37
sde_counter_t * ht_lookup_by_id(papisde_list_entry_t *hash_table, uint32_t uniq_id)

◆ sde_ti_get_event_name()

char * sde_ti_get_event_name ( int  event_id)

Definition at line 399 of file sde_lib_ti.c.

399 {
400
401 papisde_control_t *gctl = _papisde_global_control;
402 if( NULL == gctl )
403 return NULL;
404
405 sde_counter_t *counter = ht_lookup_by_id(gctl->all_reg_counters, event_id);
406 if( NULL == counter )
407 return NULL;
408
409 return counter->name;
410}

◆ sde_ti_get_num_reg_events()

int sde_ti_get_num_reg_events ( void  )

Definition at line 433 of file sde_lib_ti.c.

433 {
434
435 papisde_control_t *gctl = _papisde_global_control;
436 if( NULL == gctl )
437 return 0;
438
439 return gctl->num_reg_events;
440}

◆ sde_ti_is_counter_set_to_overflow()

int sde_ti_is_counter_set_to_overflow ( uint32_t  counter_id)

Definition at line 343 of file sde_lib_ti.c.

343 {
344
345 papisde_control_t *gctl = _papisde_global_control;
346 if( NULL == gctl )
347 return 0;
348
349 sde_counter_t *counter = ht_lookup_by_id(gctl->all_reg_counters, counter_id);
350 if( (NULL == counter) || !counter->overflow || IS_CNTR_CREATED(counter) )
351 return 0;
352
353 return 1;
354}
#define IS_CNTR_CREATED(_CNT)

◆ sde_ti_is_simple_counter()

int sde_ti_is_simple_counter ( uint32_t  counter_id)

Definition at line 325 of file sde_lib_ti.c.

325 {
326
327 papisde_control_t *gctl = _papisde_global_control;
328 if( NULL == gctl )
329 return 0;
330
331 sde_counter_t *counter = ht_lookup_by_id(gctl->all_reg_counters, counter_id);
332
333 if( (NULL == counter) || !IS_CNTR_REGISTERED(counter) )
334 return 0;
335
336 return 1;
337}
#define IS_CNTR_REGISTERED(_CNT)

◆ sde_ti_name_to_code()

int sde_ti_name_to_code ( const char *  event_name,
uint32_t *  event_code 
)

Definition at line 204 of file sde_lib_ti.c.

204 {
205 int ret_val;
206 papisde_library_desc_t *lib_handle;
207 char *pos, *tmp_lib_name;
208 sde_counter_t *tmp_item = NULL;
209 papisde_control_t *gctl;
210
211 SDEDBG( "%s\n", event_name );
212
213 sde_lock();
215
216 // Let's see if the event has the library name as a prefix (as it should). Note that this is
217 // the event name as it comes from the framework, so it should contain the library name, although
218 // when the library registers an event counter it will not use the library name as part of the event name.
219 tmp_lib_name = strdup(event_name);
220 pos = strstr(tmp_lib_name, "::");
221 if( NULL != pos ){ // Good, it does.
222 *pos = '\0';
223
224 if( NULL == gctl ){
225 // If no library has initialized SDEs, and the application is already inquiring
226 // about an event, let's initialize SDEs pretending to be the library which corresponds to this event.
227 gctl = sdei_get_global_struct();
228 lib_handle = do_sde_init(tmp_lib_name, gctl);
229 if(NULL == lib_handle){
230 SDE_ERROR("sde_ti_name_to_code(): Initialized SDE but unable to register new library: %s\n", tmp_lib_name);
231 ret_val = SDE_ECMP;
232 goto fn_exit;
233 }
234 }else{
235 int is_library_present = 0;
236 // If the library side of the component has been initialized, then look for the library.
237 lib_handle = gctl->lib_list_head;
238 while(NULL != lib_handle){ // Look for the library.
239 if( !strcmp(lib_handle->libraryName, tmp_lib_name) ){
240 // We found the library.
241 is_library_present = 1;
242 // Now, look for the event in the library.
243 tmp_item = ht_lookup_by_name(lib_handle->lib_counters, event_name);
244 break;
245 }
246 lib_handle = lib_handle->next;
247 }
248
249 if( !is_library_present ){
250 // If the library side of the component was initialized, but the specific library hasn't called
251 // papi_sde_init() then we call it here to allocate the data structures.
252 lib_handle = do_sde_init(tmp_lib_name, gctl);
253 if(NULL == lib_handle){
254 SDE_ERROR("sde_ti_name_to_code(): Unable to register new library: %s\n", tmp_lib_name);
255 ret_val = SDE_ECMP;
256 goto fn_exit;
257 }
258 }
259 }
260 free(tmp_lib_name); // We don't need the library name any more.
261
262 if( NULL != tmp_item ){
263 SDEDBG("Found matching counter with global uniq id: %d in library: %s\n", tmp_item->glb_uniq_id, lib_handle->libraryName );
264 *event_code = tmp_item->glb_uniq_id;
265 ret_val = SDE_OK;
266 goto fn_exit;
267 } else {
268 cntr_class_specific_t cntr_union = {0};
269 SDEDBG("Did not find event %s in library %s. Registering a placeholder.\n", event_name, lib_handle->libraryName );
270
271 // Use the current number of registered events as the index of the new one, and increment it.
272 uint32_t counter_uniq_id = gctl->num_reg_events++;
273 gctl->num_live_events++;
274
275 // At this point in the code "lib_handle" contains a pointer to the data structure for this library whether
276 // the actual library has been initialized or not.
277 tmp_item = allocate_and_insert(gctl, lib_handle, event_name, counter_uniq_id, PAPI_SDE_RO, PAPI_SDE_long_long, CNTR_CLASS_PLACEHOLDER, cntr_union );
278 if(NULL == tmp_item) {
279 SDEDBG("Event %s does not exist in library %s and placeholder could not be inserted.\n", event_name, lib_handle->libraryName);
280 ret_val = SDE_ECMP;
281 goto fn_exit;
282 }
283 *event_code = tmp_item->glb_uniq_id;
284 ret_val = SDE_OK;
285 goto fn_exit;
286 }
287 }else{
288 free(tmp_lib_name);
289 }
290
291 // If no library has initialized the component and we don't know a library name, then we have to return.
292 if( NULL == gctl ){
293 ret_val = SDE_ENOEVNT;
294 goto fn_exit;
295 }
296
297 // If the event name does not have the library name as a prefix, then we need to look in all the libraries for the event. However, in this case
298 // we can _not_ register a placeholder because we don't know which library the event belongs to.
299 lib_handle = gctl->lib_list_head;
300 while(NULL != lib_handle){
301
302 tmp_item = ht_lookup_by_name(lib_handle->lib_counters, event_name);
303 if( NULL != tmp_item ){
304 *event_code = tmp_item->glb_uniq_id;
305 SDEDBG("Found matching counter with global uniq id: %d in library: %s\n", tmp_item->glb_uniq_id, lib_handle->libraryName );
306 ret_val = SDE_OK;
307 goto fn_exit;
308 } else {
309 SDEDBG("Failed to find event %s in library %s. Looking in other libraries.\n", event_name, lib_handle->libraryName );
310 }
311
312 lib_handle = lib_handle->next;
313 }
314
315 ret_val = SDE_ENOEVNT;
316fn_exit:
317 sde_unlock();
318 return ret_val;
319}
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define SDE_ENOEVNT
Definition: sde_lib.h:43
#define PAPI_SDE_long_long
Definition: sde_lib.h:28
#define SDE_ECMP
Definition: sde_lib.h:42
#define PAPI_SDE_RO
Definition: sde_lib.h:23
static void SDE_ERROR(const char *format,...)
Definition: sde_lib.h:60
#define SDEDBG(format, args...)
Definition: sde_lib.h:58
#define SDE_OK
Definition: sde_lib.h:39
sde_counter_t * ht_lookup_by_name(papisde_list_entry_t *hash_table, const char *name)
@ CNTR_CLASS_PLACEHOLDER
papi_handle_t do_sde_init(const char *name_of_library, papisde_control_t *gctl)
Definition: sde_lib_misc.c:91
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
papisde_control_t * sdei_get_global_struct(void)
Definition: sde_lib_misc.c:34
#define sde_lock()
Definition: sde_lib_lock.h:24
#define sde_unlock(lck)
Definition: sde_lib_lock.h:29

◆ sde_ti_read_counter()

int sde_ti_read_counter ( uint32_t  counter_id,
long long int rslt_ptr 
)

◆ sde_ti_reset_counter()

int sde_ti_reset_counter ( uint32_t  counter_id)

Definition at line 169 of file sde_lib_ti.c.

169 {
170 int ret_val = SDE_OK;
171 papisde_control_t *gctl;
172
174 if( NULL == gctl ){
175 SDE_ERROR("sde_ti_reset_counter(): Attempt to modify unintialized SDE structures.\n");
176 return SDE_EINVAL;
177 }
178
179 if( counter_id >= gctl->num_reg_events ){
180 SDE_ERROR("sde_ti_reset_counter(): SDE with id %d does not correspond to a registered event.\n",counter_id);
181 return SDE_EINVAL;
182 }
183
184 sde_counter_t *counter = ht_lookup_by_id(gctl->all_reg_counters, counter_id);
185 if( (NULL == counter) || (!IS_CNTR_BASIC(counter) && !IS_CNTR_CALLBACK(counter)) ){
186 SDEDBG("sde_ti_reset_counter(): SDE with id %d is clobbered, or a type which does not support resetting.\n",counter_id);
187 // We allow tools to call this function even if the counter type does not support
188 // reseting, so we do not return an error if this is the case.
189 return SDE_OK;
190 }
191
192 ret_val = sdei_read_and_update_data_value( counter, 0, &(counter->previous_data) );
193 if( SDE_OK != ret_val ){
194 SDE_ERROR("sde_ti_reset_counter(): Error occured when resetting counter: %s.\n",counter->name);
195 }
196
197 return ret_val;
198}
#define SDE_EINVAL
Definition: sde_lib.h:40
#define IS_CNTR_BASIC(_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
#define IS_CNTR_CALLBACK(_CNT)

◆ sde_ti_set_counter_overflow()

int sde_ti_set_counter_overflow ( uint32_t  counter_id,
int  threshold 
)

Definition at line 360 of file sde_lib_ti.c.

360 {
361
362 papisde_control_t *gctl = _papisde_global_control;
363 if( NULL == gctl )
364 return SDE_OK;
365
366 sde_counter_t *counter = ht_lookup_by_id(gctl->all_reg_counters, counter_id);
367 // If the counter is created then we will check for overflow every time its value gets updated, we don't need to poll.
368 // That is in cases c[1-3]
369 if( IS_CNTR_CREATED(counter) )
370 return SDE_OK;
371
372 // We do not want to overflow on recorders or counting-sets, because we don't even know what this means.
373 if( ( IS_CNTR_RECORDER(counter) || IS_CNTR_CSET(counter) ) && (threshold > 0) ){
374 return SDE_EINVAL;
375 }
376
377 // If we still don't know what type the counter is, then we are _not_ in r[1-3] so we can't create a timer here.
378 if( IS_CNTR_PLACEHOLDER(counter) && (threshold > 0) ){
379 SDEDBG("Event is a placeholder (it has not been registered by a library yet), so we cannot start overflow, but we can remember it.\n");
380 counter->overflow = 1;
381 return SDE_OK;
382 }
383
384 if( 0 == threshold ){
385 counter->overflow = 0;
386 }
387
388 // Return a number higher than SDE_OK (which is zero) to indicate to the caller that the timer needs to be set,
389 // because SDE_OK only means that there was no error, but the timer should not be set either because we are dealing
390 // with a placeholder, or created counter.
391 return 0xFF;
392}
static int threshold
#define IS_CNTR_CSET(_CNT)
#define IS_CNTR_RECORDER(_CNT)
#define IS_CNTR_PLACEHOLDER(_CNT)

◆ sde_ti_shutdown()

int sde_ti_shutdown ( void  )

Definition at line 446 of file sde_lib_ti.c.

446 {
447 return SDE_OK;
448}

◆ sde_ti_write_counter()

int sde_ti_write_counter ( uint32_t  counter_id,
long long  value 
)

Definition at line 136 of file sde_lib_ti.c.

136 {
137 papisde_control_t *gctl;
138 int ret_val = SDE_OK;
139
141 if( NULL == gctl ){
142 SDE_ERROR("sde_ti_write_counter(): Attempt to write in unintialized SDE structures.\n");
143 return SDE_EINVAL;
144 }
145
146 if( counter_id >= gctl->num_reg_events ){
147 SDE_ERROR("sde_ti_write_counter(): SDE with id %d does not correspond to a registered event.\n",counter_id);
148 return SDE_EINVAL;
149 }
150
151 sde_counter_t *counter = ht_lookup_by_id(gctl->all_reg_counters, counter_id);
152 if( (NULL == counter) || !IS_CNTR_BASIC(counter) ){
153 SDE_ERROR("sde_ti_write_counter(): SDE with id %d is clobbered, or a type which does not support writing.\n",counter_id);
154 return SDE_EINVAL;
155 }
156
157 ret_val = sdei_hardware_write( counter, value );
158 if( SDE_OK != ret_val ){
159 SDE_ERROR("sde_ti_write_counter(): Error occured when writing counter: '%s'.\n",counter->name);
160 }
161
162 return ret_val;
163}
int sdei_hardware_write(sde_counter_t *counter, long long int new_value)
Definition: sde_lib_misc.c:556