You are on page 1of 16

2011

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities Introduction
A very popular open source operating system that runs on a variety of hardware platforms including x86, Itanium, PowerPC, ARM and IBM's entire product line. Based on many design principles used in the Unix operating system, and thereby often called a "Unix clone" or "Unix variant," Linux is widely deployed as a server OS and as an embedded OS. For example, Linux runs in most of the servers on the Internet and in countless appliances and consumer electronics devices. In the desktop market, Linux has nowhere near the same penetration; however, it gains ground slowly and steadily.

Linux is a powerful, non-proprietary, standards-based operating system that is currently the fastest growing computer operating system on the planet. Linux offers speed, performance, stability, and reliability that rivals (orsurpasses) that of commercial operating systems costing hundreds or thousands of dollars. Linux contains all the features required of modern desktop PCs, corporate file servers, firewalls, routers, and Internet servers. Its install base is conservatively estimated at over 10,000,000, and is growing at a rate of approximately 3% per week. In fact, Linux market share surged by 212 percent in 1998, and it is the only nonproprietary operating system that is currently demonstrating positive growth. Linux is a multitasking, multiuser operating system that is known for its stability. Although modified by numerous people, its robustness stems from its Unix-like architecture that keeps peripheral software components isolated from the core software (the kernel). This was a brief introduction to Linux operating system. Now we shall see its architecture and other OS components. This section covenants with the basic architecture of the Linux kernel and its components. It provides an overview of the most important areas of the kernel, such as the different forms of activity in the kernel, memory management, process management, device drivers, timers, and modules. Each of these issues will be discussed briefly.

Page | 1

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
Linux Architecture
Introduction to the Linux kernel Now on to a high-altitude look at the GNU/Linux operating system architecture. You can think about an operating system from two levels, as shown in Figure.

Figure: The fundamental architecture of the GNU/Linux operating system

At the top is the user, or application, space. This is where the user applications are executed. Below the user space is the kernel space. Here, the Linux kernel exists.

There is also the GNU C Library (glibc). This provides the system call interface that connects to the kernel and provides the mechanism to transition between the user-space application and the kernel. This is important because the kernel and user application occupy different protected address spaces. And while each user-space process occupies its own virtual address space, the kernel occupies a single address space.

Page | 2

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
The Linux kernel can be further divided into three gross levels. At the top is the system call interface, which implements the basic functions such as read and write. Below the system call interface is the kernel code, which can be more accurately defined as the architectureindependent kernel code. This code is common to all of the processor architectures supported by Linux. Below this is the architecture-dependent code, which forms what is more commonly, called a BSP (Board Support Package). This code serves as the processor and platform-specific code for the given architecture.

Properties of the Linux kernel When discussing architecture of a large and complex system, you can view the system from many perspectives. One goal of an architectural decomposition is to provide a way to better understand the source, and that's what we'll do here.

The Linux kernel implements a number of important architectural attributes. At a high level, and at lower levels, the kernel is layered into a number of distinct subsystems. Linux can also be considered monolithic because it lumps all of the basic services into the kernel. This differs from a microkernel architecture where the kernel provides basic services such as communication, I/O, and memory and process management, and more specific services are plugged in to the microkernel layer. Each has its own advantages, but I'll steer clear of that debate.

Over time, the Linux kernel has become efficient in terms of both memory and CPU usage, as well as extremely stable. But the most interesting aspect of Linux, given its size and complexity, is its portability. Linux can be compiled to run on a huge number of processors and platforms with different architectural constraints and needs. One example is the ability for Linux to run on a process with a memory management unit (MMU), as well as those that provide no MMU. The uClinux port of the Linux kernel provides for non-MMU support.

Page | 3

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
Major subsystems of the Linux kernel Now let's look at some of the major components of the Linux kernel using the breakdown shown in Figure as a guide.

Figure: One architectural perspective of the Linux kernel System call interface The SCI is a thin layer that provides the means to perform function calls from user space into the kernel. As discussed previously, this interface can be architecture dependent, even within the same processor family. The SCI is actually an interesting function-call multiplexing and DE multiplexing service. You can find the SCI implementation in ./linux/kernel, as well as architecture-dependent portions in ./linux/arch.

