TDDI04, K. Arvidsson, IDA, Linköpings universitet Operating System Structures. Operating System Structures Overview. Operating System Services

Similar documents
Chapter 2: Operating-System Structures

Chapter 2: Operating-System Structures. Chapter 2: Operating-System Structures. Objectives. Operating System Services

Chapter 2: Operating-System Structures. Operating System Concepts Essentials 8 th Edition

Chapter 2: Operating-System

Chapter 2: Operating-System Structures

Chapter 2: Operating-System Structures

Objectives. Chapter 2: Operating-System Structures. 2.1 Operating System Services

Chapter 2: Operating-System Structures

Chapter 2: System Structures

CS307: Operating Systems

CS420: Operating Systems. OS Services & System Calls

Operating-System Structures

Chapter 2: System Structures. Operating System Concepts 9 th Edition

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

Chapter 2. Operating-System Structures

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

Lecture 2 Operating System Structures (chapter 2)

Operating-System Structures

Chapter 2: Operating-System Structures

CHAPTER 2: SYSTEM STRUCTURES. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Operating System Services

Chapter 2: System Structures. Operating System Concepts 9 th Edition

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Chapter 2. Operating System Structures

Chapter 2: Operating-System Structures. Operating System Concepts 8 th Edition

NON SCHOLAE, SED VITAE

Chapter 2: System Structures

Lecture 2 - Fundamental Concepts

Chapter 3: Operating-System Structures

Operating System Services. User Services. System Operation Services. User Operating System Interface - CLI. A View of Operating System Services

Operating System: Chap2 OS Structure. National Tsing-Hua University 2016, Fall Semester

CS370 Operating Systems

Chapter 3: Operating-System Structures

Often, more information is required when designing system call Information varies according to OS and types of system call

Chapter 2 Operating System Structures

OS and Computer Architecture. Chapter 3: Operating-System Structures. Common System Components. Process Management

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

What are some common categories of system calls? What are common ways of structuring an OS? What are the principles behind OS design and

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Chap2: Operating-System Structures

Last class: OS and Architecture. OS and Computer Architecture

Last class: OS and Architecture. Chapter 3: Operating-System Structures. OS and Computer Architecture. Common System Components

Module 3: Operating-System Structures

Chapter 2 Operating-System Structures

Operating-System Structures

Four Components of a Computer System

Module 1 Introduction/OS Overview

Chapter 3: Operating-System Structures

TDDB68 Concurrent Programming and Operating Systems. Lecture 1: Introduction, interrupts and system calls

Kernel Types Simple OS Examples System Calls. Operating Systems. Autumn CS4023

Module 3: Operating-System Structures. Common System Components

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - VII CPU Scheduling - II. Louisiana State University

Roadmap. Multilevel Queue Scheduling. Multilevel Queue. Example of Multilevel Feedback Queue. Multilevel Feedback Queue. Tevfik Ko!

CSE 4/521 Introduction to Operating Systems

Chapter 2: OS Structures

OPERATING SYSTEMS Lecture Notes. Prepared by K.Rohini, Assistant Professor, CSE Department, GVPCEW.

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

OPERATING SYSTEMS. Prescribed Text Book Operating System Principles, Seventh Edition By Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

Processes and Threads

OPERATING SYSTEMS UNIT - 1

Introduction to PC Operating Systems

UNIT 2. OPERATING SYSTEM STRUCTURES

CSC Operating Systems Spring Lecture - II OS Structures. Tevfik Ko!ar. Louisiana State University. January 17 th, 2007.

Announcements. Operating System Structure. Roadmap. Operating System Structure. Multitasking Example. Tevfik Ko!ar

