4

Is the default Raspbian shipped with the real time patch?

I'm using the .config of the default Raspbian installation as a base for a custom kernel compilation. In the section:

 >Kernel Features      
  -> Preemption Model (<choice> [=y])

The selected option is Preemptible Kernel (Low-Latency Desktop).

The description of the option is:

This option reduces the latency of the kernel by making all kernel code (that is not executing in a critical section) preemptible. This allows reaction to interactive events by permitting a low priority process to be preempted involuntarily even if it is in kernel mode executing a system call and would otherwise not be about to reach a natural preemption point. This allows applications to run more 'smoothly' even when the system is under load, at the cost of slightly lower throughput and a slight runtime overhead to kernel code.

Select this if you are building a kernel for a desktop or embedded system with latency requirements in the milliseconds range.

However, when I did some testing, in which I generated a software PWM on the GPIO with the frequency 1kHz, the behaviour was far from real time.

Does kernel preemption mean that rt_patch is included in the kernel? What else would I gain with the real time patch if the kernel is already preemptive? If the kernel is preemptive, why was the PWM unclean?

  • Couple points: 1) The normal kernel latency for userland software is 10 ms; so if you ask for 100 Hz timing, you will get something very accurate. If you ask for more than that, you won't. 2) I would guess that the lower latency above using preempt is not necessarily going to be realized for any and all userspace processes, so if that is how you did your test, it may not make any difference (you will get the same 100 Hz accuracy). I think anything requiring better timing has to be implemented at least partially in kernelspace. – goldilocks Aug 12 '13 at 12:58
  • AFAIK, you need to change the scheduler to get soft real-time. See e.g. this answer: http://raspberrypi.stackexchange.com/a/8855/3810 – ergosys Aug 12 '13 at 17:21

2 Answers2

4

You can check what preempt is currently "active" by checking the kernel's configuration from /proc/config.gz:

CONFIG_PREEMPT=y

The configuration option for the rt_patch is:

CONFIG_PREEMPT=y
CONFIG_PREEMPT_RT_BASE=y
CONFIG_PREEMPT_RT_FULL=y

Which doesn't seem to be availabe in the stock kernel.

From what I have researched, achievements of the RT_PREEMPT development have been gradually ported into the kernel, and I feel that the PREEMPT is a first-step towards preemption that has appeared. RT Kernel wiki states, about CONFIG_PREEMPT:

The 2.6 Linux kernel has an additional configuration option, CONFIG_PREEMPT, which causes all kernel code outside of spinlock-protected regions and interrupt handlers to be eligible for non-voluntary preemption by higher priority kernel threads. With this option, worst case latency drops to (around) single digit milliseconds, although some device drivers can have interrupt handlers that will introduce latency much worse than that. If a real-time Linux application requires latencies smaller than single-digit milliseconds, use of the CONFIG_PREEMPT_RT patch is highly recommended.

RT_PREEMPT will further break control loops in the kernel, making them preemptiible, and resulting in further lower latencies.

But even the RT_PREEMPT seems only to better the response time by an additional small amount. According to Brown and Martin, the best refence I fould about Real-Time linux, if you need hard real-time you will have to look into Xenomai, or possibly RTAI.

If you want to use the RT_PREEMPT patch, there is a thread about it.

You can find ready-images of Xenomai for the Raspberry Pi, and a couple of howtos here and here if you want to build your own Xenomai Kernel.

Marco Poli
  • 1,861
  • 10
  • 20
0

When selecting "Low-Latency Desktop" you implement merely a soft real-time scheduler. Just a couple of optimized configurations to reduce the latency while keeping performance and power savings at balance. If you need hard real-time you have to include a fully preemptive kernel which will give you lower latency but worsen your performance.


For more information:

https://help.ubuntu.com/community/UbuntuStudio/RealTimeKernel

https://rt.wiki.kernel.org/index.php/Main_Page

Ghanima
  • 15,855
  • 15
  • 61
  • 119
RootRaven
  • 111
  • 2