MP2: Rate-Monotonic CPU Scheduling

Slides:



Advertisements
Similar presentations
Operating Systems Process Scheduling (Ch 3.2, )
Advertisements

Abdulrahman Idlbi COE, KFUPM Jan. 17, Past Schedulers: 1.2 & : circular queue with round-robin policy. Simple and minimal. Not focused on.
Chapter 5 Processes and Threads Copyright © 2008.
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
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.
Scheduling in Linux COMS W4118 Spring Scheduling Goals O(1) scheduling; 2.4 scheduler iterated through Run queue on each invocation Task queue.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Phones OFF Please Processes Parminder Singh Kang Home:
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.
Process Description and Control
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Scheduling in Linux and Windows 2000
Linux Scheduling CS Scheduling Policy ► The scheduling algorithm of traditional Unix systems must fulfill several conflicting objectives  Fast.
Implementing Processes and Process Management Brian Bershad.
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 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.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Thread Scheduling.
Scheduling Example 3 (1) Assume: FIFO Job Scheduling 100 K Main Memory Processor Sharing Process Scheduling (Cont…)
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1.
Lec 3aOperating Systems1 Operating Systems Lecture 3a: Linux Schedulers William M. Mongan Material drawn in part from
1 Chapter 4 Processes R. C. Chang. 2 Linux Processes n Each process is represented by a task_struct data structure (task and process are terms that Linux.
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.
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.
Processes and Process Control Anand Sivasubramaniam Dept. of Computer Science & Eng. Pennsylvania State University.
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.
MP2: RATE-MONOTONIC CPU SCHEDULING Based on slides by Gourav Khaneja, Raoul Rivas and Keun Yim University of Illinois at Urbana-Champaign Department of.
CSC 660: Advanced Operating Systems
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Types of shedulars Process.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Process Scheduling 國立中正大學 資訊工程研究所 羅習五 老師 1. Outline OS schedulers Unix scheduling Linux scheduling Linux 2.4 scheduler Linux 2.6 scheduler – O(1) scheduler.
Process Tables; Threads
Process Management Process Concept Why only the global variables?
Protection of System Resources
Lecture Topics: 11/1 Processes Process Management
Processes David Ferry, Chris Gill
Intro to Processes CSSE 332 Operating Systems
Semester Review Chris Gill CSE 422S - Operating Systems Organization
Linux Process (Task) Structure and Scheduling Overview
Structure of Processes
Linux kernel: Processes, threads and scheduling
Processes in Unix, Linux, and Windows
Process Tables; Threads
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Lecture Topics: 11/1 General Operating System Concepts Processes
Midterm Review Brian Kocoloski
Chapter 3: Processes.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Linux Scheduling CSE 2431: Introduction to Operating Systems
Presentation transcript:

MP2: Rate-Monotonic CPU Scheduling University of Illinois at Urbana-Champaign Department of Computer Science CS423 Raoul Rivas Revised and Presented by Keun Soo Yim

Extending Linux kernel to support RM scheduler Goal Extending Linux kernel to support RM scheduler 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

Overview Implements a real-time scheduler in a kernel module Uses the Proc file system as an interface instead of system calls Periodic task model Register a task (or process) Execute real-time Loop  Rate-Monotonic sched. De-registration Simplicity by separation of policy and mechanism Reuses the Linux kernel API for low-level operations Linux Scheduler Scheduler Operations Proc Filesystem Periodic App. Proc FS Write RMS Kernel Module Proc FS Read List of Processes User Space Kernel Space CS423 MP2

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

Thread (High RT Priority) Design Processing Time Preemption Point? Deadline of Job 1 1. Register Process (or Task) Job completion 4. Yield … 2. Check 5. Deregister 3. Job Arrival Period Where are the preemption points? How the scheduling policy and mechanism are separated? No Process is RUNNING but there is a process READY to be scheduled No Process is READY but there is a RUNNING process to be preempted There is a process RUNNING to be preempted and there is a process READY to be scheduled User-Level Periodic Process 1. Register Process Proc FS Write Op. RM Admission Controller 2. List of RM Processes Proc FS Read Op. Linked List for RM Tasks 4. Yield Yield Func. Handler Dispatching Thread (High RT Priority) wakeup() 5. Deregister Linux Scheduler Timer User Space Kernel Space CS423 MP2

Scheduling Points 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? Timer 1/HZ tick_periodic add_timer(1 jiffy) jiffies++ scheduler_tick() schedule() Process Context Kernel Context yield() CS423 MP2

Two Halves / Deferring Work 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) TOP HALF Timer Interrupt context Timer Handler: wake_up(thread); Kernel context Thread: While(1) { Do work(); Schedule(); } BOTTOM HALF CS423 MP2

Linux Kernel Scheduler Process Priority-based time-sharing scheduler Defines a function f(P) for a process P to calculate an effective priority R The highest effective priority process is always scheduled. Fairness is realized since the effective priorities change over time depending on dynamic process state information. Such process-specific dynamic information is stored in the Process Control Block (PCB) (Sched. Parameters, Process State Info.) f Goodness value Scheduler CS423 MP2

Process Control Block 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 task_struct task_struct Current task_struct task_struct CS423 MP2

Process Control Block mm: the memory descriptor 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 task_struct priority rt_priority counter policy state need_ resched CS423 MP2

