SlideShare a Scribd company logo
Linux Scheduler
(Practical View)
1
Liran Ben Haim
liran@discoversdk.com
Rights to Copy
— Attribution – ShareAlike 2.0
— You are free
to copy, distribute, display, and perform the work
to make derivative works
to make commercial use of the work
Under the following conditions
Attribution. You must give the original author credit.
Share Alike. If you alter, transform, or build upon this work, you may
distribute the resulting work only under a license identical to this
one.
For any reuse or distribution, you must make clear to others the
license terms of this work.
Any of these conditions can be waived if you get permission from
the copyright holder.
Your fair use and other rights are in no way affected by the above.
License text: http://creativecommons.org/licenses/by-sa/2.0/legalcode
— This kit contains work by the
following authors:
— © Copyright 2004-2009
Michael Opdenacker /Free
Electrons
michael@free-electrons.com
http://www.free-electrons.com
— © Copyright 2003-2006
Oron Peled
oron@actcom.co.il
http://www.actcom.co.il/~oron
— © Copyright 2004–2008
Codefidence ltd.
info@codefidence.com
http://www.codefidence.com
— © Copyright 2009–2010
Bina ltd.
info@bna.co.il
http://www.bna.co.il
2
Processes and Threads
A process is an instance of a running program.
Multiple instances of the same program can be running.
Program code (“text section”) memory is shared.
Each process has its own data section, address space, open
files and signal handlers.
A thread is a single task in a program.
It belongs to a process and shares the common data
section, address space, open files and pending signals.
It has its own stack, pending signals and state.
It's common to refer to single threaded programs as
processes.
3
The Kernel and Threads
In 2.6 an explicit notion of processes and threads
was introduced to the kernel.
Scheduling is done on a thread by thread basis.
The basic object the kernel works with is a task,
which is analogous to a thread.
4
Thread 1 Thread
1
Thread
2
Thread
3
Thread
4
Process 123 Process 124
File
Descriptors
Memory
Signal
Handlers
File
Descriptors
Memory
Signal
Handlers
Stack
State
Signal
Mask
Stack
State
Signal
Mask
Stack
State
Signal
Mask
Stack
State
Signal
Mask
Stack
State
Signal
Mask
Priority Priority Priority Priority Priority
5
6
Linux Priorities
0
1
2
3
4
98
99
97
...
Non real-time processes
SCHED_OTHER
SCHED_BATCH
SCHED_IDLE
Real time processes
SCHED_FIFO
SCHED_RR
SCHED_DEADLINE (3.14)
19
18
17
16
-19
-20
-18
...
Nice
level
Real Time priority
7
API
— int sched_setscheduler(pid_t pid, int policy,
const struct sched_param *param);
— int setpriority(int which, id_t who, int prio);
— int sched_setparam(pid_t pid, const struct sched_param
*param);
— int sched_setattr(pid_t pid, struct sched_attr *attr, unsigned
int flags);
8
9
Blocking Threads
— A nonblocking infinite loop in a thread scheduled under the
SCHED_FIFO, SCHED_RR, or SCHED_DEADLINE policy will
block all threads with lower priority forever
— Solution: Limiting the CPU usage of real-time and deadline
processes
— /proc/sys/kernel/sched_rt_period_us
— Period that is equivalent to 100% CPU (default:
1000000)
— /proc/sys/kernel/sched_rt_runtime_us
— how much of the "period" time can be used by all real-
time and deadline scheduled processes on the system
(default: 950000)
10
Preemption
— The Linux kernel is a preemptive operating system
— When a task runs in user space mode and gets
interrupted by an interruption, if the interrupt
handler wakes up another task, this task can be
scheduled as soon as we return from the interrupt
handler
11
— However, when the interrupt comes while the task is executing
a system call, this system call has to finish before another task
can be scheduled.
— By default, the Linux kernel does not do kernel preemption.
— This means that the time before which the scheduler will be
called to schedule another task is unbounded
12
Preemption Models
13
CONFIG_PREEMPT_NONE
— Kernel code (interrupts, exceptions, system calls)
never preempted. Default behavior in standard
kernels.
— Best for systems making intense computations, on
which overall throughput is key.
— Best to reduce task switching to maximize CPU and
cache usage (by reducing context switching).
14
CONFIG_PREEMPT_VOLUNTARY
— Kernel code can preempt itself
— Typically for desktop systems, for quicker application
reaction to user input.
— Adds explicit rescheduling points throughout kernel
code.
— Minor impact on throughput.
— Used in: Ubuntu Desktop 15.04, Ubuntu Server 14.04
— Use: cond_resched()
15
CONFIG_PREEMPT
— Most kernel code can be involuntarily preempted at any
time. When a process becomes runnable, no more need
to wait for kernel code (typically a system call) to return
before running the scheduler.
— Exception: kernel critical sections (holding spinlocks). In
a case you hold a spinlock on a uni-processor system,
kernel preemption could run another process, which
would loop forever if it tried to acquire the same
spinlock.
— Typically for desktop or embedded systems with latency
requirements in the milliseconds range.
16
CONFIG_PREEMPT_RT
— The PREEMPT_RT patch adds a new level of preemption, called
CONFIG_PREEMPT_RT_FULL
— This level of preemption replaces all kernel spinlocks by mutexes (or so-called
sleeping spinlocks)
— Instead of providing mutual exclusion by disabling interrupts and preemption, they
are just normal locks: when contention happens, the process is blocked and
another one is selected by the scheduler.
— Works well with threaded interrupts, since threads can block, while usual interrupt
handlers could not.
— Some core, carefully controlled, kernel spinlocks remain as normal spinlocks.
— With CONFIG_PREEMPT_RT_FULL, virtually all kernel code becomes preemptible
— An interrupt can occur at any time, when returning from the interrupt handler, the
woken up process can start immediately.
17
Thank You
Code examples and more
http://www.discoversdk.com/blog
18

