Operating Systems

How to think about an OS

Abstract Machine

Goal is to make life easier for programmers by hiding hardware detail with a common core for all applications

Resource Manager

Goal is to manage resources and ensure all users (processes) make progress and are not starved so as to efficiently use the system. Resources will be allocated according to a policy.

Resources

  • Disk
  • Memory
  • CPU
  • Bandwidth

Privileged Component

Applications run in user mode, and if they ever want to touch anything to do with hardware or fundamental OS functionality it has to interface with the OS (can't do it directly).

The kernel/nucleus is the part of the OS (fundamental part that handles security and services and most common functions) lives in main memory. User interface functions also live in user mode with the applications (but are part of the OS).

Allows the OS to enforce its allocation of resources as it likes and prevents applications interfering with each other or the OS.

The OS interacts with hardware (also lives in in privileged mode) via load and store instructions. Hardware = CPU, device registers, interrupts and memory.

Privilege-less Embedded OS

Some embedded OS don't have a privileged mode - so they implement functionality but can't enforce it or isolate processes/faults.

Goals of an OS

  • Abstraction
    • As above, we hide away hardware details to make applications cross platform
  • Convenience
    • Make the computer easier to use
  • Efficiency
    • Allow the system to run more efficiently than without it
  • Protection
    • Allow only authorised access to files, computation and services
  • Ability to Evolve
    • Be able to develop, test and introduce new features without bringing the existing system down or interfering with existing services.

Services

  • File control/access
  • IO interaction (printers, keyboard, etc)
  • Running a program (loading it into memory and executing it)
  • User authentication
  • Error detection/response
    • Hardware, software or application-request errors (e.g. device failures/forbidden memory access)
  • Accounting (statistics, performance monitoring, predict wanted features)

Structure

Operating systems have lots of interdependent pieces, but usually some kind of reasonable structure appears between memory management, file systems, process scheduling, inter-process communication, network interaction, etc.

Hardware

  • CPU
    • Performs actual computation
      • Fetch/Execute cycle
  • Load/store data
  • Buses
    • Carries data between IO devices, CPU and main memory
  • Memory Controller
    • Refreshes RAM
    • Arbitrates between CPU and devices (for who gets memory access)
  • Device controllers
    • Control operation of a device
    • Operate in parallel with CPU
    • Use DMA to load/store memory
    • Register = a memory location or an IO port
    • Signals CPU with interrupts
  • DMA (Direct Memory Access)
    • Used by device registers to load/store memory
  • Interrupts
    • Processing is suspended for interrupt mode
    • Allows processor to be more efficient than just polling devices or pausing whilst an IO operation happens.
    • Program Exceptions; e.g. arithmetic overflow, division by zero
    • Interrupt (e.g. Timer, IO, hardware failure)
  • Hard disks

Instructions

CPU executes the text of a program via the instruction set. BUT there are two modes - privileged and not. Privileged gets all instructions, user gets only 'safe' subset.

Safe instructions/registers

• Cannot affect application state
• Cannot uncontrollably interfere with the OS or other applications
• Cannot violate a correctly implemented system

E.g. User mode doesn't get to disable interrupts
Not all addresses are accessible to user mode. E.g. kernel stack will be privileged.

memoryspaces.png

Hierarchy

Larger/lower things = lower cost per bit, higher capacity, longer access time and (hopefully) decreased access frequency

memory%20type%20hierarchy.png

Caching

We move data from a large/slow system to a small/fast system when it is accessed. Hopefully things will be accessed frequently, and so the overhead of caching them pays off with how fast future accesses are.

caching.png

Effective access time is just average access time - e.g. the proportion of hits to M1 * T1 + proportion of hits to M2*T2.

E.g. if it takes 10 seconds to access memory 1, and 25 to access memory 2, and 30% of hits are to memory 1 and 70% to memory 2 effective access time is (10 * .3 + 25 * .7) = 20.5