rickysarraf / laptop-mode-tools

Power Savings tool for Linux
https://www.researchut.com/tags/laptop-mode-tools/
GNU General Public License v2.0
549 stars 47 forks source link

dependency error? #127

Closed GFdevelop closed 6 years ago

GFdevelop commented 6 years ago

Hello, I have this iussue (command not found): /usr/share/laptop-mode-tools/modules/hal-polling: riga 48: hal-disable-polling: comando non trovato I'm on arch linux, how to solve?

rickysarraf commented 6 years ago

Device polling moved on to the newer kernel interface quite some time ago. Your kernel should be providing that interface.

What kernel are you running? Please note that hal-disable-polling was deprecated/discontinued long time ago. The code there is for fallback and backwards compatibility only.

GFdevelop commented 6 years ago

4.15.10-1-ARCH I can't use hal-polling.conf? I have installed hal package from aur...is this package deprecated?

rickysarraf commented 6 years ago

You can use the module. Just that the code should use the kernel sysfs interface instead of falling back and calling an obsolete/unsupported tool. I am not sure why that is not happening.

To dig further, would you be able to run the hal-polling module in debug mode ? To do so, you need to enable DEBUG=1 in hal-polling.conf and then restart laptop-mode-tools. Then the logs will be logged into syslog/journald.

GFdevelop commented 6 years ago

where are logs? I have errors on boot, journalctl -p 4 -xb

mar 21 10:08:03 archlinux kernel: r8169 0000:04:00.1 enp4s0f1: rtl_ocp_gphy_cond == 1 (loop: 10, delay: 25).
mar 21 10:08:03 archlinux kernel: r8169 0000:04:00.1 enp4s0f1: rtl_ocp_gphy_cond == 1 (loop: 10, delay: 25).
mar 21 10:08:03 archlinux kernel: r8169 0000:04:00.1 enp4s0f1: rtl_ocp_gphy_cond == 1 (loop: 10, delay: 25).
mar 21 10:08:03 archlinux kernel: r8169 0000:04:00.1 enp4s0f1: rtl_ocp_gphy_cond == 1 (loop: 10, delay: 25).
mar 21 10:08:03 archlinux kernel: r8169 0000:04:00.1 enp4s0f1: rtl_ocp_gphy_cond == 1 (loop: 10, delay: 25).
mar 21 10:08:03 archlinux kernel: r8169 0000:04:00.1 enp4s0f1: rtl_ocp_gphy_cond == 1 (loop: 10, delay: 25).

(I'm using r8169aspm-dkms that enable aspm and blacklist default r8169) and this: mar 21 10:08:37 archlinux bluetoothd[15526]: Failed to set mode: Blocked through rfkill (0x12)

manually start laptop_mode:

sudo laptop_mode start
Enabling debug mode for module /etc/laptop-mode/conf.d/ethernet.conf
Enabling debug mode for module /etc/laptop-mode/conf.d/hal-polling.conf
Laptop mode
enabled, active
+ disableDebug /usr/share/laptop-mode-tools/modules/ethernet
+ . /usr/share/laptop-mode-tools/modules/ethernet
#! /bin/sh
#
# Laptop mode tools module: Ethernet power saving tweaks.
#

if [ x$CONTROL_ETHERNET = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_ETHERNET = xauto ]; then

    # Let's check the binaries firts
    if [ -x /sbin/ethtool ]; then
        ETHTOOL=/sbin/ethtool
    elif [ -x /usr/sbin/ethtool ]; then
        ETHTOOL=/usr/sbin/ethtool
    else
        log "VERBOSE" "ethtool is not installed"
        ETHTOOL=/bin/false
    fi

    if [ -x /sbin/mii-tool ]; then
        MIITOOL=/sbin/mii-tool
    elif [ -x /usr/sbin/mii-tool ]; then
        MIITOOL=/usr/sbin/mii-tool
    else
        log "VERBOSE" "mii-tool is not installed"
        MIITOOL=/bin/false
    fi

    if [ -x /bin/ip ]; then
        IPTOOL=/bin/ip
    else
        log "VERBOSE" "ip is not installed"
        IPTOOL=/bin/false
    fi

    # Determine speed capability of physical device
    speed=`$MIITOOL -v $DEVICE 2>/dev/null | grep capabilities | tr ' ' '\n' |\
        sort -n | sed -ne '/^1.*/p' | cut -d "b" -f1`
    if [ -z "$speed" ]; then
        speed=0;
    fi
    max_s=0;
    min_s=100000;
    for s in $speed;
    do
        if [ $s -gt $max_s ]; then
            max_s=$s
        fi
        if [ $s -lt $min_s ]; then
            min_s=$s
        fi
    done
    MAX_SPEED=$max_s;

    case "$THROTTLE_SPEED" in
        "slowest")
            THROTTLE_SPEED=$min_s
            ;;
        "fastest")
            THROTTLE_SPEED=$max_s
            ;;
    esac

    # Carrier detection
    if $IPTOOL link show $DEVICE | grep -q NO-CARRIER; then
        carrier="false";
    else
        carrier="true";
    fi

    # What state we are in
    if [ $ON_AC -eq 1 ]; then
        if [ "$ACTIVATE" -eq 1 ]; then
            THROTTLE_ETHERNET="$LM_AC_THROTTLE_ETHERNET"
        else
            THROTTLE_ETHERNET="$NOLM_AC_THROTTLE_ETHERNET"
        fi

        # One off a case.
        # So that when  back on AC, we can resume the speed back to MAX.
        if [ x$THROTTLE_ETHERNET = x0 ]; then
            THROTTLE_SPEED=$MAX_SPEED;
        fi

        if [ x$DISABLE_ETHERNET_ON_BATTERY = x1 ]; then
            # We are ON_AC and Disable feature is requested
            # So we might be required to re-enable the device.
