SlideShare a Scribd company logo
1 of 26
Download to read offline
Linux power management: are you doing it
right?
Chris Simmonds
Embedded World 2018
Linux power management: are you doing it right? 1 Copyright © 2011-2018, 2net Ltd
License
These slides are available under a Creative Commons Attribution-ShareAlike 3.0 license. You can read the full
text of the license here
http://creativecommons.org/licenses/by-sa/3.0/legalcode
You are free to
• copy, distribute, display, and perform the work
• make derivative works
• 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 (i.e. include this page exactly as it is)
• For any reuse or distribution, you must make clear to others the license terms of this work
Linux power management: are you doing it right? 2 Copyright © 2011-2018, 2net Ltd
About Chris Simmonds
• Consultant and trainer
• Author of Mastering Embedded Linux Programming
• Working with embedded Linux since 1999
• Android since 2009
• Speaker at many conferences and workshops
"Looking after the Inner Penguin" blog at http://2net.co.uk/
https://uk.linkedin.com/in/chrisdsimmonds/
https://google.com/+chrissimmonds
Linux power management: are you doing it right? 3 Copyright © 2011-2018, 2net Ltd
Overview
• Reducing power usage is important, especially for battery-powered
devices
• In this talk I will introduce
• The rules of power management
• The major Linux systems that implement power management
• Some practical measures you can take
Linux power management: are you doing it right? 4 Copyright © 2011-2018, 2net Ltd
The rules of power management
1. Don’t rush if you don’t have to
2. Take a break when things are quiet
3. Turn things off when they are not in use
4. Have a snooze when you expect things to be quite for a while
Linux power management: are you doing it right? 5 Copyright © 2011-2018, 2net Ltd
Rule 1: Don’t rush
• Reducing CPU frequency saves power?
• P = CfV2
• Reducing voltage, not frequency, saves power
• But, lowering frequency allows for lowering the voltage, and therefore
saves power
• The tuple of frequency and voltage is called an Operating Performance
Point (OPP)
• The ability to change OPP at run-time is called Dynamic Voltage and
Frequency Scaling (DVFS)
Linux power management: are you doing it right? 6 Copyright © 2011-2018, 2net Ltd
OPP definitions in device tree
Example from am33xx.dtsi
cpu0_opp_table: opp-table {
compatible = "operating-points-v2-ti-cpu";
syscon = <&scm_conf>;
opp50@300000000 {
opp-hz = /bits/ 64 <300000000>;
opp-microvolt = <950000 931000 969000>;
opp-supported-hw = <0x06 0x0010>;
opp-suspend;
};
opp100@600000000 {
opp-hz = /bits/ 64 <600000000>;
opp-microvolt = <1100000 1078000 1122000>;
opp-supported-hw = <0x06 0x0040>;
};
[...]
};
Linux power management: are you doing it right? 7 Copyright © 2011-2018, 2net Ltd
CPUFreq
• In Linux, selecting the best OPP is done by the CPUFreq driver
• Enable with kernel option CONFIG_CPU_FREQ=y
• Part of the Linux support for each SoC
• Control is per CPU, via directory /sys/devices/system/cpu/cpuN/cpufreq
• List of possible frequencies (corresponding to OPPs):
# cd /sys/devices/system/cpu/cpu0/cpufreq
# cat scaling_available_frequencies
300000 600000 720000 800000
Linux power management: are you doing it right? 8 Copyright © 2011-2018, 2net Ltd
CPUFreq Governors
• The policy for changing the OPP is controlled by a governor
• There are a small number of governors coded into Linux:
# cd /sys/devices/system/cpu/cpu0/cpufreq
# cat scaling_available_governors
conservative ondemand userspace powersave performance
Linux power management: are you doing it right? 9 Copyright © 2011-2018, 2net Ltd
Governors
• powersave: Always selects the lowest frequency
• performance: Always selects the highest frequency
• ondemand: Changes frequency based on the CPU utilization. If the
CPU is idle less than 20% of the time, it sets the frequency to the
maximum; if it is idle more than 30% of the time, it decrements the
frequency by 5%
• conservative: As ondemand , but switches to higher frequencies in
5% steps rather than going immediately to the maximum
• userspace: Frequency is set by a user space program
Linux power management: are you doing it right? 10 Copyright © 2011-2018, 2net Ltd
Example of the potential power saving
• BeagleBone Black running a constant load
• No governor: using fixed frequencies
OPP Freq MHz CPU use, % Power, mW
OPP50 300 94 320
OPP100 600 48 345
OPP120 720 40 370
Turbo 800 34 370
Nitro 1000 28 370
15% saving by running the job at 300 MHz instead of 1 GHz
Linux power management: are you doing it right? 11 Copyright © 2011-2018, 2net Ltd
Rule 2: take a break
• When the CPU has nothing to do, it enters an idle state
• Usually, there are several idle states to choose from
• Sometimes known as C-states
• Deeper idle states take longer to return to full operation
• Example: the CPU L1 cache may be powered down, so it takes time to
re-load the cache when restarting
Linux power management: are you doing it right? 12 Copyright © 2011-2018, 2net Ltd
CPUIdle
• In Linux, the transition between idle states is controlled by the CPUIdle
driver
• Enable with kernel option CONFIG_CPU_IDLE
• Information about idle state C for CPU N is in
/sys/devices/system/cpu/cpuN/cpuidle/stateC
• For example the TI AM335x SoC has only two states
• State0: WFI (Wait For Interrupt)
• State1: C1
Linux power management: are you doing it right? 13 Copyright © 2011-2018, 2net Ltd
CPUIdle governors
• The policy for selecting idle states is controlled by the CPUIdle
governor
• Cannot be changed at run-time
• Only two options
• ladder: steps through the idle states one at a time depending on the
time spent in the last idle period. Works well with a regular timer tick
• menu: selects an idle state based on the expected idle time. Works well
with tickless systems
Linux power management: are you doing it right? 14 Copyright © 2011-2018, 2net Ltd
Tickless operation
• Linux was written assuming a constant tick, typically 100Hz
• On an idle system, this is a waste of CPU power; stops the CU
entering deeper sleep states
• For tickless operation, configure your kernel with CONFIG_NO_HZ_IDLE=y
(on older kernels, CONFIG_NO_HZ=y)
• Schedules timer interrupts for the next event, skipping any intermediate
ticks
• Potential power saving on a device that is mostly idle: up to 70%
Linux power management: are you doing it right? 15 Copyright © 2011-2018, 2net Ltd
Rule 3: turn things off
• Managing the power usage of peripherals is also important
• In Linux, the runtime power management (pm runtime) tracks the
state of pm-aware device drivers
• Each device driver can register callback functions such as
runtime_suspend and runtime_resume
• Kernel configuration option CONFIG_PM
Linux power management: are you doing it right? 16 Copyright © 2011-2018, 2net Ltd
Controlling pm runtime
• PM runtime is exposed via directory power for each device that
supports it
• Files in that directory include:
• control: "auto": kernel will select state; "on": device always on (pm
runtime disabled)
• runtime_status: current state of the device: "active", "suspended", or
"unsupported"
• autosuspend_delay_ms: minimum time before suspending device
Linux power management: are you doing it right? 17 Copyright © 2011-2018, 2net Ltd
Runtime PM
• For example, the MMC controller on TI AM335x
# cd /sys/devices/platform/ocp/481d8000.mmc/mmc_host/mmc1/mmc1:0001/power
# grep "" *
async:disabled
autosuspend_delay_ms:3000
control:auto
runtime_active_kids:0
runtime_active_time:164440
runtime_enabled:enabled
runtime_status:suspended
runtime_suspended_time:139270
runtime_usage:0
• Note that autosuspend_delay_ms is 3 seconds
• That runtime_status is "suspended"
Linux power management: are you doing it right? 18 Copyright © 2011-2018, 2net Ltd
Rule 4: Have a snooze
• The techniques so far will optimize power usage of a running system
• Largest power saving comes from entering a system sleep mode
• Example: when closing the lid of a laptop
• Example: Android device suspending after activity timeout (default 60
seconds)
Linux power management: are you doing it right? 19 Copyright © 2011-2018, 2net Ltd
Power states
Sleep state S-state Description
freeze Stops (freezes) all activity in user space
standby S1 Powers down all CPUs except the boot CPU
mem S3 Powers down the system, puts RAM into self-refresh
disk S4 Saves memory to disk, followed by complete power down
Linux sleep states, together with equivalent ACPI S-state
• mem (suspend to RAM) typically consumes a few milliamps
(dependent on board design and BSP)
• disk (suspend to disk) typically consumes no power at all
Linux power management: are you doing it right? 20 Copyright © 2011-2018, 2net Ltd
Controlling power state
• In Linux, macro power management is via by the power management
subsystem
• Enable with kernel option CONFIG_PM
• You can view the sleep states implemented in BSP via /sys/power/state
# cat /sys/power/state
freeze standby mem disk
• mem is the one most often used in embedded systems
• disk (aka hibernation) is usually too slow and takes too much storage
when using flash memory
Linux power management: are you doing it right? 21 Copyright © 2011-2018, 2net Ltd
Changing power state
• Simply, write the desired state to /sys/power/state
• For example, to enter suspend mode:
# echo mem > /sys/power/state
[ 1646.158274] PM: Syncing filesystems ...done.
[ 1646.178387] Freezing user space processes ...(elapsed 0.001 seconds)
done.
[ 1646.188098] Freezing remaining freezable tasks ...
(elapsed 0.001 seconds) done.
[ 1646.197017] Suspending console(s) (use
no_console_suspend to debug)
[ 1646.338657] PM: suspend of devices complete
after 134.322 msecs
[ 1646.343428] PM: late suspend of devices
Linux power management: are you doing it right? 22 Copyright © 2011-2018, 2net Ltd
Waking up
• CPU is woken by interrupt or other input
• Wakeup sources need to be powered while the main CPU is powered
down
• Wakeup sources may include
• Real-time clock (RTC)
• Certain GPIO pins
• UART
• Usually managed by a dedicated Power Management chip, PMIC
Linux power management: are you doing it right? 23 Copyright © 2011-2018, 2net Ltd
Wakeup sources
• Devices that can act as wakeup sources have
/sys/devices/.../power/wakeup set to "enabled"
• For example, GPIOs 0 to 7 on AM335x
# cat /sys/devices/platform/gpio_keys/power/wakeup
enabled
• Hence, pressing the power button wakes the device
Linux power management: are you doing it right? 24 Copyright © 2011-2018, 2net Ltd
Conclusion
• A well configured Linux device will save power
• Linux features considered here:
• CPUFreq: selects OPP depending on load
• CPUIdle: selects idle state based on predicted load
• Tickless: eliminates unnecessary timer interrupts
• Runtime power management: powers off unused peripherals
• Suspend to RAM: puts system in minimum power usage state
Linux power management: are you doing it right? 25 Copyright © 2011-2018, 2net Ltd
Questions?
Further reading: Chapter 11 of Mastering Embedded Linux Programming
Contact:
Web: www.2net.co.uk
Email: training@2net.co.uk
LinkedIn: https://uk.linkedin.com/in/chrisdsimmonds
Linux power management: are you doing it right? 26 Copyright © 2011-2018, 2net Ltd

