加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何知道系统是否刚从mem睡眠中醒来?

发布时间:2020-12-16 03:48:19 所属栏目:百科 来源:网络整理
导读:我有一个在Linux上运行的Qt应用程序. 用户可以使用此应用程序将系统切换到mem sleep. 切换到mem睡眠是微不足道的,但是在用户空间中捕获唤醒事件则不然. 我目前的解决方案是使用无限循环来捕获mem睡眠,这样当系统唤醒时,我的应用程序总是从可预测的点继续. 这

我有一个在Linux上运行的Qt应用程序.

用户可以使用此应用程序将系统切换到mem sleep.

切换到mem睡眠是微不足道的,但是在用户空间中捕获唤醒事件则不然.

我目前的解决方案是使用无限循环来捕获mem睡眠,这样当系统唤醒时,我的应用程序总是从可预测的点继续.

这是我的代码:

void MainWindow::memSleep()
{   
    int fd;
    fd = ::open("/sys/power/state",O_RDWR);// see update 1)
    QTime start=QTime::currentTime();
    write(fd,"mem",3); // command that triggers mem sleep
    while(1){
        usleep(5000);  // delay 5ms
        const QTime &end=QTime::currentTime();// check system clock
        if(start.msecsTo(end)>5*2){// if time gap is more than 10ms
            break;         // it means this thread was frozen for more
        }                  // than 5ms,indicating a wake up after a sleep
        start=end;
    }
    :: close(fd);          // the end of this function marks a wake up event
}

我将此方法描述为对this question的评论,并指出它不是一个好的解决方案,我同意.

问题:是否有可用于捕获唤醒事件的C API?

更新:

1)mem睡眠是什么?

07001

The kernel supports up to four system sleep states generically,although three
of them depend on the platform support code to implement the low-level details
for each state.

The states are represented by strings that can be read or written to the
/sys/power/state file. Those strings may be “mem”,“standby”,“freeze” and
“disk”,where the last one always represents hibernation (Suspend-To-Disk) and
the meaning of the remaining ones depends on the relative_sleep_states command
line argument.

2)为什么我要赶上唤醒事件?

因为某些硬件需要在唤醒后重置.系统唤醒后,硬件输入设备会产生错误的输入事件,因此必须在睡眠前(简单)禁用,并在唤醒后启用(此问题).

这应该/可以由内核中的驱动程序处理,我可以访问或修复硬件,我的团队可以做但是没有时间去做.(为什么我,一个应用程序开发人员,需要修复它在用户空间)

3)约束

这是嵌入式linux,内核2.6.37,arch:arm,march:omap2,distro:arago.它不像PC发行版那样方便添加包,而不是它有ACPI.内核2.6.37中的mem sleep支持还不成熟.

最佳答案
用于PCI设备的Linux设备驱动程序可以选择性地处理暂停和恢复,这可能是内核分别在系统挂起之前和暂停之后恢复的. PCI入口点在struct pci_driver.

您可以编写并安装一个简单的设备驱动程序,它只能感知恢复操作,并为任何感兴趣的进程提供指示.最简单的可能是支持文件read(),只要检测到恢复,它就会返回一个字节.该程序只需要打开设备并让线程卡住读取单个字符.只要读取成功,系统就会恢复.

更重要的是,如果您的应用程序正在处理的设备具有设备驱动程序,则应更新驱动程序以对简历做出适当的反应.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读