Architectural Support for Operating Systems. Jinkyu Jeong ( Computer Systems Laboratory Sungkyunkwan University

Operating System Review

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

Operating System Structure

What we saw. Desarrollo de Aplicaciones en Red. 1. OS Design. 2. Service description. 1.1 Operating System Service (1)

Full file at

Operating System Concepts Ch. 2: Operating System Structures

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

! Software ( kernel ) that runs at all times. ! OS performs two unrelated functions: Maria Hybinette, UGA. user! 1! Maria Hybinette, UGA. user! n!

CPS221 Lecture: Operating System Functions

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - II OS Structures. University at Buffalo. OS Design and Implementation

OS Design Approaches. Roadmap. System Calls. Tevfik Koşar. Operating System Design and Implementation. CSE 421/521 - Operating Systems Fall 2013

Operating System Architecture. CS3026 Operating Systems Lecture 03

CSC Operating Systems Fall Lecture - II OS Structures. Tevfik Ko!ar. Louisiana State University. August 27 th, 2009.

Announcements. Computer System Organization. Roadmap. Major OS Components. Processes. Tevfik Ko!ar. CSC Operating Systems Fall 2009

Operating-System Structures

OS Design Approaches. Roadmap. OS Design Approaches. Tevfik Koşar. Operating System Design and Implementation

Introduction to Operating Systems (Part III)

OS Structures. ICS332 Operating Systems

Chapter 2: Operating-System Structures

Operating System Structure

CPS221 Lecture: Operating System Functions

EECS 3221 Operating System Fundamentals

EECS 3221 Operating System Fundamentals

Operating System Structure

OS concepts and structure. q OS components & interconnects q Structuring OSs q Next time: Processes

CSE Opera+ng System Principles

Spring It takes a really bad school to ruin a good student and a really fantastic school to rescue a bad student. Dennis J.

Computer System Architecture. CMPT 300 Operating Systems I. Summer Segment 3: Computer System Architecture. Melissa O Neill

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,

Memory Management. Contents: Memory Management. How to generate code? Background

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging

Overview of Operating Systems

Introduction. TDDI04, K. Arvidsson, IDA, Linköpings universitet Contents. What is an Operating System (OS)?

Transcription:

TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Operating System Structures [SGG7] Chapter 2 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin s and Gagne s book ( Operating System Concepts, 7th ed., Wiley, 2005). No part of the lecture notes may be reproduced in any form, due to the copyrights reserved by Wiley. These lecture notes should only be used for internal teaching purposes at the Linköping University. Acknowledgment: The lecture notes are originally compiled by C. Kessler, IDA. Klas Arvidsson, IDA, Linköpings universitet. Operating System Structures Overview Operating System Services User Operating System Interface System Calls System Programs Operating System Structure Layered Approach Microkernels Modules Virtual Machines Operating System Generation System Boot TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.2 Operating System Services Operating System Services (Cont.) Provide functions for the user or for the system itself. Functions that are helpful to the user or user program: User interface > Command-Line Interface > Graphics User Interface (GUI) > Batch Program execution load a program into memory, run it, terminate it. I/O operations A running program may require I/O to/from a file or an I/O device. File-system manipulation read and write files and directories, create and delete them, search them, list file information, permission management. TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.3... More functions that are helpful to the user: Communications Processes may exchange information, on the same computer or between computers over a network > Communications may be via shared memory or through message passing (packets moved by the OS) Error detection > Errors may occur in the CPU and memory hardware, in I/O devices, in user program > OS should take the appropriate action to ensure correct and consistent computing > Debugging facilities TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.4 Operating System Services (Cont.) User Operating System Interface (1) OS functions supporting the efficient operation of the system itself: Resource allocation When multiple users or multiple jobs are running concurrently, resources must be allocated to each of them > Types of resources: CPU time, main memory, file storage, I/O dev. Accounting > keep track of which users use how much and what kind of resources Protection and security > In multiuser or networked computer system, control use of stored information; concurrent processes should not interfere with each other > Protection: ensure that all access to system resources is controlled > Security of the system from outsiders requires user authentication, defending external I/O devices from invalid access attempts TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.5 > A chain is only as strong as its weakest link. Command Line Interpreter (CLI) allows direct command entry Sometimes implemented in the kernel, sometimes by a system program Sometimes multiple flavors implemented shells Primarily fetches a command from user and executes it > built-in commands or > just names of programs ( -> extendible) Unix example (csh): rm file.txt TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.6 1

User Operating System Interface (2) Graphical User Interface (GUI): user-friendly desktop metaphor Icons represent files, programs, actions, etc Folders represent directories Menus (pulldown / popup) show available commands Various mouse button clicks over objects in the interface cause various actions (e.g., provide information, show options, execute function, open directory) Invented at Xerox PARC System Calls Overview System call mechanism System call API Passing parameters Types of system calls Many systems now include both CLI and GUI interfaces Microsoft Windows is GUI with CLI command shell Apple Mac OS X as Aqua GUI interface with UNIX kernel underneath and shells available Solaris is CLI with optional GUI interfaces (CDE, Java Desktop, KDE) TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.7 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.8 Recall: Dual-Mode Operation Sharing system resources requires the operating system to ensure that an incorrect program cannot cause other programs to execute incorrectly. Hardware support (mode bit) to differentiate between at least two modes of operations. User mode Execution done on behalf of a user Access only to memory addresses owned by the process Kernel mode (also supervisor mode or system mode) Execution done on behalf of operating system. Privileged instructions instructions that may be harmful, e.g., system login, set priorities, system halt, etc. Unrestricted memory access TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.9 Dual-Mode Operation (Cont.) When an interrupt or fault occurs, hardware switches to kernel mode. System calls call OS service kernel Interrupt/fault set user mode user TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.10 Example of System Calls System call sequence to copy contents of one file to another System Call API Programming interface to the services provided by the OS Typically written in a high-level language (C or C++) Mostly accessed by programs via a high-level Application Program Interface (API) rather than direct system call use Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, Mac OS X) Java API for the Java virtual machine (JVM) Remark: the system-call names used here and in the book are generic. TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.11 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.12 2

