SlideShare a Scribd company logo
1
Scheduling in
Android
AnDevCon Washington D.C. 2017
Karim Yaghmour
@karimyaghmour
karim.yaghmour@opersys.com
2
These slides are made available to you under a Creative Commons Share-
Alike 3.0 license. The full terms of this license are here:
https://creativecommons.org/licenses/by-sa/3.0/
Attribution requirements and misc., PLEASE READ:
● This slide must remain as-is in this specific location (slide #2), everything
else you are free to change; including the logo :-)
● Use of figures in other documents must feature the below “Originals at”
URL immediately under that figure and the below copyright notice where
appropriate.
● You are free to fill in the “Delivered and/or customized by” space on the
right as you see fit.
● You are FORBIDEN from using the default “About” slide as-is or any of its
contents.
● You are FORBIDEN from using any content provided by 3rd parties without
the EXPLICIT consent from those parties.
(C) Copyright 2016-2017, Opersys inc.
These slides created by: Karim Yaghmour
Originals at: www.opersys.com/community/docs
Delivered and/or customized by
3
About
● Author of:
● Introduced Linux Trace Toolkit in 1999
● Originated Adeos and relayfs (kernel/relay.c)
● Training, Custom Dev, Consulting, ...
4
Agenda
1. Architecture
2. Linux scheduler history
3. Completely Fair Scheduler (CFS)
4. Sched Classes
5. CPU power management
6. Load tracking
7. Android problems w/ Linux scheduler
8. User-space vs. Linux scheduler
9. Framework
10. Summing up
5
1. Architecture
● Hardware on which Android is based
● Android stack
● Startup
● System services
● Binder driver
6
7
8
9
10
11
12
2. Linux scheduler history
● 1995 - Linux 1.2
● Circular queue of tasks w/ round-robin
● 1999 - Linux 2.2
● Scheduling classes: real-time, non-preemptable and non-real-time
● SMP support
● 2001 - Linux 2.4 O(N) scheduler
● Each task gets a slice (epoch)
● 2003 - Linux 2.6 O(1) scheduler
● Two queues: active vs. expired
● Heuristics-based / no “formal” algorithm
● 2007 - ~ Linux 2.6.21
● Con Kolivas' Rotating Staircase Deadline Scheduler (RSDL)
● 2007 - Linux 2.6.23
● Ingo Molnar's Completely Fair Scheduler (CFS)
13
3. Completely Fair Scheduler (CFS)
●
Tasks put in red-black tree
●
Self-balancing – i.e. no path more than twice other path
● O (log n) operations
●
task_struct->sched_entity->rb_node
●
kernel/core/sched.c:schedule()
●
put_prev_task()
●
pick_next_task()
●
Priorities provide decay factors
●
Higher priority = lower decay factor
● i.e. lower priority uses up their time more quickly
●
Group scheduling – control group mechanism (cgroups)
●
Grouped processes share a single process' virtual time
●
Use of cgroupfs – /acct in Android
14
4. Sched Classes
● See kernel/sched/sched.h
● struct sched_class
● Classes
● CFS - SCHED_OTHER (i.e. SCHED_NORMAL in the sources)
● RT - SCHED_FIFO / SCHED_RR
● Deadline - SCHED_DEADLINE(since 3.14)
● Idle - Not!!! SCHED_IDLE
● Stop – CPU stopping
● sched_setscheduler()
15
5. CPU power management
●
Need to integrate CPU power management and scheduler more closely
●
Existing Linux support for power management (governors)
●
cpuidle
– What happens when the CPU is idle
● cpufreq drivers
– HW counters- / FW-based decision (intel_pstate / longrun)
– Hard-coded values based on ranges within driver DVFS – “Dynamic Voltage and Frequency Scaling”
●
Trivial
– Performance - highest frequency
– Powersave - lowest frequency
– Userspace - User-space app makes decision
●
Non-trivial
– Based on system load
●
Stats for non-trivial governors come from scheduler stats (/proc/stat)
●
On-demand - Immediate jump on load increase
● Conservative - Gradual scale-up on increase
16
5.1. Making frequency scaling choices
● SCHED_DEADLINE
● We have precise info, because of how this works
● SCHED_FIFO / SCHED_RR
● Put CPU at max right away
● SCHED_NORMAL
● Use stats
17
6. Load tracking
● How to track how much “load” a process is putting on the
system?
● Not just CPU time consumed
● Process waiting for CPU is contributing to load
● Since 3.8
● PELT - Per-Entity Load Tracking
– Each load instance is y times the previous one:
● L0 + L1*y + L2*y2 + L3*y3 + ...
● New proposal (used in Pixel)
● WALT - Window-Assisted Load Tracking
18
7. Android problems w/ Linux scheduler
● Even “on-demand” isn't good enough
● It takes too many milliseconds for timer to tick
and stats to be updated
● Since decision is based on stats, delay is user-
noticeable
19
7.1. Android Initial Solution
● Android devs wrote their own governor:
● “interactive”
● Detects transition out of idle
● Shortens timeout to scale up to much shorter
time (“1-2 ticks”)
● Out of tree
20
7.2. Intermediate solutions discussed
● Trigger cpufreq when scheduler updates stats
● Instead of trigger using a timeout
● Introduce new governor: schedutil (merged in
4.7)
● Use the info straight from the scheduler stats
update
21
7.3. Recent Work
●
Problems:
● bigLITTLE
● EAS – Energy Aware Scheduling
●
SchedTune used in Pixel phone
● Provide user-space knobs to control schedutil governor
● Android doesn't need to make suppositions, it knows what's happening
●
Implemented as control-group controller
● Each cgroup has tunable “schedtune.boost”
●
sched-freq
● Use CFS runqueue info to scale CPU freq
●
WALT – Window-Assisted Load Tracking
22
8. User-space vs. Linux scheduler
● Control knobs
● /dev/cpuset/ - which tasks run on which CPUs
● /dev/cpuctl/ - restrict CPU time for bg tasks
● /dev/stune/ - EAS stune boosting
● init.rc
● Power HAL:
● Power “hints”
● Set interactive
23
9. Framework
● System Services:
●
Activity Manager
– Causes apps to be started through Zygote
– Feed lifecycle events
– Manages foreground vs. background, etc.
●
Scheduling Policy:
– Modifies process scheduler based on request
● Defined thread groups:
● Default (for internal use)
● BG non-interactive
● Foreground
● System
●
Audio App -- SCHED_FIFO
●
Audio Sys -- SCHED_FIFO
●
Top App
● See
●
frameworks/base/core/java/android/os/Process.java
●
frameworks/base/core/jni/android_util_Process.cpp
●
system/core/include/cutils/sched_policy.h
24
10. Summing Up
● Quite a few moving parts
● Linux does bulk of work
● Android gives hints to Linux
● Still ongoing work to get best performance with
least battery usage
25
Thank you ...
karim.yaghmour@opersys.com

