SlideShare uma empresa Scribd logo
1 de 50
Baixar para ler offline
Jerrin Shaji George
• Concept
• Linux Power Management
• Android Power Management Design
• Wake Locks
• System Sleep (Suspend)
• Battery Service
• Designed for mobile devices
• Goal is to prolong battery life
• Build on top of Linux Power Management
  o Not directly suitable for a mobile device

• Designed for devices which have a 'default-off' behaviour
  o The phone is not supposed to be on when we do not want to use it

  o Powered on only when requested to be run, off by default

  o Unlike PC, which has a default on behaviour
Two popular power management standards

1.   APM (Advanced Power Management)
2.   ACPI (Advanced Configuration and Power Interface)
APM


 • Control resides in BIOS
 • Uses activity timeouts to determine when to power down a device
 • BIOS rarely used in embedded systems
 • Makes power-management decisions without informing OS or
  individual applications

 • No knowledge of add-in cards or new devices
APM


 • Uses layered approach to
  manage devices

 • APM-aware applications
  (including device drivers)
  talk to an OS-specific
  APM driver

 • The driver communicates
  to the APM-aware BIOS,
  which controls the
  hardware
APM


 • Communication occurs in
  both directions; power
  management events are
  sent from the BIOS to the
  APM driver, and the APM
  driver sends information
  and requests to the BIOS
  via function calls

 • In this way the APM
  driver is an intermediary
  between the BIOS and
  the operating system
APM

 • Power management
  happens in two ways;
  through function calls
  from the APM driver to
  the BIOS requesting
  power state changes, and
  automatically based on
  device activity
APM
ACPI

  • Control divided between BIOS and OS
  • Decisions managed through the OS
  • Enables sophisticated power policies for general-purpose
   computers with standard usage patterns and hardware

  • No knowledge of device-specific scenarios (e.g. need to provide
   predictable response times or to respond to critical events over
   extended period)
ACPI

ACPI specification defines the following four Global ‘Gx’ states and six
Sleep ‘Sx’ states for an ACPI-compliant computer-system:

  • G0 (S0)
       oWorking
       o‘Awaymode’ is a subset of S0, where monitor is off but background
        tasks are running
ACPI

  • G1, Sleeping, subdivides into the four states S1 through S4:
       o S1 : All processor caches are flushed, and the CPU(s) stop executing
         instructions. Power to the CPU(s) and RAM is maintained; devices that
         do not indicate they must remain on may be powered down

       o S2: CPU powered off. Dirty cache is flushed to RAM

       o S3(mem): Commonly referred to as Standby, Sleep, or Suspend to RAM.
         RAM remains powered

       o S4: Hibernation/Suspend-to-Disk - All content of main memory is
         saved to non-volatile memory such as a hard drive, and is powered
         down
ACPI

  • G2 (S5), Soft Off
  • G3, Mechanical Off
       oThe computer's power has been totally removed via a mechanical
        switch
  • Legacy State : The state on an operating system which does not
   support ACPI. In this state, the hardware and power are not
   managed via ACPI, effectively disabling ACPI.
ACPI
•   Power mode interface is on sysfs
      o   /sys/power/state


•   sysfs is a virtual file system provided by Linux. sysfs exports
    information about devices and drivers from the kernel device
    model to user space, and is also used for configuration

•   Changing state done by
      o # echo mem > /sys/power/state
      o # echo disk > /sys/power/state
      o # echo standby > /sys/power/state
Overview
•   Built as a wrapper to Linux Power Management
•   In the Kernel
      o   Added 'on' state in the power state
      o   Added Early Suspend framework
      o   Added Partial Wake Lock mechanism

•   Apps and services must request CPU resource with ‘wake locks’
    through the Android application framework and native Linux
    libraries in order to keep power on, otherwise Android will shut
    down the CPU
•   Android PM uses wake locks and time out mechanism to switch state
    of system power, so that system power consumption decreases
•   By default, Android tries to put the system into a sleep or better a
    suspend mode as soon as possible

•   Applications running in the Dalvik VM can prevent the system from
    entering a sleep or suspend state, i.e. applications can assure that
    the screen stays on or the CPU stays awake to react quickly to
    interrupts

