Standard linu sleep and wake-up Mechanism Analysis (I)

Source: Internet
Author: User

 

Note:

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

2. If you are interested, please refer to: Power Management Solutions apmand acpi .doc.

Sleep and wake-up guide for the Linux system. Doc

3. This article first studies the sleep and wakeup of the standard Linux, and Android's additions and modifications to this Part are discussed in another article.

4. We will discuss it based on a previous project. Here we will only discuss commonalities.

 

Although Linux supports three power-saving modes: standby, suspend to ram, and suspend to disk, almost all solutions only support the STR mode (standby mode is also supported), because the STD mode requires support for swap partitions, but mobile embedded devices such, they generally use NAND to store data and code, and the file system yaffs used on it is generally not divided into swap partitions, so Linux on mobile devices do not support STD power-saving mode.

 

I. project power-related configuration

Currently, the Linux Power Management Solution of my project is configured as follows:

#

# 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 lower part of the above configuration corresponds to a graphical configuration..., it seems that the options for configuring STD mode are directly deleted in the kconfig file.

After running the system compiled using the above configuration, go to the Sys directory and you can see the related interfaces:

# Pwd

/Sys/power

# Ls

State wake_lock wake_unlock wait_for_fb_sleep wait_for_fb_wake

# Cat state

Mem

If macro config_pm_debug is configured, A pm_test file is added to the power directory. After 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 have read and analyzed this document in detail.

 

Ii. Create sys/power and Related Property Files

When the system bootup, create a new power file and related property files under SYS. The source code is as follows:

Kernel/power/Main. c

 

Static int _ init pm_init (void)

{

Int error = pm_start_workqueue (); // config_pm_runtime not set, so this fun is null

If (error)

Return Error;

Power_kobj = kobject_create_and_add ("power", null );

// Create the kobject and sysfs_dirent objects corresponding to power, and create a contact: kobject. SD =

// & Sysfs_dirent, sysfs_di1_.s_dir-> kobj = & kobject.

If (! Power_kobj)

Return-enomem;

Return sysfs_create_group (power_kobj, & attr_group );

// Create a set of attribute files. You can create a sub-directory under power to store these attribute files. // However, you must specify the name in the attr_group structure, otherwise, put these property files in the directory corresponding to // power_kobj.

}

Core_initcall (pm_init); // as you can see, this function has been called very early, and the initcall level is 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;

};

// Attribute files are created based on the basic attribute structure 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 ktype of kobject in the future. the two common functions sysfs_ops-> show (store) are called by using the container_of () macro to find the show and store functions in the actual attribute struct.

For more information about sysfs, see other detailed parsing documents on this part.

Note:

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

2. If you are interested, please refer to: Power Management Solutions apmand acpi .doc.

Sleep and wake-up guide for the Linux system. Doc

3. This article first studies the sleep and wakeup of the standard Linux, and Android's additions and modifications to this Part are discussed in another article.

4. We will discuss it based on a previous project. Here we will only discuss commonalities.

 

Although Linux supports three power-saving modes: standby, suspend to ram, and suspend to disk, almost all solutions only support the STR mode (standby mode is also supported), because the STD mode requires support for swap partitions, but mobile embedded devices such, they generally use NAND to store data and code, and the file system yaffs used on it is generally not divided into swap partitions, so Linux on mobile devices do not support STD power-saving mode.

 

I. project power-related configuration

Currently, the Linux Power Management Solution of my project is configured as follows:

#

# 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 lower part of the above configuration corresponds to a graphical configuration..., it seems that the options for configuring STD mode are directly deleted in the kconfig file.

After running the system compiled using the above configuration, go to the Sys directory and you can see the related interfaces:

# Pwd

/Sys/power

# Ls

State wake_lock wake_unlock wait_for_fb_sleep wait_for_fb_wake

# Cat state

Mem

If macro config_pm_debug is configured, A pm_test file is added to the power directory. After 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 have read and analyzed this document in detail.

 

Ii. Create sys/power and Related Property Files

When the system bootup, create a new power file and related property files under SYS. The source code is as follows:

Kernel/power/Main. c

 

Static int _ init pm_init (void)

{

Int error = pm_start_workqueue (); // config_pm_runtime not set, so this fun is null

If (error)

Return Error;

Power_kobj = kobject_create_and_add ("power", null );

// Create the kobject and sysfs_dirent objects corresponding to power, and create a contact: kobject. SD =

// & Sysfs_dirent, sysfs_di1_.s_dir-> kobj = & kobject.

If (! Power_kobj)

Return-enomem;

Return sysfs_create_group (power_kobj, & attr_group );

// Create a set of attribute files. You can create a sub-directory under power to store these attribute files. // However, you must specify the name in the attr_group structure, otherwise, put these property files in the directory corresponding to // power_kobj.

}

Core_initcall (pm_init); // as you can see, this function has been called very early, and the initcall level is 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;

};

// Attribute files are created based on the basic attribute structure 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 ktype of kobject in the future. the two common functions sysfs_ops-> show (store) are called by using the container_of () macro to find the show and store functions in the actual attribute struct.

For more information about sysfs, see other detailed parsing documents on this part.

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.