Testing Suspend and Resume for Driver Developers.

本文介绍了如何使用Solaris Power Management API进行驱动程序的DDI_SUSPEND和DDI_RESUME测试,包括通过uadmin命令进行不同类型的挂起操作,如挂起到内存、挂起到磁盘等,并提供了几种用于部分测试或特定驱动程序测试的方法。

Please refer to http://blogs.sun.com/randyf/entry/testing_suspend_and_resume_for for original post.

 

Testing Suspend and Resume for Driver Developers.

Happy New Year!

But in the new year, you are a driver developer and need to support DDI_SUSPEND and DDI_RESUME. How do you do this, and then test if it is working?

First, go to my weblog describing the Power Management Interfaces and the docs.sun.com Ch. 12 "Writing Device Drivers: Power Management pages, and understand, first, how to use the Solaris Power Managment API's.

OK, so you probably have done this already, but it is always nice to have these references to go back and check. And you already know how to get this driver added and loaded/unloaded into your test machine (add_drv(1m) , modload(1m) , and modunload(1m) also for reference). But how do you go about testing the driver?

In How to Suspend and Resume , I described about modifying power.conf(4) to enable S3 support on your machine. I even described about using sys-suspend to suspend your machine. However, in the course of driver development, there will be the need to do some partial testing, or in the case of suspend and resume, other drivers might not be compliant and suspend might never get to your driver to test it.

No problem! There are test points to help you out. To start, we need to understand the primary entry point to the cpr module (where most of the work is done). Note that these commands require privilege to use, so you will have to become root, or otherwise get root privileges (see the RBAC related guides). The main command is: uadmin(1m) . This utility takes two and an optional third argument. The first is the primary command, the second is the function within that command, and the third is a string that is dependent on the first two.

For Suspend and Resume, the command will always be 3 (actually defined as A_FREEZE in the uadmin(2) man page). This is the same for all Suspend and Resume functions, including for S3 (Suspend to RAM, or sleep) and S4 (Suspend to Disk, or hibernate). Note here, that as of this blog writing, S3 is supported only on x86 systems, and S4 is supported only on Sparc systems. The second argument instructs the cpr module what it should do: sleep, hibernate, or do a test entry. The third is only used in one specific test point, but it will be described at that time.

So let's start with the first four common functions: 0, 1, 20, and 21.

0    Suspend to Disk
1    Check Suspend to Disk
20    Suspend to RAM
21    Check Suspend to RAM

The "Check" functions simply verify that the feature is supported and enabled for your platform. This is useful for various applications that only desire information about the ability to perform an operation. It returns 0 if supported, and non-0 if unsupported (the system call also returns an ENOTSUP error code). And the "Suspend" commands actually perform the operation. They will return 0 if successful, and non-0 if unsuccessful. So if a "Suspend to RAM" operation is performed on a Sparc machine, it will return non-0 and not do a suspend (in this case, the system call also returns an ENOTSUP, though other failures will return different error codes).

OK, we already know these, as this is what happens when the sys-suspend command is executed, but we also know that if there are non-compliant drivers, then the uadmin command may not get to your specific driver, or may well fail in other ways, and it makes it hard to test a driver. This is where some other functions come to play. As this blog is more specific to the x86 Suspend to RAM, I will only describe the Suspend to RAM test points.

22    Suspend to RAM, but don't power off and resume normally
23    Suspend to RAM, but don't power off and resume as a failure
24    Suspend to RAM, but don't power off and skip drivers that fail suspend
25    Suspend only a single driver - this takes the optional 'mdep' argument

The first two test points should be fairly descriptive. Go through the process of suspending, but instead of powering off, just resume (the second sets a "failure" error that is mostly only useful for framework testing, as errors are not provided to the drivers on resume). This is a good way to verify the code paths of your driver. If your driver doesn't properly execute DDI_SUSPEND or DDI_RESUME, it will be easily checked. And just as importantly, the hardware state remains intact, as the hardware wasn't actually powered off. This is also useful, if you are working on a system without a compliant framebuffer, and had to bypass it's suspend processing. Note, though, that this is an incomplete test as the hardware is not actually powered off. But it is a good way to test that code paths execute correctly.

The "25" function, though, can be used to only suspend your driver. It takes an optional 3rd (or mdep ) argument that is the major number of your driver. This can be found by searching /etc/name_to_major for your driver name, and using that number. It will only suspend your driver, and isn't useful for nexus drivers, as it doesn't walk the device tree to suspend leaf drivers (and can have adverse effects to those drivers). This may change in the future, however. But it is very useful for test suspending hardware drivers. The syntax is:

uadmin 3 25 14 , where 14 is the driver major number.

The last function, 24 should be used very cautiously! It walks the device tree as expected for a regular suspend and resume, but if it encounters a driver that returns DDI_FAILURE, instead of stopping and resuming, it will continue to the next driver, ultimately walking through the entire device tree. But use caution with this function, as it has no way of knowing if a driver returned a failure because it actually failed, or if the driver doesn't support suspend and resume. In either case, the machine could be left in an undesirable state, and a reboot might be needed (or worse, a hang, and you don't know what failed). The /var/adm/messages, as in all the other functions, will contain information as to what drivers failed, or what other failures might have occured.

This leads us to a good way to test your driver: first try uadmin 3 25 [major_number] , and see how your driver responds to a simple driver suspend. Then try a suspend without power off by uadmin 3 22 . If still successful, it is now time to try the real thing, and execute uadmin 3 20 , or /usr/openwin/bin/sys-suspend . If all goes well, your machine will suspend, and a simple case of pressing a key (or power button), the machine will resume to it's original state.

 

This is a great time to have a "Chimay Blue Lable"! A 'powerful' Belgian Trappist style ale with complex Belgian malt character, and hop bitterness to compliment the malt body. A light fruitiness due to the hops and Trappist yeast, and a good warming level of alcohol, makes for a strong and very enjoyable ale to celebrate the success of your driver!

提供了基于BP(Back Propagation)神经网络结合PID(比例-积分-微分)控制策略的Simulink仿真模型。该模型旨在实现对杨艺所著论文《基于S函数的BP神经网络PID控制器及Simulink仿真》中的理论进行实践验证。在Matlab 2016b环境下开发,经过测试,确保能够正常运行,适合学习和研究神经网络在控制系统中的应用。 特点 集成BP神经网络:模型中集成了BP神经网络用于提升PID控制器的性能,使之能更好地适应复杂控制环境。 PID控制优化:利用神经网络的自学习能力,对传统的PID控制算法进行了智能调整,提高控制精度和稳定性。 S函数应用:展示了如何在Simulink中通过S函数嵌入MATLAB代码,实现BP神经网络的定制化逻辑。 兼容性说明:虽然开发于Matlab 2016b,但理论上兼容后续版本,可能会需要调整少量配置以适配不同版本的Matlab。 使用指南 环境要求:确保你的电脑上安装有Matlab 2016b或更高版本。 模型加载: 下载本仓库到本地。 在Matlab中打开.slx文件。 运行仿真: 调整模型参数前,请先熟悉各模块功能和输入输出设置。 运行整个模型,观察控制效果。 参数调整: 用户可以自由调节神经网络的层数、节点数以及PID控制器的参数,探索不同的控制性能。 学习和修改: 通过阅读模型中的注释和查阅相关文献,加深对BP神经网络与PID控制结合的理解。 如需修改S函数内的MATLAB代码,建议有一定的MATLAB编程基础。
“Gave up waiting for suspend/resume device” 是一种常见的错误信息,通常出现在Linux系统中,特别是在尝试挂起(suspend)或恢复(resume)系统时。这个错误信息表明系统在等待某些设备进入挂起或恢复状态时超时了。以下是一些可能的原因和解决方法: ### 可能的原因 1. **设备驱动问题**:某些设备的驱动程序可能不支持挂起或恢复操作。 2. **硬件兼容性**:某些硬件组件可能与系统的挂起/恢复功能不兼容。 3. **电源管理设置**:系统的电源管理设置可能不正确,导致设备无法正常挂起或恢复。 4. **固件问题**:设备的固件可能需要更新以支持挂起/恢复功能。 ### 解决方法 1. **更新驱动程序**:确保所有设备的驱动程序都是最新版本。可以从设备制造商的网站或Linux发行版的软件仓库中获取更新。 2. **检查硬件兼容性**:查阅设备的文档,确保它们支持挂起和恢复功能。 3. **调整电源管理设置**:可以通过编辑系统配置文件(如`/etc/systemd/logind.conf`)来调整电源管理设置。 4. **更新固件**:检查设备是否有可用的固件更新,并按照制造商的说明进行更新。 ### 示例步骤 1. **更新驱动程序**: ```bash sudo apt update sudo apt upgrade ``` 2. **编辑电源管理设置**: ```bash sudo nano /etc/systemd/logind.conf ``` 找到并修改以下行: ``` HandleSuspendKey=suspend HandleHibernateKey=hibernate HandleLidSwitch=suspend ``` 3. **重启服务**: ```bash sudo systemctl restart systemd-logind ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值