Lecture 2 - Fundamental Concepts

Similar documents
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. Chapter 2: Operating-System Structures. Objectives. Operating System Services

Chapter 2: Operating-System Structures

Chapter 2: Operating-System Structures

Chapter 2: System Structures

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

Operating System Services

Operating System Review

CS307: Operating Systems

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

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

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

Lecture 2 Operating System Structures (chapter 2)

Module 2: Computer-System Structures. Computer-System Architecture

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

Four Components of a Computer System

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

Chapter 2: Operating-System Structures

Instruction Cycle. Computer-System Architecture. Computer-System Operation. Common Functions of Interrupts. Chapter 2: Computer-System Structures

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

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

Computer-System Architecture

Computer-System Architecture. Common Functions of Interrupts. Computer-System Operation. Interrupt Handling. Chapter 2: Computer-System Structures

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

Common Computer-System and OS Structures

Computer-System Structures

Operating-System Structures

EECS 3221 Operating System Fundamentals

EECS 3221 Operating System Fundamentals

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

CS420: Operating Systems. OS Services & System Calls

Chapter 2. Operating-System Structures

Chapter 2: Operating-System Structures

Operating-System Structures

CS370 Operating Systems

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

CPSC 341 OS & Networks. Introduction. Dr. Yingwu Zhu

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

CSE 4/521 Introduction to Operating Systems

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

Chapter 2 Operating-System Structures

Chapter 2. Operating System Structures

Chapter 1: Introduction

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

Chapter 1: Introduction

European University of Lefke. Instructor: Dr. Arif SARI

Chapter 1: Introduction. Chapter 1: Introduction

OPERATING SYSTEMS UNIT - 1

Lecture 1 - Operating System Overview

Chapter 2 Operating System Structures

To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

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

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

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

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

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.

OPERATING SYSTEMS: Lesson 1: Introduction to Operating Systems

7/20/2008. What Operating Systems Do Computer-System Organization

UNIT 2. OPERATING SYSTEM STRUCTURES

Chapter 1: Introduction. Operating System Concepts 8th Edition,

Lecture 1 Introduction (Chapter 1 of Textbook)

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

Process Description and Control

Chapter 1: Introduction

Chapter 2: System Structures

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

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!

Unit 2 : Computer and Operating System Structure

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

DM510 Operating Systems. Jacob Aae Mikkelsen

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

Topics: Early systems and OS overview Skim Chapters 1-2 of SGG Read Chapter 1 of USP CS 3733 Operating Systems

CS399 New Beginnings. Jonathan Walpole

Chapter 1: Introduction. Operating System Concepts 9 th Edit9on

CS 333 Introduction to Operating Systems Class 2 OS-Related Hardware & Software The Process Concept

Chapter 3: Operating-System Structures

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

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

Chapter 3: Operating-System Structures

Chapter 3: Operating-System Structures

CS3600 SYSTEMS AND NETWORKS

OPERATING SYSTEM OVERVIEW

SRIMAAN COACHING CENTRE-TRB-COMPUTER INSTRUCTORS STUDY MATERIAL CONTACT: III

Chapter 2: OS Structures

PG-TRB COMPUTER INSTRUCTOR OPERATING SYSTEMS

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

Module 3: Operating-System Structures

Operating-System Structures

CS370 Operating Systems

Operating Systems CS 571

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

CSE Opera+ng System Principles

CSC 2405: Computer Systems II

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

Transcription:

Lecture 2 - Fundamental Concepts Instructor : Bibhas Ghoshal (bibhas.ghoshal@iiita.ac.in) Autumn Semester, 2015 Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 1 / 43

Lecture Outline Operating System Overview : Re-visit Computer System Operation Storage Structure Storage Hierarchy Hardware protection Interacting with services provided by the OS System calls - link between application programs and OS System programs - users interact using programs Installation, customization etc. booting References and Illustrations have been used from: lecture slides of the book - Operating System Concepts by Silberschatz, Galvin and Gagne, 2005 Modern Operating System by Andrew S. Tanenbaum lecture slides of CSE 30341: Operating Systems (Instructor : Surendar Chandra), Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 2 / 43

Operating system Overview Operating System allows the user to achieve the intended purpose of using the computer system in a fast and efficient manner Operating system controls and coordinates use of hardware among various applications and users Key concerns of Operating System Programs Resources Scheduling Protection Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 3 / 43

Computer System Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 4 / 43

Operating System Overview Operating System Structure Multiprogramming needed for efficiency Timesharing (multitasking) Multi-user OS should protect the users/processes from each other as well as protect itself from users Dual-mode operation allows OS to protect itself and other system components Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 5 / 43