More Related Content

What's hot

LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
Linaro
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
Brendan Gregg
 

What's hot (20)

Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
Kvm and libvirt
Kvm and libvirtKvm and libvirt
Kvm and libvirt
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
Introduction to Optee (26 may 2016)
Introduction to Optee (26 may 2016)Introduction to Optee (26 may 2016)
Introduction to Optee (26 may 2016)
 
BUD17-400: Secure Data Path with OPTEE
BUD17-400: Secure Data Path with OPTEE BUD17-400: Secure Data Path with OPTEE
BUD17-400: Secure Data Path with OPTEE
 
Quick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOQuick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIO
 
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardKernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Achieving the ultimate performance with KVM
Achieving the ultimate performance with KVM Achieving the ultimate performance with KVM
Achieving the ultimate performance with KVM
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
Yocto Project introduction
Yocto Project introductionYocto Project introduction
Yocto Project introduction
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
Power management
Power managementPower management
Power management
 
Linux Audio Drivers. ALSA
Linux Audio Drivers. ALSALinux Audio Drivers. ALSA
Linux Audio Drivers. ALSA
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 

Similar to Linux power management: are you doing it right?

Module 1 Introduction.ppt
Module 1 Introduction.pptModule 1 Introduction.ppt
Module 1 Introduction.ppt
shreesha16
 

