SlideShare a Scribd company logo
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

PDF
Kdump and the kernel crash dump analysis
PDF
USB Drivers
PDF
Power Management from Linux Kernel to Android
PPT
Kernel module programming
PDF
LCU13: An Introduction to ARM Trusted Firmware
PDF
AndroidとSELinux
PPTX
Introduction Linux Device Drivers
PDF
U-Boot - An universal bootloader
Kdump and the kernel crash dump analysis
USB Drivers
Power Management from Linux Kernel to Android
Kernel module programming
LCU13: An Introduction to ARM Trusted Firmware
AndroidとSELinux
Introduction Linux Device Drivers
U-Boot - An universal bootloader

What's hot (20)

PDF
Embedded_Linux_Booting
PDF
systemd
PDF
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
PPTX
Linux Memory Management
PPTX
Linux Kernel Booting Process (1) - For NLKB
PDF
Android Boot Time Optimization
PDF
Anatomy of the loadable kernel module (lkm)
PDF
Uboot startup sequence
PDF
Embedded Linux BSP Training (Intro)
PDF
Arm device tree and linux device drivers
PDF
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
PPT
U Boot or Universal Bootloader
PPTX
Linux Usb overview
PPTX
RISC-V Boot Process: One Step at a Time
PDF
LCU14 500 ARM Trusted Firmware
PDF
malloc & vmalloc in Linux
PPTX
Linux Initialization Process (2)
PPT
U boot porting guide for SoC
PDF
ARM Trusted FirmwareのBL31を単体で使う!
PDF
강좌 01 ARM 프로세서 개요
Embedded_Linux_Booting
systemd
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
Linux Memory Management
Linux Kernel Booting Process (1) - For NLKB
Android Boot Time Optimization
Anatomy of the loadable kernel module (lkm)
Uboot startup sequence
Embedded Linux BSP Training (Intro)
Arm device tree and linux device drivers
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
U Boot or Universal Bootloader
Linux Usb overview
RISC-V Boot Process: One Step at a Time
LCU14 500 ARM Trusted Firmware
malloc & vmalloc in Linux
Linux Initialization Process (2)
U boot porting guide for SoC
ARM Trusted FirmwareのBL31を単体で使う!
강좌 01 ARM 프로세서 개요
Ad

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

ODP
Optimizing Linux Servers
PDF
OS Lecture 01 Introductiodg (Slides).pdf
PDF
operating system S6 ktu physics and computer application
PDF
Ch4 memory management
PPTX
Insider operating system
PPTX
Computer system architecture
PPT
Module 1 Introduction.ppt
PDF
linux monitoring and performance tunning
PDF
Session 7362 Handout 427 0
PDF
Virtualization Basics
PDF
MK Sistem Operasi.pdf
PDF
Introduction to Operating Systems.pdf
PDF
1 introduction
PPTX
Engg chapter one which shows that how it works
PPT
Basics of micro controllers for biginners
PPTX
UNIT 3 - General Purpose Processors
PPT
Considerations when implementing_ha_in_dmf
PPTX
Operating System introduction topics for beginners
PPTX
Operating Systems Module 1 Session 1.pptx
PPTX
Operating System Unit 1
Optimizing Linux Servers
OS Lecture 01 Introductiodg (Slides).pdf
operating system S6 ktu physics and computer application
Ch4 memory management
Insider operating system
Computer system architecture
Module 1 Introduction.ppt
linux monitoring and performance tunning
Session 7362 Handout 427 0
Virtualization Basics
MK Sistem Operasi.pdf
Introduction to Operating Systems.pdf
1 introduction
Engg chapter one which shows that how it works
Basics of micro controllers for biginners
UNIT 3 - General Purpose Processors
Considerations when implementing_ha_in_dmf
Operating System introduction topics for beginners
Operating Systems Module 1 Session 1.pptx
Operating System Unit 1
Ad

More from Chris Simmonds (20)

PDF
Debugging embedded devices using GDB
PDF
Debian or Yocto Project? Which is the best for your Embedded Linux project?
PDF
Embedded Linux Quick Start Guide v1.5
PDF
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
PDF
Reducing the boot time of Linux devices
PDF
Android rpi-csimmonds-fosdem-2019
PDF
Reducing boot time in embedded Linux
PDF
Embedded Android: Android beyond the smartphone
PDF
Software update for IoT Embedded World 2017
PDF
Quick and Easy Device Drivers for Embedded Linux Using UIO
PDF
Software update for IoT: the current state of play
PDF
Read-only rootfs: theory and practice
PDF
Android beyond the smartphone
PDF
10 ways hardware engineers can make software integration easier
PDF
Userspace drivers-2016
PDF
The end of embedded Linux (as we know it)
PDF
Linux field-update-2015
PDF
Tuning Android for low RAM
PDF
The Android graphics path, in depth
PDF
Booting Android: bootloaders, fastboot and boot images
Debugging embedded devices using GDB
Debian or Yocto Project? Which is the best for your Embedded Linux project?
Embedded Linux Quick Start Guide v1.5
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Reducing the boot time of Linux devices
Android rpi-csimmonds-fosdem-2019
Reducing boot time in embedded Linux
Embedded Android: Android beyond the smartphone
Software update for IoT Embedded World 2017
Quick and Easy Device Drivers for Embedded Linux Using UIO
Software update for IoT: the current state of play
Read-only rootfs: theory and practice
Android beyond the smartphone
10 ways hardware engineers can make software integration easier
Userspace drivers-2016
The end of embedded Linux (as we know it)
Linux field-update-2015
Tuning Android for low RAM
The Android graphics path, in depth
Booting Android: bootloaders, fastboot and boot images

Recently uploaded (20)

PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
AI in Product Development-omnex systems
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Digital Strategies for Manufacturing Companies
PDF
System and Network Administraation Chapter 3
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
history of c programming in notes for students .pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Nekopoi APK 2025 free lastest update
PTS Company Brochure 2025 (1).pdf.......
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How to Choose the Right IT Partner for Your Business in Malaysia
Online Work Permit System for Fast Permit Processing
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Design an Analysis of Algorithms II-SECS-1021-03
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
AI in Product Development-omnex systems
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Digital Strategies for Manufacturing Companies
System and Network Administraation Chapter 3
Odoo POS Development Services by CandidRoot Solutions
history of c programming in notes for students .pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
top salesforce developer skills in 2025.pdf
Softaken Excel to vCard Converter Software.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Nekopoi APK 2025 free lastest update

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