Computer Architecture for IB

Page 1

IB Computer Science Topic 2 Computer Organisation 2.1 Computer Architecture Computers are electronic devices; fundamentally the gates and circuits of the CPU control the flow of electricity. We harness this electricity to perform calculations and make decisions. Understanding the architecture of the computer is almost equal parts Computer Science and equal parts Electrical Engineering. Before going too deep into this part of the course, it is useful to have a fundamental understanding of how the binary number system works as this section explores how the computer use electric signals to represent and manipulate binary values. Any given electric signal has a level of voltage. As we know binary consists of 2 values, 1 and 0 or high and low to think of it another way. The tricky thing is representing this in voltage. Computers consider a signal of between 0 and 2 volts to be “low” and therefore a 0 in binary. The voltage level between 2 and 5 is considered “high” and therefore is 1. Gates are devices that perform basic operations on electrical signals. Gates can accept one or more inputs and produce a single output signal. Several types of gate exist but we will only consider the 6 fundamental types. Each gate performs a particular logical function. Gates can be combined to create circuits. Circuits can perform one or more complicated tasks. For example, they could be designed to perform arithmetic and store values. In a circuit, the output value of one gate often becomes the input for another. The flow of electricity in circuits is controlled by these gates. George Boole, a nineteenth century mathematician, invented a form of algebra in which functions and variables can only have 1 of 2 values (1 and 0). His notation is an elegant and powerful way to demonstrate the activity of electrical circuits. This algebra is appropriately named Boolean algebra. A logic diagram is a way of representing a circuit in a graphical way. Each gate is represented by a specific symbol. By connecting them in various ways we can represent an entire circuit this way. A truth table defines the function of a gate by listing all possible combinations of inputs and the output produced by each. The tables can have extra rows added to increase the complexity of the circuit they represent.


Gates Gates are sometimes referred to as logic gates as they each perform a single logical operation. The type of gate determines the number of inputs and the corresponding output. NOT Gate This gate takes a single input and gives a single output. Below are three ways to represent the NOT gate, the truth table (Boolean notation), the logic diagram symbol (real and IB forms) and the Boolean expression. Note: the input in each case is A and the output is X. The NOT gate simply inverts the input it is given. As it only has one input, there are only 2 possibilities for input. Boolean Expression X = ‘A

Logic Diagram Symbol This is acceptable in IB

Truth Table

NOT

A 0 1

However, the actual symbol is this:

X 1 0

AND Gate This gate differs from the NOT gate in many ways. Firstly it accepts two inputs. Both inputs have an influence on the output. If both inputs in the AND gate are 1, then the output is 1, otherwise the output is 0. Note the Boolean algebra symbol for AND is ∙, sometimes an asterisk is used and at other times the symbol is ignored entirely e.g. X = AB Boolean Expression

X=A∙B

Logic Diagram Symbol In IB, this is acceptable AND But the actual symbol is this

A 0 0 1 1

Truth Table B 0 1 0 1

X 0 0 0 1


OR Gate Like the AND gate, the OR gate has 2 inputs. If both inputs are 0, then the output is 0. In all other cases the output is 1. The Boolean algebra symbol for OR is +. Boolean Expression

Logic Diagram Symbol For IB, you can use this:

X=A+B OR

A 0 0 1 1

Truth Table B 0 1 0 1

X 0 1 1 1

However, the actual symbol is this:

XOR Gate The eXclusive OR gate again uses 2 inputs. It behaves only very slightly differently to the OR Gate. It requires that only one of the inputs be 1 to produce an output of 1. If both are 0, the output is 0, the same when both inputs are 1. You can see the symbol for XOR is the symbol for OR inside a circle. Boolean Expression

X = A ⊕B

Logic Diagram Symbol For IB, you can use this: XOR However, the actual symbol is this:

A 0 0 1 1

Truth Table B 0 1 0 1

X 0 1 1 0

NAND and NOR Gates The final 2 gates we will look at are the NOR and NAND gates. Each accepts 2 inputs. They are essentially the opposite of AND and OR gates respectively. E.g. They take the output produced by these gates and invert it.


NAND Boolean Expression

X = (A ∙ B)’

Logic Diagram Symbol For IB you can use this: NAND However, the actual symbol is this:

A 0 0 1 1

Truth Table B 0 1 0 1

X 1 1 1 0

A 0 0 1 1

Truth Table B 0 1 0 1

X 1 0 0 0

NOR Boolean Expression