•   The means Android provides for this task is wake locks

•   If there are no active wake locks, CPU will be turned off

•   If there are partial wake locks, screen and keyboard will be turned
    off
Types of Wake Locks
•   PARTIAL_WAKE_LOCK
     o   Ensures that the CPU is running
     o   The screen might not be on
•   SCREEN_DIM_WAKE_LOCK
     o   Wake lock that ensures that the screen is on, but the keyboard backlight
         will be allowed to go off, and the screen backlight will be allowed to go
         dim
•   SCREEN_BRIGHT_WAKE_LOCK
     o   Wake lock that ensures that the screen is on at full brightness; the
         keyboard backlight will be allowed to go off
•   FULL_WAKE_LOCK
     o   Full device ON, including backlight and screen
• Android implements an application framework on top of the
 kernel called Android Power Management Applications
 Framework
• The Android PM Framework is like a driver. It is written in Java
 which connects to Android power driver through JNI
• Currently Android only supports screen, keyboard, buttons
 backlight, and the brightness of screen
Through the framework, user space applications can use
‘PowerManger’ class to control the power state of the device
Green - Native
Blue - Java
Red   - Kernel
Touchscreen or keyboard user activity
     event or full wake locks acquired




                   AWAKE




                                    NOTIFI
SLEEP                               CATION
          All partial wake locks
                 released

                           Partial Wake Lock Acquired
• When a user application acquire full wake lock or
 screen/keyboard touch activity event occur, the machine will
 enter ‘AWAKE’ state
• If timeout happens or power key is pressed, the machine will
 enters ‘NOTIFICATION’ state
    oIf partial wake locks are acquired, it will remain in ‘NOTIFICATION’
    oIf all partial locks are released, the machine will go into ‘SLEEP’
• Android PM Framework provides a service for user space
 applications through the class PowerManger to achieve power
 saving
• The flow of exploring Wake locks are :
  o Acquire handle to the PowerManager service by calling
    Context.getSystemService()
  o Create a wake lock and specify the power management flags for
    screen, timeout, etc.
  o Acquire wake lock
  o Perform operation such as play MP3
  o Release wake lock
• Used to prevent system from entering suspend or low-power-
 state
• Partial Wake Lock behaviour
• Can be acquired/released from Native apps through Power.c
 interface
• Can be acquired/released internally from kernel
How are Wake Locks Managed
•       Wake Locks are mainly managed in Java layer
•       When an android application takes a wake lock, a new instance of
        wake lock is registered in the PowerManagerService
    o     PowerManagerService is running in the java layer
•       Registered wake locks are put in a list
How are Wake Locks Managed
• A Single Partial Wake Lock in Kernel is needed to protect multiple
 instance of Partial Wake Locks in Java
  oIt is taken on behalf of PowerManagerService class with the name
    PowerManagerService

• Other wake lock residing in kernel side are either from Native code
 via Power.c API or taken internally in the Kernel
  o E.g. Partial wake lock for keyboard

• There is one main wake lock called ‘main’ in the kernel to keep the
 kernel awake

• It will be the last wake lock to be released when system goes to
 suspend
How are Wake Locks Managed



WakeLock in
 Java layer




WakeLock
in Kernel
Working
• By default, a time out is set to off the screen
• If FULL_WAKE_LOCK or SCREEN_BRIGHT_WAKE_LOCK has been taken,
 when a request comes to the system to go to sleep, the system does
 not go to sleep
• If no locks are currently being taken, request is sent through JNI to
 suspend the device
Special behaviour of Partial Wake Lock
• PARTIAL_WAKE_LOCK is maintained in the kernel, not in Java
• When a PARTIAL_WAKE_LOCK in Java layer is taken, internally in the
 Kernel a PARTIAL_WAKE_LOCK is taken
• All of the PARTIAL_WAKE_LOCK in the Java layer is protected by one
 wake lock in the Kernel
