FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 07-12-2008, 06:56 AM
Arthur A
 
Default Applying correct hdparm values after resuming from suspend

Hi list,

I'm using Debian Lenny with Laptop-mode tools that I've configured to manage my
laptop's hd, which is controlled by firmware that gives insane load cycle
values. Thus, I've enabled laptop-mode-tools and it currently applies a setting
of 254 (disabled) when running on AC and 128 (enabled and aggressive pm
settings) when running on battery. This works fine on boot, and when removing or
inserting the AC power. However, upon resume a setting of 128 is applied
regardless of the machine's powerstate.


I believe that laptop-mode is being restarted correctly since if I remove and
reinsert the AC cord the correct hdparm settings (254) are applied. My guess is
that something is also being re-initialized upon resume from suspend that is
over-riding laptop-mode-tools. In any event, I thought that the simplest fix for
this would be to add a script to /etc/pm/sleep.d/01-hdparm-power-check which
would do nothing if going to sleep, and if resuming would check whether the
computer was running on ac, and if so apply hdparm -B 254 /dev/sda


My problem lies in this second part, as I'm not sure how to correctly do a
check, the rest of it I can steal from other scripts included under
/usr/lib/pm-utils/sleep.d/


This is what I think 01-hdparm-power-check would look like:
=====================================
#
#!/bin/sh
# Check to see if we are running on AC power, and if so,
# override mystery program overriding laptop-mode.conf

. "${PM_FUNCTIONS}"

if cat /proc/acpi/ac_adapter/C1AB/state = off-line || exit $NA

case "$1" in
hibernate|suspend)
;;
thaw|resume)
hdparm -B 254 /dev/sda
;;
*) exit $NA
;;
esac
======================================

As you can see, I don't know much (anything) about bash scripting. Your advice,
assistance, criticism or concerns would be greatly appreciated.


Best,

AA



NOTE: I originally posted this to debian-laptop, but there does not seem to be
much traffic on that list. I have also tried posting this to Bart Samwell's
laptop-mode-tools waiting list, but there appears to be virtually no traffic there.



--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-12-2008, 03:24 PM
Florian Kulzer
 
Default Applying correct hdparm values after resuming from suspend

On Sat, Jul 12, 2008 at 09:56:35 +0300, Arthur A wrote:
> Hi list,
>
> I'm using Debian Lenny with Laptop-mode tools that I've configured to
> manage my laptop's hd, which is controlled by firmware that gives insane
> load cycle values. Thus, I've enabled laptop-mode-tools and it currently
> applies a setting of 254 (disabled) when running on AC and 128 (enabled
> and aggressive pm settings) when running on battery. This works fine on
> boot, and when removing or inserting the AC power. However, upon resume a
> setting of 128 is applied regardless of the machine's powerstate.
>
> I believe that laptop-mode is being restarted correctly since if I remove
> and reinsert the AC cord the correct hdparm settings (254) are applied.
> My guess is that something is also being re-initialized upon resume from
> suspend that is over-riding laptop-mode-tools. In any event, I thought
> that the simplest fix for this would be to add a script to
> /etc/pm/sleep.d/01-hdparm-power-check which would do nothing if going to
> sleep, and if resuming would check whether the computer was running on
> ac, and if so apply hdparm -B 254 /dev/sda
>
> My problem lies in this second part, as I'm not sure how to correctly do
> a check, the rest of it I can steal from other scripts included under
> /usr/lib/pm-utils/sleep.d/
>
> This is what I think 01-hdparm-power-check would look like:

[...]

I would first check if the "on_ac_power" command works reliably on your
system. If you run

on_ac_power; echo $?

then you should get 0 (true) if you are connected to AC power and 1
(false) if you are running on battery. (See "man on_ac_power"; the "echo
$?" part is necessary to print the exit status.)

If that is OK then your script should work like this:

=====================================
#!/bin/sh
# Check to see if we are running on AC power, and if so,
# override mystery program overriding laptop-mode.conf

. "${PM_FUNCTIONS}"

on_ac_power || exit $NA

case "$1" in
hibernate|suspend)
;;
thaw|resume)
hdparm -B 254 /dev/sda
;;
*) exit $NA
;;
esac
======================================

The double pipe "||" is the logical OR operator. If on_ac_power returns
true then the OR expression is already true overall and the shell will
therefore not even bother to evaluate the second argument; it goes
directly to the case structure. If on_ac_power returns false, on the
other hand, then the shell has to evaluate the second argument, which
makes it exit with status $NA.

Note: I have to admit that I am not entirely sure about the role of the
$NA variable; I assume it is properly defined in the context of these
scripts since many of the other sleep.d hooks use it in the same way.

--
Regards, | http://users.icfo.es/Florian.Kulzer
Florian |


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-13-2008, 09:02 AM
Arthur A
 
