Wiley.Symbian.OS.C.plus.plus.for.Mobile.Phones.Aug.2007 (779890), страница 7
Текст из файла (страница 7)
The nanokernel is the core of modern Symbian OS kernel architecture (EKA2) and is a very small Real Time Operating System (RTOS),designed to underlie Symbian OS, and provide low interrupt and threadlatency.Symbian OSapplicationSymbian OSapplicationSymbian OS Micro-kernelRTOS applicationRTOS personalityNanokernelRTOS applicationRTOSFigure 2.1 Symbian OS kernel architectureIn EKA2, the nanokernel does not deal with any dynamic memorymanagement.
Memory management is provided by the Symbian OSmicrokernel.For the rest of this book, we will use the term ‘kernel’ to refer to thecombination of nanokernel and microkernel that makes up the SymbianOS kernel, as it appears to applications and unprivileged programs (whichare our primary concern).The design of Symbian OS focuses on open mobile phones and therefore is, above all, optimized for efficient user-driven resource-constrainedoperation.From microkernel architectures, the Symbian OS kernel borrows thefollowing characteristics:20A SYSTEM INTRODUCTION TO SYMBIAN OS• several message-passing frameworks designed for the benefit of userside servers• networking and telephony stacks hosted in user-side servers• file-systems hosted in a user-side server.In the Symbian OS kernel, as in monolithic kernel architectures:• device drivers are run kernel-side; not embedded in the kernel binary,though, but implemented as libraries that can be loaded and unloadedat run-time• the scheduler and scheduling policy are implemented in the kernel• memory management is implemented in the kernel.In general, the kernel deals with core hardware resources such as:• central processing unit (CPU) and memory management unit (MMU)• memory management policies• interrupt handling and management• DMA channel management.As mentioned above, some of the above responsibilities are sharedbetween the nanokernel and the microkernel.The microkernel nature of Symbian OS allows many OS services tobe offered in the non-privileged mode of the processor.
The kernel useshardware-supported privilege to gain access to such hardware resources.That is, the CPU will perform certain privileged instructions only for thekernel. It runs other programs, so-called user-mode programs, withoutprivilege, so that they can access system resources only through the kernelAPIs.In this text we refer to the non-privileged mode as user-side andto the privileged mode as kernel-side (ARM calls this mode SVC, for‘supervisor’).The boundary between the kernel and all other components is effectively a privilege boundary, which needs to be crossed every time auser-side program needs to communicate with the kernel as well as whenone user-side process needs to communicate with another (since suchcommunication is mediated by the kernel in all but exceptional cases).Crossing from user side to kernel sideIn Symbian OS, components never link to the kernel directly (that is,statically), as one would expect in more traditional embedded RTOSs.They have to interface to the kernel through a dynamically linked userlibrary called euser.dll.
This is always located at a known address, sothat calls can be resolved at link/load time for more efficiency.SYMBIAN OS BASICS21In euser.dll there are three families of exported calls:• utility classes, methods and common constructs such as descriptors,array classes and math functions• fast executive calls (system calls that execute with interrupts disabled)• slow executive calls (system calls that execute with interrupts enabled).Executive calls are the user library calls that allow a user thread to enterprocessor-privileged mode so that they can access hardware resources orkernel-space objects in a controlled and predefined way.
An executivecall switches control to the kernel executive. In that respect, the kernelexecutive is not a separate thread, but a collection of pre-programmedkernel functions that, while in kernel mode, execute in the context of thethread that calls them.When programs call these functions, the user library causes a softwareinterrupt (i.e., an ARM SWI instruction). This causes the processor tobranch to the software interrupt handler routine, as defined at OS startuptime. The software interrupt handler checks the type of executive calland branches to the correct kernel function accordingly (for a precisetreatment of how this happens in EKA2 refer to [Sales 2005]).From Symbian OS v8.1b onwards, executive calls can be pre-empted.This means that, while a thread is executing kernel-side (which may beblocking in the kernel), its system call may safely be interrupted.
Thisflexibility is possible because each user thread has two stacks, a user stackfor user-side operation and a kernel stack that is used when the threadhas crossed to the kernel side. This gives much higher pre-emptibility,leading to much shorter latency during interrupts.Executive calls may access and even modify kernel-side objects, aswell as offer privileged access to hardware. On EKA2, executive callscan create and/or destroy kernel-side objects and, in general, performallocations or de-allocations on the kernel heap.Kernel threadsOn EKA2, there are by default five threads that run in supervisor mode,as illustrated in Figure 2.2.• The Null thread is the first thread to be scheduled.
It has the lowestpriority and is, amongst other things, responsible for placing the CPUin low-power mode when there is no other thread executing. Thisthread is also responsible for de-fragmenting physical RAM from timeto time.• The Supervisor thread is primarily responsible for asynchronouslycleaning up resources after thread and process termination. This22A SYSTEM INTRODUCTION TO SYMBIAN OSPrivileged mode(Kernel-side)User-sideTimer threadProcessProcessProcessUSERLIBRARYSWISupervisorthreadEXECUTIVENull threadDFC0 threadDFC1 threadFigure 2.2 User-side processes and the kernelthread is also responsible for the completion of property subscriptions(see Chapter 8).• DFC thread 0 is where most driver Deferred Function Calls execute.DFCs, which form part of driver non-ISR (Interrupt Service Routine)processing, are queued sequentially on this thread.
Device driverswithout stringent real-time requirements use this thread for their DFCs(for more information, see [Sales 2005]).• DFC thread 1, which by default has the highest priority is usuallyresponsible for running the nanokernel’s timer DFCs.• The Timer thread is, by default, used to manage the Symbian OSmicrokernel time queues.These five threads run kernel-side by default, but they are not theonly threads that can run in supervisor mode. In order to support othermicrokernel personalities, as well as device drivers and kernel extensionsthat need to run in supervisor mode, there may be other threads that alsorun kernel-side.Threading and Process ModelAs discussed already, Symbian OS is a pre-emptive multitasking operatingsystem whose kernel runs in privileged mode, while all other tasks run inSYMBIAN OS BASICS23non-privileged mode [Furber 2000].
All access to memory and memorymapped hardware is protected through use of the MMU by the operatingsystem. Kernel-side code can access all the memory belonging to anyprogram, whereas a non-privileged program can directly access only thememory specifically mapped to it.In Symbian OS the unit of memory protection is called the process,while the unit of execution is the thread. A process may contain oneor more threads. In the case of the nanokernel, by default there are fivethreads, as discussed above.
What gets scheduled in Symbian OS arethe threads – not the processes, which are effectively memory-protectioncontainers.Memory management ensures that Symbian OS presents a virtualmemory machine model to all running programs. This means that allprograms are presented with, and make use of, a linear virtual-memoryenvironment facilitated by the use of the MMU. Virtual memory in thiscontext does not mean that Symbian OS makes use of program swapping(for example, on hard disks), but that all programs during linking, locatingand execution appear at the same virtual address; and that they cannotdirectly access each other’s memory.In general, each program runs as a separate Symbian OS process,within its own virtual address space, so the boundary between oneapplication and another is a process boundary.