• What is it used for ?
   o If a PARTIAL_WAKE_LOCK has been take in java, when system tries to go
     to sleep, the android will ask the kernel to go to sleep
   o But kernel will check if a PARTIAL_WAKE_LOCK has been taken. If so it
     will not suspend the CPU
   o CPU could run at a reduced frequency/low power mode for running the
     background app
Special behaviour of Partial Wake Lock
• EG : Audio playback
     o When an audio is played, the audio handler, like an ALSA driver, will
       take a wake lock in the kernel
     o So whenever the device is turned off, we can still hear the audio
       because the kernel never fully suspend the audio processing
The flow when a Wake Lock is acquired



• Request sent to PowerManager to acquire a wake lock
• PowerManagerService to take a wake lock
• Add wake lock to the list
• Set the power state
    o   For a FULL_WAKE_LOCK, PowerState would be set to ON

• For taking Partial wake lock, if it is the first partial wake
  lock, a kernel wake lock is taken. This will protect all the
  partial wake locks. For subsequent requests, kernel wake
  lock is not taken, but just added to the list
The flow when a Wake Lock is acquired
The flow when a Wake Lock is released


• Request to release wake lock sent to PowerManager
• Wake Lock removed from the list
• For PARTIAL_WAKE_LOCK release, if the wake lock to be
  released is the last PARTIAL_WAKE_LOCK,
  PowerManagerService will also release the wake lock in
  the kernel. Will bring kernel to suspend
• setPowerState
   o If it is the last wake lock, power state will be set to
      mem, which will bring the device to standby
The flow when a Wake Lock is released
•   Extension of Linux Power Management Suspend Hooks
•   Used by drivers that need to handle power mode settings to the
    device before kernel is suspended
•   Used to turn off screen and non-wakeup source input devices
•   Any driver can register its own early suspend and late_resume
    handler using register_early_suspend() API
•   Unregistration is done using unregister_early_suspend() API
•   When the system is brought to suspend mode, early suspend is
    called first. Depending on how the early suspend hook is
    implemented, various things can be done
•   For e.g. consider a display driver
    o In early suspend, the screen can be turned off
    o In the suspend, other things like closing the driver can be done

• When system is resumed, resume is called first, followed by
    resume late
• API to bring device to sleep when we press the power button
• Require DEVICE_POWER permission
• Can only be called in system process context by verifying uid
 and pid
• When power button is presed, an API goToSleep() is called in
 the PowerManager
• goToSleep() will force release all wake locks
• When force releasing all locks, power state will be set to off
• In the JNI bridge there is a function setScreenState.
 setScreenState is set to off
• Then setPowerState to mem, ie write a mem to
 /sys/power/state
• The BatteryService monitors the battery status, level,
 temperature etc.
• A Battery Driver in the kernel interacts with the physical
 battery via ADC [to read battery voltage] and I²C ( Inter-
 Integrated Circuit: a multi-master serial single-ended
 computer bus used to attach low-speed peripherals to an
 electronic device)
• Whenever BatteryService receives information from the
 BatteryDriver, it will act accordingly
 E.g. if battery level is low, it will ask system to shutdown
•   Using power supply class in Linux Kernel
        /sys/class/power_supply
•   Utilize uevent mechanism to update battery status
•   uevent : An asynchronous communication channel for kernel
•   Battery Service will monitor the battery status based on
    received uevent from the kernel
• Android Power Management Hacks, Slow Boot
• Power Management from Linux Kernel to Android, Matt Hsu &
 Jim Huang, 0xlab

• Analysis of the Android Architecture. Stefan Brahler

Mais conteúdo relacionado

Mais procurados

A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)Siji Sunny
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting SequenceJayanta Ghoshal
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Opersys inc.
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewYu-Hsin Hung
 
Android Automotive
Android AutomotiveAndroid Automotive
Android AutomotiveOpersys inc.
 
Android Binder IPC for Linux
Android Binder IPC for LinuxAndroid Binder IPC for Linux
Android Binder IPC for LinuxYu-Hsin Hung
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security InternalsOpersys inc.
 
Linux booting process!!
Linux booting process!!Linux booting process!!
Linux booting process!!sourav verma
 
