Page 413 - DCAP103_Principle of operating system
P. 413

Principles of Operating Systems



                   Notes         The  kernel  sits  directly  on  the  hardware  and  enables  interactions  with  various  devices,  the
                                 system memory and controls CPU accesses. At the lowest level, as shown in Figure 14.3,
                                 it contains interrupt handlers which are the primary way for interacting with devices, and
                                 low-level dispatching mechanism. This dispatching occurs when an interrupt  happens. The
                                 low-level code here stops the running process, saves its state in the kernel process structures,
                                 and starts the appropriate driver. Process dispatching also happens when the kernel completes
                                 some operations and it is the time to start up a user process again. The dispatching code is in
                                 assembler and is quite distinct from scheduling. Next, we divide the various kernel subsystems
                                 into three main components.

                                 The I/O component in Figure 14.3 contains all kernel pieces responsible for interacting with
                                 devices  and  performing  network  and  storage  I/O  operations.  At  the  highest  level,  the  I/O
                                 operations are all integrated under a Virtual File System layer. That is, at the top level, performing
                                 a read operation to a file, whether it is in memory or on disk, is the same as performing a read
                                 operation to retrieve a character from a terminal input. At the lowest level, all I/O operations
                                 pass  through  some  device  driver.  All  Linux  drivers  are  classified  as  either  character  device
                                 drivers or block device drivers, with the main difference that seeks and random accesses are
                                 allowed on block devices and not on character devices.
                                 Technically, network devices are character devices, but they are handled somewhat differently
                                 that it is probably clearer to separate them, as has been done in the figure. Above the device
                                 driver level, the kernel code is different for each device type. Character devices may be used
                                 in two different ways. Some programs, such as visual editors like vi and emacs, want every
                                 key stroke as it is hit. Raw terminal (tty) I/O makes this possible. Other software, such as the
                                 shell, is line oriented, and allows users to edit the whole line before hitting ENTER to send it
                                 to the program.
                                 In this case the character stream from the terminal device is passed through a so called line
                                 discipline, and appropriate formatting is applied. Networking software is often modular, with
                                 different  devices and  protocols supported. The  layer  above the  network  drivers handles  a
                                 kind of routing function, making sure that the right packet goes to the right device or protocol
                                 handler.  Most  Linux systems  contain  the full  functionality of  a  hardware  router within the
                                 kernel, although the performance is less than that of a hardware router. Above the router code
                                 is the actual protocol stack, always including IP and TCP, but also many additional protocols.
                                 Overlaying all the network is the socket interface, which allows programs to create sockets for
                                 particular networks and protocols, getting back a file descriptor for each socket to use later. On
                                 top of the disk drivers is the I/O scheduler, which is responsible for ordering and issuing disk
                                 operation requests in a way that tries to conserve wasteful disk head movement, or to meet
                                 some other system policy.

                                 At the very top of the block device columns are the file systems. Linux may have, and it does in
                                 fact, multiple file systems coexisting concurrently. In order to hide the gruesome architectural
                                 differences of various hardware devices from the file system implementation, a generic block
                                 device layer provides an abstraction used by all file systems.

                                 To the right in Figure 14.3 are the other two key components of the Linux kernel. These are
                                 responsible for the memory and process management tasks. Memory management tasks include
                                 maintaining the virtual to physical memory mappings, maintaining a cache of recently accessed
                                 pages  and  implementing  a  good  page  replacement  policy,  and  on-demand  bringing  in  new
                                 pages of needed code and data into memory. The key responsibility of the process management
                                 component is the creation and termination of processes. It also includes the process scheduler,
                                 which chooses which process or, rather, thread to run next. As we shall see in the next section,
                                 the Linux kernel treats both processes and threads simply as executable entities, and will schedule
                                 them based on a global scheduling policy. Finally, code for signal handling also belongs to this
                                 component.


        406                               LOVELY PROFESSIONAL UNIVERSITY
   408   409   410   411   412   413   414   415   416   417   418