COMP2300/6300 Computer Organisation & Program Execution Dr Uwe - - PowerPoint PPT Presentation

comp2300 6300
SMART_READER_LITE
LIVE PREVIEW

COMP2300/6300 Computer Organisation & Program Execution Dr Uwe - - PowerPoint PPT Presentation

COMP2300/6300 Computer Organisation & Program Execution Dr Uwe Zimmer Dr Charles Martin Semester 1, 2019 1 info Make sure you pick up your jumper wires in your labyou cant do assignment 3 without them. Marks for Assignment 2


slide-1
SLIDE 1

COMP2300/6300

Computer Organisation & Program Execution Dr Uwe Zimmer Dr Charles Martin Semester 1, 2019

1

slide-2
SLIDE 2

info

Make sure you pick up your jumper wires in your lab—you can’t do without them. Marks for Assignment 2 coming soon. assignment 3

2

slide-3
SLIDE 3

Week 11: Operating Systems

3

slide-4
SLIDE 4

Outline

what is an OS? privilege levels processes & scheduling

4

slide-5
SLIDE 5

What is an OS?

5

slide-6
SLIDE 6

6

slide-7
SLIDE 7

talk

what is an operating system (OS)?

7

slide-8
SLIDE 8

…it’s a virtual machine

  • fering a more familiar, comfortable and safer environment for your programs to

run in memory management hardware abstraction process management inter-process communication (IPC)

8

slide-9
SLIDE 9

…it’s a resource manager

co-ordinating access to hardware resources processors memory mass storage communication channels devices (timers, GPUs, DSPs, other peripherals…) multiple tasks/processes/programs may be applying for access to these resources!

9

slide-10
SLIDE 10

A brief history of operating systems (1)

in the beginning: single user, single program, single task, serial processing—no OS 50s: system monitors/batch processing

the monitor ordered the sequence of jobs and triggered their sequential execution

50s-60s: advanced system monitors/batch processing:

the monitor handles interrupts and timers rst support for memory protection rst implementations of privileged instructions (accessible by the monitor only)

early 60s: multi-programming systems:

use the long device I/O delays for switches to other runnable programs

early 60s: multi-programming, time-sharing systems:

assign time-slices to each program and switch regularly

10

slide-11
SLIDE 11

A brief history of operating systems (2)

early 70s: multi-tasking systems – multiple developments resulting in UNIX (and others) early 80s: single user, single tasking systems, with emphasis on user interface or

  • APIs. MS-DOS, CP/M, MacOS and others rst employed ‘small scale’ CPUs

(personal computers). mid-80s: Distributed/multiprocessor operating systems - modern UNIX systems (SYSV, BSD) late 70s: Workstations starting by porting UNIX or VMS to ‘smaller’ computers. 80s: PCs starting with almost none of the classical OS-features and services, but with an user-interface (MacOS) and simple device drivers (MS-DOS)

11

slide-12
SLIDE 12

A brief history of operating systems (3)

last 20 years: evolving and expanding into current general purpose OSes, like for instance:

Solaris (based on SVR4, BSD, and SunOS, and pretty much dead now) Linux (open source UNIX re-implementation for x86 processors and others) current Windows (used to be partly based on Windows NT, which is ‘related’ to VMS) MacOS (Mach kernel with BSD Unix and a proprietary user-interface)

multi-processing is supported by all these OSes to some extent

but not (really) suitable for embedded, or real-time systems

12

slide-13
SLIDE 13

Distributed operating systems

all CPUs carry a small kernel operating system for communication services all other OS services are distributed over available CPUs services may migrate services can be multiplied in order to guarantee availability (hot stand-by), or to increase throughput (heavy duty servers)

13

slide-14
SLIDE 14

Real-time operating systems?

14

slide-15
SLIDE 15

Real-time operating systems?

15

slide-16
SLIDE 16

Real-time operating systems?

16

slide-17
SLIDE 17

Real-time operating systems

should be fast anyway should be small anyway not quick, but predictable

  • ten, not always

needed in many operating systems needed in almost all operating systems fault tolerance builds on redundancy fast context switches? small size? quick response to external interrupts? multitasking? 'low level' programming interfaces? interprocess communication tools? high processor utilisation?

17

slide-18
SLIDE 18

Real-time operating systems need to provide…