X = (A + B)’

Logic Diagram Symbol For IB, you can use: NOR Bu the actual symbol is this:

You can see that there are no specific symbols for NAND and NOR gates in Boolean. We rely on the AND and OR expressions combined with a NOT to define them. You can also see that the Logic Diagram Symbols are like hybrids of AND or OR gates with a NOT. In fact, the circle before the output is known as the inversion bubble. Outline the architecture of the central processing unit (CPU) and the functions of the arithmetic logic unit (ALU) and the control unit (CU) and the registers within the CPU. Circuits Circuits can be put into 2 categories, combinational and sequential. In a combinational circuit, the input values explicitly determine the output, in a sequential circuit, the output is a function of the input values as well as the existing state of the circuit, and so sequential circuits usually involve the storage of some information.


Combinational Gates are combined into circuits, where the output of one gate is the input to another. Consider the following diagram: A B

D

AND

OR AND

C

X

E

You can see that the output of the AND gate (D, inputs A, B) is the first input to the OR gate, and the second input comes from the AND gate (E, inputs A, C). What this means is that for the overall output to be 1, either A∙B must be 1 or A∙C must be 1. We can represent this in a truth table like so, because there are three inputs to the system, there are eight possible combinations to consider: A 0 0 0 0 1 1 1 1

B 0 0 1 1 0 0 1 1

C 0 1 0 1 0 1 0 1

D(A∙B) 0 0 0 0 0 0 1 1

E(A+B) 0 0 0 0 0 1 0 1

X(A∙B + A∙C) 0 0 0 0 0 1 1 1

We can express this truth table as: (A∙B + A∙C) The Boolean expression for the circuit is an interesting one, and one that we should look at more carefully. We could actually use some rules to generate an equivalent circuit. That’s the beauty of Boolean algebra; you can apply provable mathematical rules. These can be used to reduce the complexity of circuits. We can apply the distributive law: (A∙B + A∙C) = A∙ (B+C)


Thus reducing the circuit to this:

A

X

OR

B C

AND

If we look at the truth table for this circuit, it should prove the law: A 0 0 0 0 1 1 1 1

B 0 0 1 1 0 0 1 1

C 0 1 0 1 0 1 0 1

B+C 0 1 1 1 0 1 1 1

A∙(B+C) 0 0 0 0 0 1 1 1

The result in column 5, exactly matches the result in the previous truth table, proving the distributive law. Here are some other laws worth knowing about. You can try to prove them yourself by creating the truth tables. Property Commutative Associative Distributive Identity Complement De Morgan’s

AND A∙B = B∙A (A∙B) ∙C = A∙(B∙C) A∙(B+C) = A∙B + A∙C A∙1 = A A∙(A’) = 0 (A∙B)’ = A’ + B’

OR A+B = B+A (A+B) + C = A+(B+C) A+(B∙C) = (A+B) ∙ (A+C) A+0 = A A+(A’)=1 (A+B)’ = A’ ∙ B’

Adders The most basic of operations a computer can perform is an addition. Fundamentally, this happens in binary, and the simplest of additions would be to add two binary digits together. Like addition in any number bas, there is the potential for a carry to take place. We can draw a truth table for the addition of two binary values: A 0 0 1 1

B 0 1 0 1

Sum 0 1 1 0

Carry 0 0 0 1


You can see that the sum column is the same as an XOR, whilst the Carry column matches the pattern for an AND. We can use this to construct the logic diagram for the adder: A B

XOR

Sum

OR

Carry

This circuit will happily sum two single binary digits, but will not work for binary numbers of more than one digit as it takes not account of a carry in. It is in fact a half-adder; we can combine two of them to create a full-adder that takes account of a carry in. It should also be noted that circuits play another important role: they can store information. These circuits form a sequential circuit, because the output of the circuit also serves as input to the circuit. E.g. the current state of the circuit is used in part to determine the next state. This is how memory is created. Integrated circuits (chips) are pieces of silicon on which multiple gates have been embedded. The silicon is mounted on plastic and has pins that can be soldered onto circuit boards or inserted into appropriate sockets. The most important integrated circuit in the computer is the CPU. The CPU The CPU is essentially an advanced circuit with input and output lines. Each CPU chip contains multiple pins through which, all communication in a computer system takes place. The pins connect the CPU to memory and I/O devices, which at a fundamental level are actually circuits themselves. Von Neumann Architecture In 1944-1945 there was a realisation that the data and instructions needed to manipulate it were logically the same. This also meant that they could be stored in the same place. The computer design built upon this principle became known as the von Neumann architecture and is still the basis for computers today. In this architecture there are some distinct features:     

