Linux or RTOS?

On the importance of choosing the right OS

by Sebastian Floss
4 minute read

If the question was “Linux, Windows or OSX?”, a follow up question would quickly be about the target audience and the applications that need to run on the OS. 

That’s because those three are all so-called General Purpose OS’es and the decision in favour of one of them, at least in a consumer context, is more about a personal preference than anything else.

Since this article is asking the question “Linux or RTOS?” (where RTOS stands for "Realtime Operating System), let’s first have a look at what aspects of an operating system we’re interested in when targeting an IoT device.

The two core functions that any OS needs to be able to perform are :

  1. abstracting the hardware to a generalised level and providing services for simplifying development of a device’s utility functions
  2. providing a way of running several tasks or processes “simultaneously”  

What sets the plethora of available Operating Systems apart now is the availability of drivers for certain hardware and also the way the higher level abstraction is presented to application developers in form of software frameworks or libraries. Regarding the ability to schedule tasks there really only is a difference in the way this happens and most times this will be looked at only if certain “hard” timing requirements have to be met.

Linux has a long history and a wide adoption base by hardware manufacturers, therefore there’s few chips and extension boards that won’t have a linux driver available which can easily be compiled in by just changing a configuration setting. 

Most RTOSes that are fit for IoT (the ones like FreeRTOS or ThreadX) don’t have that. The drivers come from the chip manufacturers or have to be written from scratch and then integrated by the developer.

Now why would I go with an RTOS then in the first place?

Well here’s the thing: Linux (and all the other “General Purpose” OSes) are multi-user systems, designed to run on machines where you can install (almost) any application that was build for that OS. And you can run multiple applications at a time. While this is good for the desktop/notebook/tablet/smartphone world, it comes at the price of certain requirements in hardware.

Any GPOS needs an “application processor” type of CPU like ARMs Cortex A series, that features a Memory Management Unit (MMU) and is able to provide each running application with its own virtual memory space. Those CPUs need larger amounts of DRAM to account for that and are much more power hungry than their Cortex M counterparts, so you can’t really run them on a battery for more than a couple of days. With that and the bill of materials in mind at this point you should start asking yourself: do I really need to run an extensible set of multiple applications on my IoT device? 

The answer should really only be yes if your device is more of a “platform” that will be serving as a base for third parties to run their applications on.

In any other case an IoT device should have a pretty well defined set of functions that it was built to carry out and this is the perfect application for a small RTOS that just takes care of task scheduling for you. Regarding the driver and framework part, don’t worry - there are plenty of them available, instead of just selecting them at compile time though, you will have to put it all together in your IDE. While it may be a little more work, it comes with the benefit that the developers really need to think about what they need and thus serve the most important IoT OS-Security requirement “disable any unused services” right from the beginning.

Of course there is plenty more reasons why anyone would go with either type of OS. The intention in this short article is to emphasise, that the OS choice should not be made light-heartedly. Just because there is no expert for a certain technology on your team, for example, should not be the pivotal reason.

Warum sollte ich dann überhaupt über ein RTOS nachdenken?

Die Sache ist die: Linux (und alle anderen "General Purpose" Betriebssysteme) sind Multi-User-Systeme, die auf Computern laufen, auf denen Sie (fast) jede Anwendung installieren können, die für dieses Betriebssystem erstellt wurde. Außerdem können sie mehrere Anwendungen gleichzeitig ausführen. Während das für die Desktop- / Notebook- / Tablet- / Smartphone-Welt gut ist, hat es gewisse Hardware-Anforderungen zur Folge.

Jedes GPOS benötigt eine CPU vom Typ "Anwendungs-Prozessor" wie die Cortex A-Serie von ARM, die über eine Memory Management Unit (MMU) verfügt und in der Lage ist, jeder laufenden Anwendung ihren eigenen virtuellen Speicherbereich zur Verfügung zu stellen. Solche CPUs benötigen größere Mengen an DRAM-Speicher und sind viel energiehungriger als ihre Cortex M "Kollegen", so dass man sie nicht mehr als ein paar Tage mit einer Batterie betreiben kann. Mit dieser Tatsache und der Bauteile-Stückliste im Hinterkopf sollten man nun anfangen, sich zu fragen: Muss ich wirklich eine erweiterbare Anzahl von mehreren Anwendungen auf meinem IoT-Gerät ausführen?

Die Antwort sollte eigentlich nur dann "Ja" lauten, wenn Ihr Gerät eher eine Plattform ist, auf der Dritte ihre Anwendungen ausführen können sollen.

In jedem anderen Fall sollte ein IoT-Gerät eine ziemlich gut definierte Reihe von Funktionen haben, für die es gebaut wurde, und das ist die perfekte Anwendung für ein kleines RTOS, das sich nur um das Task-Scheduling kümmert. In Bezug auf den Treiber und den Framework-Teil, keine Sorge - es gibt auch hier viel Software, bloß anstatt diese nur beim Konfigurieren des Betriebssystems zu selektieren, müssen Sie alles in Ihrer IDE zusammensetzen. Auch wenn das vielleicht ein wenig mehr Arbeit macht, liegt ein Vorteil darin, dass die Entwickler  wirklich darüber nachdenken müssen, was sie benötigen und damit die wichtigste IoT OS-Sicherheitsanforderung erfüllen: "unbenutzte Dienste von Anfang an deaktivieren".

Natürlich gibt es viele weitere Gründe, warum jemand mit dem einen oder anderen Typ von Betriebssystemen arbeiten sollte. Die Absicht in diesem kurzen Artikel ist es auch nur, zu betonen, dass die OS Wahl nicht leichtherzig getroffen werden sollte. Dass es in einem Team beispielsweise keinen Experten für eine bestimmte Technologie gibt, sollte auf keinen Fall der entscheidende Faktor sein 

more insights