OS Structure. Kevin Webb Swarthmore College January 25, Relevant xkcd:

Similar documents
CS 31: Intro to Systems Operating Systems Overview. Kevin Webb Swarthmore College November 8, 2018

Memory Management. Kevin Webb Swarthmore College February 27, 2018

OS DESIGN PATTERNS II. CS124 Operating Systems Fall , Lecture 4

Input / Output. Kevin Webb Swarthmore College April 12, 2018

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

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Four Components of a Computer System

Operating System Architecture. CS3026 Operating Systems Lecture 03

Operating System Structure

CS 31: Intro to Systems Operating Systems Overview. Kevin Webb Swarthmore College March 31, 2015

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

Operating System Structure

CS 550 Operating Systems Spring Operating Systems Overview

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

OS structure. Process management. Major OS components. CSE 451: Operating Systems Spring Module 3 Operating System Components and Structure

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

Chapter 2. Operating-System Structures

Hardware OS & OS- Application interface

Processes, Context Switching, and Scheduling. Kevin Webb Swarthmore College January 30, 2018

Operating System Structure

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

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

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

CS 104 Computer Organization and Design

Chapter 2: Operating-System Structures

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

ADVANCED OPERATING SYSTEMS USB in a microkernel based operating system

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018

COS 318: Operating Systems. File Systems. Topics. Evolved Data Center Storage Hierarchy. Traditional Data Center Storage Hierarchy

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

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

COS 318: Operating Systems

Module 1 Introduction/OS Overview

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

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

Operating Systems. System calls. Guillaume Salagnac. Fall Insa-Lyon IST Semester

Networks and Operating Systems Chapter 11: Introduction to Operating Systems

Real Time and Embedded Systems. by Dr. Lesley Shannon Course Website:

Anne Bracy CS 3410 Computer Science Cornell University

CSE 120 Principles of Operating Systems

Operating System. Operating System Overview. Structure of a Computer System. Structure of a Computer System. Structure of a Computer System

Virtualization Overview NSRC

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

CS 31: Intro to Systems Digital Logic. Kevin Webb Swarthmore College February 3, 2015

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

1 System & Activities

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

CS 326: Operating Systems. Process Execution. Lecture 5

CS 31: Intro to Systems Digital Logic. Kevin Webb Swarthmore College February 2, 2016

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

COS 318: Operating Systems

Storage and File System

Chapter 2: System Structures

Cute Tricks with Virtual Memory

Last time: introduction. Networks and Operating Systems ( ) Chapter 2: Processes. This time. General OS structure. The kernel is a program!

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Processes & Threads. Process Management. Managing Concurrency in Computer Systems. The Process. What s in a Process?

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

Processes and Threads

6.033 Spring Lecture #6. Monolithic kernels vs. Microkernels Virtual Machines spring 2018 Katrina LaCurts

Processes and Non-Preemptive Scheduling. Otto J. Anshus

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

Kernels & Processes The Structure of the Operating System

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

Mon Sep 17, 2007 Lecture 3: Process Management

Operating-System Structures

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

Lecture 3: O/S Organization. plan: O/S organization processes isolation

CSC 369H1S. Operating Systems Spring 2007 Professor Angela Demke Brown U of T

Operating System Structure

Operating System Services

CSCI 6730 / 4730 Operating Systems. Key Questions in System Design. Review: What is An Operating System? Key Points

Introduction CHAPTER. Review Questions

L4/Darwin: Evolving UNIX. Charles Gray Research Engineer, National ICT Australia

Reserves time on a paper sign-up sheet. Programmer runs his own program. Relays or vacuum tube hardware. Plug board or punch card input.

CSci 4061 Introduction to Operating Systems. (Thread-Basics)

Process Time. Steven M. Bellovin January 25,

Operating System Structure

Anne Bracy CS 3410 Computer Science Cornell University

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

Operating-System Structures

Operating Systems Overview. Chapter 2

Overview of the OS. CS 450 : Operating Systems Michael Saelee

Introduction to Operating Systems (Part III)

Process Address Spaces and Binary Formats

Introduction to Operating Systems. Chapter Chapter

Operating Systems Course Overview

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

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

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

CS Operating Systems

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

Process Description and Control

Chapter 3: Operating-System Structures

Chapter 2: Operating-System Structures

Address spaces and memory management

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Transcription:

OS Structure Kevin Webb Swarthmore College January 25, 2018 Relevant xkcd: One of the survivors, poking around in the ruins with the point of a spear, uncovers a singed photo of Richard Stallman. They stare in silence. "This," one of them finally says, "This is a man who BELIEVED in something."

Today s Goals Broad strokes: processes, resources, and protection Terminology (kernel, interrupts, traps, system calls, exceptions, ) Operating system structure and design patterns

