Military Embedded Systems Spring 2005 Volume 1 Number 1

Military Embedded Systems Spring 2005 Volume 1 Number 1 Military Embedded Systems Spring 2005 Volume 1 Number 1

mil.embedded.com
from mil.embedded.com More from this publisher
24.11.2014 Views

Software MILITARY EMBEDDED SYSTEMS Resource Guide ents live video, such as MPEG movies. If this device depends on software for any part of its content delivery, it may experience dropped frames at a rate that the user perceives as unacceptable. With an RTOS, however, the developer can precisely control the order in which software processes execute and thereby ensure that playback occurs at an appropriate and consistent media rate. RTOS: A working definition What, exactly, constitutes a hard realtime operating system? No universally accepted definition exists, but here is a good working definition based on realtime scheduling theory and consistent with industry practice: A hard RTOS must guarantee that a feasible schedule can be executed given sufficient computational capacity if external factors are discounted. External factors, in this case, are devices that may generate interrupts, including network interfaces that generate interrupts in response to network traffic. In other words, if a system designer controls the environment, the operating system itself will not be the cause of any tardy computations. To provide such guarantees, the OS must satisfy the following basic conditions: 1. Higher-priority tasks always execute in preference to lower-priority tasks (see Figure 1). 2. Priority inversions, which may result when a higher-priority task needs a resource allocated to a lower-priority one, are bounded. 3. Non-schedulable activities, including both non real-time activities and operating system activities, don’t exceed the remaining capacity in any particular division. ensures that OS services themselves, which are internal factors, don’t introduce non-schedulable activities that could violate basic requirement 3. RTOS vs. GPOS The key characteristic that separates an RTOS from a General-Purpose OS (GPOS) is the predictability inherent in all of the requirements specified above. A GPOS such as Linux attempts to use a “fairness” policy when scheduling threads and processes to the CPU. This gives all applications in the system a chance to make progress, but doesn’t establish the supremacy of real-time threads in the system or preserve their relative priorities, as is required to guarantee that they finish on time. Likewise, all priority information is usually lost when a system service, usually performed in a kernel call, is executing on behalf of the client thread. This results in unpredictable delays and thus prevents an activity from completing on time. By contrast, the microkernel architecture used in an OS like the QNX Neutrino RTOS is designed to deal directly with all of these requirements (Figure 2). Because of its modular design, a microkernel RTOS can employ granular synchronization mechanisms, ensuring that latencies are unaffected by system services. The microkernel itself simply manages processes and threads within the system, and allows them to communicate with each other. Scheduling is always performed at the thread level, and threads are always scheduled according to their fixed priority – in the case of priority inversion, by the priority as adjusted by the microkernel to compensate for priority Figure 1 inversions. Consequently, a high-priority thread that becomes ready to run can preempt a lower-priority thread. Within this framework all device drivers and operating system services apart from basic scheduling and Interprocess Communication (IPC) exist as separate processes within the system. All services are accessed through a synchronous message-passing IPC mechanism that allows the receiver to inherit the priority of the client. This priority-inheritance scheme allows OSR 5 to be met by carrying the priority of the original real-time activity into all service requests and subsequent device driver requests. There is an attendant flexibility available as well. Since OSR 1 and OSR 5 (refer back to Table 1) stress that device-driver requests need to operate in priority order, at the priority of the client, throughput for normal operations can be substantially reduced. Using this model, an operating In Figure 1, the RTOS scheduler determines which thread should run by looking at the priority assigned to every thread ready for execution. The thread with the highest priority is selected to run. Because of condition 3, we must discount those activities outside of the control of the operating system, yielding the external factors provision above. From these conditions, we can derive the Operating System Requirements (OSRs) listed in Table 1. OSR 3 and OSR 4 impose a fixed upper bound on the latency that may occur on the onset of any real-time activity. OSR 5 Operating System Requirements for Real Time OSR 1 OSR 2 OSR 3 OSR 4 OSR 5 The OS must support fixed-priority preemptive scheduling for tasks. (Both threads and processes, as applicable) The OS must provide priority inheritance or priority-ceiling emulation for synchronization primitives. This prevents cases of unbounded priority inversion, where a higher-priority task cannot obtain a resource from a lower-priority task. The OS kernel must be preemptible. Interrupts must have a fixed upper bound on latency. By extension, support for nested interrupts is required. Operating system services must execute at a priority determined by the client of the service. All services on which the client depends must inherit that priority. Priority inversion avoidance must be applied to all shared resources used by the service. Table 1 38 / 2005 MILITARY EMBEDDED SYSTEMS Resource Guide