Default Applying correct hdparm values after resuming from suspend

Florian Kulzer wrote:

On Sat, Jul 12, 2008 at 09:56:35 +0300, Arthur A wrote:

Hi list,

I'm using Debian Lenny with Laptop-mode tools that I've configured to
manage my laptop's hd, which is controlled by firmware that gives insane
load cycle values. Thus, I've enabled laptop-mode-tools and it currently
applies a setting of 254 (disabled) when running on AC and 128 (enabled
and aggressive pm settings) when running on battery. This works fine on
boot, and when removing or inserting the AC power. However, upon resume a
setting of 128 is applied regardless of the machine's powerstate.


I believe that laptop-mode is being restarted correctly since if I remove
and reinsert the AC cord the correct hdparm settings (254) are applied.
My guess is that something is also being re-initialized upon resume from
suspend that is over-riding laptop-mode-tools. In any event, I thought
that the simplest fix for this would be to add a script to
/etc/pm/sleep.d/01-hdparm-power-check which would do nothing if going to
sleep, and if resuming would check whether the computer was running on
ac, and if so apply hdparm -B 254 /dev/sda


My problem lies in this second part, as I'm not sure how to correctly do
a check, the rest of it I can steal from other scripts included under
/usr/lib/pm-utils/sleep.d/


This is what I think 01-hdparm-power-check would look like:


[...]

I would first check if the "on_ac_power" command works reliably on your
system. If you run

on_ac_power; echo $?

then you should get 0 (true) if you are connected to AC power and 1
(false) if you are running on battery. (See "man on_ac_power"; the "echo
$?" part is necessary to print the exit status.)

If that is OK then your script should work like this:

=====================================
#!/bin/sh
# Check to see if we are running on AC power, and if so,
# override mystery program overriding laptop-mode.conf

. "${PM_FUNCTIONS}"

on_ac_power || exit $NA

case "$1" in
hibernate|suspend)
;;
thaw|resume)
hdparm -B 254 /dev/sda
;;
*) exit $NA
;;
esac


It worked great. I've tested it resuming on batteries and on ac, and it works
perfect. pm-util.logs show no problems.


Thanks so much!

Best,
AA


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-14-2008, 02:45 PM
Arthur A
 
Default Applying correct hdparm values after resuming from suspend

Florian Kulzer wrote:

On Sat, Jul 12, 2008 at 09:56:35 +0300, Arthur A wrote:

Hi list,

I'm using Debian Lenny with Laptop-mode tools that I've configured to
manage my laptop's hd, which is controlled by firmware that gives insane
load cycle values. Thus, I've enabled laptop-mode-tools and it currently
applies a setting of 254 (disabled) when running on AC and 128 (enabled
and aggressive pm settings) when running on battery. This works fine on
boot, and when removing or inserting the AC power. However, upon resume a
setting of 128 is applied regardless of the machine's powerstate.


I believe that laptop-mode is being restarted correctly since if I remove
and reinsert the AC cord the correct hdparm settings (254) are applied.
My guess is that something is also being re-initialized upon resume from
suspend that is over-riding laptop-mode-tools. In any event, I thought
that the simplest fix for this would be to add a script to
/etc/pm/sleep.d/01-hdparm-power-check which would do nothing if going to
sleep, and if resuming would check whether the computer was running on
ac, and if so apply hdparm -B 254 /dev/sda


My problem lies in this second part, as I'm not sure how to correctly do
a check, the rest of it I can steal from other scripts included under
/usr/lib/pm-utils/sleep.d/


This is what I think 01-hdparm-power-check would look like:


[...]

I would first check if the "on_ac_power" command works reliably on your
system. If you run

on_ac_power; echo $?

then you should get 0 (true) if you are connected to AC power and 1
(false) if you are running on battery. (See "man on_ac_power"; the "echo
$?" part is necessary to print the exit status.)

If that is OK then your script should work like this:

=====================================
#!/bin/sh
# Check to see if we are running on AC power, and if so,
# override mystery program overriding laptop-mode.conf

. "${PM_FUNCTIONS}"

on_ac_power || exit $NA

case "$1" in
hibernate|suspend)
;;
thaw|resume)
hdparm -B 254 /dev/sda
;;
*) exit $NA
;;
esac
======================================

The double pipe "||" is the logical OR operator. If on_ac_power returns
true then the OR expression is already true overall and the shell will
therefore not even bother to evaluate the second argument; it goes
directly to the case structure. If on_ac_power returns false, on the
other hand, then the shell has to evaluate the second argument, which
makes it exit with status $NA.


Note: I have to admit that I am not entirely sure about the role of the
$NA variable; I assume it is properly defined in the context of these
scripts since many of the other sleep.d hooks use it in the same way.



Worked a treat. Wish I could explain how great it feels to finally have this
fixed. Thanks much!


Best,
AA


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 12:00 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org