while loop in a multi-core cpu
Hi Guys,
We are trying to develop a polling mode thread to skip the delay of the interrupt response. This is done by a while loop to check the hardware (say a gpio or a timer) continuously. When we did this we found that the system was frozen, meaning that the other cores are not functioning when we run a polling loop on a single core. But if we do the same in a normal Linux thread, the system is not frozen. I'm just wondering if polling mode is allowed for xenomai, or if we did anything incorrectly. A simple test piece of code to replicate this is attached below. Our code runs on RaspberryPiCM4 (four-core ARM V7l) with Linux 4.19 and xenomai 3.1.
Best Regards,
Yunjie
#include <stdio.h>
#include <unistd.h>
#include <alchemy/task.h>
#include <alchemy/timer.h>
#include <alchemy/sem.h>
#include <rtdm/uapi/rtdm.h>
#include <fcntl.h>
#include <linux/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>RT_TASK demo_task;
void demo(void *arg)
{
RT_TASK *curtask;
RT_TASK_INFO curtaskinfo;
curtask=rt_task_self();
rt_task_inquire(curtask,&curtaskinfo);
printf("Task name : %s \n", curtaskinfo.name);
//------------------ hello world --------------------
while (1)
{
printf("Hello World!\n");
}}
int main(int argc, char* argv[])
{
char str[10];
// rt_print_auto_init(1);
mlockall(MCL_CURRENT|MCL_FUTURE);
printf("start task\n");
sprintf(str,"hello");
rt_task_create(&demo_task, str, 0, 50, 0);
rt_task_start(&demo_task, &demo, 0);
pause();
rt_task_delete(&demo_task);
}Quoted 10 lines
-----Original Message-----
From: Yunjie Gu <[email protected]>
Sent: Monday, January 16, 2023 12:08 AM
To: [email protected]
Subject: while loop in a multi-core cpuHi Guys,
Quoted 7 lines
We are trying to develop a polling mode thread to skip the delay of the interrupt response. This is done by a while loop to check the hardware (say a gpio or a timer) continuously. When we did this we found that the system was frozen, meaning that the other cores are not functioning when we run a polling loop on a single core. But if we do the same in a normal Linux thread, the system is not frozen. I'm just wondering if polling mode is allowed for xenomai, or if we did
Xenomai threads should not dominate cpu too much time in dual kernel configuration. When xenomai was dominating cpu too long time, from Linux 's view, cpu is like dead and Linux can not handle it correctly in such case. If you enable CONFIG_XENO_OPT_WATCHDOG, it may notify system to avoid such thing from debug point.
Regards
Hongzhan Chen
Quoted 54 lines
anything incorrectly. A simple test piece of code to replicate this is attached below. Our code runs on RaspberryPiCM4 (four-core ARM V7l) with Linux 4.19 and xenomai 3.1.
Best Regards,
Yunjie#include <
stdio.h>
#include <unistd.h>
#include <alchemy/task.h>
#include <alchemy/timer.h>
#include <alchemy/sem.h>
#include <rtdm/uapi/rtdm.h>
#include <fcntl.h>
#include <linux/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>RT_TASKdemo_task;void
demo(void *arg){ RT_TASK *curtask; RT_TASK_INFO curtaskinfo; curtask=rt_task_self(); rt_task_inquire(curtask,&curtaskinfo); printf("Task name : %s \n", curtaskinfo.name); //------------------ hello world -------------------- while (1) { printf("Hello World!\n"); }}
int
main(int argc, char* argv[]){ char str[10]; // rt_print_auto_init(1); mlockall(MCL_CURRENT|MCL_FUTURE); printf("start task\n"); sprintf(str,"hello"); rt_task_create(&demo_task, str, 0, 50, 0); rt_task_start(&demo_task, &demo, 0); pause(); rt_task_delete(&demo_task); }
Quoted 18 lines · Hongzhan
Quoted 10 lines
-----Original Message-----
From: Yunjie Gu <[email protected]>
Sent: Monday, January 16, 2023 12:08 AM
To: [email protected]
Subject: while loop in a multi-core cpuHi Guys,
Quoted 7 lines
We are trying to develop a polling mode thread to skip the delay of the interrupt response. This is done by a while loop to check the hardware (say a gpio or a timer) continuously. When we did this we found that the system was frozen, meaning that the other cores are not functioning when we run a polling loop on a single core. But if we do the same in a normal Linux thread, the system is not frozen. I'm just wondering if polling mode is allowed for xenomai, or if we did
Quoted 4 lines
Xenomai threads should not dominate cpu too much time in dual kernel configuration. When xenomai was dominating cpu too long time, from Linux 's view, cpu is like dead and Linux can not handle it correctly in such case. If you enable
CONFIG_XENO_OPT_WATCHDOG, it may notify system to avoid such thing from debug point.
Theoretically, a stable NOHZ-full setup should be able to tolerate on top a Xenomai-only schedule with full CPU domination. However, achieving that under Linux is already not trivial, and I haven't tested if Linux is actually entering the right state when out-of-band Dovetail/Xenomai takes over.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Quoted 33 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, January 16, 2023 1:17 PM
To: Chen, Hongzhan <[email protected]>; Yunjie Gu <[email protected]>; [email protected]
Subject: Re: while loop in a multi-core cpuQuoted 18 lines · Hongzhan
Quoted 10 lines
-----Original Message-----
From: Yunjie Gu <[email protected]>
Sent: Monday, January 16, 2023 12:08 AM
To: [email protected]
Subject: while loop in a multi-core cpuHi Guys,
Quoted 7 lines
We are trying to develop a polling mode thread to skip the delay of the interrupt response. This is done by a while loop to check the hardware (say a gpio or a timer) continuously. When we did this we found that the system was frozen, meaning that the other cores are not functioning when we run a polling loop on a single core. But if we do the same in a normal Linux thread, the system is not frozen. I'm just wondering if polling mode is allowed for xenomai, or if we did
Quoted 1 line
Xenomai threads should not dominate cpu too much time in dual kernel
configuration.
Quoted 1 line
When xenomai was dominating cpu too long time, from Linux 's view, cpu is
like dead
Quoted 1 line
and Linux can not handle it correctly in such case. If you enable
Quoted 8 lines
CONFIG_XENO_OPT_WATCHDOG,Quoted 1 line
it may notify system to avoid such thing from debug point.
Theoretically, a stable NOHZ-full setup should be able to tolerate on top a Xenomai-only schedule with full CPU domination. However, achieving that under Linux is already not trivial, and I haven't tested if Linux is actually entering the right state when out-of-band Dovetail/Xenomai takes over.
What do you means about NOHZ-full setup? Is it just related to configuration or commands passed for linux? Is it possible to fix such issue that we do not need to modify Linux kernel?
Regards
Hongzhan Chen
Quoted 6 lines
Jan
--
Siemens AG, Technology
Competence Center Embedded Linux
Quoted 36 lines · Hongzhan
Quoted 36 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, January 16, 2023 1:17 PM
To: Chen, Hongzhan <[email protected]>; Yunjie Gu <[email protected]>; [email protected]
Subject: Re: while loop in a multi-core cpuQuoted 18 lines · Hongzhan
Quoted 10 lines
-----Original Message-----
From: Yunjie Gu <[email protected]>
Sent: Monday, January 16, 2023 12:08 AM
To: [email protected]
Subject: while loop in a multi-core cpuHi Guys,
Quoted 7 lines
We are trying to develop a polling mode thread to skip the delay of the interrupt response. This is done by a while loop to check the hardware (say a gpio or a timer) continuously. When we did this we found that the system was frozen, meaning that the other cores are not functioning when we run a polling loop on a single core. But if we do the same in a normal Linux thread, the system is not frozen. I'm just wondering if polling mode is allowed for xenomai, or if we did
Quoted 1 line
Xenomai threads should not dominate cpu too much time in dual kernel
configuration.
Quoted 1 line
When xenomai was dominating cpu too long time, from Linux 's view, cpu is
like dead
Quoted 1 line
and Linux can not handle it correctly in such case. If you enable
CONFIG_XENO_OPT_WATCHDOG,Quoted 1 line
it may notify system to avoid such thing from debug point.
Quoted 9 lines
Quoted 5 lines
Theoretically, a stable NOHZ-full setup should be able to tolerate on top a Xenomai-only schedule with full CPU domination. However, achieving that under Linux is already not trivial, and I haven't tested if Linux is actually entering the right state when out-of-band Dovetail/Xenomai takes over.
What do you means about NOHZ-full setup? Is it just related to configuration or commands passed for linux? Is it possible to fix such issue that we do not need to modify Linux kernel?
I'm referring to
https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-clock-ticks-for-idle-cpus
If all works well in such a setup, a single(!) Linux userspace task can run at 100% without being interrupted by any timers and other background activity. Difference to Xenomai: If Linux finds out that the promise to that task cannot be fulfilled, it simply interrupts it. But if that should happen to a Xenomai task, Linux can't express that, and we would be back to a deadlock situation.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Quoted 43 lines · Jan Kiszka
Quoted 42 lines · Hongzhan
Quoted 41 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, January 16, 2023 1:17 PM
To: Chen, Hongzhan <[email protected]>; Yunjie Gu <[email protected]>; [email protected]
Subject: Re: while loop in a multi-core cpuQuoted 18 lines · Hongzhan
Quoted 10 lines
-----Original Message-----
From: Yunjie Gu <[email protected]>
Sent: Monday, January 16, 2023 12:08 AM
To: [email protected]
Subject: while loop in a multi-core cpuHi Guys,
Quoted 7 lines
We are trying to develop a polling mode thread to skip the delay of the interrupt response. This is done by a while loop to check the hardware (say a gpio or a timer) continuously. When we did this we found that the system was frozen, meaning that the other cores are not functioning when we run a polling loop on a single core. But if we do the same in a normal Linux thread, the system is not frozen. I'm just wondering if polling mode is allowed for xenomai, or if we did
Quoted 1 line
Xenomai threads should not dominate cpu too much time in dual kernel
configuration.
Quoted 1 line
When xenomai was dominating cpu too long time, from Linux 's view, cpu is
like dead
Quoted 1 line
and Linux can not handle it correctly in such case. If you enable
CONFIG_XENO_OPT_WATCHDOG,Quoted 1 line
it may notify system to avoid such thing from debug point.
Theoretically, a stable NOHZ-full setup should be able to tolerate on top a Xenomai-only schedule with full CPU domination. However, achieving that under Linux is already not trivial, and I haven't tested if Linux is actually entering the right state when out-of-band Dovetail/Xenomai takes over.
Quoted 7 lines
Quoted 3 lines
What do you means about NOHZ-full setup? Is it just related to configuration or commands passed for linux? Is it possible to fix such issue that we do not need to modify Linux kernel?
I'm referring to
https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-clock-ticks-for-idle-cpus
Quoted 9 lines
If all works well in such a setup, a single(!) Linux userspace task can run at 100% without being interrupted by any timers and other background activity. Difference to Xenomai: If Linux finds out that the promise to that task cannot be fulfilled, it simply interrupts it. But if that should happen to a Xenomai task, Linux can't express that, and we would be back to a deadlock situation.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Quoted 60 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, January 16, 2023 5:13 PM
To: Chen, Hongzhan <[email protected]>; Yunjie Gu <[email protected]>; [email protected]
Subject: Re: while loop in a multi-core cpuQuoted 29 lines · Jan Kiszka
Quoted 28 lines · Hongzhan
Quoted 28 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, January 16, 2023 1:17 PM
To: Chen, Hongzhan <[email protected]>; Yunjie Gu <[email protected]>; [email protected]
Subject: Re: while loop in a multi-core cpuQuoted 18 lines · Hongzhan
Quoted 17 lines
-----Original Message-----
From: Yunjie Gu <[email protected]>
Sent: Monday, January 16, 2023 12:08 AM
To: [email protected]
Subject: while loop in a multi-core cpuHi Guys,
We are trying to develop a polling mode thread to skip the delay of the interrupt response. This is done by a while loop to check the hardware (say a gpio or a timer) continuously. When we did this we found that the system was frozen, meaning that the other cores are not functioning when we run a polling loop on a single core. But if we do the same in a normal Linux thread, the system is not frozen. I'm just wondering if polling mode is allowed for xenomai, or if we did
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Xenomai threads should not dominate cpu too much time in dual kernel
configuration.
Quoted 1 line
When xenomai was dominating cpu too long time, from Linux 's view,
cpu is
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
like dead
Quoted 1 line
and Linux can not handle it correctly in such case. If you enable
CONFIG_XENO_OPT_WATCHDOG,Quoted 1 line
it may notify system to avoid such thing from debug point.
Theoretically, a stable NOHZ-full setup should be able to tolerate on top a Xenomai-only schedule with full CPU domination. However,
achieving
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
that under Linux is already not trivial, and I haven't tested if Linux is actually entering the right state when out-of-band Dovetail/Xenomai takes over.
What do you means about NOHZ-full setup? Is it just related to
configuration or commands passed for linux?
Quoted 3 lines
Quoted 2 lines
Is it possible to fix such issue that we do not need to modify Linux kernel?
Quoted 8 lines
Quoted 2 lines
I'm referring to
https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-clock-ticks-for-idle-cpus
Quoted 1 line
Actually:
https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-
clock-ticks-for-cpus-with-only-one-runnable-task
The last paragraph of known issues in https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-
clock-ticks-for-cpus-with-only-one-runnable-task, it mentioned that there is still the needs which
are are currently accommodated by scheduling-clock tick every second or so including calculating CPU load, maintaining sched average, computing CFS entity vruntime, computing avenrun, and carrying out load balancing. If we can not meet these needs , may it cause other system issue?
In dpdk, we may also need 100% dominating cpu in PMD mode, it is worth giving it a try.
Regards
Hongzhan Chen
Quoted 13 lines
Quoted 9 lines
If all works well in such a setup, a single(!) Linux userspace task can run at 100% without being interrupted by any timers and other background activity. Difference to Xenomai: If Linux finds out that the promise to that task cannot be fulfilled, it simply interrupts it. But if that should happen to a Xenomai task, Linux can't express that, and we would be back to a deadlock situation.
Jan
--
Siemens AG, Technology
Competence Center Embedded Linux
Quoted 69 lines · Hongzhan
Quoted 60 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, January 16, 2023 5:13 PM
To: Chen, Hongzhan <[email protected]>; Yunjie Gu <[email protected]>; [email protected]
Subject: Re: while loop in a multi-core cpuQuoted 29 lines · Jan Kiszka
Quoted 28 lines · Hongzhan
Quoted 28 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, January 16, 2023 1:17 PM
To: Chen, Hongzhan <[email protected]>; Yunjie Gu <[email protected]>; [email protected]
Subject: Re: while loop in a multi-core cpuQuoted 18 lines · Hongzhan
Quoted 17 lines
-----Original Message-----
From: Yunjie Gu <[email protected]>
Sent: Monday, January 16, 2023 12:08 AM
To: [email protected]
Subject: while loop in a multi-core cpuHi Guys,
We are trying to develop a polling mode thread to skip the delay of the interrupt response. This is done by a while loop to check the hardware (say a gpio or a timer) continuously. When we did this we found that the system was frozen, meaning that the other cores are not functioning when we run a polling loop on a single core. But if we do the same in a normal Linux thread, the system is not frozen. I'm just wondering if polling mode is allowed for xenomai, or if we did
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Xenomai threads should not dominate cpu too much time in dual kernel
configuration.
Quoted 1 line
When xenomai was dominating cpu too long time, from Linux 's view,
cpu is
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
like dead
Quoted 1 line
and Linux can not handle it correctly in such case. If you enable
CONFIG_XENO_OPT_WATCHDOG,Quoted 1 line
it may notify system to avoid such thing from debug point.
Theoretically, a stable NOHZ-full setup should be able to tolerate on top a Xenomai-only schedule with full CPU domination. However,
achieving
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
that under Linux is already not trivial, and I haven't tested if Linux is actually entering the right state when out-of-band Dovetail/Xenomai takes over.
What do you means about NOHZ-full setup? Is it just related to
configuration or commands passed for linux?
Quoted 3 lines
Quoted 2 lines
Is it possible to fix such issue that we do not need to modify Linux kernel?
Quoted 8 lines
Quoted 2 lines
I'm referring to
https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-clock-ticks-for-idle-cpus
Quoted 1 line
Actually:
https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-
clock-ticks-for-cpus-with-only-one-runnable-task
Quoted 6 lines
The last paragraph of known issues in https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-
clock-ticks-for-cpus-with-only-one-runnable-task, it mentioned that there is still the needs which
are are currently accommodated by scheduling-clock tick every second or so including calculating CPU load, maintaining sched average, computing CFS entity vruntime, computing avenrun, and carrying out load balancing. If we can not meet these needs , may it cause other system issue?
In dpdk, we may also need 100% dominating cpu in PMD mode, it is worth giving it a try.
Yeah, didn't check in a while that status, just recalling the at least mainline was not able to provide 100%, but there were concepts (or hacks?) to get it at that level. Obviously, if there is still no 100% in mainline, we would just prolong the phase of CPU domination also for Xenomai tasks, but not eliminate the need to periodically release it for a while.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Hi Hongzhan and Jan,
Many thanks for the answers. Is this also true even for multi-core cpus? When one of the cores is running a xenomai thread 100%, what the other cores are doing?
If we really want a core to run a 100% while loop, how can we do that in a dual-core xenomai system? Say, can we isolate one core that is not managed by the OS (i.e. kind of bare-metal) to do this?
Best Regards,
Yunjie
Quoted 91 lines · Jan Kiszka
Quoted 69 lines · Hongzhan
Quoted 60 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, January 16, 2023 5:13 PM
To: Chen, Hongzhan <[email protected]>; Yunjie Gu <[email protected]>; [email protected]
Subject: Re: while loop in a multi-core cpuQuoted 29 lines · Jan Kiszka
Quoted 28 lines · Hongzhan
Quoted 28 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, January 16, 2023 1:17 PM
To: Chen, Hongzhan <[email protected]>; Yunjie Gu <[email protected]>; [email protected]
Subject: Re: while loop in a multi-core cpuQuoted 18 lines · Hongzhan
Quoted 17 lines
-----Original Message-----
From: Yunjie Gu <[email protected]>
Sent: Monday, January 16, 2023 12:08 AM
To: [email protected]
Subject: while loop in a multi-core cpuHi Guys,
We are trying to develop a polling mode thread to skip the delay of the interrupt response. This is done by a while loop to check the hardware (say a gpio or a timer) continuously. When we did this we found that the system was frozen, meaning that the other cores are not functioning when we run a polling loop on a single core. But if we do the same in a normal Linux thread, the system is not frozen. I'm just wondering if polling mode is allowed for xenomai, or if we did
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Xenomai threads should not dominate cpu too much time in dual kernel
configuration.
Quoted 1 line
When xenomai was dominating cpu too long time, from Linux 's view,
cpu is
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
like dead
Quoted 1 line
and Linux can not handle it correctly in such case. If you enable
CONFIG_XENO_OPT_WATCHDOG,Quoted 1 line
it may notify system to avoid such thing from debug point.
Theoretically, a stable NOHZ-full setup should be able to tolerate on top a Xenomai-only schedule with full CPU domination. However,
achieving
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
that under Linux is already not trivial, and I haven't tested if Linux is actually entering the right state when out-of-band Dovetail/Xenomai takes over.
What do you means about NOHZ-full setup? Is it just related to
configuration or commands passed for linux?
Quoted 3 lines
Quoted 2 lines
Is it possible to fix such issue that we do not need to modify Linux kernel?
Quoted 8 lines
Quoted 2 lines
I'm referring to
https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-clock-ticks-for-idle-cpus
Quoted 1 line
Actually:
https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-
clock-ticks-for-cpus-with-only-one-runnable-taskQuoted 6 lines
The last paragraph of known issues in https://www.kernel.org/doc/html/latest/timers/no_hz.html#omit-scheduling-
clock-ticks-for-cpus-with-only-one-runnable-task, it mentioned that there is still the needs which
are are currently accommodated by scheduling-clock tick every second or so including calculating CPU load, maintaining sched average, computing CFS entity vruntime, computing avenrun, and carrying out load balancing. If we can not meet these needs , may it cause other system issue?
In dpdk, we may also need 100% dominating cpu in PMD mode, it is worth giving it a try.Yeah, didn't check in a while that status, just recalling the at least mainline was not able to provide 100%, but there were concepts (or hacks?) to get it at that level. Obviously, if there is still no 100% in mainline, we would just prolong the phase of CPU domination also for Xenomai tasks, but not eliminate the need to periodically release it for a while.
Jan
--
Siemens AG, Technology
Competence Center Embedded Linux
Quoted 5 lines · Yunjie Gu
Hi Hongzhan and Jan,
Many thanks for the answers. Is this also true even for multi-core cpus? When one of the cores is running a xenomai thread 100%, what the other cores are doing?
NO_HZ_FULL only works on multicore - you can't operate a complete Linux system with only a single runnable task.
Quoted 3 lines
If we really want a core to run a 100% while loop, how can we do that in a dual-core xenomai system? Say, can we isolate one core that is not managed by the OS (i.e. kind of bare-metal) to do this?
An architectural alternative to using 100%-tasks under Linux is applying a hypervisor and running that task on an isolated core bare-metal. Jailhouse (https:github.com/siemens/jailhouse) is one example for such an hypervisor. That comes with its own pros and cons, though.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux