CPU/Process Management : Objectives & Challenges. Data Structures for CPU Management

Similar documents
CHAPTER 2: PROCESS MANAGEMENT

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

Lecture 2 Process Management

Chapter 3: Processes. Operating System Concepts 8th Edition,

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

Processes and Threads

CPU Scheduling: Part I ( 5, SGG) Operating Systems. Autumn CS4023

So far. Next: scheduling next process from Wait to Run. 1/31/08 CSE 30341: Operating Systems Principles

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

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

Processes. Sanzheng Qiao. December, Department of Computing and Software

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Operating Systems CMPSC 473. Process Management January 29, Lecture 4 Instructor: Trent Jaeger

Announcements Processes: Part II. Operating Systems. Autumn CS4023

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

CS370 Operating Systems

TDIU25: Operating Systems II. Processes, Threads and Scheduling

Processes. Process Concept

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

Operating Systems. Lecture 05

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

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

Operating Systems & Concurrency: Process Concepts

CS370 Operating Systems

Chapter 3: Processes

Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

OPERATING SYSTEMS: Lesson 4: Process Scheduling

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Part Two - Process Management. Chapter 3: Processes

CSCE 313: Intro to Computer Systems

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

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

Chapter 3: Processes. Operating System Concepts 8 th Edition,

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

Chap 4, 5: Process. Dongkun Shin, SKKU

Class average is Undergraduates are performing better. Working with low-level microcontroller timers

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

Processes-Process Concept:

Chapter 3: Process Concept

Chapter 3: Process Concept

LECTURE 3:CPU SCHEDULING

Chapter 3: Process Concept

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

Frequently asked questions from the previous class survey

Processes and Threads

Chapter 5: CPU Scheduling

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

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

Chapter 5: CPU Scheduling

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

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

CS370 Operating Systems

csci3411: Operating Systems

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

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

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

Chapter 6: CPU Scheduling

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Chapter 5 CPU scheduling

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

Chapter 4: Processes. Process Concept

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

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Chapter 4: Processes

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Course Syllabus. Operating Systems

Processes. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & Apps 1

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

Chapter 3: Processes. Operating System Concepts 8th Edition

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

CS307: Operating Systems

Lecture 3: Processes. CMPUT 379, Section A1, Winter 2014 January 13, 15 and 17

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

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

CPU scheduling. Alternating sequence of CPU and I/O bursts. P a g e 31

Processes. Dr. Yingwu Zhu

COSC243 Part 2: Operating Systems

Chapter 3: Processes

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

Computer Systems II. First Two Major Computer System Evolution Steps

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

Chapter 3: Process Concept

Chapter 6: CPU Scheduling

Killing Zombies, Working, Sleeping, and Spawning Children

Processes. Operating System Concepts with Java. 4.1 Sana a University, Dr aimen

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

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

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

2. PROCESS. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

CS3733: Operating Systems

UNIT - II PROCESS MANAGEMENT

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

Transcription:

CPU/Process Management : Objectives & Challenges Scheduling Determine the order in which processes get to use the CPU Prevent starvation, ensure fairness, be efficient Allow processes to communicate efficiently and securely Synchronization When things need to be done in a certain order Prevent deadlocks A situation where no-one can make progress More later Data Structures for CPU Management Already seen: PCBs, one per process Several linked lists List of ready (runnable) processes List of waiting (blocked) processes Often multiple lists, one per event List of running processes?? Que: Why linked lists? Why not better data structures? 1

Re-entrant Kernels Kernel control path Multiple kernel control paths may be active simultaneously Reason: Efficiency How to achieve this? Interleaved Interrupt Handling User User User USER MODE Excp Intr Intr Intr KERNEL MODE Time 2

