Home > Linux, NXP i.MX, Testing > Save Power, Hibernate Your Embedded Linux System

Save Power, Hibernate Your Embedded Linux System

This is a guest post by Tharma Rajan G, Project Lead, e-con Sytems.

What is the best way to save power consumption of your embedded Linux system? Is there any way to save max power and resume operation ? Yes. It is ‘hibernate’ mode, one of the Power Modes in Linux. This article talks about how we utilized this ‘hibernate mode’ in our Reference Platform Kit Meissa-I with eSOMiMX6-micro SOM.

Click to Enlarge

Meissa-I is a dual board solution that features eSOMiMX6-micro Computer on Module & carrier board. Meissa-I development board runs Linux and Android Marshmallow (under development). eSOMiMX6-micro is based on Dual/Quad core ARM CortexTM-A9 based CPU @ 800MHz/Core. It has 1GB LPDDR2 and 4GB eMMC FLASH (expandable upto 32GB). The eSOMiMX6-micro module also has the Wireless LAN and Bluetooth module.

Linux Power Modes

Power Management is a key feature in embedded Linux system and there are two types for implementing the power management on x86 platforms:

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

ACPI is the newer of the two technologies and puts power management in the hands of the operating system, allowing for more intelligent power management than is possible with BIOS controlled APM.

For ARM based systems however, APM/ACPI is not used. Instead power management in ARM Linux System, is implemented using sysfs entries. Following are sysfs entries for power management.

SI.No Sysfs Entry Purpose Notes
1 /sys/power/state
  1. To get supported system sleep states
  2. To set one of the supported system sleep states
Comparing to ACPI, this entry handles System Sleep States (Sx)
2 /sys/devices/system/cpu/cpu0/cpufreq/
  1. To get supported cpufreq governors and current governor for DVFS
  2. To set one of the supported cpufreq governors as current governor
Comparing to ACPI, this entry handles Processor low-power states (Px)
3 /sys/devices/system/cpu/cpuN/online
  1. To check whether CPUN is turned on in SMP (or multi core) system. Here N is not 0 (i.e boot core)
  2. To turn CPUN on/off in SMP (or multi core) system. Here N is not 0 (i.e boot core)
Comparing to ACPI, this entry handles CPU states (Cx)
4 /sys/devices/…/power/wakeup
  1. To set this device as wake up source for waking up the system from one of sleep states.
  2. To check whether this device is wakeup source or not
A wake up source device can not be put in low power states. Other non wake up source devices can be in low-power states.For example,
  1. Debug Serial port as wake up source


2. Ethernet LAN receive data as wake up source


3. RTC alarm as wake up source

5 /sys/class/thermal/thermal_zone0/temp 1. To get the CPU temperature current CPU temp in milli-celcius.
6 /sys/class/thermal/thermal_zone0/trip_point_1_temp 1. To get critical temperature value2. To set critical temperature value when the measured on die temperature exceeds the critical threshold → reboot the system (protection mechanism to prevent damage).
7 /sys/class/thermal/thermal_zone0/trip_point_0_temp 1. To get passive temperature value2. To set passive temperature value The passive trip point is a preventative measure before reaching critical that does things to lower temperature such as reducing cpu/gpu frequencies. The thermal driver works with CPU Freq mechanism

The power management subsystem provides a unified sysfs interface to userspace, regardless of what architecture or platform one is running. Generally sysfs filesystem is mounted in /sys directory and one can see that power management related entries in /sys/power path.


Using the entry /sys/power/state, one can get supported power states (or power modes) of the embedded system. And also one can put that embedded system in one of those supported power states.


System Sleeping States and Description

Sl.No

Label

Description

Alternative name

1

freeze

Will freeze user space process and put all I/O Devices into low-power state.

Make the processors to spend more time in idle state.

Suspend-To-Idle

2

standby

Addition to freeze power mode features , nonboot cpus are put into offline and all low-level system functions are suspended during transition into this state.

None of the operating state is lost ( i.e the cpu retains power ), so the system easily starts up again where it left off.

Power-On Suspend

3

mem

Offer more power savings as everything in the system is put into low power state except RAM, and RAM will be working in self refresh mode to retains its contents.

This mode also supports standby power mode.

Suspend-to-RAM or STR

