Академический Документы
Профессиональный Документы
Культура Документы
Cheng, Chen-Mou
Abstract
A real-time operating system architecture for embedded applications, namely, the OS/T 3.0 architecture, is proposed, and an implementation on the IBM PowerPC 403GA platform, called the OS/T v3.0PPC, is explored in depth in this thesis. The architecture addresses the issues of splitting control of physical hardware devices from that of logical ow of program execution, as well as a compact model of e cient and exible interrupt handling. Furthermore, implementations of the OS/T 3.0 architecture on di erent platforms should be source-level compatible in the sense that the same application program can run on each of the implementations after limited modi cation of hardware-related code and recompilation. One of the implementation, the OS/T v3.0-PPC features a fully-preemptive multitasking real-time operating system, with support for periodic and sporadic tasks, as well as deterministic and predictable behaviors. Performance measurement of OS/T v3.0-PPC has been carried out, and the results show the e ectiveness of the design.
Contents
1 Introduction
1.1 Overview and Design Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Related Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.3 Outlines of the Thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1 The Process Model . . . . . . . . . . . . . . . 2.2 Inter-Process Communication . . . . . . . . . 2.2.1 The Event Model . . . . . . . . . . . . 2.2.2 The Message Queue Model . . . . . . 2.2.3 The Semaphore Model . . . . . . . . . 2.3 The Time Model and Timer Facilities . . . . 2.3.1 Calendar Time and Date . . . . . . . 2.3.2 Alarm Timer Facilities . . . . . . . . . 2.3.3 Comparisons between Timer Facilities 2.4 The Exception Model . . . . . . . . . . . . . 2.5 Process State Transitions . . . . . . . . . . . 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1 3 4
. 5 . 6 . 6 . 6 . 7 . 8 . 8 . 8 . 9 . 9 . 10 . . . . . . . . . .
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . Naming Convention . . . . . . . . . . . . . . . . . . . . Queue Operations . . . . . . . . . . . . . . . . . . . . . Memory Management . . . . . . . . . . . . . . . . . . . Process Management and Inter-Process Communication Interrupt Handling and Timer Management . . . . . . . Debugging Facilities and Miscellaneous . . . . . . . . . . Error Handling . . . . . . . . . . . . . . . . . . . . . . . Bootstrapping and System Initialization . . . . . . . . . Performance Measurement . . . . . . . . . . . . . . . . . i
15
15 15 16 17 18 18 19 20 20 21
26 27
27 29 31 34
B STBLD
35
ii
List of Figures
2.1 2.2 2.3 2.4 2.5 3.1 3.2 3.3 3.4 An Example Periodic Task . . . . . . . . Another Example Periodic Task . . . . . . An Example Exception Handler . . . . . . An Example Multiple-IRQ Device Driver The Process State Transition Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 . 9 . 11 . 12 . 13 . . . . 22 23 24 25
System Call Timing Under Light Load (N = 10) . . . System Call Timing Under Medium Load (N = 100) . System Call Timing Under Heavy Load (N = 500) . . System Call Timing Under Di erent Load Conditions
iii
Chapter 1
Introduction
1.1 Overview and Design Goals
The operating system is de ned as a layer of software that multiplexes as well as abstracts physical resources, such as volatile memory, processor cycles, I/O devices, etc, for the application programmers. Application software, in contrast, refers to everything else that is designed for a special purpose, to acheive a speci c goal, or to solve a particular problem. From the programmer's point of view, in addition to providing a set of high-level operations that conceals the details of the bare machine, an operating system enables programming based upon an extended, elegant, and platform-independent model that is probably not embedded in any hardware design. An embedded system usually involves a microcontroller with limited computation power and simplied architecture. Despite the fact that programming model of a microcontroller is simple as compared with that of a general purpose processor, developing an operating system for embedded applications is not an easy task because requirements in such applications are usually very strict, especially in timing constraints. A real-time system is a system in which the correctness is determined not only by the result of computation but also by the time at which the result is computed. Missing timing constraints will, in a so-called hard real-time system, cause the result totally useless, thus regarded as a system failure even it is correctly computed. In contrast, in a soft real-time system, missing timing constraints occassionally is not fatal, although it might indicate a aw in the design. Microcontroller-based embedded systems are widely used in industry. One of the challenges in developing software for such applications is how to fastly adapt existing application software onto a new and more cost-e ective hardware platform. As cheaper, faster, and more powerful embedded hardware develops, such ability can e ectively shorten the time-to-market of new and competitively priced products. But application programs on embedded systems are mostly involved with direct manipulation of hardware for e ciency considerations, making porting across di erent hardware architecture nearly infeasible. The strategy is to separate control of physical hardware devices from ow of program execution the operating system provides primitives to assist application programmers by controlling 1
the ow of program execution, leaving these programmers concentrating on writing code for hardware dependent and speci c control. The goal of operating system architecture is to de ne common and hardware-independent abstraction of ow of program execution, making programming on di erent platforms similar and porting accross these platforms easy. The term `architecture' means structure | the way in which something is made, built, or organized 1]. In the context of operating systems design, it refers to the assumptions on system behavior and the model based upon which a programmer develops application software. In short, the architecture of an operating system primarily determines how a programmer programs on top of it. An implementation, in contrast, is a realization of the architecture it refers to a set of software that acts as an operating system, runs on a particular platform, and conforms to the architecture. A platform is characterized both by the hardware as well as the development software, including preprocessor, compiler, assembler, linker, etc. A set of implementations of an operating system architecture, possibly on di erent platforms, are said to be source-level compatible if the same application program can run without modi cation on each of the implementations after recompilation. The goal is to design an operating system architecture | namely, the OS/T 3.0 architecture1, that is primarily aimed for embedded real-time applications. OS/T 1.0 is a fast and compact realtime kernel, running on the ITRI CMS Development Card Model CMSS9306A, an MC68000-based single board system 2]. In addition to porting onto Intel real-mode 80x86-based systems, OS/T 2.x introduces the concept of interrupt handling tasks and the portability of the operating system itself 3]. Both OS/T 1.0 and OS/T 2.x feature fully-preemptive multitasking operating systems, and provide inter-process communication facilities. OS/T 2.x also addresses the issues of source-level compatibility. Based upon the experience, OS/T 3.0 formalizes our strategy in solving the portability problems of both the application software and the operating sytem, and provides a new model of exception handling. Since the main purposes of applications on an embedded system are mostly to control a wide variety of hardware, they are usually deeply hardware dependent, making complete source-level compatibility a very di cult but less meaningful criterion for the operating systems to achieve. The de nition of the source-level compatibility for embedded operating systems and applications is modi ed as follows: A set of operating systems are said to be source-level compatible if the same application program can run after modi cation of a limited portion of hardware dependent code and recompilation on these operating systems. In this context, the goal of the OS/T 3.0 architecture is a set of well-de ned, powerful application programming interface and elegant, compact programming model, so that the implementations can easily achieve the following goals: 1. Any implementation of the architecture should have deterministic and predictable behavior 2. Any implementation of the architecture should be fully preemptive multitasking 3. Any implementation of the architecture should support periodic as well as sporadic tasks
1
Chapter 2
In this document, a process is sometimes called a task these two terms are interchangeable.
fashion.
metaphor, groups of cooperative processes can synchronize and exchange information using such a message sending mechanism. In OS/T 3.0, however, the metaphor is a little bit di erent by introducing the concept of a message queue. A message queue is like a mailbox, but this kind of mailbox is not owned exclusively by any process. Rather, any process which knows the message queue can send and receive messages from that queue. A process can still create its own message queue from which only that process can receive messages, or, alternatively, a group of cooperative processes can share a message queue to communicate with one another or with other processes outside the group. The message queue, therefore, is a more generalized model of message passing. A process receives messages from a message queue via the q recv operation. Like issueing an ev recv operation, the process has to specify whether it will wait for the message to arrive and if it wants to wait, how long it is willing to wait. If two or more processes have issued q recv operations over the same message queue and there is no message in that queue, they will pile up in the waiting queue of the message queue. A message arrived later on will be delivered to the piled processes in a rst-in- rst-out fashion, just as the name `waiting queue' indicates. There are three ways to send a message: q send, q urgent, and q broadcast. Normally when a message arrives at a message queue where there is no process waiting, the message will be queued in a rst-in- rst-out fashion, just as the name `message queue' indicates. However, if a message is sent via the q urgent operation, it will be put at the head, rather than the end, of the message queue. A successive q urgent will be regarded as hasving an even greater urgency that the message it delivers will be put in front of all previously arrived messages. A q broadcast operation will broadcast identical messages to each process at the waiting queue of a message queue, but if there is no process waiting, the broadcast message will be lost, received by no process at all.
if a sem p operation is about to increment the semaphore value beyond the upper bound, an error is reported to the issueing process.
Figure 2.2: Another Example Periodic Task However, if the computation in do something is so complex that it takes two or more ticks to nish, this approach may not work | at least the period has to be compensated, taking into account the computation time. The situation can be worse if the computation time can not be decided deterministically, which is usually the case in the real-world algorithms and computation. If the error of the period is required to be within, say, a few ticks, this approach does not work at all.
handling policy. Rather, the architecture suggests a programming style to handle exceptions, using the inter-process communication primitives. An exception is modeled as an event and an interrupt simply sends such an event to the corresponding process. The architecture de nes three operations regarding exception handling they are: isr hook, isr unhook, and isr getinfo. The isr hook operation speci es an event sent to a process, after a usually small fragment of code is executed, when a particular type of exception occurs, while the isr unhook operation cancels such a linkage. The isr getinfo operation reports the current setting of a particular type of exception handling. Fig.2.3 is an example showing how to create a task to handle a particular exception, or, in other words, to create an interrupt service routine. Another example in g.2.4 shows how to write a device driver if that device uses two or more interrupt request lines, which is not rarely seen in a real-world device.
void root_task(void) { ULONG pid do_some_initialization() t_create('ISRn', A_HIGH_ENOUGH_PRIORITY, ..., &pid) t_start(pid, ..., irq_n_task, ...) isr_hook(IRQ_N, irq_n_isr, pid, EVENT_N) do_other_initialization() } void irq_n_isr(void) { do_low_level_interrupt_service() } void do_low_level_interrupt_service(void) { clear_hardware_flags__etc() } void irq_n_task(void) { for ( ) { ev_recv(EVENT_N, I_WILL_WAIT, FOREVER) do_high_level_interrupt_service() } } void do_high_level_interrupt_service(void) { sem_p(some_sem, I_WILL_WAIT, FOREVER) execute_code_mutual_exclusively() sem_v(some_sem) }
11
void root_task(void) { ULONG pid do_some_initialization() t_create('DEVX', A_HIGH_ENOUGH_PRIORITY, ..., &pid) t_start(pid, ..., dev_x_drv, ...) isr_hook(IRQ_X1, ..., pid, EVENT_X1) isr_hook(IRQ_X2, ..., pid, EVENT_X2) isr_hook(IRQ_X3, ..., pid, EVENT_X3) ... do_other_initialization() } void dev_x_drv(void) { ULONG my_events = EVENT_X1|EVENT_X2|EVENT_X3 for ( ) { ev_recv(my_events, I_WILL_WAIT, FOREVER) if ( is_irq_x1_coming() ) { do_something() } if ( is_irq_x2_coming() ) { do_another_thing() } if ( is_irq_x3_coming() ) { do_a_third_thing() } ... } }
12
Bems
t_suspend
scheduler
Re
SBems
t_resume
t_suspend
13
8. SBm =Suspended and Blocked at Messages 9. SBs =Suspended and Blocked at Semaphores
Bems in the graph is either Be , Bm , or Bs , representing a state in which the process is blocked for some
reason.
Re
! Bems
An executing process becomes blocked when: 1. It attempts to receive via q recv a message from an empry message queue or 2. It attempts to wait via ev recv for an event condition that has not occurred or 3. It attempts to acquire via sem p an semaphore that is not currently available.
Bems
A blocked process P becomes ready when: 1. A message arrives at the message queue where P has been waiting and P is at the head of the waiting queue or 2. An event for which P has been waiting is sent to P or 3. A semaphore for which P has been waiting is released and P is at the head of the waiting queue or 4. P has been waiting with a timeout option for events, a message, or a semaphore and the speci ed timeout interval expires or 5. P has been waiting at a message queue or a semaphore and that queue or semaphore is deleted by some other process.
!R
Other state transitions are quite straight forward. For example, a ready process becomes suspended (R ! S ) when another process invokes a t suspend system call upon it.
14
Chapter 3
pollution. A naming convention is a systematic way of naming symbols. A symbol is the name of a constant, a typedef'ed data type, a function1 , or a variable. The logical region in which a symbol is known is called its scope. A global symbol is known to all modules, while a modular symbol should only be known to programs within the same module. OS/T v3.0-PPC is coded using a hybrid programming style, mixing code written in assembly language as well as in C language. A module may contains two separate source les written in these two di erent programming language. Furthermore, sometimes it is convenient to split a module into several small source les to enhance the readability and the maintainability of code. In either situations, the names of the source les in a module should indicate their belonging to that module, having a common pre x abbreviated from the module name, or located in a subdirectory named after the module. In OS/T v3.0-PPC, all global symbol names begin with a letter `g', while modular symbol names begin with the letter `m'. A local symbol name may begin with an underscore character ` ', or it may have nothing indicating its scope for simplicity. Immediately following the scope indicating letter, the o cial abbreviation of the module is appended, and then the name of the symbol describing its purpose and functionality follows after an underscore character ` '. For a symbolic constant, a name all in upper case is used for other kinds of symbols, the name is in all lower case. The underscore character ` ' works as the separating letter if the name contains two or more words. For a routine name, a verb is usually used at the beginning, followed by an object altogether the `verb-object' form indicates the main operation of the routine. Finally, if the symbol is a typedef'ed data type, a su x ` t' is appended at the end, while a ` i' is appended at the end of the name of an inline function. The length of the name, as a rule of thumb, is usually between 8{20 letters, including the pre x and the su x 17].
16
becomes the most widely used in OS/T v3.0-PPC. The priority queue has 256 levels of priority the number of levels is hard-wired into program code and therefore can not be changed. Furthermore, in order to accelerate search speed, three levels of masks are applied to indicate whether there is any item in a particular range of priorities 2]. Such a p p p p mechanism makes the time complexity of a priority queue O( 4 N + N + N ) = O( N ), in the expense p p of 4 N + N extra memory space. Since the e ciency of the priority queue plays an important role in determining the performance of the scheduling, we feel that such a cost is much more than acceptable. The table is another useful data structure. A table is, basically, a mapping from a nonnegative integer to a pointer that may point to an arbitrary type of object. The object, for example, can represent a process or a timer, and the nonnegative integers is the identi er, or simply the id, of that object. It has constant search and deletion time complexity, but linear insertion time in a rarely happening worst case is unavoidable. All of the queue operations assume the existence of target objects. The operations do not concern themselves with any memory allocation nor release operations the derived classes, if we put it in an object-oriented design nomenclature, should assume the responsibilty for the allocation and release of the actual storage of an object. All of the queue operations do not check the consistency of target objects for e ciency considerations. The deletion routine of the circular doubly-linked list doesn't check whether the object is really an item in such a list it might cause unexpected errors if used carelessly. The operations on priority queues doesn't check whether the object to manipulate indeed has the priority speci ed either. Inconsistency may arise if incorrect priority information is passed into these routines. Insertion into a table may result in an in nite loop if inconsistency occurs inside the target table data structure. More speci cally, if the removal of an entry in a full table does not ll that entry with a proper value as designed, a latter insertion into the table will loop in nitely since no empty entry can be found.
operating
17
exactly one of the three lists, indicating its current usage. In such arrangement, the operating system is capable of managing physically separate memory space, say, in a system with both SRAM and DRAM whose addresses are not contiguous. The rst- t algorithm is applied when allocating new memory blocks 18]. When a memory block is to be released, it is inserted into the free memory block list according to the address of the starting byte in the block, and is merged, if possible, with its neighbour blocks4 . Thus while allocating memory blocks may result in an increase in the total number of memory blocks, releasing blocks may, on the contrary, decrease the total number of blocks.
18
In IBM PowerPC 403GA, the current context of the processor is saved in two special purpose registers, one for machine status register, the MSR and the other for program counter, the PC 16]. There are two kinds of interrupts, namely, critical and non-critical. For a non-critical interrupt, the processor saves PC in SRR0 (save/restore register 0) and MSR in SRR1, while for a critical interrupt, the PC is saved in SRR2 and MSR in SRR3. Then the processor looks up in the vector table, pointed by a special register, the exception vector pre x register, or EVPR for short. Next the address of the correponding interrupt service routine is calculated and branched to, starting the execution of the interrupt service routine. The MSR is modi ed to disable other exceptions which save the context in the same place to prevent nested interrupts from corrupting the context. From here the interrupt handling routines takes over, saving the entire context of currently running process. The stack has been switched to the system stack in the context save routine, so kernel routines that do state-transistion computations can be performed immediately. Finally the scheduler is called, nishing an interrupt processing. The exception handling lies at the heart of the design of a multiprogramming time-sharing environment since the real-time clock interrupts the processor periodically to generate system `ticks,' based upon which the kernel program has to properly switch back and forth from one process to another. Besides real-time clock interrupts, interrupt handling can constitute a signi cant portion of the main task of the kernel program in an embedded system. An e cient and robust interrupt handling mechanism, therefore, is the key to a successful real-time operating system. OS/T v3.0-PPC uses a exible timer abstraction, which enables taking an action periodically or at a speci ed moment in the future. Each tick a clock interrupts the operating system, and a system routine named gclk tick is invoked to check whether there is any timer expiration, and if so, the time-out action routine of that timer is invoked.
system log, the debugger can be used to peek at most of the kernel data structures, as well as memory locations. Timing of system calls can also be measured by issueing a sc command in the debugger. OS/T 3.0-PPC is designed to gracefully halts the execution of the system when a serious error has been detected. When the system encounters internal errors that are not recoverable, the panic routine will be invoked to inform the system programmer of such a situation. Depending on whether a RISC WATCH debugger is attached, panic will dump appropriate debugging information before halting. The gppc m ft]reg , gppc l whb]z and gppc st whb] functions are the C interface for accessing registers as well as main memory. They are restricted for privileged usage. There are I/O routines for the built-in serial port of IBM PowerPC 403GA these routines are primarily designed for kernel to send and receive control information. User applications should develop their own serial port drivers there is an example driver in spdrv.c.
20
There is a 64-Kbytes symbol table in OS/T v3.0-PPC, which is constructed by the stbld6 program using the information in the ELF (Executable and Linkable Format) le 20] generated by the High C compiler and linker 21, 22, 23]. The stbld program reads and parses the map le and writes what is needed by OS/T v3.0-PPC into the ELF le. In addition, the stbld program calculates the beginning and the ending of the OS/T v3.0-PPC image in the memory, according to which the operating system can bypass the occupied memory, collect unused memory blocks, and link these blocks in the free memory block list as described in 3.4 when it initializes the main memory. The stbld program is appended in appendix B.
21
minimum mean std dev. maximum 2.43 s 2.46 s 0.24 s 9.75 s 23.55 s 24.08 s 0.41 s 27.18 s 20.97 s 21.67 s 0.30 s 22.41 s 85.47 s 86.19 s 0.52 s 87.72 s 17.94 s 18.77 s 0.34 s 19.68 s 86.82 s 89.60 s 0.53 s 91.11 s 61.23 s 62.43 s 0.58 s 69.33 s 50.13 s 51.72 s 0.84 s 59.19 s 55.02 s 56.90 s 0.84 s 59.49 s 28.50 s 31.46 s 0.58 s 33.42 s 69.72 s 71.41 s 0.93 s 83.01 s 44.19 s 45.46 s 0.65 s 47.55 s 37.50 s 39.89 s 0.82 s 42.90 s 38.40 s 40.21 s 0.69 s 41.88 s 1601.82 s 1603.26 s 0.83 s 1606.92 s 20.85 s 22.12 s 0.48 s 23.67 s 30.57 s 32.24 s 0.61 s 33.75 s 27.78 s 28.29 s 0.58 s 30.33 s 23.97 s 24.42 s 0.35 s 25.53 s 50.85 s 53.35 s 0.97 s 59.67 s 52.62 s 55.01 s 0.79 s 57.84 s 37.44 s 39.86 s 0.80 s 42.51 s 56.13 s 57.71 s 0.61 s 59.79 s 49.35 s 50.74 s 0.76 s 53.55 s 55.44 s 57.30 s 0.69 s 59.10 s 47.49 s 48.81 s 0.75 s 57.36 s 32.85 s 33.82 s 0.49 s 35.25 s 32.10 s 33.83 s 0.73 s 36.33 s 47.01 s 48.83 s 0.67 s 51.24 s
22
minimum mean std dev. maximum 2.43 s 2.46 s 0.24 s 9.75 s 23.52 s 24.02 s 0.42 s 27.27 s 20.79 s 21.67 s 0.29 s 22.32 s 84.96 s 86.20 s 0.52 s 87.75 s 17.94 s 18.77 s 0.34 s 19.62 s 87.42 s 89.60 s 0.53 s 91.14 s 58.47 s 59.64 s 2.19 s 126.27 s 48.48 s 49.91 s 2.27 s 118.32 s 51.69 s 53.21 s 0.78 s 56.16 s 28.50 s 31.42 s 0.58 s 33.21 s 66.60 s 68.23 s 2.31 s 137.55 s 45.06 s 46.21 s 0.70 s 48.24 s 37.53 s 40.05 s 0.80 s 42.87 s 38.10 s 40.22 s 0.77 s 42.42 s 1600.29 s 1601.89 s 0.82 s 1605.18 s 20.31 s 22.08 s 0.49 s 23.79 s 30.72 s 32.25 s 0.60 s 33.78 s 27.75 s 28.29 s 0.58 s 30.33 s 23.97 s 24.40 s 0.36 s 25.59 s 49.08 s 51.11 s 2.28 s 117.33 s 54.39 s 55.86 s 0.78 s 58.26 s 37.92 s 40.14 s 0.77 s 43.14 s 56.07 s 57.35 s 0.66 s 59.34 s 49.11 s 50.66 s 0.86 s 53.40 s 53.91 s 54.93 s 0.56 s 56.73 s 48.30 s 50.39 s 2.22 s 117.30 s 33.27 s 34.09 s 0.47 s 35.55 s 31.41 s 33.57 s 0.74 s 36.03 s 46.98 s 49.83 s 0.68 s 52.20 s
23
minimum mean std dev. maximum 2.43 s 2.46 s 0.24 s 9.75 s 23.52 s 24.00 s 0.44 s 27.15 s 21.06 s 21.67 s 0.29 s 22.32 s 32.55 s 86.14 s 1.77 s 87.72 s 17.40 s 18.77 s 0.34 s 19.62 s 87.75 s 89.61 s 0.53 s 91.14 s 65.10 s 66.94 s 10.27 s 390.72 s 58.74 s 60.41 s 14.52 s 384.90 s 60.03 s 61.61 s 0.89 s 64.53 s 29.49 s 32.25 s 0.55 s 33.93 s 73.11 s 74.83 s 10.31 s 399.51 s 47.04 s 48.23 s 0.66 s 50.13 s 39.33 s 41.65 s 0.79 s 44.25 s 39.99 s 42.40 s 0.78 s 44.73 s 1600.05 s 1601.69 s 0.78 s 1604.31 s 20.61 s 22.13 s 0.50 s 23.67 s 30.54 s 32.25 s 0.61 s 33.78 s 27.78 s 28.28 s 0.58 s 30.33 s 23.97 s 24.43 s 0.36 s 25.53 s 55.14 s 56.98 s 10.22 s 378.84 s 56.49 s 59.06 s 0.79 s 61.26 s 39.60 s 42.65 s 0.62 s 44.82 s 60.39 s 62.21 s 0.55 s 63.90 s 55.29 s 57.15 s 0.88 s 59.79 s 63.84 s 65.92 s 0.76 s 68.34 s 51.30 s 52.77 s 10.36 s 379.41 s 32.85 s 33.80 s 0.50 s 35.43 s 32.31 s 33.54 s 0.76 s 36.36 s 51.78 s 53.69 s 0.72 s 56.19 s
24
lightly loaded medium loaded heavily loaded 2.46 s 2.46 s 2.46 s 24.08 s 24.02 s 24.00 s 21.67 s 21.67 s 21.67 s 86.19 s 86.20 s 86.14 s 18.77 s 18.77 s 18.77 s 89.60 s 89.60 s 89.61 s 62.43 s 59.64 s 66.94 s 51.72 s 49.91 s 60.41 s 56.90 s 53.21 s 61.61 s 31.46 s 31.42 s 32.25 s 71.41 s 68.23 s 74.83 s 45.46 s 46.21 s 48.23 s 39.89 s 40.05 s 41.65 s 40.21 s 40.22 s 42.40 s 1603.26 s 1601.89 s 1601.69 s 22.12 s 22.08 s 22.13 s 32.24 s 32.25 s 32.25 s 28.29 s 28.29 s 28.28 s 24.42 s 24.40 s 24.43 s 53.35 s 51.11 s 56.98 s 55.01 s 55.86 s 59.06 s 39.86 s 40.14 s 42.65 s 57.71 s 57.35 s 62.21 s 50.74 s 50.66 s 57.15 s 57.30 s 54.93 s 65.92 s 48.81 s 50.39 s 52.77 s 33.82 s 34.09 s 33.80 s 33.83 s 33.57 s 33.54 s 48.83 s 49.83 s 53.69 s
25
Chapter 4
Conclusions
The thesis has proposed an operating system kernel architecture, called OS/T 3.0, for embedded systems. The OS/T 3.0 architecture de nes abstraction of, as well as primitives for, concurrent programming on embedded real-time systems, enabling programming under an elegant and compact model. The architecure de nes multitasking with processes, and primitives for inter-process communication. It also provides primitives for exception handling and suggests an interrupt driven programming style by encapsulating and modeling exceptions as events. In micro kernel concepts, the inter-process communication facilities are the only service a kernel should provide, and it is su cient to build an operating system of full functionality using only interprocess communication primitives. The OS/T 3.0 has, in some sense, a micro-kernel avor in that OS/T 3.0 only provides a set of powerful inter-process communication primitives as well as CPU house-keeping services. However, OS/T 3.0 is not a micro-kerneled operating system since the cost of such exibility is overkill to embedded systems. OS/T v3.0-PPC fully comply with the speci cation of OS/T 3.0 it has deterministic and predictable behavior, is fully preemptive multitasking, and supports both periodic and sporadic tasks. Furthermore, by explitly pointing out the assumptions about the underlying hardware platform, it becomes, at least, easier to tell whether it is possible to port OS/T v3.0-PPC to another platform, and if it is, which part of code should be modi ed. OS/T v3.0-PPC is, in this context, a portable operating system itself. We hope that we can port OS/T v3.0-PPC to similar platforms in the future to con rm that the design goal of the OS/T 3.0 architecture is not only feasible but pro table in that the porting is easy as compared with writing a new operating system.
26
Appendix A
Reference Manual
The application programming interface, or API for short, of OS/T 2.x is adopted after minor modi cations to provide backward compatibility and make easy the design process. Among all, the system call interface may be the most important aspect of the application programming interface. The synopsis of real-time kernel system call is descibed as a reference manual.
NAME
1
The tick eld in TIME is ignored since the tick o set within a second is maintained automatically.
27
SYNOPSIS
ULONG set_time(time) TIME *time void tm_settime(seconds) ULONG seconds /* from 1970/1/1 0:0:0 */
NAME
SYNOPSIS
NAME
SYNOPSIS
tm wkwhen, tm wktime | suspend the calling task until the appointed system's time
ULONG tm_wkwhen(time) TIME *time ULONG tm_wktime(seconds, ticks) ULONG seconds, ticks
NAME
SYNOPSIS
tm evafter | send events to the calling task after the speci ed interval
ULONG tm_evafter(afterticks, events, tmid) ULONG afterticks, events, *tmid
NAME
SYNOPSIS
tm evwhen, tm evtime | send events to the calling task at the appointed system's time
ULONG tm_evwhen(time, events, tmid) TIME *time ULONG events, *tmid ULONG tm_evtime(seconds, ticks, events, tmid) ULONG seconds, ticks, events, *tmid
NAME
SYNOPSIS
28
NAME
SYNOPSIS
NAME
SYNOPSIS
10000
ULONG tm_getload()
NAME
SYNOPSIS
ULONG t_start(pid, mode, entry, arg1, arg2, arg3, arg4) ULONG pid ULONG mode void (*entry)() ULONG arg1, arg2, arg3, arg4
NAME
SYNOPSIS
NAME
SYNOPSIS
void t_exit() /* never return */
NAME
SYNOPSIS
NAME
SYNOPSIS
NAME
SYNOPSIS
NAME
SYNOPSIS NAME
SYNOPSIS
NAME
SYNOPSIS
30
NAME
SYNOPSIS
NAME
SYNOPSIS
NAME
SYNOPSIS
ULONG ULONG ULONG ULONG
NAME
SYNOPSIS
ULONG ULONG ULONG ULONG
NAME
SYNOPSIS
ULONG ULONG ULONG ULONG q_create(name, len_limit, qid) name /* message queue name */ len_limit /* max no. of messages queued */ *qid /* obtain the queue id */
NAME
SYNOPSIS
NAME
SYNOPSIS
NAME
SYNOPSIS
ULONG ULONG ULONG ULONG
NAME
SYNOPSIS
ULONG q_urgent(qid, message) ULONG qid ULONG *message /* up to four long words */
NAME
SYNOPSIS
ULONG ULONG ULONG ULONG ULONG
32
NAME
SYNOPSIS
NAME
SYNOPSIS
ULONG ULONG ULONG ULONG ULONG
NAME
SYNOPSIS
NAME
SYNOPSIS
ULONG ULONG ULONG ULONG
NAME
SYNOPSIS
NAME
SYNOPSIS
33
SYNOPSIS
ULONG isr_hook(vector, pid, events) ULONG vector /* exception vector */ void (*isr)() /* isr entry point */ ULONG pid ULONG events
NAME
SYNOPSIS
NAME
SYNOPSIS
ULONG isr_(vector) ULONG vector /* ULONG *name /* void (**isr)() /* ULONG *pid /* ULONG *events /*
34
Appendix B
STBLD
#include <stdio.h> #define chend(x) ((x)=((x)&0x000000ff)<<24| ((x)&0x0000ff00)<<8|\ ((x)&0x00ff0000)>>8 | ((x)&0xff000000)>>24) typedef unsigned long ULONG /* 57328 is chosen to make sizeof(struct symbol_table_t) = 65536 bytes */ static struct symbol_table_t { ULONG img_start ULONG img_size ULONG img_end ULONG max ULONG addr 1024] ULONG name 1024] char pool 57328] } symtab static struct symbol_entry_t { ULONG number, value, size char bind 256], type 256], sect 256], name 256] } syment static char symtabstr ] = "gerr_symbol_table_storage" int main (int argc, char *argv ]) { char linebuf 4096], tokbuf 64], *elffile ULONG flag, strptr, offset, d_addr, d_off, valtmp, strtmp, *buf int i, bytes FILE *fp symtab.img_start = 0x10000 symtab.img_size = 0 symtab.img_end = 0x10000 symtab.max = 0
35
strptr = flag = offset = d_addr = d_off = 0 while (gets (linebuf) != NULL) { if (flag) { sscanf (linebuf, "%d 0x%x %d %s %s %s %s", &syment.number, &syment.value, &syment.size, syment.bind, syment.type, syment.sect, syment.name) if (syment.size != 0) { if (strcmp (syment.name, symtabstr) == 0) { offset = syment.value } symtab.addr symtab.max] = syment.value symtab.name symtab.max] = strptr symtab.max++ strcpy (&symtab.pool strptr], syment.name) strptr += strlen (syment.name) + 1 } } else if (sscanf (linebuf, " Section #%*d: %s %*s addr=0x%X, off=0x%X", tokbuf, &valtmp, &strtmp) > 0) { tokbuf 63] = (char) 0 if (strcmp (tokbuf, ".data,") == 0) { d_addr = valtmp d_off = strtmp } if (valtmp > symtab.img_end) { gets (linebuf) if (sscanf (linebuf, " size=%d", &strtmp)) { if (strtmp != 0) { symtab.img_end = valtmp + strtmp } } } } else if (strncmp (linebuf, " { ++flag } } symtab.img_size = symtab.img_end - symtab.img_start -----", 10) == 0)
36
fprintf (stdout, "%d bytes used for %d symbols.\n", strptr, symtab.max) fprintf (stdout, "binary image: addr=0x%X, size=%d(0x%X)\n", symtab.img_start, symtab.img_size, symtab.img_size) do { flag = 0 for (i = 1 i < symtab.max ++i) { if (symtab.addr i - 1] > symtab.addr i]) { valtmp = symtab.addr i - 1] strtmp = symtab.name i - 1] symtab.addr i - 1] = symtab.addr i] symtab.name i - 1] = symtab.name i] symtab.addr i] = valtmp symtab.name i] = strtmp ++flag } } } while (flag) for (i = 0 i < symtab.max { chend (symtab.addr i]) chend (symtab.name i]) } chend chend chend chend (symtab.max) (symtab.img_end) (symtab.img_size) (symtab.img_start) ++i)
/* bubble sort */
if (offset == 0) { fprintf (stderr, "%s: can't find %s in elf file.\n", argv 0], symtabstr) exit (1) } else if (d_addr == 0 || d_off == 0) { fprintf (stderr, "%s: can't find data section in elf file.\n", argv 0]) exit (1) } if (argc < 2) { elffile = "OST" } else
37
{ elffile = argv 1] } if ((fp = fopen (elffile, "r+b")) == (FILE *) 0) { fprintf (stderr, "%s: can't open elf file %s.\n", argv 0], elffile) exit (1) } offset = offset - d_addr + d_off fseek (fp, offset, SEEK_SET) bytes = fwrite ((void *) &symtab, sizeof (char), sizeof (symtab), fp) fclose (fp) fprintf (stdout, "%d bytes written to %s, offset = 0x%08X.\n", bytes, elffile, offset) exit (0) }
38
Bibliography
1] John Sinclair, editor. Collins Cobuild English Dictionary. HarperCollins, 1995. 2] Ching-He Lin. A real-time kernel: Design and implementation. Master's thesis, National Taiwan University, Jun 1994. 3] I-Chun Chuang. A portable real-time operating system kernel: Design and implementation. Master's thesis, National Taiwan University, Jun 1996. 4] Jean J. Labrosse. C/OS: The Real-Time Kernel. R & D, 1992. 5] Integrated Systems, Inc. pSOSystem System Concepts, Nov 1996. 6] Integrated Systems, Inc. pSOS+/68K User's Manual, Sep 1992. 7] Michael Barabanov. A linux-based real-time operating system. Master's thesis, New Mexico Institute of Mining and Technology, Jun 1997. 8] Douglas Comer. Operating System Design, the Xinu Approach. Prentice-Hall, 1984. 9] Abraham Silberschatz and Peter B. Galvin. Operating System Concepts. Addison-Wesley, fourth edition, 1995. 10] Andrew S. Tanenbaum and Albert S. Woodhull. Operating Systems: Design and Implementation. Prentice-Hall, second edition, 1997. 11] James R. Pinkert and Larry L. Wear. Operating Systems. Prentice-Hall, 1989. 12] Jerry Young. Insider's Guide to PowerPC Computing. Que, 199? 13] Gary Kacmarcik. Optimizing PowerPC Code. Addison Wesley, Apr 1995. 14] Tom Shanley. PowerPC System Architecture. Addison Wesley, Feb 1995. 15] Kip McClanahan. PowerPC Programming for Intel Programmers. IDG, Jun 1995. 16] IBM Corporation. IBM PowerPC 403GA User's Manual, Mar 1995. 17] Steve C. McConnell. Code Complete: a Practical Handbook of Software Construction. Microsoft Press, 1993. 39
18] Donald E. Knuth. Fundamental Algorithms, volume 1 of The Art of Computer Programming. Addison-Wesley, 1968. 19] Bjarne Stroustrup. The C++ Programming Language. Addison-Wesley, second edition, June 1994. 20] Tool interface standard (tis) portable formats speci cation, Oct 1993. 21] IBM Corporation. High C/C++TM Programmer's Guide, rst edition, Aug 1995. 22] IBM Corporation. ELF Linker User's Guide, second edition, Nov 1995. 23] IBM Corporation. ELF Assembler User's Guide, rst edition, Aug 1995.
A 24] Leslie Lamport. L TEX: A Document Preparation System. Addison-Wesley, second edition, 1994. A 25] Michel Goossens, Frank Mittelbach, and Alexander Samarin. The L TEXCompanion. AddisonWesley, 1994. A 26] Helmut Kopka and Patrick W. Daly. A Guide to L TEX: Document Preparation for Beginners and Advanced Users. Addison-Wesley, 1992.
27] Brian W. Kernighan and Dennis M. Rithie. The C Programming Language. Prentice-Hall, second edition, 1988. 28] Leland L. Beck. System Software: An Introduction to Systems Programming. Addison-Wesley, second edition, Mar 1990. 29] Richard A. Burgess. Developing Your Own 32-Bit Operating System. Sams, 1995. 30] IBM Corporation. RISCWatch 400 Debugger User's Guide, fth edition, Oct 1995.
40