There is a memory unit that holds both data and instructions There is an arithmetic/logic unit that is capable of performing arithmetic and logic operations on data There is an input unit that moves data from the outside world into the computer An output unit that can move results from inside the computer to the outside world There is a control unit that acts like a conductor, ensuring all of components work in concert


The structure of such a computer might look something like this:

Input

Output

CPU Arithmetic /Logic Unit

Control Unit IR

PC

MAR

Address bus

MDR

Cache

Data bus Primary Memory

Arithmetic/Logic Unit (ALU) This unit is capable of carrying out basic arithmetic such as adding, subtracting, dividing and multiplying 2 numbers. It is also capable of performing logic operations such as AND, OR and NOT. The ALU operates on ‘words’ a natural unit of data associated with a particular computer design. Historically, the ‘word length’ of a computer is the number of bits that can be processed at once by the ALU. It should be noted that Intel now define ‘word length’ as 16 bits and their processors can work with double words(32 bits) and quadwords(64 bits). We will use ‘word length’ in its traditional sense. The ALU also has a small number of special storage units called registers. Registers can store one word temporarily. For example, consider the following calculation: (value1 + value2) * (value3 + value4) We know that the ALU can only deal with 2 numbers at one time, so the outcome of value1 + value2 needs to be stored before the ALU can add value3 and value4. Both outcomes are then required to do the multiplication. Rather than storing the values in memory and then having to retrieve them when required, the registers can be used to store the results and then retrieve them as necessary. Access to registers is much quicker than access to memory. Control Unit This is the organising force in the computer, it is in charge of the fetch-execute cycle (discussed further on in these notes). The control unit contains 2 special registers as you can see in the diagram, the PC –program counter and the IR- instruction register. The IR contains the current instruction being executed and the PC the address of the next instruction to be carried out.


Buses This diagram shows how a bus is used to allow data to flow through a von Neumann machine.

Input Devices

CPU

Main Memory

Output Devices

Bus

This is a very simplified view of how buses work. There are a number of different buses connecting each component. Buses allow data to travel throughout the computer. A bus is a collection of wires, meaning that if your bus is 16-bits wide, 16 bits can be transmitted at a single time. If your computer has a word length of 16 bits, then it is very helpful if your bus is the same width. If the bus was 8 bits wide for example, it would take two operations to move that data from memory to the ALU. Buses can carry three types of information: data, address and control. Address information is sent to memory to tell it where to store data or where to retrieve it from. Address information might also indicate a device that data should be sent to. Data can then flow to memory and I/O from the CPU. Control information is used to manage the flow of address and data, typically the direction of the flow is managed in this way. Address Bus and Data Bus Buses are collections of wires through which data can be sent for example: Single wire: 10011100

Destination

You can see that in order to send an 8-bit number through a single wire, you would have to do it sequentially, this means you would have to wait until the last bit arrived. By using a bus, a parallel group of wires, the data can be sent simultaneously, so it all arrives at the same time: Bus 1

0

0

1

1

Destination

1

0

0


MAR/MDR These are the Memory Address Register and Memory Data Register respectively. The MAR is where the CPU sends address information when writing to or reading from memory. The MAR specifies to memory where the data should go or come from. The MDR is where the CPU sends data to be stored in memory and where the data being read from memory arrives in the CPU. It may be more useful to see how these registers play a big part in the stored program concept or Fetch-Execute Cycle, a little later in these notes. Cache On the diagram you can see an area of cache connected to the CPU. Many modern CPU architectures make use of cache to speed things up. Cache is a small amount of fast access memory where copies of frequently used data are stored. This might be values that have been computed previously or duplicates of original values that are stored elsewhere. The cache will be checked before accessing primary memory, which is a time consuming process, as the buses tend to slow things down. The CPU will check the cache to see whether it contains the data required, if does then we get a cache hit and access to data without using the buses. If it doesn’t then access to primary memory becomes a necessity. RAM or ROM? As mentioned previously, RAM and primary memory are considered to be the same thing. RAM stores programs and data whilst they are in use by the CPU; otherwise they are kept in secondary storage (hard disk). RAM is memory in which each location can be accessed, as well as being able to access each location; the contents can also be changed. You may want to visualise RAM like so:

Address 000 001 010 011 100 101

