[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: 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


Reply to: