Difference between OS scheduling and RTOS scheduling
Asked Answered
R

4

7

Consider the function/process,

void task_fun(void) { while(1) } If this process were to run on a normal PC OS, it would happily run forever. But on a mobile phone, it would surely crash the entire phone in a matter of minutes as the HW watchdog expires and resets the system. On a PC, this process, after it expires its stipulated time slice would be scheduled out and a new runnable process would be scheduled to run.

My doubt is why cant we apply the same strategy on an RTOS? What is the performance limitation involved if such a scheduling policy is implemeted on an RTOS?

One more doubt is that I checked the schedule() function of both my PC OS ( Ubuntu ) and my phone which also runs Linux Kernel. I found both of them to be almost the same. Where is the watchdog handing done on my phone? My assumption is that scheduler is the one who starts the watchdog before letting a process run. Can someone point me where in code its being done?

Residency answered 10/6, 2011 at 6:6 Comment(5)
I'm not so confident about your use of terms here: an RTOS is generally an OS where there is a guaranteed maximum time for an event to be serviced (like an ISR). Watchdog timers aren't really required if an OS properly schedules tasks pre-emptively, only if one task can monopolise the processor(s) such as with co-operative multitasking. Typically a watchdog timer is a hardware thing which you have to "kick" every so often (such as on task switch) to ensure it doesn't reset the device.Socher
Perhaps it would be less controversial to use the term "Embedded OS"? Which OS does your phone use?Unbar
@John Mulder : Yes you are right! Embedded OS would be a better term! My phone is running Linux kernel 2.6.35.11!Residency
How do you know this would surly crash your phone ?Louiselouisette
@Louiselouisette : I've worked on quite a few embedded mobile phone platforms. The phones crash whenever there is a time consuming process in a task ( like contacts DB updating ) or there is a bug in the system which results in a plain while(1){}Residency
D
1

The phone "crashing" is an issue with the phone design or the specific OS, not embedded OSes or RTOSes in general. It would 'starve' lower priority tasks (possibly including the watchdog service), which is probably what is happening here.

In most embedded RTOSes it is intended that all processes are defined at deployment by the system designer and the design is for all processes to be scheduled as required. Placing user defined or third party code on such a system can compromise its scheduling scheme as in your example. I would suggest that all such processes should run at the same low priority as all others so that the round-robin scheduler will service user application equally without compromising system services.

Phone operating systems are usually RTOS, but user processes should not run at higher priority that system processes. It may be intentional that such processes run higher than the watchdog service exactly to protect the system from "misbehaving" applications which yours simulates.

Most RTOSes use a pre-emptive priority based scheduler (highest priority ready task runs until it terminates, yields, or is pre-empted by a higher priority task or interrupt). Some also schedule round-robin for tasks at the same priority level (task runs until it terminates, yields or consumes its time-slice and other tasks of the same priority are ready to run).

Dorthydortmund answered 11/6, 2011 at 7:43 Comment(0)
I
1

There are several ways a watchdog can be implemented, none of which is imposed by Linux:

  • A process or thread runs periodically to test that vital operations are being performed. If they are not, correction action is taken, like reboot the machine, or reset a troublesome component.
  • A process or thread runs continuously to soak up extra CPU time and reset a timer. If the task is not able to run, a timer expires and takes corrective action.
  • A hardware component resets the system if it is not periodically massaged; that is, a hardware timer expires.

There is nothing here that can't be done on either an RTOS or any other multitasking operating system.

Inherence answered 10/6, 2011 at 6:52 Comment(2)
All your points are exactly true! But my doubt why doesn't a PC OS impose any of these and an embedded OS does it and what are performance hits, if any, if such a thing is not implemented on an embedded OS and if implemented on a PC OS?Residency
@PavanM: most embedded systems have well known characteristics, so it is straightforward to identify "normal behavior." Most PCs are general purpose: sometimes they run programs which add a few numbers; other times they run programs which compute pi to ten million decimal digits. How would the O/S identify an errant program?Inherence
P
1

Linux, on a desktop computer or on a mobile phone, is not a RTOS. Its scheduling policy is time-driven.

On a RTOS, scheduling is triggered by events, either from environment through ISR or from software itself through system calls (send message, wait for mutex, ...)

Polyploid answered 10/6, 2011 at 7:58 Comment(1)
There are time-driven RT scheduling policies as well. See rate-monotonic / earliest deadline approaches to scheduling task sets.Cistercian
D
1

The phone "crashing" is an issue with the phone design or the specific OS, not embedded OSes or RTOSes in general. It would 'starve' lower priority tasks (possibly including the watchdog service), which is probably what is happening here.

In most embedded RTOSes it is intended that all processes are defined at deployment by the system designer and the design is for all processes to be scheduled as required. Placing user defined or third party code on such a system can compromise its scheduling scheme as in your example. I would suggest that all such processes should run at the same low priority as all others so that the round-robin scheduler will service user application equally without compromising system services.

Phone operating systems are usually RTOS, but user processes should not run at higher priority that system processes. It may be intentional that such processes run higher than the watchdog service exactly to protect the system from "misbehaving" applications which yours simulates.

Most RTOSes use a pre-emptive priority based scheduler (highest priority ready task runs until it terminates, yields, or is pre-empted by a higher priority task or interrupt). Some also schedule round-robin for tasks at the same priority level (task runs until it terminates, yields or consumes its time-slice and other tasks of the same priority are ready to run).

Dorthydortmund answered 11/6, 2011 at 7:43 Comment(0)
T
0

In a normal OS, we have two types of processes. User process & kernel Process. Kernel processes have time constraints.However, user processes do not have time constraints.

In a RTOS,all process are Kernel process & hence time constraints should be strictly followed. All process/task (can be used interchangeably) are based on priority and time constraints are important for the system to run correctly.

So, if your code void task_fun(void) { while(1) } runs forever, other higher priority tasks will be starving. Hence, watch dog will crash the system to specify the developer that time constraints of other tasks are not met.

For example, GSM Scheduler needs to run every 4.6ms, if your task runs for more time, time constraints of GSM Scheduler task cannot be satisfied. So the system has to reboot as its purpose is defeated.

Hope this helps :)

Taboret answered 29/3, 2012 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.