COSC243 Part 2: Operating Systems - Department of Computer ... · COSC243 Part 2: Operating Systems...

29
COSC243 Part 2: Operating Systems Lecture 14: Introduction, and history of operating systems Zhiyi Huang Dept. of Computer Science, University of Otago Zhiyi Huang (Otago) COSC243 Lecture 14 1 / 27

Transcript of COSC243 Part 2: Operating Systems - Department of Computer ... · COSC243 Part 2: Operating Systems...

COSC243 Part 2: Operating SystemsLecture 14: Introduction, and history of operating systems

Zhiyi Huang

Dept. of Computer Science, University of Otago

Zhiyi Huang (Otago) COSC243 Lecture 14 1 / 27

General info

Lecturer:Zhiyi HuangOffice 126, Owheo BuildingEmail: [email protected]: 479 5680.Teaching fellow: IainOffice G37A, Owheo BuildingEmail: [email protected]: 479 8584.Textbook:Operating System Concepts with Java(8th Edition)A. Silberschatz, J. Galvin and G. Gagne.John Wiley (2009)

Zhiyi Huang (Otago) COSC243 Lecture 14 2 / 27

Lectures

Will use a small teaching OS xv6 to explain concepts:https://github.com/zhiyihuang/xv6_rpi2_portParticipate, think, criticize, learn!Not all material can be covered in lectures. You are expected to do12hrs/wk for this course, leaving 6hrs for readings andassignments.Any readings are examinable!A copy of the lecture notes will be available on the coursewebpage before each lecture.

Zhiyi Huang (Otago) COSC243 Lecture 14 3 / 27

Tutorials and internal assessment

Tutorials are an integral part of the course.The tutorial for each lecture will be available on the coursewebpage before each tutorial.Each tutorial is worth 0.5%. This mark is awarded for

A quiz at the beginning of the tutorial;Participation in the rest of the tutorial.

Summary of internal assessment:Tutorial marks: 10% in total.Data representation test in Tutorial 3A: 10%.CPU scheduling test in Tutorial 11A: 10%.Total: 30%.

Zhiyi Huang (Otago) COSC243 Lecture 14 4 / 27

COSC243 Course overview

Introduction (1 lecture): Ch1(1-8)Process Management (5 lectures)

System Structure and Processes: Ch2(1-9),Ch3(1-2)Threads and data sharing: Ch4(1-4)Scheduling: Ch5(1-3,7)Synchronisation: Ch6(1-7)Deadlocks: Ch7

Memory Management (2 lectures)Main memory: Ch8(1-6)Virtual memory: Ch9(1-7)

File System Interface (1 lecture): Ch10(1-5),Ch11(1-4)I/O Management (2 lectures)

I/O systems: Ch13(1-4,7)Mass storage: Ch12(1-4)

Zhiyi Huang (Otago) COSC243 Lecture 14 5 / 27

Learning about Operating Systems

Knowing about Operating Systems will change the way you workwith a computer.

Knowing about low-level architecture issues doesn’t make a bigimpact on how you use a computer day-to-day. But knowing aboutoperating systems does.

Getting to grips with terminology. . .Some gobbledegook:

“One multi-threaded process uses fewer resources thanmultiple redundant processes, including memory, open files,and CPU scheduling. For example, as Solaris evolves,network daemons are being rewritten as kernel threads, toincrease greatly the performance of those network serverfunctions.”

(From an earlier edition of Silberschatz et al.)

Zhiyi Huang (Otago) COSC243 Lecture 14 6 / 27

What is an Operating System?

Defn 1: (protected intermediary) an operating system is a programwhich acts as an intermediary between the hardware and the user.

What Andrew was

user nuser 2user 1 . . . .

computerhardware

OPERATING SYSTEM

system and application programs

text editor databaseprogram

compiler

What I’ll betalking about. talking about.

An operating system makes life more convenient for the user, becauseshe doesn’t have to operate at the level of machine instructions.

Zhiyi Huang (Otago) COSC243 Lecture 14 7 / 27

What is an Operating System?

Defn 2: (resource manager) an operating system is a program thatcontrols all of the system’s resources, and decides how these are to beallocated.

The resources of a computer system include. . .CPU TIMEMEMORY /STORAGECONTROL OF I/O DEVICES

One role of an operating system is to improve the efficiency with whichthe computer’s resources are used, if there’s heavy demand on them.

Zhiyi Huang (Otago) COSC243 Lecture 14 8 / 27

What is an Operating System?

Defn 3: (OS kernel) an operating system is a program which is alwaysrunning on a machine while it is in operation.

When the machine is started up, a bootstrap program is run, toinitialise various things, and then the OS kernel is loaded andexecuted.The OS kernel is the code running with the highest privilege in themachine, accessing hardware directly and handling servicerequest (aka system calls) from user applications.The OS kernel basically cycles waiting for events to occur, e.g.interrupts or system calls at the background, but at the foregroundscheduling processes in a loop.

