Problems/inconsistencies in power scheme switching...

Started by mjdl, April 25, 2010, 05:52:24 PM

Previous topic - Next topic

mjdl

Since I was one of the people that discussed, back in 2009, the idea of automatically switching power schemes for certain programs, i.e. the anti-sleep/High Performance/Gaming Mode features, I thought it was time I actually tried it, with my newly updated lasso 3.84 installation...

I use a Lenovo Thinkpad notebook w/Windows 7 x86. Lenovo has its own UI to the Windows 7 power scheme infrastructure, a bit nicer and more complete than the Windows default, but the power scheme UIs are completely coordinated, so that things can be changed using either programs(s): new or changed power schemes defined in one are adjustable in the other, and the settings for each scheme are specified separately for battery and for mains power use.

Using the command-line powerfg.exe tool, this is the list of my current power schemes:

powercfg.exe -LIST:

Existing Power Schemes (* Active)
-----------------------------------
Power Scheme GUID: 0209ab81-db53-41d8-93f6-c58ad4d1c8e2  (Timers Off (Screen Off
))
Power Scheme GUID: 03164b9c-9ce5-45af-aab2-95d5f6dac850  (Maximum Performance)
Power Scheme GUID: 1019336e-8043-4773-a667-495b611fa1a0  (Video Playback)
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e  (Balanced)
Power Scheme GUID: 52853127-4e7d-4d08-b3ff-4d1b0a2ea218  (Maximum Battery Life)
Power Scheme GUID: 542e37df-1e59-4eb2-9b88-17fdfbc30e79  (Power Source Optimized
)
Power Scheme GUID: 56f5379d-bf83-434f-aa78-3465ffe2ef16  (Energy Star) *
Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c  (High performance)
Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a  (Power saver)
Power Scheme GUID: ab21624c-83e6-4daf-b02b-75836c9302a1  (Timers off (Presentati
on))
Power Scheme GUID: dc3d28ca-1084-412c-a160-ae0ec9e136a8  (Intervideo WinDVD)

And these are some of the various features that can be configured for each power scheme: (powercfg.exe -ALIASES)

a1841308-3541-4fab-bc81-f71556f20b4a  SCHEME_MAX
8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c  SCHEME_MIN
381b4222-f694-41f0-9685-ff5bb260df2e  SCHEME_BALANCED
fea3413e-7e05-4911-9a71-700331f1c294  SUB_NONE
238c9fa8-0aad-41ed-83f4-97be242c8f20  SUB_SLEEP
29f6c1db-86da-48c5-9fdb-f2b67b1f44da  STANDBYIDLE
9d7815a6-7ee4-497e-8888-515a05f02364  HIBERNATEIDLE
94ac6d29-73ce-41a6-809f-6363ba21b47e  HYBRIDSLEEP
d4c1d4c8-d5cc-43d3-b83e-fc51215cb04d  REMOTEFILESLEEP
7516b95f-f776-4464-8c53-06167f40cc99  SUB_VIDEO
3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e  VIDEOIDLE
90959d22-d6a1-49b9-af93-bce885ad335b  VIDEOADAPT
17aaa29b-8b43-4b94-aafe-35f64daaf1ee  VIDEODIM
aded5e82-b909-4619-9949-f5d71dac0bcb  VIDEONORMALLEVEL
f1fbfde2-a960-4165-9f88-50667911ce96  VIDEODIMLEVEL
0012ee47-9041-4b5d-9b77-535fba8b1442  SUB_DISK
6738e2c4-e8a5-4a42-b16a-e040e769756e  DISKIDLE
4f971e89-eebd-4455-a8de-9e59040e7347  SUB_BUTTONS
7648efa3-dd9c-4e3e-b566-50f929386280  PBUTTONACTION
96996bc0-ad50-47ec-923b-6f41874dd9eb  SBUTTONACTION
5ca83367-6e45-459f-a27b-476b1d01c936  LIDACTION
a7066653-8d6c-40a8-910e-a1f54b84c7e5  UIBUTTON_ACTION
e73a048d-bf27-4f12-9731-8b2076e8891f  SUB_BATTERY
637ea02f-bbcb-4015-8e2c-a1c7b9c0b546  BATACTIONCRIT
9a66d8d7-4ff7-4ef9-b5a2-5a326ca2a469  BATLEVELCRIT
d8742dcb-3e6a-4b3c-b3fe-374623cdcf06  BATACTIONLOW
8183ba9a-e910-48da-8769-14ae6dc1170a  BATLEVELLOW
54533251-82be-4824-96c1-47b60b740d00  SUB_PROCESSOR
bc5038f7-23e0-4960-96da-33abaf5935ec  PROCTHROTTLEMAX
893dee8e-2bef-41e0-89c6-b55d0929964c  PROCTHROTTLEMIN
0e796bdb-100d-47d6-a2d5-f7d2daa51f51  CONSOLELOCK
501a4d13-42af-4429-9fd1-a8218c268e20  SUB_PCIEXPRESS
ee12f906-d277-404b-b6da-e5fa1a576df5  ASPM

(Some of these may not have any kind of UI.)

I pretty much only use "Energy Star", "Maximum Battery Life", and "Presentation (Timers Off)", which I've customized to do the "right thing" when on AC or DC depending on their intent. Simple.

Some observations on how Lasso 3.84 deals with this:

1) When the Process Lasso UI is started (I never autostart the UI, just the Process Governor), the Main menu enumeration of power schemes does not show the tick against the current active power scheme:



2) When I configure wmplayer.exe to be an "anti-sleep" process, Lasso changes the power scheme first, then presents the dialog to configure the anti-sleep processes. However, it chose the "Power Source Optimized" power scheme:



This scheme by default does have various system idle timers activated for both AC and DC use (at least on the Lenovo), so it's not a good choice for "anti-sleep" (how does it make this choice anyway?). So here is my recommendation on this point: either a) add a new panel to the initial configuration Lasso wizard which allows the user to choose which power scheme is deemed the "anti-sleep" one (you could add a considerable amount of intelligence to the panel by using the Windows power APIs to enumerate the idle timers for each scheme and alerting the user when a chosen "anti-sleep" scheme defines idle time-outs) or b) when Lasso is installed, define a custom power scheme--name it something obvious like "Process Lasso Anti-sleep"--with idle timers disabled (just make sure the user can still change the power scheme defaults via the right user permissions on the scheme) and use that for the anti-sleep scheme (and uninstall it when Lasso is uninstalled).

3) When I tried configuring the High Performance process list, Lasso changed the power scheme to "Maximum Battery Life" before presenting the executable choice dialog:



which is completely *not* high performance. Again, I'm not sure how it chooses this scheme, and I think I would prefer one of the alternative choice mechanisms I discussed in (2) above.

4) The tick mark on the "Active Power Scheme" sub-menu can have toggle-like behaviour in conjunction with other programs setting power schemes: let's say I've selected "Balanced" from the sub-menu, which is not one of the Microsoft-provided power schemes enumerated in the Lenovo power manager UI. When I change to a scheme which is enumerated in both applications, say "Maximum Battery Life", via the Lenovo Power manager UI, then Lasso removes the tick mark from the former scheme, but does not detect the new scheme:



5) However, when I change the power scheme a second time in the Lenovo application, it does put the sub-menu tick mark on the right scheme. Then, if I change the scheme right away via the Lasso sub-menu, say from "Presentations" to "Energy Star", then Lasso fails to remove the tick mark from the former power scheme and adds a second, correct tick-mark to the new scheme:



Now, it is philosophically possible that I live in "parallel worlds" (well, it might be a theory among certain nerds who spend their Sunday afternoons testing software...), but this kind of thing will confuse most people. It's probably best solved by having a thread that continually monitors changes in the Windows power scheme state (something in the registry, perhaps?) and call back into the Lasso UI to make the appropriate changes. Such an arrangement will track power scheme changes, no matter what the source.

Finally, when I once more change the power scheme via the Lasso sub-menu, *both* tick marks are removed, as in (4) above, it requires another activation of the same (or different) sub-menu item to display the proper tick mark once more.

Anyway, all these power scheme changing features will be very welcome, once they work. (Maybe they work for others, but not for me right now.)

