proposalPlanningDiaryDownloadsLinks

Wednesday 24th.3.2004

(PLAN 1) Interrupt Service Routine or Interrupt Handler (Source: comp.realtime newsgroup)

As I read many articles related to Interrupt handling, I came across so many different definitions on Interrupt Latency, Interrupt Service Routine, and Interrupt handler. So I posted the following messages to the realtime newsgroup.

Date: Mon, 22 Mar 2004 20:07:30 +1200
From: Sang Hyeb Lee 
Newsgroups: comp.realtime
Subject: Interrupt Latency.

Hello.

I'm quite confused about what exactly Interrupt Latency means.
Is it the amount of time that elapses between the physical interrupt
signal being asserted and the interrupt service routine running OR the
amount of time that elaspes between the physical interrupt and the
device driver's interrupt handler?
                                                                       
thanks,
sam

After a while, I got the following answer from the newsgroup.

Date: Mon, 22 Mar 2004 11:11:27 +0100
From: Juergen_Sievers 
Reply-To: never.answer.me@go.away.de
Newsgroups: comp.realtime
Subject: Re: Interrupt Latency.

Hi sam                                                                         

A) Interrupt latency time:
   The time from physically event to the first instruction of the ISP.
                                                                              
B) Scheduling latency time:
   The time from the last instruction of the ISP to the first instruction of
the interrupted process.

C) Context Switch time:
   The time from the last instuctuin of the leaving user process to the
first instruction of the following user process.
                                                                               
Hope it's helpfully and Regards
j.

Aha! So the definition of interrupt latency in [WILLIAMS 2002] was right. The interrupt latency is the amount of time from physical interrupt to the starts of the Interrupt Service Procedure/Routine. However, the definition of scheduling latency time here differs from the one from [WILLIAMS 2002]. In [WILLIAMs 2002], the scheduling latency time is defined as the amount of time that elapses between the interrupt service routine complting and the scheduling function being run.And the scheduling duration is the amount of time that elapses inside the scheduler proper to decide what thread to run and context switch to it. So the definition given in this reply actually refers to both scheduler latency and scheduler duration.

I posted another messages, shown below.

Date: Tue, 23 Mar 2004 11:21:13 +1200
From: Sang Hyeb Lee 
Newsgroups: comp.realtime
Subject: Re: Interrupt Latency.

Hi, Juergen.
                                                                              
Thank you very much for your help. ;) ;)
                                                                               
I've got a couple more questions on basic terminologies.
                                                                              
(1) What does ISP stands for? Does it stand for Interrupt Service Routine?
Shouldn't it be ISR?
                                                                               
(2) What is different between an interrupt service routine and a device
driver's interrupt handler? Does ISP refers to both interrupt service
routine and a device driver's interrupt handler?
                                                                              
Thanks! ;)
                                                                               
Regards,
Sam

Here is the reply

Date: Tue, 23 Mar 2004 13:19:57 +0100
From: Juergen_Sievers 
Reply-To: never.answer.me@go.away.de
Newsgroups: comp.realtime
Subject: Re: Interrupt Latency.

On most new CPUs the Intterupt Service Routine (ISP) runs in a complet
different context. So Interrup Service Process/Procedure (ISP) may
subscribele the situation a littel bit better :)
                                                                               
Interupt Service Rotines reflecting only on an external events. (Excepting:
some/most CPUs have the capabillity to emit software Interrupt to generat
such "!!extern!!" event by software). Such events (Extern and Software
emitted) has well defined priorities!!!.
                                                                       
Some drivers have its own thread or process, controlled by intterupt events
and/or User requests. Those Drivers processes are not interrupt service
processes. Onliy the ISP who takes the external event and signaled the
Drivers Processes are an ISPs.
                                                                       
For example a simple clock driver.
The events from the external clock hardware occures every second and would
be processed from an ISP. Simple he counts up the events and signales the
following processes.
The driver\'s Process is mostly waiting for a semaphore. Remember this
semaphore will be unblocked be the ISP each secound. Then the driver\'s
workerthread may calculete the right time in reflection on the current time
zone eg.

                                      
Die einfachen Kostenz%Gï¿¿%@hlerdurchl%Gï¿¿%@ufe als ISP.
Es dauert allways diegleiche
sehr kurze Zeit und entblockt jedes secound das Semaphor.

                                      
The driver\'s process takes the ISP\'s signal to read the counter and
calculates the right time in reflection on what Day, Month, Jahr,Schaltjahr
eg.

                                      
Why?
a: The ISP takes always the same short time on each event and it's system
load could be calculate.

b: The driver's process has at least one secound to calculate the right
system time. Most it has only to increment the secount part, some times he
has to find out if the 3/29/200X exist or not.

                                      
Sorry about my bad english, but my native language is C and C++ :)
                                                                               
j.

Aha! So on modern CPU, Interrupt service routine runs in a completely different context, so it can be called Interrupt Service Process instead of Procedure/Routine! And I got another useful reply