Content Instruction Instruction Instruction End Data Data

Of course the data and instructions would be stored as binary, but you can see that the instructions are stored contiguously and the data in a separate section of memory. This is helpful in the machine instruction cycle, as we can simply increment the pointer that keeps the place of the next instruction to be executed. The address is used to access a particular location in RAM, so the CPU needs to pass this information when it wants to read a location, and when it wants to write to a location.


ROM has very different behaviour to RAM. ROM stands for Read Only Memory; this means that the contents of ROM cannot be altered. The content of ROM is permanent and cannot be changed by stored operations. The content of ROM is ‘burned’ either at the time of manufacture or when the computer is assembled. RAM and ROM also differ in another basic property, RAM is volatile, and ROM is not. This means that whatever is in the contents of RAM when the computer is switched off, will not be there when it is restarted. ROM retains its contents even when the machine is turned off. Because ROM is stable it is used to store the instructions that the computer needs to start itself (bootstrap loader). Other frequently used software can be stored in ROM so that it does not have to be read into memory each time the machine is turned on. Primary memory is usually made up of a combination of both RAM and ROM. Machine Instruction Cycle A computer is a device that can store, retrieve and process data (remember the fundamental operations). Therefore all of the instructions it is given relate to these three operations. The underlying principle of the von Neumann machine is that data and instructions are stored in memory and treated alike. This means that both are addressable (see notes on primary memory). Instructions are stored in contiguous memory locations; the data to be manipulated is stored in a different part of memory. To start the Machine Instruction Cycle (Fetch-Execute Cycle) the address of the first instruction is loaded into the Program Counter. The cycle then follows 4 steps:    

Fetch the next instruction Decode the instruction Get data if needed Execute the instruction

Of course each of these is an abstraction of what actually takes place, so let’s look at each in a little more detail. Fetch the next instruction The PC contains the address of the next instruction to be executed. So the address from the PC is loaded into the MAR in order to access that location in memory, the address information travels along the address bus to main memory. The control unit tells memory that the CPU wishes to read the instruction at the address specified by the address bus. Primary memory accesses the contents of that memory location and sends the data to the CPU along the data bus. It arrives in the MDR where it is quickly passed to the Instruction Register to be decoded. Before decoding takes place, the Control Unit updates the address held in the PC to ensure it is for the next instruction. Decode the instruction In order to execute the instruction held in the IR, it first must be decoded to determine what it is. It could be an instruction to access data, from an input device, send data to an output device or to perform an operation on a value. The instruction is decoded into control signals. The logic circuitry in


the CPU determines which operation is to be executed. This shows why a computer can only execute machine language instructions that are written in its own native language. Get Data if needed If the instruction is to use the contents of a certain memory location and add them to the contents of a register, memory will have to be accessed again to get the contents of the memory location. Execute Instruction After being decoded and any data that is needed is accessed, the instruction can be executed. Execution usually involves the control unit sending signals to the appropriate part of the CPU or system. For example if the instruction is to add the values stored in 2 registers, the CU sends a signal to the ALU to do so. The next instruction might be to store the result in a register or even a memory location. After execution, the next instruction is fetched and the process begins all over again, until the last instruction has been executed. A useful animated version of the Machine Instruction Cycle can be found here:

Persistent Storage There are a few other terms by which Persistent Storage might be known: backing storage/secondary storage. They all refer to the same thing, a place where programs and data can be stored when they are not being processed or the machine is turned off. As data is read from and written to these devices, they could also be considered input and output devices. There are several types of persistent storage, the most popular is the hard-disk, usually installed by the manufacturer, and the typical size of these nowadays is 500GB-1TB. Let’s look at the hard-disk first. The hard disk has several moving parts. The disk itself has to spin at between 5400rpm-7200rpm, the small delay that you experience when accessing the hard-disk after an idle period is the time it takes for the disk to reach the required speed. The disk is made of magnetic material and the data is represented by magnetic charge (positive and negative charge lends itself nicely to our binary system of 2 states). Above the disk (platter) is a read/write head. It is fixed at one end and can move from the outside of the disk to the inside. The disk spins underneath to get the data required underneath the read/write head. With the speed of the disk and the read/write head about the width of hair away from it, you can understand how any violent movement could damage or corrupt the disk. The disk itself is divided up by sectors and tracks. This creates blocks; you can choose the size of these blocks when you format a hard-disk. The diagram on the right illustrates the division of the disk. The red section is a track; the yellow section is a block, created by the further division of the disk into sectors. It should be noted that this division is not a physical one, these lines are not scored on the disk; they are magnetic. This means we can re-format disks to use different file formats or to create


