Operating System Organization: Difference between revisions

From Soma-notes
Rgould (talk | contribs)
No edit summary
m minor typo & grammar fixes
Line 45: Line 45:
handle = open(/dev/cdrom, ...)
handle = open(/dev/cdrom, ...)
</pre>
</pre>
This is call to the kernel which will use the cd-rom devices drivers to read from the disc.
This is a call to the kernel which will use the cd-rom devices drivers to read from the disc.


Pipes and sockets both operate as files and support the basic operations
Pipes and sockets both operate as files and support the basic operations:
* open
* open
* read
* read

Revision as of 02:13, 1 October 2007

Operating System Organization

Device Management

How do kernels communicate with devices such as a network card? How do drivers for such devices fit into the kernel? We need a mechanism to allow applications to communicate with the devices. Most kernels use a form of message passing, often using a registration system. For example, a network card device driver would register itself with the kernel and identify that it is in fact a network card (as opposed to say, a mouse). MS DOS used interrupt handlers instead.

Glenn's talk focused mostly on the how the Linux Kernel works.

File Abstraction in Device Management

In Linux there exists a "/proc" directory which contains special information. This directory does not actually exist on disk. When the kernel receives a request to read a file in one of these directories, it retrieves system information and serves it up as a file. For example, executing more /proc/cupinfo gives:

$ more /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family    : 6
model         : 13
model name    : Intel(R) Pentium(R) M processor 1.73GHz
stepping  : 8
cpu MHz       : 798.000
cache size    : 2048 KB
...

Each process that is currently running on the system gets its own directory in /proc, with the process ID (pid) as the directory name. For example for process with pid 2, there exists "/proc/2/" which contains more information about that process.

/dev

The "/dev" directory actually exists on the file system and contains entries for devices (called nodes). For example, the first hard drive on the system might reside in "/dev/hda/". Each device entry has a major node number and a minor node number. For example, the hard drive specified by "/dev/hda" might have major node number "3" and minor node number "0". At first the node numbers were pre-defined and there could be no more than 255 of them. These major/minor node numbers are used to link the specific device types into the kernel. These nodes existed in "/dev" even if the devices were not connected to the system.

devfs

This was eventually replaced with a new system called "devfs" (device file system), which was a pseudo-file system similar to /proc. Devfs is implemented in the kernel and knows about the currently available hardware. Some problems still existed with this system: it was implemented in the kernel, and thus a change to hardware required an update to the kernel; and the major and minor node numbers were still fixed in the kernel. It would be nice to dynamically reassign major nodes to unknown devices that are actually present on the system. Devfs also prevented the renaming of nodes in /dev. For example, previously one could rename /dev/hda to /dev/cdrom, but it would still actually point at hard-drive a. This behaviour was prevented in devfs.

udev

Another problem existed with hot-pluggable devices (such as USB devices). Minor node numbers were assigned by the kernel in the order by which they were discovered. Devices might have different node numbers after a reboot. Also no notifications occur when a device is connected or disconnected from the system.

Devfs has since been replaced by a new system named "udev", which was implemented in the user space, not the kernel space. The ability to rename nodes in /dev was enabled again by udev. The issue regarding hot-pluggable devices was addressed by permitting minor node numbers to be dynamically assigned. udev also notifies applications when hardware is connected or disconnected. Network cards are a special case - the kernel knows about network protocols, so network cards must be accessed using a different interface.

Other files, pipes and sockets

An example call for opening the CD-ROM may look something like:

handle = open(/dev/cdrom, ...)

This is a call to the kernel which will use the cd-rom devices drivers to read from the disc.

Pipes and sockets both operate as files and support the basic operations:

  • open
  • read
  • write
  • close

Pipes are used for inter-process communication. Each process can open one end of the pipe, and then they can read or write to it.

Sockets are used in a similar manner to communicate over a network.

Kernel Development

Standard development tools aren't always helpful when debugging during kernel development. How can you debug a kernel that crashes before the display drivers work? The Linux kernel outputted Morse code to the LED lights on the keyboard.

Often developers must work around bugs in hardware, as it is usually much cheaper to fix it in software than to change the hardware design.

Process and Thread Management

Context switching between different process is very expensive in terms of execution time. Different situations call for different strategies for managing context switches. For example, consider terminals and servers. Server systems can get away with fewer context switches, as they can completely serve up a request for a web-page before moving on to the next request. On a terminal, the user is present and expects instant feedback. If the mouse is moved, and the process that moves the mouse pointer does not respond quickly, the user will perceive that the machine is slow, or unresponsive.

Memory Management

Chapter 3 gives just a brief introduction to memory management.

Processes have their own virtual memory map. P3s and P4s used 32-bit addressing, which gave a maximum address space of 4GB. Note that there may not even be 4GB of physical RAM available to be used. When a process requests memory that is not currently in RAM, the operating system must retrieve it from disk (aka paging).

The operating system also needs to protect the kernel's memory space from other applications. Supervisor (root) vs user mode determines the level of access to memory.

Kernel Design

Monolithic vs micro - how much stuff should be implemented in the kernel. Microkernel design means that processes and applications do more work, which requires more context switching, but this permits the kernel to be more reliable.

An example monolithic kernel might include things such as:

  • network driver
  • display
  • clock

A micro kernel might only include the minimal items:

  • memory allocation
  • process switching

File Systems

Consist of many items:

  • directories
  • files
  • device nodes
  • links (in Windows these are called shortcuts)
  • pipes

In DOS, only directories, files and device nodes were used. In Windows, they are well hidden under the path "\\" or they are given special names, such as "AUX", "COM0" or "LPT0".