Concepts with Symbian OS (779878), страница 12
Текст из файла (страница 12)
Inner layers implement basic,primitive functions in such a way that these basics execute very quickly.Innermost layers are also the most privileged layers, able to access allcomponents of the operating system whenever they need to. As youlook from inner to outer layers, the functions of the layers get lessprimitive and privileges are taken away; you move out toward user-modeapplications requiring fewer kernel-mode privileges and functionality.Figure 3.1 shows the general Symbian OS kernel structure.• The nanokernel provides some of the most basic functions in SymbianOS.
Simple threads operating in privileged mode implement servicesUser-mode ApplicationsMicrokernel ServersSymbian OS kernelNanokernelMMFetelesockWservFigure 3.1 Layers in the Symbian OS kernelHOW A KERNEL IS PUT TOGETHER49that are very primitive. Included among the implementations at thislevel are scheduling and synchronization operations, interrupt handling and synchronization objects called mutexes and semaphores(we discuss these later). Most of the functions implemented at thislevel can be pre-empted.
Functions at this level are so primitive (sothat they are fast) that the nanokernel must not implement any kind ofcomplicated operation, such as dynamic memory allocation.• The Symbian OS kernel layer provides kernel functions needed by therest of the operating system. Each operation at this level is a privilegedoperation and combines the primitive operations of the nanokernel toimplement more complex tasks. Complex object services, user-modethreads, process scheduling and context switching, dynamic memory,dynamically loaded libraries, complex synchronization objects andinterprocess communication are just some of the operations implemented by this layer. This layer is fully pre-emptible and interruptscan cause this layer to reschedule any part of its execution – even inthe middle of context-switching!• The server layer is typical of microkernel architectures.
Operationsthat do not require complete privileged operations or that have acomplex implementation are pushed out to servers. Server-basedfunctions typically govern specific areas of functionality, such ashandling the display or working with sockets, and usually run asuser-mode services.
These areas of functionality require kernel-basedoperations only sporadically and therefore can sit outside the SymbianOS kernel layer.• The user-mode applications run almost completely in user mode andperform kernel-based operations either by interacting with servers orby making system calls that activate kernel-mode activity.It is instructive to look at the kernel structure from another perspective. Itis easy to think of the kernel as an always-on, executing set of code thatruns alongside application programs. This is not the case. Only part ofthe kernel runs constantly; much of the kernel is implemented passively,set into operation by system calls and interrupt handlers.Active Kernel ComponentsActive kernel components are those parts of the kernel that execute alongwith other processes in the operating system.
These kernel processes50KERNEL STRUCTUREtypically have higher priorities and high levels of protection. They areusually multithreaded to allow for multiple threads of access from threadsof execution in various processes.Active kernel components are active so that they can monitor thesystem in real time.
They field requests for kernel services, servicethose requests, load and unload system modules (the passive kernelcomponents), and perform all the bookkeeping that needs to be done.Active components assist with the working of passive components as theyfield requests and implement the requests in kernel mode. Consider someexamples.• Two processes want to communicate. One of their implementationchoices is to pass data through global memory from one processto another.
This global memory is maintained by the kernel andaccess is gained through kernel requests. Each process makes asystem call that sends a request to the kernel process. As we see inChapter 6, this request requires a mechanism called a semaphore thatcoordinates how each process accesses the global data. All of thisaccess, from semaphores to global memory reading and writing, mustbe maintained by active kernel components.• An application begins execution by building a context, then switchinginto and out of contexts as the CPU is multiplexed between processes.
Context-switching is managed by active kernel componentsin response to a voluntary relinquishing of the CPU, some kind ofI/O blocking or a timer event. Again, bookkeeping must be done andmemory must be managed to make sure processes switch contextsproperly. In between process switches, other system duties must takeplace and the active components implement these as well.• An application wishes to manipulate an I/O device, for example,sending data to an IR port. Active kernel components are built withvarying degrees of peripheral support.
Monolithic kernel structurestypically have a built-in set of device implementations. Microkernelarchitectures, by contrast, are typically independent of peripheralimplementations. In all cases, it is highly likely that code is loadeddynamically to implement various portions of device I/O. The activecomponents of the kernel are involved in module loading and unloading and do these tasks as required by service requests. In Symbian OS,for example, sending data through an IR port results in the loading ofseveral I/O drivers in sequence, in response to several kernel requests.HOW A KERNEL IS PUT TOGETHER51Let’s consider this last example a little more closely.
In a freshly bootedsystem, the active components of a microkernel-based operating systemhave a very small memory footprint. For example, the executing kernel inSymbian OS v8 uses about 200 KB of memory when it starts up. A requestto use the IR port on a device causes a series of events, orchestrated andimplemented by the executing kernel code. The executing kernel needsto add layers of code to implement the data exchange over IR. None ofthese layers are initially in memory and all of these layers represent aninitial performance hit as the kernel code initializes device drivers andstarts communication.The size of the executing kernel components have a direct impact onsystem performance through the use of memory and the time it takes toload additional modules that implement various features. A monolithickernel structure minimizes the loading of implementation layers.
Muchof the functionality of device I/O, for example, is built into a monolithickernel. Response time is initially quicker because modules do not need tobe loaded. However, because many modules are loaded that are perhapsunneeded, memory requirements go up dramatically. Unix operatingsystems typically boot an active kernel that requires 10 MB to 60 MBat boot time. Microsoft Windows has a smaller requirement, but it istypically at least 8 MB of memory.Monolithic structures come preloaded with many of the implementations required to run an operating system.
The structure is very static,because support for various hardware is built in. On the other side of thesize spectrum, microkernel structures take up much less memory uponboot and their structure is more dynamic. Microkernels usually supporta ‘pluggable’ architecture with support for hardware that can be loadedas needed and ‘plugged into’ the kernel. Thus, microkernels are moreflexible – code to support new hardware can be loaded and plugged inany time – but monolithic structures are faster – they avoid the overheadof the pluggable interface).One way to enhance the performance of all types of active kernelcomponents is to give multithreaded implementations.
Remember thatthe active part of the kernel is an executing process like the otherprocesses in the system. Therefore, it can have multiple threads ofexecution running inside a single context. The benefit of multithreadingto kernel implementation is that each thread can execute a request forkernel service, resulting in multiple requests being serviced at the sametime. This is especially helpful when multithreading is implemented for52KERNEL STRUCTUREsystem modules – such as microkernel servers – and for user code.
Whenall of these threads of control are capable of requesting kernel services,the kernel must be multithreaded to support them.Consider a user-mode application that requests a kernel-mode operation, for example, to load a set of data from a flash memory card. Asthe kernel is doing this, a phone call comes in and must be serviced. Akernel with a single thread would have to select one of these requeststo work on and queue the other request for later service. The systemcould prioritize the requests by making the phone call (a real-timeoperation) more important and thereby making the user-mode requestwait.
However, a multithreaded kernel could service both operations atthe same time, handling device interrupts with a thread separate fromuser-mode requests. While the CPU must still be shared between thesetwo requests, the end result is that service is faster because both operationsare in memory at the same time.Passive Kernel ComponentsPassive kernel components are those parts of the kernel that are notcontinually executing but are available for execution on behalf of servicerequests. These components are present in the form of libraries anddynamically loaded modules that contain code that implements systemcalls and interrupt service routines. It is through these components thatuser-level code can get kernel-level tasks done on their behalf.These elements of the kernel are called passive because they do notexecute on their own.