Skip to content

Commit 7b0d2c6

Browse files
author
Marcus Winter
committed
Merge branch 'embb546_low_performance_on_arm' into development
2 parents 6dc01f7 + 24fae6c commit 7b0d2c6

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

mtapi_c/include/embb/mtapi/c/mtapi.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,9 @@ enum mtapi_node_attributes_enum {
552552
the node */
553553
MTAPI_NODE_MAX_ACTIONS_PER_JOB, /**< maximum number of actions in a job
554554
allowed by the node */
555-
MTAPI_NODE_MAX_PRIORITIES /**< maximum number of priorities
555+
MTAPI_NODE_MAX_PRIORITIES, /**< maximum number of priorities
556556
allowed by the node */
557+
MTAPI_NODE_REUSE_MAIN_THREAD /**< reuse main thread as worker */
557558
};
558559
/** size of the \a MTAPI_NODE_CORE_AFFINITY attribute */
559560
#define MTAPI_NODE_CORE_AFFINITY_SIZE sizeof(embb_core_set_t)
@@ -577,6 +578,8 @@ enum mtapi_node_attributes_enum {
577578
#define MTAPI_NODE_MAX_ACTIONS_PER_JOB_SIZE sizeof(mtapi_uint_t)
578579
/** size of the \a MTAPI_NODE_MAX_PRIORITIES attribute */
579580
#define MTAPI_NODE_MAX_PRIORITIES_SIZE sizeof(mtapi_uint_t)
581+
/** size of the \a MTAPI_NODE_REUSE_MAIN_THREAD attribute */
582+
#define MTAPI_NODE_REUSE_MAIN_THREAD_SIZE sizeof(mtapi_boolean_t)
580583

581584
/* example attribute value */
582585
#define MTAPI_NODE_TYPE_SMP 1
@@ -688,6 +691,8 @@ struct mtapi_node_attributes_struct {
688691
mtapi_uint_t max_actions_per_job; /**< stores
689692
MTAPI_NODE_MAX_ACTIONS_PER_JOB */
690693
mtapi_uint_t max_priorities; /**< stores MTAPI_NODE_MAX_PRIORITIES */
694+
mtapi_boolean_t reuse_main_thread; /**< stores
695+
MTAPI_NODE_REUSE_MAIN_THREAD */
691696
};
692697

693698
/**

mtapi_c/src/embb_mtapi_thread_context_t.c

+30-12
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ mtapi_boolean_t embb_mtapi_thread_context_initialize_with_node_worker_and_core(
5454
that->core_num = core_num;
5555
that->priorities = node->attributes.max_priorities;
5656
that->is_initialized = MTAPI_FALSE;
57+
that->is_main_thread = (worker_index == 0) ? node->attributes.reuse_main_thread : MTAPI_FALSE;
5758
embb_atomic_store_int(&that->run, 0);
5859

5960
that->queue = (embb_mtapi_task_queue_t**)embb_mtapi_alloc_allocate(
@@ -121,17 +122,29 @@ mtapi_boolean_t embb_mtapi_thread_context_start(
121122
embb_core_set_add(&core_set, that->core_num);
122123

123124
/* create thread */
124-
err = embb_thread_create(&that->thread, &core_set, worker_func, that);
125-
if (EMBB_SUCCESS != err) {
126-
embb_mtapi_log_error(
127-
"embb_mtapi_ThreadContext_initializeWithNodeAndCoreNumber() could not "
128-
"create thread %d on core %d\n", that->worker_index, that->core_num);
129-
return MTAPI_FALSE;
130-
}
131-
132-
/* wait for worker to come up */
133-
while (0 == embb_atomic_load_int(&that->run)) {
134-
embb_thread_yield();
125+
if (that->is_main_thread) {
126+
/* reuse main thread */
127+
that->thread = embb_thread_current();
128+
err = embb_tss_create(&that->tss_id);
129+
if (EMBB_SUCCESS != err) {
130+
/* report error to scheduler */
131+
embb_atomic_store_int(&that->run, -1);
132+
return MTAPI_FALSE;
133+
}
134+
embb_tss_set(&(that->tss_id), that);
135+
embb_atomic_store_int(&that->run, 1);
136+
} else {
137+
err = embb_thread_create(&that->thread, &core_set, worker_func, that);
138+
if (EMBB_SUCCESS != err) {
139+
embb_mtapi_log_error(
140+
"embb_mtapi_ThreadContext_initializeWithNodeAndCoreNumber() could not "
141+
"create thread %d on core %d\n", that->worker_index, that->core_num);
142+
return MTAPI_FALSE;
143+
}
144+
/* wait for worker to come up */
145+
while (0 == embb_atomic_load_int(&that->run)) {
146+
embb_thread_yield();
147+
}
135148
}
136149

137150
if (0 < embb_atomic_load_int(&that->run)) {
@@ -146,7 +159,9 @@ void embb_mtapi_thread_context_stop(embb_mtapi_thread_context_t* that) {
146159
if (0 < embb_atomic_load_int(&that->run)) {
147160
embb_atomic_store_int(&that->run, 0);
148161
embb_condition_notify_one(&that->work_available);
149-
embb_thread_join(&(that->thread), &result);
162+
if (MTAPI_FALSE == that->is_main_thread) {
163+
embb_thread_join(&(that->thread), &result);
164+
}
150165
}
151166
}
152167

@@ -158,6 +173,9 @@ void embb_mtapi_thread_context_finalize(embb_mtapi_thread_context_t* that) {
158173
embb_mtapi_log_trace("embb_mtapi_thread_context_finalize() called\n");
159174

160175
if (that->is_initialized) {
176+
if (that->is_main_thread) {
177+
embb_tss_delete(&that->tss_id);
178+
}
161179
embb_condition_destroy(&that->work_available);
162180
embb_mutex_destroy(&that->work_available_mutex);
163181
}

mtapi_c/src/embb_mtapi_thread_context_t.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct embb_mtapi_thread_context_struct {
6868
embb_atomic_int run;
6969
mtapi_status_t status;
7070
mtapi_boolean_t is_initialized;
71+
mtapi_boolean_t is_main_thread;
7172
};
7273

7374
#include <embb_mtapi_thread_context_t_fwd.h>

mtapi_c/src/mtapi_node_attributes_t.c

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void mtapi_nodeattr_init(
5252
attributes->max_jobs = MTAPI_NODE_MAX_JOBS_DEFAULT;
5353
attributes->max_actions_per_job = MTAPI_NODE_MAX_ACTIONS_PER_JOB_DEFAULT;
5454
attributes->max_priorities = MTAPI_NODE_MAX_PRIORITIES_DEFAULT;
55+
attributes->reuse_main_thread = MTAPI_FALSE;
5556

5657
embb_core_set_init(&attributes->core_affinity, 1);
5758
attributes->num_cores = embb_core_set_count(&attributes->core_affinity);
@@ -143,6 +144,11 @@ void mtapi_nodeattr_set(
143144
&attributes->max_priorities, attribute, attribute_size);
144145
break;
145146

147+
case MTAPI_NODE_REUSE_MAIN_THREAD:
148+
local_status = embb_mtapi_attr_set_mtapi_boolean_t(
149+
&attributes->reuse_main_thread, attribute, attribute_size);
150+
break;
151+
146152
default:
147153
/* attribute unknown */
148154
local_status = MTAPI_ERR_ATTR_NUM;

0 commit comments

Comments
 (0)