Priority Level Process P1 P2 SCHED FIFO NORMAL f rt_priority (99, 0) Goodness value Scheduler SCHED FIFO P2 NORMAL Prio 1 Prio 140 Context Switch Pick Process 1 rt_priority (99, 0) Nice (-20, +19) CS423 MP2

Goodness Pseudo code: p: process to evaluate, prev: previous process if (p->policy != SCHED_OTHER) return 1000 + p->rt_priority; if (p->counter == 0) return 0; if (p->mm == prev->mm) return p->counter + p->priority + 1; return p->counter + p->priority; CS423 MP2

O(1) Scheduler v2.6 – before v2.6.23 Problem Scalability (e.g., Java) A task used all of its time slice is moved to the expired RQ. During the move, the time slice and priority are updated. If no tasks exist on the active RQ for a given priority, the pointers are swapped. v2.6 – before v2.6.23 http://www.ibm.com/developerworks/linux/library/l-scheduler/ CS423 MP2

Bitmap 31 … … … … … … … … … … … … … … … … 63 … … … … … … … … … … … … … … .. … 32 95 … … … … … … … … … … … … … … .. … 64 127 … … … … … … … … … … … … … … .. … 96 159 … … … … … … … … … … … … … … .. … 128 int sched_find_first_bit(unsigned long *b){ if (b[0]) return __ffs(b[0]); if (b[1]) return __ffs(b[1]) + 32; if (b[2]) return __ffs(b[2]) + 64; return __ffs(b[3]) + 96; } __ffs(): bit scan forward instruction returns the index of the least significant set bit in x86. CS423 MP2

CFS – Completely Fair Sched. CFS from kernel v2.6.23 for normal process (not real-time process) to improve fairness. Maintains virtual runtime (amount of time given to a task) and supports sleeper fairness to ensure that tasks not currently runnable (e.g., due to I/O) receive a comparable share later when it is needed A time-ordered red-black tree is used as a RQ data structure, which is self-balancing (longest path <= 2 x shortest path) and has O(log n) operation time. CS423 MP2

Scheduler API schedule(): triggers rescheduling Runs after changing the state of any process wake_up_process(): wakes a process 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

Implementation Proc file system (FS) Linked list Critical section by mutex Kernel thread Timer Caution: Source code provided in this slide give examples of how such mechanisms are implemented and thus are simplified and incomplete, while the MP1 solution and reference materials provide the complete implementation. CS423 MP2

PROC FS [MP1 CODE] static struct proc_dir_entry *mp1_proc_dir; int __init my_module_init(void) { mp1_proc_dir=proc_mkdir("mp1",NULL); register_task_file=create_proc_entry("status", 0666, mp1_proc_dir); register_task_file->read_proc = proc_registration_read; register_task_file->write_proc = proc_registration_write; … } void __exit my_module_exit(void){ remove_proc_entry("status", mp1_proc_dir); remove_proc_entry("mp1", NULL); CS423 MP2

PROC FS [MP1 CODE] int proc_registration_write(struct file *file, const char *buffer, unsigned long count, void *data){ char *proc_buffer; unsigned int pid; proc_buffer=kmalloc(count, GFP_KERNEL); copy_from_user(proc_buffer, buffer, count); … kfree(proc_buffer); return count; } CS423 MP2

PROC FS [MP1 CODE] int proc_registration_read(char *page, char **start, off_t off, int count, int* eof, void* data){ off_t i; struct list_head *pos; i=0; if (off == 0) { memcpy(page, “hello world”, 11); i = 11; *eof=1; } return i; CS423 MP2

LINKED LIST [MP1 CODE] LIST_HEAD(mp1_task_list); static DEFINE_MUTEX(mp1_mutex); mutex_lock(&mp1_mutex); list_add_tail(&t->task_node, &mp1_task_list); mutex_unlock(&mp1_mutex); CS423 MP2

LINKED LIST [MP1 CODE] struct list_head *pos; mutex_lock(&mp1_mutex); list_for_each(pos, &mp1_task_list) { p = list_entry(pos, struct mp1_task_stats, task_node); /* use of p->pid and p->cpu_use */ } mutex_unlock(&mp1_mutex); CS423 MP2

KERNEL THREAD [MP1 CODE] struct task_struct* update_kthread; int __init my_module_init(void){ update_kthread=kthread_create(scheduled_update, NULL,"kmp1"); } void __exit my_module_exit(void){ kthread_stop(update_kthread); CS423 MP2

KERNEL THREAD [MP1 CODE] int scheduled_update(void *data){ while(1) { if (stop_thread==1) break; … set_current_state(TASK_INTERRUPTIBLE); schedule(); set_current_state(TASK_RUNNING); } return 0; wake_up_process(update_kthread); CS423 MP2

TIMER [MP1 CODE] inline void timer_init(struct timer_list *timer, void (*function)(unsigned long)){ init_timer(timer); timer->function=function; timer->data=(unsigned long) timer; } int __init my_module_init(void){ timer_init(&up_timer, up_handler); void __exit my_module_exit(void){ del_timer_sync(&up_timer); CS423 MP2

TIMER [MP1 CODE] void up_handler(unsigned long ptr){ wake_up_process(update_kthread); } int scheduled_update(void *data){ while(1) { … set_timer(&up_timer,UPDATE_TIME); CS423 MP2

Conclusion 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