Example of a System Call API ReadFile() function in Win32 API (function for reading from a file) Parameters passed to ReadFile(): file the file to be read buffer a buffer where the data will be read into and written from bytestoread the number of bytes to be read into the buffer bytesread the number of bytes read during the last read ovl indicates if overlapped I/O is being used System Call API Implementation System call implementation is hardware-specific, e.g. special trap instruction with a system call number passed in a register, indexing the interrupt vector (branch table) System call interface (usually, in C) invokes the intended system call in OS kernel and returns status of the system call and any return values Advantage: Caller does not need to know anything about how the system call is implemented Most details of OS interface hidden from programmer by API TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.13 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.14 System Call API OS Relationship Standard C Library Example C program invoking printf(), which calls write() system call TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.15 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.16 System Call Parameter Passing System Call Parameter Passing via Block Three general methods used to pass parameters to syscalls: Simplest: pass the parameters in registers > but number of parameter registers is limited Parameters stored in a block in memory, and address of block passed as a parameter in a register > This approach taken by Linux and Solaris Parameters pushed onto the stack by the program and popped off the stack by the operating system Block and stack methods do not limit the number or length of parameters being passed TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.17 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.18 3

Types of System Calls Process control load, execute, end, abort, create, terminate, wait... memory allocation and deallocation File management open, close, create, delete, read, write, get/set attributes... Device management request / release device, read, write,... Information maintenance get / set time, date, system data, process / file attributes Communications create / delete connection, send, receive,... Solaris 10 dtrace Following System Call dtrace: dynamic tracing facility instrument the code to collect diagnostic information during runtime, e.g. entry/exit of functions U = User mode K = Kernel mode TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.19 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.20 FreeBSD Running Multiple Programs For each new user, the kernel starts a new shell process in a fresh memory area with the fork() system call. For each program started, the shell starts a new process in a fresh memory area with the fork() system call System Programs provide a convenient environment for program development and execution. File management Status information File modification Programming language support: Compilers, assemblers, debuggers... Program loading and execution Communications: Message passing, e-mail, web browser,... Some of them are simply user interfaces to system calls; others are considerably more complex Most users view of the operation system is defined by system programs, not the actual system calls TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.21 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.22 Operating System Design and Implementation Design and implementation of OS: No silver bullet, but some approaches have proven successful Internal structure of different OS can vary widely Start by defining goals and specifications Affected by choice of hardware, type of system User goals versus System goals User goals OS should be convenient to use, easy to learn, reliable, safe, and fast System goals OS should be easy to design, implement, and maintain, as well as flexible, reliable, error-free, and efficient Operating System Structure How to manage OS complexity? Divide-and-conquer! Decompose into smaller components with well-defined interfaces and dependences Layered Approach Microkernels Modules Virtual Machines TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.23 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.24 4