++ basename /usr/share/laptop-mode-tools/modules/ethernet
            DISABLE_ETHERNET=0 #zero would mean that the device needs be re-enabled.
        else
            DISABLE_ETHERNET=2
            # IF this is the case, don't touch the device for
            # enable/disable
        fi
    else
        THROTTLE_ETHERNET="$BATT_THROTTLE_ETHERNET"

        if [ x$DISABLE_ETHERNET_ON_BATTERY = x1 ]; then
            DISABLE_ETHERNET=1
        else
            DISABLE_ETHERNET=2
        fi
    fi

++ cut -d . -f1
    for DEVICE in $ETHERNET_DEVICES ; do
        log "VERBOSE" "ethernet: $DEVICE"

        # Wakeup-on-LAN handling
        if [ x$DISABLE_WAKEUP_ON_LAN = x1 ] ; then
            ret=`$ETHTOOL -s $DEVICE wol d 2>&1`
            exit_status=$?;
            log "VERBOSE" "$ret"
            if [ $exit_status -eq 0 ]; then
                log "VERBOSE" "Enabled wakeup-on-LAN for $DEVICE"
            else
                log "VERBOSE" "Could not enable wakeup-on-LAN for $DEVICE"
            fi
        fi

        # Handle throttling
        if [ x$THROTTLE_ETHERNET = x1 ] ; then
            # Handle Speed Throttling
            ret=`$ETHTOOL -s $DEVICE speed $THROTTLE_SPEED 2>&1`
            exit_status=$?;
            log "VERBOSE" "$ret";
            if [ $exit_status -eq 0 ]; then
                log "VERBOSE" "Throttled speed to $THROTTLE_SPEED Mbit for $DEVICE"
++ tr '[:lower:]' '[:upper:]'
            else
                log "VERBOSE" "Could not throttle speed for $DEVICE"
            fi
        fi

        # Shut down interface
        if [ x$DISABLE_ETHERNET = x1 -a $carrier = "false" ]; then
            log "VERBOSE" "ethernet: Disabling ethernet device $DEVICE"
            $IPTOOL link set dev $DEVICE down
        elif [ x$DISABLE_ETHERNET = x0 ]; then
            $IPTOOL link set dev $DEVICE up
            log "VERBOSE" "ethernet: Re-enabling ethernet device $DEVICE"
        fi

    done
else
    log "VERBOSE" "Ethernet module is disabled."