Understaing Android EGL
Understaing Android EGLUnderstaing Android EGL
Understaing Android EGLSuhan Lee
 
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...The Linux Foundation
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debuggingUtkarsh Mankad
 

Mais procurados (20)

A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)A deep dive into Android OpenSource Project(AOSP)
A deep dive into Android OpenSource Project(AOSP)
 
Deep Dive into the AOSP
Deep Dive into the AOSPDeep Dive into the AOSP
Deep Dive into the AOSP
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Low Level View of Android System Architecture
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System Architecture
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture Overview
 
Android Automotive
Android AutomotiveAndroid Automotive
Android Automotive
 
Android Binder IPC for Linux
Android Binder IPC for LinuxAndroid Binder IPC for Linux
Android Binder IPC for Linux
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security Internals
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Linux booting process!!
Linux booting process!!Linux booting process!!
Linux booting process!!
 
Understaing Android EGL
Understaing Android EGLUnderstaing Android EGL
Understaing Android EGL
 
Windows kernel
Windows kernelWindows kernel
Windows kernel
 
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
XPDS13: Xen in OSS based In–Vehicle Infotainment Systems - Artem Mygaiev, Glo...
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 

Semelhante a Linux and Android Power Management Design

Hibernation in Linux 2.6.29
Hibernation in Linux 2.6.29Hibernation in Linux 2.6.29
Hibernation in Linux 2.6.29Varun Mahajan
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?Chris Simmonds
 
Digital computer Basics by, Er. Swapnil Kaware
Digital computer Basics by, Er. Swapnil KawareDigital computer Basics by, Er. Swapnil Kaware
Digital computer Basics by, Er. Swapnil KawareProf. Swapnil V. Kaware
 
S6 EEE MPLC FULL NOTE.pdf subject in electrical and electronics engineering
S6 EEE MPLC FULL NOTE.pdf subject in electrical and electronics engineeringS6 EEE MPLC FULL NOTE.pdf subject in electrical and electronics engineering
S6 EEE MPLC FULL NOTE.pdf subject in electrical and electronics engineeringAbinjohnson15
 
BKK16-502 Suspend to Idle
BKK16-502 Suspend to IdleBKK16-502 Suspend to Idle
BKK16-502 Suspend to IdleLinaro
 
A deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processorA deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processorZongYing Lyu
 
Linux synchronization tools
Linux synchronization toolsLinux synchronization tools
Linux synchronization toolsmukul bhardwaj
 
computer system structure
computer system structurecomputer system structure
computer system structureHAMZA AHMED
 
1 introduction
1 introduction1 introduction
1 introductionMohd Arif
 
The central processing unit by group 5 2015
The central processing unit by group 5 2015The central processing unit by group 5 2015
The central processing unit by group 5 2015Tendai Karuma
 
Dan Norris: Exadata security
Dan Norris: Exadata securityDan Norris: Exadata security
Dan Norris: Exadata securityKyle Hailey
 
Locked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernelLocked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernelSUSE Labs Taipei
 

Semelhante a Linux and Android Power Management Design (20)

Hibernation in Linux 2.6.29
Hibernation in Linux 2.6.29Hibernation in Linux 2.6.29
Hibernation in Linux 2.6.29
 
Linux_swspnd_v0.3_pub1
Linux_swspnd_v0.3_pub1Linux_swspnd_v0.3_pub1
Linux_swspnd_v0.3_pub1
 
Power management android
Power management androidPower management android
Power management android
 
Introduction to OS.
Introduction to OS.Introduction to OS.
Introduction to OS.
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?
 
Digital computer Basics by, Er. Swapnil Kaware
Digital computer Basics by, Er. Swapnil KawareDigital computer Basics by, Er. Swapnil Kaware
Digital computer Basics by, Er. Swapnil Kaware
 
S6 EEE MPLC FULL NOTE.pdf subject in electrical and electronics engineering
S6 EEE MPLC FULL NOTE.pdf subject in electrical and electronics engineeringS6 EEE MPLC FULL NOTE.pdf subject in electrical and electronics engineering
S6 EEE MPLC FULL NOTE.pdf subject in electrical and electronics engineering
 
