Linux - 电源管理

引用

一. Linux Power Management

二. Linux Generic PM


2.1 Suspend

https://elixir.bootlin.com/linux/latest/source/kernel/power/suspend.c#L605

2.2 Hibernate and Sleep

https://elixir.bootlin.com/linux/latest/source/kernel/power/main.c#L782

2.3 Wakeup events framework

2.3.1 wakeup events architecture

2.3.2 wakeup count

https://elixir.bootlin.com/linux/latest/source/drivers/base/power/wakeup.c#L971

2.3.3 wakelocks

https://elixir.bootlin.com/linux/latest/source/kernel/power/wakelock.c#L206

2.3.4 autosleep

https://elixir.bootlin.com/linux/latest/source/kernel/power/autosleep.c#L117

三. Runtime PM

https://elixir.bootlin.com/linux/latest/source/include/linux/pm_runtime.h#L417

device driver(或者driver所在的bus、class等)需要提供3个回调函数,runtime_suspend、runtime_resume和runtime_idle,分别用于suspend device、resume device和idle device。它们一般由RPM core在合适的时机调用,以便降低device的power consumption。

而调用的时机,最终是由device driver决定的。driver会在适当的操作点,调用RPM core提供的put和get系列的helper function,汇报device的当前状态。RPM core会为每个device维护一个引用计数,get时增加计数值,put时减少计数值,当计数为0时,表明device不再被使用,可以立即或一段时间后suspend,以节省功耗。

四. Linux PM files and Data structure

  • kernel/power/ *
  • drivers/power/
  • drivers/base/power/*
  • drivers/cpuidle/*
  • drivers/cpufreq/*
  • drivers/devfreq/*
  • include/linux/power_supply.h
  • include/linux/cpuidle.h
  • include/linux/cpufreq.h
  • include/linux/cpu_pm.h
  • include/linux/device.h
  • include/linux/pm.h
  • include/linux/pm domain.h
  • include/linux/pm runtime.h
  • include/linux/pm wakeup.h
  • include/linux/suspend.h
  • Documentation/power/*.txt

https://elixir.bootlin.com/linux/latest/source/include/linux/pm.h#L278

/* struct dev_pm_ops - device PM callbacks. */

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);
};

从Linux PM Core的角度来说,这些callbacks并不复杂,因为PM Core要做的就是在特定的电源管理阶段,调用相应的callbacks,例如在suspend/resume的过程中,PM Core会依次调用“prepare—>suspend—>suspend_late—>suspend_noirq  <.........lowpower.......> wakeup--------->resume_noirq—>resume_early—>resume-->complete”。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值