Linux driver Power management standard Linux hibernation and wake-up mechanism analysis (i)

Source: Internet
Author: User

1. Based on linux2.6.32, only for Mem (SDR)

2. Please refer to read: Power management solution APM and ACPI comparison. doc

Introduction to hibernation and wake-up of Linux systems. doc

3. This article first studies the sleep and wake-up of Standard Linux, and Android's modification of this part is discussed in another article

4. Based on a project on the hand to discuss, here only to discuss the common place

While Linux supports three power-down modes: Standby, suspend to RAM, suspend to disk, almost all scenarios on battery-powered handheld devices support only STR mode (and also support standby mode). Because the STD mode requires the support of the swap partition, but like the handset class embedded device, they generally use NAND to store the data and the code, and it uses the file system yaffs generally does not divide the swap partition, therefore the handset class device Linux does not support the STD power saving mode.

First, the project power-related configuration

Currently, the Linux power management scheme for my project is configured as follows, and the. config file can, of course, be configured using the Make Menuconfig graphically:

#

# CPU Power Management

#

# Config_cpu_idle is not set

#

# Power Management options

#

Config_pm=y

# Config_pm_debug is not set

Config_pm_sleep=y

Config_suspend=y

Config_suspend_freezer=y

Config_has_wakelock=y

Config_has_earlysuspend=y

Config_wakelock=y

Config_wakelock_stat=y

Config_user_wakelock=y

Config_earlysuspend=y

# Config_no_user_space_screen_access_control is not set

# Config_console_earlysuspend is not set

Config_fb_earlysuspend=y

# config_apm_emulation is not set

# Config_pm_runtime is not set

Config_arch_suspend_possible=y

Config_net=y

The above configuration corresponds to the bottom half of the graphical configuration ... , it appears that the option to configure STD mode is removed directly from the Kconfig file.

Using the above configuration compiled system, after running, into the SYS directory can see the relevant interface:

# pwd

/sys/power

# ls

State Wake_lock Wake_unlock Wait_for_fb_sleep Wait_for_fb_wake

# Cat State

Mem

If the macro Config_pm_debug is configured, then a pm_test file is added to the Power directory, and after the cat pm_test, the test options listed are: [None] core processors platform devices Freezer. For the use of this test mode, refer to the kernel documentation:/kernel/documentation/power/basic-pm-debugging.txt

I also have detailed reading and analysis of this document.

Second, Sys/power and related properties file creation

When the system bootup new power and related properties files under SYS, the relevant source location:

Kernel/kernel/power/main.c

static int __init pm_init (void)

{

int error = Pm_start_workqueue ();//Config_pm_runtime not set

if (Error)

return error;

Power_kobj = Kobject_create_and_add ("Power", NULL);

Establish the Kobject and Sysfs_dirent objects for power, while establishing a contact: KOBJECT.SD =

&sysfs_dirent, sysfs_dirent.s_dir->kobj = &kobject.

if (!power_kobj)

Return-enomem;

Return Sysfs_create_group (Power_kobj, &attr_group);

Set up a set of properties files, you can set up a subdirectory under power to hold these properties files,//But you need to specify name in the struct attr_group, otherwise directly put these property files in//power_kobj corresponding directory.

}

Core_initcall (Pm_init); See, the function is very early called, Initcall Level 1

static struct Attribute_group Attr_group = {

. Attrs = g,

};

struct Attribute_group {

const char *name;

mode_t (*is_visible) (struct Kobject *,

struct attribute *, int);

struct attribute **attrs;

};

Property files are built with the most basic attribute struct struct attribute.

static struct attribute * g[] = {

&state_attr.attr,

#ifdef Config_pm_trace//Not set

&pm_trace_attr.attr,

#endif

#if defined (config_pm_sleep) && defined (config_pm_debug)//Not set

&pm_test_attr.attr,

#endif

#ifdef Config_user_wakelock//Set

&wake_lock_attr.attr,

&wake_unlock_attr.attr,

#endif

Null

};

#ifdef Config_pm_sleep

#ifdef Config_pm_debug

Power_attr (pm_test);

#endif

#endif

Power_attr (state);

#ifdef Config_pm_trace

Power_attr (Pm_trace);

#endif

#ifdef Config_user_wakelock

Power_attr (Wake_lock);

Power_attr (Wake_unlock);

#endif

#define POWER_ATTR (_name)/

static struct Kobj_attribute _name# #_attr = {/

. attr = {/

. Name = __stringify (_name),/

. Mode = 0644,/

},                                /

. Show = _name# #_show,/

. store = _name# #_store,/

}

These encapsulated attribute structures will use the Kobject ktype.sysfs_ops->show (store) for the next two general functions through container_of () The macro finds the actual property structure in the body of the show and store functions to invoke.

For more information on SYSFS, please see the additional detailed documentation for this section.

Linux driver Power management standard Linux hibernation and wake-up mechanism analysis (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.