Linux电源管理-Runtime PM
前言
Subsystem and Driver Callbacks
struct dev_pm_ops {....int (*runtime_suspend)(struct device *dev);int (*runtime_resume)(struct device *dev);int (*runtime_idle)(struct device *dev);
};
三个回调函数分别用于suspend device,resume device和idle device。通常Runtime PM framework会在合适的时机调用三个函数。
Device States
enum rpm_status {RPM_ACTIVE = 0,RPM_RESUMING,RPM_SUSPENDED,RPM_SUSPENDING,
};
RPM_ACTIVE: 设备处于正常工作状态,处于全速全进状态。runtime_resume的回调执行完毕。
Runtime PM请求类型
enum rpm_request {RPM_REQ_NONE = 0,RPM_REQ_IDLE,RPM_REQ_SUSPEND,RPM_REQ_AUTOSUSPEND,RPM_REQ_RESUME,
};
PRM_REQ_NONE: Do nothing
Runtime PM数据段
struct dev_pm_info {....struct timer_list suspend_timer;unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue;atomic_t usage_count;atomic_t child_count;unsigned int disable_depth:3;unsigned int idle_notification:1;unsigned int request_pending:1;unsigned int deferred_resume:1;unsigned int run_wake:1;unsigned int runtime_auto:1;unsigned int no_callbacks:1;unsigned int irq_safe:1;unsigned int use_autosuspend:1;unsigned int timer_autosuspends:1;unsigned int memalloc_noio:1;enum rpm_request request;enum rpm_status runtime_status;int runtime_error;int autosuspend_delay;unsigned long last_busy;unsigned long active_jiffies;unsigned long suspended_jiffies;unsigned long accounting_timestamp;};
.suspend_timer: 休眠时候用到的定时器。
Runtime PM运行机制
Runtime PM回调约束
Runtime Sys接口
if (pm_runtime_callbacks_present(dev)) {rc = sysfs_merge_group(&dev->kobj, &pm_runtime_attr_group);if (rc)goto err_out;}
runtime的属性如下:
static struct attribute *runtime_attrs[] = {
#ifdef CONFIG_PM_RUNTIME
#ifndef CONFIG_PM_ADVANCED_DEBUG&dev_attr_runtime_status.attr,
#endif&dev_attr_control.attr,&dev_attr_runtime_suspended_time.attr,&dev_attr_runtime_active_time.attr,&dev_attr_autosuspend_delay_ms.attr,
#endif /* CONFIG_PM_RUNTIME */NULL,
};
其中有五个属性。分别为control, runtime_susupend_time, runtime_active_time, autosuspend_delay_ms,runtime_status属性。
active - 设备的状态是正常工作状态。
Runtime API
- pm_runtime_enable(使能设备的runtime pm)
void pm_runtime_enable(struct device *dev)
{unsigned long flags;spin_lock_irqsave(&dev->power.lock, flags);if (dev->power.disable_depth > 0)dev->power.disable_depth--;elsedev_warn(dev, "Unbalanced %s!\n", __func__);spin_unlock_irqrestore(&dev->power.lock, flags);
}
disable_depth在pm_runtime_init会被初始化为1,enabel函数就是将此值减去1而已。当然了在disable函数中会给该值加1。
- pm_runtime_get/pm_runtime_put(异步请求增加/减少引用计数)
- pm_runtime_get_sync/pm_runtime_put_sync(同步请求增加/减少引用计数)
- pm_runtime_set_active/pm_runtime_set_suspended(设置设备的runtime运行状态)
- pm_schedule_suspend(在指定时间之后suspend)
- __pm_runtime_resume(resume设备)
Runtime PM举例
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/platform_device.h>
#include <linux/types.h>
#include <linux/pm_runtime.h>static int runtime_pm_probe(struct platform_device *pdev)
{printk(KERN_EMERG "runtime_pm: runtime_pm_probe!\n");pm_runtime_set_active(&pdev->dev);pm_runtime_enable(&pdev->dev); return 0;
}static int runtime_pm_remove(struct platform_device *pdev)
{printk(KERN_EMERG "runtime_pm: runtime_pm_remove!\n");pm_runtime_disable(&pdev->dev);return 0;
}static int runtime_pm_suspend(struct device *dev)
{printk(KERN_EMERG "runtime_pm: runtime_pm_suspend!\n");return 0;
}static int runtime_pm_resume(struct device *dev)
{printk(KERN_EMERG "runtime_pm: runtime_pm_resume!\n");return 0;
}static int runtime_pm_idle(struct device *dev)
{printk(KERN_EMERG "runtime_pm: runtime_pm_idle\n");return 0;
}static const struct dev_pm_ops runtime_pm_ops = {SET_RUNTIME_PM_OPS(runtime_pm_suspend,runtime_pm_resume,runtime_pm_idle)
};static void runtime_pm_release(struct device * dev)
{
}static struct platform_device runtime_device = {.name = "runtime_device",.id = -1,.dev = {.release = runtime_pm_release,},
};static struct platform_driver runtime_driver = {.probe = runtime_pm_probe,.remove = runtime_pm_remove,.driver = {.owner = THIS_MODULE,.name = "runtime_device",.pm = &runtime_pm_ops,},
};static int runtime_pm_init(void)
{ printk(KERN_EMERG "runtime_pm: runtime_pm_init\n");platform_device_register(&runtime_device);platform_driver_register(&runtime_driver);return 0;
}static void runtime_pm_exit(void)
{printk(KERN_EMERG "runtime_pm: runtime_pm_exit\n");platform_driver_unregister(&runtime_driver);platform_device_unregister(&runtime_device);
}module_init(runtime_pm_init);
module_exit(runtime_pm_exit);
MODULE_LICENSE("GPL");
如下是测试结果:
cat /sys/devices/platform/runtime_device/power/runtime_status
suspend
2. 查看设备的runtime_suspend时间
cat /sys/devices/platform/runtime_device/power/runtime_suspended_time
341028
3. 使设备处于active状态
echo on > /sys/devices/platform/runtime_device/power/control
4. 使设备进入suspend状态
echo auto > /sys/devices/platform/runtime_device/power/control
5. 查看转换状态的打印
test:/ # dmesg | grep "runtime"
[ 451.432602] c7 runtime_pm: runtime_pm_resume!
[ 509.842328] c5 runtime_pm: runtime_pm_idle
[ 509.846430] c5 runtime_pm: runtime_pm_suspend!
Linux电源管理-Runtime PM相关推荐
- linux 电源管理 Generic PM之Suspend功能
Linux电源管理(6)_Generic PM之Suspend功能 作者:wowo 发布于:2014-8-22 21:40 分类:电源管理子系统 1. 前言 Linux内核提供了三种Suspend: ...
- linux 电池管理软件,Linux电源管理(2)_Generic PM之基本概念和软件架构
Linux电源管理(2)_Generic PM之基本概念和软件架构 作者:wowo 发布于:2014-5-13 19:24 分类:电源管理子系统 1. 前言 这里的Generic PM,是蜗蜗自己起的 ...
- Linux电源管理(2)_Generic PM之基本概念和软件架构(蜗窝科技,www.wowotech.net)
1. 前言 这里的Generic PM,是蜗蜗自己起的名字,指Linux系统中那些常规的电源管理手段,包括关机(Power off).待机(Standby or Hibernate).重启(Reboo ...
- Linux电源管理(6)_Generic PM之Suspend功能【重磅文章】-- wowo
文章目录 1. 前言 2. Suspend功能有关的代码分布 1)PM Core 2)Device PM 3)Platform dependent PM 3. suspend&resume过程 ...
- linux 电源管理 regulator,Linux内核电源管理综述
资料: http://blog.csdn.net/bingqingsuimeng/article/category/1228414 http://os.chinaunix.net/a2006/0519 ...
- linux系统电源时钟,linux电源管理的一些梳理
由于项目产品需要过能源之星3.0,所以最近做了一些电源管理低功耗方面的工作,抽个时间正好梳理一下. 其实Linux 电源管理非常复杂,牵扯到很多方面,比如系统级的待机.频率电压变换.系统空闲时的处理以 ...
- Linux电源管理(一)电源管理系统架构
概述 Linux 电源管理非常复杂,牵扯到系统级的待机.频率电压变换.系统空闲时的处理以及每个设备驱动对于系统待机的支持和每个设备的运行时电源管理,可以说和系统中的每个设备驱动都息息相关. 对于消费电 ...
- Linux电源管理(1)_整体架构 -- wowo
1. 前言 在这个世界中,任何系统的运转都需要能量.如树木依靠光能生长,如马儿依靠食物奔跑,如计算机系统依靠电能运行.而能量的获取是有成本的,因此如果能在保证系统运转的基础上,尽量节省对能量的消耗,就 ...
- Linux 电源管理子系统
Linux 在消费电子领域的应用已经相当普遍,而对于消费电子产品而言,省电是一个重要的议题. Linux 电源管理非常复杂,牵扯到系统级的待机.频率电压变换.系统空闲时的处理以及每个设备驱动对系统待机 ...
- Linux电源管理(10)_autosleep
Linux电源管理(10)_autosleep 作者:wowo 发布于:2014-9-18 23:42 分类:电源管理子系统 1. 前言 Autosleep也是从Android wakelocks补丁 ...
最新文章
- IEnumerator,IEnumerable,IEnumerableT
- 作者:卢祥虎,男,北京金信网银金融信息服务有限公司机器学习算法工程师。...
- linux-vim-环境永久-多窗口操作
- Android HAL层与Linux Kernel层驱动开发简介
- 拼多多首届“非遗购物节”开幕 十一省市“非遗馆”入驻
- kickstart注意事项
- apache poi excel显示 base64 图片_java操作Excel一:POI
- 汽车诊断之UDS入门-0x19 0x06服务
- 神通数据库常见问题解决方案
- android 圆形进度条样式,Android编程之ProgressBar圆形进度条颜色设置方法
- wps图片与图片间距怎么调整_wps图片与图片间距怎么调整_微信图文排版,字间距,行间距,怎么调整合适?......
- 制作旅行英语图书封面
- 国产计算机硬件发展史,计算机基础-计算机硬件发展史以及硬件
- SAP MM 事务代码MI31之思考
- Linear Discriminant Analysis (LDA)
- Linux常用命令——modprobe命令
- Python全局变量和局部变量(超详细,纯干货,保姆级教学)
- 未能找到引用的组件“Microsoft.Office.Core”
- 高晓松的《晓说》很棒,这脑袋怎么长得?
- 游戏:致那个曾经热血的青春