Timers 1 / 46. Jiffies. Potent and Evil Magic

Similar documents
PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Midterm Exam. October 20th, Thursday NSC

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Chapter 2 Processes and Threads

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Main Points of the Computer Organization and System Software Module

CS 326: Operating Systems. CPU Scheduling. Lecture 6

Chendu College of Engineering & Technology

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Lecture 9: Midterm Review

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

To Everyone... iii To Educators... v To Students... vi Acknowledgments... vii Final Words... ix References... x. 1 ADialogueontheBook 1

Advanced Operating Systems (CS 202) Scheduling (1)

CSC 4320 Test 1 Spring 2017

Process Time. Steven M. Bellovin January 25,

8: Scheduling. Scheduling. Mark Handley

Course Syllabus. Operating Systems

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

Dealing with Issues for Interprocess Communication

CSI3131 Final Exam Review

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies


NuttX Realtime Programming

Native POSIX Thread Library (NPTL) CSE 506 Don Porter

CSE Traditional Operating Systems deal with typical system software designed to be:

STUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total

HY345 - Operating Systems

CS450/550 Operating Systems

CSE 153 Design of Operating Systems

What are they? How do we represent them? Scheduling Something smaller than a process? Threads Synchronizing and Communicating Classic IPC problems

HY 345 Operating Systems

Course Description: This course includes the basic concepts of operating system

True/False: In Signal and Wait, the signaller finishes execution while the signalled process waits for its turn

CMPS 111 Spring 2003 Midterm Exam May 8, Name: ID:

MARUTHI SCHOOL OF BANKING (MSB)

Lesson 6: Process Synchronization

CSE 4/521 Introduction to Operating Systems

Uniprocessor Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Three level scheduling

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

Tasks. Task Implementation and management

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Subject Name: OPERATING SYSTEMS. Subject Code: 10EC65. Prepared By: Kala H S and Remya R. Department: ECE. Date:

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

LINUX OPERATING SYSTEM Submitted in partial fulfillment of the requirement for the award of degree of Bachelor of Technology in Computer Science

Operating Systems Design Exam 1 Review: Spring 2012

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

W4118 Operating Systems. Junfeng Yang

CS450/550 Operating Systems

POSIX Threads: a first step toward parallel programming. George Bosilca

CLASS: II YEAR / IV SEMESTER CSE SUBJECT CODE AND NAME: CS6401 OPERATING SYSTEMS UNIT I OPERATING SYSTEMS OVERVIEW

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

Concurrent & Distributed Systems Supervision Exercises

Modern Computers often do lots of things at the same time (web servers, accessing disks, background processes waiting for s,...).

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

CS 153 Design of Operating Systems Winter 2016

Chapter 6: Process Synchronization

EECS 482 Introduction to Operating Systems

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

C09: Process Synchronization

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Lecture 21 Disk Devices and Timers

CS350: Final Exam Review

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

SMD149 - Operating Systems

QUESTION BANK UNIT I

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Administration. Matteo Corti RZ H


Department of Computer applications. [Part I: Medium Answer Type Questions]

PROCESS SCHEDULING II. CS124 Operating Systems Fall , Lecture 13

CSE 451 Midterm 1. Name:

Systemy RT i embedded Wykład 11 Systemy RTOS

SYED AMMAL ENGINEERING COLLEGE CS6401- OPERATING SYSTEM

Operating Systems Comprehensive Exam. Spring Student ID # 2/17/2011

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

CHAPTER 6: PROCESS SYNCHRONIZATION

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Scheduling Mar. 19, 2018

Midterm Exam Amy Murphy 6 March 2002

CMSC421: Principles of Operating Systems

CS 326: Operating Systems. Process Execution. Lecture 5

Interrupts and Time. Real-Time Systems, Lecture 5. Martina Maggio 28 January Lund University, Department of Automatic Control

( D ) 4. Which is not able to solve the race condition? (A) Test and Set Lock (B) Semaphore (C) Monitor (D) Shared memory

CSE 153 Design of Operating Systems

Operating Systems. Introduction & Overview. Outline for today s lecture. Administrivia. ITS 225: Operating Systems. Lecture 1

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Multiprocessor and Real-Time Scheduling. Chapter 10

Interrupts and Time. Interrupts. Content. Real-Time Systems, Lecture 5. External Communication. Interrupts. Interrupts

CHAPTER NO - 1 : Introduction:

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018

Transcription:

Timers 1 / 46 Jiffies Each timer tick, a variable called jiffies is incremented It is thus (roughly) the number of HZ since system boot A 32-bit counter incremented at 1000 Hz wraps around in about 50 days We need 64 bits but there s a problem 2 / 46 Potent and Evil Magic A 64-bit value cannot be accessed atomically on a 32-bit machine A spin-lock is used to synchronize access to jiffies 64; kernel routines call get jiffies 64() But we don t want to have to increment two variables each tick Linker magic is used to make jiffies the low-order 32 bits of jiffies 64 Ugly! 3 / 46 1

Time of Day The time of day is stored in xtime, which is a struct timespec It s incremented once per tick Again, a spin-lock is used to synchronize access to it The apparent tick rate can be adjusted slightly, via the adjtimex() system call 4 / 46 Kernel Timers Two types of timers use by kernel routines Dynamic timer call some routine after a particular interval Delay loops tight spin loops for very short delays User-mode interval timers are similar to kernel dynamic timers 5 / 46 2

Dynamic Timers Specify an interval, a subroutine to call, and a parameter to pass to that subroutine Parameter used to differentiate different instantiations of the same timer if you have 4 Ethernet cards creating dynamic timers, the parameter is typically the address of the per-card data structure Timers can be cancelled; there is (as usual) a delicate synchronization dance on multiprocessors. See the text for details 6 / 46 Delay Functions Spin in a tight loop for a short time microseconds or nanoseconds Nothing else can use that CPU during that time, except via interrupt Used only when the overhead of creating a dynamic timer is too great for a very short delay 7 / 46 3

