gpt4 book ai didi

c - Xenomai clock_nanosleep in POSIX skin跳转到Linux Kernel

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:38 26 4
gpt4 key购买 nike

我正在 Xenomai 中测试 POSIX 皮肤。我正在尝试从 Raspberry Pi 上的一些 GPIO 读取和写入,当我执行程序时,上下文切换的次数越来越多(在/proc/xenomai/stat/中)。

程序的主体将 GPIO 映射到内存并启动 pthreads。闹事的pthread是这样的:

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 documentation 中定义的.能否以某种方式对其进行改进(使用 POSIX 皮肤)?

最佳答案

当进程休眠时,它会执行自愿的上下文切换。这很好,除非您确实看到错过了最后期限。

关于c - Xenomai clock_nanosleep in POSIX skin跳转到Linux Kernel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19816030/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com