Hardware Control Aspect of the Operating System Acts as an intermediary between user and hardware Resource allocator Control program Operating Systems cannot make hardware go faster. However, OS can make hardware appear faster. Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 6 / 43

Computer Hardware Review Hardware issues of concern to OS Designers Computer System : CPU, Memory and I/O connected through buses to communicate among each other CPU : Fetches instruction from memory and executes them CPU has specific instruction set that it executes Registers - General Purpose and Special Purpose (Program Counter and Stack Pointer) Program Status Word : contains condition code bits, CPU priority, mode (kernel/user) etc. PSW plays important role in system calls and I/O Techniques to improve performance : Pipelining, Superscalar CPU etc. Memory : Should be extremely fast, abundantly large and cheap No technology satisfies it :-( Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 7 / 43

Storage Structure Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 8 / 43

Caching Principle Caching is an important principle, performed at many levels in a computer (in hardware, operating system, software) Information in use is copied from slower to faster storage temporarily Faster storage (cache) checked first to determine if information is there If it is (cache hit), information used directly from the cache (fast) If not (cache miss), data copied to cache and used there May need to evict some other data (cache replacement) Cache smaller than storage being cached Cache management important design problem Cache size and replacement policies are important Sometimes bring data before needed (pre-fetch) Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 9 / 43

Typical Computer Architecture Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 10 / 43

Computer System Operation I/O devices and the CPU can execute concurrently. Each device controller is in charge of a particular device type. 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. Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 11 / 43

Common Functions of Interrupts Interrupts transfers control to the interrupt service routine generally, through the interrupt vector, which contains the addresses of all the service routines. Interrupt architecture must save the address of the interrupted instruction. Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt. A trap is a software-generated interrupt caused either by an error or a user request. An operating system is interrupt driven. Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 12 / 43

Interrupt Handling The operating system preserves the state of the CPU by storing registers and the program counter. Determines which type of interrupt has occurred: polling vectored interrupt system Separate segments of code determine what action should be taken for each type of interrupt Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 13 / 43

I/O Structure After I/O starts, control returns to user program only upon I/O completion. wait instruction idles the CPU until the next interrupt wait loop (contention for memory access). At most one I/O request is outstanding at a time, no simultaneous I/O processing. After I/O starts, control returns to user program without waiting for I/O completion. System call request to the operating system to allow user to wait for I/O completion. Device-status table contains entry for each I/O device indicating its type, address, and state. Operating system indexes into I/O device table to determine device status and to modify table entry to include interrupt. Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 14 / 43

Hardware Protection Dual-Mode Operation I/O Protection Memory Protection CPU Protection Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 15 / 43

Dual Mode Operation Sharing system resources requires operating system to ensure that an incorrect program cannot cause other programs to execute incorrectly. Provide hardware support to differentiate between at least two modes of operations. User mode execution done on behalf of a user. Monitor mode (also supervisor mode or system mode) execution done on behalf of operating system. Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 16 / 43

Dual Mode Operation contd.. Mode bit added to computer hardware to indicate the current mode: monitor (0) or user (1). When an interrupt or fault occurs hardware switches to monitor mode. Interrupt/fault monitor user set user mode Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 17 / 43

I/O Protection All I/O instructions are privileged instructions. Must ensure that a user program could never gain control of the computer in monitor mode (I.e., a user program that, as part of its execution, stores a new address in the interrupt vector). Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 18 / 43

Memory Protection Must provide memory protection at least for the interrupt vector and the interrupt service routines. In order to have memory protection, add two registers that determine the range of legal addresses a program may access: Base register : holds the smallest legal physical memory address. Limit register : contains the size of the range Memory outside the defined range is protected. Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 19 / 43

A Base And A Limit Register define A Logical Address Space Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 20 / 43

Protection Hardware Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 21 / 43

CPU Protection Timer interrupts computer after specified period to ensure operating system maintains control. Timer is decremented every clock tick. When timer reaches the value 0, an interrupt occurs. Timer commonly used to implement time sharing. Load-timer is a privileged instruction. Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 22 / 43

General-System Architecture Given the I/O instructions are privileged, how does the user program perform I/O? System call the method used by a process to request action by the operating system. Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 23 / 43

System Calls Programming interface to the services provided by the OS Typically written in a high-level language (C, C++). Maybe in assembly Performs basic functions that requires communication with CPU, memory and devices All activities related to file handling, memory managemnt and process management are handled by system calls Examples : getuid() - get the user ID fork() - create a child process exec() - executing a program Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 24 / 43

System Calls contd... System call usually takes the form of a trap to a specific location in the interrupt vector. Control passes through the interrupt vector to a service routine in the OS, and the mode bit is set to monitor mode. The OS verifies that the parameters are correct and legal, executes the request, and returns control to the instruction following the system call. Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 25 / 43

Use of APIs in system calls System calls are 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, and Mac OS X), and Java API for the Java virtual machine (JVM) Why use APIs rather than system calls? Underlying systems calls (error codes) can be more complicated. API gives a uniform, portable interface One need not remeber I/O registers or order of I/O operation APIs example : BOOL ReadFile c(handle file, LPVOID buffer, DWORD bytes to read, LPDWORD bytes read, LPOVERLAPPED ovl); Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 26 / 43