As always, I'm impressed with the quality of the software: everything else seems to work as advertised (quickly tested, of course).

Jeremy Collake

#1
I need to go through this in detail, but the basic problem is that Process Lasso is using pre-defined system GUIDs (globally unique identifiers) for the 3 default power schemes in Vista+ (High Performance, Balanced, and Power Saver). In your case, since these system default power schemes have been changed, the power schemes that happen to match the system default GUIDs are the ones being used. In theory, they should be customized in such a way so that the original system GUIDs for High Performance, Balanced, and Power Saver still correspond to power schemes that match those attributes, but there is no rule that says that MUST be the case. Further, the other inconsistencies (i.e. double ticks) are also due to the customized power schemes. I simply did not anticipate this sort of condition.

I honestly need to go through the code and change the handling of this for cases like this.

Thanks for reporting the problems, I will use this report as a guide to correcting the anomalous behavior. As you surmised, I will likely have to add some new options to specify which power schemes are used, since the pre-defined system GUIDs can clearly not be relied upon in customized configurations like yours. It may be that many companies customize the power schemes, especially on portable devices. Again, I am surprised to see the system default schemes changed to schemes that do not match their original intent. This may cause interoperability problems with other software as well. Regardless, it is something I can and will handle.

I'll keep you updated as I progress on this. I am moving toward v4.00 alpha soon, so will likely address it there since it represents a fairly major change.. UPDATE: On second thought, its not that major.. We'll see. I may partially address it in some minor updates prior to v4.
Software Engineer. Bitsum LLC.

mjdl

Your're quick in reply! Thank you very much.

On further reflection, I think the least disruptive alternative (in the sense of "no surprises" for the end-user) is to simply install ProcessLasso custom energy schemes (with their own unique guids) for each special mode "Game", "HighPerformance", etc. You would have to be extra-careful, I think, about establishing the right user permissions on each such scheme, since even limited privilege users must be able to use/change them. Asking the user to choose (and perhaps to define) a particular scheme for each special mode is really is really going against the user-friendly principle of "Don't make me think". (Yes, this is the "Homer Simpson" school of UI design...)

But that choice depends on the GUIDS for each power characteristic (i.e. processor throttling, idle timers, etc., some of which can be found by looking at the output of the powercfg.exe -ALIASES command) being common across each particular Windows OS version, even if they differ between versions. All a bit complicated! Maybe you will be able to make it work.

Jeremy Collake

Unfortunately, the power schemes are too granular and hardware specific for Process Lasso to try to create its own custom ones. There are too many properties/variables, and it really requires some knowledge of the hardware. While its not impossible, its not something I would dare try. Lenovo can do it because they know what the PC is intended for, and its hardware components, and their capabilities and limitations (because they 'built' it).

The reason I relied upon the 3 pre-defined system GUIDs was that they are consistent in Vista and above. In Vista, the power scheme management code was completely retooled. That is why Process Lasso doesn't support power scheme management in XP, for anyone who may wonder.

These pre-defined GUIDs were created so that programs could differentiate between the 3 basic power schemes without having to rely on names, or individual properties of those power schemes. This is why I was surprised to see customization that changes the 3 basic power schemes into something other than they were originally intended for. I believe this was not the best idea by Lenovo, if the system came configured like this.

IMHO, I believe the core problem here is Lenovo's customization is not appropriately done and/or their program too easily allows users to change the 3 default profiles from their intents to something else (i.e. High Performance changed to Maximum Battery Life). That said, I have to deal with it one way or another, and that way is inevitably going to be asking the user.

Trying to deduce what power scheme is what by name is difficult, as they could be in any language. Similarly, trying to differentiate them based on properties is also difficult, or at least imperfect. There are too many properties to go through, and some may contradict each other. There are also infinite custom properties for additional hardware installed on the system.

In the majority of cases, I can use the 3 pre-defined system profiles. So, for most users I can not ask by simply examining the power profiles available. If there are only the 3 default ones, then I can assume that they are valid to be used as intended (even if they have been tweaked by the user, their intents should remain the same). If there are more power schemes, then I have to assume the power schemes could mean anything, and the High Performance power scheme could have been changed to Maximum Battery Power, or something similar (again, as improper as I think that change would be). In such a case, I would have to prompt the user with available power schemes.