4

disk

Take a snapshot of current system state and save it into a disk ( i.e swap space ) . While resuming , snapshot image is read and memory is restored to its pre-suspend state.

STD will put the system to the lowest power state.

Suspend-to-Disk or STD or Hibernate

Swap Memory for Hibernate Power Mode

Swap memory

Swap memory is the area on disk that is reserved to be used as extra RAM when your system needs more RAM than what is available. When your embedded Linux system runs out of free memory, then kernel can move some of the inactive pages into swap partition to make free room for active pages in RAM memory. If you plan to use hibernation in your embedded Linux systems, then you swap space have to be at least twice the RAM capacity.

Kernel support for swap memory

Enable swap support in Linux kernel

Click to Enlarge

Test swap memory

  1. To test swap memory, we created a simple test application test_swap_mem which will allocate memory infinitely using malloc() API and fill that allocated memory using memset() API. Let’s have a look at the source code
  2. Before creating swap space, Check whether swap space is enabled using free command
    Here swap total , used and free space is marked as 0 which means swap space in not enabled yet.
  3. Run test_swap_mem application as discussed below

    Let us wait till the application reaches OOM.

    Click to Enlarge

    From the above image, you can observe test_swap_mem allocates maximum of 799MB, after that it reaches OOM and also you can confirm swap space is not used by observing Free swap and Total swap is marked as 0 kB and no swap pages are used

  4. Now let we create a swap memory region and test with the same application. Once you decided about the partition block to be used as swap space , you have to mark that partition block as swap partition.
  5. After marking that specific partition as swap partition , you have to prepare it using mkswap tool
  6. Now your swap space is ready to use , then activate swap partition.
  7. First notice how much swap memory is available and then run test_swap_mem application.
    Here 892892 bytes of swap memory region is available. Try to explore how much swap space is used and when OOM will be reached.

    Click to Enlarge

    Yes , swap memory is utilized. As there is no free memory (including swap) available for allocation, kernel throws OOM error hence kills that test application.

Hibernate – Power Mode

Hibernation power mode saves the system state (i.e all the pages created in RAM memory) to swap space and put the system power down.When the system is powered on, the state is restored (i.e pages are moved from swap to RAM memory). To write the system state to swap space, a mechanism called ‘swsusp’ (Swap Suspend ) is used.

Kernel Configuration for Hibernate mode

Click to Enlarge

Now we will prepare the Swap Space to hold the Hibernation Image.

Setup the swap area,

Enable partition for swapping

Run a process, to verify restoring the hibernation image.

Entering into Hibernate

  1. Enter into hibernation state by executing below command.

Resume from Hibernate

Before starting to resume from hibernate state, append resume=/pathto/swapspace command line parameter to read back hibernate image from that specific swap partition. Let us change the bootargs for hibernate resume state , and run the bootcmd.

Click to Enlarge

Now you will observe, hibernate image is read from swap partition and resumed.

Click to Enlarge

Analysis

Power Measurement Analysis

The power data is obtained by computing the product of voltage and current measured.


Hardware and Software Used:

  1. The software version used for the measurement is
    • U-Boot 2016.03
    • Linux Kernel Version 4.1.15.
    • Yocto Krogoth X11 image.
  2. The board used for the measurement is Meissa-I with eSOMiMX6-micro SOM.
  3. The measurements were performed using Fluke 15B+ Digital Multimeter.

Power Consumption details in tested power modes.

Sl.No

Power Mode

Current

(mA)

Voltage

(V)

Power Consumption

(mW)

Description

1

Active

288

3.3

950

In active state, no peripheral is connected with the MEISSA development board except HDMI monitor , MicroSD card and a debug cable which is connected to the development system.

2

Standby

55

3.3

181.5

In standby mode, all the peripherals will be put into sleep state. ARM core and DDR will be active.

3

Suspend

10

3.3

33

In suspend state, all the peripherals along with ARM core will be put into sleep state. DDR will be put into self refreshing mode.

4

Hibernate

0

3.3

0

In hibernate mode , entire system will be put into low power state.

System Power Consumption Chart

Click to Enlarge

Active Mode Power Consumption

Power Domain

Voltage ( V )

Current Consumption (mA)

Power Calculated (mW)

