MP2: RATE-MONOTONIC CPU SCHEDULING Based on slides by Gourav Khaneja, Raoul Rivas and Keun Yim University of Illinois at Urbana-Champaign Department of.

Slides:



Advertisements
Similar presentations
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
Advertisements

CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Chapter 5 Processes and Threads Copyright © 2008.
Processes CSCI 444/544 Operating Systems Fall 2008.
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Process Concept An operating system executes a variety of programs
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Scheduler Activations Jeff Chase. Threads in a Process Threads are useful at user-level – Parallelism, hide I/O latency, interactivity Option A (early.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
COP 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park.
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
PROCESSES TANNENBAUM, SECTION 2-1 OPERATING SYSTEMS.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
The Structure of Processes. What is a Process? an instance of running program Program vs process(task) Program : just a passive collection of instructions.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Processes & Threads Bahareh Goodarzi. Single & Multiple Thread of control code files data code files data.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Assistant Professor, University of Maryland Baltimore County.
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
REVIEW OF COMMONLY USED DATA STRUCTURES IN OS. NEEDS FOR EFFICIENT DATA STRUCTURE Storage complexity & Computation complexity matter Consider the problem.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Lec 3aOperating Systems1 Operating Systems Lecture 3a: Linux Schedulers William M. Mongan Material drawn in part from
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Scheduling II: priority scheduling.
CSE 451: Operating Systems Winter 2015 Module 5 1 / 2 User-Level Threads & Scheduler Activations Mark Zbikowski 476 Allen Center.
CS140 Project 1: Threads Slides by Kiyoshi Shikuma.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
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.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Periodic scheduler for Linux OS
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
CSC 660: Advanced Operating Systems
CS Spring 2009 CS 414 – Multimedia Systems Design Lecture 31 – Process Management (Part 1) Klara Nahrstedt Spring 2009.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
MP2: Rate-Monotonic CPU Scheduling
1.  System Characteristics  Features of Real-Time Systems  Implementing Real-Time Operating Systems  Real-Time CPU Scheduling  An Example: VxWorks5.x.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Timers and Time Management Ok-Kyun Ha
REAL-TIME OPERATING SYSTEMS
Process Management Process Concept Why only the global variables?
OPERATING SYSTEMS CS3502 Fall 2017
Midterm Review David Ferry, Chris Gill
Intro to Processes CSSE 332 Operating Systems
Threads & multithreading
Linux Process (Task) Structure and Scheduling Overview
Linux kernel: Processes, threads and scheduling
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Mid Term review CSC345.
Scheduling.
Lecture Topics: 11/1 General Operating System Concepts Processes
CSE 451 Autumn 2003 Section 3 October 16.
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy Amrita-UB-MSES /11/2013.
Midterm Review Brian Kocoloski
Chapter 3: Processes.
Linux Process State Scheduling information Identifiers
Real-Time Process Scheduling Concepts, Design and Implementations
Real-Time Process Scheduling Concepts, Design and Implementations
Linux Scheduling CSE 2431: Introduction to Operating Systems
Presentation transcript:

MP2: RATE-MONOTONIC CPU SCHEDULING Based on slides by Gourav Khaneja, Raoul Rivas and Keun Yim University of Illinois at Urbana-Champaign Department of Computer Science CS423

G OAL  Understand real-time scheduling concepts  Design a real-time scheduler (i.e., RM) and its admission controller in OS  Implement the RM scheduler and admission controller as a Linux kernel module  Learn how to use the kernel-lv. API of the Linux scheduler, timer, and proc file system  Test the kernel-level real-time scheduler by implementing a user-level periodic task CS423 MP2 2 Extending Linux kernel to support RM scheduler

R ATE M ONOTONIC S CHEDULER  Periodic tasks to be completed before next period starts.  Medical systems such as pace maker, airline navigation system CS423 MP2 3

/P ROC  Uses the Proc file system as an interface instead of system calls  Process Registers: provide pid, period, processing time Yield: Finished Processing. Sleep until the next period De-register CS423 MP2 4

C ONTEXT S WITCH  Use Linux Scheduler for context switches through scheduling API and policies. CS423 MP2 5 Linux Scheduler User Space Proc FS Read Proc FS Write RMS Kernel Module Kernel Space Periodic App.

D ESIGN CS423 MP2 6 Process (or Task) Period Processing Time Deadline of Job 1 3. Job Arrival Job completion 4. Yield Kernel Space Proc FS Read Op. Proc FS Write Op. 2. List of RM Processes 1. Register Process Linked List for RM Tasks Dispatching Thread (High RT Priority) Timer RM Admission Controller Yield Func. Handler Linux Scheduler User- Level Periodic Process 4. Yield 5. Deregister 1. Register 2. Check wakeup() User Space … 5. Deregister

P ROCESS C ONTROL B LOCK  PCB is defined by the task_struct structure  PCBs are managed by a circular doubly linked list  task_struct *current points to PCB of the currently running process.  PCB contains the process state: Running or ready: TASK_RUNNING Waiting: TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE Other: TASK_TRACED, TASK_STOPPED CS423 MP2 7 task_struct Current

task_struct P ROCESS C ONTROL B LOCK  Additionally PCB contains: priority: the static priority rt_priority: the real-time priority counter: the number of clock ticks left in the scheduling budget of the process policy: the scheduling policy ○ SCHED_NORMAL: Normal ○ SCHED_FIFO or SCHED_RR mm: the memory descriptor CS423 MP2 8 priority rt_priority counter policy state need_ resched

M P 2_ TASK _ STRUCT  struct task_struct * task  Int period  Int processing_time  Int task_state  timer_list timer  … CS423 MP2 9

S CHEDULING P OINTS  schedule() is the entry point of the scheduler and invoked by: scheduler_tick() if a reschedule is marked. (task_struct→needs_resched) yield() is called by an application in user space schedule() in kernel or process context in kernel space  Can schedule() be called inside interrupt handler? CS423 MP2 10 schedule() Timer 1/HZ add_timer(1 jiffy) jiffies++ scheduler_tick() tick_periodic Kernel Contextyield() Process Context

T WO H ALVES / D EFERRING W ORK  Kernel timers are used to create timed events  They use jiffies to measure the system time  Timers are interrupts We can't sleep or hog CPU in them!  Solution: Divide the work into two parts Uses the timer handler to signal a thread. (TOP HALF) Let the kernel thread do the real job. (BOTTOM HALF) CS423 MP2 11 Timer Timer Handler: wake_up(thread); Thread: While(1) { Do work(); Schedule(); } Interrupt context Kernel context TOP HALF BOTTOM HALF

S CHEDULER API  schedule(): triggers rescheduling Runs after changing the state of any process  wake_up_process(struct task_struct *): This can be called in the interrupt context.  sched_setscheduler(): sets sched. parameters e.g., priority & scheduling policy  set_current_state(): changes the state used to put the running context to sleep.  set_task_state(): changes the state of another CS423 MP2 12

I MPLEMENTATION CS423 MP2 13 Select the “ready” process with shortest period. State = running Wake up process sleep State = ready Wake up scheduler Update timer State = sleep Wake up scheduler sleep Yield function handler Scheduler Timer interrupt

S CHEDULING H ACK  Use Linux Scheduling policies CS423 MP2 14 struct sched_param sparam; wake_up_process(task): sparam.sched_priority=MAX_USER_RT_PRIO-1; sched_setscheduler(task, SCHED_FIFO, &sparam);

LOCKS  Spinlocks inside timer interrupts  spin_lock_irqsave(spinlock_t *, unsigned ) Disable interrupts: can safely implement spinlocks on single core machines  spin_unlock_irqrestore(spinlock_t *, unsigned int)  Mutex for linked list CS423 MP2 15

M EMORY CACHE  Improves memory management by reducing fragmentation  For frequent allocation/de-allocation of given objects  Kmem_cache_create  Kmem_cache_alloc  Kmem_cache_free  Kmem_cache_destroy CS423 MP2 16

A DMISSION C ONTROL CS423 MP2 17

T EST APPLICATION void main (void) { REGISTER(PID, Period, ProcessTime); //Proc filesystem list=READ STATUS(); //Proc filesystem: Verify the process was admitted if (!process in the list) exit 1; //setup everything needed for real-time loop: t0=gettimeofday() for test.c YIELD(PID); //Proc filesystem //this is the real-time loop while(exist jobs) { do_job(); //wakeup_time=t0-gettimeofday() and factorial computation YIELD(PID); //Proc filesystem } UNREGISTER(PID); //Proc filesystem } CS423 MP2 18

T ESTS  Calculate the factorial of a fixed number  Estimate approx. processing time  Test with multiple applications  Verify Pre-emption CS423 MP2 19

C ONCLUSION  Linux uses Priority based Scheduling  Priorities are adjusted based on the state of the process and its scheduling policy  The PCB (task_struct) contains the information about the state of a process  Rescheduling in Linux follows the Two-Halves approach. Reschedule can occur in process context or kernel context only.  We can use the Scheduler API to build our own policy on top of the Linux scheduler.  Our RMS scheduler will have a scheduler thread and will be invoked after a Job Release and after a Job Completion CS423 MP2 20