Kernel vs. Userspace: Terminology OS & Kernel - interchangeable in this course Compiled Linux kernel: ~5-10 MB Fully installed system - a few GB Most of this is user-level programs that get executed as processes System utilities, graphical window system, shell, text editor, etc.

Primary Abstraction: The Process Abstraction of a running program a dynamic program in execution Program: blueprint Process: constructed building Program: class Process: instance

Basic Process Resources 1. CPU Time execute a stream of instructions 2. Main memory storage store variables / scratch space 3. Input/Output (I/O) interact with the outside world 4. Also: State (metadata) bookkeeping kernel data structures Programmer / user doesn t see this Details next time

Process Resource: CPU Time CPU: Central Processing Unit Program Counter (PC): Instruction Register (IR): Memory address of next instr Instruction contents (bits) PC points to next instruction CPU loads instruction, decodes it, executes it, stores result Process given CPU by OS Mechanism: context switch Policy: CPU scheduling in WE in WE in WE in WE Required for process to execute and make progress! 32-bit Register #0 32-bit Register #1 32-bit Register #2 32-bit Register #3 Register File MUX MUX A L U

Process Resource: Main Memory Process must store: : code instructions : static (known at compile time) variables : dynamically requested memory at runtime (malloc, new, etc.) 0x0 Operating system : store local variables and compiler-generated function call state (e.g., saved registers) Required for process to store instructions (+data)! 0xFFFFFFFF

Process Resource: I/O Allows processes to interact with a variety of devices (i.e., everything that isn t a CPU or main memory). Enables files, communication, human interaction, etc. Disk Learn about or change the state of the outside world. Required? Wireless Network Keyboard / Mouse

Is I/O a requirement for processes? A. Yes B. No

Is the kernel a process? Should it be? Could it be? A. Yes it is, and it should be. B. Yes it is, but it shouldn t be. C. No it isn t, but it should be. D. No it isn t, and it can t be. E. Something else

OS Kernel Many styles / ways to structure a kernel Unless we say otherwise: assume the OS is not a process! It s a special management entity It supports the user s processes, but is a special case with different needs The OS might create some processes to help itself out e.g., Linux flushes buffered data to disks periodically Other OS styles: kernel processes take a larger role, but still a core kernel

Kernel vs. Userspace: Model Process 1 Process 2 Process N OS OS OS System Calls fork read write Kernel System Management Context Switching Scheduling

Kernel vs. Userspace: Model Process 1 Process 2 Process N Code: : OS OS OS Code: System Calls fork read write Kernel System Management Context Switching Scheduling Code + :

How/When should the OS Kernel s code execute? A. The kernel code is always executing. B. The kernel code executes when a process asks it to. C. The kernel code executes when the hardware needs it to. D. The kernel code should execute as little as possible. E. The kernel code executes at some other time(s).

Same Question, Different Resource How much of the system s memory should the OS use? Hopefully not much just enough to get its work done. Leave the rest for the user!

OS: Taking Control of the CPU The terminology here is, unfortunately, muddy. 1. System call user requests service from the OS Trap 2. Exception user process has done something that requires help 3. (Hardware) interrupt a device needs attention from the OS System call often implemented as a special case of exception: execute intentional exception-generating instruction.

Why make system calls? A. Reliability: Kernel code always behaves the same. B. Security: Programs can t use kernel code in unintended ways. C. Usability: Kernel code is easier / adds value for programmers to use. D. More than one of the above. E. Some other reason(s).

Common Functionality Some functions useful to many programs I/O device control Memory allocation Place these functions in kernel Called by programs (system calls) Or accessed implicitly as needed (exceptions) What should these functions be? How many programs should benefit? Might kernel get too big?

How about a function like printf()? A. printf() is a system call (why?) B. printf() is not a system call (why not, what is it?) Some functions useful to many programs I/O device control Memory allocation Place these functions in kernel Called by programs (system calls) Or accessed implicitly as needed (exceptions) What should these functions be? How many programs should benefit? Might kernel get too big?

System Calls in Practice Often hidden from user by libraries (e.g., libc) for convenience printf: performs a write() system call, but handles variable-length arguments raw syscall does as little as possible. write(): move (already formatted) data How can you tell if a function is a syscall or belongs to a library? Man page section number: 2 syscall, 3 library Follow the trail of included header files

Syscall Protection Features Small syscalls: minimize attack surface area in trusted kernel code. Hardware mode: x86 / amd64 rings Ring 0 Ring 1 Ring 2 Ring 3