More Related Content

PDF
The Linux Kernel Scheduler (For Beginners) - SFO17-421
PDF
Cgroups in android
PDF
Booting Android: bootloaders, fastboot and boot images
PDF
LCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
PPT
Learning AOSP - Android Booting Process
PDF
PDF
Jagan Teki - U-boot from scratch
PPTX
The TCP/IP Stack in the Linux Kernel
The Linux Kernel Scheduler (For Beginners) - SFO17-421
Cgroups in android
Booting Android: bootloaders, fastboot and boot images
LCA14: LCA14-306: CPUidle & CPUfreq integration with scheduler
Learning AOSP - Android Booting Process
Jagan Teki - U-boot from scratch
The TCP/IP Stack in the Linux Kernel

What's hot (20)

PDF
Android Boot Time Optimization
PDF
LAS16-105: Walkthrough of the EAS kernel adaptation to the Android Common Kernel
PDF
Linux Profiling at Netflix
PDF
Android Things : Building Embedded Devices
PDF
BKK16-317 How to generate power models for EAS and IPA
PDF
Porting Android
PDF
LCU14-410: How to build an Energy Model for your SoC
PPTX
Linux kernel debugging
PDF
Linux-Internals-and-Networking
PPT
Basic Linux Internals
PDF
Embedded Android : System Development - Part II (Linux device drivers)
ODP
Q4.11: Porting Android to new Platforms
PDF
BKK16-208 EAS
PDF
Linux Performance Profiling and Monitoring
PDF
Understanding the Android System Server
PDF
Embedded Android : System Development - Part II (HAL)
PDF
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
PDF
U-Boot - An universal bootloader
PDF
Introduction to CUDA
Android Boot Time Optimization
LAS16-105: Walkthrough of the EAS kernel adaptation to the Android Common Kernel
Linux Profiling at Netflix
Android Things : Building Embedded Devices
BKK16-317 How to generate power models for EAS and IPA
Porting Android
LCU14-410: How to build an Energy Model for your SoC
Linux kernel debugging
Linux-Internals-and-Networking
Basic Linux Internals
Embedded Android : System Development - Part II (Linux device drivers)
Q4.11: Porting Android to new Platforms
BKK16-208 EAS
Linux Performance Profiling and Monitoring
Understanding the Android System Server
Embedded Android : System Development - Part II (HAL)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
U-Boot - An universal bootloader
Introduction to CUDA
Ad