Process management As shown in Figure, a kernel is really nothing more than a resource manager. Whether the resource being managed is a process, memory, or hardware device, the kernel manages and arbitrates access to the resource between multiple competing users (both in the kernel and in user space).

Page | 4

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
Process management is focused on the execution of processes. In the kernel, these are called threads and represent an individual virtualization of the processor (thread code, data, stack, and CPU registers). In user space, the term process is typically used, though the Linux implementation does not separate the two concepts (processes and threads). The kernel provides an application program interface (API) through the SCI to create a new process (fork, exec, or Portable Operating System Interface [POSIX] functions), stop a process (kill, exit), and communicate and synchronize between them (signal, or POSIX mechanisms).

Also in process management is the need to share the CPU between the active threads. The kernel implements a novel scheduling algorithm that operates in constant time, regardless of the number of threads vying for the CPU. This is called the O(1) scheduler, denoting that the same amount of time is taken to schedule one thread as it is to schedule many. The O(1) scheduler also supports multiple processors (called Symmetric MultiProcessing, or SMP). You can find the process management sources in ./linux/kernel and architecture-dependent sources in ./linux/arch

Storage Management The Linux kernel has made great

advancement in this area. With the introduction of newer file system to even methods of device and volume

management, it makes it increasingly easy for a storage administrator to set up a Linux server to perform all necessary tasks Generally speaking, systems have several levels of storage, including primary storage, secondary storage and cache storage. Instructions and data must be placed in primary storage or cache to be referenced by a running program. Because main memory is too small to accommodate all data and programs, and its data are lost when power is lost, the computer system must provide

Page | 5

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
secondary storage to back up main memory. Secondary storage consists of tapes, disks, and other media designed to hold information that will eventually be accessed in primary storage (primary, secondary, cache) is ordinarily divided into bytes or words consisting of a fixed number of bytes. Each location in storage has an address; the set of all addresses available to a program is called an address space. The three major activities of an operating system in regard to storage management are: 1. Managing the free space available on the secondary-storage device. 2. Allocation of storage space when new files have to be written. 3. Scheduling the requests for memory access. The operating system must balance the needs of the various processes with the availability of the different types of memory, moving data in blocks (called pages) between available memory as the schedule of processes dictates. Memory management Another important resource that's managed by the kernel is memory. For efficiency, given the way that the hardware manages virtual memory, memory is managed in what are called pages (4KB in size for most architecture). Linux includes the means to manage the available memory, as well as the hardware mechanisms for physical and virtual mappings.

But memory management is much more than managing 4KB buffers. Linux provides abstractions over 4KB buffers, such as the slab allocator. This memory management scheme uses 4KB buffers as its base, but then allocates structures from within, keeping track of which pages are full, partially used, and empty. This allows the scheme to dynamically grow and shrink based on the needs of the greater system.

Supporting multiple users of memory, there are times when the available memory can be exhausted. For this reason, pages can be moved out of memory and onto the disk. This process is

Page | 6

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
called swapping because the pages are swapped from memory onto the hard disk. You can find the memory management sources in ./linux/mm.

Virtual file system The virtual file system (VFS) is an interesting aspect of the Linux kernel because it provides a common interface abstraction for file systems. The VFS provides a switching layer between the SCI and the file systems supported by the kernel (see Figure).

Figure: The VFS provides a switching fabric between users and file systems

At the top of the VFS is a common API abstraction of functions such as open, close, read, and write. At the bottom of the VFS are the file system abstractions that define how the upper-layer functions are implemented. These are plug-ins for the given file system (of which over 50 exist). You can find the file system sources in ./linux/fs.

Below the file system layer is the buffer cache, which provides a common set of functions to the file system layer (independent of any particular file system). This caching layer optimizes access to the physical devices by keeping data around for a short time (or speculatively read ahead so
Page | 7

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
that the data is available when needed). Below the buffer cache are the device drivers, which implement the interface for the particular physical device.

Network stack The network stack, by design, follows a layered architecture modeled after the protocols themselves. Recall that the Internet Protocol (IP) is the core network layer protocol that sits below the transport protocol (most commonly the Transmission Control Protocol, or TCP). Above TCP is the sockets layer, which is invoked through the SCI.

