linux dpm机制分析(下)【转】

简介:

转自:http://blog.csdn.net/lixiaojie1012/article/details/23707901

1      设备注册到dpm_list路径

(Platform_device->device->device_driver指向platform_driver->driver)

 

2      低功耗接口

dpm_suspend_start():调用注册到dpm_list的设备的回调函数,执行睡眠前的准备和保存工作;

dpm_suspend_end():执行suspend_late和suspend_noirq设备的回调函数,进行睡眠前的准备工作。

睡眠时,设备在链表中的转移:

dpm_list--->dpm_prepared_list-->dpm_suspended_list---->

dpm_late_early_list--->dpm_noirq_list

 

Dpm_resume_start():执行设备的resume_noirq和resume_early回调,恢复suspend_noirq和suspend_late阶段保存的东西

dpm_resume_end():执行各设备的resume和complete回调接口,做suspend和prepare的逆操作

唤醒时,设备从链表中的转移顺序是上述suspend阶段顺序的逆序。

3      低功耗接口是如何调用到各设备驱动注册的回调函数的

系统进入睡眠前回调设备的回调函数是有选择的:

如果dev->pm_domain域的回调函数注册的话,首选此处的回调函数

否则,如果dev->type域和dev->type->pm域都注册的话,会选择dev->type->pm处的回调函数

否则,如果dev->class 和 dev->class->pm两处都注册回调函数的话,会选择dev->class->pm的回调函数

如果dev->bus 和 dev->bus->pm两处都注册回调函数的话,会选择dev->bus->pm的回调函数

示例方法1和方法4:

3.1       在dev域的电源域进行注册

struct platform_device {

       const char       * name;

       int          id;

       bool        id_auto;

       struct device   dev;

       u32         num_resources;

       struct resource * resource;

       const struct platform_device_id     *id_entry;

       /* MFD cell pointer */

       struct mfd_cell *mfd_cell;

       /* arch specific additions */

       struct pdev_archdata      archdata;

};

struct device {

       struct device          *parent;

       struct device_private      *p;

       struct kobject kobj;

       const char              *init_name; /* initial name of the device */

       const struct device_type *type;

       struct mutex           mutex;    /* mutex to synchronize calls to

                                    * its driver.*/

       struct bus_type       *bus;              /* type of bus device is on */

       struct device_driver *driver;  /* which driver has allocated this device */

       void        *platform_data;      /* Platform specific data, device core doesn't touch it */

       struct dev_pm_info power;

       struct dev_pm_domain *pm_domain;

…….}

struct dev_pm_domain {

       struct dev_pm_ops  ops;

};

struct dev_pm_ops {

       int (*prepare)(struct device *dev);

       void (*complete)(struct device *dev);

       int (*suspend)(struct device *dev);

       int (*resume)(struct device *dev);

       int (*freeze)(struct device *dev);

       int (*thaw)(struct device *dev);

       int (*poweroff)(struct device *dev);

       int (*restore)(struct device *dev);

       int (*suspend_late)(struct device *dev);

       int (*resume_early)(struct device *dev);

       int (*freeze_late)(struct device *dev);

       int (*thaw_early)(struct device *dev);

       int (*poweroff_late)(struct device *dev);

       int (*restore_early)(struct device *dev);

       int (*suspend_noirq)(struct device *dev);

       int (*resume_noirq)(struct device *dev);

       int (*freeze_noirq)(struct device *dev);

       int (*thaw_noirq)(struct device *dev);

       int (*poweroff_noirq)(struct device *dev);

       int (*restore_noirq)(struct device *dev);

       int (*runtime_suspend)(struct device *dev);

       int (*runtime_resume)(struct device *dev);

       int (*runtime_idle)(struct device *dev);

};

低功耗接口在函数__device_suspend函数内会首先调用在struct device电源域注册的回调函数。

 

唤醒时调用顺序:

 

3.2       在bus的ops电源域进行注册

注册设备和注册驱动进行匹配成功后

Platform_device->device->device_driver指针会指向platform_driver->driver成员

设备注册:

 (1)int platform_device_add(struct platform_device *pdev)

{

       ……………

       if (!pdev->dev.parent)

              pdev->dev.parent = &platform_bus;

       pdev->dev.bus = &platform_bus_type;

…………..

}

(2)struct bus_type platform_bus_type = {

       .name             = "platform",

       .dev_attrs       = platform_dev_attrs,

       .match            = platform_match,

       .uevent           = platform_uevent,

       .pm         = &platform_dev_pm_ops,

};