Data Structures for CPU Management (contd.) Kernel-level stacks for processes Linked List Example from Linux struct list_head { ; struct list_head *next, *prev; struct runqueue { [.] struct list_head migration_queue; ; [.] next prev runqueue next prev 3

Linked List in Linux (2.4 onwards) A linked list (what we normally encounter) A linked list in Linux Why? Process Operations: Process Creation Parent process create children processes, which, in turn create other processes, forming a tree of processes Resource sharing Parent and children share all resources Children share subset of parent s resources Parent and child share no resources Execution Parent and children execute concurrently Parent waits until children terminate 4

Process Creation (contd.) Address space Child duplicate of parent Child has a program loaded into it UNIX examples fork system call creates new process exec system call used after a fork to replace the process memory space with a new program Process Creation (contd.) 5

C Program Forking Separate Process int main( ) { pid_t pid; /* fork another process */ pid = fork( ); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit(-1); else if (pid == 0) { /* child process */ execlp("/bin/ls", "ls", NULL); else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit(0); A tree of processes on a typical Solaris 6

Process Operations: Process Termination Process executes last statement and asks the operating system to delete it (exit) Output data from child to parent (via wait) Process resources are deallocated by operating system Parent may terminate execution of children processes (abort) Child has exceeded allocated resources Task assigned to child is no longer required If parent is exiting Some operating system do not allow child to continue if its parent terminates All children terminated - cascading termination CPU Scheduling 7

CPU Scheduling OS implements a CPU scheduling algorithm that decides which process to run when (plus itself!) Needs to be online Set of processes changes dynamically Needs to be fast, efficient May need to implement specified policies E.g., Run certain processes at a higher priority Timers CPU is a temporal resource Other temporal resources? Non-temporal? OS needs to be aware of the passage of time Several clocks might be present E.g., Intel: Real time clock, Time Stamp Counter, Programmable Interval Timer RTC: Battery operated TSC: All Intel CPUs have a CLK input pin, which receives the clock signal of an external oscillator 64-bit TSC register, can be read using the rdtsc assembly instruction Incremented at each clock signal E.g., 400 MHz clock => TSC incremented every 2.5 nanosec PIT: Like an alarm, the OS sets the frequency at which it interrupts Linux programs PIT to send interrupt on IRQ0 every tick time units Linux/Intel: ~10 msec, Linux/Alpha: ~1 msec jiffies: a variable in Linux that stores # ticks since startup 8

Choosing the Right Scheduling Algorithm/Scheduling Criteria CPU utilization keep the CPU as busy as possible Throughput # of processes that complete their execution per time unit Turnaround time amount of time to execute a particular process Waiting time amount of time a process has been waiting in the ready queue Response time amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) Fairness When is the scheduler invoked? 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 Scheduling only under 1 and 4: nonpreemptive scheduling All other scheduling is preemptive 9

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 Example from Linux 2.6.x asmlinkage void sched schedule(void) { [... ] prepare_arch_switch(rq, next); prev = context_switch(rq, prev, next); barrier(); finish_task_switch(prev); [... ] task_t * context_switch(runqueue_t *rq, task_t *prev, task_t *next) { struct mm_struct *mm = next->mm; struct mm_struct *oldmm = prev->active_mm; /* Here we just switch the register state and the stack. */ switch_to(prev, next, prev); return prev; #define switch_to(prev,next,last) \ asm volatile(save_context \ "movq %%rsp,%p[threadrsp](%[prev])\n\t" /* saversp */ \ "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */ \ "call switch_to\n\t" \ ".globl thread_return\n" \ "thread_return:\n\t" \ "movq %%gs:%p[pda_pcurrent],%%rsi\n\t" \ "movq %P[thread_info](%%rsi),%%r8\n\t" \ LOCK "btr %[tif_fork],%p[ti_flags](%%r8)\n\t" \ "movq %%rax,%%rdi\n\t" \ "jc ret_from_fork\n\t" \ RESTORE_CONTEXT \ : "=a" (last) \ : [next] "S" (next), [prev] "D" (prev), \ [threadrsp] "i" (offsetof(struct task_struct, thread.rsp)), \ [ti_flags] "i" (offsetof(struct thread_info, flags)),\ [tif_fork] "i" (TIF_FORK), \ [thread_info] "i" (offsetof(struct task_struct, thread_info)), \ [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \ : "memory", "cc" EXTRA_CLOBBER) 10

First-Come, First-Served Scheduling (FCFS) Process Burst Time P 1 24 P 2 3 P 3 3 Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule is: P 1 P 2 P 3 0 24 27 30 Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P 2, P 3, P 1 The Gantt chart for the schedule is: P 2 P 3 P 1 0 3 6 30 Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case Convoy effect short process behind long process 11