smaller or larger blocks. In order to provide the storage required for today’s computer users very often a hard disk contains several platters each with their own read-write head. These platters are stacked with little space between them. The diagram illustrates this arrangement. You can also see that both sides of the platter are utilised. In relation to the speed at which the CPU works, accessing the hard disk and the data therein is slow. This is due to a couple of factors. Firstly, the read-write head needs to be positioned over the correct track, this is called seek time. The disk then needs to spin in order to get the correct sector under the read-write head, called latency. The sum of latency and seek time is what we call access time, the time it takes for data to start being read. After we begin reading data there is of course the transfer rate, which is the rate at which data moves from the disk to memory. This is usually measured in Mbps (Mega-bits per second. Note: b = bits, B = bytes) Solid state disks (SSD) are gaining more prominence, they have no moving parts so are considered to be more robust than traditional hard-disks. They also come with the benefit of less power consumption, highly beneficial as computing moves ever more mobile, and they are faster. SSDs use electrical signals, gates and transistors to store data. How they work is beyond the scope of the course, but if you have an interest in how they work you can find out more here. Older Persistent Storage Some older technologies for persistent data storage include punch cards and paper tape. A more recent and sometimes still used technology is magnetic tape. A lot of back-up copies of servers are still committed to magnetic tape. Like hard disks, magnetic tape is read/written by passing through a read/write head. One of the drawbacks is that the data is stored and accessed sequentially. In other words, if you want to access a piece of data in the middle of the tape, you need to go through all the data that precedes it. More modern tape systems have functions to overcome this however, they can skip sections of the tape, but the tape must still pass through the read-write head.


Operating System Software can be divided into 2 categories, application software and systems software. Application software is written to address specific needs – to solve real world problems. Systems software manages a computer system at a more fundamental level. System software usually interacts directly with hardware and provides more functionality than the hardware itself does. The operating system is at the core of system software. It manages computer resources such as memory and I/O devices and provides the interface through which we as humans interact with the computer. The following diagram shows how the OS is positioned and related to all other aspects of the computer system.

Human Users

Application Software

Operating System

Other systems software

Hardware

The operating system manages hardware resources and allows application software to access system resources either directly or through other systems software. It also provides access to the computer system via an interface. This interface has evolved in look and input devices over time. If we look at MS-DOS, the pre-cursor to Windows, you can see it is a command drive interface. This meant that in order to use a computer, you had to learn at least a basic set of commands, this made them inaccessible to most people as they did not have the desire to invest the time necessary to use them proficiently for personal use.


This style of OS then evolved with the creation of the mouse. Users could point to things and click on them, this was a different, easier way to interact with the system. Windows XP is an example of the how the OS has evolved. To begin with, Windows was simply an interface for MS-DOS but more recent versions have moved away from this but still use DOS as part of the bootstrap system. This style of OS is often referred to as a WIMP environment (Windows Icons Menus Pointers). Of course the biggest change since the idea of GUI first appeared is the input devices we use. Touch is almost ubiquitous in smartphones nowadays but the idea of gesture is gaining traction too, especially low power consuming versions of gesture control. This has led to a change in the design of the GUI for operating systems, where icons for apps use a skeuomorphism approach. Smartphones run versions of operating systems that are tailored to their needs. For example, they have more constraints on memory use, power consumption and a smaller set of peripherals to deal with. Apple products run iOS which is derived from Mac OS. Android devices run the open source OS developed by Google, and is the most popular OS for hand held devices. Any given operating system manages resources in its own way. The goal for you is to understand the common ideas that apply to all operating systems. If you are interested in the development and evolution of Operating Systems then read more here: http://en.wikipedia.org/wiki/History_of_operating_systems Multiprogramming, Memory Management and CPU Scheduling Operating systems have developed to allow multiple programs to reside in main memory at any one time. These programs compete for use of the CPU so that they can do what they need to do. This has created the need to manage memory to keep track of what programs are in memory and where they are. A key concept when referring to the OS is the idea of a process. A process is simply a program in execution. The process is a dynamic entity that represents the program whilst it is being executed. A process has a lifecycle, presented as a chart below:


