Timer slack for slacker developers
Timer slack for slacker developers
Posted Oct 17, 2011 23:40 UTC (Mon) by yoe (guest, #25743)Parent article: Timer slack for slacker developers
I think the proper way to implement this is not to force a particular timing upon applications, but to have applications register to use a "slacky" timing when available.
For instance, in response to issues that were found with powertop, an API call was added to glib that would align timeouts on one-second intervals, thereby grouping them together so the processor would only wake up once per second, in the worst case.
Analoguously, glib (or similar libraries for other environments) could provide a way for an application to say "I need to check a condition once in a while. It's probably a good idea to do this fairly often if there's an active user using the system, but it's perfectly fine to slow down a bit if not". The library could then, say, vary the time to a point between two extremes given by the app's programmer, based on the amount of time it's been since the user last did "something". Perhaps the shortest time could even be chosen only if the application in question is actually active.
This way, mail apps can provide mail "instantly" if the user is actively reading mail, but slow down a bit if not. Or so.
Oh hell, just thinking out loud here.
Posted Oct 17, 2011 23:44 UTC (Mon)
by dlang (guest, #313)
[Link] (16 responses)
it would be good to let the application do things to indicate what it needs (the once a second wakeup is a perfect example), but trying to encode all the policy into each application seems like a configuration disaster waiting to happen.
we don't try to have each application configure screen dimming, sleep, etc. Instead we have one power management application on the system that looks at what the system is doing, including what the applications request and hint that they want, but that then makes the decisions on what to do.
This sort of thing seems like it fits in very nicely with the other things the power management app is doing.
Posted Oct 18, 2011 7:00 UTC (Tue)
by cmccabe (guest, #60281)
[Link] (15 responses)
For example, a movie player should keep the system awake for as long as it is playing the movie. Anything less will just result in a lot of frustrated users. This problem is more than theoretical-- I have had this problem under Linux before where the screen has been blanked after a few "idle" minutes playing a movie. Thankfully my current build of mplayer now seems to be able to tell Xorg not to blank the screen, but "clever" solutions like this could reintroduce the same kinds of problems.
Android got this right. An application that needs to keep the phone from going to sleep can take a wakelock. There is zero chance that the phone will, for example, go to sleep in the middle of a phone call because a "clever" power manager thought that not many buttons had been pushed recently.
There are some people who argue that applications should not have the ability to influence power management because application developers cannot be trusted. But this is the worst kind of tribal mentality ("kernel devs good, user space devs bad"). The best thing that we could do as kernel and systems software developers is not to hide functionality from the upper layers, but to make it clear what exactly is going on. We need more tools like powertop that can point a finger at bad code and get it fixed.
Posted Oct 18, 2011 7:05 UTC (Tue)
by dlang (guest, #313)
[Link] (13 responses)
it's perfectly fine for a movie player to tell the power management daemon that it doesn't want the system to go to sleep, but the power management daemon may still decide to save power by shutting down the other 7 cores of an 8-core machine (or slow the clock down, but not so much that the app maxes out the remaining processing time)
Android 'gets it right' only for the simple case of a single core system. for multiple cores the information of an app claiming "I don't want to sleep now" isn't enough
Posted Oct 18, 2011 7:57 UTC (Tue)
by cmccabe (guest, #60281)
[Link] (12 responses)
Well, if you're using an Intel system, the unused cores will be clocked slower by the firmware running on them. cpufreq also has a role, and a bigger role on ARM. I don't think userspace daemons come into play at all here.
Your talk about "slowing the clock down" definitely seems like something that would screw up my movie playback. Even ignoring that issue, what if your externally imposed policy slows down other daemons that the movie player needs to function efficiently? A lot of applications use D-BUS these days. It's pretty clear that messing with timings on the pulseaudio daemon will probably cause audio glitches and dropouts in my movie playing, even though you oh so kindly allowed the movie player to continue running. Or If the movie player is embedded in Firefox, and you decide to mess with that process, there could also be problems.
If application developers want to opt in to a lazy clock policy, that is fine. We should set up a system call that allows them to do that, and start making use of that. But it shouldn't be forced on developers who don't want it.
Incidentally, kernel developers get really mad when other folks pull the same kind of "for your own good" BS on them-- for example, when hard drives "optimize" by not actually flushing the writes out to disk when they're told to do so.
At the end of the day, if you take away the ability of stupid people to do stupid things, you also take away the ability of smart people to do smart things. We have enough application developers out there that we can afford to install the programs written by the smart ones and ignore or fix the rest.
> Android 'gets it right' only for the simple case of a single core
Wakelocks and cpufreq are two distinct systems with different roles.
In general, Android's approach is to allow the application to use as much CPU as it wants, but to have good monitoring tools that allow users to spot and de-install CPU hogs. However, you need certain capabilities to do things like take a wakelock.
Posted Oct 18, 2011 8:18 UTC (Tue)
by dlang (guest, #313)
[Link] (11 responses)
for every scenario that someone paints where this could be useful, there is going to be another scenario where it could be misused.
but the same thing can apply to 'renice' or 'ionice' as well, why aren't you also opposed to the ability for the evil (or clueless) system administrator to mess with the application by changing it's priority.
or for that matter ulimit can cause programs to fail, it should be ripped out of the system, instead every applications should be audited to make sure it only allocates the resources that it really needs, and the applications should then be changed to cooperatively give up resources if something else needs it.
for that matter, what about preemptive time slicing, the system is more efficient if the applications cooperate instead, so we should just change every application to do cooperative time slicing, including setting the priority between applications (after all, doesn't the application writer know what's best for the applications)
why are all of these ways for an administrator to control what's happening with their machine acceptable, but the idea that the administrator could override the application's decision (or lack thereof) on timer slack be so horrible?
Posted Oct 18, 2011 9:28 UTC (Tue)
by dgm (subscriber, #49227)
[Link] (10 responses)
Thus, I would say: if this gets finally in, advise to distributions and admins to NOT use it, unless you understand in gory detail ALL the implications. With great power... yada, yada, yada.
Frankly, I would add that using cgroups with this is calling for abuse. Make it a per process option and it will become much less "dangerous".
Posted Oct 18, 2011 14:18 UTC (Tue)
by bronson (subscriber, #4806)
[Link] (2 responses)
Posted Oct 18, 2011 16:35 UTC (Tue)
by dgm (subscriber, #49227)
[Link]
Of course, if the group hierarchy is standardized, processes known to behave badly can be moved out of the group, but it would mean modification of the process, thus (at least partially) negating the benefits of being able to do it without changing code.
Posted Oct 18, 2011 16:56 UTC (Tue)
by Cyberax (✭ supporter ✭, #52523)
[Link]
cgroups allow to do it atomically.
Posted Oct 18, 2011 17:49 UTC (Tue)
by dlang (guest, #313)
[Link] (6 responses)
in all cases you can cause an application being limited to behave in ways different from what the application programmer expected.
Posted Oct 18, 2011 21:40 UTC (Tue)
by cmccabe (guest, #60281)
[Link] (5 responses)
nice and ulimit are also things specified by POSIX and implemented by many other operating systems. Like Linus said, Linux-specific interfaces tend not to get very much use, even when they're much better than the standard interfaces they're replacing. In this case, you're talking about adding a platform specific interface that is not better than what it's replacing, just different. It's also an interface that application developers have no easy way to opt-out of. IMHO, not a win at all.
Posted Oct 18, 2011 22:23 UTC (Tue)
by dgm (subscriber, #49227)
[Link] (2 responses)
Posted Oct 18, 2011 22:37 UTC (Tue)
by dlang (guest, #313)
[Link] (1 responses)
normally this further amount is relatively short, but if the system is under high load it could be a significant amount of time (if the system is swapping badly, it could be seconds after the timer is scheduled to fire before the application executes)
this is just changing things to that some other suitably privileged task in the system can increase the maximum lag that the application sees.
it's not something that can't happen today.
Posted Oct 19, 2011 13:39 UTC (Wed)
by dgm (subscriber, #49227)
[Link]
Posted Oct 18, 2011 22:33 UTC (Tue)
by dlang (guest, #313)
[Link] (1 responses)
as I see it there is no knob that you (as an administrator) can twist for this today.
there's also no knob that you as a application programmer can twist that will change the slack for you and your running children, instead you would have to have each child invoke the change independently.
Posted Oct 19, 2011 2:08 UTC (Wed)
by cmccabe (guest, #60281)
[Link]
The one use case that is intriguing is synchronizing application timers so that a lot of them fire at once, in order to save on wakeups. I honestly can't think of any good way to do this with the existing timeout APIs-- maybe someone else can.
All these comments about "slack" are making me think of this guy:
Posted Oct 19, 2011 7:16 UTC (Wed)
by Rudd-O (guest, #61155)
[Link]
This is why the policy belongs in the power management application, not in the user applications (which should, of course, have a mechanism available to commandeer the power management application or otherwise override policy decisions).
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
> daemon that it doesn't want the system to go to sleep, but the
> power management daemon may still decide to save power by shutting
> down the other 7 cores of an 8-core machine (or slow the clock down,
> but not so much that the app maxes out the remaining processing time)
> system. for multiple cores the information of an app claiming "I
> don't want to sleep now" isn't enough
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
Timer slack for slacker developers
http://en.wikipedia.org/wiki/File:Bobdobbs.png
Timer slack for slacker developers