Simple Structure Layered Approach MS-DOS written to provide the most functionality in the least space Not divided into modules Although MS-DOS has some structure, its interfaces and levels of functionality are not well separated The operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0) is the hardware the highest (layer N) is the user interface. Modularity: Design layers s.t. each uses functions and services of only lower-level layers. new operations existing operations.. hidden operations. layer M layer M 1 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.25 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.26 UNIX System Structure: 2 Layers THE OS: 6 Layers A layered design was first used in the THE operating system [Dijkstra 68, Technische Hogeschool at Eindhoven, NL] layer 5: layer 4: layer 3: layer 2: layer 1: layer 0: user programs buffering for input and output operator-console device driver memory management CPU scheduling hardware TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.27 see SGG7 Ch. 23.4, p. 847 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.28 Microkernel System Structure Lean kernel : Moves as much service functionality as possible from the kernel into user space Communication takes place between user modules using message passing Example: Mach kernel, used e.g. in Tru64 Unix or Mac OS-X 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 Detriments: Performance overhead of user space to kernel space communication TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.29 Modules Most modern operating systems implement kernel modules Component-based approach: Each core component is separate Each talks to the others over known interfaces Each is loadable as needed within the kernel Example: Solaris loadable kernel modules Overall, similar to layers but more flexible TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.30 5

Virtual Machines Virtual Machines (Cont.) A virtual machine provides an interface identical to the underlying bare hardware. Example: Multitasking OS creates the illusion that each process executes on its own (virtual) processor with its own (virtual) memory. A virtual machine takes the layered approach to its logical conclusion: It treats hardware and the operating system kernel as though they were all hardware. Virtual machine implementation intercepts operations and interprets them. The virtual machines share the resources of the physical computer: CPU scheduling: create illusion that users have their own processor Virtual disks with virtual file systems on physical disk / file system A normal user time-sharing terminal serves as the virtual machine operator s console Can run multiple and different OS s on the same physical computer Examples: VMware, Xen TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.31 Non-virtual Machine (a) Nonvirtual machine Virtual Machine (b) virtual machine TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.32 Virtual Machines Advantages, Drawbacks VMware Architecture Complete protection of system resources since each virtual machine is isolated from all other virtual machines. however, permits no direct sharing of resources. Perfect vehicle for operating-systems research and development (and teaching ;-). System development is done on the virtual machine, instead of on a physical machine and so does not disrupt normal system operation. Example: PINTOS, NACHOS Portability across multiple platforms (host OS, hardware) Example: Java Virtual Machine (JVM) (Nowadays very popular also in computer architecture: e.g., TransMeta Crusoe processor emulates IA-32 on VLIW) Difficult to implement to provide an exact duplicate to the underlying machine See also: IEEE Computer May 2005 special issue on Virtual Machines TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.33 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.34 The Java Virtual Machine Operating System Generation Operating systems are designed to run on any of a class of machines... but the system must be configured for each specific computer site: CPU type, memory sizes, devices, performance parameters (e.g. scheduling algorithm),... SYSGEN program obtains information concerning the specific configuration of the hardware system TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.35 TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.36 6

Booting Booting = starting up a computer by loading the kernel Bootstrap loader: The initial program executed when system is powered up code stored in ROM at address where execution starts locates the kernel, loads it into memory, and start its execution initializes the system > CPU registers, device controllers, memory contents... Once the OS is loaded, the OS starts executing the first process (e.g., init) and then waits for some event to occur (interrupt). TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.37 Operating System Structures Summary Operating System Services User Operating System Interface System Calls System Programs Operating System Structure Layered Approach Microkernels Modules Virtual Machines Operating System Generation System Boot TDDI04, K. Arvidsson, IDA, Linköpings universitet. 3.38 7