main

Chapter 1

An operating system is a program that manages the computer hardware.

4 high level components:

  • hardware
    • CPU, memory, I/O devices provide computing resources for the system.
  • operating system
    • controls the hardware and coordinates its use among the various applicatoin programs for the various users.
  • application programs
    • word processors, spreadsheets, compilers, web browsers define ways to use resources to solve users’ computer problems.
  • users

We can also view a computer system as:

  • hardware
  • software
  • data

The OS provides the mans for proper use of these resources in the operation of the computer system. The OS performs no useful function by itself. It provides an environment within which other programs can do useful work.

User View

Most computer users sit in front of a PC that has

  • a monitor
  • keyboard
  • mouse
  • and system unit

Another usage is where a user sits at a terminal connected to a mainframe or a minicomputer. Other users access the same computer through other terminals. These users share resources and may exchange information.

The operating system is the one program running at all times on the computer - usually called the kernel. Along with the kernel there are systems programs, which are associated with the operating system but are not part of the kernel, and application programs, which include all programs not associated with the operation of the system.

  1. bootstrap program stored in ROM or EEPROM known as firmware.
  • initializes CPU registers, device controllers, memory contents.
  • must know how to load the operating system
  • must load the operating system kernel
  • execute first process known as init.
  • occurrence of an event is signaled by an interrupt from either hardware or software.
  • hardware may send signal to CPU to trigger an interrupt via the system bus.
  • software may trigger an interrupt by executing system calls.
  • when a CPU is interrupted it stops what it is doing and immediately transfers execution to a fixed location. The fixed location usually contains the starting address where the service routine for the interrupt is located. Interrupts must be handled quickly so only a predefined # of interrupts is possible.

Interrupt vector: table of interrupt addresses.

The CPU can load instructions only from memory, so any programs to run must be stored there. All forms of memory provide an array of words. Each word has its own address. Interaction is achieved through a sequence of load or store instructions to specific memory addresses. The load instruction moves a word from main memory to an internal register within the CPU, whereas the store instruction moves the content of a register to main memory.

von Neumann architecture:

  1. fetch instruction from memory and store that instruction in the instruction register.
  2. decode instruction. may cause operands to be fetched from memory and stored in some internal register.
  3. execute instruction
  4. store result back in register

Memory unit only sees a stream of memory addresses.

Ideally, we want programs and data to reside in main memory. This is usually not possible because:

  1. main memory is usually too small to store all needed programs and data permanently.
  2. main memory is a volatile storage device that loses its contents when power is removed.

Most computer systems use secondary storage as an extension of main memory. Secondary storage must be able to hold large quantities of data permanently.

The magnetic disk is a common secondary storage device. Most programs are stored on disk until they are loaded into memory.

Computer System Architecture

Single-Processor Systems: one main CPU Multiprocessor System: have two or more processors in close communication sharing the computer bus, clock, memory and peripheral devices.

Multiprocessor systems have three main advantages:

  1. Increased throughput: more work done in less time.
  2. Economy of scale: can cost less because they share peripherals, storage, and power.
  3. Increased reliability: failure of one processor will not halt the system. only slow it down

Symetric Multi Processor (SMP): Solaris is a commercial version of UNIX designed by Sun Microsystems. Many processors can run simultaneously. Uniform Memory Access (UMA): access to any RAM from any CPU takes the same amount of time. Non-uniform Memory Access (NUMA): some parts of memory may take longer to access than other parts.

Another trend is to include multiple cores on a single chip. These are like multiprocessor chips. On chip communication is faster than a single core per chip. One chip with multiple cores also uses less power than multiple single-core chips.

Dual core design:

   ------------------------------------
   | ---------------  --------------- |
   | | CPU core0   |  | CPU core1   | |
   | | ----------- |  | ----------- | |
   | | |registers| |  | |registers| | |
   | | ----------- |  | ----------- | |
   | |      |      |  |     |       | |
   | | ----------- |  | ----------- | |
   | | |  cache  | |  | |  cache  | | |
   | | -----|----- |  | -----|----- | |
   | -------|-------  -------|------- |
   ---------|----------------|---------
            ------------------
                    |
                ----------
                | memory |
                ----------

Job pool

 0   |------------------|
     | operating system |
     |------------------|
     | job 1            |
     |------------------|
     | job 2            |
     |------------------|
     | job 3            |
     |------------------|
     | job 4            |
512M |------------------|

Operating schedules a job to put into memory to execute. When the job needs to wait for an I/O operation to complete the operating system switches to another job and so on. As long as at least one job needs to execute then the CPU is never idle.

In time-sharing systems, the CPU executes multiple jobs by switching among them, but the switches occur so frequently that the users can interact with each program while it is running.

A program laoded into memory and executing is called a process. When a process executes, it typically executes for only a short time before it either finishes or needs to perform I/O.

Modern operating systems are interrupt driven. Events are almost always signaled by the occurrence of an interrupt or a trap.

A trap, or an exception, is a software generated interrupt caused either by an error or by a specific request from a user program that an operating-system service be performed.

Terms:

  • CPU scheduling
  • job scheduling
  • logical memory
  • physical memory
  • swapping
  • virtual memory

For each type of interrupt, separate segments of code in the operating system determine what action should be taken. An interrupt service routing is provided that is responsible for dealing with the interrupt.

Dual Mode Operation

Must distinguish between operating system code and user-defined code.

  • user mode
  • kernel mode (supervisor mode, system mode, priviliged mode)