(3)static const struct dev_pm_ops platform_dev_pm_ops = {

       .runtime_suspend = pm_generic_runtime_suspend,

       .runtime_resume = pm_generic_runtime_resume,

       .runtime_idle = pm_generic_runtime_idle,

       USE_PLATFORM_PM_SLEEP_OPS

};

(4)#define USE_PLATFORM_PM_SLEEP_OPS \

       .suspend = platform_pm_suspend, \

       .resume = platform_pm_resume, \

       .freeze = platform_pm_freeze, \

       .thaw = platform_pm_thaw, \

       .poweroff = platform_pm_poweroff, \

       .restore = platform_pm_restore,

(5) int platform_pm_suspend(struct device *dev)

{

       struct device_driver *drv = dev->driver;

       int ret = 0;

       if (!drv)

              return 0;

       if (drv->pm) {

              if (drv->pm->suspend)

                     ret = drv->pm->suspend(dev);

       } else {

              ret = platform_legacy_suspend(dev, PMSG_SUSPEND);

       }

       return ret;

}










本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/5333660.html,如需转载请自行联系原作者

相关文章
|
30天前
|
消息中间件 Unix Linux
Linux进程间通信(IPC)介绍:详细解析IPC的执行流程、状态和通信机制
Linux进程间通信(IPC)介绍:详细解析IPC的执行流程、状态和通信机制
43 1
|
1月前
|
Linux Android开发
嵌入式linux中Framebuffer 驱动程序框架分析
嵌入式linux中Framebuffer 驱动程序框架分析
26 0
|
1月前
|
Linux C语言 SoC
嵌入式linux总线设备驱动模型分析
嵌入式linux总线设备驱动模型分析
32 1
|
1月前
|
Linux
嵌入式linux系统设备树实例分析
嵌入式linux系统设备树实例分析
34 0
|
27天前
|
监控 Shell Linux
【Shell 命令集合 网络通讯 】Linux 分析串口的状态 statserial命令 使用指南
【Shell 命令集合 网络通讯 】Linux 分析串口的状态 statserial命令 使用指南
32 0
|
3月前
|
安全 Linux 编译器
内存泄漏检测组件的分析与实现(linux c)-mtrace工具使用
内存泄漏产生原因 在堆上使用malloc/remalloc/calloc分配了内存空间,但是没有使用free释放对应的空间。
73 0
|
3月前
|
监控 Linux 编译器
多线程死锁检测的分析与实现(linux c)-有向图的应用
在日常的软件开发中,多线程是不可避免的,使用多线程中的一大问题就是线程对锁的不合理使用造成的死锁,死锁一旦发生,将导致多线程程序响应时间长,吞吐量下降甚至宕机崩溃,那么如何检测出一个多线程程序中是否存在死锁呢?在提出解决方案之前,先对死锁产生的原因以及产生的现象做一个分析。最后在用有向环来检测多线程中是否存在死锁的问题。
56 0
|
30天前
|
资源调度 算法 Linux
Linux进程/线程的调度机制介绍:详细解析Linux系统中进程/线程的调度优先级规则
Linux进程/线程的调度机制介绍:详细解析Linux系统中进程/线程的调度优先级规则
48 0
|
6天前
|
算法 Linux 调度
深度解析:Linux内核的进程调度机制
【4月更文挑战第12天】 在多任务操作系统如Linux中,进程调度机制是系统的核心组成部分之一,它决定了处理器资源如何分配给多个竞争的进程。本文深入探讨了Linux内核中的进程调度策略和相关算法,包括其设计哲学、实现原理及对系统性能的影响。通过分析进程调度器的工作原理,我们能够理解操作系统如何平衡效率、公平性和响应性,进而优化系统表现和用户体验。
15 3
|
15天前
|
Prometheus 监控 数据可视化
linux分析方法与技巧
【4月更文挑战第3天】在Linux环境中,进行日志分析和系统性能分析的关键方法包括:使用`cat`, `less`, `tail`查看和过滤日志,`logrotate`管理日志文件,`rsyslog`或`syslog-ng`聚合日志,以及通过`top`, `mpstat`, `pidstat`, `free`, `iostat`, `netstat`, `strace`, `sar`, `dstat`等工具监控CPU、内存、磁盘I/O和网络。对于高级分析,可利用Brendan Gregg的性能工具,以及Grafana、Prometheus等可视化工具。
16 2
linux分析方法与技巧