The OS must manage these processes carefully; there might be many active processes open at once. If you open your task manager or equivalent, you will see which processes are active on your computer. As you can see, some processes might need input or to output, they may also need to wait on the results of some calculation. A process might also be interrupted during its execution. Think about playing Angry Birds on the MTR, if you get a call on your phone, the game will pause and you will be prompted to either answer or reject the call. This is an example of an interrupt, and Angry Birds becoming a process in “waiting”. Related to these management issues is the need for CPU scheduling, this determines which process will be executed at any point in time. Memory Management As mentioned earlier, multiple programs and their data will reside in memory at the same time, this gives us multi-programming. Therefore, the OS needs to be able to:  

Track how and where programs reside in memory Convert logical addresses into physical addresses

As we know from our programming experience, programs are filled with references to variables and to other parts of the code. When the program is compiled, these references are changed to actual addresses in memory where the data and code reside. Given that the compiler has no control over where in memory a program could end up, how will it know what address to use for anything? To overcome this, programs will need two kinds of address. A logical address (sometimes called a relative address). This specifies a location relative to the rest of the program but is not associated with main memory. A physical address refers to an actual location in main memory. When a program is compiled, references are changed to logical addresses. When the program is eventually loaded into memory, logical addresses are translated into physical addresses. This mapping is called address binding. Logical addresses mean that a program can be moved around in memory, as long as we keep track of where the program is stored, the physical address can always be determined. Let’s look at how this might work in a technique known as single contiguous memory management.


If we imagine main memory divided into 2 sections: OS

A

Application program

A+L

This method of management is so-called because the entire application is loaded into on large chunk of memory. To carry out address binding, all we need to do is take the operating system into consideration. Remember, the logical address (in our example denoted as L) is simply an address relative to the start of the program. So these logical addresses are created as if the program is loaded at location 0 in memory. To create a physical address, we add the logical address to the physical address. To be more specific, the OS in our example takes up the first section of memory, and the application is loaded at location A. We simply add the logical address to this value to give us the physical address (A+L) in the diagram. If we are even more specific, suppose the program is loaded at address 3000. When the program uses relative address 2000, it would actually be referring to address 7000 in physical terms. It doesn’t matter what address L is, as long as we kept track of A, we can always translate the logical address into a physical one. Of course, you might think, why not swap the OS and the application around so that it is loaded at 0, then the logical and physical address is the same. This is true but presents security issues, the application program might then try to access a location that is part of the OS and corrupt it, either by accident or maliciously. With the OS loaded where it is, all logical addresses for the application are valid, unless it exceeds the bounds of memory. This method of management is simple to implement but inefficient. It wastes memory space as the application is unlikely to need all of the memory allocated. Partition Memory Management The previous technique does not really allow for multi-programming. This technique addresses this. Applications need to share memory space with the OS and other applications. Memory can be partitioned into different portions. The size of these portions can be fixed or dynamic. If they are fixed, they do not need to be the same size, but the partitions are fixed at boot time. A process is loaded into a partition big enough to hold it. It is up to the OS to keep track of where partitions start and how long they are. Using dynamic partitioning, the partitions are created to fit the process that they will hold. The OS will keep a table of where partitions start and their length, but the values will change all the time as programs come and go.


OS

Process 1

Empty A Process 2 A+L

As with the contiguous approach, each of the programs being executed has its own logical addresses. The address binding technique is slightly different. The value A in this case is taken from the table that the OS maintains about where partitions begin. Let’s imagine that process 2 becomes active. The start of that partition is retrieved from the table and loaded to a special register called the base register. The value for the length of the partition is stored in another register called the bounds register. When address binding takes place, the physical address is first compared to the bounds register to make sure the address is not outside the partition, if it is not, the physical address is calculated by adding the value for the logical address to the value in the base register. There are 3 approaches to partition selection: 1. First fit – allocate to the first partition that it fits inside, works well in fixed partitioning 2. Best fit – allocate to the partition that is closest in size to the process(or smallest enough to hold it), works well in fixed partitioning, but in dynamic, it leaves small gaps that are not big enough to accommodate any other processes 3. Worst fit – the process is allocated to the largest portion big enough to hold it. This works well in dynamic partitioning, as it leaves gaps big enough to be usable by other programs later on.