fi
++ '[' xauto = x1 ']'
++ sed s/-/_/g
++ '[' x1 = x1 -a xauto = xauto ']'
++ '[' -x /sbin/ethtool ']'
++ ETHTOOL=/sbin/ethtool
++ '[' -x /sbin/mii-tool ']'
++ MIITOOL=/sbin/mii-tool
++ '[' -x /bin/ip ']'
++ IPTOOL=/bin/ip
+++ /sbin/mii-tool -v
+++ grep capabilities
+++ tr ' ' '\n'
+++ sort -n
+++ sed -ne '/^1.*/p'
+++ cut -d b -f1
+ '[' x1 = x1 ']'
+ set +vx
++ speed=
++ '[' -z '' ']'
++ speed=0
++ max_s=0
++ min_s=100000
++ for s in $speed
++ '[' 0 -gt 0 ']'
++ '[' 0 -lt 100000 ']'
++ min_s=0
++ MAX_SPEED=0
++ case "$THROTTLE_SPEED" in
++ THROTTLE_SPEED=0
++ /bin/ip link show
++ grep -q NO-CARRIER
++ carrier=true
++ '[' 0 -eq 1 ']'
++ THROTTLE_ETHERNET=1
++ '[' x1 = x1 ']'
++ DISABLE_ETHERNET=1
++ for DEVICE in $ETHERNET_DEVICES
++ log VERBOSE 'ethernet: enp4s0f1'
++ '[' x1 = x1 ']'
++ '[' -x /usr/bin/logger -a VERBOSE '!=' STATUS ']'
++ '[' VERBOSE = MSG ']'
++ '[' VERBOSE = ERR ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' x0 = x1 ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' 1 = 0 ']'
++ '[' x1 = x1 ']'
+++ /sbin/ethtool -s enp4s0f1 wol d
++ ret=
++ exit_status=0
++ log VERBOSE ''
++ '[' x1 = x1 ']'
++ '[' -x /usr/bin/logger -a VERBOSE '!=' STATUS ']'
++ '[' VERBOSE = MSG ']'
++ '[' VERBOSE = ERR ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' x0 = x1 ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' 1 = 0 ']'
++ '[' 0 -eq 0 ']'
++ log VERBOSE 'Enabled wakeup-on-LAN for enp4s0f1'
++ '[' x1 = x1 ']'
++ '[' -x /usr/bin/logger -a VERBOSE '!=' STATUS ']'
++ '[' VERBOSE = MSG ']'
++ '[' VERBOSE = ERR ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' x0 = x1 ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' 1 = 0 ']'
++ '[' x1 = x1 ']'
+++ /sbin/ethtool -s enp4s0f1 speed 0
++ ret='Cannot advertise speed 0'
++ exit_status=0
++ log VERBOSE 'Cannot advertise speed 0'
++ '[' x1 = x1 ']'
++ '[' -x /usr/bin/logger -a VERBOSE '!=' STATUS ']'
++ '[' VERBOSE = MSG ']'
++ '[' VERBOSE = ERR ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' x0 = x1 ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' 1 = 0 ']'
++ '[' 0 -eq 0 ']'
++ log VERBOSE 'Throttled speed to 0 Mbit for enp4s0f1'
++ '[' x1 = x1 ']'
++ '[' -x /usr/bin/logger -a VERBOSE '!=' STATUS ']'
++ '[' VERBOSE = MSG ']'
++ '[' VERBOSE = ERR ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' x0 = x1 ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' 1 = 0 ']'
++ '[' x1 = x1 -a true = false ']'
++ '[' x1 = x0 ']'

+ disableDebug /usr/share/laptop-mode-tools/modules/hal-polling
+ . /usr/share/laptop-mode-tools/modules/hal-polling
#! /bin/sh
#
# Laptop mode tools module: change HAL polling mode
#

# Some backward compatibility for version 1.42
if [ ! x$BATT_ENABLE_HAL_POLLING  = x ] ; then
    if [ x$BATT_ENABLE_HAL_POLLING  = x1 ] ; then
        BATT_DISABLE_HAL_POLLING=0
    else
        BATT_DISABLE_HAL_POLLING=1
    fi
fi
++ '[' '!' x = x ']'

if [ ! x$AC_ENABLE_HAL_POLLING  = x ] ; then
    if [ x$AC_ENABLE_HAL_POLLING  = x1 ] ; then
        AC_DISABLE_HAL_POLLING=0
    else
        AC_DISABLE_HAL_POLLING=1
    fi