Zhiyi Huang (Otago) COSC243 Lecture 14 9 / 27

Kernel Space and User Space

Kernel space is the protected space where software has theprivilege to access any hardware.User space is the non-privileged space where software cannotaccess hardware directly unless permitted otherwise by the OSkernel.The OS kernel is run in the kernel space, while all other softwareare run in the user space.The CPU can tell if the software is run in the kernel space or theuser space by just checking one bit in its status word.OS kernel changes the bit when it switches to non-privilegedsoftware.When an interrupt or system call occurs, the bit is set to kernelspace.

Zhiyi Huang (Otago) COSC243 Lecture 14 10 / 27

What is an Operating System?

Defn 4: (different OS designs) an operating system is MS-DOS,Windows’98, UNIX, MacOS, etc.

This isn’t just a kernel program; it also includes a whole set ofapplication programs that are compatible with this kernel and aretypically used in a particular environment.

This is a colloquial use of the word operating system, and we won’t beusing it.

Zhiyi Huang (Otago) COSC243 Lecture 14 11 / 27

What is an Operating System?

Here’s the definition which we’ll use to structure the course:

Defn 5: an operating system is a program that manages the differentaspects of the operation of the machine and runs with the highestprivilege in a protected domain.

Manages processes running on the machine.Manages data storage like RAM and file systems on the machine.Manages input/output devices associated with the machine.Manages networks and communications with other machines.Manages the user interface.Manages security and protection issues.

Zhiyi Huang (Otago) COSC243 Lecture 14 12 / 27

Process Management

Defn: a Process is a program in execution.

A program is not a process! A program in execution is.Process management involves:

creating and deleting processesscheduling processessuspending and resuming processesprocess synchronisationprocess communicationdeadlock handling

Zhiyi Huang (Otago) COSC243 Lecture 14 13 / 27

Storage Management

The term ‘storage’ covers primary storage (main memory),secondary storage (hard disk), tertiary storage (floppy disks,tapes, CDs).Storage management involves:

Allocating and deallocating storageKeeping track of storage in use and free storageTransferring data between primary and secondary storage

Defn: the file system is the mechanism by which the useraccesses/manipulates stored data in secondary storage like hard disk.

Zhiyi Huang (Otago) COSC243 Lecture 14 14 / 27

I/O Device Management

A computer system can include a very wide range of I/O devices:keyboards, mice, printers, hard disks, CD-roms, etc etc etc.

I/O device management includes tasks like:tracking the status of each deviceallocating devices to particular processesdeallocating devicesscheduling tasks for individual devices (e.g. disk scheduling)these functions are built into modules called device drivers; eachdevice needs one device driver to manage the hardware andserve the requests from user applications via the OS kernel.

Note: we are not going to cover networks much in this paper.

Zhiyi Huang (Otago) COSC243 Lecture 14 15 / 27

User Interface

Defn: the shell is the program through which the user interacts withthe operating system.

Two common types of shell:Icon-based point-and-click system (e.g. MacOS, MS Windows)Simple to learn and use.Keyboard-entered commands (e.g. UNIX)Harder to learn, but more powerful and flexible.

The shell is (obviously) the aspect of an operating system which ismost evident to the user. But in fact it’s only a very small part of it.

Note: we are not going to cover security much in this paper.

Zhiyi Huang (Otago) COSC243 Lecture 14 16 / 27

The first computer system (1945)

Zhiyi Huang (Otago) COSC243 Lecture 14 17 / 27

The first computer system

The first computers didn’t have operating systems:there was no ‘intermediary system’ between the programmer andthe hardwarethe programmer gave instructions directly to the CPU.

However, this meant that the CPU was idle for most of the time.

Zhiyi Huang (Otago) COSC243 Lecture 14 18 / 27

Batch operating systems

The first operating systems were introduced to increase the efficiencyof (I/O) processes.

Programmers didn’t deal directly with these machines: instead,they prepared their programs as ‘jobs’, and submitted their jobs tooperators. It wasn’t possible to interact with a program while it wasexecuting.Operators grouped jobs together and submitted batches of jobs tothe machine. The computer then needed an operating system totransfer control automatically from one job to another.

These early batch operating systems were still inefficient:I/O processing is still very slow in comparison to CPU processing;While I/O is occurring, the CPU is still idle.

Zhiyi Huang (Otago) COSC243 Lecture 14 19 / 27

Spooling (Simultaneous Peripheral Operations OnLine)

A solution to the I/O bottleneck is to perform I/O for one job J1 at thesame time as the CPU is executing another job J2. This is known asspooling.

In this scenario, we need a secondary storage medium:somewhere to store the jobs being input to the system;somewhere to store the output from jobs in the system.