MILITARY EMBEDDED SYSTEMS Resource Guide Software a lower priority than Job 1 (Figure 3). If Job 3 becomes ready to run while Job 2 is executing, it will preempt Job 2, and Job 2 won’t be able to run again until Job 3 blocks or completes. This will, of course, increase the blocking factor of Job 1; that is, it will further delay Job 1 from executing. The total delay introduced by the preemption is a priority inversion. In fact, multiple jobs can preempt Job 2 in this way, resulting in an effect known as chain blocking. Under these circumstances, Job 2 might be preempted for an indefinite period of time, yielding an unbounded priority inversion and causing Job 1 to fail to meet any of its timeliness constraints. Figure 2 This is where priority inheritance comes in. If we return to our scenario and make Job 2 run at the priority of Job 1 during the synchronization period, then Job 3 won’t be able to preempt Job 2, and the resulting priority inversion is avoided (Figure 4). service or device driver can be swapped out in favor of a real-time version that satisfies these requirements. A closer look A closer examination of OSR 2 (the OS must provide priority inheritance or priority-ceiling emulation) showcases the value of having services execute at a priority determined by the client of the service. To begin, we must look at how task synchronization can result in blocking, and how this blocking can, in turn, cause priority inversion. Manipulating priorities If you are writing an application for deployment on an RTOS, it is important to consider the effect that the RTOS’s characteristics have on the execution of the application, and to understand how these can be used to your benefit. Let’s say two jobs are running, Job 1 and Job 2, and that Job 1 has the higher priority. If Job 1 is ready to execute, but must wait for Job 2 to complete an activity, blocking is said to occur. The blocking may occur because of synchronization; for instance, Job 1 and Job 2 share a resource controlled by a lock or semaphore, and Job 1 is waiting for Job 2 to unlock the resource. Or, it may occur because Job 1 is requesting a service currently used by Job 2. Figure 3 The blocking allows Job 2 to run until the condition that Job 1 is waiting for occurs (for instance, Job 2 unlocks the resource that both jobs share). At that point, Job 1 gets to execute. The total time that Job 1 must wait may vary, with a minimum, average, and maximum time. This interval is known as the blocking factor. If Job 1 is to meet any of its timeliness constraints, this factor can’t vary according to any parameter, such as the number of threads or an input into the system. In other words, the blocking factor must be bounded. Now let’s introduce a third job. Job 3 that has a higher priority than Job 2 but Figure 4 MILITARY EMBEDDED SYSTEMS Resource Guide 2005 / 39

Software<br />

MILITARY EMBEDDED SYSTEMS Resource Guide<br />

ents live video, such as MPEG movies. If<br />

this device depends on software for any<br />

part of its content delivery, it may experience<br />

dropped frames at a rate that the user<br />

perceives as unacceptable. With an RTOS,<br />

however, the developer can precisely control<br />

the order in which software processes<br />

execute and thereby ensure that playback<br />

occurs at an appropriate and consistent<br />

media rate.<br />

RTOS: A working definition<br />

What, exactly, constitutes a hard realtime<br />

operating system? No universally<br />

accepted definition exists, but here is a<br />

good working definition based on realtime<br />

scheduling theory and consistent<br />

with industry practice: A hard RTOS<br />

must guarantee that a feasible schedule<br />

can be executed given sufficient computational<br />

capacity if external factors are<br />

discounted. External factors, in this case,<br />

are devices that may generate interrupts,<br />

including network interfaces that generate<br />

interrupts in response to network traffic.<br />

In other words, if a system designer<br />

controls the environment, the operating<br />

system itself will not be the cause of any<br />

tardy computations. To provide such guarantees,<br />

the OS must satisfy the following<br />

basic conditions:<br />

1. Higher-priority tasks always execute<br />

in preference to lower-priority tasks<br />

(see Figure 1).<br />

2. Priority inversions, which may result<br />

when a higher-priority task needs a<br />

resource allocated to a lower-priority<br />

one, are bounded.<br />

