Skip to content

Commit b5d696b

Browse files
Eugeniy Paltsevabrodkin
Eugeniy Paltsev
authored andcommitted
MITH: Home-brew dynamic stack allocation for threads
While zephyrproject-rtos/zephyr#25973 is not fixed, let's use a dirty hack in the benchmark sources.
1 parent 4832cc6 commit b5d696b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

mith/src/mith_lib.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ static int RunBigEndian()
224224
return 0;
225225
}
226226

227+
#define MITH_MAX_CONTEXT_NUM 12
228+
#define STACK_SZ (1024 * 64)
229+
K_THREAD_STACK_ARRAY_DEFINE(stack_ctx, MITH_MAX_CONTEXT_NUM, STACK_SZ);
230+
227231
/* Function: mith_main
228232
Description:
229233
main function that fires off work items.
@@ -291,15 +295,25 @@ size_t mith_main_loop(ee_workload *workload, unsigned int num_iterations, unsign
291295
}
292296
th_log(TH_INFO,"Starting Run...");
293297

298+
if (num_contexts > MITH_MAX_CONTEXT_NUM) {
299+
th_log(TH_INFO, "Too much contexts selected!");
300+
return 0;
301+
}
302+
303+
pthread_attr_t attr[MITH_MAX_CONTEXT_NUM] = {};
304+
294305
/* now to start the timer, and get the first item */
295306
/* from here on we need to worry about thread safety */
296307
al_signal_start();
297308
/* create the thread pool */
298-
for (i=0; i<num_contexts; i++)
299-
al_thread_create(&(context[i].thread),bench_thread,(void *)(&context[i]));
309+
for (i=0; i<num_contexts; i++) {
310+
pthread_attr_init(&attr[i]);
311+
pthread_attr_setstack(&attr[i], &stack_ctx[i][0], STACK_SZ);
312+
pthread_create((pthread_t *)(&(context[i].thread)),&attr[i],bench_thread,(void *)(&context[i]));
313+
}
300314
/* and wait until threads are all done executing */
301315
for (i=0; i<num_contexts; i++)
302-
al_thread_join((context[i].thread),&context_ret);
316+
pthread_join((pthread_t)(context[i].thread),&context_ret);
303317
total_time=al_signal_finished();
304318
/* workload is now done, report results */
305319
/* from here on, only one thread operates */

0 commit comments

Comments
 (0)