The secondary storage medium is a disk.

PrinterCPUCard Reader

memory

Zhiyi Huang (Otago) COSC243 Lecture 14 20 / 27

Spooling (Simultaneous Peripheral Operations OnLine)

A solution to the I/O bottleneck is to perform I/O for one job J1 at thesame time as the CPU is executing another job J2. This is known asspooling.

In this scenario, we need a secondary storage medium:somewhere to store the jobs being input to the system;somewhere to store the output from jobs in the system.

The secondary storage medium is a disk.

PrinterCPUCard Reader

memory

Zhiyi Huang (Otago) COSC243 Lecture 14 20 / 27

Spooling (Simultaneous Peripheral Operations OnLine)

A solution to the I/O bottleneck is to perform I/O for one job J1 at thesame time as the CPU is executing another job J2. This is known asspooling.

In this scenario, we need a secondary storage medium:somewhere to store the jobs being input to the system;somewhere to store the output from jobs in the system.

The secondary storage medium is a disk.

CPUCard Reader Printer

Disk

memory

Zhiyi Huang (Otago) COSC243 Lecture 14 20 / 27

The Job Pool

Spooling introduces a key concept for operating systems: the job pool.

CPU

Job3 Job3..Job1Disk

memory

We can have many jobs spooled onto the disk, all waiting to beexecuted. The operating system has to decide which one to run next.

There are still inefficiencies in this setup.Jobs often have to wait for an I/O task to complete.While this is happening, the CPU is again idle.

Zhiyi Huang (Otago) COSC243 Lecture 14 21 / 27

Multiprogrammed Batch Systems

In a multiprogrammed batch system,several jobs are held in main memory;when one job has to wait for some I/O task, the operating systemswitches the CPU to another job, keeping track of where it left offthe first job.

This way, the CPU can be busy for more of the time.

Operating System

...

...

I/O

...

...

...

I/O

...

I/O

...

I/O

...

...

Job 2

Job 4

Job 5

Main memory

CPU

DiskJob 1

Job 3

In this scenario, the operating system has quite a lot of responsibility.Zhiyi Huang (Otago) COSC243 Lecture 14 22 / 27

Time Sharing Systems

So far we have just been considering batch (i.e. non-interactive)programs. However, the concept of multiprogramming can be appliedto interactive programs too.

An interactive program is constantly checking for user input whileit is running.If several interactive programs are multiprogrammed, and the CPUswitches fast between them, they behave as though they arebeing run independently, on several (slower) CPUs.

This type of system is called a time-sharing, or multitasking system.

Another reason for the big mainframes using time sharing is that CPUswere very expensive, and it paid to be able to share a single CPUamong several users.

Zhiyi Huang (Otago) COSC243 Lecture 14 23 / 27

Personal Computer Systems

In the 70s, it became economically feasible to have a single computerfor each user.

Early PC systems had no need for multi-tasking; only 1 process ata time. Hence they just required a simple operating system.MS-DOS is a product of this era.

As PCs became more powerful, it became feasible to include moresophisticated O/S services on PCs (e.g. multi-tasking).

The central concern is no longer just CPU utilisation: equallyimportant are user interface issues. (Even a single user wants lotsof interactive jobs running simultaneously.)Operating systems of this kind include MacOS, MicrosoftWindows, UNIX.

Zhiyi Huang (Otago) COSC243 Lecture 14 24 / 27

Parallel Systems and distributed systems

In a parallel operating system, there are multiple CPUs.The CPUs share a common bus, clock, memory, and devices.Improvements in performance, and in reliability.Some extra factors to consider:

Special techniques are required to ensure no conflicts arise (e.g.writing to disk at the same time).The increased throughput isn’t linear on the number of processors.

In a distributed system, computation is distributed among severalprocessors.

Processors do not share memory or a clock.They communicate via data lines.Examples include a LAN, the WWW.Advantages are similar to the advantages of parallel systems.

Zhiyi Huang (Otago) COSC243 Lecture 14 25 / 27

Real-time systems

In some domains, there are rigid time requirements for processes tocomplete. For these domains, a real-time operating system is required.

Hard real-time systems: guarantee that jobs be completed withinspecified times. (This typically means that advancedoperating-system features aren’t used.)Soft real-time systems: some jobs have higher priorities thanothers, and high priority jobs are processed preferentially.

Zhiyi Huang (Otago) COSC243 Lecture 14 26 / 27

Summary and reading

Types of operating system:Batch systemsTime sharing systemsPersonal computer systemsParallel systemsDistributed systems, real time systems

For this lecture, you should read Chapter 1 (Sections 1-8).For next lecture:

1 Read Chapter 2 (Sections 1-8) and Chapter 3 (Sections 1-2).

Zhiyi Huang (Otago) COSC243 Lecture 14 27 / 27