You are not logged in.
Hello,
I've made a powersave script that uses pm-powersave to decide whether it should turn on power saving (true) or restore the defaults (false).
However, I've switched to systemd now and that does not support pm-utils. This means I'll have to find another way to read whether or not the laptop is using AC or battery. I've looked briefly at laptop-mode-tools' source and AFAIK it does so with a udev rule:
ACTION=="change", SUBSYSTEM=="power_supply", RUN+="/lib/udev/lmt-udev auto"
Is this the way I should go, to be able to let my script determine if I'm on battery or AC? If so, then how can I make this udev rule see if I'm on AC or battery? If possible, I'd like to make a rule that detects AC and then runs powersave false and (either in the same rule or another one, I won't mind using two rules) when it detects battery that it runs powersave true.
Is this possible? Are there any better ways to accomplish what I want?
Thanks in advance!
Last edited by Unia (2012-09-02 13:13:29)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
I'm using systemd and pm-utils right now, without any kind of problem...what are you referring to? I didn't know systemd doesn't support pm!
Offline
I'm using systemd and pm-utils right now, without any kind of problem...what are you referring to? I didn't know systemd doesn't support pm!
I mean, it doesn't support sleep/hibernate using pm-utils and as such, it seems a bit redundant to keep it on my system only to run my script. That's why I'm looking for an alternative way to read AC/battery status.
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Yes, since upower 0.9.18 it is true.
I was having the same thought...i use pm only to use my powersave function.
I asked systemd developer to implement pm-powersave functions in systemd (since it already handles some acpid events and pm-suspend/hibernate) but i wasn't convinced.
So i asked the upower developer to make upower run every script i want, instead of the only /power.d/* . But again, he told me that powersave script aren't so useful, because what it's good on battery is also good on ac...so don't know how can we reach this behaviour without pm-utils for now.
Offline
If I can just find out how other applications read whether the system is on AC or battery, I can make my script work.
So, can anyone answer this?
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Well, if you find the right way, i hope you'll share it with us
Offline
/sys/class/power_supply/BAT1/status
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
...he told me that powersave script aren't so useful, because what it's good on battery is also good on ac...
I have always been skeptical regarding all these powersave scripts. Shouldn't the kernel know best about the settings? Are all these settings actually useful? Do they actually save power? Especially the cpufreq powersave governor: I read somewhere (don't have a source, sorry) that it does't actually save power. The ondemand governor may increase the frequency on load, but therefore the cpu is also done faster with the job and can idle longer. So all in all, it doesn't really make sense to use anything other than ondemand.
I'm not saying that these power saving scripts are completely useless - I don't know that. But I would love to see some comparions on how much effect all these settings actually have.
I know I haven't actually helped here, but I wanted to get his off my mind, sorry....
Offline
Sorry for the OT:
Yes, i use conservative governor, a little tweaked. I know powersave governor is useless.
But since with my script my battery life has increased of something like 30-40%, i guess those settings aren't at least so bad.
Yes, we can use our de-power-manager (in my case xfce-p-m), but they lack of lots of settings. And i prefer to have my hard disk power management set the way i like, not the way xfce developers like.
/close OT.
Offline
nierro wrote:...he told me that powersave script aren't so useful, because what it's good on battery is also good on ac...
I have always been skeptical regarding all these powersave scripts. Shouldn't the kernel know best about the settings? Are all these settings actually useful? Do they actually save power? Especially the cpufreq powersave governor: I read somewhere (don't have a source, sorry) that it does't actually save power. The ondemand governor may increase the frequency on load, but therefore the cpu is also done faster with the job and can idle longer. So all in all, it doesn't really make sense to use anything other than ondemand.
I'm not saying that these power saving scripts are completely useless - I don't know that. But I would love to see some comparions on how much effect all these settings actually have.
I know I haven't actually helped here, but I wanted to get his off my mind, sorry....
The general solutions (DE-dependant powermanagers, laptop-mode-tools, cpu frequency) don't save that much power. However, Taylorchu's powerdown (find here on Community Contributions) and my script (based on Taylorchu's) do save alot of power. Without my script, I get ~1 hour of battery life. With my script, it's ~1:45. That's roughly 75% more! (and yes, my battery is fried, I know )
Trilby, I know about the /sys interface. But to my knowledge, I'd have to make a script loop in checking that directory. I don't think this is the best solution, e.g. I think (if possible) udev rules or something along those lines is cleaner.
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Ah, sorry, I didn't read very carefully. I just read up to wanting a script to know if you were on battery or AC.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Will something like
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/etc/mypowersavescript true"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/etc/powersavescript false"
work?
EDIT: i'm studying and i have no time to try it, so, please, tell me whether it works or not! Thanks!
Last edited by nierro (2012-09-02 12:54:03)
Offline
Will something like
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/etc/mypowersavescript true" SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/etc/powersavescript false"
work?
EDIT: i'm studying and i have no time to try it, so, please, tell me whether it works or not! Thanks!
You the man! I had already found this on Launchpad: https://bugs.launchpad.net/ubuntu/+sour … bug/250355
But that didn't work. What you proposed, however, does work!
I've updated everything on GitHub so should someone want to test, you can find it there. The PKGBUILD is in the PKGBUILDS repo.
Thanks everyone!
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Glad it helps you, and me too
Well, can you tell me how will you set the right state after a suspend cycle? (you know, we now have /usr/lib/pm-utils/sleep.d/00powersave. But without pm-utils, how can we reach that?)
As i thought, udev can't handle suspend/hibernate. (yes i *was* studying )
So, we have to create a suspend script for systemd in /usr/lib/systemd/system-sleep/powersave and inside it, make a check whether we're on battery or ac and do the right thing.
EDIT: ok, if someone need it, here it is:
cat /usr/lib/systemd/system-sleep/00powersave
#!/bin/sh
case $1 in
pre) /etc/powersave false ;;
post)
if cat /sys/class/power_supply/ADP1/online | grep 0 > /dev/null 2>&1
then
/etc/powersave true
else
/etc/powersave false
fi
;;
esac
exit 0
Be aware that ADP1 is fine for my notebook, but probably not for yours (AC0 is quite often right).
And now, pm-utils is no more a dep of upower, please remove it!
pacman -Rdd pm-utils
is something i had always wait to do! And finally, i got it!
EDIT2: no, i did not get it indeed. It seems that xfce4 relies on pm-utils to suspend/hibernate, even if i'm using upower 0.9.18...Don't know why, but without pm-utils, i can't suspend/hibernate from menu, or closing the lid anymore.
I do not want to use acpid, or create buttons on my panel to run "systemctl suspend". And i want to go on using xfce4-power-manager. So i'll stick with pm-utils only as dep of upower and xfce, waiting for a patch for xfce-p-m.
Last edited by nierro (2012-09-02 14:04:56)
Offline
That's something I can't test, sorry. I don't use a DE nor a power manager.
For me, it all works now. Unplug laptop -> powersave true. Plug back in -> powersave false. When I unplug and suspend, it wakes up with powersave true. When I suspend and then unplug, it wakes up and sets powersave true.
I only used upower to run my script and only had pm-utils for its pm-powersave function and its sleep function. Now I don't need either of it anymore, not do I need acpid to run pm-suspend when the lid is closed.
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Are you using the "/usr/lib/systemd/system-sleep/00powersave" script or for you it magically works out of the box?
Offline
┌─[jente @ lappy ~] 16:34:07
└─■ cat /usr/lib/systemd/system-sleep/00powersave
cat: /usr/lib/systemd/system-sleep/00powersave: Bestand of map bestaat niet
Don't have it
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Wow, I had to use it indeed!
very strange, well, as always, i'm not lucky enough to get everything work as expected
Last edited by nierro (2012-09-02 14:37:22)
Offline
Wow, I had to use it indeed!
very strange, well, as always, i'm not lucky enough to get everything work as expected
I'm just glad I'm not that person this time
Happy you got it working after all!
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
I think this should be added somewhere in the wiki. I can do this, but...where can i add this? Under systemd page, or under laptop page?Or under pm-utils page?
EDIT:@unia: well, it seems on my netbook the udev rule is enough indeed...without the system-sleep script, it works! But why on my home laptop it needs that script? Well, as long as it work anyway, i won't mind
Last edited by nierro (2012-09-02 15:58:43)
Offline
Yes, I suppose we could add this somewhere to the wiki. It's not systemd specific, and has nothing to do with pm-utils.
I think laptop would be a nice category, and perhaps make a a small intro on it on the systemd page which links to the full article?
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Here it is: https://wiki.archlinux.org/index.php/La … _udev_rule
If anyone of you can improve it, any help is welcomed!
Offline
Are you using one udev rule with two lines? I'm using two. Otherwise, it looks good. Only the spelling is a bit messy, but I guess that's because you're from Italy I don't want to offend you, but shall I fix that?
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Yes, fix everything...nope it's not because i'm from italy, it's because i've been using my laptop all day to study and then to test that udev rule...i'm really tired
And yes, i use a two lines single rule.
Thanks!
Last edited by nierro (2012-09-02 18:15:17)
Offline
nierro/unia your script works great I may be able to get rid of pm-utils once I get that upower update (although I have a feeling gnome power manager will probably do the same thing xfce power manager is doing for you and require it anyway haha)
EDIT: Yeah, even with the new upower gnome and/or upower still needs pm-utils to work correctly. If I Rdd pm-utils then gnome will not suspend (just goes to black screen and I have to hard reset, also suspend option disappears from gnome status menu)
EDIT2: I also do not need the 00powersave script here. I can unplug (and it enabled powersave) > suspend > plug and when it wakes powersave is disabled. Good thing you already have an easy workaround script for those that it won't work for though!
Last edited by bwat47 (2012-09-09 15:59:07)
Offline