VCC_SW1AB_CORE

1.3

29

37.7

VCC_SW1C_SOC

1.3

262

340.6

VCC_HIGH_IN

3.1

73

226.3

VCC_LDO5

2.4

10

24

VCC_SW3_LPDDR2

1.1

43

47.3

VCC_LDO4_1P8

1.8

1.96

3.52

VCC_SW_3P3

3.3

24

79.2

VCC_1P2

1.1

62

68.2

VCC_1P8

1.8

0.55

0.99

VCC_WIFI_VBAT

3.3

0

0

Total Power

827.81

Standby Mode Power Consumption:

Power Domain

Voltage ( V )

Current Consumption (mA)

Power Calculated ( mW )

VCC_SW1AB_CORE

1.3

13

16.9

VCC_SW1C_SOC

1.3

11

14.3

VCC_HIGH_IN

3.1

34

105.4

VCC_LDO5

2.4

0.27

0.648

VCC_SW3_LPDDR2

1.1

7

7.7

VCC_LDO4_1P8

1.8

0.38

0.684

VCC_SW_3P3

3.3

0

0

VCC_1P2

1.1

0

0

VCC_1P8

1.8

0.24

0.432

VCC_WIFI_VBAT

3.3

0

0

Total Power

146.064

Suspend Mode Power Consumption:

Power Domain

Voltage ( V )

Current Consumption (mA)

Power Calculated ( mW )

VCC_SW1AB_CORE

0.97

0

0

VCC_SW1C_SOC

0.97

3

2.91

VCC_HIGH_IN

2.9

1.64

4.756

VCC_LDO5

2.4

1

2.4

VCC_SW3_LPDDR2

1.1

6

6.6

VCC_LDO4_1P8

1.8

0.37

0.66

VCC_SW_3P3

3.3

1.32

4.35

VCC_1P2

1.1

0

0

VCC_1P8

1.8

0.85

1.53

VCC_WIFI_VBAT

3.3

0

0

Total Power

23.206

Hibernate mode Power Consumption:

Power Domain

Voltage ( V )

Current Consumption (mA)

Power Calculated ( mW )

VCC_SW1AB_CORE

0

0

0

VCC_SW1C_SOC

0

0

0

VCC_HIGH_IN

0

0

0

VCC_LDO5

0

0

0

VCC_SW3_LPDDR2

0

0

0

VCC_LDO4_1P8

0

0

0

VCC_SW_3P3

0

0

0

VCC_1P2

0

0

0

VCC_1P8

0

0

0

VCC_WIFI_VBAT

0

0

0

Total Power

0

Domain Power Consumption Chart :

Click to Enlarge

Boot Time Analysis

App launch time Measurement in Normal Boot.

We have taken our eSOMiMX6Micro SOM as reference, it takes nearly 19 secs to execute watch command which is part of rc.local script file.

Click to Enlarge

App launch time measurement in Resume Mode.

While resuming from hibernate, it takes 16.76 secs to retain and execute the same watch command process state.

Click to Enlarge

Normal Boot and Hibernation Resume Comparison Chart.

Conclusion

From the above analysis on ‘hibernate mode’, we find it to be the best choice for putting the system in low power state. Also, it consumes minimal time for ‘hibernate resuming’ as compared to normal booting time. The only downside we observed is that, manual interaction was required to resume the device from hibernate mode.
I believe, this hibernate power mode analysis will be very useful to you. We will see you next time with another interesting article.

  1. SlowBro
    August 30th, 2017 at 22:24 | #1

    Thank you very much! What is are the times for sleep and suspend, both sleeping and waking?

  2. xxiao
    August 31st, 2017 at 20:28 | #2

    great and insightful!

  3. September 4th, 2017 at 12:34 | #3

    Hi,
    Power Mode -> /
    Time Detail ↓ Suspend Standby Hibernate
    Time for Entering 0.4 Secs 0.6 Secs 30 Secs
    Time for Resuming 2.2 Secs 2.4 Secs 16 Secs

    Hope this helps! Would love to hear more of your thoughts.

    Regards,
    Suganthi , e-con Systems

  4. SlowBro
    September 24th, 2017 at 15:10 | #4

    @Suganthi
    Grateful!

  1. No trackbacks yet.