Opened 6 years ago

Last modified 5 years ago

#14507 new enhancement

Implement a way to pause programs

Reported by: miqlas Owned by: nobody
Priority: normal Milestone: Unscheduled
Component: Kits/Application Kit Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

Lets suppose you started a render job on Haiku and it eats all your CPU. Now you remember, you have to check something on the web. You can go to ProcessController to change the render prio, but thats not nice. For Gui programs i can imagine a keyboard/mouse shortcut to freeze/unfreeze application state. For multi-threaded programs the whole process-tree have to be frozen from the selected window (or tab for cli programs). The frozen programs would get a PAUSE symbol overlay.

For more info check: https://vermaden.wordpress.com/2018/09/19/freebsd-desktop-part-16-configuration-pause-any-application/

Change History (14)

comment:1 by pulkomandy, 6 years ago

This should not be needed. It is the OS job to schedule threads, not the user's.

If your heavy rendering job is slowing down things, it means either it did not set its own priority properly (badly ported software?) or there is a bug in Haiku.

comment:2 by ahwayakchih, 6 years ago

@pulkomandy setting heavy computing application to low priority, makes it work a lot slower to finish the task. Sure, you could add some flags/switches for starting it in "fast" or "slow" mode, or change priority through ProcessController, but maybe having another option is not that bad idea.

I've read that article earlier today and i think that the idea is not bad. I would rarely have use for it probably, but that does not mean that it would be useless for everyone. For me, the only part of it that i could probably use is to automatically pause pre-selected applications whenever they lose focus - websites these days can contain some scripts that keep working all the time and drain battery. Sure, i can simply close browser every time, or find some add-on to "pause" specific tabs only, but that way would be browser-specific only. Having generic solution sounds better to me.

I'm not sure how Haiku applications react on those two signals, but if they (or actually default Application API, or system?) already support it, then it shouldn't be hard to implement one/any of:

  • tiny command line application and set up keyboard shortcut to it
  • additional button to the popup window of ProcessController where it already asks if you want to kill or debug selected team (process)
  • additional option in right-click popup menu of Deskbar for selected application

I don't like the last one, as it could make menu less readable for regular users.

I'm not sure if there is a way for Deskbar to observe application (to show additional non-clickable pause icon - just to let user know that application was paused?) without eating up resources, i.e., if there is a way to register observer with system/application server or if Deskbar would have to periodically check every process/thread (a big no-go IMHO).

Last edited 6 years ago by ahwayakchih (previous) (diff)

in reply to:  2 ; comment:3 by pulkomandy, 6 years ago

Replying to ahwayakchih:

@pulkomandy setting heavy computing application to low priority, makes it work a lot slower to finish the task. Sure, you could add some flags/switches for starting it in "fast" or "slow" mode, or change priority through ProcessController, but maybe having another option is not that bad idea.

Benchmarks please.

If the CPU has free cycles, no matter the application priority, it will use the CPU cycles and run just as fast. It will just more easily free cycles for other more important things: refreshing the UI and letting your MP3 or video player run smoothly. Which means you can just let it run in the background and do something else anyways, so the computer isn't even "busy" and you can continue your work as if nothing special was happening.

For me, the only part of it that i could probably use is to automatically pause pre-selected applications whenever they lose focus - websites these days can contain some scripts that keep working all the time and drain battery. Sure, i can simply close browser every time, or find some add-on to "pause" specific tabs only, but that way would be browser-specific only. Having generic solution sounds better to me.

Battery draining is a somewhat different problem indeed. However, sometimes you want the websites to keep running (eg. you are playing music on some music stremaing website in the background, or you have gmail and want new mail notifications to be sent). So, you can't really do this on a per-application basis.

