Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Search:

CA216      CA249      CA318

CA400      CA651      CA668


OS and hardware

The fundamental job of an OS is to make the hardware usable for programs.
To do this, it needs to understand the properties of its different forms of storage (in particular the access speeds and volumes).
This is the "memory hierarchy" (see below).



Hardware v. Software

First we consider what is a program anyway, and how can a program be implemented.



What is a Program?

A list of instructions. A precise definition of what is to be done, as opposed to an English language description of what is to be done. A precise description is an algorithm, a recipe that can be followed blindly by a machine. A list of instructions to be executed one by one by a machine that has no memory of past instructions and no knowledge of future instructions.

There are many processes that we observe in nature (animal vision, language use, consciousness) and invent in culture (calculating prime numbers, sorting a list). Some we have converted to algorithms. Some remain in the domain of an English language description.

The Church-Turing thesis claims that "Any well-defined process can be written as an algorithm".



How is this Program, this list of instructions, to be encoded?

What (if any) is the difference between the machine and the program?
Many possibilities:


  1. Hardware (mechanical/electronic) is specially constructed to execute the algorithm. All you do is turn the machine on.
    e.g. Searle's "Chinese Room" thought experiment.
    (Hardware does not have to be general-purpose. Hardware can encode any algorithm at all.)


  2. Hardware is specially constructed to execute the algorithm, but there is some input data which is allowed to vary. This input data is read at run-time by the machine.
    e.g. Lots of machinery in factories and transport, calculators, clocks, (old) watches, (old) mobile phones.
    e.g. Many computer networking algorithms in routers (such as error-detection and error-correction) are done in hardware since they are run billions of times.


  3. Hardware is a general-purpose device, and the program, as well as the input data, is read at run-time by the machine.
    e.g. Every normal computer.

    A general-purpose device implements a number of simple, low-level hardware instructions (the instruction set) that can combine (perhaps in the millions) to run any algorithm.
    Human programmer might write program in the hardware instructions themselves.
    Or might write program in High Level Language. Compiler translates this into low-level instructions for the particular hardware.

    
    

    The complete Intel x86 instruction set (the start of the popular x86 CPU family).
    For full reference guide, see Intel manuals for the x86-64 architecture.


    
    
    If you write direct in the low-level instructions, program likely to be much more efficient. But you can only run the program on that particular hardware.
    If you write in a HLL, the same program can be recompiled into the low-level instruction set of a different machine, which is an automated process, and much easier than having to re-write the program from scratch.

    One HLL instruction like x := x+y+5 may translate into many low-level instructions:

    find the memory location represented by "x"
    read from memory into a register
    do the same with "y" into another register
    carry out various arithmetic operations
    retrieve the results from some further register
    write back into a memory location
    



CISC v RISC

There is a body of theory, Computability theory, showing what set of low-level instructions you need to be able to run any algorithm.

We can have pressure to:


As Operating Systems have evolved over the years, they constantly redefine the boundary between what should be hardware and what should be software.




The standard model for a Computer System

We have different types of Computer memory.
Permanent v. Temporary.

  1. Program is kept until needed on some permanent (or "non-volatile") medium (hard disk, flash drive, DVD, backup tape).
    "Permanent" means retains data after power off.

  2. To run the program, it is loaded into some temporary (or "volatile") but faster medium (RAM).
    Temporary data structures and variables are created, and worked with, in this temporary medium.

  3. In fact the CPU may not work directly with this medium, but require that for each instruction, data is read from RAM and loaded temporarily into an even faster, volatile medium (registers).
    e.g. To implement X := X+1, where program variable X is stored at RAM location 100:
    		MOV 	AX, [100]
    		INC 	AX
    		MOV 	[100], AX
    

  4. The results of the program are output either to some temporary or permanent medium.

  5. When the program terminates, its copy (the instructions) in the temporary medium is lost, along with all of its temporary data and variables. The long-term copy survives however, on the permanent medium it was originally read from.




Memory hierarchy



The memory hierarchy in computer architecture.
Credit here.






Up and down the memory hierarchy: Higher speed - Lower volume



A typical computer: MacBrook Pro.
Spec (highest values):
4 M cache memory.
8 G RAM memory.
1 T disk.
Shows the memory hierarchy of speed and volume.





The multi-tier model is a practical necessity, not a mathematical necessity

The multi-tier model is necessary to make machines work in practice, with the storage hardware that exists.
Mathematically, a multi-tier system is not needed to run a program.
Consider the following.

If RAM was as fast as registers


If disk was as fast as RAM


Thought experiment



Feeds      w2mind.org

On Internet since 1987.