More Related Content

What's hot

Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
Adrian Huang
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
RuggedBoardGroup
 
Process Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux KernelProcess Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux Kernel
Haifeng Li
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
Shay Cohen
 
Linux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKBLinux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKB
shimosawa
 
Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0
Emertxe Information Technologies Pvt Ltd
 
Linux Programming
Linux ProgrammingLinux Programming
Linux kernel
Linux kernelLinux kernel
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
Tushar B Kute
 
Linux boot process
Linux boot processLinux boot process
Linux boot process
Archana Chandrasekharan
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
dibyajyotig
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and output
MythiliA5
 
Linux process management
Linux process managementLinux process management
Linux process managementRaghu nath
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
Saadi Rahman
 
Linux Interrupts
Linux InterruptsLinux Interrupts
Linux Interrupts
Kernel TLV
 
The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421
Linaro
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
艾鍗科技
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O
YourHelper1
 

What's hot (20)

Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
Process Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux KernelProcess Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux Kernel
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 
Linux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKBLinux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKB
 
Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0
 
Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
 
Linux boot process
Linux boot processLinux boot process
Linux boot process
 
Linux Memory
Linux MemoryLinux Memory
Linux Memory
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and output
 
Linux process management
Linux process managementLinux process management
Linux process management
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
 
Linux Interrupts
Linux InterruptsLinux Interrupts
Linux Interrupts
 
The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O
 

Viewers also liked

Programming Embedded linux
Programming Embedded linuxProgramming Embedded linux
Programming Embedded linux
Liran Ben Haim
 
Linux internals v4
Linux internals v4Linux internals v4
Linux internals v4
Liran Ben Haim
 
Scheduling In Linux
Scheduling In LinuxScheduling In Linux
Scheduling In Linux
Marcello Missiroli
 
React native
React nativeReact native
React native
Liran Ben Haim
 
Android internals
Android internalsAndroid internals
Android internals
Liran Ben Haim
 
Linux IO
Linux IOLinux IO
Linux IO
Liran Ben Haim
 
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecksKernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Anne Nicolas
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra Solutions
QUONTRASOLUTIONS
 
