POSIX皮肤中的Xenomai clock_nanosleep跳到Linux内核 [英] Xenomai clock_nanosleep in POSIX skin jumps to Linux Kernel
问题描述
我正在Xenomai中测试POSIX皮肤.我正在尝试从Raspberry Pi上的一些GPIO读取和写入,并且在执行该程序时,上下文切换的数量越来越多(在/proc/xenomai/stat/中).
I'm testing POSIX skin in Xenomai. I'm trying to read and write from some GPIOs on a Raspberry Pi, and when I execute the program, there is an increasing number of context switching (in /proc/xenomai/stat/).
程序的主程序将GPIO映射到内存并启动pthread.造成麻烦的pthread是这样的:
The main of the program maps the GPIOs to memory and starts the pthreads. The pthread that makes trouble is this:
void *productive_thread(void *arg)
{
struct timespec delay, sleep;
unsigned long over;
delay.tv_sec = 0;
delay.tv_nsec = 10000; // 10 usec
sleep.tv_sec = 0;
sleep.tv_nsec = *(long *)arg;
while(1)
{
// This are the read and write macros (gpio is the address of the GPIO mapping):
// #define GPIO_SET *(gpio+7)
// #define GPIO_CLR *(gpio+10)
// #define GPIO_READ(g) (*(gpio + 13)&(1<<(g)))>>4
while(GPIO_READ(4) != 1);
GPIO_SET = 1 << 17;
clock_nanosleep(CLOCK_REALTIME, 0, &delay, NULL);
GPIO_CLR = 1 << 17;
clock_nanosleep(CLOCK_REALTIME, 0, &sleep, NULL);
}
return NULL;
}
上下文切换的次数每个循环都会增加.我怀疑问题是clock_nanosleep,因为所有其他操作都是算术运算,但是clock_nanosleep是在 Xenomai文档.可以通过使用POSIX皮肤以某种方式进行改进吗?
The number of context switching increases by every loop. I suspect the problem is clock_nanosleep, because all other operations are arithmetic, but clock_nanosleep is defined in Xenomai documentation. Can it be improved somehow (using POSIX skin)?
推荐答案
当进程进入休眠状态时,它将执行自愿的上下文切换.很好,除非您实际上看到错过了最后期限.
When a process sleeps it performs a voluntary context switch. This is fine, unless you are actually seeing your deadlines missed.
这篇关于POSIX皮肤中的Xenomai clock_nanosleep跳到Linux内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!