Similar to Scheduling in Android (20)

PDF
Scheduling in Android
PDF
Process Scheduler and Balancer in Linux Kernel
PDF
Building a Custom Linux CPU Scheduler with sched_ext.pdf
PDF
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
PDF
BKK16-104 sched-freq
PDF
Linux kernel development ch4
PDF
Linux Scheduler Latest_ viresh Kumar.pdf
PDF
Linux scheduler
PDF
seminar report
PPTX
Process scheduling
PDF
When the OS gets in the way
PPTX
Usage and Comparisons of Control Group in Android AOSP: Marshmallow and Before
PDF
Q2.12: Existing Linux Mechanisms to Support big.LITTLE
PDF
Scheduling
PDF
Lect17
PDF
CS6401 OPERATING SYSTEMS Unit 2
PPT
06-scheduling.ppt including multiple CPUs
PPTX
UNIT II PPT.pptx
PPTX
Process Management in Android
PDF
Operating System / System Operasi
Scheduling in Android
Process Scheduler and Balancer in Linux Kernel
Building a Custom Linux CPU Scheduler with sched_ext.pdf
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
BKK16-104 sched-freq
Linux kernel development ch4
Linux Scheduler Latest_ viresh Kumar.pdf
Linux scheduler
seminar report
Process scheduling
When the OS gets in the way
Usage and Comparisons of Control Group in Android AOSP: Marshmallow and Before
Q2.12: Existing Linux Mechanisms to Support big.LITTLE
Scheduling
Lect17
CS6401 OPERATING SYSTEMS Unit 2
06-scheduling.ppt including multiple CPUs
UNIT II PPT.pptx
Process Management in Android
Operating System / System Operasi
Ad

More from Opersys inc. (20)

PDF
Android Automotive
PDF
Android 10 Internals Update
PDF
Android Security Internals
PDF
Embedded Android Workshop with Pie
PDF
Android's HIDL: Treble in the HAL
PDF
Android Treble: Blessing or Trouble?
PDF
Embedded Android Workshop with Oreo
PDF
Android Things Internals
PDF
Android Platform Debugging and Development
PDF
Embedded Android Workshop with Nougat
PDF
Embedded Android Workshop with Nougat
PDF
Android Things: Android for IoT
PDF
Android Things Internals
PDF
Brillo / Weave Internals
PDF
Android Platform Debugging and Development
PDF
Memory Management in Android
PDF
Embedded Android Workshop with Nougat
PDF
Brillo / Weave Internals
PDF
Project Ara
PDF
Android Platform Debugging and Development
Android Automotive
Android 10 Internals Update
Android Security Internals
Embedded Android Workshop with Pie
Android's HIDL: Treble in the HAL
Android Treble: Blessing or Trouble?
Embedded Android Workshop with Oreo
Android Things Internals
Android Platform Debugging and Development
Embedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
Android Things: Android for IoT
Android Things Internals
Brillo / Weave Internals
Android Platform Debugging and Development
Memory Management in Android
Embedded Android Workshop with Nougat
Brillo / Weave Internals
Project Ara
Android Platform Debugging and Development