Paged Memory Management This places more of a burden on the OS to keep track of allocated memory and to resolve addresses. There are many benefits to this approach and these are generally worth the effort. In this technique, main memory is divided into small fixed size blocks called frames. A process is then divided into pages, and we’ll assume these pages are the same size as a frame. When a program is to be executed, it is distributed to unused frames throughout memory. This means they may be scattered around and even out of order. To keep track of what is going on, the OS needs to keep a page-map table for each process. It matches a page to the frame it is loaded in. The diagram below illustrates this. Process 1 PMT Page Frame 0 5 1 12 2 8 3 22 Process 2 PMT Page Frame 0 4 1 7 2 13 3 1 4 31

Memory Frame Content 0 P2/Page 3 1 2 3 4 P2/Page 0 5 P1/Page 0 6 7 P2/Page 1 8 P1/Page 2 9 10 11 12 P1/Page 1 13 P2/Page 2

Address binding is a more complex process in this system. As in the previous methods, the logical address is an integer relative to the start of the program. This address needs to be modified into 2 values: a page number and an offset. The page number can be created by dividing the logical address by the page size. The page number is the number of times the logical address can be divided, the offset is the remainder. So if we take a logical address of 2301, where the page size is 1024. The page number is 2 and the offset 53(2301/1024 = 2 r 53). To create a physical address, the page number is looked up in the PMT to find the frame number in which it is stored. You would then multiply the frame number by the page size and then add the offset. So taking our previous example where the logical address was converted to <<2, 53>>. Let’s assume this refers to Page 2 of Process 2 above. Page 2 of process 2 is stored in Frame 13 of memory. So to get the physical address of where this is in memory we need to multiply by the size of the frames by the number of frames (1024 * 13 = 13,312) we then add the offset to this value (13,312 + 53 = 13,365). Therefore, the physical address of <<2, 53>> referring to Page 2 in process 2 is 13,365. The advantage of paging is that processes no longer need to be stored contiguously in memory and the process of finding available memory space is made easier as it is about finding lots of small chunks instead of having to find one large one to accommodate the entire process.


Process Management The OS must manage the use of the CPU by individual processes. To understand how this works, we must first appreciate the stages that a process goes through during its computational life. Processes move through specific states as they are managed. A process enters the system, is ready to be executed, is executing, is waiting for a resource, or is finished. The diagram below depicts this lifecycle:

A process with nothing preventing it’s execution is in the ready state. A process in this state is not waiting on an event to occur or data to be brought from secondary memory. It is waiting on it’s chance to use the CPU. A process that is executing/running is using the CPU. The instructions in the process are being executed by the fetch-execute cycle. A process in the waiting state is waiting for other resources, e.g. not the CPU. It may be waiting on a page to be brought into primary memory from secondary memory or another process to pass it a signal that it can continue. A process in a terminated state has completed execution and is no longer active. The OS no longer needs to keep information regarding the process. Process management is very closely linked to CPU scheduling, processes can only be in the running state if they can use the CPU. While running, a process may be interrupted by the OS to allow another process an opportunity on the CPU. In that case the process simply returns to the ready state. Alternatively, a running process might request a resource or require I/O to retrieve data or a newly referenced part of the process from secondary memory, in this case it moves to the waiting state. CPU Scheduling This is the act of determining which of the processes in the ready state should be moved to the running state. Algorithms to schedule this process make this decision.


CPU scheduling decisions take place when a process moves from the running state to the waiting state, or when it termintates. This type of scheduling is termed “non-preemptive scheduling”, this is because the new CPU process results from the activity of the currently executing process. CPU scheduling should also take place when a process moves from the running state to the waiting state or the ready state. This is called “preemptive scheduling” as the currently executing process(through no fault of its own) is preempted by the OS. Turnaround Time Scheduling algorithms are often evaluated using metrics, such as turnaround time for a process. This is the amount of time between when a proess arrives in the ready state and whn it exits the running state for the last time. On average, the smaller this value the better. Several different algorithms exist for the determination of which process should be chosen first to move to the running state. We will look at 3 and try to evaluate using turnaround time. First Come, First Served This operates like a queue. The processes are given CPU time in the order that they arrive in the running state. They retain access to the CPU unless it makes a request to a resource that forces a wait. This type of scheduling is non-preemptive Process P1 P2 P3 P4 P5

Service Time 140 75 320 280 125

If we represent this as a Gantt type chart to show when processes are executed it would look something like this: 140 P1

215 P2

535

815

P3

940

P4

P5

For the purposes of this example, let us assume that all processes arrive at 0. Therefore, the average time for them to move from ready to complete is (140+215+535+815+940 / 5 = 529) Shortest Job Next This algorithm looks at all the processes in the ready state and allows the process with the smallest service time to execute. It is also a non-pre-emptive algorithm. If we use the same set of processes as before for this algorithm, we will see the effects that this method of scheduling has: 75 P2