Jireh ict
Jireh ictJireh ict
Jireh ict
Mountain Zion
 
Operating system 11.10.2016 adarsh bang
Operating system 11.10.2016 adarsh bangOperating system 11.10.2016 adarsh bang
Operating system 11.10.2016 adarsh bang
adarshbang1998
 
Userfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy MigrationUserfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy Migration
Kernel TLV
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
Kernel TLV
 
WiFi and the Beast
WiFi and the BeastWiFi and the Beast
WiFi and the Beast
Kernel TLV
 
Docker & Badoo: 
никогда не останавливайся на достигнутом
Docker & Badoo: 
никогда не останавливайся на достигнутомDocker & Badoo: 
никогда не останавливайся на достигнутом
Docker & Badoo: 
никогда не останавливайся на достигнутом
Anton Turetsky
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
Kernel TLV
 
grsecurity and PaX
grsecurity and PaXgrsecurity and PaX
grsecurity and PaX
Kernel TLV
 
(07) instalaã§ã£o de programas
(07) instalaã§ã£o de programas(07) instalaã§ã£o de programas
(07) instalaã§ã£o de programasAnderson Lago
 
Loss Monitor
Loss MonitorLoss Monitor
Loss Monitor
Jean Pimentel
 
Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel Developers
Kernel TLV
 
Intro to cluster scheduler for Linux containers
Intro to cluster scheduler for Linux containersIntro to cluster scheduler for Linux containers
Intro to cluster scheduler for Linux containers
Kumar Gaurav
 

Viewers also liked (20)

Programming Embedded linux
Programming Embedded linuxProgramming Embedded linux
Programming Embedded linux
 
Linux internals v4
Linux internals v4Linux internals v4
Linux internals v4
 
Scheduling In Linux
Scheduling In LinuxScheduling In Linux
Scheduling In Linux
 
React native
React nativeReact native
React native
 
Android internals
Android internalsAndroid internals
Android internals
 
Linux IO
Linux IOLinux IO
Linux IO
 
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecksKernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra Solutions
 
Jireh ict
Jireh ictJireh ict
Jireh ict
 
Operating system 11.10.2016 adarsh bang
Operating system 11.10.2016 adarsh bangOperating system 11.10.2016 adarsh bang
Operating system 11.10.2016 adarsh bang
 
Userfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy MigrationUserfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy Migration
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
 
WiFi and the Beast
WiFi and the BeastWiFi and the Beast
WiFi and the Beast
 
Docker & Badoo: 
никогда не останавливайся на достигнутом
Docker & Badoo: 
никогда не останавливайся на достигнутомDocker & Badoo: 
никогда не останавливайся на достигнутом
Docker & Badoo: 
никогда не останавливайся на достигнутом
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
 
grsecurity and PaX
grsecurity and PaXgrsecurity and PaX
grsecurity and PaX
 
(07) instalaã§ã£o de programas
(07) instalaã§ã£o de programas(07) instalaã§ã£o de programas
(07) instalaã§ã£o de programas
 
Loss Monitor
Loss MonitorLoss Monitor
Loss Monitor
 
Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel Developers
 
Intro to cluster scheduler for Linux containers
Intro to cluster scheduler for Linux containersIntro to cluster scheduler for Linux containers
Intro to cluster scheduler for Linux containers
 

Similar to Linux scheduler

Interview questions
Interview questionsInterview questions
Interview questions
xavier john
 
the NML project
the NML projectthe NML project
the NML projectLei Yang
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
National Cheng Kung University
 
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Tushar B Kute
 
Linux Booting Process
Linux Booting ProcessLinux Booting Process
Linux Booting Process
Rishabh5121993
 
OffensiveCon2022: Case Studies of Fuzzing with Xen
OffensiveCon2022: Case Studies of Fuzzing with XenOffensiveCon2022: Case Studies of Fuzzing with Xen
OffensiveCon2022: Case Studies of Fuzzing with Xen
Tamas K Lengyel
 
