chiques
Posts: 21
Joined: Tue Jul 09, 2013 2:11 pm

Is the Raspbian Image RTOS?

Tue Jul 09, 2013 2:17 pm

Is the Linux image capable of running as an RTOS?

User avatar
Jessie
Posts: 1754
Joined: Fri Nov 04, 2011 7:40 pm
Location: C/S CO USA

Re: Is the Raspbian Image RTOS?

Tue Jul 09, 2013 3:16 pm

No. There is a version of Free RTOS out there somewhere.

WebPi
Posts: 262
Joined: Wed Apr 10, 2013 6:47 pm
Location: Birmingham, UK

Re: Is the Raspbian Image RTOS?

Tue Jul 09, 2013 3:23 pm

Check this out: https://github.com/jameswalmsley/RaspberryPi-FreeRTOS. I' never used it, so can't comment on what it's like to use.
raspberrywebserver.com - Raspberry Pi tutorials
LinuxWebServers.net - Linux Web Server tutorials and examples
pyplate.com - Python web publishing tool

Heater
Posts: 19101
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is the Raspbian Image RTOS?

Tue Jul 09, 2013 5:52 pm

Yes.

Depends what you mean by "Real Time".

The Linux kernel does have a real time scheduler. You can select different scheduling algorithms for the threads in your program. You can assign priorities to your threads. For example a high priority thread can be set to execute every 100ms and it will do so even if hundred of lower priority threads or processes are trying to get 100% CPU.

There are limits to how well this works:

When I last used this seriously. many years ago, you had to be careful as some device drivers were not "real time" aware and might block your thread. I guess this is a lot less of a problem today.

Your "timer tick" interval, like the above example is limited to the size of the Linux "jiffy". Is that 10ms in modern kernels? I have not checked for ages.

Response to device interrupts may not have the low latency that you are looking for.

See here:

https://access.redhat.com/site/document ... icies.html
http://www.cs.fsu.edu/~baker/realtime/r ... reads.html
http://www.yolinux.com/TUTORIALS/LinuxT ... reads.html
Memory in C++ is a leaky abstraction .

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe

Re: Is the Raspbian Image RTOS?

Wed Jul 10, 2013 11:29 am

Heater - virtually all of the distros available for the Pi are based on versions of Linux that are not real-time capable. Real-time is sorta like pregnancy - either it is or it ain't, despite the use of the ridiculous terms "hard" and "soft" real-time. If a driver is capable of blocking any OS-level thread, then it's not a real-time OS. RTOSes tend to be much, much leaner than any of the popular distros available for the Pi today and they have to have a strict time-slot mechanism at the task/process level for guaranteeing that critical operations happen when needed. Tasks can only run within their allotted time-slot, no matter what else may be going on, and this is typically enforced via processor hardware features, so there's no way to program around it outside the kernel level. Anything with more than 15 microsecond (not millisecond) response delay today is not considered to be real-time.

There have been projects where standard Linux distros have been hosted on top of a real-time microkernel so that the entire Linux distro is essentially given specific time-slots in which to perform its services. Some of these projects essentially just virtualize the Linux distro, but that can lead to significant performance degradation. The more sophisticated projects provide strict time-slots to critical Linux kernel threads (e.g., input-output to storage, network, video, etc.) so that performance is enhanced while still maintaining strict control of access to hardware resources. The most recent projects take advantage of multi-core processors to reserve one core for the real-time microkernel and Linux tasks/threads can only run on the other core(s) as scheduled by the microkernel.

The ChibiOS/RT port to the Pi is incomplete, but currently includes device drivers for GPIO, serial, General-Purpose Timer (GPT), I2C, SPI and PWM, and there are examples showing how to access devices such as the TMP102 temperature sensor, MCP3008 Analog/Digital Converter (ADC), MCP4725 Digital/Analog Converter (DAC), and DS1307 Real-time Clock (RTC):
http://www.stevebate.net/chibios-rpi/Ge ... arted.html

The Free RTOS Pi port is also currently incomplete, lacking basics such as networking and other things that require device drivers (the author is looking for help):
https://github.com/jameswalmsley/RaspberryPi-FreeRTOS

An incomplete RTEMS port is also available that doesn't have support for the SD card interface, GPIO, I2C, USB, Ethernet, HDMI, etc.:
http://alanstechnotes.blogspot.com/2013 ... ry-pi.html

None of these ports take into account the GPU, and are unlikely to given the proprietary nature of The GPU Blob (the GPU does run ThreadX, a real-time set of services, but we have no access to it). There are probably other Pi real-time port projects Out There - Google is your friend for finding them :D
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Heater
Posts: 19101
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is the Raspbian Image RTOS?

Thu Jul 11, 2013 12:31 pm

Jim,

Not so fast, Raspian is plenty "real-time" enough for many things.

The current Raspian kernel, the subject of this thread, supports preemptive threading. As shown by the output of "uname -a"

Code: Select all

Linux raspberrypi 3.6.11+ #456 PREEMPT Mon May 20 17:42:15 BST 2013 armv6l GNU/Linux
Therefore Raspian is an RTOS for some definition of "real-time".

Yes indeed real-time is like pregnancy, your code either meets it's deadlines or it does not. I too am not so happy with the terms "hard" and "soft" real
time". The former seems redundant and the latter is just wrong.
If a driver is capable of blocking any OS-level thread, then it's not a real-time OS.
I'm sure you can write a driver in most RTOS that can hang everything. Most of the RTOS I have used of the decades did not have mechanisms to stop you
shooting yourself in the foot. Mostly because the CPUs did not have such hardware protections. Besides if I'm writing the driver I'm probably on the "protected" side of the fence anyway.
Anything with more than 15 microsecond (not millisecond) response delay today is not considered to be real-time.
Not so. A real-time application has some timing deadlines in it's requirement specification that it must meet. Normally this is all about keeping up with real world events. Say controlling your cars fuel injectors or keeping a fighter jet stable. The phrase "real-time" itself makes no statement about how short those time scales may be. A chess playing super computer has a real time requirement when playing in tournaments, hardly down to micro-seconds though.

So, is Raspian an RTOS? I say yes because:

1) You can set priorities on threads.
2) Threads can be preempted by higher priority code at any time. An endless loop in a low priority thread will not get in your way.
3) High resolution timers are supported. You are not limited to the "jiffy" tick.

Of course there are limitations and you may not get the tiny latencies you can with a dedicated RTOS. I might not want to be using it for safety critical or
other stringent applications but a lot of "real-time" ground can be covered with this.

http://elinux.org/High_Resolution_Timers
https://rt.wiki.kernel.org/index.php/Fr ... _Questions
Memory in C++ is a leaky abstraction .

User avatar
elektrknight
Posts: 140
Joined: Sat Mar 02, 2013 1:25 pm

Re: Is the Raspbian Image RTOS?

Thu Jul 11, 2013 1:41 pm

Is the Linux image capable of running as an RTOS?
"Machinoid hard real-time distribution optimized for machines" http://www.raspberrypi.org/phpBB3/viewt ... 3&p=384463
Raspbian compatible and Xenomai based distro
Placek Malinowy to jest to!

Return to “General discussion”