fi
++ '[' '!' x = x ']'

if [ x$CONTROL_HAL_POLLING = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_HAL_POLLING = xauto ]; then
    DISABLE_HAL_POLLING=$BATT_DISABLE_HAL_POLLING
    if [ $ON_AC -eq 1 ] ; then
        DISABLE_HAL_POLLING=$AC_DISABLE_HAL_POLLING
    fi
    if [ x$DISABLE_HAL_POLLING = x1 ] ; then
        DISABLE_HAL_POLLING_CMD="hal-disable-polling --device"
    else
        DISABLE_HAL_POLLING_CMD="hal-disable-polling --enable-polling --device"
    fi

    for DEV in $HAL_POLLING_DEVICES ; do
        # Thanks to the kernel's new in-kernel block dev polling.
        device=`readlink $DEV`;
        if [ -f /sys/block/$device/events_poll_msecs ]; then
            if [ x$DISABLE_HAL_POLLING = x1 ]; then
                echo 0 > /sys/block/$device/events_poll_msecs;
                log "VERBOSE" "Set polling to 0 for device /sys/block/$device/events_poll_msecs"
            else
                echo "-1" > /sys/block/$device/events_poll_msecs;
                log "VERBOSE" "Set polling to -1 i.e. System Default, for device /sys/block/$device/events_poll_msecs"
            fi
        else
            if [ -b "$DEV" ] ; then
                $DISABLE_HAL_POLLING_CMD "$DEV"
                log "VERBOSE" "Executing command $DISABLE_HAL_POLLING_CMD on device $DEV"
            fi
        fi
    done
fi
++ '[' x1 = x1 ']'
++ DISABLE_HAL_POLLING=1
++ '[' 0 -eq 1 ']'
++ '[' x1 = x1 ']'
++ DISABLE_HAL_POLLING_CMD='hal-disable-polling --device'
++ for DEV in $HAL_POLLING_DEVICES
+++ readlink /dev/sr0
++ basename /usr/share/laptop-mode-tools/modules/hal-polling
++ cut -d . -f1
++ tr '[:lower:]' '[:upper:]'
++ sed s/-/_/g
++ device=
++ '[' -f /sys/block//events_poll_msecs ']'
++ '[' -b /dev/sr0 ']'
++ hal-disable-polling --device /dev/sr0
/usr/share/laptop-mode-tools/modules/hal-polling: riga 48: hal-disable-polling: comando non trovato
++ log VERBOSE 'Executing command hal-disable-polling --device on device /dev/sr0'
++ '[' x1 = x1 ']'
++ '[' -x /usr/bin/logger -a VERBOSE '!=' STATUS ']'
++ '[' VERBOSE = MSG ']'
++ '[' VERBOSE = ERR ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' x0 = x1 ']'
++ '[' VERBOSE = VERBOSE ']'
++ '[' 1 = 0 ']'

+ '[' x1 = x1 ']'
+ set +vx
LCD Brightness Command succeeded.
rickysarraf commented 6 years ago

Thanks. It seems you have a device, which is enumerated as /dev/sr0. And this device does not have a block sysfs interface. Hence we fallback to the old HAL way to disabling polling. The only catch being your distribution may not be shipping hal any more, because as far as I know, it is obsolete/unsupported now.

I am still curious how you got /dev/sr0. Because the default configuration sets it at: /dev/scd?. Maybe a symlink. Hmmm.

rickysarraf commented 6 years ago

Can you show me the output of ls /sys/block/ ?

GFdevelop commented 6 years ago

I have changed scd? to sr0... output of ls /sys/block sda@ sr0@ zram0@

dmesg | grep scd (no output) dmesg | grep sr0

[    1.362509] sr 2:0:0:0: [sr0] scsi3-mmc drive: 24x/24x writer dvd-ram cd/rw xa/form2 cdda tray
[    1.362666] sr 2:0:0:0: Attached scsi CD-ROM sr0
rickysarraf commented 6 years ago

Okay. Thanks. So we have 2 things here.

  1. Your device is enumerated as /dev/sr0, which is fine. Perhaps that interface does not have event polling exposed through sysfs. Can you also show the output of: /sys/block/sr0/ ?

  2. hal-disable-polling not being available is understood. HAL was deprecated long ago, and I doubt if there's any distribution shipping it today.