the logical correctness of the results as well as the correctness of the time: what and when are both important all results are to be delivered just-in-time – not too early, not too late. timing constraints are specied in many diferent ways… oten as a response to ‘external’ events (reactive systems)

18

slide-19
SLIDE 19

predictability, not performance!

19

slide-20
SLIDE 20

Embedded operating systems

usually real-time systems, oten hard real-time systems very small footprint (oten a few kBytes) none or limited user-interaction 90-95% of all the processors in the world are in embedded systems

20

slide-21
SLIDE 21

How many OSes?

21

slide-22
SLIDE 22

Standard features?

is there a standard set of features for operating systems? no. the term operating system covers everything from 4 kB microkernels, to > 1 GB installations of desktop general purpose operating systems

22

slide-23
SLIDE 23

Minimal set of features?

is there a minimal set of features? almost: memory management, process management and inter-process communication/synchronisation would be considered essential in most systems is there always an explicit operating system? no: some languages and development systems operate with standalone runtime environments

23

slide-24
SLIDE 24

Process management

(we’ll talk more about this ) basically, this is the task of keeping multiple things going all at once… …while tricking them all into thinking they’re the main game in a moment

24

slide-25
SLIDE 25

talk

what’s a task?

25

slide-26
SLIDE 26

Memory management

remember memory? the OS is responsible for sharing it around allocation / deallocation virtual memory: logical vs. physical addresses, segments, paging, swapping, etc. memory protection (privilege levels, separate virtual memory segments, …) shared memory (for performance, communication, …)

26

slide-27
SLIDE 27

Synchronisation/inter-process communication

remember all the stuf? the OS is responsible for managing that as well semaphores, mutexes, condition variables, channels, mailboxes, MPI, etc. this is tightly coupled to scheduling / task switching! asynchronism

27

slide-28
SLIDE 28

Hardware abstraction

remember all the specic load-twiddle-store addresses in the labs? no? good news everyone! the OS does so you don’t have to device drivers protocols, le systems, networking, everything else… all through a consistent API

28

slide-29
SLIDE 29

Kernel: denition

the kernel is the program (functions, data structures in memory, etc.) which performs the core role(s) of the OS access to the CPU, memory, peripherals all happens through the kernel through a system call

29

slide-30
SLIDE 30

30

slide-31
SLIDE 31

31

slide-32
SLIDE 32

32

slide-33
SLIDE 33

info

if you want to look at some real system call APIs

  • n Linux,
  • n Windows,

syscalls.h header le

how to add a new system call Windows API Index

33

slide-34
SLIDE 34

writing an OS seems complicated how is it done in practice?

34

slide-35
SLIDE 35

Monolithic OS

(or ‘the big mess…’) non-portable/hard to maintain lacks reliability all services are in the kernel (on the same privilege level) but: may reach high eciency e.g., most early UNIX systems, MS-DOS (80s), Windows (all non- NT based versions) MacOS (until version 9), and many others…

35

slide-36
SLIDE 36

Monolithic & Modular OS

modules can be platform independent easier to maintain and to develop reliability is increased all services are still in the kernel (on the same privilege level) may reach high eciency e.g., current Linux versions

36

slide-37
SLIDE 37

μKernels & client-server models

μkernel implements essential process, memory, and message handling all ‘higher’ services are user level servers kernel ensures reliable message passing between clients and servers highly modular, lexible & maintainable servers can be redundant and easily replaced (possibly) reduced eciency through increased communications e.g., current research projects, μ, L4, Minix 3, etc.

37

slide-38
SLIDE 38

38

slide-39
SLIDE 39

Example: UNIX

hierarchical le-system (maintained via mount and unmount) universal le-interface applied to les, devices (I/O), as well as IPC dynamic process creation via duplication choice of shells internal structure as well as all APIs are based on C relatively high degree of portability many versions/lavours: UNICS, UNIX, BSD, XENIX, System V, QNX, IRIX, SunOS,

39

slide-40
SLIDE 40

Privilege levels

40

slide-41
SLIDE 41

talk

what do you think privilege means? how does it afect your code running on the discoboard?

41

slide-42
SLIDE 42

Privilege

42

slide-43
SLIDE 43

Privilege levels

certain instructions can only be executed in “privileged” mode—this is enforced in hardware diferent architectures enforce this in diferent ways check the manual (e.g. Section A2.3.4 on p32 or Table B1-1 Mode on p568 of the ARMv7-M reference manual Fun video for the nostalgic: What is DOS protected mode?

43

slide-44
SLIDE 44

ARMv7-M execution levels

thread mode handler mode privileged regular code all exceptions (including interrupts) unprivileged regular code n/a priviliges may control: code execution memory read/write access register access (e.g., for peripherals)

44

slide-45
SLIDE 45

“Supervisor call” instruction

did you notice these entries in the ? the svc instruction (A7.7.175 in the ) runs the SVC_Handler immediately vector table

.word SVC_Handler @ ... .word PendSV_Handler

reference manual

45

slide-46
SLIDE 46

Deferred supervisor call (PendSV)

there’s a PENDSVSET bit (bit 28) in the Interrupt Control and State Register (ICSR) if set, the PendSV_Handler will be called according to the usual interrupt/exception priority rules both SVC_Handler and PendSV_Handler run in privileged mode, like all interrupts

46

slide-47
SLIDE 47

System calls with svc

How might we implement a system call on a discoboard? How do ? system calls work in linux

47

slide-48
SLIDE 48

Processes & scheduling

48

slide-49
SLIDE 49

Trust the Process

49

slide-50
SLIDE 50

talk

(if you’ve got your laptop here) how many processes are running on your machine right now? how about on your phone?

50

slide-51
SLIDE 51

Process: denition

basically: a running program includes the code (instructions) for the program, and the current state/context: registers/lags memory (stack and heap) permissions/privileges

  • ther resources (e.g. global variables, open les & network connections, address

space mappings)

51

slide-52
SLIDE 52

processes as far as the eye can see

52

slide-53
SLIDE 53

exact denition of process depends on the OS

53

slide-54
SLIDE 54

so how do we manage them?

54

slide-55
SLIDE 55

1 CPU per control-low

specic congurations only, e.g.: distributed microcontrollers physical process control systems 1 cpu per task, connected via a bus system Process management (scheduling) not required Shared memory access need to be coordinated

55

slide-56
SLIDE 56

1 CPU for all control-lows

the OS may “emulate” one CPU for every control-low this is a multi-tasking operating system support for memory protection essential process management (scheduling) required shared memory access need to be coordinated

56

slide-57
SLIDE 57

Symmetric multiprocessing (SMP)

all CPUs share the same physical address space (and have access to the same resources) so any process can be executed on any available CPU

57

slide-58
SLIDE 58

Processes vs threads

processes (as discussed ) have their own registers, stack, resources, etc. threads have their own registers & stack, but share the other process resources

  • ne process can create/manage many threads

earlier

58

slide-59
SLIDE 59

Torvalds vs Threads

59

slide-60
SLIDE 60

"Depends on the implementation"...

60

slide-61
SLIDE 61

Process Control Blocks (PCBs)

process ID process state: {created, ready, executing, blocked, suspended, bored …} scheduling attributes: priorities, deadlines CPU state: (e.g. registers, stack pointer) memory attributes/privileges: permissions, limits, shared areas allocated resources: open/requested devices and les, etc.

61

slide-62
SLIDE 62

a data structure for processes

62

slide-63
SLIDE 63

Process states

created: the task is ready to run, but not yet considered by any dispatcher ready: ready to run (waiting for a free CPU) running: holds a CPU and executes blocked: not ready to run (waiting for a resource) suspended: swapped out of main memory (e.g. waiting for main memory space)

63

slide-64
SLIDE 64

64

slide-65
SLIDE 65

First come, rst served (FCFS) scheduling

Waiting time: 0..11, average: 5.9

65

slide-66
SLIDE 66

FCFS (again)

Waiting time: 0..11, average: 5.4 (was 5.9 before)

66

slide-67
SLIDE 67

Round-robin (RR) scheduling

Waiting time: 0..5, average: 1.2 Turnaround time: 1..20, average: 5.8

  • ptimised for swit initial responses, but “stretches out” long tasks

bound maximal waiting time! (depended only on the number of tasks)

67

slide-68
SLIDE 68

talk

when might you want to use FCFS scheduling? how about RR?

68

slide-69
SLIDE 69

Again, a whirlwind tour of OSes

remember the concepts

69

slide-70
SLIDE 70

go build your own in lab 11

70

slide-71
SLIDE 71

Questions

71

slide-72
SLIDE 72

Fun With Operating Systems

Kernel writing 101 Linux on an 8bit AVR How to make an operating system (WikiHow)

72