Date: Tue, 23 Mar 2004 06:44:54 -0700
From: Ed Skinner 
Newsgroups: comp.realtime
Subject: Re: Interrupt Latency.

Again, Juergen's descriptions are very good.
Here is a little more information that may be helpful.
                                                                       
In some architectures, the processor and the I/O device have a brief
conversation when an interrupt is just beginning. The device tells the CPU
it's "vector number" (which was programmed into the device earlier,
probably by the device's software driver). The processor then uses that
number to calculate an execution address (typically using another
processor register called the Vector Base Register) to go "directly" to
the Interrupt Service Routine (ISR).
                                                                        
In other architectures, the initial determination of which device is
causing the interrupt and, therefore, which ISR to use must be handled in
the software (because the hardware is simpler). In these systems, when an
interrupt is just beginning, the processor jumps to a specific memory
location and begins executing whatever code happens to be there. The
operating system puts its own interrupt handler in that specific memory
location so it (the OS) will get control when an interrupt occurs. That
software must figure out which device is causing the interrupt. This is
usually done by interrogating a device called a Programmable Interrupt
Controller, or PIC. The OS's ISR asks the PIC, "Who did it?" and the PIC
gives back some identification. The OS's ISR then uses that value to
figure out which device-specific-ISR to execute (usually by means of some
lookup table). The OS "calls" the device-specific-ISR to continue the
processing.
                                                                      
In this second approach, "ISR" is confusing because some of the processing
is done in the OS (the initial part where the interrupt source is
determined) and some is in what I think of as the device-specific software
(or "device driver").
                                                                        
For that reason, some extra terms may be helpful. The AIX operating system
(a Unix variant from IBM) refers to First-Level Interrupt Handling (FLIH)
and Second Level Interrupt Handling (SLIH) for these two levels. Note that
there is one FLIH (in the Operating System itself) and probably many SLIHs
(one for each device).
                                                                          

In both kinds of architectures, the Operating system may offer some after-
the-interrupt processing service to the device driver. The intention is to
allow the device driver's ISR (SLIH) to "defer" some of the processing it
might need to do to a later time (but not much later). The goal is to
get-in and then get-out of the ISR as quickly as possible to reduce
interrupt latency (for other devices). In operating systems that offer
this capability, the deferred software typically executes after all
interrupts have been processed, and before the OS continues the execution
of any normal program.
                                                                          
This deferred capability goes by any of several names. AIX calls it an
Off-Level Interrupt Handler (OLIH). Linux calls it a Bottom Half, a
Tasklet or a Soft IRQ which are (subtle but important) variations on the
same idea. Some OSs refer to these as Callbacks but that terms has other
meanings also in common use so you'll need to be cautious when someone
talks about them to figure out exactly what they are referring to. And,
finally, some variants of Windows have a similar capability -- I think
they call it a Deferred Procedure Call but I could be mistaken.
                                                              
Hope this helps!

The second approach is used in MINIX,too!!

(PLAN 2) Process model in MINIX (Chapter 2 of OSDI)

I've decided to re-read the whole MINIX textbook to understand better. Today, I read the chapter 2 which explains process management. A process is an executing program including the current value of program counter(instruction pointer), registers, and variables. At any instant of time, CPU is actually running one process at a time, switching between different processes in memory. In Minix, there is a init process at the top of process hierarchies, these process forks off onw new process per terminal. When someone logs in, the login process executes a shell to accept commands. These commands may start up more process, and so forth. Thus, all the processes in the whole system belong to a SINGLE tree, with INIT at the root. At any instant of time, a process can be in one of the following states: Running, Ready, and Blocked. When a process is in Running state, it is actually using the cpu at that instant. When a process is in Ready state, it is able to run but temporarily stopped to let another process run. When a process is in Blocked state, it is unable to run until some external event happens, such as I/O blocking.To implement the process model, the operating system maintains a table, called the process table, with one entry per process. This entry contains information contains information about process' state, its program counter(instruction pointer), stack pointer, memory allocation, the status of its open files, its accounting and scheduling information, and everything else about the process that must be saved when the process is switched from running to ready state so that it can be restarted later as if it had never been stopped. In MINIX, the process entry is ditributed among Process management, Memory management, and File management which holding only the relevent informations to itself. In modern operating system, each process can have multiple threads of control within the process. These threads of control are usually called, threads or lightweight processes. The context switching between threads is much faster because only small portions needs to be changed. In some systems, operating system is not aware of the threads, so the thread management is done in user-space. This approach faster but it has a serious drawback: when one thread blocks, the kernel blocks the entire process, since it is not even aware that other threads exist. In other systems in which OS is aware of the existence of multiple threads per process, the OS chooses the next one to run, either from the same processes or a different one. Threads is quite useful when multiple processes need to share common data. However, it has many disadvantages. Race condition refers to the situation where the result of the computation depends on the order of process scheduling. Suppose that we have a spoole rdirectory which has a number of slots and two shared variables, out which points to the nnext file to be printed, and in, which points to the next free slot in the directory. At a certain instance, slot 7 and 8 are empty. a Process A reads the variable in (which points to the next free slot, 7) and and store the value, 8, a local variable called next_free_slot. At this very moment, a clock interrupt occurs and the CPU decides that process A has run long enough, so it switches to process B. Process B reads ..(TO BE CONTINUED)