So, to summarize, there's little LMT can do here. Because either of the interfaces that we use is unavailable.

But for 1, there's still an issue. You mentioned that /sys/block did have sr0. But in the logs above, a readlink /dev/sr0 failed. Which led to the fallback hal code. You'll have to dig a little deeper yourself because I do not have any machine with a cdrom drive.

What is the output of readlink /dev/sr0 ?

GFdevelop commented 6 years ago

ls -al /sys/block/sr0/

totale 0
drwxr-xr-x 8 root root    0 22 mar  2018 ./
drwxr-xr-x 3 root root    0 22 mar  2018 ../
-r--r--r-- 1 root root 4096 22 mar 10.54 alignment_offset
lrwxrwxrwx 1 root root    0 22 mar 10.54 bdi -> ../../../../../../../../virtual/bdi/11:0/
-r--r--r-- 1 root root 4096 22 mar 10.54 capability
-r--r--r-- 1 root root 4096 22 mar 10.54 dev
lrwxrwxrwx 1 root root    0 22 mar 10.48 device -> ../../../2:0:0:0/
-r--r--r-- 1 root root 4096 22 mar 10.54 discard_alignment
-r--r--r-- 1 root root 4096 22 mar 10.54 events
-r--r--r-- 1 root root 4096 22 mar 10.54 events_async
-rw-r--r-- 1 root root 4096 22 mar 10.54 events_poll_msecs
-r--r--r-- 1 root root 4096 22 mar 10.54 ext_range
drwxr-xr-x 2 root root    0 22 mar 10.48 holders/
-r--r--r-- 1 root root 4096 22 mar 10.54 inflight
drwxr-xr-x 2 root root    0 22 mar 10.52 integrity/
drwxr-xr-x 2 root root    0 22 mar 10.52 power/
drwxr-xr-x 3 root root    0 22 mar 10.49 queue/
-r--r--r-- 1 root root 4096 22 mar 10.54 range
-r--r--r-- 1 root root 4096 22 mar 10.54 removable
-r--r--r-- 1 root root 4096 22 mar 10.54 ro
-r--r--r-- 1 root root 4096 22 mar 10.54 size
drwxr-xr-x 2 root root    0 22 mar 10.52 slaves/
-r--r--r-- 1 root root 4096 22 mar 10.54 stat
lrwxrwxrwx 1 root root    0 22 mar 10.48 subsystem -> ../../../../../../../../../class/block/
drwxr-xr-x 2 root root    0 22 mar 10.52 trace/
-rw-r--r-- 1 root root 4096 22 mar 10.54 uevent

no output for readlink /dev/sr0

rickysarraf commented 6 years ago

Thank you very much for this output. I can see the problem here with readlink

rrs@priyasi:/tmp$ readlink /tmp/c
b
11:42 ♒♒♒   ☺ 😄    
rrs@priyasi:/tmp$ readlink /tmp/b
11:42 ♒♒♒    ☹ 😟=> 1  
rrs@priyasi:/tmp$ file /tmp/b /tmp/c
/tmp/b: directory
/tmp/c: symbolic link to b
11:42 ♒♒♒   ☺ 😄    

The problem is that for a block device, readlink is returning nothing. Which is the cause of the problem in this case. Let me think what best can be done here.

rickysarraf commented 6 years ago

@GFdevelop Can you please try this fix ? https://github.com/rickysarraf/laptop-mode-tools/commit/53b7b0b0d4e671bf61cf8330c9f5fc3acb7ad829 It should fix your problem. Please report back your results.

rickysarraf commented 6 years ago

Hello @GFdevelop . Any feedback ?

GFdevelop commented 6 years ago

It don't give me hal polling error, hot to check if it work?

rickysarraf commented 6 years ago

In the usual case, the cdrom drive will spin up every 30 seconds or a couple of minutes. I don't recall how often that was. With this setting, the automatic polling gets disabled.

GFdevelop commented 6 years ago

ok I don't have any cdrom in this time, tonight I can do test with a cdrom. Sorry for the wait.

rickysarraf commented 6 years ago

Any feedback @GFdevelop