Saturday, October 23, 2010

Minix Context Switching Detail

Download and view this PDF file.

I have shown both hardware and software interrupt workflows here. Since the diagram is large and complex, it may have some errors due to oversight. Comments/corrections welcome.

Wednesday, October 20, 2010

Context Switching

I think I now understand exactly how context switching happens in Minix. I am working on a detailed diagram which I will upload once I am done.

Sunday, October 17, 2010

Minix Interrupt Handling





Context Switching - The illusion of multiple processes executing simultaneously

In a single processor system, at any instant, only one process is executing - be it a system process (part of the OS) or a user process. The illusion of multiple processes running simultaneously is achieved by constantly switching from process to process. Now, when does a context switch happen in minix? What causes the CPU to suspend execution of one process and resume another? There are three ways in which this can happen:

1. Hardware interrupt (one of the devices in the computer sends a signal to the interrupt controller which in turn sends an interrupt signal to the INT pin of the CPU)
2. Software interrupt (i. e. system call made by the executing process)
3. The 'quantum' of time assigned to the executing process has been used up, so this process is pre-emptively suspended and another one is picked for execution. (This is really a special case of hardware interrupt where the interrupting device is the clock.)

In upcoming posts, I will first explain interrupt processing and context switching and then give more details on scheduling of processes.

Friday, October 15, 2010

The Global Descriptor Table

The GDT (Global Descriptor Table), LDTs (Local Descriptor Tables) and the IDT (Interrupt Descriptor Table) , all located in memory provide protected access to system resources. The GDT and IDT are pointed to by special registers within the CPU (so the processor can access them), and the GDT entries point both to the operating system segments and to the LDTs. The IDT contains pointers to code that needs to be executed when interrupts occur.

Each running program has its own LDT but there is a single GDT for the entire system.

The LDT describes segments local to each program including its text (code), data, stack and so on. The GDT describes system segments including the operating system itself. (Segments are independent address spaces. Segmentation is one of the techniques use to manage memory on computers. More on segments when we discuss memory management but for now just understand that with segmented memory, we need a two part address to reach any memory location - the first part is the address of the segment and the second part is the location (offset) within the segment.)

So the GDT basically points to (i.e. contains the physical addresses of) segments that contain the operating system code and data but also provides a way to get to all the LDTs in the system.