A problem regarding SMP
Hello!
Currently I encountered a problem with SMP while using linux-evl core.
I created multiple kernel processes sequentially in the kernel state using evl_run_kthread and would like to have them run in parallel on multiple CPUs, but the parallelism I was expecting is not happening in EVL core.
After reading the relevant code in the EVL kernel, I discovered the reason as follows. When calling evl_run_kthread in the master process to create multiple processes sequentially, the master process creates the first process first and then waits for the first process to finish initializing:
wait_for_completion(&kthread->done);
The newly created process enters the kthread_trampoline function and switches the OOB state first, then calls irq_work_queue to put the inband irq_work that wakes up the master process into the current CPU. However, this results in that the inband irq_work that wakes up the master process having no way to be handled until the first created process finishes executing, because it is OOB. This would also cause the creation and running of the second process being delayed, since these events occur in the master process. So in summary, there is no way to run all the processes in parallel.
By the way, the /kernel/evl/thread.c file also exists a comment explaining this problem:
/*
* We are now running OOB, therefore __evl_run_kthread() can't
* start us before we enter the dormant state because
* irq_work_queue() schedules the in-band wakeup request on
* the current CPU. If we fail switching to OOB context,
* kthread->status tells __evl_run_kthread() not to start but
* cancel us instead.
*/
Now I'm thinking that theoretically this phenomenon is correct for RTOS, since the main process that creates the new processes is not OOB, so it does should be woken up using inband ways. But this does cause a lot of wasted CPU resources in SMP environments, because it would have been possible to have the inband processes and the OOB processes running at the same time on different CPUs.
So, here I would like to ask, should this problem to be solved? And is there anyone in the community working on this?
Best regards,
Jiajun
Quoted 15 lines · JiajunDu
Hello!
Currently I encountered a problem with SMP while using linux-evl core.
I created multiple kernel processes sequentially in the kernel state using
evl_run_kthreadand would like to have them run in parallel on multiple CPUs, but the parallelism I was expecting is not happening in EVL core.After reading the relevant code in the EVL kernel, I discovered the reason as follows. When calling
evl_run_kthreadin the master process to create multiple processes sequentially, the master process creates the first process first and then waits for the first process to finish initializing:
wait_for_completion(&kthread->done);
Quoted 9 lines
The newly created process enters the
kthread_trampolinefunction and switches the OOB state first, then callsirq_work_queueto put the inbandirq_workthat wakes up the master process into the current CPU. However, this results in that the inbandirq_workthat wakes up the master process having no way to be handled until the first created process finishes executing, because it is OOB. This would also cause the creation and running of the second process being delayed, since these events occur in the master process. So in summary, there is no way to run all the processes in parallel.
Well, yes there is: you need all evl kthreads to synchronize on a barrier (e.g. evl_flag) before entering their work loop. The master process would post that barrier when evl_run_kthread() has returned for the last kthread, unleashing them all on each CPU you placed them. Per the property you mentioned, we know for sure that an evl kthread is ready to run when the master process resumes execution after a call to evl_run_kthread().
Quoted 19 lines
By the way, the /kernel/evl/thread.c file also exists a comment explaining this problem:
/*
* We are now running OOB, therefore__evl_run_kthread()can't
* start us before we enter the dormant state because
*irq_work_queue()schedules the in-band wakeup request on
* the current CPU. If we fail switching to OOB context,
*kthread->statustells__evl_run_kthread()not to start but
* cancel us instead.
*/Now I'm thinking that theoretically this phenomenon is correct for RTOS, since the main process that creates the new processes is not OOB, so it does should be woken up using inband ways. But this does cause a lot of wasted CPU resources in SMP environments, because it would have been possible to have the inband processes and the OOB processes running at the same time on different CPUs.
Quoted 3 lines
So, here I would like to ask, should this problem to be solved? And is there anyone in the community working on this?
I don't think there is any problem in this case. You only need to account for the inband/oob duality of any evl (k)thread. Inband is where the basic OS resources are allocated, oob is where scheduling happens with real-time guarantee.
Signature · 1 line
Philippe.
PATCH 1/1 test: smp: achieve parallelism by using barriers to synchronize processes
https://lore.kernel.org/xenomai/[email protected]/T/#t
--- include/evl/flag.h | 13 +++++++++++++ kernel/evl/init.c | 43 +++++++++++++++++++++++++++++++++++++++++++ kernel/evl/thread.c | 2 ++ 3 files changed, 58 insertions(+)
include/evl/flag.h +13 -0
@@ -69,6 +69,19 @@ static inline int evl_wait_flag(struct evl_flag *wf)return evl_wait_flag_timeout (wf,EVL_INFINITE ,EVL_REL ); } +static inline +int evl_wait_flag_timeout_same (struct evl_flag *wf, +ktime_t timeout,enum evl_tmode timeout_mode) +{ +return evl_wait_event_timeout (&wf->wait, timeout, + timeout_mode,evl_peek_flag (wf)); +} + +static inline int evl_wait_flag_same (struct evl_flag *wf) +{ +return evl_wait_flag_timeout_same (wf,EVL_INFINITE ,EVL_REL ); +} +/* wf->wait.lock held, irqs off */ static inline struct evl_thread *evl_wait_flag_head (struct evl_flag *wf) {
kernel/evl/init.c +43 -0
61 lines not on this page · raw message
kernel/evl/thread.c +2 -0
@@ -145,6 +145,8 @@ static void pin_to_initial_cpu(struct evl_thread *thread)if (!cpumask_test_cpu (cpu, &thread->affinity)) cpu =cpumask_first (&thread->affinity); +printk (EVL_INFO "thread name is %s, cpu is %d\n" , thread->name, cpu); +set_cpus_allowed_ptr (p,cpumask_of (cpu));/* * @thread is still unstarted EVL-wise, we are in the process
Signature · 1 line
2.34.1