The sockets layer is the standard API to the networking subsystem and provides a user interface to a variety of networking protocols. From raw frame access to IP protocol data units (PDUs) and up to TCP and the User Datagram Protocol (UDP), the sockets layer provides a standardized way to manage connections and move data between endpoints. You can find the networking sources in the kernel at ./linux/net.

Device drivers The vast majority of the source code in the Linux kernel exists in device drivers that make a particular hardware device usable. The Linux source tree provides a drivers subdirectory that is further divided by the various devices that are supported, such as Bluetooth, I2C, serial, and so on. You can find the device driver sources in ./linux/drivers.

Architecture-dependent code While much of Linux is independent of the architecture on which it runs, there are elements that must consider the architecture for normal operation and for efficiency. The ./linux/arch subdirectory defines the architecture-dependent portion of the kernel source contained in a number of subdirectories that are specific to the architecture (collectively forming the BSP). For a typical desktop, the i386 directory is used. Each architecture subdirectory contains a number of other subdirectories that focus on a particular aspect of the kernel, such as boot, kernel, memory management, and others. You can find the architecture-dependent code in ./linux/arch.

Page | 8

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
Interrupt Mechanism in Linux
Interrupt handling is a fundamental part of the Linux kernel. Most of the kernel's functionality, in particular the parts of interest to embedded developers, in some way involve interrupts handling.

A Logical Diagram of Interrupt Routing The most important concepts related to the Linux kernel's interrupt handling mechanisms are defined here. These concepts include the relevant data structures and their description. Figure shows that there are two 8 bit controllers chained together; each having a mask and an interrupt status register, PIC1 and PIC2. The mask registers are at addresses 0x21 and 0xA1 and the status registers are at0x20 and 0xA0 Writing a one to a particular bit of the mask register enables an interrupt, writing a zero disables it. So, writing one to bit 3 would enable interrupt 3, writing zero would disable it. Unfortunately (and irritatingly), the interrupt mask registers are write only, you cannot read back the value that you wrote. This means that Linux must keep a local copy of what it has set the mask registers to. It modifies these saved masks in the interrupt enable and disables routines and writes the full masks to the registers every time. When an interrupt is signaled, the interrupt handling code reads the two interrupt status registers (ISRs). It treats the ISR at 0x20 as the bottom eight bits of a sixteen bit interrupt register and the ISR at 0xA0 as the top eight bits. So, an interrupt on bit 1 of the ISR at 0xA0 would be treated as system interrupt 9. Bit 2 of PIC1 is not available as this is used to chain interrupts from PIC2, any interrupt on PIC2 results in bit 2 of PIC1 being set.
Page | 9

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
When the interrupt happens, Linux must first determine its source by reading the interrupt status register of the system's programmable interrupt controllers. It then translates that source into an offset into the irq_action vector vector. So, for example, an interrupt on pin 6 of the interrupt controller from the floppy controller would be translated into the seventh pointer in the vector of interrupt handlers. If there is not an interrupt handler for the interrupt that occurred then the Linux kernel will log an error, otherwise it will call into the interrupt handling routines for all of the irqaction data structures for this interrupt source. When the device driver's interrupt handling routine is called by the Linux kernel it must efficiently work out why it was interrupted and respond. To find the cause of the interrupt the device driver would read the status register of the device that interrupted. The device may be reporting an error or that a requested operation has completed. For example the floppy controller may be reporting that it has completed the positioning of the floppy's read head over the correct sector on the floppy disk. Once the reason for the interrupt has been determined, the device driver may need to do more work. If it does, the Linux kernel has mechanisms that allow it to postpone that work until later. This avoids the CPU spending too much time in interrupt mode.

Page | 10

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
OS components and their responsibilities Following is a table that describes Linux components and theirs responsibilities. Component Description/Responsibilities
 

Examples

The kernel is the core component of the operating system. The kernel coordinates communication between the hardware and other software components. The kernel is the only component that is technically Linux. All other components are add-ons that turn the system into a fully-functional operating system. The kernel is constantly being updated. Current and previous kernel versions can be found at www.kernel.org.

Kernel


bash (Bourne-Again Shell) is the most




Shell


The shell is the user interface that accepts and interprets commands (either from a command prompt or a script) and forwards them to the kernel. A Linux shell is comparable to the DOS interpreter/DOS prompt.