The application itself should be able to behave properly, and indeed most web browser will know when they are not focused, and will already reduce CPU use of background tabs (again, notice how this is unrelated to window focus: it's really a matter of what happens in each browser tab).

My conclusion is the same: this is not something the user should care for. This is something the OS should do right. In no way I can imagine an use for manually freezing and resuming a GUI app. The OS should just make it so it runs as fast as possible without draining battery. And applications themselves (eg. web browsers) should be careful to not run useless code at full speed.

in reply to:  3 comment:4 by ahwayakchih, 6 years ago

Replying to pulkomandy:

Replying to ahwayakchih:

@pulkomandy setting heavy computing application to low priority, makes it work a lot slower to finish the task. Sure, you could add some flags/switches for starting it in "fast" or "slow" mode, or change priority through ProcessController, but maybe having another option is not that bad idea.

Benchmarks please.

I'm running in VirtualBox, so no point in those, even if i had a long-running computing task to use as a specific example.

If the CPU has free cycles, no matter the application priority, it will use the CPU cycles and run just as fast. [...]

Yes, but if, for example you want to make sure that computing task actually goes forward, but then still browse the web for some information? Let's say you open one website that's simple and static - that's easy and does not impact much. But then you open another website that contains some video autoplay crap, or some "funny" animations (or even GIFs?) along the interesting article. CPU usage goes up, even though you don't need or want it. Default WebPositive does not include any options or plugins to allow users to keep such stuff under their control and not everyone uses proxy solutions (adblocking, etc...). If "pause" was available, one could use it to still read article while not wasting CPU time.

Battery draining is a somewhat different problem indeed. However, sometimes you want the websites to keep running (eg. you are playing music on some music stremaing website in the background, or you have gmail and want new mail notifications to be sent). So, you can't really do this on a per-application basis.

Why not allow multiple launch of web browser application then? You could open gmail in one process and the rest in another (keeping video playing while trying to finish long computing task ASAP is not a good idea anyway ;).

The application itself should be able to behave properly, and indeed most web browser will know when they are not focused, and will already reduce CPU use of background tabs (again, notice how this is unrelated to window focus: it's really a matter of what happens in each browser tab).

Yes, new browsers APIs allow JavaScript to know when window is active or not, and act accordingly. But you have to count on the website owners/developers for that. Most ads and annoying stuff will ignore that anyway.

My conclusion is the same: this is not something the user should care for.

I don't think this issue was created to make users do care about it. ProcessController is available (and i always keep it running, even though i do not use it that often aside from visually checking if CPUs are going crazy or not :) but no one is forcing it on users. It's for those who are interested. So is "pausing applications" idea.

This is something the OS should do right. In no way I can imagine an use for manually freezing and resuming a GUI app.

Quick pause of game, when that game has no such option :)? Quick pause of browser, when malicious scripts are running amok and browser does not know how to handle them?

Think of it like a non-standard but de-facto standard CTRL+C and CTR+V. Only implemented globally so application does not have to implement anything on its side.

The OS should just make it so it runs as fast as possible without draining battery. And applications themselves (eg. web browsers) should be careful to not run useless code at full speed.

Yes, but we're not living in ideal world and having additional option (option, not required step) to handle misbehaving software is not a bad idea.

Anyway, i checked the API: https://www.haiku-os.org/docs/api/classBRoster.html#a2cd20378ab189c4df1eba833f1079dae

Looks like there already is a way to "observe" applications and it could just be extended with a new flag (aside from implementing catching signals and notifications on app server side?).

comment:5 by Janus, 6 years ago

I think you should try Slayer https://github.com/HaikuArchives/Slayer

in reply to:  3 comment:6 by Janus, 6 years ago

Replying to pulkomandy:

My conclusion is the same: this is not something the user should care for. This is something the OS should do right. In no way I can imagine an use for manually freezing and resuming a GUI app. The OS should just make it so it runs as fast as possible without draining battery. And applications themselves (eg. web browsers) should be careful to not run useless code at full speed.

+1

in reply to:  description ; comment:7 by ahwayakchih, 6 years ago

Replying to miqlas:

For Gui programs i can imagine a keyboard/mouse shortcut to freeze/unfreeze application state. For multi-threaded programs the whole process-tree have to be frozen from the selected window (or tab for cli programs).

I prepared proof of concept mini-application and configured Shortcut for it - it works :). It's actually pretty cool to "freeze" and then "unfreeze" browser with a simple key shortcut, instead of clicking around through "manager" menus and/or windows.

Window content gets "broken" visually, after some other app/window is moved above it, just like some people commented. So, without some additional stuff, it may be confusing (looks like buggy application got frozen/hanged ;).

The frozen programs would get a PAUSE symbol overlay.

This may require a lot of hacking (for example: creating windows with overlay bitmap and placing it at the same spot as original windows, and then hiding originals) and/or changes in Haiku "core", so i'm guessing it will not happen anytime soon.

Besides, overlay would prevent user from seeing whatever was last rendered in window.

in reply to:  7 ; comment:8 by miqlas, 6 years ago

Replying to ahwayakchih:

Replying to miqlas:

I prepared proof of concept mini-application and configured Shortcut for it - it works :). It's actually pretty cool to "freeze" and then "unfreeze" browser with a simple key shortcut, instead of clicking around through "manager" menus and/or windows.

Can you share your code, please?

in reply to:  8 ; comment:9 by ahwayakchih, 6 years ago

Replying to miqlas:

Can you share your code, please?

Sure, i created gist at: https://gist.github.com/ahwayakchih/f9b42cac1a8afed28c8e732ab61e3fdf

comment:10 by cb88, 6 years ago

Freezing an application and then saving it's state is something you'd have to do for a sane suspend implementation on Haiku. Why not add extra functionality to process controller, it's certainly rather power user centric anyway already. So instead of just Cancel / Debug / Kill you could also have Pause\Unpause or send to remote machine etc..

Haiku boots fast enough that normal susped isn't much use. But freezing applications and then saving all thier memory to disk, then rebooting, then restoring the applicaition could in fact be useful and has been menitoned by Haiku developers recently as a method of supporting suspend.

