# laptop-mode-tools error

## equaeghe

When starting/stopping laptop-mode, I get the following error message:

```
/usr/share/laptop-mode-tools/modules/cpufreq: line 11: echo: write error: Invalid argument
```

repeated four times.

I'm using laptop-mode-tools-1.63-r2 and gentoo-sources-3.10.7.

The offending line says:

```
        if ! echo "$2" > "$1" ; then
```

and the arguments are described in the same file as

```
# Set kernel setting, showing an error if this fails.

# Parameter 1: sysctl/proc path

# Parameter 2: the value
```

What might be the problem? I do not know how (with what arguments) this script is called. (I have not encountered any obvious bad behavior related to this error message.)

----------

## eccerr0r

You could instrument it by making it echo out the contents of $1 and $2 to the console...

But did this happen with a new kernel?  Possibly the /proc/* or /sys/* structure changed slightly and what it was sending no longer makes sense to the current kernel.  Or you don't have all the correct options set in your kernel.

----------

## equaeghe

 *eccerr0r wrote:*   

> You could instrument it by making it echo out the contents of $1 and $2 to the console...

 

Hmm, adding echo "(1:$1)" and echo "(1:$2)" (before, inside or outside of the function with the offending line) doesn't do anything

 *eccerr0r wrote:*   

> But did this happen with a new kernel?  Possibly the /proc/* or /sys/* structure changed slightly and what it was sending no longer makes sense to the current kernel.  Or you don't have all the correct options set in your kernel.

 

I guess this is the problem. I think it appeared after installing 3.10.7 to replace 3.8.13. I'll reboot using the previous kernel to see if that fixes this error and then look at the kernel config diff.

----------

## wjholden

I had the same error, having recently upgraded to 3.10.7 and installing laptop-mode-tools for the first time.

Removing the redirect to /dev/null from /etc/init.d/laptop_mode helped to produce more debugging output:

```
start() {

        checkconfig || return 1

        ebegin "Starting laptop_mode"

        # bug #342049 fix

        # check if dir exists and creates if it doesn't

        checkpath -q -d -m 755 /var/run/laptop-mode-tools

        touch /var/run/laptop-mode-tools/enabled

        /usr/sbin/laptop_mode auto >/dev/null  # remove /dev/null to get standard output

        eend $?

}
```

Restarting the laptop_mode daemon now gives much more interesting output:

```
sisig ~ # /etc/init.d/laptop_mode restart       

 * Stopping laptop_mode ...

/usr/share/laptop-mode-tools/modules/cpufreq: line 11: echo: write error: Invalid argument

/usr/share/laptop-mode-tools/modules/cpufreq: line 11: echo: write error: Invalid argument

/usr/share/laptop-mode-tools/modules/cpufreq: line 11: echo: write error: Invalid argument

/usr/share/laptop-mode-tools/modules/cpufreq: line 11: echo: write error: Invalid argument                                                                        [ ok ]

 * Starting laptop_mode ...

Laptop mode 

enabled, not active

/usr/share/laptop-mode-tools/modules/cpufreq: line 11: echo: write error: Invalid argument

SETTING OF KERNEL PARAMETER FAILED: echo ondemand \> /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

/usr/share/laptop-mode-tools/modules/cpufreq: line 11: echo: write error: Invalid argument

SETTING OF KERNEL PARAMETER FAILED: echo ondemand \> /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor

/usr/share/laptop-mode-tools/modules/cpufreq: line 11: echo: write error: Invalid argument

SETTING OF KERNEL PARAMETER FAILED: echo ondemand \> /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor

/usr/share/laptop-mode-tools/modules/cpufreq: line 11: echo: write error: Invalid argument

SETTING OF KERNEL PARAMETER FAILED: echo ondemand \> /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor                                                        [ ok ]
```

Aha! So the error repeats four times because the Core i5 in my laptop appears to Linux as four separate CPUs. So what is this "echo ondemand", and why does it say invalid argument? This is a setting in the kernel that I turned off because the menuconfig recommends "If unsure, say N":

```
  [*] CPU Frequency scaling --->

    [*] CPU Frequency scaling

             Default CPUFreq governor (performance)  ---> 

    -*-     'performance' governor

    <*>   'powersave' governor

    < >    'userspace' governor

    < >    'ondemand' governor

    <*>   'conservative' cpufreq governor
```

Now, I was very surprised to find the word "ondemand" more than once in /etc/. This was caused by gnome-base/gnome-applets +cpufreq, so I set -cpufreq, reinstalled gnome-applets, and then removed sys-power/cpufrequtils.

```
sisig linux # find /etc/ -type f -exec grep -H -i ondemand {} \;

/etc/laptop-mode/conf.d/cpufreq.conf:# includes "ondemand", "conservative", and "performance". The

/etc/laptop-mode/conf.d/cpufreq.conf:BATT_CPU_GOVERNOR=ondemand

/etc/laptop-mode/conf.d/cpufreq.conf:LM_AC_CPU_GOVERNOR=ondemand

/etc/laptop-mode/conf.d/cpufreq.conf:NOLM_AC_CPU_GOVERNOR=ondemand

/etc/conf.d/cpufrequtils:START_OPTS="--governor ondemand"

/etc/conf.d/cpufrequtils:#SYSFS_EXTRA="ondemand/ignore_nice_load=1 ondemand/up_threshold=70"
```

Fixing these variables appears to clear the errors. The command laptop_mode status is useful in verifying everything works as advertised.

With power supply connected:

```
sisig linux # laptop_mode status

Mounts:

   /dev/sda1 on / type ext4 (rw,noatime,commit=0)

 

Drive power status:

   

   /dev/sda:

    drive state is:  active/idle

 

(NOTE: drive settings affected by Laptop Mode cannot be retrieved.)

 

Readahead states:

   /dev/sda1: 128 kB

 

Laptop Mode Tools is allowed to run: /var/run/laptop-mode-tools/enabled exists.

 

/proc/sys/vm/laptop_mode:

   0

 

/proc/sys/vm/dirty_ratio:

   10

 

/proc/sys/vm/dirty_background_ratio:

   5

 

/proc/sys/vm/dirty_expire_centisecs:

   3000

 

/proc/sys/vm/dirty_writeback_centisecs:

   500

 

/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq:

   2501000

 

/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq:

   2501000

 

/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq:

   800000

 

/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq:

   2501000

 

/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq:

   2501000

 

/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_min_freq:

   800000

 

/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq:

   2501000

 

/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_max_freq:

   2501000

 

/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_min_freq:

   800000

 

/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_cur_freq:

   2501000

 

/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_max_freq:

   2501000

 

/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_min_freq:

   800000

 

/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor:

   performance

 

/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor:

   performance

 

/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor:

   performance

 

/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor:

   performance

 

/proc/acpi/button/lid/LID0/state:

   state:      open

 

/sys/class/power_supply/ADP1/online:

   1

 

Laptop mode 

enabled, not active [unchanged]
```

With power supply disconnected:

```
sisig linux # laptop_mode status

Mounts:

   /dev/sda1 on / type ext4 (rw,noatime,commit=600)

 

Drive power status:

   

   /dev/sda:

    drive state is:  active/idle

 

(NOTE: drive settings affected by Laptop Mode cannot be retrieved.)

 

Readahead states:

   /dev/sda1: 1536 kB

 

Laptop Mode Tools is allowed to run: /var/run/laptop-mode-tools/enabled exists.

 

/proc/sys/vm/laptop_mode:

   5

 

/proc/sys/vm/dirty_ratio:

   60

 

/proc/sys/vm/dirty_background_ratio:

   40

 

/proc/sys/vm/dirty_expire_centisecs:

   60000

 

/proc/sys/vm/dirty_writeback_centisecs:

   60000

 

/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq:

   800000

 

/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq:

   2501000

 

/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq:

   800000

 

/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq:

   800000

 

/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq:

   2501000

 

/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_min_freq:

   800000

 

/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq:

   800000

 

/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_max_freq:

   2501000

 

/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_min_freq:

   800000

 

/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_cur_freq:

   800000

 

/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_max_freq:

   2501000

 

/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_min_freq:

   800000

 

/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor:

   powersave

 

/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor:

   powersave

 

/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor:

   powersave

 

/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor:

   powersave

 

/proc/acpi/button/lid/LID0/state:

   state:      open

 

/sys/class/power_supply/ADP1/online:

   0

 

Laptop mode 

enabled, active [unchanged]
```

Had I actually read the manual at http://www.gentoo.org/doc/en/power-management-guide.xml I could have saved myself a lot of trouble figuring all this stuff out on my own.

The kernel configuration describes "ondemand" thusly:

```
'ondemand' - This driver adds a dynamic cpufreq policy governor. The governor does a periodic polling and changes frequency based on the CPU utilization. The support for this governor depends on CPU capability to do fast frequency switching (i.e, very low latency frequency transitions).

To compile this driver as a module, choose M here: the module will be called cpufreq_ondemand.

For details, take a look at linux/Documentation/cpu-freq.

If in doubt, say N.
```

I don't understand why they recommend not using this when in doubt; "ondemand" sounds like the most intuitive, common-sense setting for most uses. I've actually gone through and modified my configuration, since typing up this post, to use "ondemand" on battery and "performance" only when plugged in. "powersave" goes straight to the minimum CPU frequency, which sounds great for saving the earth and extending battery life, but I didn't buy a new computer to go slow.

----------

## equaeghe

 *wjholden wrote:*   

> I had the same error,  [...] "ondemand" sounds like the most intuitive, common-sense setting for most uses. [...]

 

Indeed, ondemand seems like the best all-round option. I had this as my standard governor all along and still don't know what caused the problem. However, because laptop-mode-tools actually didn't (and shouldn't) change this, I just disabled its cpufreq module to get rid of the warnings,

----------