common (and default) Linux shell. It is an enhancement of the original Bourne shell (sh).

tcsh is an enhanced version of the Berkeley UNIX C-shell (csh).

XWindows is the most common GUI




Graphical User Interface (GUI)




The GUI is responsible for drawing graphical elements on the computer screen. The Linux GUI was designed to work the same way regardless of the video hardware on the computer system.

system. X Windows works in conjunction with an X Client to render the GUI. X Windows is capable of running as a server and sending the GUI images to separate machines running an X Client. Xfree86 is the most common X Client

Page | 11

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities

The window manager modifies the GUI output that comes from X Windows. To change or modify the X Windows output, you can simply change the window manager. You can also use a desktop environment with a window manager. A desktop environment provides software (e.g., Web browsers and file managers) and gives users access to common tasks. A Windows emulator is an implementation of the Microsoft Windows API. The emulator lets you run Windows applications on Linux without running the Windows operating system.

KDE (Kommon Desktop Environment), which uses the K Window Manager (kwm) and comes with the Qt toolkit for C++. GNOME (GNU Object Model Environment) does not specify a window manager because its design allows use of any window manager. However, it does use Metacity as a default window manager in the absence of a window manager. GNOME requires the use of the GIMP Toolkit (GTK) to render the full GNOME desktop.

Window Manager/Desktop Environment




Windows Emulator


Wine, available at www.winehq.com.

A boot loader runs after the system executes the BIOS ROM and LILO (LInux LOader) is the most POST functions. It loads the Linux kernel from the boot partition on the hard disk. It is also used to boot other operating systems present on the computer. common bootloader. GRUB (GRand Unified Bootloader) is a new bootloader that offers extra functionality

Boot Loader

 

Applications and Utilities




Utilities are special programs that help you manage the system. Applications are programs that let you use the computer for specific tasks (such as word processing,

Text Editors (command-line based) Vi

Page | 12

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
listening to music, or managing data). Nautilus (used with GNOME)

File Managers

Office Applications (similar to Word, Excel, etc.) OpenOffice KOffice (for KDE) GIMP

Graphic Editor (like PhotoShop)

SMB/Samba File/Print Services NFS

Print services

LPR CUPS

Web Server


Apache Tomcat

Daemons (Services)


Daemons are programs that run in the background, providing additional functionality to a system. The Windows equivalent of a daemon is a service.

Domain Name Service (DNS)

BIND

E-mail

Sendmail Postfix ipchains Smoothwall Astaro Security Linux Squid

Firewall

Proxy Server

Page | 13

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
Conclusion
If the portability and efficiency of the Linux kernel weren't enough, it provides some other features that could not be classified in the previous decomposition.

Linux, being a production operating system and open source, is a great test bed for new protocols and advancements of those protocols. Linux supports a large number of networking protocols, including the typical TCP/IP, and also extension for high-speed networking (greater than 1 Gigabit Ethernet [GbE] and 10 GbE). Linux also supports protocols such as the Stream Control Transmission Protocol (SCTP), which provides many advanced features above TCP (as a replacement transport level protocol).

Linux is also a dynamic kernel, supporting the addition and removal of software components on the fly. These are called dynamically loadable kernel modules, and they can be inserted at boot when they're needed (when a particular device is found requiring the module) or at any time by the user. A recent advancement of Linux is its use as an operating system for other operating systems (called a hypervisor). Recently, a modification to the kernel was made called the Kernel-based Virtual Machine (KVM). This modification enabled a new interface to user space that allows other operating systems to run above the KVM-enabled kernel. In addition to running another instance of Linux, Microsoft Windows can also be virtualized. The only constraint is that the underlying processor must support the new virtualization instructions.

Page | 14

Design of Linux OS covering its Architecture, Interrupt Mechanism, Storage Management and OS Component Responsibilities
Resources: http://drdobbs.com/open-source/193301272

http://www.qsl.net/kd2bd/linux.html

http://www.ibm.com/developerworks/linux/library/l-linux-kernel/ http://technotraining.wordpress.com/2010/03/22/linux-components-facts/
http://tldp.org/LDP/tlk/dd/interrupts.html

Page | 15

You might also like