Similar to Linux power management: are you doing it right? (20)

Optimizing Linux Servers
Optimizing Linux ServersOptimizing Linux Servers
Optimizing Linux Servers
 
Your Linux AMI: Optimization and Performance (CPN302) | AWS re:Invent 2013
Your Linux AMI: Optimization and Performance (CPN302) | AWS re:Invent 2013Your Linux AMI: Optimization and Performance (CPN302) | AWS re:Invent 2013
Your Linux AMI: Optimization and Performance (CPN302) | AWS re:Invent 2013
 
Ch4 memory management
Ch4 memory managementCh4 memory management
Ch4 memory management
 
Insider operating system
Insider   operating systemInsider   operating system
Insider operating system
 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architecture
 
Module 1 Introduction.ppt
Module 1 Introduction.pptModule 1 Introduction.ppt
Module 1 Introduction.ppt
 
linux monitoring and performance tunning
linux monitoring and performance tunning linux monitoring and performance tunning
linux monitoring and performance tunning
 
Session 7362 Handout 427 0
Session 7362 Handout 427 0Session 7362 Handout 427 0
Session 7362 Handout 427 0
 
Virtualization Basics
Virtualization BasicsVirtualization Basics
Virtualization Basics
 
MK Sistem Operasi.pdf
MK Sistem Operasi.pdfMK Sistem Operasi.pdf
MK Sistem Operasi.pdf
 