(PLAN 3) Bits, flags, braches, tables (Source: Chapter 10 of Assembly Language SBS)

Monday 22nd.3.2004

(PLAN 1) Preemptible patch Linux kernel (Source: MORGAN, KEVIN: Preemptible Linux: a Reality Check, MontaVista Software)

There are many characteristics of Linux which makes it unsuitible for Real-time OS. Among them, the two biggest causes for Linux kernel's high response time are the high interrupt latency and high scheduling latency. The interrupt latency is the amount of time that elapses between the physical interrupt signal being asserted and the interrupt service routine running (definition from WILLIAMS, CLARK: Which is better -- the preempt patch, or the low-latency patch? Both!). High interrupt latency resulted from disabling interrupts frequently. The scheduling latency is the amount of time that elapses between the interrupt handler completing and the scheduling function being run. There are some parts of real-time software, such as real-time control software written in Java, which can not be implemented in driver-level software. These program has to be written in user-space. Therefore, the kernel needs to be able to preempt process and switch to a higher priority (newly awoken) very quickly. Originally, Linux kernel itself was non-preemptible. There is now a kernel-preemption patch which speeds up response time by making kernel pre-emptible. To make kernel pre-emptible, they have done the following four things.

  • Modify the definition of a spinlock chaning it from its symmetric multiprocessing (SMP) specific implementation to a preemption lock. Preemption Lock can be used as a control on re-entracy to a critical section of kernel software
  • Modify the interrupt haandling software to allow rescheduling on return from interrupt if a higher priority process has become executble, even if the interrupted process was runnign in kernel mode (provided the procvess is not in critical preemption locked state). Namely, provide a scheduling point after interrupt handler returns
  • Spin unlocks are redefined to return the system to a pre-emptible state, and check if an immediate context switch is needed. Namely, provide a scheduling point after each spin unlock.
  • Modify the kernel build definition for a uniprocess target system to include the spinlocks (implemented as pre-emption locks)
  • Pre-emptible kernel reduces the throughput a bit but does not introduce any cimplexity in the kernel because it is using already required and in place SMP locking. This article tells that pre-emptible kernel patch will included in the Linux source code with starting with the kernel 2.5 kernel base. In fact, this pre-emptible patch is now part of offical linux kernel 2.6

    (PLAN 2) Comparison between two approaches reducing scheduler latency (Source: WILLIAMS, CLARK: Which is better -- the preempt patch, or the low-latency patch? Both!, March 2002)

    There are two approaches to making Linux kernel more responsive by reducing the scheduler latency. These are the preemption patch (by MontaVista Software) and the low-latency patch (by Ingo Molnar). In this article, these two methods are briefly explained and they tested the performance of each method on x86 machine. The results shows that low-latency patch performs slightly better than preemption patch. However, the hybrid method of these two technique performs best. This article gives an example of hardware interrupt handling. It can be summarized as bellows.

  • A thread issues an I/O requests via a kernel system call
  • Device driver receives the requests and checks if it can satisfy the requests for data. If not, it puts the thread on a wait queue and sends a I/O requests to the device.
  • After the device completed its work. It sends an physical interrupt to CPU.
  • Interrupt service routine gets running. It runs the device drivers' interrupt handler.
  • This interrupt handler extracts the data and make the thread runnable
  • Flag is set to request for rescheduling
  • When the kernel gets to a point where scheduling is allowed, it will note that need-resched is set and will call the function, which will determine what thread should run next.
  • If the thread has a good enough goodness value, the kernel will context switch to it and the thread will run and receives data.
  • The amount of time that elaspes from when the interrupt is asserted to when the thread that issued the I/O request runs, is what we call kernel response time. There are many components which make up the kernel's reponse time to an event. These are (1) interrupt latency, (2) Interrupt handler duration, (3) Scheduler latency, and (4) Scheduling duration. The interrupt latency is the amount of time that elapses between the physical interrupt signal being assserted and the interrupt service routine running. The second componenent interrupt handler duration, is the amount of time spent in the routine that actually handles interrupt. Interrupt handler is the routine that sets the flag which is used to signify that a scheduling pass is needed. The scheduler latency is the amount of time that elapses between the interrupt handler complting and the scheduling function being run. The scheduler duration is the amount of the time that elapses inside the scheduler proper to decide what thread to run and context switch to it. Since interrupt latency, interrupt duration, scheduling duration has a very low duration compared to scheduler latency, the recent research focuses on reducing the scheduler latency. There are many causes to high scheduler latency. One of the biggest cuaes is the kernel which styas in a block of code for a long period of time, without expliicitly introducing scheduling opportunities. So How does we reduce scheduler latency? Well, the simplest answer would be performing re-scheduling more often. However, we might end up spending most cpu cycles on scheduling which thread to run without actually getting works done. The actual answer is to run the scheduler as soon as possible after an event (such as interrupt) indicates the need for a scheduler pass. Most Real Time Operating System have pre-emptible kernel and they also prioritize device interrupts so that important interrupts gets serviced quickly. There are two major patches to Linux to reduce its scheduler latency: Preemption patches and low-latency patches. *PREEMPTION PATCHES* The basic idea behind the preemption patches is to introduce more scheduling points to minimize the time between the occurrence of an event and the running of the schedule() code. It is done by modifying the spinlock macros and the interrupt return code so that if it is safe to preempt the current process and a rescheduling request is pending, the scheduler is called. Originally, when a current process is running in kernel-mode, it was impossible to pre-empt the current process does not matter if it is running in a critical section or not. This assumption allowed the kernel to modift kernel data structure without requiring mutual exclusion primitives be used to protect the modification. In pre-emption patch, each time a spinlock is released or an interrupt routine returns there is an opportunity to reschedule. *LATENCY PATCHES* This patch was introduced by Ingo Molnar and is not maintained by Ingo Morton. Rather than attempting a brute-force approach in a kernel, such as preemption patch, this patch focus on introducing explicit preemption points in blocks of code that may execute for long stretches time. The basic idea is to find places that iterate over large data structures and figure out how to safely introduce a call on the scheduler if the loop has gone over a certain threshold and a scheduleing pass is needed. The concept beind low-latency is simple but it is quite hard to implement. Given the dynamic nature of the state of the Linux kernel, the job of finding and fixing high-latency points in kernel code could be a full-time job. For more details on Low-latency code, visit Andrew Morton's website. They have measured the performnace of each patches and found out the low-latency patch outperforms the preemption patch. However, the hybrid method of these two techniques performs the best. Preemption patch is now part of official linux kernel from kernel 2.6.

    (PLAN 3) Design of File System in MINIX (Source: Chapter 5 of OSDI)

    (PLAN 4) Macros and external modules (Source: Assembly Language SBS)

    Saturday 20th.3.2004

    (PLAN 1) Accessing BIOS (SOURCE: Assembly language)

    (PLAN 2) Overview of File system in general (Source: Minix OS book)

    All computer needs to retrive and store information. When a process is running, it can store information in its address space. However, the storage capacity is restired to the size of the virtual address space. And also, when the process is terminated, the information is lost. And the last problem is that some processes needs to share some information at the same time. These problems can be solved by using a larget secondary storage such as hard disk. On this storage, informations are stored in units called files. Files are an abstract mechanism which provides a way to stor information on the disk and read it back. There are many ways files can be structued. The most common approach is an unstructured sequences of bytes. This approach is taken by UNI and MS-DOS. This approach provides a maximum flexibility. The other approach is to have a sequence of fiexed-length records, each with some internal structure. In this model, all read and write operations are based on one record. This approach was used in old OSs where each record was a image of 80-colum punched card. In the last approach, a flie consists of a tree of records, not necessarily all the same length, each containing a key field in a fixed position in record. The tree is sotred on the eky field, to allow rapid searching for a particular key. This scheme is widely used on the large mainfrrame computers still used in some commercial data processing. In MS-DOS and UNIX, there are regular files and directories files. Regular files contains user information whereas directory files are system files used for maintaing the structure of the file system. In Unix, there are also character special files and block special files. Character special files are related to input/output and used to model serial I/O devices. Block special files are used to model disks. Regular files are generally ASCII files and binary files. ASCII files are text files which contains human-readable informations. Binary files means that they are not ASCII files. In old days, OS provides two different kind of files access: sequential access and random access. In seqneutial access, all the data in the files are accessed in order. In random access, any part of file can be accssed directly without accessing the data beside it. Mordern operating system only provides random access. There are many attributes associated with each files. These are protection, password, creator, owner and etc. There are many operations which can be done on a files such as create, delete and open. Directory file is a system file which is used to maintain file system structure. The contents of directory file differs from OS os OS. However, on most of OS, it contains the lists of file names and its disk address. There are many ways files can be stored on disks. The simplest and easiest way is to store each file as a contiguous block of data on the disk. This approach is simple to implement and the performance is excellent because the entire file can be read from the disk in a single operation. However, this approach is not feasible unless the maximum file size is known at the time the file is created and the external fragmentation of the disk can results. The second method is to keep each one as a linked list of disk blocks. This method prevent any spaces to be lost to external disk fragmentation (However, internal fragmentation still occurs in the last block because even the small data occupies the entire block) and directory entry only needs to store the address of the first block. The disadvantages of this method is random access is extremely slow because to access a particular part in the file, we always needs to follow the linked list from the beginning of the file. And also, the amount of disk storage in a block in no longer power of two because the pointer always takes up pa few bytes. The third method is associating a memory-resident table which conatins the pointer word from each block. Using this approach, the entire block is available for data and random access is much easier. Although the chain must still be followed to find a given offset within the file, the chain is entirely in memory, so it can be followed without making any disk referneces. However, the entire table must be in memory all the time. This approach is used in MS-DOS. The last method is associating each file with a table called i-node, which lists the attirbutes and disk address of the file's blocks. This approach is used in UNIX. As said earily, the contents of directory files differ from OS to OS. In MS-DOS. directory files contains many attributes in the directory entires like file name, extension, attributes, time, date, first block size and size of file in bytes. In UNIX, each entry contains just a file name and it's i-node number. All the formation in the i-node. We need to be carefully when choosing the block size. If we use a large allocation unit, every file, event 1-byte file, ties up an entire cylinder. On the other hand, using a small allocation unit means that each file consists of many blocks. Reading each block normally requires a seek and a rotation dealy, so reading file consisting of many small blocks will be slow. So when choosing the optimum block size, we need to take into the account the average file size. So how OS keeps trakc of free blocks? There are two general methods: using a linked lists of disk blocks and a bit map. In linked lists method, each disk block contains the address of free disk blocks. So when there is a large number of free disk blocks, the linked lists will be very large. In bit-map method, a disk with n blocks requires a bit map with n bits. Free blocks are represented by 1s in the map, allocated blocks by 0s. If there is enough main memory to hold the bit map, that method is generally preferable. The rest of the chapter explains about file system consistency, security and virus. Since these issues are not relevant to my thesis topic, I just skimmed through it.

    Friday 19th.3.2004

    (PLAN 1) MINIX newsgroup (comp.os.minix)

    I was in doubt if MM (Memory Manager) and FS (File System) were non-preemptive in Minix. So I've posted the following message to Minix newgroup.
          Date: Thu, 18 Mar 2004 09:42:09 +1300
          From: Sang Hyeb Lee 
          Newsgroups: comp.os.minix
          Subject: Are FS and MM non-preemtable in Minix?
                                 
          Hi guys.
                                                                                   
          Are FS and MM non-preemtable in Minix?
                                                                                   
          Thanks,
          Sam
          

    I was not clear of the meaning for preemtability. I thought that if something is non-preemtable, the interrupts are disabled so it can not be stopped. However, I was wrong. The preemtability means that if something is preemtable, there is no re-scheduling so it continues execution even after the hardware interrupt occurs.

          
                                                                                    
    Date: 18 Mar 2004 09:24:34 -0800
    From: Luiz Capitulino 
    Newsgroups: comp.os.minix
    Subject: Re: Are FS and MM non-preemtable in Minix?
                                                                                    
    Hi Sang,
                                                                                    
    Sang Hyeb Lee  wrote in message
    news:...
                                                                                    
    > Are FS and MM non-preemtable in Minix?
                                                                                    
     It is not preemtable like the users process (which have the a quantum
    time to execute), when FS or MM is executing, the kernel will not stop
    then to execute another process.
                                                                                    
     There are only one exception: when a interrupt ocurrs.
                                                                                    
    -- Luiz Fernando N. Capitulino
    
    Hello Luiz.
                                                                                    
    Thanks for your reply.
                                                                                    
    I've got another question on non-preemtability of kernel in Minix.
                                                                                    
    so if the hardware interrupt happens when MM is running, the
    interrupt-service routine does some house-keeping for the actual
    process which handles interrupt, and after that MM runs again. (No
     Context Switching)
                                                                                    
    So MM is non-preemtable. Is it right?
                                                                                    
    Thank you very much for your help.
    

    Now I'm quite clear what the pre-emtability means and what is pre-emtable in Minix. I also got the following reply from Kees J Bot.

    That may send an interrupt message to a task, and tasks preempt servers
    like MM and FS.  Tasks cannot preempt each other, so a tasks only needs
    to worry about the code in interrupt handlers modifying something
    unexpectedly.  With lock() and unlock() one can keep such handlers away.
    

    Aha! so when an interrupt handler sends an interrupt message to a task, the task may be scheduled to run so task preempt servers. (I remember there are 3 queues used for scheduling: task queue, server queue, user-process queue. And scheduler always pick the process out of the highest non-empty queue). However, tasks cannot preempt each other, so tasks only needs to worry about the code in interrupt handlers which modifies something unexpectedly. It can be solved by disabling interrupts using lock() and unlock()

     
    *Summary* 
    (1) MM and FS are preemtable in Minix (but not ilke user process which gets 
        interrupted by timer at fixed interval)
    (2) When an interrupt occurs, a task for which handles that interrupt might be 
        re-scheduled to run so task preempt servers.
    (3) Tasks can not preempt each other. So tasks only needs to worry about the 
        code in interrupt handler which modifies something unexpectedly. This 
        problem can be solved by disabling interrupts using lock and unlock() 
        which call cli() and sti() respectively!
    

    (PLAN 2) software interrupt in DOS (SOURCE: Assembly Language SBS)

    The software is a interrupt which does not interrupt anything! ;) This sounds a bit odd. The nature of software can be best explained by an example. DOS contains a little sequences of machine instructions tucked away within itse.f Each sequence does something useful (e.g. display a line of character to the screen, print something). These sequences are used inside DOS and also these sequences are available for the programmer as well. Since DOS is evolving, we can not just remember the absolute address of each sequences, So what they have done is to have a special table (Interrupt Vector Table) at the very start of real mode memory. Each entry (Interrupt Vector) contains an address. None of address is burned into permanenet memory the way BIOS routines are. When the machine starts up, DOS and BIOS fill many slots in the interrupt vector table with addresses of certain service routines with themselves. The x86 CPUs include a machine instruction that makes use of the interrupt vector table. The INT (INTerrupt) instruction causes a software interrupt. For example, when an INT 21H instruction is executed, the CPU goes down to the interrupt vector table, fetches the address from slot 21H, and then jumps execution to the address stored in slot 21H. So how does the interrupt service routine know where to resume the execution of the process? It simply pushes the address of the next instruction on the stack before it jumps to the address in the interrupt vector. Software interrupts can be thought as ways to request services to the kernel. Whereas hardware interrupts can be thought as CPU's mechnism for paying attention to the world outside itself. The only difference between hardware and software interrupts is in the event that triggers the trip through the interrupt vector table. With a software interrupt the triggering event is part of the software; INT instruction. With a hardware interrupt, the triggering event is an electrical signal applied to the CPU chip itself without any INT instruction taking a hand in the process.

    Thursday 18th.3.2004

    (PLAN 1) Memory Management in Minix (Chapter 4 of Minix OS Book)

    I read a chapter 4 of Minix OS book, which explains about memory management in general and minix's memory management.

    (*) Memory management in general.

    There are many memory managament model. The simplest one of all is monoprogramming in which only one program can run at a time. In this model, OS starts up one program, let it do its work and remove it when it is finished. There other model is multiprogramming with fixed partitions. In this model, the memory is divided into a number of fixed partitions. Each program can occupy one partition. So many different program can resides in the memory at the same time. Having multiple programs in a memory at a time introduces two problems: relocation and protection. When a program is linkxed, the linker must know at what address the program will begin in memory because there might be a call to a procedure at some absolute address. Because program can be allocated to a number of different locations, this can cause a bit of problem. One possible solution is to perform relocation when program gets loaded into the memory. Protection can be solved by using special hardware registers, the base and limit registeres. When a process is scheduled, the base register is loaded with the address of the start of its partition, and the limit register is loaded with the lngth of the partition. Every memory address generated automatically has the base register contents added to it. Address are also checked against the limit register to make sure that they do not attempt to address memory outside the current partiiton. There might be an unsufficient amount of memory to hold all the currently active processes. There are two general approaches to this problem. These swapping and virtual memory. Swapping is just swapping an entire process out of a memory and put it onto a disk when there is not enough room for another process to run. Virtual memory allows programs to run even when they are only partially in main memory. When memory is assigned dynamically, the os needs to keep track of which part of memory is being used or free. This can be done in a various ways. Two famous approces are using bit map and linked lists. With a bit map, the main memory is divided into allocation units. Corresponding to each allocation unit is a bit in the bit map, which is 0 if the unit is free and 1 if it is occupied. With a linked lists, we have a linked lists of free memory. Each entity has the starting address of free memory, its length. Using virtual memory, we can even run a process which is too large to fit into physical memory. There is a special hardware which handles this method. It is MMU (Memory Management Unit) Virtual memory is divided into small unit called page. Physical memory is divided into small unit called page frame. The pages and page frames are always exactly same size. When a program access a particular page, the page table is referenced to find out the actual page frame in the physical memory. If the page is not unmapped (there is no corresponding page frame loaded into the main memory), the page fault occurs and causes CPU to trap to the operating system. The OS picks a litee-used page frame and writes its contents back to the disk. It then fetches the page just referenced into the page frame just freed, changes the page table and restarts the trapped instruction. a special hardware called TLB can be used to speed up this page table look-up process. Since Minix does not use paging, I wouldn't go into details of how paging works.

    (*) Memory managament in Minix

    The memory managament model used in Minix is very simple. There is no paging nor swapping. Minix maintains a list of freeed memory address using a linked lists. All the memory management is handled in Memory Manager (This is only an illution to the user program. Most of the work is done in the system task inside the kernel. I will explain this later). It is a separate program from the kernel. It is combined with kernel, file system to form a Minix image. The decisions about which process will be placed where in memory are made by the memory manager. However, the actual works of memory maps for process is done by the system task within the kernel. In minix, a process can choose to use combined I and D space or seprated I and D space. In minix, a process is allocated a fixed amount of memory and stays in the same place until it terminates.

    (PLAN 2) Study basic Intel x86 Instruction sets

    (PLAN 3) Modifying and recompiling nel source code

    I modified and recompiled Minix kernel to get familiar with Minix. src/tty.c was modified to print a memory to the terminal when the system starts up. src/keyboard.c was modified to disable the terminal switch. src/mm/getset.c was modified to print out a message whenever getset method was called. After making the above changes to the source code, I recompiled the kernel by executing the /usr/src/tools/make. This script compiled all the modified source code and made a Minix image by combining fs, mm and kernel. (installboot -image mm image fs). After recompiling the kernel, I copied the new image to the /minix directory, where boot monitor looks for the minix image to boot. I also carefully examined monitor manual page to examine how boot monitor works. Finally everything in Minix starts making sense to me!
    Monday 15th.3.2004

    (PLAN 1) playing with MS-DOS and Bochs

    I spent most of the afternoon installing bochs (Intel x86 emulator) and installing ms-dos 6.22 on bochs. And also, I examined the configuration file for bochs. I am planning to run & test minix and other operating system on bochs. The bochs configuration file was quite easy to set up. To set up a x86 system running MS-DOS, i first created a 30MB hard disk image using bxshare program. I then wrote a configuration file for a system with 32 memory with a 30MB hard disk, one 1_44 floppy disk, a rom bios, and a elpin video rom. I then started up my new system with a ms-dos installation disk image in a floppy disk drive and installed ms-dos 6.22 onto my system! I will be working on ms-dos 6.22 to learn Intel x86 assembly language.

    (PLAN 2) chapter 5 (Memory architecture in Intel x86 system) of Assembly language book

    I read about how memories are organized in Intel x86 system. There are 3 major different ways in which memory is organized. These are real mode flat model, real mode segmented model, and protected mode flat model. Some OS concepts, which did not make sense before, are getting clearer as I learn assembly language.

    (PLAN 3) Real-time and embedded system guide by Herman bruyninckx

    This article provides a general overview on real-time and embedded system. At the moment, I am reading chapter 4.

    Tuesday 9th.3.2004

    (PLAN 1) Chapter 3 Of MINIX OS book(Continued)

    (PLAN 2) read 2 embedded system papers.

    • A Real-time Linux By Bivtor Yodaiken and Michael Barbanov

    This paper explains how real-time version of Linux is implemented. In their implementation, Linux is ran as a completely preemptable task on a small real-time micro-kernel. In their design, only small changes need to be made to Linux kernel. These are low level interrupt wrappers and the routines to disable and enable interrupts. Linux has a high interrupt latency (the time from interrupt to task run) so this property makes not suitable for Real-time OS. Linux disables interrupt quite often and also kernel itself is not preemptable.

    so intetading of letting Linux handle interrupt hard ware directly, there is a global flag in real-time kernel which is set when Linux wants to enalble interrupts, and similarly reset when interrupts needs to be disabled.

    When Linux requests interrupts to be disabled, the real-time microkernel makes the interrupts ad pending. When linux requests interrupts to be enabled, th ereal-time kernel causes control to switch to the Linux handler for highest priority pending interrupt. Linux is then able to provide sophisticated services to the real-time system without increasing interrupt latency.

    There are also many disadvantages of this method. These are well explained in "SMX vs Linux" article. This real-time Linux is also well explained in Michael's master thesis "Linux as a Real-time Operating System".

    • Implementing Real-Time services in MINIX by Gabriel A. Wainer (1995)

    In this article, Wainer explains how he implemented real-time servieces into Minix. This was achived by simply modifying the original MINIX round-robin time scheduling mechanism to th real-time scheduling algorithm. And also some system calls and signals were added as an interface between the kernel and applications.

    (PLAN 3) other..

    I read an article "SMX vs RT-Linux", which explains why Linux is not suitable as an OS for embedded system. It argues that Linux and even RT-Linux (RealTime-Linux) are not suitable for embedded system OS. The reasons includes non-preemptable tasks resulting in a long interrupt latency, big size, multi-process, IPC, and etc. It should be useful when designing a embedded minix.

     

    Monday 8th.3.2004 (IMPORTANT)

    (PLAN 1) Chapter 3 of MINIX OS book

    I spent most of the day reading chapter 3 of MINIX OS book. This book explains the principle of I/O device drivers and how they are implemented in MINIX. There are two kinds of I/O devices: block devices and character devices. A Block device is one that stores information in fixed-size blocks, each one with its own space. A good example of a block device is disks. A character devices is one which delivers or accepts a stream of characters, without regard to any block structure. It is not addressable. Printers, network interfaces, mouse and most other devices tha t are not dist-like can be clssfied as character devices. I/O unit typically consists of a I/O controller and a device. I/O controller is an electronic component which does all messay stuff related to controlling I/O device. OS always deals with the controller. DMA (Direct Memory Access) were discussed. This controller allows the communication between the buffer in I/O device controller and memory without help of CPU. I/O software can be structured in the following four layers:

    1) Interrupt handlers

    2) Device Drivers

    3) Device independent OS software

    4) User-level software

    These four layers are explained. And also Deadlock is also discussed in detail. Finally, many device drivers including RAM Disk (which allows some part of memory to be reserved to be used like disk space), hard disk, floppy disk, and clock device drivers were explained in detail.

    (PLAN 3) Otherthing

    I found a very useful website which explains MINIX boot-sequence in a great details. The website address is http::www.swartzbaugh.net/minix/index.php. This site explains bootsequence very well by going through each line of source code.

     

     

    Friday 5th.3.2004

    I finished reading the chapter 2 of MINIX book. The second half of the chapter 2 was really helpful in understanding how MINIX actually handles boot-up, interprocess communication, process scheduling and all other process related stuff. In page 145 of this book, the author actually gave some useful hints on using MINIX on small system.

    "MINIX is also intended to run on small systems, which are likely to have only, one use ror perhaps just a few trusted users. On such a system a user oculd very well want to write an application program that accesses I/O ports, for instance, for use in scientific data acquistion. The file system has a little secret built into it- when the files /dev/mem or /dev/kmem are opened, the memory task calls enable_iops, which changes the privilege level for I/O operations, allowing the current proces to execute insturctions which read and write I/O ports"

    I might be able to use it when implementing MINIX on embedded system. It can be useful when providing a faster I/O device handling". I also found "Interrupt handling in MINIX" part useful; however, i should have a better understanding of assembly language before I can fully understand what is actually going on.

     

     

    Wednesday 3rd.3.2004

    I read a book called "Introduction to Assembly Language programming" to know more about Intel 80x86 processer and computer architecture. I also decided to read this book since "booting process" in minix is mostly written in assembly language. I read Chapter 1 and 2. In chapter 1, the author argues that using assembly language on embedded system and real-time application is very useful because assembly language is more time-efficient and space-efficient. The rest of chapter 1 talked about the disadvantages and advantages of using assembly language. In chatper 2, the basic computer organization is well explained. I learnt a lot about computer architecture. I will write some of stuffs I learnt today here.The basic computer system consists of a CPU, I/O devices, and memory. The system bus is used to connect them. The system bus consists of address bus, data bus, and control bus. The address bus is used to address a specific memory locatoin. The width of address determines the maximum amount of addressable physical memory. For example, 80x86 has a 20-bit address bus. The data bus is used to transfer data. The width of data bus determines the maximum number of data which can be transferred at a time. For example, 80x86 has a 16-bit data bus. And control bus is used to signal a various control actions such as memory read, memory write, I/O stuffs. And it talks about pentium memory architecture and different types of memory. I really found the chapter 2 of this book useful.

    I also started reading a book called "Operating system concepts" to understand MINIX better. It should help me have more clear understanding of operating systems. At the moment I'm reading a chapter 2. It really gives me a better understanding of OS concepts. I should keep reading this book.

    PAPER SUMMARY) Embedded Software by Edward A. Lee (2002)

    This paper says that embedded system differs from conventional software because embedded system needs to take care of timeliness, concurrency, liveness, reactivity, and so on. It argues that embedded software needs to be taken differently from conventional software so that a new model of design strategy should be taken. This paper kinds of states the requirements of embedded system. and also it lists a lot of computation models which can be applied to embedded software. It is kinda hard to understand at the moment. I should read another paper and get back to this one later.

     

    Monday 1st.3.2004

    I've searched the citeseer and found a bunch of useful papers on "Embedded system".

    I have read a chapter 2 "process management" of MINIX OS book and found the following useful.

    Bootstrapping MINIX

    (1) When the computer hardware is turned on, the first sector of the first track of the boot disk is loadded into memory.

    (2) The first sector contains a partition table and a small program. That program reads the partition table and loads and executes the first sector of the active parition.

    (3) The bootstrap on the active partition loads boot program for the partition.

    (4) Boot looks in the second sector of its partition to find a set of parameters to use and loads operating system image according to the configuration. (ASIDE: Like standard UNIX, MINIX reserves It loads OS image by looking for a file called /minix. The different image can be loadded by passing an appropriate parameter.

     

     

    Thursday 26th.2.2004

    I spent most of day building this project webpage. And also, I finished planning for my project. I found an useful quote from 'how to be a good thesis student guide':

    "Keeping a research journal or diary of your research activities and ideas is very useful. Write down speculations, interesting problems, possible solutions, random ideas, references to look up, notes on papers you've read, outlines of papers to write, and interesting quotes. Read back through it periodically."

    I also spent some time looking at some minix source code. I'd better spend more time on literature review. I have not found any useful papers yet.

    I read also an article 'Introduction to Real time". It explains basic terminology used in real time system. It is a quite useful article. The URL is http://www.embedded.com/showArticle.jthml?articleID=9900353

     

     

     

    Monday 16th.2.2004

    I had a meeting with my supervisor. We talked mostly about our proposal and plans for my thesis. Here is a brief ideas of what I need to do for my thesis.

    (1) Requirement of embedded systems

    eg) small, fast, real-time

    (2) Difference between Real OS and Normal OS

    (3) Simulate what they'v edone in Linux in Minix

    (4) Current status on Real time embedded OS

     

    TO DO>> (1) Search gogle about embedded system, minix, linux

    (2) ACM digital Journal

    (3) plan

     

    My supervisor suggested me to look very carefully on how minix is loaded into the memory.

     

     


    SangHyeb Lee(shlee@cs.otago.ac.nz)

    Last updated: Thursday, March 11, 2004 8:57 AM