void vt_cupti_activity_finalize() { if(!vt_cuptiact_finalized && vt_cuptiact_initialized){ VT_CUPTI_ACT_LOCK(); if(!vt_cuptiact_finalized && vt_cuptiact_initialized){ vt_cntl_msg(2, "[CUPTI Activity] Finalizing ... "); vt_cuptiact_finalized = 1; VT_CUPTI_ACT_UNLOCK(); while(vt_cuptiact_ctxList != NULL){ vt_cuptiact_ctx_t *vtCtx = vt_cuptiact_ctxList; /* write buffered activities, which have not been dumped yet */ vt_cuptiact_flushCtxActivities(vtCtx->cuCtx); /* set pointer to next context before freeing current one */ vt_cuptiact_ctxList = vt_cuptiact_ctxList->next; /* free the context */ vt_cuptiact_destroyContext(vtCtx); } #if (defined(VT_MT) || defined (VT_HYB)) VTTHRD_LOCK_ENV(); VTThrd_deleteMutex(&VTThrdMutexCuptiAct); VTTHRD_UNLOCK_ENV(); #endif /* VT_MT || VT_HYB */ } } }
/* * Finalize the CUPTI common interface. * - free the VampirTrace CUPTI context list */ void vt_cupti_finalize() { if(!vt_cupti_finalized && vt_cupti_initialized){ VT_CUPTI_LOCK(); if(!vt_cupti_finalized && vt_cupti_initialized){ vt_cntl_msg(2, "[CUPTI] Finalizing ... "); /* free VampirTrace CUPTI context structures */ while(vt_cupti_ctxList != NULL){ vt_cupti_ctx_t *tmp = vt_cupti_ctxList; vt_cupti_ctxList = vt_cupti_ctxList->next; vt_cupti_finalizeCtx(tmp); tmp = NULL; } vt_cupti_finalized = 1; VT_CUPTI_UNLOCK(); #if (defined(VT_MT) || defined (VT_HYB)) VTTHRD_LOCK_ENV(); VTThrd_deleteMutex(&VTThrdMutexCupti); VTTHRD_UNLOCK_ENV(); #endif /* VT_MT || VT_HYB */ } } }
void VTThrd_destroy(VTThrd* thrd, uint32_t tid) { #if !defined(VT_DISABLE_RFG) RFG_Regions_free(thrd->rfg_regions); #endif /* VT_DISABLE_RFG */ VTGen_destroy(thrd->gen); #if defined(VT_RUSAGE) if ( vt_rusage_num() > 0 ) { if ( thrd->ru_obj ) { vt_rusage_free(thrd->ru_obj); thrd->ru_obj = NULL; } if ( thrd->ru_valv ) { free(thrd->ru_valv); thrd->ru_valv = NULL; } } #endif /* VT_RUSAGE */ #if defined(VT_METR) if ( vt_metric_num() > 0 && thrd->is_virtual_thread == 0 ) { if ( thrd->metv ) { vt_metric_free(thrd->metv, tid); thrd->metv = NULL; } if ( thrd->offv ) { free(thrd->offv); thrd->offv = NULL; } if ( thrd->valv ) { free(thrd->valv); thrd->valv = NULL; } } #endif /* VT_METR */ free(thrd); /* decrement the thread object counter */ #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_LOCK_ENV(); VTThrdn--; vt_cntl_msg(2, "Thread object #%u destroyed, leaving %u", tid, VTThrdn); VTTHRD_UNLOCK_ENV(); #else /* VT_MT || VT_HYB || VT_JAVA */ VTThrdn--; vt_cntl_msg(2, "Thread object #%u destroyed, leaving %u", tid, VTThrdn); #endif /* VT_MT || VT_HYB || VT_JAVA */ }
/* * Finalizes the VampirTrace CUPTI implementation. */ void vt_cupti_finalize() { if(!vt_cupti_finalized){ CUPTI_LOCK(); if(!vt_cupti_finalized){ vt_cntl_msg(2, "[CUPTI] Finalizing ..."); /* free VampirTrace CUPTI context structures (should already be freed) */ while(vtcuptiCtxlist != NULL){ vt_cupti_ctx_t *tmp = vtcuptiCtxlist; vt_cupti_finish(vtcuptiCtxlist); vtcuptiCtxlist = vtcuptiCtxlist->next; free(tmp); tmp = NULL; } /* free capability metric list */ while(vt_cupti_capList != NULL){ vt_cupti_dev_t *tmp = vt_cupti_capList; vt_cupti_capList = vt_cupti_capList->next; /* free VampirTrace CUPTI events */ while(tmp->vtcuptiEvtList != NULL){ vt_cupti_evt_t *tmpEvt = tmp->vtcuptiEvtList; tmp->vtcuptiEvtList = tmp->vtcuptiEvtList->next; free(tmpEvt); tmpEvt = NULL; } free(tmp); tmp = NULL; } vt_cupti_finalized = 1; CUPTI_UNLOCK(); #if (defined(VT_MT) || defined (VT_HYB)) VTTHRD_LOCK_ENV(); VTThrd_deleteMutex(&VTThrdMutexCupti); VTTHRD_UNLOCK_ENV(); #endif /* VT_MT || VT_HYB */ } } }
uint32_t VTThrd_createNewThreadId() { uint32_t tid; #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_LOCK_ENV(); #endif /* VT_MT || VT_HYB || VT_JAVA */ if ( VTThrdn > VTThrdMaxNum ) { #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_UNLOCK_ENV(); #endif /* VT_MT || VT_HYB || VT_JAVA */ vt_error_msg("Cannot create more than %d threads", VTThrdMaxNum); } tid = VTThrdn; VTThrdn++; #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_UNLOCK_ENV(); #endif /* VT_MT || VT_HYB || VT_JAVA */ return tid; }
void VTThrd_delete(VTThrd* thrd, uint32_t tid) { if ( !thrd ) return; #if !defined(VT_DISABLE_RFG) if ( thrd->rfg_regions ) RFG_Regions_free(thrd->rfg_regions); #endif /* VT_DISABLE_RFG */ /* must be called before VTGen_delete */ #if defined(VT_PLUGIN_CNTR) /* if we really use plugins and this thread also uses some */ if ( vt_plugin_cntr_used && thrd->plugin_cntr_defines ){ vt_plugin_cntr_thread_exit(thrd); } #endif /* VT_PLUGIN_CNTR */ if ( thrd->gen ) VTGen_delete(thrd->gen); #if defined(VT_RUSAGE) if ( vt_rusage_num() > 0 ) { if ( thrd->ru_obj ) { vt_rusage_free(thrd->ru_obj); thrd->ru_obj = NULL; } if ( thrd->ru_valv ) { free(thrd->ru_valv); thrd->ru_valv = NULL; } } #endif /* VT_RUSAGE */ #if defined(VT_METR) if ( vt_metric_num() > 0 && thrd->is_virtual_thread == 0 ) { if ( thrd->metv ) { vt_metric_free(thrd->metv, tid); thrd->metv = NULL; } if ( thrd->offv ) { free( thrd->offv ); thrd->offv = NULL; } if ( thrd->valv ) { free(thrd->valv); thrd->valv = NULL; } } #endif /* VT_METR */ free(thrd); /* decrement the thread object counter */ #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_LOCK_ENV(); VTThrdn--; vt_cntl_msg(2, "Thread object #%u deleted, leaving %u", tid, VTThrdn); VTTHRD_UNLOCK_ENV(); #else /* VT_MT || VT_HYB || VT_JAVA */ VTThrdn--; vt_cntl_msg(2, "Thread object #%u deleted, leaving %u", tid, VTThrdn); #endif /* VT_MT || VT_HYB || VT_JAVA */ }
void VTThrd_create(uint32_t tid, uint32_t ptid, const char* tname, uint8_t is_virtual) { VTThrd *thread; #if defined(VT_METR) uint32_t num_metrics = (uint32_t)vt_metric_num(); #endif /* VT_METR */ #if defined(VT_RUSAGE) uint32_t num_rusage = (uint32_t)vt_rusage_num(); #endif /* VT_RUSAGE */ thread = (VTThrd*)calloc(1, sizeof(VTThrd)); if ( thread == NULL ) vt_error(); /* set thread name, if available */ if ( tname == NULL ) { if ( tid == 0 ) tname = "Process"; else tname = "Thread"; } /* set thread name */ strncpy(thread->name, tname, sizeof(thread->name)); thread->name[sizeof(thread->name)-1] = '\0'; /* set thread name suffix */ if ( tid != 0 ) { #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_LOCK_ENV(); #endif /* VT_MT || VT_HYB || VT_JAVA */ snprintf(thread->name_suffix, sizeof(thread->name_suffix)-1, "%s:%d", VTThrdv[ptid]->name_suffix, ++(VTThrdv[ptid]->child_num)); #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_UNLOCK_ENV(); #endif /* VT_MT || VT_HYB || VT_JAVA */ } /* set parent ID of thread */ thread->parent_tid = ptid; /* set the virtual thread flag */ thread->is_virtual_thread = is_virtual; #if defined(VT_GETCPU) thread->cpuid_val = (uint32_t)-1; #endif /* VT_GETCPU */ #if defined(VT_RUSAGE) if ( num_rusage > 0 ) { /* create rusage object */ thread->ru_obj = vt_rusage_create(); /* initialize per-thread arrays for rusage counter values */ thread->ru_valv = (uint64_t*)calloc(num_rusage, sizeof(uint64_t)); if ( thread->ru_valv == NULL ) vt_error(); /* initialize next timestamp for reading rusage counters */ thread->ru_next_read = 0; } #endif /* VT_RUSAGE */ #if defined(VT_METR) if ( num_metrics > 0 && is_virtual == 0) { /* create event set */ thread->metv = vt_metric_create(); # if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) /* initialize per-thread arrays for counter offsets */ thread->offv = (uint64_t*)calloc(num_metrics, sizeof(uint64_t)); if ( thread->offv == NULL ) vt_error(); #endif /* VT_MT || VT_HYB || VT_JAVA */ /* initialize per-thread arrays for counter values */ thread->valv = (uint64_t*)calloc(num_metrics, sizeof(uint64_t)); if ( thread->valv == NULL ) vt_error(); } #endif /* VT_METR */ #if !defined(VT_DISABLE_RFG) /* initialize region filter and grouping management */ thread->rfg_regions = RFG_Regions_init(); if( thread->rfg_regions == NULL ) vt_error_msg("Could not initialize region filter and grouping management"); #endif /* VT_DISABLE_RFG */ /* enable tracing */ thread->trace_status = VT_TRACE_ON; VTThrdv[tid] = thread; #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_LOCK_ENV(); vt_cntl_msg(2, "Thread object #%u created, total number is %u", tid, VTThrdn); VTTHRD_UNLOCK_ENV(); #else /* VT_MT || VT_HYB || VT_JAVA */ vt_cntl_msg(2, "Thread object #%u created, total number is %u", tid, VTThrdn); #endif /* VT_MT || VT_HYB || VT_JAVA */ }