3. Non-schedulable activities, including<br />

both non real-time activities and<br />

operating system activities, don’t<br />

exceed the remaining capacity in any<br />

particular division.<br />

ensures that OS services themselves,<br />

which are internal factors, don’t introduce<br />

non-schedulable activities that could violate<br />

basic requirement 3.<br />

RTOS vs. GPOS<br />

The key characteristic that separates<br />

an RTOS from a General-Purpose OS<br />

(GPOS) is the predictability inherent in<br />

all of the requirements specified above.<br />

A GPOS such as Linux attempts to use a<br />

“fairness” policy when scheduling threads<br />

and processes to the CPU. This gives all<br />

applications in the system a chance to<br />

make progress, but doesn’t establish the<br />

supremacy of real-time threads in the<br />

system or preserve their relative priorities,<br />

as is required to guarantee that they<br />

finish on time. Likewise, all priority<br />

information is usually lost when a system<br />

service, usually performed in a kernel<br />

call, is executing on behalf of the client<br />

thread. This results in unpredictable<br />

delays and thus prevents an activity from<br />

completing on time.<br />

By contrast, the microkernel architecture<br />

used in an OS like the QNX Neutrino<br />

RTOS is designed to deal directly with all<br />

of these requirements (Figure 2). Because<br />

of its modular design, a microkernel<br />

RTOS can employ granular synchronization<br />

mechanisms, ensuring that latencies<br />

are unaffected by system services.<br />

The microkernel itself simply manages<br />

processes and threads within the system,<br />

and allows them to communicate with<br />

each other. Scheduling is always performed<br />

at the thread level, and threads are<br />

always scheduled according to their fixed<br />

priority – in the case of priority inversion,<br />

by the priority as adjusted by the<br />

microkernel to compensate for priority<br />

Figure 1<br />

inversions. Consequently, a high-priority<br />

thread that becomes ready to run can preempt<br />

a lower-priority thread.<br />

Within this framework all device drivers<br />

and operating system services apart<br />

from basic scheduling and Interprocess<br />

Communication (IPC) exist as separate<br />

processes within the system. All services<br />

are accessed through a synchronous message-passing<br />

IPC mechanism that allows<br />

the receiver to inherit the priority of the<br />

client. This priority-inheritance scheme<br />

allows OSR 5 to be met by carrying the<br />

priority of the original real-time activity<br />

into all service requests and subsequent<br />

device driver requests.<br />

There is an attendant flexibility available<br />

as well. Since OSR 1 and OSR 5 (refer<br />

back to Table 1) stress that device-driver<br />

requests need to operate in priority order,<br />

at the priority of the client, throughput for<br />

normal operations can be substantially<br />

reduced. Using this model, an operating<br />

In Figure 1, the RTOS scheduler determines<br />

which thread should run by looking<br />

at the priority assigned to every thread<br />

ready for execution. The thread with<br />

the highest priority is selected to run.<br />

Because of condition 3, we must discount<br />

those activities outside of the control of<br />

the operating system, yielding the external<br />

factors provision above.<br />

From these conditions, we can derive the<br />

Operating System Requirements (OSRs)<br />

listed in Table 1.<br />

OSR 3 and OSR 4 impose a fixed upper<br />

bound on the latency that may occur on<br />

the onset of any real-time activity. OSR 5<br />

Operating System Requirements for Real Time<br />

OSR 1<br />

OSR 2<br />

OSR 3<br />

OSR 4<br />

OSR 5<br />

The OS must support fixed-priority preemptive scheduling for tasks. (Both<br />

threads and processes, as applicable)<br />

The OS must provide priority inheritance or priority-ceiling emulation for<br />

synchronization primitives. This prevents cases of unbounded priority<br />

inversion, where a higher-priority task cannot obtain a resource from a<br />

lower-priority task.<br />

The OS kernel must be preemptible.<br />

Interrupts must have a fixed upper bound on latency. By extension, support<br />

for nested interrupts is required.<br />

Operating system services must execute at a priority determined by the<br />

client of the service. All services on which the client depends must inherit<br />

that priority. Priority inversion avoidance must be applied to all shared<br />

resources used by the service.<br />

Table 1<br />

38 / <strong>2005</strong> MILITARY EMBEDDED SYSTEMS Resource Guide

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!