So.. in short.. programmatically, asking the user in such cases is very much preferred to trying to create my own power schemes. It is simply safer, easier, and more appropriate. It also doesn't have any cleanup problems. People do improper uninstalls every day, and I'd hate to leave a bunch of new power schemes laying around.

There's some more to think about.. but I will be working on this. I'm pretty sure this is the route I'll take, but will keep an open mind.

Thanks ;)
Software Engineer. Bitsum LLC.

Jeremy Collake

#4
BTW, as I was reading your original post in detail (I skim at first, sorry..).. Just FYI, the anti-sleep feature is actually not done by changing power schemes, but instead done by continually resetting the idle timer every few seconds. Only the gaming mode and High Performance features change the active power scheme, and attempt to change it to 'High Performance' in both cases. If only all customization utilities adhered to the GUID for 'High Performance' meaning 'High Performance'.. then no problems, BUT...

Now, how the power scheme became changed I don't know.. it may have automatically been changed by the Lenovo software, based on the idle timer being reset? Or perhaps inadvertently changed some other way. Regardless, its not really the issue here, I just figured I'd clear that up.

So.. the anti-sleep *should* work fine for your PC, no matter what power scheme, since its not based on the power scheme. I reset the idle timer frequently enough to where no power scheme (within reason) should allow the display or PC to sleep during anti-sleep mode.
Software Engineer. Bitsum LLC.

mjdl

Quote from: jeremy.collake on April 26, 2010, 04:22:18 PM
BTW, as I was reading your original post in detail (I skim at first, sorry..).. Just FYI, the anti-sleep feature is actually not done by changing power schemes, but instead done by continually resetting the idle timer every few seconds. Only the gaming mode and High Performance features change the active power scheme, and attempt to change it to 'High Performance' in both cases.

[...]

So.. the anti-sleep *should* work fine for your PC, no matter what power scheme, since its not based on the power scheme. I reset the idle timer frequently enough to where no power scheme (within reason) should allow the display or PC to sleep during anti-sleep mode.

O.K., let me check this more thoroughly.

Anti-sleep processes: I just started the Lasso UI, and chose the "Configure anti-sleep processes..." menu item. The active power scheme changed immediately from my current choice "Presentation" to "Optimized Power Source", the Lasso "Power Scheme has been changed" dialog was displayed, I clicked OK, and the anti-sleep processes UI was displayed. I added "wmplayer.exe" to the list.

