ESE Magazine Jan/Feb 06 42 XP & real-time <strong>system</strong>s Paul Fischer, TenAsys Corp A virtual machine approach combines a Windows interface with an RTOS. TO AUGMENT the flexibility of Windows as a human-machine interface OS with support <strong>for</strong> the deterministic requirements of embedded applications, <strong>design</strong>ers usually add a dedicated real-time component (i.e., a second computer). Un<strong>for</strong>tunately, a second control computer adds substantial cost of goods, manufacturing complexity, and <strong>system</strong>-<strong>to</strong>-<strong>system</strong> coordination headaches. A “single-computer dual-OS” <strong>system</strong>, where one compute element hosts both the Windows <strong>system</strong> and the RTOS, significantly reduces the cost of goods and complexity, and simplifies the coordination of Windows with real-time processes. Typical real-time Windows solutions utilize a Windows driver inserted in the Windows kernel, an approach that presents many software <strong>design</strong> challenges. A true dual-OS solution employs virtual machine technology where the non-deterministic application elements execute on a “Windows virtual machine,” and deterministic software executes on a “real-time virtual machine” (see figure). A significant advantage of this virtual machine approach is the leverage application developers gain by using a single standard development <strong>to</strong>ol <strong>for</strong> both environments. Interval timers Real-time processes and threads running on the RTOS virtual machine need access <strong>to</strong> highspeed interval timers <strong>for</strong> accurate, low-drift time measurements and <strong>for</strong> generating exact periodic intervals <strong>to</strong> insure precise control of real-time <strong>system</strong>s. x86 APIC uniprocessor and multi-processor <strong>system</strong>s, the vast majority of embedded and desk<strong>to</strong>p Windows plat<strong>for</strong>ms built <strong>to</strong>day, are excellent candidates. To insure efficient implementation of realtime threads, developers need an environment that supports direct access <strong>to</strong> I/O and memory, a fixed priority scheduling <strong>system</strong> with priorityinversion protection, and simplified interrupthandling services. They can then create and deploy sophisticated real-time applications without having <strong>to</strong> write complex and cumbersome device drivers <strong>for</strong> access <strong>to</strong> real-time hardware, simplifying development and debugging of control and data acquisition algorithms. The net gain of the virtual machine “singlecomputer dual-OS” approach is elimination of redundant computer and communication hardware and faster communication and coordination between the real-time and Windows appli- cation parts. The RTOS and its processes run on the same hardware as the standard Windows kernel, sharing the CPU, memory, and I/O resources. A better approach The virtual machine approach <strong>to</strong> adding realtime task processing <strong>to</strong> applications incorporating Windows is quite different from those approaches that install a real-time kernel in the <strong>for</strong>m of a Windows device driver or sub<strong>system</strong>. The device driver and sub<strong>system</strong> models <strong>for</strong>ce real-time applications <strong>to</strong> operate as part of the Windows kernel. Kernel mode code has privileged access <strong>to</strong> the entire memory space, including the Windows kernel and other device drivers; it lacks address isolation and memory protection. A real-time thread running on such a <strong>system</strong> can easily overwrite other processes: both real-time and Windows processes. Because such programming errors are difficult <strong>to</strong> detect in kernel mode and result in spurious but critical failures, achieving reliable operation through this method often requires extensive testing and debugging. Many such errors are not detectable until the <strong>system</strong> has been deployed in the field. Creating a complex, multi-threaded, real-time application <strong>to</strong> run inside the Windows kernel is contrary <strong>to</strong> the notion of building reliable, safe, and dependable real-time applications. <strong>On</strong> the other hand, using a virtual machine <strong>to</strong> add real-time responsiveness <strong>to</strong> Windows, as TenAsys’ INtime does, enables the RTOS <strong>to</strong> maintain reliable operation of real-time processes in the event of a Windows crash. The virtual machine approach <strong>to</strong> real-time Windows allows real-time applications <strong>to</strong> run in user-mode, not kernel-mode. The result is improved reliability and robustness, as well as simplified programming and debugging. Each real-time process runs in a separate 32-bit protected memory segment. These segments are distinct from those used by Windows and provide address isolation and protection not just between the real-time processes, but also between real-time processes and non-real-time Windows code. Dual-core enhancements Using two virtual machines <strong>to</strong> share a single CPU plat<strong>for</strong>m that supports Windows and real-time, works <strong>for</strong> a large number of real-time Windows applications. Typically, applications with cycle times of one millisecond or slower are served quite well by this arrangement and have been deployed Win32 Processes Win32 APIs Windows OS Windows Kernel Windows Virtual Machine Real-Time Application Inter-OS Communication Pentium-class processor Real-Time Processes INtime APIs Real-Time Kernel INtime Virtual Machine Figure 1: A virtual machine implementation on an Intel Architecture processor. on the current crop of desk<strong>to</strong>p and industrial motherboard plat<strong>for</strong>ms (uniprocessor and hyper-threaded Pentium 4 class processors running at 1-3GHz). However, some applications demand faster cycle times. For these applications the solution is dual-core processors. Higher speed cycle times mean higher bandwidth controllers, a desirable trait because it leads <strong>to</strong> improved per<strong>for</strong>mance and throughput. Dual-core processors easily support two operating <strong>system</strong>s by dedicating one CPU <strong>to</strong> the RTOS. The CPU instruction cycles of the dedicated core are available 100% of the time <strong>to</strong> the RTOS. The CPU cycles of all remaining cores become the exclusive property of the Windows virtual machine. Contention <strong>for</strong> key CPU resources such as pipelines, cache, and the FPU are avoided. Coordination between the two processors is accomplished by using built-in interprocessor communication mechanisms, eliminating context switch. In this scenario, interrupt latencies are reduced by an order of magnitude, from 10-30 microseconds down <strong>to</strong> 1-3 microseconds. Loop cycle times in the 50-200 microsecond range are able <strong>to</strong> operate with high precision and accuracy. The advent of inexpensive dual-core hardware means an order of magnitude improvement in the quality and bandwidth of control algorithms can be obtained on a realtime Windows plat<strong>for</strong>m! An RTOS that shares the CPU with Windows, using virtual machine technology, allows embedded Windows applications <strong>to</strong> take full advantage of the Windows’ standard user interface, network capabilities, development <strong>to</strong>ols, and off-the-shelf software and still deliver the per<strong>for</strong>mance required of critical, hard real-time tasks. www.tenasys.com
NO SLOWING DOWN. EVER. The market won’t care who gets there first. We'll work with you <strong>to</strong> architect the best embedded solution <strong>for</strong> your company. And you can start now because we are already doing it. Get your product out there. Fast. PEDAL TO THE METAL. www.radisys.com