Recently uploaded (20)

PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
medical staffing services at VALiNTRY
PDF
AI in Product Development-omnex systems
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Digital Strategies for Manufacturing Companies
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
System and Network Administration Chapter 2
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
ai tools demonstartion for schools and inter college
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Odoo POS Development Services by CandidRoot Solutions
Upgrade and Innovation Strategies for SAP ERP Customers
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Adobe Illustrator 28.6 Crack My Vision of Vector Design
medical staffing services at VALiNTRY
AI in Product Development-omnex systems
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Transform Your Business with a Software ERP System
Digital Strategies for Manufacturing Companies
CHAPTER 2 - PM Management and IT Context
System and Network Administration Chapter 2
wealthsignaloriginal-com-DS-text-... (1).pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PTS Company Brochure 2025 (1).pdf.......
Design an Analysis of Algorithms II-SECS-1021-03
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
How to Choose the Right IT Partner for Your Business in Malaysia
ai tools demonstartion for schools and inter college
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...

Scheduling in Android

  • 1. 1 Scheduling in Android AnDevCon Washington D.C. 2017 Karim Yaghmour @karimyaghmour karim.yaghmour@opersys.com
  • 2. 2 These slides are made available to you under a Creative Commons Share- Alike 3.0 license. The full terms of this license are here: https://creativecommons.org/licenses/by-sa/3.0/ Attribution requirements and misc., PLEASE READ: ● This slide must remain as-is in this specific location (slide #2), everything else you are free to change; including the logo :-) ● Use of figures in other documents must feature the below “Originals at” URL immediately under that figure and the below copyright notice where appropriate. ● You are free to fill in the “Delivered and/or customized by” space on the right as you see fit. ● You are FORBIDEN from using the default “About” slide as-is or any of its contents. ● You are FORBIDEN from using any content provided by 3rd parties without the EXPLICIT consent from those parties. (C) Copyright 2016-2017, Opersys inc. These slides created by: Karim Yaghmour Originals at: www.opersys.com/community/docs Delivered and/or customized by
  • 3. 3 About ● Author of: ● Introduced Linux Trace Toolkit in 1999 ● Originated Adeos and relayfs (kernel/relay.c) ● Training, Custom Dev, Consulting, ...
  • 4. 4 Agenda 1. Architecture 2. Linux scheduler history 3. Completely Fair Scheduler (CFS) 4. Sched Classes 5. CPU power management 6. Load tracking 7. Android problems w/ Linux scheduler 8. User-space vs. Linux scheduler 9. Framework 10. Summing up
  • 5. 5 1. Architecture ● Hardware on which Android is based ● Android stack ● Startup ● System services ● Binder driver
  • 6. 6
  • 7. 7
  • 8. 8
  • 9. 9
  • 10. 10
  • 11. 11
  • 12. 12 2. Linux scheduler history ● 1995 - Linux 1.2 ● Circular queue of tasks w/ round-robin ● 1999 - Linux 2.2 ● Scheduling classes: real-time, non-preemptable and non-real-time ● SMP support ● 2001 - Linux 2.4 O(N) scheduler ● Each task gets a slice (epoch) ● 2003 - Linux 2.6 O(1) scheduler ● Two queues: active vs. expired ● Heuristics-based / no “formal” algorithm ● 2007 - ~ Linux 2.6.21 ● Con Kolivas' Rotating Staircase Deadline Scheduler (RSDL) ● 2007 - Linux 2.6.23 ● Ingo Molnar's Completely Fair Scheduler (CFS)
  • 13. 13 3. Completely Fair Scheduler (CFS) ● Tasks put in red-black tree ● Self-balancing – i.e. no path more than twice other path ● O (log n) operations ● task_struct->sched_entity->rb_node ● kernel/core/sched.c:schedule() ● put_prev_task() ● pick_next_task() ● Priorities provide decay factors ● Higher priority = lower decay factor ● i.e. lower priority uses up their time more quickly ● Group scheduling – control group mechanism (cgroups) ● Grouped processes share a single process' virtual time ● Use of cgroupfs – /acct in Android
  • 14. 14 4. Sched Classes ● See kernel/sched/sched.h ● struct sched_class ● Classes ● CFS - SCHED_OTHER (i.e. SCHED_NORMAL in the sources) ● RT - SCHED_FIFO / SCHED_RR ● Deadline - SCHED_DEADLINE(since 3.14) ● Idle - Not!!! SCHED_IDLE ● Stop – CPU stopping ● sched_setscheduler()
  • 15. 15 5. CPU power management ● Need to integrate CPU power management and scheduler more closely ● Existing Linux support for power management (governors) ● cpuidle – What happens when the CPU is idle ● cpufreq drivers – HW counters- / FW-based decision (intel_pstate / longrun) – Hard-coded values based on ranges within driver DVFS – “Dynamic Voltage and Frequency Scaling” ● Trivial – Performance - highest frequency – Powersave - lowest frequency – Userspace - User-space app makes decision ● Non-trivial – Based on system load ● Stats for non-trivial governors come from scheduler stats (/proc/stat) ● On-demand - Immediate jump on load increase ● Conservative - Gradual scale-up on increase
  • 16. 16 5.1. Making frequency scaling choices ● SCHED_DEADLINE ● We have precise info, because of how this works ● SCHED_FIFO / SCHED_RR ● Put CPU at max right away ● SCHED_NORMAL ● Use stats
  • 17. 17 6. Load tracking ● How to track how much “load” a process is putting on the system? ● Not just CPU time consumed ● Process waiting for CPU is contributing to load ● Since 3.8 ● PELT - Per-Entity Load Tracking – Each load instance is y times the previous one: ● L0 + L1*y + L2*y2 + L3*y3 + ... ● New proposal (used in Pixel) ● WALT - Window-Assisted Load Tracking
  • 18. 18 7. Android problems w/ Linux scheduler ● Even “on-demand” isn't good enough ● It takes too many milliseconds for timer to tick and stats to be updated ● Since decision is based on stats, delay is user- noticeable
  • 19. 19 7.1. Android Initial Solution ● Android devs wrote their own governor: ● “interactive” ● Detects transition out of idle ● Shortens timeout to scale up to much shorter time (“1-2 ticks”) ● Out of tree
  • 20. 20 7.2. Intermediate solutions discussed ● Trigger cpufreq when scheduler updates stats ● Instead of trigger using a timeout ● Introduce new governor: schedutil (merged in 4.7) ● Use the info straight from the scheduler stats update
  • 21. 21 7.3. Recent Work ● Problems: ● bigLITTLE ● EAS – Energy Aware Scheduling ● SchedTune used in Pixel phone ● Provide user-space knobs to control schedutil governor ● Android doesn't need to make suppositions, it knows what's happening ● Implemented as control-group controller ● Each cgroup has tunable “schedtune.boost” ● sched-freq ● Use CFS runqueue info to scale CPU freq ● WALT – Window-Assisted Load Tracking
  • 22. 22 8. User-space vs. Linux scheduler ● Control knobs ● /dev/cpuset/ - which tasks run on which CPUs ● /dev/cpuctl/ - restrict CPU time for bg tasks ● /dev/stune/ - EAS stune boosting ● init.rc ● Power HAL: ● Power “hints” ● Set interactive
  • 23. 23 9. Framework ● System Services: ● Activity Manager – Causes apps to be started through Zygote – Feed lifecycle events – Manages foreground vs. background, etc. ● Scheduling Policy: – Modifies process scheduler based on request ● Defined thread groups: ● Default (for internal use) ● BG non-interactive ● Foreground ● System ● Audio App -- SCHED_FIFO ● Audio Sys -- SCHED_FIFO ● Top App ● See ● frameworks/base/core/java/android/os/Process.java ● frameworks/base/core/jni/android_util_Process.cpp ● system/core/include/cutils/sched_policy.h
  • 24. 24 10. Summing Up ● Quite a few moving parts ● Linux does bulk of work ● Android gives hints to Linux ● Still ongoing work to get best performance with least battery usage