200 P5

340 P1

620 P4

940 P5


If we work out the average turnaround time in this instance (75+200+340+620+940 / 5 = 435). This is significantly better than the previous algorithm; however, there are some issues to consider. This algorithm relies on knowledge of the future. Essentially the OS estimates the time that a process will take based on the type of job and some other factors. If these estimates are wrong, the premise of the algorithm breaks down and the efficiency deteriorates. The algorithm is provably optimal, meaning that if we knew the service time of each job, the algorithm would produce the shortest turnaround time of all the algorithms we will consider. Round Robin This algorithm distributes processing time equally among all processes. The algorithm relies on timeslicing (a time slice is the amount of time the process receives before being returned to the ready state). The algorithm is pre-emptive, it returns processes to the ready state to give the next process its time-slice. This continues until each process gets enough CPU time to be completed and terminates. Let us assume that a time-slice is 50 and we use the same processes as the previous example 50

P1

325

P2

P3

P4

P5

P1

P2

515

P3

P4

P5

P1

6 4 0 P3

P4

P5

P3

P4

P3

P4

P3

9 2 0

9 4 0

P 4

P 3

Each process is given a time slice of 50, unless it doesn’t need it. Process 2 needed 75 units, therefore on its second time slice, will only require half the time and so terminates at 325. The average turnaround time here is (325 + 515 +640 + 920 + 940 /5 = 668) this is significantly worse that the other algorithms. This does not mean it is the worst of the three, which would be too general a claim based on a specific set of processes. The round robin algorithm is one of the most widely used; it supports all kinds of jobs and is considered the most fair. Application Software Application software is all the computer software that causes a computer to perform useful tasks beyond the running of the computer itself. You have experience of using these on an almost daily basis, from browsers to word processors, email clients to image editing. These applications are designed to help the user to perform singular or multiple related specific tasks. This software usually costs money, however there is a movement in the online community to provide free, open-source programs. These programs are often more limited than their paid for counterparts but the fact they are open-source means the community to embellish and improve them and re-distribute for public use. The user interface controls how you enter data or instructions and how information displays on the computer screen. Many of today’s software programs have a graphical user interface (GUI). A GUI combines text, graphics, and other visual images to make software easier to use. As mentioned previously, this can sometimes be called a WIMP environment (Windows Icons Menus Pointers).


Many of today’s applications could also be considered WYSIWYG (Whizzy Wig). Dreamweaver is a prime example of this. You drag and drop items and place them on the page where you think you want them to go in your web page. Dreamweaver then generates the HTML to make this happen. When you view the webpage in a browser, it normally looks the same as it did in Dreamweaver (What You See is What You Get). There are lots of common features in today’s applications. Consider the following screenshots:

The above is taken from Microsoft Word and shows the menus and toolbars. Let’s consider a different application from a different vendor:

This is from Photoshop CS6, and although the specific menus have different names, this feature and layout is very similar to MS Word. We have the menus along the top, with a toolbar underneath. The menus present commands for the user to select with the mouse pointer (previously these commands would need to have been remembered and entered using the keyboard). Expert users might make use of keyboard shortcuts to avoid the sometimes laborious process of navigating through menus and sub-menus. The toolbar provides a set of buttons, these buttons are usually designed to give a clue as to what function they perform e.g. the Print icon is of a printer. These buttons are created to give access to the most often used commands. Another area of similarity is the use of windows/dialogue boxes. The 2 images below show the similarity in the use of windows in the Windows and Mac OS respectively.

Windows and dialog boxes present the user with icons or buttons to select files or choose options. These choices are made using the mouse/pointing device. Previously, the user would have had to


use commands to navigate through the file structure to find files to open or to choose a location in which to save a file. There are obvious benefits to the common features of application software. If a user becomes an expert in one piece of software, they should be able to go to another application and figure out where they can look for most used commands and find different options in the menus. Compare this to command driven software; firstly, the user would need to learn all the commands. If they then moved on to another piece of software some of the commands might be the same as we have seen in the screenshots previously, but there would be new ones that would have to be learned. Using menus, the user can experiment and have access to all of the options by navigating through them. The common features of these applications make things easier for the “everyman� the non-expert who wants to use a computer but doesn’t have the time or desire to invest in becoming an expert user.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.