Syscall Protection Features Small syscalls: minimize attack surface area in trusted kernel code. Hardware mode: x86 / amd64 rings Ring 0 Hypervisor Guest Kernel unused user processes Virtualization Ring 0 Kernel unused unused user processes Traditional (Unix, Windows)

Syscall Protection Features Small syscalls: minimize attack surface area in trusted kernel code. Hardware mode: x86 / amd64 rings Privileged instructions Well-defined syscall entry points amplify power, switch mode to ring 0 Ring 0 Kernel unused unused user processes Traditional (Unix, Windows)

Syscall Entry Points - Note This behavior is different from user space code, where to execute a new function we just specify which instruction to jump to Switching into the kernel means we guarantee kernel code will start running at a fixed point in the code the beginning of a function Guarantees we will run an entire function, not just some part of it (your process is no longer in control of the CPU)

Structure of a Kernel Simple (MS-DOS, early UNIX) Monolithic + Modules (Linux, Windows 9x) Microkernel (Mach) Hybrid (Windows NT, XNU/OS X)

Structure of a Kernel Simple (MS-DOS, early UNIX) Monolithic + Modules (Linux, Windows 9x) Microkernel (Mach) There is no one-size-fits-all solution! Hybrid (Windows NT, XNU/OS X)

Simple (MS-DOS) User Application System Programs MS-DOS Device Drivers BIOS Device Drivers

What s problematic about this simple model? A. Insecure B. Inefficient C. Hard to add functionality D. More than one of the above E. Something else

What s problematic about this simple model? A. Insecure B. Inefficient C. Hard to add functionality D. More than one of the above Solution: add the protection features we talked about earlier (or something similar)! Most importantly: Limit user s entry into important stuff. But where should the important stuff go? E. Something else

Monolithic without modules User process OS User process OS User process OS Problem: How many devices are you planning to support? Userspace Kernel OS Kernel: Signal handling, I/O system, terminal drivers, file system, swapping, device drivers, scheduling, page replacement, virtual memory Hardware

Modular Monolithic (Linux) User process OS User process OS User process OS Suppose user plugs in USB drive. Userspace Kernel OS Kernel (core services): Signal handling, I/O system, swapping, scheduling, page replacement, virtual memory file system: ext4 device driver: USB disk file system: fat32 Hardware

Modular Monolithic (Linux) User process OS User process OS User process OS Advantage: easily extensible. Can have lots of modules ready, only use the ones you need! Userspace Drawback: still one giant kernel. Kernel OS Kernel (core services): Signal handling, I/O system, swapping, scheduling, page replacement, virtual memory file system: ext4 device driver: USB disk file system: fat32 Hardware

Microkernel Kernel supports as little as possible: message-passing (communication between processes) process / task management memory allocation All other functionality delegated to user level processes

Userspace Kernel Microkernel User process OS User process OS User process OS Processes communicate with each other to get / provide services. Important system functionality implemented in userspace processes. OS process: file system OS OS process: device driver OS Minimal OS Kernel (core services): inter-process communication, scheduling, virtual memory Hardware

Microkernel Kernel supports as little as possible: message-passing (communication between processes) process / task management memory allocation All other functionality delegated to user level processes Benefits: Strong isolation between services, less trusted kernel code.

What s problematic about microkernels? A. Insecure B. Inefficient C. Hard to add functionality Problem: LOTS of transitioning between userspace and the kernel. We ll see: not a trivial operation D. More than one of the above E. Something else

Of the choices we ve seen so far, which do you like best / would you choose if you built an OS? Why? A. Simple B. Monolithic See: https://en.wikipedia.org/wiki/tanenbaum%e2%80%93torvalds_debate C. Monolithic + modules D. Microkernel E. Something else (?)

Hybrid Kernels NT Kernel (Used in modern Windows) Divided into modules Modules communicate via function calls or messaging Almost all modules run in kernel mode Some application system services run in user mode Graphics example: Graphics driver moved around a couple of times Initially -> Userspace process for isolation Later -> back to kernel for performance reasons

Hybrid Kernels XNU (OS X) Combines Mach (classic microkernel) with BSD Runs core Mach kernel, but with BSD subsystems and APIs added Mach communicates with BSD via IPC, but everything is running in kernel mode

Recent OS Research: Arrakis (2014) Applications have direct access to virtualized I/O devices, allowing most I/O operations to skip the kernel entirely... Takes advantage of hardware support for virtualizing I/O devices (meant for performance speedups in virtual machines) in order to guarantee protection

Summary Important distinction: userspace vs. the OS kernel We don t want the OS using resources, but it has to when it gets a system call, exception, or hardware interrupt. Transition to kernel amplifies power, allows privileged instructions Many patterns for structuring a kernel, each has merits and drawbacks monolithic, microkernel, hybrid