Sleep/suspend function in Haiku?

Just a quick question for the developers on behalf of those of us who use and/or test Haiku on laptop systems: Would it require too much coding/recoding to implement a suspend/sleep function in Haiku?

If it would be too much work, I for one could do without it, but it’d be nice to have on a laptop.

7 Likes

If it was a two line change, we would have done it already.
It’s quite hard to put the system to sleep, power down all devices, and then when you power them back on make sure everything is still set so that they perform normally.

It may be easier to implement state-saving in all applications instead, and perform a complete shutdown + saving application states to restore on next start. Wouldn’t that be nice?

6 Likes

Thanks for the response… Just wanted to pose that question anyway. You may be right about the state-saving idea being easier to implement; if this is the case, perhaps that could be done for one of the nightlies…?

Neither suspend nor state-saving planned for beta. It could happen in the master branch if somebody does it.
The state saving could need some support from the application side too.

Actually it sounds like a good GSoC project. Do we have an entry for it?

4 Likes

That’s a great idea but how easy would saving app states be? If someone can pull it off as a temp solution to standby, then it should be added to a new dialog that comes up when you click “Restart System”. Either that or a third option in the “Shutdown…” menu. Lastly, maybe hibernate won’t be as hard as standby or is “app state” your idea of hibernate?

State saving would only work for Native BeAPI applications though right not… QT applications etc?

Well, there are two ways to approach this. One would indeed be that the application QuitRequested would store the application state in an archive and write it down to a file. The OS would then just have to look at archived files and restart the apps.

Qt applications could also implement it if they wanted to, but this solution requires support from the application developer. This is however quite common eg. on Android, where the OS can kill background applications when RAM is low. Not all applications will do this properly, however.

The alternative would be to do this at a lower level. We could snapshot the application memory image (a bit like what Debugger can do when saving core files) and then handle resuming it from there. In that case, it should work for all applications.

Note that doing it this way instead of at the system level has another advantage: you can snapshot multiple sessions and switch between them, or even grab your session snapshot on an USB stick or over the network to resume it on another computer. Wouldn’t that be a great feature?

4 Likes

What happens after if one updates a program and Haiku tries preload unexpected data at unexpected memory areas? Is it possible to handle it without crash-loops or data-loss?

details… :o)

We could run the app from the older version of the package in that case but that would be tricky.

I can see this being difficult in general if there is interaction with stateful hardware, e.g. graphics card or USB device, the state of these would need to be saved by the OS. And for the scenario of moving application memory images around, you would also need the state of any hardware that application had open, and it might need to be able to cope with e.g. a different GPU on the target machine (perhaps irrelevant atm where haiku has no GPU acceleration).

Also, in terms of your two differing approaches, you could combine them - provide a callback (virtual function in c++ I guess) that will be called just before the memory imaging happens, and allowing the default memory snapshotting to be be exchanged for something simpler if the application wants.

If you could make this work at application granularity, you would even be able to e.g. move an application between screens (from laptop to desktop perhaps) when using multiple machines on one desk with linked keyboard/mouse (using usynergy)… amazing!

Another thought… security implications might be quite significant.

EDIT: of course I should have expected that Linux already has this functionality https://www.criu.org/

1 Like

Minix actually does something like this these days experimentally even with drivers and services in the OS… where they can even unload drivers and update them whil erunning and such and clang does some conversion between data structures etc…

I think there are situations where it doesn’t work though.