ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Similar documents
CHAPTER 2: PROCESS MANAGEMENT

Lecture 2 Process Management

Chapter 5 CPU scheduling

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Chapter 5: CPU Scheduling

Chapter 5: CPU Scheduling

CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. Dispatcher. CPU Scheduler. Alternating Sequence of CPU and I/O Bursts

Chapter 5: CPU Scheduling

Chapter 5: CPU Scheduling. Operating System Concepts Essentials 8 th Edition

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition,

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

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

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Last class: Today: CPU Scheduling. CPU Scheduling Algorithms and Systems

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Chapter 5: Process Scheduling

Processes and Threads

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

CS 4284 Systems Capstone. Resource Allocation & Scheduling Godmar Back

CS307: Operating Systems

TDIU25: Operating Systems II. Processes, Threads and Scheduling

Processes and Threads

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

Process- Concept &Process Scheduling OPERATING SYSTEMS

Last Class: Processes

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Chapter 5 Scheduling

SMD149 - Operating Systems

Chapter 6: CPU Scheduling

Operating Systems CS 323 Ms. Ines Abbes

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Advanced Operating Systems (CS 202) Scheduling (1)

CSCE 313: Intro to Computer Systems

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

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

Operating Systems. Figure: Process States. 1 P a g e

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

CS370 Operating Systems

CS370 Operating Systems

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

CPU Scheduling: Objectives

Chapter 5 Process Scheduling

LECTURE 3:CPU SCHEDULING

Operating Systems ECE344. Ding Yuan

Job Scheduling. CS170 Fall 2018

CS3733: Operating Systems

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

INF1060: Introduction to Operating Systems and Data Communication. Pål Halvorsen. Wednesday, September 29, 2010

Chapter 6: CPU Scheduling

Properties of Processes

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Operating Systems. Process scheduling. Thomas Ropars.

Unit 3 : Process Management

Scheduling in the Supermarket

CSE 4/521 Introduction to Operating Systems

CS370 Operating Systems

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

Chapter 5: Process Scheduling

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

Process Concept Process in Memory Process State new running waiting ready terminated Diagram of Process State

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

Announcements/Reminders

Course Syllabus. Operating Systems

Scheduling of processes

Titolo presentazione. Scheduling. sottotitolo A.Y Milano, XX mese 20XX ACSO Tutoring MSc Eng. Michele Zanella

Scheduling. Today. Next Time Process interaction & communication

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

CS 322 Operating Systems Practice Midterm Questions

Process Concepts 8/21/2014. CS341: Operating System. Scheduling: Theoretical Analysis

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Assignment 3 (Due date: Thursday, 10/15/2009, in class) Part One: Provide brief answers to the following Chapter Exercises questions:

Process Description and Control

Chapter 4: Threads. Operating System Concepts with Java 8 th Edition

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

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

CS370 Operating Systems

Processes and Threads. Processes: Review

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Interactive Scheduling

Two Level Scheduling. Interactive Scheduling. Our Earlier Example. Round Robin Scheduling. Round Robin Schedule. Round Robin Schedule

Chapter 3: Processes. Operating System Concepts 8th Edition

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

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

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

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Practice Exercises 305

Chapter 6: CPU Scheduling

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

COSC243 Part 2: Operating Systems

Chapter 5: CPU Scheduling. Operating System Concepts 9 th Edit9on

Frequently asked questions from the previous class survey

CS 326: Operating Systems. CPU Scheduling. Lecture 6

CSL373: Lecture 6 CPU Scheduling

Operating Systems. Scheduling

Transcription:

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective Part I: Operating system overview: Processes and threads 1

Overview Process concept Process scheduling Thread concept 2

Process These are all possible definitions: A program in execution, and process execution must progress in sequential fashion An instance of a program running on a computer Schedulable entity (*) Unit of resource ownership Unit of protection Execution sequence (*) + current state (*) + set of resources (*) can be said of threads as well 3

Process in Memory A process includes text section program counter stack data section heap 4

Data placement, seen from C/C++ int a; static int b; int c = 5; struct S { int t; }; struct S s; void func(int d) { static int e; int f; struct S w; int *g = new int[10]; } Q.: where are these variables stored? A.: On stack: d, f, w (including w.t), g On (global) data section: a, b, c, s (including s.t), e On the heap: g[0] g[9] 5

Process State As a process executes, it changes state new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur ready: The process is waiting to be assigned to a processor terminated: The process has finished execution 6

Process Control Block (PCB) PCB records information associated with each process Process identifier (pid) Value of registers, including stack pointer Program counter CPU registers Information needed by scheduler Process state Other CPU scheduling information Resources held by process: Memory-management information I/O status information Accounting information 7

Context Switching Multiprogramming: switch to another process if current process is (momentarily) blocked Time-sharing: switch to another process periodically to make sure all process make equal progress this switch is called a context switch. Understand how it works how it interacts with user/kernel mode switching how it maintains the illusion of each process having the CPU to itself (process must not notice being switched in and out!) 8

CPU Switch From Process to Process 1) Save the current process s execution state to its PCB 2) Update current s PCB as needed 3) Choose next process N 4) Update N s PCB as needed 5) Restore N s PCB execution state May involve reprogramming MMU 9

Process Scheduling Queues Processes are linked in multiple queues: Job queue set of all processes in the system Ready queue set of all processes residing in main memory, ready and waiting to execute Device queues (wait queue ) set of processes waiting for an I/O device or other events Processes migrate among the various queues 10

