Linux kernel: Processes, threads and scheduling

Slides:



Advertisements
Similar presentations
Linux Scheduler. Linux is a multitasking OS Deciding what process runs next, given a set of runnable processes, is a fundamental decision a scheduler.
Advertisements

Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
CS591 (Spring 2001) The Linux Kernel: Process Management.
Processes CSCI 444/544 Operating Systems Fall 2008.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
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.
CSSE Operating Systems
Linux Review COMS W4118 Spring Linux Overview History Distributions Licensing Components Kernel, daemons, libraries, utilities, etc Modules Build.
Process Description and Control A process is sometimes called a task, it is a program in execution.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Threads, Thread management & Resource Management.
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.
Seminar on Linux Process Management Presentation by Manoj Dhage MTech 1 st Year, SIT, IIT Kharagpur.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
CPU Scheduling Presentation by Colin McCarthy. Runqueues Foundation of Linux scheduler algorithm Keeps track of all runnable tasks assigned to CPU One.
Linux Processes. Process Descriptor Process – dynamic, program in motion –Kernel data structures to maintain "state" –Descriptor, PCB (control block),
4P13 Week 3 Talking Points 1. Process State 2 Process Structure Catagories – Process identification: the PID and the parent PID – Signal state: signals.
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.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Processes.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
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, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Threads, Thread management & Resource Management.
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
Linux Process Management. Linux Implementation of Threads Threads enable concurrent programming / true parallelism Linux implementation of threads.
Chapter 4: Threads 羅習五. Chapter 4: Threads Motivation and Overview Multithreading Models Threading Issues Examples – Pthreads – Windows XP Threads – Linux.
Operating System Examples - Scheduling. References r er/ch10.html r bangalore.org/blug/meetings/200401/scheduler-
Processes David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 5 Threads.
CS703 – Advanced Operating Systems By Mr. Farhan Zaidi.
Chapter 4 – Thread Concepts
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
OPERATING SYSTEM CONCEPT AND PRACTISE
Process Management Process Concept Why only the global variables?
Chapter 4 – Thread Concepts
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 3: Processes.
Chapter 4: Threads 羅習五.
Processes David Ferry, Chris Gill
Processes in Unix, Linux, and Windows
Chapter 4: Threads.
Threads & multithreading
System Structure and Process Model
System Structure and Process Model
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Threads.
Chapter 4: Threads.
System Structure B. Ramamurthy.
Processes in Unix, Linux, and Windows
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
System Structure and Process Model
Process & its States Lecture 5.
Chapter 2: The Linux System Part 3
Chapter 5: Threads Overview Multithreading Models Threading Issues
Processes in Unix and Windows
Chapter 4: Threads.
Chapter 4: Threads.
Linux Scheduling CSE 2431: Introduction to Operating Systems
Presentation transcript:

Linux kernel: Processes, threads and scheduling Process management: Linux calls its PCB as struct task_struct (<kernel source>/include/linux/sched.h) Large structure, about 1.7 KB on a 32 bit machine Each task’s thread_info structure it allocated at the end of its kernel stack, its points to the task_struct Process IDs are 0-32767 (like most UNIX). Only possible to have 32768 concurrent tasks Processes can be in TASK_RUNNING, TASK_INTERRUPTIBLE, TASK_UNINTERRUPTIBLE, TASK_ZOMBIE and TASK_STOPPED state.

Process creation Fork(), vfork() or thread() Linux threads are basically tasks which share data Fork optimizations: Copy-on-write (COW): Child data not cloned till modified Schedule child first in order to prevent parent from tripping over COW. More on COW later in memory management Vfork: optimized fork where child is not allowed to modify any data All implemented using clone() Kernel threads are created by other kernel threads and run in kernel-space (does not context switch to user space at all)

Process creation Processes are created using clone() system call. CLONE_FILES Parent and child share open files. CLONE_FS Parent and child share filesystem information. CLONE_IDLETASK Set PID to zero (used only by the idle tasks) CLONE_NEWNS Create a new namespace for the child CLONE_PARENT Child is to have same parent as its parent CLONE_PTRACE Continue tracing child CLONE_SETTID Write the TID back to user-space CLONE_SETTLS Create a new TLS for the child CLONE_SIGHAND Parent and child share signal handlers and blocked signals CLONE_SYSVSEM Parent and child share System V SEM_UNDO semantics CLONE_THREAD Parent and child are in the same thread group CLONE_VFORK vfork was used and the parent will sleep until the child wakes it CLONE_UNTRACED Do not let the tracing process force CLONE_PTRACE on the child CLONE_STOP Start process in the TASK_STOPPED state CLONE_SETTLS Create a new TLS (thread-local storage) for the child CLONE_CHILD_CLEARTID Clear the TID in the child CLONE_CHILD_SETTID Set the TID in the child CLONE_PARENT_SETTID Set the TID in the parent CLONE_VM Parent and child share address space.

Process scheduling Process priority POSIX define nice values of -20 to +19. Larger value means lower priority Real time priorities are in the range 0 to 99. Higher than for normal processes Time slice: allocated to each process based on its niceness. Minimum is the time slice. Maximum is 800 ms. Once time slice runs out, moved to exhausted queue. After all processes exhaust their time slice, everyone gets new time slice. Instead of waiting to reassign time slices, assign time slice before moving task to exhausted list Rotate pointers to move between exhausted and active O(1) operation

Scheduling O(1) scheduling - scheduling duration takes constant time and does not depend on the number of tasks running (compare with O(n), O(n2) Priority arrays - a bit mapped structure

Scheduling Full SMP. Each processor runs its own queue except to load balance. Idle processors may take processes from other processors (take the exhausted pool in order to avoid affinity issues with cache) Improved SMP affinity Good interactive performance and fair: Kernel keeps track of CPU use and the rate of usage How much time a process spent sleeping vs how much time the process spends in a runnable state Takes care of processes which sleep for a while and then hog CPU Interactive jobs are put in active list even if they exhaust their time slice Kernel is fully pre-emptible

Real-time Supports SCHED_FIFO and SCHED_RR. Normal processes, SCHED_NORMAL always yield to SCHED_FIFO and SCHED_RR. Linux implements soft realtime Performance is quite good