linux内核休眠、唤醒流程分析之挂起到RAM(一)

本文探讨Linux内核中挂起到RAM(s2ram/STR)的流程,涉及同步文件系统、冻结进程、设备驱动挂起等步骤。讲解了如何在platform_driver等结构体中封装PM回调函数,以及Linux核心层的选择执行机制。
摘要由CSDN通过智能技术生成

挂起到RAM

Linux支持STANDBY、挂起到RAM、挂起到硬盘等形式的待机,如图所示。
在这里插入图片描述
一般的嵌入式产品仅仅实现了挂起到RAM(s2ram/STR),即将系统的状态保存到内存中,并将SDRAM置于自刷新状态,待用户按键等操作后再重新恢复系统。少数嵌入式linux系统会实现挂起到硬盘(STD),它与挂起到RAM不同的是s2ram并不关机,STD则把系统的状态保存于硬盘,然后关闭整个系统。
在linux内核中,大致的挂起到RAM的挂起和恢复流程如图所示。(其中包括同步文件系统、freeze进程、设备驱动挂起、系统的挂起入口等)。
在这里插入图片描述
在Linux内核中,相关的结构体定义在

// include\linux\device\driver.h

struct device_driver {
   
	const char		*name;
	struct bus_type		*bus;

	struct module		*owner;
	const char		*mod_name;	/* used for built-in modules */

	bool suppress_bind_attrs;	/* disables bind/unbind via sysfs */
	enum probe_type probe_type;

	const struct of_device_id	*of_match_table;
	const struct acpi_device_id	*acpi_match_table;

	int (*probe) (struct device *dev);
	void (*sync_state)(struct device *dev);
	int (*remove) (struct device *dev);
	void (*shutdown) (struct device *dev);
	int (*suspend) (struct device *dev, pm_message_t state);
	int (*resume) (struct device *dev);
	const struct attribute_group **groups;
	const struct attribute_group **dev_groups;

	const struct dev_pm_ops *pm;
	void (*coredump) (struct device *dev);

	struct driver_private *p;
};

其中pm是一个dev_pm_ops结构体指针,在该结构体中,封装了挂起到RAM和挂起到硬盘所需的回调函数。

// include\linux\pm.h

struct dev_pm_ops {
   
	int (*prepare)(struct device *dev);
	void (*complete)
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值