Computer Architecture, the Boot Process, the Kernel and systemd

Von-Neumann Architecture –

A brief but interesting history of computing machines can be found at Wikipedia.

Modern day computers are “stored-program” computers that include an instruction set and memory that can hold sets of instructions (i.e. a program).  A notable scientists that helped develop the theoretical basis for the stored-program computer is Alan Turing who in 1936 wrote a paper that described a universal computing machine; a machine that can theoretically execute any algorithm.  He called it the Universal computing machine.  Today we call it the Turing machine.

Another pioneer was Von-Neumann who, while working on the Manhattan Project in 1944, wrote the first logical design of a stored-program computer, for the EDVAC machine.  The design was conceptually equivalent to Eckert and Mauchly’s ENIAC machine, developed at the University of Pennsylvania.

The logical description produced by Von-Neumann gave him a great deal of notoriety, and as a result, the architecture of a stored-program computer is dubbed Von-Neumann Architecture.

A high-level diagram of the Von-Neumann architecture for computers is shown below.

Von Neumann Architecture

As you can see, the computer contains a central processing unit (CPU) as well as random access memory (RAM) and devices for input and output.  The CPU contains a control unit and arithmetic/logic unit (ALU) which handle the execution of instructions that are stored in RAM.

Although we’ll delve deeper into computer architecture in CSCI-340, for now, understand the that today’s computers are still based on the Von-Neumann architecture.

Boot Process

In a modern-day computer, the basic input/output system (BIOS) is a program that initializes the computer when you turn it on.

A typical boot sequence includes the following steps.

  1. Power is given to the machine. The chipset sends a reset signal to the CPU until a clean power signal is received.
  2. The CPU is preprogramed to look at a particular memory address in ROM for a jump instruction to the start of the BIOS boot program.
  3. The BIOS boot program starts with a power-on self test (POST). The POST includes the following checks.
    1. Verify CPU registers
    2. Verify BIOS code
    3. Verify DMA (direct memory access) which allows access to memory without CPU
    4. Verify timer, interrupt controller
    5. Locate, determine size and set up access to main memory
    6. Identify and set up access to devices available for booting
    7. Identify and set up access to system busses
    8. Setup a user interface for BIOS configuration
  4. The BIOS runs the video BIOS that stored on a chip on the video card (dedicated) or included in the BIOS (integrated).
  5. The BIOS looks for other device BIOSs and runs them (eg. IDE/ATA hard disk BIOS).
  6. The BIOS displays a start-up screen allowing access to BIOS configuration.
  7. The BIOS performs other tests like a memory check and displays the results to the screen.
  8. The BIOS tests and configures hardware like hard drives, COM and LPT ports.
  9. The BIOS detects and configures Plug and Play devices.
  10. The BIOS displays a summary screen.
  11. The BIOS determines the boot drive.
  12. The BIOS locates the boot sector on the drive.
  13. The BIOS loads the boot loader code in the boot sector into memory and starts running the boot loader.
  14. The boot loader loads and starts running a second-stage boot loader like GNU GRUB, located in the master boot record in the first sector of the bootable drive.
  15. The second-stage boot loader loads the file system drivers, displays a menu to choose a kernel and loads the kernel and passes control to the kernel.

The Kernel

An operating systems contains numerous programs that together manage the resources of the computer.  The primary program in an operating system is called the kernel.  The kernel handles the following operating system functions (among others):

  • Process creation and CPU scheduling
  • Memory management
  • Interprocess communication
  • Device I/O (including networks)
  • Managing the file systems

Throughout the semester, we’ll be discussing aspects common to all operating systems.  But to see how we, as programmers, can utilize the services an operating system provides, we’ll be using the Linux operating system.  As such, it may be useful to refer to the various articles found here which which discuss many aspects of the Linux operating system and these which focus on the Linux kernel.

Loading the Linux Kernel

The Linux kernel is loaded in two stages:

  1. The kernel is loaded into memory as a compressed image file (bzImage or zImage). It is decompressed, a few functions such as basic memory control are set up and control is switched to the kernel by calling startup().
  2. startup() (also called process 0) established memory management, detects and configures hardware capabilities then calls start_kernel().
  3. start_kernel() performs a wide range of initializations, then find, loads, decompresses and starts Initrd.
  4. Initrd loads all necessary drivers. Next, it initializes virtual devices related to the file system.  Then it creates a root device and mounts the root partition.  At this point kernel is loaded into memory and operational.

The kernel, as well as the various subsystems started by the kernel, stay loaded in RAM while the computer is running.

The First Process, Systemd

While the kernel performs the core functions of the operating system, other programs are needed to make the system usable.

On most Linux systems today, the kernel starts systemd, a program that:

  • Manages on-demand starting of daemons like windowing system
  • Manages network configurations
  • Manages user sessions
  • Manages the console
  • Manages virtual devices (/dev)
  • Contains a cron-style task scheduler
  • Starts an event logging facility
  • Provides system state snapshot and restore
  • Allows power management
  • Becomes parent of orphaned children.

These system processes are usually performed by daemon processes.  A daemon is a process that runs in the background without user interaction.

Systemd, initially released in 2010, replaced the inherited initd process. Most major Linux distributions have adopted systemd.

OSX has a similar daemon called launchd – but is not so ambitious.

Systemd has PID 1.  If a parent of a child process dies, systemd becomes the child’s parent.   When a process dies, systemd reclaims its resources.

© 2018, Eric. All rights reserved.