I then looked at the "Active Power Scheme" entry on the main menu: as in para. (5) of my original post above, both power schemes ("Presentation" and "Optimized Power Source" had tick marks--I verified via powercfg.exe that the Lasso choice was actually the currently active one.

Using the Lenovo power manager, I switched to "Energy Star". The Lasso menu tick mark tracked that change (but "Presentation" also remained ticked). I started "wmplayer.exe": the power-scheme did not change, as expected. (I'm assuming the idle time-out was adjusted, there's no way of checking that, other than waiting around.)

Games processes: OK, I remove "wmplayer.exe" from the anti-sleep list and add it to the "Game" processes list (choosing that menu entry does not provoke a power scheme change). I verify that starting the player switches the computer automatically to "High Performance" from whatever scheme it's currently using, and switches back when the program exits.

High Performance processes: Using the same test plan as for Game processes, putting "wmplayer.exe" on the High Performance process list dialog provokes a change to the "Maximum Battery Life" scheme, but once the process is on that list, Lasso correctly toggles back and forth between the "High Performance" power scheme when "wmplayer.exe" is running and the user's current power scheme.

Are the changes in power schemes when using the Game and High Performance process lists something you planned? It seems bizarre. In any case, it seems that the actual process-driven switching of power schemes works as intended, very smoothly. The active Power Scheme sub-menu still has problems with the double-ticking when power schemes are changed by other programs, but the sub-menu does change schemes entirely correctly.

I've come around to your point-of-view: the simplest solution is to have something like a drop-down list of power schemes currently defined on the machine to choose from on the Game and High Performance process list dialogues. Make the "High Performance" power scheme the default for both, so that 95% of users won't need to change the option. Or, if you are confident that this power scheme exists and has the default characteristics on all machines, just eliminate the option. But I prefer the choice, since people may have slightly different ideas about the power scheme parameters of a game or high performance process. (For instance, I would still specify CPU scaling for both, since keeping the CPU at maximum speed--which is what the "High Performance" power scheme does by default on my machine--just generates unnecessary heat.)

I hope this testing demonstrates that everything is "mostly" working, modulo the problems with menu tick marks, i.e. power scheme status display.

Jeremy Collake

#6
Quote from: mjdl on April 26, 2010, 06:52:43 PM
Anti-sleep processes: I just started the Lasso UI, and chose the "Configure anti-sleep processes..." menu item. The active power scheme changed immediately from my current choice "Presentation" to "Optimized Power Source", the Lasso "Power Scheme has been changed" dialog was displayed, I
clicked OK, and the anti-sleep processes UI was displayed. I added "wmplayer.exe" to the list.
...

Are the changes in power schemes when using the Game and High Performance process lists something you planned?

No, they weren't intentional, and I figured out what is going on - thanks to your detailed report. It is that the addition of so many power schemes is confusing the menu item handler. This results in Process Lasso switching to another power scheme because it thought you were trying to do just that (as opposed to just configuring anti-sleep processes, high performance processes, or gaming processes).

UPDATE: I have confirmed this bug. When you have more than 5 power schemes, they conflict with the menu item ID for the anti-sleep processes, and other menu items as the count increases. So, you click 'Configure anti-sleep processes', and it thought you just clicked one of your power schemes! I am addressing this ASAP.

Its good to know things mostly work except for this menu item ID confusion.

Thanks again for your assistance, its quite invaluable!
Software Engineer. Bitsum LLC.

Jeremy Collake

I am going to supply you with a test build soon, its a pretty quick and easy fix to give the menu IDs more room. I just released v3.84.1 last night though, and wish I would have waited now. Regardless, it will be in v3.84.2, and will give me some more time to clean up other portions of the code so that it at least handles things decently pending larger improvements in v4.00.
Software Engineer. Bitsum LLC.

mjdl

As you say, the Lenovo Power manager installs several default power schemes in addition to the Windows 7 out-of-the-box. WinDVD also adds its own, although I've never noticed it automatically switching to that one. And I added a copy of the "Presentation" scheme that has an extremely short screen backlight time-out, for those times when I want the notebook to chug away unattended and not go into suspend. So there are a lot of schemes!

The Windows 7 Control Panel lists them all and does not provide a way to customize the 2 "favourite" power schemes that appear in the taskbar icon pop-up, for reasons that only Microsoft's UX experts can probably understand (I would want my own 3 favourites to appear there):



The Lenovo power manager UI gets around this by displaying only its own schemes plus any that the user has created:



So your approach of reworking the menu code to reliably display all these schemes in a long list is probably the only way to go...

OOPS, I just hit preview before posting this, and you've already posted some more thoughts--I'll install a test build, send me a PM on this board (or my email) with the URL or atttachment. Nobody can keep up with you!

Jeremy Collake

What I ended up doing is issuing a silent update to v3.84.1, so please re-download it and give it a try if you would like. I just fixed the anomalous menu item behavior, but that probably cleared up quite a bit. I did not want to make any additional code modifications, it being a silent update and all. I'll keep working at this, and I appreciate your time and reports very much ;).
Software Engineer. Bitsum LLC.

mjdl

OK, I've installed it and run quick tests. All the problems indicated above seem solved, but I'll be able to do a more thorough examination over this weekend, I hope.

Jeremy Collake

Quote from: mjdl on April 29, 2010, 05:52:51 PM
OK, I've installed it and run quick tests. All the problems indicated above seem solved, but I'll be able to do a more thorough examination over this weekend, I hope.

Thanks for reporting the results ;). I don't think further testing is necessary, it should do fine -- though definitely let me know if to doesn't. I've done my own testing and everything seems to be in order. The core problem was as I described, the resource IDs were getting confused due to your large number of power schemes. I'll work on the new power scheme selection configuration, to be shown when necessary, in v4 alpha.

Software Engineer. Bitsum LLC.