01 Linux Introduction
01 Linux Introduction
4. Multithreaded application support. Linux defines its own version of LWPs ( Light weight processes ) using a nonstandard system call clone, while all other unix versions use kernel threads to implement LWPs. 5. 2.4.x version of the kernel is non-preemptive while running in privileged mode. The 2.6 version allows pre-emption as an optional feature. 6. 7. 8. 9. Multiprocessor support. Support for several filesystems. Unix STREAMS I/O is not part of the kernel. Separately maintained. FREE / FAST / POWERFUL / COMPACT / RELIABLE / SUPPORTED
10. Version numbering X.Y.Z ( X => version. Y=even => stable else development. Z = stable / dev release ).
V.Radhakrishnan 2002.
Linux Portability
Linux runs on a very large number of hardware: Special PCs : SGI-Linux, MCA Linux, NEC PC-98 Linux IA-64 Motorola SPARC Compaq ARM : 68K, Linux Power PC or PPC : SunSparc, UltraLinux : VAX Linux, Linux Alpha : ARM and Strong ARM
Linux/MIPS : SGI, Cobalt, DEC, Nintendo 64 HandHelds : Crusoe, Palm, ELKS, VME, Linux CE
Fundamental Concepts
Difference between a "Program" and a "Process"
A Program is a complete set of executable instructions on the hard disk. A Process is created when the program is loaded into memory. A process space has DATA, STACK and INSTRUCTIONS. It has an ID ( Identification ) and exists as long as it is required to run. The same program can be run (loaded) twice. There will be two program). processes (but only one
V.Radhakrishnan 2002.
My CPU My Memory
My CPU My Memory
My CPU My Memory
Process-1
V.Radhakrishnan 2002.
Process-2
Process-3
Seen fromoutside
Task - 1 Task - 2 Task - 3
Task-1
Task-2
Task-3
Task-1
Task-3 Task-1
Task-2 Task-3
Task-1
Process-1 over
The task is active and running in the non-privileged User Mode. This state can only be exited via an interrupt or a system call. ( System calls are a special case of interrupts ). In either case, the processor is switched to the privileged mode and the appropriate interrupt routine is activated. The process is competing for the processor, which is however occupied with another process at the present time. Its ready to execute and will be executed at the first available moment.
Ready "runnable"
The process is waiting for an external event. Only after this has occurred, will it continue its execution.
Waiting "blocked"
Two kinds of "Waiting Processes" Interruptible - processes can be interrupted by signals uninterruptible - waiting ONLY for hardware conditions
V.Radhakrishnan 2002.
Running
Running
Interrupt
Scheduler
Interrupt Service Routine
V.Radhakrishnan 2002.
V.Radhakrishnan 2002.
Rings of Protection
Privilege Levels 3 Most Privileged 2 1 0 Private OS functions OS Services Device Drivers Application programs Least Privileged
Note: Though the x86 processor provides 4 levels, Linux only uses 2 of the ring levels to enforce Kernel Mode and User Mode levels.
V.Radhakrishnan 2002.
However, in spite of the above limitations, some applications have drivers written in the User Space.
Advantages of using the User Space mode for writing drivers: 1. The full C library can be linked in. This is NOT possible when programming in kernel mode. 2. A conventional debugger can be run without the extra effort involved in trying to debug a running kernel. 3. If a user space driver hangs, you can just kill it. Problems with the driver are unlikely to hang the entire system. 4. User memory is swappable. Infrequently used device with a huge driver could be swapped out, unlike a driver written in the kernel mode, where it doesnt get swapped out. Examples of user space drivers are the X Server, the gpm mouse server, the libsvga program, SANE, cdrecord etc...
V.Radhakrishnan 2002.
Linux is Re-Entrant.
Mainline Driver Procedure 7 1 Call Driver 2 3 4 Interrupt occurs 11 12 7 10 9 Interrupt Procedure 5 Call Driver 6
13 8 The Linux Kernel as well as driver code needs to be re-entrant. The Linux Kernel is NOT PRE-EMPTIVE, which means that a process can be pre-empted only when running in User Mode. ( Changed in Linux 2.6 !! ) V.Radhakrishnan 2002.