Ready Queue And Various I/O Device Queues 11

Representation of Process Scheduling 12

Schedulers Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue The long-term scheduler controls the degree of multiprogramming A good mix of processes can be described as either: I/O-bound process spends more time doing I/O than computations, many short CPU bursts CPU-bound process spends more time doing computations; few very long CPU bursts Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU 13

CPU Scheduling Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state 2. Switches from running to ready state 3. Switches from waiting to ready 4. Terminates 14

Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency time it takes for the dispatcher to stop one process and start another running 15

Static scheduling Static vs Dynamic Scheduling The arrival and execution times of all jobs are known in advance. It create a schedule, execute it Used in statically configured systems, such as embedded real-time systems Dynamic/online scheduling Jobs are not known in advance, scheduler must make online decision whenever jobs arrives or leaves Execution time may or may not be known Behavior can be modeled by making assumptions about nature of arrival process 16

Alternating Sequence of CPU And I/O Bursts 17

P1 CPU Scheduling Model Process alternates between CPU burst and I/O burst I/O Bound Process P2 CPU Bound Process Scheduling on the same CPU: Waiting CPU I/O P1 P2 18

CPU Scheduling Terminology A job (sometimes called a task, or a job instance) Activity that s schedulable: process/thread and a collection of processes that are scheduled together Arrival time: time when job arrives Start time: time when job actually starts Finish time: time when job is done Completion time (aka turn-around time) Finish time Arrival time Response time Time when user sees response Arrival time Execution time (aka cost): time a job needs to execute 19

CPU Scheduling Terminology (cont d) Waiting time = time when job was ready-to-run didn t run because CPU scheduler picked another job Blocked time = time when job was blocked while I/O device is in use Completion time Execution time + Waiting time + Blocked time 20

Minimize latency Can mean completion time Can mean response time Maximize throughput CPU Scheduling Goals Throughput: number of finished jobs per time-unit Implies minimizing overhead (for context-switching, for scheduling algorithm itself) Requires efficient use of non-cpu resources Fairness Minimize variance in waiting time/completion time 21

Scheduling Constraints Reaching those goals is difficult, because Goals are conflicting: Latency vs. throughput Fairness vs. low overhead Scheduler must operate with incomplete knowledge Execution time may not be known I/O device use may not be known Scheduler must make decision fast Approximate best solution from huge solution space 22

Round Robin (RR) Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. No more unfairness to short jobs or starvation for long jobs! Performance q large FIFO q small q must be large with respect to context switch, otherwise overhead is too high 23

Round Robin Cost of Time Slicing Context switching incurs a cost Direct cost (execute scheduler & context switch) + indirect cost (cache & TLB misses) Long time slices lower overhead, but approaches FCFS if processes finish before timeslice expires Short time slices lots of context switches, high overhead Typical cost: context switch < 10 us Time slice typical around 100 ms Linux: 100ms default, adjust to between 10ms & 300ms Note: time slice length!= interval between timer interrupts Timer frequency usually 1000Hz 24

Multi-Level Feedback Queue Scheduling Objectives: preference for I/O bound jobs (tends to lead to good I/O utilization) longer timeslices for CPU bound jobs (reduces context-switching overhead) Challenge: Don t know type of each process algorithm needs to figure out Solutions: use multiple queues queue determines priority usually combined with static priorities (nice values) many variations of this 25

Longer Timeslices Higher Priority MAX 1 2 3 MLFQS Processes start in the highest queue Process that use up their time slice move down MIN 4 Higher priority queues are served before lower-priority ones - within highest-priority queue, round-robin Only ready processes are in this queue - blocked processes leave queue and reenter same queue on unblock Processes that starve move up 26

Scheduling Summary OS must schedule all resources in a system CPU, Disk, Network, etc. CPU Scheduling affects indirectly scheduling of other devices Goals: (1) Minimize latency (2) Maximize throughput (3) Provide fairness In Practice: some theory, lots of tweaking 27

Single and Multithreaded Processes 28

Benefits of Multithreading Responsiveness Resource Sharing Economy Utilization of MP Architectures 29

User threads Thread Implementations Thread management done by user-level threads library Three primary thread libraries: POSIX Pthreads Win32 threads Java threads Kernel threads: Supported by the Kernel Examples Windows XP/2000 Solaris Linux Tru64 UNIX Mac OS X 30

#include <stdio.h> #include <stdlib.h> #include <pthread.h> void *print_message_function( void *ptr ); main() { pthread_t thread1, thread2; char *message1 = "Thread 1"; char *message2 = "Thread 2"; int iret1, iret2; /* Create independent threads each of which will execute function */ iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); /* Wait till threads are complete before main continues. Unless we */ /* wait we run the risk of executing an exit which will terminate */ /* the process and all threads before the threads have completed. */ pthread_join( thread1, NULL); pthread_join( thread2, NULL); printf("thread 1 returns: %d\n",iret1); printf("thread 2 returns: %d\n",iret2); exit(0); } void *print_message_function( void *ptr ) { char *message; message = (char *) ptr; printf("%s \n", message); } An example: Pthread cc -lpthread pthread1.c 31

Thread Pools Create a number of threads in a pool where they await work Advantages: Usually slightly faster to service a request with an existing thread than create a new thread Allows the number of threads in the application(s) to be bound to the size of the pool 32