Introduction to Operating Systems.pdf
Introduction to Operating Systems.pdfIntroduction to Operating Systems.pdf
Introduction to Operating Systems.pdf
 
1 introduction
1 introduction1 introduction
1 introduction
 
Basics of micro controllers for biginners
Basics of  micro controllers for biginnersBasics of  micro controllers for biginners
Basics of micro controllers for biginners
 
UNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsUNIT 3 - General Purpose Processors
UNIT 3 - General Purpose Processors
 
Considerations when implementing_ha_in_dmf
Considerations when implementing_ha_in_dmfConsiderations when implementing_ha_in_dmf
Considerations when implementing_ha_in_dmf
 
Operating System Unit 1
Operating System Unit 1Operating System Unit 1
Operating System Unit 1
 
Engg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdfEngg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdf
 
Ibm spectrum scale fundamentals workshop for americas part 2 IBM Spectrum Sca...
Ibm spectrum scale fundamentals workshop for americas part 2 IBM Spectrum Sca...Ibm spectrum scale fundamentals workshop for americas part 2 IBM Spectrum Sca...
Ibm spectrum scale fundamentals workshop for americas part 2 IBM Spectrum Sca...
 
OS Content.pdf
OS Content.pdfOS Content.pdf
OS Content.pdf
 
(CMP402) Amazon EC2 Instances Deep Dive
(CMP402) Amazon EC2 Instances Deep Dive(CMP402) Amazon EC2 Instances Deep Dive
(CMP402) Amazon EC2 Instances Deep Dive
 

More from Chris Simmonds

Linux field-update-2015
Linux field-update-2015Linux field-update-2015
Linux field-update-2015
Chris Simmonds
 

More from Chris Simmonds (19)

Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDB
 
Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?
 
Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
 
Reducing the boot time of Linux devices
Reducing the boot time of Linux devicesReducing the boot time of Linux devices
Reducing the boot time of Linux devices
 
Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019
 