BKK16-502 Suspend to Idle
BKK16-502 Suspend to IdleBKK16-502 Suspend to Idle
BKK16-502 Suspend to Idle
 
A deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processorA deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processor
 
Linux synchronization tools
Linux synchronization toolsLinux synchronization tools
Linux synchronization tools
 
computer system structure
computer system structurecomputer system structure
computer system structure
 
1 introduction
1 introduction1 introduction
1 introduction
 
ITE7_Chp3.pptx
ITE7_Chp3.pptxITE7_Chp3.pptx
ITE7_Chp3.pptx
 
2 srs
2 srs2 srs
2 srs
 
The central processing unit by group 5 2015
The central processing unit by group 5 2015The central processing unit by group 5 2015
The central processing unit by group 5 2015
 
Dan Norris: Exadata security
Dan Norris: Exadata securityDan Norris: Exadata security
Dan Norris: Exadata security
 
Techno-Fest-15nov16
Techno-Fest-15nov16Techno-Fest-15nov16
Techno-Fest-15nov16
 
Virtualization Basics
Virtualization BasicsVirtualization Basics
Virtualization Basics
 
Locked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernelLocked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernel
 
1_to_10.pdf
1_to_10.pdf1_to_10.pdf
1_to_10.pdf
 

Último

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Último (20)

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Linux and Android Power Management Design

  • 2. • Concept • Linux Power Management • Android Power Management Design • Wake Locks • System Sleep (Suspend) • Battery Service
  • 3. • Designed for mobile devices • Goal is to prolong battery life • Build on top of Linux Power Management o Not directly suitable for a mobile device • Designed for devices which have a 'default-off' behaviour o The phone is not supposed to be on when we do not want to use it o Powered on only when requested to be run, off by default o Unlike PC, which has a default on behaviour
  • 4. Two popular power management standards 1. APM (Advanced Power Management) 2. ACPI (Advanced Configuration and Power Interface)
  • 5. APM • Control resides in BIOS • Uses activity timeouts to determine when to power down a device • BIOS rarely used in embedded systems • Makes power-management decisions without informing OS or individual applications • No knowledge of add-in cards or new devices
  • 6. APM • Uses layered approach to manage devices • APM-aware applications (including device drivers) talk to an OS-specific APM driver • The driver communicates to the APM-aware BIOS, which controls the hardware
  • 7. APM • Communication occurs in both directions; power management events are sent from the BIOS to the APM driver, and the APM driver sends information and requests to the BIOS via function calls • In this way the APM driver is an intermediary between the BIOS and the operating system
  • 8. APM • Power management happens in two ways; through function calls from the APM driver to the BIOS requesting power state changes, and automatically based on device activity
  • 9. APM
  • 10. ACPI • Control divided between BIOS and OS • Decisions managed through the OS • Enables sophisticated power policies for general-purpose computers with standard usage patterns and hardware • No knowledge of device-specific scenarios (e.g. need to provide predictable response times or to respond to critical events over extended period)
  • 11. ACPI ACPI specification defines the following four Global ‘Gx’ states and six Sleep ‘Sx’ states for an ACPI-compliant computer-system: • G0 (S0) oWorking o‘Awaymode’ is a subset of S0, where monitor is off but background tasks are running
  • 12. ACPI • G1, Sleeping, subdivides into the four states S1 through S4: o S1 : All processor caches are flushed, and the CPU(s) stop executing instructions. Power to the CPU(s) and RAM is maintained; devices that do not indicate they must remain on may be powered down o S2: CPU powered off. Dirty cache is flushed to RAM o S3(mem): Commonly referred to as Standby, Sleep, or Suspend to RAM. RAM remains powered o S4: Hibernation/Suspend-to-Disk - All content of main memory is saved to non-volatile memory such as a hard drive, and is powered down
  • 13. ACPI • G2 (S5), Soft Off • G3, Mechanical Off oThe computer's power has been totally removed via a mechanical switch • Legacy State : The state on an operating system which does not support ACPI. In this state, the hardware and power are not managed via ACPI, effectively disabling ACPI.
  • 14. ACPI
  • 15. Power mode interface is on sysfs o /sys/power/state • sysfs is a virtual file system provided by Linux. sysfs exports information about devices and drivers from the kernel device model to user space, and is also used for configuration • Changing state done by o # echo mem > /sys/power/state o # echo disk > /sys/power/state o # echo standby > /sys/power/state
  • 17. Built as a wrapper to Linux Power Management • In the Kernel o Added 'on' state in the power state o Added Early Suspend framework o Added Partial Wake Lock mechanism • Apps and services must request CPU resource with ‘wake locks’ through the Android application framework and native Linux libraries in order to keep power on, otherwise Android will shut down the CPU • Android PM uses wake locks and time out mechanism to switch state of system power, so that system power consumption decreases
  • 18. By default, Android tries to put the system into a sleep or better a suspend mode as soon as possible • Applications running in the Dalvik VM can prevent the system from entering a sleep or suspend state, i.e. applications can assure that the screen stays on or the CPU stays awake to react quickly to interrupts • The means Android provides for this task is wake locks • If there are no active wake locks, CPU will be turned off • If there are partial wake locks, screen and keyboard will be turned off
  • 19. Types of Wake Locks • PARTIAL_WAKE_LOCK o Ensures that the CPU is running o The screen might not be on • SCREEN_DIM_WAKE_LOCK o Wake lock that ensures that the screen is on, but the keyboard backlight will be allowed to go off, and the screen backlight will be allowed to go dim • SCREEN_BRIGHT_WAKE_LOCK o Wake lock that ensures that the screen is on at full brightness; the keyboard backlight will be allowed to go off • FULL_WAKE_LOCK o Full device ON, including backlight and screen
  • 20. • Android implements an application framework on top of the kernel called Android Power Management Applications Framework • The Android PM Framework is like a driver. It is written in Java which connects to Android power driver through JNI • Currently Android only supports screen, keyboard, buttons backlight, and the brightness of screen
  • 21. Through the framework, user space applications can use ‘PowerManger’ class to control the power state of the device
  • 22. Green - Native Blue - Java Red - Kernel
  • 23. Touchscreen or keyboard user activity event or full wake locks acquired AWAKE NOTIFI SLEEP CATION All partial wake locks released Partial Wake Lock Acquired
  • 24. • When a user application acquire full wake lock or screen/keyboard touch activity event occur, the machine will enter ‘AWAKE’ state • If timeout happens or power key is pressed, the machine will enters ‘NOTIFICATION’ state oIf partial wake locks are acquired, it will remain in ‘NOTIFICATION’ oIf all partial locks are released, the machine will go into ‘SLEEP’
  • 25. • Android PM Framework provides a service for user space applications through the class PowerManger to achieve power saving • The flow of exploring Wake locks are : o Acquire handle to the PowerManager service by calling Context.getSystemService() o Create a wake lock and specify the power management flags for screen, timeout, etc. o Acquire wake lock o Perform operation such as play MP3 o Release wake lock
  • 26. • Used to prevent system from entering suspend or low-power- state • Partial Wake Lock behaviour • Can be acquired/released from Native apps through Power.c interface • Can be acquired/released internally from kernel
  • 27. How are Wake Locks Managed • Wake Locks are mainly managed in Java layer • When an android application takes a wake lock, a new instance of wake lock is registered in the PowerManagerService o PowerManagerService is running in the java layer • Registered wake locks are put in a list
  • 28. How are Wake Locks Managed • A Single Partial Wake Lock in Kernel is needed to protect multiple instance of Partial Wake Locks in Java oIt is taken on behalf of PowerManagerService class with the name PowerManagerService • Other wake lock residing in kernel side are either from Native code via Power.c API or taken internally in the Kernel o E.g. Partial wake lock for keyboard • There is one main wake lock called ‘main’ in the kernel to keep the kernel awake • It will be the last wake lock to be released when system goes to suspend
  • 29. How are Wake Locks Managed WakeLock in Java layer WakeLock in Kernel
  • 30. Working • By default, a time out is set to off the screen • If FULL_WAKE_LOCK or SCREEN_BRIGHT_WAKE_LOCK has been taken, when a request comes to the system to go to sleep, the system does not go to sleep • If no locks are currently being taken, request is sent through JNI to suspend the device
  • 31. Special behaviour of Partial Wake Lock • PARTIAL_WAKE_LOCK is maintained in the kernel, not in Java • When a PARTIAL_WAKE_LOCK in Java layer is taken, internally in the Kernel a PARTIAL_WAKE_LOCK is taken • All of the PARTIAL_WAKE_LOCK in the Java layer is protected by one wake lock in the Kernel • What is it used for ? o If a PARTIAL_WAKE_LOCK has been take in java, when system tries to go to sleep, the android will ask the kernel to go to sleep o But kernel will check if a PARTIAL_WAKE_LOCK has been taken. If so it will not suspend the CPU o CPU could run at a reduced frequency/low power mode for running the background app
  • 32. Special behaviour of Partial Wake Lock • EG : Audio playback o When an audio is played, the audio handler, like an ALSA driver, will take a wake lock in the kernel o So whenever the device is turned off, we can still hear the audio because the kernel never fully suspend the audio processing
  • 33.
  • 34. The flow when a Wake Lock is acquired • Request sent to PowerManager to acquire a wake lock • PowerManagerService to take a wake lock • Add wake lock to the list • Set the power state o For a FULL_WAKE_LOCK, PowerState would be set to ON • For taking Partial wake lock, if it is the first partial wake lock, a kernel wake lock is taken. This will protect all the partial wake locks. For subsequent requests, kernel wake lock is not taken, but just added to the list
  • 35. The flow when a Wake Lock is acquired
  • 36. The flow when a Wake Lock is released • Request to release wake lock sent to PowerManager • Wake Lock removed from the list • For PARTIAL_WAKE_LOCK release, if the wake lock to be released is the last PARTIAL_WAKE_LOCK, PowerManagerService will also release the wake lock in the kernel. Will bring kernel to suspend • setPowerState o If it is the last wake lock, power state will be set to mem, which will bring the device to standby
  • 37. The flow when a Wake Lock is released
  • 38. Extension of Linux Power Management Suspend Hooks • Used by drivers that need to handle power mode settings to the device before kernel is suspended • Used to turn off screen and non-wakeup source input devices • Any driver can register its own early suspend and late_resume handler using register_early_suspend() API • Unregistration is done using unregister_early_suspend() API • When the system is brought to suspend mode, early suspend is called first. Depending on how the early suspend hook is implemented, various things can be done
  • 39.
  • 40. For e.g. consider a display driver o In early suspend, the screen can be turned off o In the suspend, other things like closing the driver can be done • When system is resumed, resume is called first, followed by resume late
  • 41.
  • 42.
  • 43. • API to bring device to sleep when we press the power button • Require DEVICE_POWER permission • Can only be called in system process context by verifying uid and pid • When power button is presed, an API goToSleep() is called in the PowerManager
  • 44. • goToSleep() will force release all wake locks • When force releasing all locks, power state will be set to off • In the JNI bridge there is a function setScreenState. setScreenState is set to off • Then setPowerState to mem, ie write a mem to /sys/power/state
  • 45.
  • 46. • The BatteryService monitors the battery status, level, temperature etc. • A Battery Driver in the kernel interacts with the physical battery via ADC [to read battery voltage] and I²C ( Inter- Integrated Circuit: a multi-master serial single-ended computer bus used to attach low-speed peripherals to an electronic device) • Whenever BatteryService receives information from the BatteryDriver, it will act accordingly E.g. if battery level is low, it will ask system to shutdown
  • 47. Using power supply class in Linux Kernel /sys/class/power_supply • Utilize uevent mechanism to update battery status • uevent : An asynchronous communication channel for kernel • Battery Service will monitor the battery status based on received uevent from the kernel
  • 48.
  • 49.
  • 50. • Android Power Management Hacks, Slow Boot • Power Management from Linux Kernel to Android, Matt Hsu & Jim Huang, 0xlab • Analysis of the Android Architecture. Stefan Brahler