API System Call OS Relationship Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 27 / 43

Example of API-System call System call sequence to copy the contents of one file to another file (POSIX like C pseudo code) (bold are API system calls) write(1, Input file, 11); read(0, &buffer, 100);... fd = open(buffer,o RDONLY); outfd = open(buffer,o WRONLY O CREAT O TRUNC,0666); if(outfd<0)abort( File creation failed );... closefd; Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 28 / 43

Standard C library example Some library calls themselves make system calls ex: C program invoking printf library call which calls write system call Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 29 / 43

Steps in Making a System Call, Example : read call read(fd,buffer,nbytes) Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 30 / 43

System Call Implementation A number associated with each system call System-call interface maintains a table indexed according to these numbers Additional info: check /usr/include/sys/syscall.h The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values The caller need know nothing about how the system call is implemented Just needs to obey API and understand what OS will do as a result call Details of OS interface hidden from programmer by API Managed by run-time support library (set of functions built into libraries included with compiler) Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 31 / 43

System Call Parameter Passing More information is required than simply identity of desired system call Three general methods used to pass parameters to the OS Simplest: pass the parameters in hardware registers Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register (This approach taken by Linux and Solaris) Parameters placed, or 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 Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 32 / 43

Parameter Passing via Table Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 33 / 43

Use of A System Call Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 34 / 43

Some System Calls For Process Management Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 35 / 43

Some System Calls For Directory Management Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 36 / 43

Some System Calls For Miscellaneous Tasks Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 37 / 43

System Call Example Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 38 / 43

System programs Provide a convenient environment for program development and execution. Some of them are simply user interfaces to system calls; others are considerably more complex File management - Create, delete, copy, edit, rename, print, dump, list, and generally manipulate files and directories Programming-language support - Compilers, assemblers, debuggers and interpreters sometimes provided Program loading and execution- Absolute loaders, relocatable loaders, linkage editors, and overlay-loaders, debugging systems for higher-level and machine language Communications - chat, web browsing, email, remote login, file transfers Status information - system info such as date, time, amount of available memory, disk space, number of users Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 39 / 43

Interfacing with OS User Interface Command Line Interface (CLI) : The command line may itself perform functions or call other system programs to implement functions (e.g. in UNIX, /bin/rm to remove files). Examples are shell in UNIX and command.exe in Windows Graphics User Interface (GUI) : Point and click interface. Examples are MS windows, MAC OS X Aqua, Unix X & variants. Batch : Commands are given using a file/command script to the OS and are executed with little user interaction. Examples are.bat files in DOS, shell scripts Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 40 / 43

Operating System Generation Operating systems are designed to run on any of a class of machines; the system must be configured for each specific computer site SYSGEN program obtains information concerning the specific configuration of the hardware system Booting starting a computer by loading the kernel Bootstrap program code stored in ROM that is able to locate the kernel, load it into memory, and start its execution Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 41 / 43

System Boot Operating system must be made available to hardware so hardware can start it Small piece of code bootstrap loader, locates the kernel, loads it into memory, and starts it Sometimes two-step process where boot block at fixed location loads bootstrap loader When power initialized on system, execution starts at a fixed memory location - Firmware used to hold initial boot code Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 42 / 43

Some Fundamental Concepts about OS Process Memory Files Process : Program in execution Address Space - list of address locations which the process can read or write. Address space contains the following: program, program s data and stack registers associated with the program Program counter and Stack Pointer PSW When a process is suspended temporarily (such as in time sharing system), it must be restarted in the same state in which it was stopped - information about process needs to be saved information of a suspended process is stored in process table Deadlock : Two interacting process get into a stalemate position through which they cannot get out (Analogous to deadlock in traffic) Bibhas Ghoshal IOSY 332C & IOPS 332C: OS Autumn Semester, 2015 43 / 43