I'm mostly regugitating what I was told here but I've heard it discussed several times over the years, Native applicaitons could implement a native suspend method that saves thier state a bit more efficently but you could probably save state on any applicaiton by just freezing all of it's memory and writing it out to disk. Linux does something similar these days where You can even transfer instances of applcations between different computers or VMs. LinuxPMI comes to mind but I'm not sure if that was what I was intending to remember.

Suspending a program you were working in and sending it to your laptop, working in it while traveling then sending it back automatically to your desktop once you got home would be a wicked cool feature. Though obviously it would requite alot of infrastructure that doesn't exist right now (syncronized filesystems and probably some IPC related wrangling etc.. ).

While it may be a few years off the technology exists and I wouldn't be a bit supprised if laptops of the future shipped with some ammount of non volatile ram, mainly because it's cheaper by volume than DRAM perhaps even allowing omission of disk drives from low cost devices. It would likely be attached to PCIE or directly to DDR4/5 etc... that's already a thing in the enterprise space and it will likely eventually trickle down. So instead of saving to disk you just freeze the applcation perhaps compress it and move it into the non volatile area. On unsuspend you'd just reverse te process etc..

I went down the rabbit hole here a bit but hopefully that fires up people's imaginations...

Last edited 6 years ago by cb88 (previous) (diff)

in reply to:  10 ; comment:11 by ahwayakchih, 6 years ago

Replying to cb88:

Freezing an application and then saving it's state is something you'd have to do for a sane suspend implementation on Haiku.

Automatic persistence was one of (main?) features of now dead Unununium OS and then ich:os (http://ichos.sourceforge.net/) - which also seems dead.

BeOS/Haiku actually has API for implementing almost that (BArchivable, BFlattenable), but it has to be implemented per application, which puts heavy burden on developers of every application.

Simply dumping current memory/registers/whatnot of selected application is outside of reach for 3rd party application AFAIK.

Why not add extra functionality to process controller, it's certainly rather power user centric anyway already. So instead of just Cancel / Debug / Kill you could also have Pause\Unpause or send to remote machine etc...

Yes, additional button is one of the ways to implement this on the "system" side (now that ProcessController is part of the "core") and could work quite nice.

Haiku boots fast enough that normal susped isn't much use. But freezing applications and then saving all thier memory to disk, then rebooting, then restoring the applicaition could in fact be useful and has been menitoned by Haiku developers recently as a method of supporting suspend.

Not sure if just dumping memory would do. I mean, if every application has its own address space, so pointers would not have to be "translated", and does not onnect to anything "outside" then maybe? Still, things like port_id, area_id, thread_id, sem_id... all would become either invalid or pointing to a very different target, so there would have to be some way to "reconnect" them, or an API for application to do that... which points us again to BArchivable API, etc...

Linux does something similar these days where You can even transfer instances of applcations between different computers or VMs. LinuxPMI comes to mind but I'm not sure if that was what I was intending to remember.

I wonder how they reconstruct connections to "global" (system-wide) resources. Simply dumping and then reading into RAM may be not enough.

I went down the rabbit hole here a bit but hopefully that fires up people's imaginations...

It's good to have dreams and goals :).

in reply to:  9 comment:12 by miqlas, 6 years ago

Replying to ahwayakchih:

Replying to miqlas:

Can you share your code, please?

Sure, i created gist at: https://gist.github.com/ahwayakchih/f9b42cac1a8afed28c8e732ab61e3fdf

Nice! I pretty like that it can freeze/unfreeze the active program, i already made a shortcut for it and works beautifully. Thanks!

in reply to:  11 comment:13 by tangobravo, 6 years ago

Not sure if just dumping memory would do. I mean, if every application has its own address space, so pointers would not have to be "translated", and does not onnect to anything "outside" then maybe? Still, things like port_id, area_id, thread_id, sem_id... all would become either invalid or pointing to a very different target, so there would have to be some way to "reconnect" them, or an API for application to do that... which points us again to BArchivable API, etc...

Linux does something similar these days where You can even transfer instances of applcations between different computers or VMs. LinuxPMI comes to mind but I'm not sure if that was what I was intending to remember.

I wonder how they reconstruct connections to "global" (system-wide) resources. Simply dumping and then reading into RAM may be not enough.

I guess you'd need some kind of translation layer to "virtualize" all of those resources. Obviously you can suspend the entire state of a VM, move the files somewhere else, and resume where you left off. If each app is effectively running in a VM then the same thing could happen. This is potentially how docker containers work on Linux, but I've never looked into the details there. They have significantly less overhead than using lots of VMs, but generally see a pretty isolated view of the system thanks to the kernel I believe, so might be possible to implement storing and restoring state without needing special code on the app side.

comment:14 by luroh, 5 years ago

Type: bugenhancement
Note: See TracTickets for help on using tickets.