LINUX Device Drivers
LINUX Device DriversLINUX Device Drivers
LINUX Device Drivers
Partha Bhattacharya
 
Fuzzing_with_Xen.pdf
Fuzzing_with_Xen.pdfFuzzing_with_Xen.pdf
Fuzzing_with_Xen.pdf
distortdistort
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
Priyank Kapadia
 
Tuning systemd for embedded
Tuning systemd for embeddedTuning systemd for embedded
Tuning systemd for embedded
Alison Chaiken
 
Fast boot
Fast bootFast boot
Fast boot
SZ Lin
 
cpu-affinity
cpu-affinitycpu-affinity
cpu-affinity
Magnetic Poetry
 
Linux clustering solution
Linux clustering solutionLinux clustering solution
Linux clustering solution
Chanaka Lasantha
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
Alessandro Selli
 
Lab6 rtos
Lab6 rtosLab6 rtos
Lab6 rtos
indirakumar86
 

Similar to Linux scheduler (20)

Interview questions
Interview questionsInterview questions
Interview questions
 
Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
 
the NML project
the NML projectthe NML project
the NML project
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
 
Linux Booting Process
Linux Booting ProcessLinux Booting Process
Linux Booting Process
 
Ch04
Ch04Ch04
Ch04
 
Ch04 system administration
Ch04 system administration Ch04 system administration
Ch04 system administration
 
OffensiveCon2022: Case Studies of Fuzzing with Xen
OffensiveCon2022: Case Studies of Fuzzing with XenOffensiveCon2022: Case Studies of Fuzzing with Xen
OffensiveCon2022: Case Studies of Fuzzing with Xen
 
LINUX Device Drivers
LINUX Device DriversLINUX Device Drivers
LINUX Device Drivers
 
RTDroid_Presentation
RTDroid_PresentationRTDroid_Presentation
RTDroid_Presentation
 
Fuzzing_with_Xen.pdf
Fuzzing_with_Xen.pdfFuzzing_with_Xen.pdf
Fuzzing_with_Xen.pdf
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 
Tuning systemd for embedded
Tuning systemd for embeddedTuning systemd for embedded
Tuning systemd for embedded
 
Fast boot
Fast bootFast boot
Fast boot
 
cpu-affinity
cpu-affinitycpu-affinity
cpu-affinity
 
Linux clustering solution
Linux clustering solutionLinux clustering solution
Linux clustering solution
 
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
 
Lab6 rtos
Lab6 rtosLab6 rtos
Lab6 rtos
 

Recently uploaded

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 

Recently uploaded (20)

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 

