1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
Chapter 6 Limited Direct Execution
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
CSE 451: Operating Systems Section 2 Shells and System Calls.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1 CSE 451 Section Autumn 2004 Alex Moshchuk Office hours: Tue 1-2, Thu 4:30-5:30 Allen 218 (or lab)
CSE 451 Section Autumn 2005 Richard Dunn Office hours: WTh 3:30-4:20 Allen 216 (or lab)
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
OS Spring’03 Introduction Operating Systems Spring 2003.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Process Description and Control A process is sometimes called a task, it is a program in execution.
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
Virtual Machine Monitors CSE451 Andrew Whitaker. Hardware Virtualization Running multiple operating systems on a single physical machine Examples:  VMWare,
CSE 451: Operating Systems Section 2 Interrupts, Syscalls, Virtual Machines, and Project 1.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
System Calls 1.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Project 2: Initial Implementation Notes Tao Yang.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
Operating Systems Process Creation
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Lecture 26 Virtual Machine Monitors. Virtual Machines Goal: run an guest OS over an host OS Who has done this? Why might it be useful? Examples: Vmware,
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
CSE 451: Operating Systems Winter 2015 Module 25 Virtual Machine Monitors Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska,
CSE451 Section 2: Spring 2006 Kurtis Heimerl, YongChul Kwon
1 CSE 451 Section 2: Processes, the shell, and system calls.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
CSE 451 Section Autumn 2004 Alex Moshchuk Office hours: Tue 2-3, Thu 4:30-5:30 Allen 216 (or lab)
Of Privilege, Traps, Interrupts & Exceptions Prof. Sirer CS 316 Cornell University.
CSE 451 Section #3 Project 0 Recap Project 1 Overview
Introduction to Operating Systems Concepts
Exceptional Control Flow
Virtual Machine Monitors
Introduction to Operating Systems
Introduction to Kernel
Operating Systems CMPSC 473
Exceptional Control Flow
CSE 451 Section 2: Processes, the shell, and system calls
Protection and OS Structure
Anton Burtsev February, 2017
Protection of System Resources
Lecture 24 Virtual Machine Monitors
CS 3305 System Calls Lecture 7.
Intro to Processes CSSE 332 Operating Systems
Exceptional Control Flow: System Calls, Page Faults etc.
OS Virtualization.
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Architectural Support for OS
CSE 451 Section 2 – Winter 2006.
CSE 451 Section 2 - Spring 2005.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
CSE 451: Operating Systems Autumn Module 24 Virtual Machine Monitors
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
CSE 451: Operating Systems Autumn Module 24 Virtual Machine Monitors
Presentation transcript:

1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1

2 Project 0 How is it going? What's happening here? key == ht[loc]->key

3 Project 0 How is it going? What's happening here? key == ht[loc]->key Bad! Comparing pointers. Need a “deep equals” Must pass in an equality function Worry about it for this project Also, don’t forget about resizing! And memory management And memory leaks And edge cases And fun

Interrupts Interrupt Hardware or software Hardware interrupts caused by devices signalling CPU Software interrupts caused by code Exception Unintentional software interrupt E.g. errors, divide-by-zero, general protection fault Trap Intentional software interrupt Controlled method of entering kernel mode System calls

What happens in an interrupt? Execution halted CPU switched from user mode to kernel mode State saved Registers, stack pointer, PC With interrupt number index interrupt descriptor table to find handler Run handler Handler is (mostly) just a function pointer Restore state CPU switched from kernel mode to user mode Resume execution

Interrupts What happens if there's another interrupt during the handler? What happens if an interrupt fires when they are disabled?

System calls An invocation of an OS service – So the OS can manage and protect services Requires architectures support – But the most basic mechanism is just an interrupt

Syscall control flow User application calls a library User-level library call Invoke system call through stub _syscallN() sets up arguments for the OS Interrupt (probably) Syscall handler indexes system call table to find a vector to jump to OS performs operation Must check arguments! Cannot allow user to trick the OS into performing an unsafe operation! OS prepares return OS returns from interrupt and resume user

How Linux does syscalls You can see what happens when the kernel invokes a syscall here: Arch/x86/kernel/entry_32.S If you don't mind reading assembly Doesn't really use “interrupts” anymore “int 0x80” and “iret” replaced by “sysenter” and “sysexit” Similar operations supported by architecture

Syscalls with a SW VMM read() syscall trap handler handle read syscall read from disk() trap privileged instruction If “kernel” mode: emulate virtual disk else: raise protection violation finish read syscall copy data to user buffer return from system call return from read() Application Guest OSVMM

But really... ApplicationGuest OSVMMHardware read() syscall trap detected trap handler; change VM to “kernel” mode trap handler handle read syscall read from disk() priv insc. detected trap handler; emulate I/O

Syscalls with a HW VMM System call and interrupt vectors for the guest OS are loaded into hardware. There's actually no VMM intervention required (if it doesn't require a host OS service) In a read, we still need to go to the VMM for the hardware I/O. But, this is only one case. Sometimes SW beats HW.

Paravirtualization Duplicate a similar architecture Compromise: use HW and guest OS in harmony Reduce duplicated work in guest OS Breaks fidelity! Requires changes to guest OS like its being implemented for a new platform

Not enough? For masochists: A Comparison of Software and Hardware Techniques for x86 Virtualization ms.pdf

15 Project 1 Two main parts: Write a simple shell in C Add a simple system call to Linux kernel Due: Mon., Oct 19, 11:59pm Electronic turnin: code + writeup

16 The CSE451 shell Print out prompt Accept input Parse input If built-in command do it directly Else spawn new process Launch specified program Wait for it to finish Repeat CSE451Shell% /bin/date Fri Jan 16 00:05:39 PST 2004 CSE451Shell% pwd /root CSE451Shell% cd / CSE451Shell% pwd / CSE451Shell% exit

17 CSE451 Shell Hints In your shell: Use fork to create a child process Use execvp to execute a specified program Use wait to wait until child process terminates Useful library functions (see man pages): Strings: strcmp, strncpy, strtok, atoi I/O: fgets Error report: perror Environment variables: getenv

18 Adding a System Call Add execcounts system call to Linux: Purpose: collect statistics Count number of times you call fork, vfork, clone, and exec system calls. Steps: Modify kernel to keep track of this information Add execcounts to return the counts to the user Use execcounts in your shell to get this data from kernel and print it out.

19 Programming in kernel mode Your shell will operate in user mode Your system call code will be in the Linux kernel, which operates in kernel mode Be careful - different programming rules, conventions, etc.

20 Programming in kernel mode Can’t use application libraries (e.g. libc) E.g. can’t use printf Use only functions defined by the kernel E.g. use printk instead Include files are different in the kernel Don’t forget you’re in kernel space You cannot trust user space E.g. unsafe to access a pointer from user space directly

21 Kernel development hints Best way to learn: read existing code Use grep –r search_string * – -I for case-insensitive Use LXR (Linux Cross Reference):