The mode bit is added to hardware to indicate the current mode: kernel (0), user (1) The hardware allows privileged instructions to be executed only in kernel mode.

System calls provide the means for a user program to ask the operating system to perform tasks reserved for hte operating system on the user program’s behalf.

A system call usually takes the form of a trap to a specific location in the interrupt vector. This trap can be executed by a generic trap instruction, although some systems have a specific syscall instruction.

Timer

We must ensure that the operating system maintains control over the CPU. We cannot allow a user program to get stuck in an infinite loop or to fail to call system services and never return control to the operating system.

To accomplish this, we can use a timer. A timer can be set to interrupt the computer after a specified period.

Process Management

A programs instructions are executed by a CPU. A program in execuation is a process. A time-shared user program is a process.

A process needs:

  • CPU time
  • memory
  • files
  • I/O devices

A single-threaded process has one program counter specifying the next instruction to execute. The execution of such a process must be sequential.

Although more than one process may be associated with the same program, they are considered two separate execution sequences.

The operating system is responsible for:

  • scheduling processes and threads on the CPU
  • creating and deleting both user and system processes
  • suspending and resuming processes
  • providing mechanisms for process synchronization
  • providing mechanisms for process communication

Memory Management

Main memory is a large array of words or bytes, ranging in size from hundreds of thousands to billions.

Each word or byte has it’s own address. Main memory is a pool of quickly accessible data shared by the CPU and I/O devices.

On a von Neuman architecture, the central processor reads instructions from main memory during the instruction-fetch cycle and both reads and writes data from main memory during the data-fetch cycle.

The main memory is generally the only large storage device that the CPU is able to address and access directly.

For example, for the CPU to process data from disk, those data must first be transferred to main memory by CPU-generated I/O calls.

For a program to be executed, it must be mapped to absolute addresses and loaded into memory. As the program executes, it accesses program instructions and data from memory by generating these absolute addresses.

The operating system is responsible for the following:

  • keeping track of which parts of memory are currently being used and by whom
  • deciding which processes (or parts thereof) and data to move into and out of memory
  • allocating and deallocating memory space as needed.

Storage Management

The OS provides uniform, logical view of information storage. The OS abstracts from the physical properties of its storage devices to define a logical storage unit, the file. The OS maps files onto physical media and accesses these files via the storage devices.

File-System Management

File management is one of the most visible components of an operating system. Computers can store information on several different types of physical media. Magnetic disk, optical disk, and magnetic tape are th emost common. Each of these media has its own characteristics and physical organization. Each medium is controlled by a device, such as a disk drive or tape drive, that also has its own unique characteristics. These properties include access speed, capacity, data-transfer rate, and access method (sequential or random).

A file is a collection of related information defined by it’s creator. Files represent programs and data. Data files may be numeric, alphabetic, alphanumeric or binary. File may be free-from or they may be formatted rigidly.

The OS is responsible for:

  • creating and deleting files
  • creating and deleting directories to organize files
  • supporting primitives for manipulating files and directories
  • mapping files onto secondary storage
  • backing up files on stable (nonvolatile) storage media

Mass-Storage Managment

OS is responsible for

  • free space management
  • storage allocation
  • disk scheduling

Caching

Level 1 2 3 4
Name registers cache main memory disk storage
Size < 1 KB < 16 MB < 64 GB > 100 GB
Access time (ns) 0.25 - 0.5 0.5 - 25 80 - 250 5,000.000
Bandwith (MB/sec) 20,000 - 100,000 5,000 - 10,000 1,000 - 5,000 20 - 150
Managed by compiler hardware operating system operating system
Backed by cache main memory disk CD or tape

I/O Systems

OS’s hide the pecularities of specific hardware devices from the user. The I/O subsystem consists of:

  • memory management component that includes buffering, caching, and spooling
  • general device-driver interface
  • drivers for specific hardware devices

Only the device driver knows the peculiarities of the specific device to which it is assigned.

Protection and Security

Memory-addressing hardware ensures that a process can execute only within its own address space. The timer ensures that no process can gain control of the CPU without eventually relinquishing control. Device-control registers are not accessible to users, so the integrity of the various peripheral devices is protected.

Protection is any mechanism for controlling the access of processes or users to the resources defined by a computer system. It is the job of security to defend a system from external and internal attacks.

Operating systems maintain a list of user names and associated user identifiers (user IDs aka SIDs).

The GNU General Public License (GPL) codifies copylefting and is a common license under which free software is released. Fundamentally, GPL requires that the source code be distributed with any binaries and that any changes made to the source code be released under the same GPL license.

BSD Unix

BSD Unix has a longer and more complicated history than Linux. It started in 1978 as a derivative of AT&T’s UNIX.

Releases from the University of California at Berkeley came in source and binary form, but they were not open-source because a license form AT&T was required. BSD UNIX’s development was slowed by a lawsuit by AT&T, but eventually a fully functional open-source version, 4.4BSD-lite, was released in 1994.

There are many distributions of UNIX, including FreeBSD, NetBSD, OpenBSD and DragonflyBSD. The source code for FreeBSD can be found in /usr/src/. Ther kernel source code is in /usr/src/sys.

Darwin, the core kernel component of macOS is based on BSD UNIX and is open-sourced as well.

Summary

An operating system is software that manages the computer hardware, as well as providing an environment for application programs to run.

For a computer to do its job of executing programs, the programs must be in main memory. Main memory is the only large storage area that the processor can access directly. It is an array of words or bytes, ranging in size from millions to billions. Each word in memory has its own address.