Linux scheduler

  • 1. Linux Scheduler (Practical View) 1 Liran Ben Haim liran@discoversdk.com
  • 2. Rights to Copy — Attribution – ShareAlike 2.0 — You are free to copy, distribute, display, and perform the work to make derivative works to make commercial use of the work Under the following conditions Attribution. You must give the original author credit. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. License text: http://creativecommons.org/licenses/by-sa/2.0/legalcode — This kit contains work by the following authors: — © Copyright 2004-2009 Michael Opdenacker /Free Electrons michael@free-electrons.com http://www.free-electrons.com — © Copyright 2003-2006 Oron Peled oron@actcom.co.il http://www.actcom.co.il/~oron — © Copyright 2004–2008 Codefidence ltd. info@codefidence.com http://www.codefidence.com — © Copyright 2009–2010 Bina ltd. info@bna.co.il http://www.bna.co.il 2
  • 3. Processes and Threads A process is an instance of a running program. Multiple instances of the same program can be running. Program code (“text section”) memory is shared. Each process has its own data section, address space, open files and signal handlers. A thread is a single task in a program. It belongs to a process and shares the common data section, address space, open files and pending signals. It has its own stack, pending signals and state. It's common to refer to single threaded programs as processes. 3
  • 4. The Kernel and Threads In 2.6 an explicit notion of processes and threads was introduced to the kernel. Scheduling is done on a thread by thread basis. The basic object the kernel works with is a task, which is analogous to a thread. 4
  • 5. Thread 1 Thread 1 Thread 2 Thread 3 Thread 4 Process 123 Process 124 File Descriptors Memory Signal Handlers File Descriptors Memory Signal Handlers Stack State Signal Mask Stack State Signal Mask Stack State Signal Mask Stack State Signal Mask Stack State Signal Mask Priority Priority Priority Priority Priority 5
  • 6. 6
  • 7. Linux Priorities 0 1 2 3 4 98 99 97 ... Non real-time processes SCHED_OTHER SCHED_BATCH SCHED_IDLE Real time processes SCHED_FIFO SCHED_RR SCHED_DEADLINE (3.14) 19 18 17 16 -19 -20 -18 ... Nice level Real Time priority 7
  • 8. API — int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param); — int setpriority(int which, id_t who, int prio); — int sched_setparam(pid_t pid, const struct sched_param *param); — int sched_setattr(pid_t pid, struct sched_attr *attr, unsigned int flags); 8
  • 9. 9
  • 10. Blocking Threads — A nonblocking infinite loop in a thread scheduled under the SCHED_FIFO, SCHED_RR, or SCHED_DEADLINE policy will block all threads with lower priority forever — Solution: Limiting the CPU usage of real-time and deadline processes — /proc/sys/kernel/sched_rt_period_us — Period that is equivalent to 100% CPU (default: 1000000) — /proc/sys/kernel/sched_rt_runtime_us — how much of the "period" time can be used by all real- time and deadline scheduled processes on the system (default: 950000) 10
  • 11. Preemption — The Linux kernel is a preemptive operating system — When a task runs in user space mode and gets interrupted by an interruption, if the interrupt handler wakes up another task, this task can be scheduled as soon as we return from the interrupt handler 11
  • 12. — However, when the interrupt comes while the task is executing a system call, this system call has to finish before another task can be scheduled. — By default, the Linux kernel does not do kernel preemption. — This means that the time before which the scheduler will be called to schedule another task is unbounded 12
  • 14. CONFIG_PREEMPT_NONE — Kernel code (interrupts, exceptions, system calls) never preempted. Default behavior in standard kernels. — Best for systems making intense computations, on which overall throughput is key. — Best to reduce task switching to maximize CPU and cache usage (by reducing context switching). 14
  • 15. CONFIG_PREEMPT_VOLUNTARY — Kernel code can preempt itself — Typically for desktop systems, for quicker application reaction to user input. — Adds explicit rescheduling points throughout kernel code. — Minor impact on throughput. — Used in: Ubuntu Desktop 15.04, Ubuntu Server 14.04 — Use: cond_resched() 15
  • 16. CONFIG_PREEMPT — Most kernel code can be involuntarily preempted at any time. When a process becomes runnable, no more need to wait for kernel code (typically a system call) to return before running the scheduler. — Exception: kernel critical sections (holding spinlocks). In a case you hold a spinlock on a uni-processor system, kernel preemption could run another process, which would loop forever if it tried to acquire the same spinlock. — Typically for desktop or embedded systems with latency requirements in the milliseconds range. 16
  • 17. CONFIG_PREEMPT_RT — The PREEMPT_RT patch adds a new level of preemption, called CONFIG_PREEMPT_RT_FULL — This level of preemption replaces all kernel spinlocks by mutexes (or so-called sleeping spinlocks) — Instead of providing mutual exclusion by disabling interrupts and preemption, they are just normal locks: when contention happens, the process is blocked and another one is selected by the scheduler. — Works well with threaded interrupts, since threads can block, while usual interrupt handlers could not. — Some core, carefully controlled, kernel spinlocks remain as normal spinlocks. — With CONFIG_PREEMPT_RT_FULL, virtually all kernel code becomes preemptible — An interrupt can occur at any time, when returning from the interrupt handler, the woken up process can start immediately. 17
  • 18. Thank You Code examples and more http://www.discoversdk.com/blog 18