Reducing boot time in embedded Linux
Reducing boot time in embedded LinuxReducing boot time in embedded Linux
Reducing boot time in embedded Linux
 
Embedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneEmbedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphone
 
Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017
 
Software update for IoT: the current state of play
Software update for IoT: the current state of playSoftware update for IoT: the current state of play
Software update for IoT: the current state of play
 
Read-only rootfs: theory and practice
Read-only rootfs: theory and practiceRead-only rootfs: theory and practice
Read-only rootfs: theory and practice
 
Android beyond the smartphone
Android beyond the smartphoneAndroid beyond the smartphone
Android beyond the smartphone
 
10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016
 
The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)
 
Linux field-update-2015
Linux field-update-2015Linux field-update-2015
Linux field-update-2015
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAM
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
 
A timeline for embedded Linux
A timeline for embedded LinuxA timeline for embedded Linux
A timeline for embedded Linux
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

Linux power management: are you doing it right?

  • 1. Linux power management: are you doing it right? Chris Simmonds Embedded World 2018 Linux power management: are you doing it right? 1 Copyright © 2011-2018, 2net Ltd
  • 2. License These slides are available under a Creative Commons Attribution-ShareAlike 3.0 license. You can read the full text of the license here http://creativecommons.org/licenses/by-sa/3.0/legalcode You are free to • copy, distribute, display, and perform the work • make derivative works • 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 (i.e. include this page exactly as it is) • For any reuse or distribution, you must make clear to others the license terms of this work Linux power management: are you doing it right? 2 Copyright © 2011-2018, 2net Ltd
  • 3. About Chris Simmonds • Consultant and trainer • Author of Mastering Embedded Linux Programming • Working with embedded Linux since 1999 • Android since 2009 • Speaker at many conferences and workshops "Looking after the Inner Penguin" blog at http://2net.co.uk/ https://uk.linkedin.com/in/chrisdsimmonds/ https://google.com/+chrissimmonds Linux power management: are you doing it right? 3 Copyright © 2011-2018, 2net Ltd
  • 4. Overview • Reducing power usage is important, especially for battery-powered devices • In this talk I will introduce • The rules of power management • The major Linux systems that implement power management • Some practical measures you can take Linux power management: are you doing it right? 4 Copyright © 2011-2018, 2net Ltd
  • 5. The rules of power management 1. Don’t rush if you don’t have to 2. Take a break when things are quiet 3. Turn things off when they are not in use 4. Have a snooze when you expect things to be quite for a while Linux power management: are you doing it right? 5 Copyright © 2011-2018, 2net Ltd
  • 6. Rule 1: Don’t rush • Reducing CPU frequency saves power? • P = CfV2 • Reducing voltage, not frequency, saves power • But, lowering frequency allows for lowering the voltage, and therefore saves power • The tuple of frequency and voltage is called an Operating Performance Point (OPP) • The ability to change OPP at run-time is called Dynamic Voltage and Frequency Scaling (DVFS) Linux power management: are you doing it right? 6 Copyright © 2011-2018, 2net Ltd
  • 7. OPP definitions in device tree Example from am33xx.dtsi cpu0_opp_table: opp-table { compatible = "operating-points-v2-ti-cpu"; syscon = <&scm_conf>; opp50@300000000 { opp-hz = /bits/ 64 <300000000>; opp-microvolt = <950000 931000 969000>; opp-supported-hw = <0x06 0x0010>; opp-suspend; }; opp100@600000000 { opp-hz = /bits/ 64 <600000000>; opp-microvolt = <1100000 1078000 1122000>; opp-supported-hw = <0x06 0x0040>; }; [...] }; Linux power management: are you doing it right? 7 Copyright © 2011-2018, 2net Ltd
  • 8. CPUFreq • In Linux, selecting the best OPP is done by the CPUFreq driver • Enable with kernel option CONFIG_CPU_FREQ=y • Part of the Linux support for each SoC • Control is per CPU, via directory /sys/devices/system/cpu/cpuN/cpufreq • List of possible frequencies (corresponding to OPPs): # cd /sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_frequencies 300000 600000 720000 800000 Linux power management: are you doing it right? 8 Copyright © 2011-2018, 2net Ltd
  • 9. CPUFreq Governors • The policy for changing the OPP is controlled by a governor • There are a small number of governors coded into Linux: # cd /sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_governors conservative ondemand userspace powersave performance Linux power management: are you doing it right? 9 Copyright © 2011-2018, 2net Ltd
  • 10. Governors • powersave: Always selects the lowest frequency • performance: Always selects the highest frequency • ondemand: Changes frequency based on the CPU utilization. If the CPU is idle less than 20% of the time, it sets the frequency to the maximum; if it is idle more than 30% of the time, it decrements the frequency by 5% • conservative: As ondemand , but switches to higher frequencies in 5% steps rather than going immediately to the maximum • userspace: Frequency is set by a user space program Linux power management: are you doing it right? 10 Copyright © 2011-2018, 2net Ltd
  • 11. Example of the potential power saving • BeagleBone Black running a constant load • No governor: using fixed frequencies OPP Freq MHz CPU use, % Power, mW OPP50 300 94 320 OPP100 600 48 345 OPP120 720 40 370 Turbo 800 34 370 Nitro 1000 28 370 15% saving by running the job at 300 MHz instead of 1 GHz Linux power management: are you doing it right? 11 Copyright © 2011-2018, 2net Ltd
  • 12. Rule 2: take a break • When the CPU has nothing to do, it enters an idle state • Usually, there are several idle states to choose from • Sometimes known as C-states • Deeper idle states take longer to return to full operation • Example: the CPU L1 cache may be powered down, so it takes time to re-load the cache when restarting Linux power management: are you doing it right? 12 Copyright © 2011-2018, 2net Ltd
  • 13. CPUIdle • In Linux, the transition between idle states is controlled by the CPUIdle driver • Enable with kernel option CONFIG_CPU_IDLE • Information about idle state C for CPU N is in /sys/devices/system/cpu/cpuN/cpuidle/stateC • For example the TI AM335x SoC has only two states • State0: WFI (Wait For Interrupt) • State1: C1 Linux power management: are you doing it right? 13 Copyright © 2011-2018, 2net Ltd
  • 14. CPUIdle governors • The policy for selecting idle states is controlled by the CPUIdle governor • Cannot be changed at run-time • Only two options • ladder: steps through the idle states one at a time depending on the time spent in the last idle period. Works well with a regular timer tick • menu: selects an idle state based on the expected idle time. Works well with tickless systems Linux power management: are you doing it right? 14 Copyright © 2011-2018, 2net Ltd
  • 15. Tickless operation • Linux was written assuming a constant tick, typically 100Hz • On an idle system, this is a waste of CPU power; stops the CU entering deeper sleep states • For tickless operation, configure your kernel with CONFIG_NO_HZ_IDLE=y (on older kernels, CONFIG_NO_HZ=y) • Schedules timer interrupts for the next event, skipping any intermediate ticks • Potential power saving on a device that is mostly idle: up to 70% Linux power management: are you doing it right? 15 Copyright © 2011-2018, 2net Ltd
  • 16. Rule 3: turn things off • Managing the power usage of peripherals is also important • In Linux, the runtime power management (pm runtime) tracks the state of pm-aware device drivers • Each device driver can register callback functions such as runtime_suspend and runtime_resume • Kernel configuration option CONFIG_PM Linux power management: are you doing it right? 16 Copyright © 2011-2018, 2net Ltd
  • 17. Controlling pm runtime • PM runtime is exposed via directory power for each device that supports it • Files in that directory include: • control: "auto": kernel will select state; "on": device always on (pm runtime disabled) • runtime_status: current state of the device: "active", "suspended", or "unsupported" • autosuspend_delay_ms: minimum time before suspending device Linux power management: are you doing it right? 17 Copyright © 2011-2018, 2net Ltd
  • 18. Runtime PM • For example, the MMC controller on TI AM335x # cd /sys/devices/platform/ocp/481d8000.mmc/mmc_host/mmc1/mmc1:0001/power # grep "" * async:disabled autosuspend_delay_ms:3000 control:auto runtime_active_kids:0 runtime_active_time:164440 runtime_enabled:enabled runtime_status:suspended runtime_suspended_time:139270 runtime_usage:0 • Note that autosuspend_delay_ms is 3 seconds • That runtime_status is "suspended" Linux power management: are you doing it right? 18 Copyright © 2011-2018, 2net Ltd
  • 19. Rule 4: Have a snooze • The techniques so far will optimize power usage of a running system • Largest power saving comes from entering a system sleep mode • Example: when closing the lid of a laptop • Example: Android device suspending after activity timeout (default 60 seconds) Linux power management: are you doing it right? 19 Copyright © 2011-2018, 2net Ltd
  • 20. Power states Sleep state S-state Description freeze Stops (freezes) all activity in user space standby S1 Powers down all CPUs except the boot CPU mem S3 Powers down the system, puts RAM into self-refresh disk S4 Saves memory to disk, followed by complete power down Linux sleep states, together with equivalent ACPI S-state • mem (suspend to RAM) typically consumes a few milliamps (dependent on board design and BSP) • disk (suspend to disk) typically consumes no power at all Linux power management: are you doing it right? 20 Copyright © 2011-2018, 2net Ltd
  • 21. Controlling power state • In Linux, macro power management is via by the power management subsystem • Enable with kernel option CONFIG_PM • You can view the sleep states implemented in BSP via /sys/power/state # cat /sys/power/state freeze standby mem disk • mem is the one most often used in embedded systems • disk (aka hibernation) is usually too slow and takes too much storage when using flash memory Linux power management: are you doing it right? 21 Copyright © 2011-2018, 2net Ltd
  • 22. Changing power state • Simply, write the desired state to /sys/power/state • For example, to enter suspend mode: # echo mem > /sys/power/state [ 1646.158274] PM: Syncing filesystems ...done. [ 1646.178387] Freezing user space processes ...(elapsed 0.001 seconds) done. [ 1646.188098] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done. [ 1646.197017] Suspending console(s) (use no_console_suspend to debug) [ 1646.338657] PM: suspend of devices complete after 134.322 msecs [ 1646.343428] PM: late suspend of devices Linux power management: are you doing it right? 22 Copyright © 2011-2018, 2net Ltd
  • 23. Waking up • CPU is woken by interrupt or other input • Wakeup sources need to be powered while the main CPU is powered down • Wakeup sources may include • Real-time clock (RTC) • Certain GPIO pins • UART • Usually managed by a dedicated Power Management chip, PMIC Linux power management: are you doing it right? 23 Copyright © 2011-2018, 2net Ltd
  • 24. Wakeup sources • Devices that can act as wakeup sources have /sys/devices/.../power/wakeup set to "enabled" • For example, GPIOs 0 to 7 on AM335x # cat /sys/devices/platform/gpio_keys/power/wakeup enabled • Hence, pressing the power button wakes the device Linux power management: are you doing it right? 24 Copyright © 2011-2018, 2net Ltd
  • 25. Conclusion • A well configured Linux device will save power • Linux features considered here: • CPUFreq: selects OPP depending on load • CPUIdle: selects idle state based on predicted load • Tickless: eliminates unnecessary timer interrupts • Runtime power management: powers off unused peripherals • Suspend to RAM: puts system in minimum power usage state Linux power management: are you doing it right? 25 Copyright © 2011-2018, 2net Ltd
  • 26. Questions? Further reading: Chapter 11 of Mastering Embedded Linux Programming Contact: Web: www.2net.co.uk Email: training@2net.co.uk LinkedIn: https://uk.linkedin.com/in/chrisdsimmonds Linux power management: are you doing it right? 26 Copyright © 2011-2018, 2net Ltd