62 #include <sys/sysinfo.h> 84 #define HPCRUN_OPTION_MERGE_THREAD "HPCRUN_MERGE_THREADS" 85 #define HPCRUN_THREADS_DEBUG 0 103 #if HPCRUN_THREADS_DEBUG 104 static atomic_int_least32_t threadmgr_tot_threads =
ATOMIC_VAR_INIT(1);
117 adjust_thread_count(int32_t val)
160 TMSG(EPOCH,
"process init setting up initial epoch/loadmap");
202 while (data !=
NULL) {
206 TMSG(PROCESS,
"%d: write thread data", cptd->
id);
220 adjust_thread_count(1);
227 adjust_thread_count(-1);
246 static int compact_thread = -1;
248 if (compact_thread >= 0) {
249 return compact_thread;
254 compact_thread = atoi(env_option);
255 EMSG(
"hpcrun compact thread: %d", compact_thread);
259 return compact_thread;
293 bool need_to_allocate = (*data ==
NULL);
295 if (need_to_allocate) {
301 #if HPCRUN_THREADS_DEBUG 305 return need_to_allocate;
356 int num_cores = get_nprocs();
358 int max_iter = num_cores < num_log_thr ? num_cores : num_log_thr;
365 monitor_disable_new_threads();
375 pthread_t threads[max_iter];
378 pthread_attr_init(&attr);
379 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
381 for (
int i=0; !
SLIST_EMPTY(&list_thread_head) && i < max_iter; i++)
388 EMSG(
"Error cannot create thread %d with return code: %d",
389 (item ? item->thread_data->core_profile_trace_data.id : -1), rc);
399 pthread_attr_destroy(&attr);
402 for(
int i=0; i<num_threads; i++) {
403 int rc = pthread_join(threads[i], &status);
405 EMSG(
"Error: return code from pthread_join: %d for thread #%d", rc, i);
413 monitor_enable_new_threads();
427 #if HPCRUN_THREADS_DEBUG 429 EMSG(
"Total threads: %d, logical threads: %d", tot_threads, num_threads);
static atomic_int_least32_t threadmgr_num_threads
void hpcrun_threadMgr_data_fini(thread_data_t *td)
void hpcrun_set_thread_data(thread_data_t *td)
static SLIST_HEAD(thread_list_head, thread_list_s)
#define SLIST_HEAD_INITIALIZER(head)
static int32_t get_num_logical_threads()
struct thread_list_s thread_list_t
static thread_list_t * grab_thread_data()
void hpcrun_trace_open(core_profile_trace_data_t *cptd)
#define atomic_fetch_add_explicit(object, operand, order)
#define ATOMIC_VAR_INIT(value)
void hpcrun_threadmgr_thread_delete()
thread_data_t * thread_data
int hpcrun_threadmgr_thread_count()
static void spinlock_unlock(spinlock_t *l)
void hpcrun_threadMgr_data_put(epoch_t *epoch, thread_data_t *data)
void hpcrun_trace_append(core_profile_trace_data_t *cptd, cct_node_t *node, uint metric_id)
#define SLIST_REMOVE_HEAD(head, field)
static int32_t adjust_num_logical_threads(int32_t val)
#define OPTION_NO_COMPACT_THREAD
static atomic_int_least32_t threadmgr_active_threads
static bool is_compact_thread()
size_t hpcrun_get_num_sample_sources(void)
#define OPTION_COMPACT_THREAD
void hpcrun_thread_data_init(int id, cct_ctxt_t *thr_ctxt, int is_child, size_t n_sources)
#define atomic_load_explicit(object, order)
void hpcrun_trace_close(core_profile_trace_data_t *cptd)
int hpcrun_write_profile_data(core_profile_trace_data_t *cptd)
bool hpcrun_threadMgr_data_get(int id, cct_ctxt_t *thr_ctxt, thread_data_t **data)
void hpcrun_threadmgr_thread_new()
void hpcrun_epoch_init(cct_ctxt_t *ctxt)
static void finalize_thread_data(core_profile_trace_data_t *current_data)
#define SLIST_FIRST(head)
#define SLIST_EMPTY(head)
static void * finalize_all_thread_data(void *arg)
core_profile_trace_data_t core_profile_trace_data
cct_node_t * hpcrun_cct_bundle_get_nothread_node(cct_bundle_t *cct)
void * hpcrun_malloc(size_t size)
int hpcrun_threadMgr_compact_thread()
static void spinlock_lock(spinlock_t *l)
#define SLIST_ENTRY(type)
#define SPINLOCK_UNLOCKED
#define HPCRUN_OPTION_MERGE_THREAD
static thread_data_t * allocate_and_init_thread_data(int id, cct_ctxt_t *thr_ctxt)
thread_data_t * hpcrun_allocate_thread_data(int id)
#define SLIST_INSERT_HEAD(head, elm, field)