System Calls time() and gettimeofday() adjtimex() tweaks apparent clock rate (even the best crystals drift; see the Remote Physical Device Fingerprinting paper from my COMS E6184 class setitimer() and alarm() interval timers for applications 8 / 46 The Test 9 / 46 Conditions Closed book, closed notes, calculator ok 75 minutes 10 / 46 4

Format Approximately 8 questions I m not asking you to write programs Three types of questions Explanations of certain concepts, somewhat above the pure memorization level Carrying out tasks based on things discussed in class Design questions (i.e., ones intended to make you think) 11 / 46 Material If it s in my slides or I said it in class, you re responsible for it There will be some material based more on Tanenbaum; there won t be much from Linux internals You re responsible for the assigned readings at about the level of class coverage. I m not going to ask you to memorize the crazy synchronization algorithms, but if one shows up you should be prepared to explain it 12 / 46 5

Limits I can t quiz you on everything I ve covered in a dozen lectures I can t review 15 hours of class time today I m to some extent limited by the kinds of things it s feasible to ask on an exam 13 / 46 Review 14 / 46 What s an Operating System? Resource manger Multiplexor Fairness Protection 15 / 46 6

Pieces of an OS Kernel Scheduler Memory management File systems Device drivers 16 / 46 History of Operating Systems Single-user Punchcard+printer spooling to mag tape Early monitor programs Lack of memory protection I/O libraries 17 / 46 7

3rd Generation Computers Disks, memory protection, schedulers Reasons: efficiency; CPUs were expensive Timesharing 18 / 46 Minicomputers Much cheaper Used similarly to old systems no memory protection, small disks if any, etc. 19 / 46 8

Microcomputers Same evolutionary path Took almost 20 years to get modern OS features 20 / 46 Hardware Features Memory protection Privileged operations Interrupts and system calls Timers 21 / 46 9

Multiprogramming Run several programs at once; precise order and timing don t matter What s a process? Separately scheduled, protection, isolation, distinct from threads Lots of per-process state User- and kernel-level stacks Process creation and inheritance 22 / 46 Processes Separately scheduled; isolated and protected Lots of per-process state Kernel stack per process Process creation: copying, inheritance, etc. Process relationships 23 / 46 10

Threads Non-preemptive scheduling Used in most graphical applications Implementable three different ways: user, kernel, scheduler activations The need for reentrancy 24 / 46 Signals Interrupts to process Catchable; different default actions Watch for race conditions 25 / 46 11

Linux Processes and Interrupts Reality is more complex: efficiency Lightweight processes: used for threads; less to copy Several data structures, some indirect; kernel stack pointer is the handle for most of them Wait queues for sleeping processes Processes put themselves to sleep 26 / 46 Switching Processes Save general registers on the stack; other hardware context in task struct Loading new state switches processes; the stack pointer determines most of the state Changing the kernel stack pointer changes the process 27 / 46 12

Creating a Process Fork() vs. vfork() vs. clone() Copy on write for memory why? Exiting must close files; process is a zombie until wait() call issued 28 / 46 Interrupts Synchronous (faults and traps) vs. asynchronous IRQs and priorities Interrupt masking Entering an interrupt handler; returning from interrupts First- vs. second-level interrupt handlers No process context for interrupts Deferred work softirqs, tasklets, work queues 29 / 46 13

System Calls Why? C code vs. assembler glue Calling conventions: stack vs. registers Copying data to/from user space 30 / 46 Race Conditions; Critical Regions Why they happen Where they can happen Critical regions and blocking Desired properties 31 / 46 14

Lock Variables Care needed; must have atomicity Test and Set Lock locks memory bus Strict alternation; properties of Peterson s Algorithm Spin locks and priority inversion 32 / 46 Semaphores Operations: down and up; what they do Different uses of semaphores: counting vs. exclusion (mutex) 33 / 46 15

Monitors Programming language construct Operations: wait and signal 34 / 46 Synchronization Problems Dining philosophers Watch for deadlocks and starvation Readers and writers 35 / 46 16

Deadlock What s a deadlock? Conditions for deadlocks Recovery, avoidance, prevention Release and rerequest Two-phase locking 36 / 46 Scheduling What is it? Types of schedulers and their goals Batch, interactive, real-time First come, first served Shortest first Shortest remaining time 37 / 46 17

Interactive Scheduling Round robin Quantum length issues: responsiveness vs. overhead; variable size Priority scheduling and aging Interactivity boost Security issues 38 / 46 More Scheduling Process history moving average Guaranteed scheduling Lottery scheduling Fair share scheduling 39 / 46 18

Real-Time Scheduling Hard vs. soft real-time Periodic vs. aperiodic; mixing with non-real-time Rate Monotonic Earliest Deadline First 40 / 46 Multiprocessing Asymmetric vs. symmetric Locking: fine-grained vs. coarse 41 / 46 19

Measuring Time Statistical time I/O, memory, and the scheduler 42 / 46 Evaluation What s the metric? What are you optimizing for? Deterministic, queueing theory, simulation, build it Limits to evaluation 43 / 46 20

Linux Scheduler O(1) Run queue per processor 140 run queues per processor High priority processes get long quanta Dynamic priority for quick boost Run each queue once before starting at the high priority again 44 / 46 Sleeping and Waking Processes sleep on queues Queues are awakened, not processes; must check if condition is satisfied 45 / 46 21

Timers Time of day and interval timer Types of timers What happens at each tick? Dynamic timers 46 / 46 22