Introduction

Created

Operating system allows user processes to access the hardware resources they need effectively.

  • The OS kernel virtualizes system resources, and presents user processes with an abstraction of those resources.
  • No process gets direct access to hardware resources
  • process abstraction. Virtual execution environment realized on specific and complicated hardware devices. OS Kernel provides the higher level abstraction for those resources.
  • Imagine "i want to open a file" - process abstraction sees it at a high level. The file is realized as a pattern of bits written to a storage device or we communicate over the network.
    • The OS kernel is interacting with real hardware devices. Essentially, we take low level concrete devices, and we build a nice high level abstraction.

The hardware is a set of resources. E.g.,

  • CPU: ability to execute
  • Storage: ability to store persistent data
  • RAM: ability to store data that can be quickly access
  • Hardware typically has a complex interface

The cost of abstraction:

  • They have a performance or memory use cost.

Why do we need an OS?

  • Imagine if you let the programs themselves access hardware devices. If every process does it at the same time, there are high odds they interfere with each other.

History

  • In the beginning, we directly programmed on hardware. Took a long time to prepare a program for execution, meaning that from when you submitted your job to when it was run, it could take many hours or days. Batch processing doesn't require too much system hardware.
  • Next (1960-1970s) came the mini computer era where you wanted to interact with the program. This was when the earliest multi-user operating systems were developed (CTSS, ITS, Multics, Unix). These supported memory protection via segmentation (e..g, PDP-10, PDP-11) that were quite primitive.
  • Paged virtual memory was an enormous innovation because it allowed you to do memory isolation, provision memory as an on demand resource.
  • First x86 system with support for paged virtual memory came in 1985 with Intel 80386. These are the modern personal computers that were powerful enough to run modern operating systems (multiprocess, multiuser, virtual memory, etc.)
  • Unix workstations (1980s-2000s):
  • Every current computing device is a supercomputer, meaning that modern, fully-featured OS are possible and useful on a large subset of computing devices. OS is so relevant!

OS Kernel vs OS:

  • Things that are part of the "OS" but outside the "OS Kernel": standard libraries (e.g., the C library), window system, standard utility program
  • The OS is very necessary
  • Linux terminology: "Distribution" = kernel + lots of necessary / useful softwrae

Process: a running program

  • for a process to access system resources, it requests service from the OS kernel
  • The kernel must only give processes the resources to which they've been granted access

Modes:

  • Kernel modes: code running in this mode has full access to all hardware resources
    • only the OS kernel runs in kernel mode
  • User modes: regular processes cannot access resources / access resources must be via the kernel
    • cannot access a hardware device. Cannot interface create page tables or else it can access any memory
    • ordinary processes use this
    • can only access memory to which the process has specifically granted access
    • can invoke system calls to request a service from the OS kernel
  • Restrictions are (in theory) sufficient for the OS kernel to maintain complete control over the system
  • reti is called when kernel mode has handled the system call and it includes information about how it was in kernel mode

Fair access to the CPU

  • in the case that there is a program that loops infinitely on a single core, we don't want it occupy the processor completely. so how do they handle it?
  • hardware devices can interrupt
  • storage devices also uses interrupt to the let the kernel know that that "this transfer is done" so that the process is that their request was completed.

Hardware interrupts are when the system hardware device requests to interrupt the CPU.

  • It occurs when there is a transition to kernel mode (if the CPU is not already in kernel mode) or when executing a kernel interrupt handler routine to respond to the interrupt
  • the hardware interrupt occurs while a process is executing user code, the OS kernel regains control
  • interval timer: a hardware device whose only purpose is to periodically interrupt the CPU to ensure the OS kernel regains control of the CPU at regular intervals
  • the OS can make scheduling decisions to allocate intervals of CPU time to processes fairly. This is called time-slicing

A system call allows a user process to request a service from the OS kernel like opening a file, reading/writing data from a file, creating a child process, mapping memory to the address space.

  • invoked using a special CPU instruction, sometimes referred to as a trap or "software interrupts"
  • Effect similar to when a hardware interrupt occurs: the cpu switches to kernel mode, and the system call handler routine in the OS kernel is executed