Linux 休眠喚醒(一)

2021-07-23 03:14:06 字數 3455 閱讀 7967

**

一、專案power相關的配置

目前我手上的專案的linux電源管理方案配置如下,.config檔案的截圖,當然也可以通過make menuconfig使用圖形化來配置:

# 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

上面的配置對應下圖中的下半部分圖形化配置。。。,看來是直接在kconfig檔案中刪除了配置std模式的選項。

# pwd

/sys/power

# ls

state  wake_lock   wake_unlock   wait_for_fb_sleep   wait_for_fb_wake

# cat state

mem如果配置了巨集config_pm_debug,那麼在power目錄下會多出乙個pm_test檔案,cat pm_test後,列出的測試選項有:[none] core processors platform devices freezer。關於這個test模式的使用,可以參考kernel文件:/kernel/documentation/power/basic-pm-debugging.txt

這個文件我也有詳細的閱讀和分析。

二、sys/power和相關屬性檔案建立

kernel/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);

// 建立power對應的kobject和sysfs_dirent物件,同時建立聯絡:kobject.sd =

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

if (!power_kobj)

return -enomem;

return sysfs_create_group(power_kobj, &attr_group);

// 建立一組屬性檔案,可以在power下建立乙個子目錄來存放這些屬性檔案,    // 不過需要在結構體attr_group中指定name,否則直接將這些屬性檔案放在     //  power_kobj對應的目錄下。

core_initcall(pm_init);  // 看的出來,該函式是很早就被呼叫,initcall等級為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;

// 屬性檔案都是以最基本得屬性結構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,        /

// 而這些被封裝過的屬性結構體,將來會使用kobject的ktype.sysfs_ops->show(store)這兩個通用函式通過container_of()巨集找到實際的屬性結構體中的show和store函式來呼叫。



Linux 休眠喚醒(一)

說明 1.based on linux2.6.32,only for mem sdr 2.有興趣請先參考閱讀 電源管理方案apm和acpi比較.doc linux系統的休眠與喚醒簡介.doc 4.基於手上的乙個專案來討論,這裡只討論共性的地方 雖然linux支援三種省電模式 standby susp...

Linux 休眠喚醒(一)

說明 1.based on linux2.6.32,only for mem sdr 2.有興趣請先參考閱讀 電源管理方案apm和acpi比較.doc linux系統的休眠與喚醒簡介.doc 4.基於手上的乙個專案來討論,這裡只討論共性的地方 雖然linux支援三種省電模式 standby susp...

Linux程序休眠和喚醒

當程序以阻塞的方式通訊,在得到結果前程序會掛起休眠。為了將程序以一種安全的方式進入休眠,我們需要牢記兩條規則 一 永遠不要在原子上下文中進入休眠。二 程序休眠後,對環境一無所知。喚醒後,必須再次檢查以確保我們等待的條件真正為真 簡單休眠 完成喚醒任務的 還必須能夠找到我們的程序,這樣才能喚醒休眠的程...