简体   繁体   English

Linux RTOS sleep()-定时器任务的wakeup()

[英]Linux RTOS sleep() - wakeup() for timer task

I have a task which is basically a TIMER; 我的任务基本上是一个TIMER; so it goes to sleep and is supposed to wake up periodically.. So the timer task sleeps for say 10ms. 所以它进入睡眠状态,并且应该定期唤醒。所以计时器任务会睡10个小时。 But what is happening is that it is inconsistent in waking up and cannot be relied upon to awaken in time correctly. 但正在发生的事情是它在醒来时是不一致的,不能依赖于及时正确唤醒。

In fact, in my runs, there is a big difference in sleep times. 事实上,在我的跑步中,睡眠时间有很大差异。 Sometimes it can vary by 1-2 ms in awakening and very few times does not come back to at all. 有时它在觉醒时可能会有1-2毫秒的变化,很少有时间也不会恢复。 This is because the kernel scheduler puts all the sleeping and waiting tasks in a queue and then when it polls to see who is to be awakened, I think it is round robin. 这是因为内核调度程序将所有睡眠和等待任务放入队列中,然后在进行轮询以查看谁将被唤醒时,我认为它是循环轮询。 So sometimes the task would have expired by the time the scheduler polls again. 因此,有时候调度程序再次轮询时任务就会过期。 Sometimes, when there are interrupts, the ISR gets control and delays the timer from waking up. 有时,当有中断时,ISR会控制并延迟计时器的唤醒。

What is the best solution to handle this kind of problem? 处理这类问题的最佳解决方案是什么?

(Additional details: The task is a MAC timer for a wireless network; RTOS is a u-velOSity microkernel) (其他细节:任务是无线网络的MAC定时器; RTOS是u-velOSity微内核)

You should be using the timer API provided by the OS instead on relying on the scheduler. 您应该使用操作系统提供的计时器API,而不要依赖调度程序。 Here's an introduction to the timer API for Linux drivers . 以下是Linux驱动程序计时器API简介

If you need hardcore timing, the OS scheduler is not likely to be good enough (as you've found). 如果你需要硬核定时,OS调度程序可能不够好(正如你所发现的那样)。

If you can, use a separate timer peripheral, and use it's ISR to do as little as you can get away with (timestamping some critical data, set some flags for example) and then let your higher-jitter routine make use of that data with its less guaranteed timing. 如果可以的话,请使用单独的定时器外设,并使用它的ISR尽力而为(减少一些关键数据的时间戳,例如设置一些标志), 然后让较高抖动的例程将其用于它不太保证时间。

Linux is not an RTOS, and that is probably the root of your problem. Linux不是RTOS,这可能是您问题的根源。

You can render Linux more suited to real-time use in various ways and to various extent. 您可以通过各种方式和不同程度地使Linux更适合实时使用。 See A comparison of real-time Linux approaches for some methods and an assessment of the level of real-time performance you can expect. 请参阅一些方法的实时Linux方法的比较,以及您可以预期的实时性能水平的评估。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM