You are on page 1of 36

Operating Systems

2. Introduction to O.S.

2011/2012

Luis Moura e Silva Email: luis@dei.uc.pt Departamento de Eng. Informtica Universidade de Coimbra

Disclaimer

This slides and notes are heavily based on the companion material of [Silberschatz05].The original material can be found at:

http://codex.cs.yale.edu/avi/os-book/os7/slide-dir/index.html

In some cases, material from [Stallings04] may also be used. The original material can be found at:

http://williamstallings.com/OS/OS5e.html

The respective copyrights belong to their owners.

Whats an Operating System?

What Operating Systems Do:

Sharing resources among applications


scheduling allocation improving utilization minimizing overhead improving throughput/good put enforcement of boundaries

Making efficient use of limited resources


Protecting applications from each other

Classification of Operating Sytems

Virtual Time and Real Time Operating Systems Examples of OS with Virtual Time:

Windows, Unix, Linux, Mac OS X, Novell, VxWorks, VRTX, pSOS, LynxOS,

Examples of Real-Time Operating Systems

Embedded Operating Systems

Symbian, WindowCE, PalmOS, iPhone OS, Android,

Open/Closed Operating Systems:


Proprietary Open systems Open-source systems (GPL license)


5

Market Share Desktop OS: July 2011

Share Mobile Operating Systems: Q1 2011

Simple Organization of an Operating System

Applications System Libraries Protection Barrier KERNEL

Two Modes of Operation (to assure security)

User Mode

Kernel Mode

UNIX Operating System Structure


9

Input/Output versus CPU Usage


I/O devices and the CPU can execute concurrently Each device controller is in charge of a particular device Each device controller has a local buffer CPU moves data from/to main memory to/from local buffers I/O is from the device to local buffer of controller Device controller informs CPU that it has finished its operation by causing an interrupt

10

Interrupt Timeline

11

Different Types of I/O

12

Device Status Table

13

Direct Memory Access (DMA)

Used for high-speed I/O devices able to transmit information at close to memory speeds Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention Implies the capability of arbitrating the system bus Only one interrupt is generated per block, rather than the one interrupt per byte

14

DMA (2)

15

Protection

Dual Mode of Operation User Mode and Kernel Mode In User Mode only common instructions can be performed (e.g. arithmetic and logic). In Kernel Mode can do anything. A mode bit contains the current mode of operation RTI: Return from interruption Kernel mode assumed on traps and on interrupts I/O Protection All I/O Instructions are privileged. For doing I/O a trap into the operating system must be generated. Memory Protection Each program can only access its memory CPU Protection The CPU must remain in control of the Operating System, even if the applications dont want to let go.
16

Dual Mode of Operation

17

System Calls, Traps and Interrupts

System calls

Traps

Operating System

Interrupts

18

Structure of a System Call

19

Example with a Hello World Application!


#include <stdio.h> int main() { printf(Hello World\n); return 0; }

The strace program is very useful:

It allows you to see what system calls are made and with what parameters!

20

strace in Action!

21

Storage Hierarchy

Caches, Buffers and a Storage Hierarchy are Essential

22

Storage Hierarchy

A great part of this hierarchy is controlled by the Operating System


Cache Management Policies Buffer Management Policies Memory Management Policies

Principles of Locality: - Temporal Locality - Spatial Locality

23

Memory Protection

Each program must only be able to access its own memory


Segmentation Virtual Memory

Segmentation is based on having a base pointer and a limit for each process running

Any access made outside of its space generates a trap and normally leads to the process being killed

Virtual Memory is based on having a table that translates virtual addresses into real ones

Normally, there is such a table for each process Each process sees all the address space An access made to an non existing page generates a trap and normally leads to the process being killed
24

Segmentation

25

Virtual Memory

4Gb

4Gb Disk 5000

1000 0
Address Space of Process A

1000 0
Address Space of Process B

256Mb

Address Translation Table

Physical Memory

(simplified)

26

Multiprogramming

Multiprogramming: maintaining several jobs in memory, active at the same time, so that when the current program can no longer run (for example because its blocked waiting for I/O), another is available to run Optimizes resource utilization: CPU and I/O

Time Multiplexed CPU

CPU

E.g. Windows 95/98!


27

Multitasking

Multitasking is an extension of multiprogramming in which the execution of the active programs is time-sliced:

Each program runs for a short period of time, then another is run. When a program is running and is forcibly replaced by another, typically with a higher priority, it is said to have been preempted, thus the term Preemptive Operating Systems

28

Multitasking

For implementing multitasking, a non-maskable interrupt must connected to a hardware timer

Every few milliseconds (e.g. 100ms), the interrupt causes a task (or process) switch

User Level

total = 0; for (int i=0; i<20000; i++) total = total + i; printf(total=%d\n, total);

while (!feof(fd)) { if (fscanf(fd, %d, &d) == 1) printf(%d\n, d); }

(...)

Kernel Level

Interrupt Handler

29

Nowadays

Windows XP, Linux 2.6.xx:


Preemptive multitasking operating systems using virtual memory Each process thinks it has the whole computer for itself Virtual Machine

30

Operating System Architecture and Structures

Currently, there are two dominant architectures Microkernel:


Moves as much as possible from the kernel into user space Communication takes place between user modules using message passing Benefits:

Easier to extend a microkernel Easier to port the operating system to new architectures More reliable (less code is running in kernel mode) More secure SLOW: Performance overhead of user space to kernel space communication
31

Detriments:

Operating System Architecture and Structures

Currently, there are two dominant architectures Monolithic:


Consists of everything below the system-call interface and above the physical hardware Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level Benefits:

FAST! Less reliable (more code is running in kernel mode) Less secure No so easy to port to new architectures ( it depends)
32

Detriments:

Operating System Architecture and Structures

Most modern operating systems implement kernel modules


Uses object-oriented approach Each core component is separate Each talks to the others over known interfaces Each is loadable as needed within the kernel

Benefits

Its easier to extend the operating system Allows to isolate functionality in well defined software entities, making the OS more maintainable and reliability

33

Virtual Machines

Facet A:

Abstract Machine that runs bytecode (e.g. Java, MS.NET) Good for portability, allowing running the same unmodified application in different physical architectures

Facet B:

Software that allows different operating systems to be run in parallel giving them the illusion of having a whole machine (e.g. VMWARE, XEN, Virtuozzo, ) Some Virtual Machines run on top of the hardware: IBM z/VM Others run on top of the host OS: XEN, VMWARE, etc Allows for server consolidation, software testing, software fault tolerance, etc.
34

VMWARE Architecture

35

Reference

Chapter 1: Introduction

1.1, 1.2, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9

Chapter 2: Operating Systems Structures


All chapter 2! 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.10

36

You might also like