User Tools

Site Tools


laptop_hacks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
laptop_hacks [2017/03/04 02:37] – [Who's doing the work?] adminlaptop_hacks [2020/02/08 16:41] (current) – [Laptop Hacks] admin
Line 1: Line 1:
 =====Laptop Hacks===== =====Laptop Hacks=====
  
-Ho boy, this got difficult really quickly - in 2012 I had everything working on my laptop with the LXDE spin of fedora plus fluxbox. After a quick spurt of travel using all the laptoppy things like conserving battery life, suspend/resume and lid up and downI left it alone, using it like a desktop on AC power but updating through various fedora's. Quite unbeknownst to me, ''systemd'' came in and the laptoppy stuff got broken - I had to re-discover how to do everything again. Now I know and understand some of it and hopefully recording it here will help me next time.+Ho boy, this got difficult really quickly - in 2011 I had everything working on my laptop (Dell XPS-15 L502X) with the LXDE spin of fedora plus fluxbox. After a quick spurt of travel using all the laptoppy things like conserving battery life, suspend/resume and lid up and down I left it alone, using it like a desktop on AC power but updating through various fedora's. Quite unbeknownst to me, ''systemd'' came in and the laptoppy stuff got broken - I had to re-discover how to do everything again. Now I know and understand some of it and hopefully recording it here will help me next time.
  
 Maybe it'll help you too - but you will almost certainly need to some make tweaks for your particular setup. Maybe it'll help you too - but you will almost certainly need to some make tweaks for your particular setup.
  
-Why go through all this? Why not just use a full DE like KDE or gnome to take care of it? With KDE the best I could get (without digging just as deep as I have done here) was about 4 hours of battery life. By doing the hard work and understanding what's going on I can get up to 6.5 hours! Not bad.+Why go through all this? Why not just use a full DE like KDE or gnome to take care of it? With KDE the best I could get was about 4 hours of battery life. By doing the hard work and understanding what's going on I can get up to 6.5 hours! Not bad.
  
 ====Who's doing the work?==== ====Who's doing the work?====
Line 29: Line 29:
   action=systemctl suspend   action=systemctl suspend
  
-I need to reset my synaptics touch pad on resume - this is ''/usr/local/bin/set-synaptics'':+====Tweaking touchpad====
  
-  #!/bin/sh +Seems the synaptics driver is deprecated in favour of libinput - put tweaks in /etc/X11/xorg.conf.d/30-touchpad.conf:
-   +
-  [ "$DISPLAY" ] || { +
-      echo $0': $DISPLAY not set' >&+
-      exit 1 +
-  } +
-   +
-  pkill syndaemon +
-  syndaemon -i 1 -d -+
-  synclient VertEdgeScroll=1 HorizEdgeScroll=1 VertTwoFingerScroll=1 HorizTwoFingerScroll=1 PalmDetect=1 TapButton1=1 TapButton2=2 # RTCornerButton=2+
  
-If using ''systemd'' then you would put this into ''/etc/systemd/system/resume@.service'': +  Section "InputClass" 
- +      Identifier "touchpad" 
-  [Unit] +      Driver "libinput" 
-  Description=User resume actions +      MatchIsTouchpad "on" 
-  After=suspend.target +      Option "Tapping" "on" 
-   +      Option "TappingButtonMap" "lmr" 
-  [Service] +      Option "ScrollMethod" "edge" 
-  User=%I +  EndSection
-  Type=simple +
-  ExecStart=/usr/local/bin/set-synaptics +
-   +
-  [Install] +
-  WantedBy=suspend.target +
- +
-then run ''systemctl enable resume@bhepple.service''+
  
 ====Power Disconnect/Connect events==== ====Power Disconnect/Connect events====
Line 62: Line 46:
 These events come through DBus, so I run this in my ''.xsession''. These events come through DBus, so I run this in my ''.xsession''.
  
-  # if there's a battery battery then listen on dbus for a/c connect/disconnect: +  # if there's a battery then listen on dbus for a/c connect/disconnect: 
-  upower -e |grep -q battery && power-monitor &+  upower -e |grep -q battery && 
 +      power-monitor & 
 +      xfce4-power-manager & 
 +  }
  
-Where, ''power-monitor'' is this bit of python which just runs the ''low-power'' script when the power/battery status changes:+Where, ''power-monitor'' is this bit of python which keeps an eye on remaining battery life (and hibernate as it gets low) but also runs the ''low-power'' script when the power/battery status changes:
  
   #!/bin/env python   #!/bin/env python
      
-  import gobject, os+  # needs to run as normal user under X (so that battery-alarm can popup) 
 +  # requires dbus-python 
 +   
 +  import gobject, os, sys
   gobject.threads_init()   gobject.threads_init()
      
Line 76: Line 66:
   import dbus   import dbus
   bus = dbus.SystemBus()   bus = dbus.SystemBus()
 +  
 +  sys.dont_write_bytecode = True
      
   def backtick(command):   def backtick(command):
Line 88: Line 80:
       return(value)       return(value)
      
 +  # power connection events
   def ac(*args, **kwargs):   def ac(*args, **kwargs):
-      if args[1]['Online'] == 0: +      print("[" + backtick("date '+%Y%m%d:%H%M%S'") + "] power-monitor: ac: args = ") 
-          print("unplugged"+      print args 
-          os.system("sudo /home/bhepple/bin/low-power true"+      try: 
-      else: +          if args[1]['Online'] == 0: 
-          print("plugged in") +              print("power-monitor: ac: unplugged - calling low-power true") 
-          os.system("sudo /home/bhepple/bin/low-power false"+              os.system("low-power true"
-          +          else: 
 +              print("power-monitor: ac: plugged in - calling low-power false") 
 +              os.system("low-power false") 
 +      except: 
 +          pass 
 +   
 +  # warn user or suspend
   def check_battery(*args, **kwargs):   def check_battery(*args, **kwargs):
       battery_status = backtick("acpi -b")       battery_status = backtick("acpi -b")
-      print(battery_status)+      print("[" + backtick("date '+%Y%m%d:%H%M%S'") + "] power-monitor: " + battery_status)
       if "Discharging" in battery_status:       if "Discharging" in battery_status:
           percent = int( backtick("acpi -b | awk '{print $4}' | tr -d '%,'"))           percent = int( backtick("acpi -b | awk '{print $4}' | tr -d '%,'"))
-          print percent +          if percent < 5: 
-          if percent < 10: backtick("battery-alarm&")+              print("power-monitor: check-battery: systemctl hibernate"
 +              os.system("pkill battery-alarm; sudo systemctl hibernate") 
 +          if percent < 10: 
 +              print("power-monitor: check-battery: battery-alarm"
 +              os.system("battery-alarm&")
       gobject.timeout_add(60 * 1000, check_battery)       gobject.timeout_add(60 * 1000, check_battery)
      
Line 112: Line 115:
   l = gobject.MainLoop()   l = gobject.MainLoop()
   l.run()   l.run()
 +  
 Put this in ''$HOME/bin/low-power'': Put this in ''$HOME/bin/low-power'':
  
-  #!/bin/sh+  #!/usr/bin/env bash 
      
   POWER="OFF"   POWER="OFF"
   [[ "${1:-}" && "$1" == "false" ]] && POWER="ON"   [[ "${1:-}" && "$1" == "false" ]] && POWER="ON"
      
-  (( $(id -u) == 0 )) || { +  echo "$0: POWER=$POWER"
-      echo "$0: needs to run as root" +
-      exit 1 +
-  } +
-   +
-  LOG=/tmp/low-power +
-  echo "stdout and stderr will be sent to $LOG" +
-  exec >$LOG 2>&1+
      
   case "$POWER" in   case "$POWER" in
       OFF)       OFF)
           battery-status           battery-status
-           
-          logger -t $0 "power disconnect: killing bluetooth" 
-          systemctl stop bluetooth.target 
-          BT_PID=$(ps -ef |grep '[/]usr/libexec/bluetooth/bluetoothd' | awk '{print $2}') 
-          [[ "$BT_PID" ]] && kill -9 $BT_PID 
-          rmmod bnep btbcm btrtl btusb btintel bluetooth 
      
-          sudo /home/bhepple/bin/01-pm-power-display true +          #sudo $( which 01-pm-power-displaytrue 
-          sudo /home/bhepple/bin/02-pm-power-tweaks true +          sudo $( which brightness ) 20 
-          sudo /home/bhepple/bin/03-pm-power-hda true+          sudo $( which 02-pm-power-tweakstrue 
 +          sudo $( which 03-pm-power-hdatrue
      
-          powertop --auto-tune+          sudo powertop --auto-tune
           sleep 3           sleep 3
      
           battery-status           battery-status
-   
-          echo "consider turning off wifi" 
-          echo "consider turning off camera: rmmod uvcvideo" 
-          echo "consider turning off ethernet: rmmod r8169 mii" 
           ;;           ;;
       ON)       ON)
-          sudo /home/bhepple/bin/01-pm-power-display false +          #sudo $( which 01-pm-power-displayfalse 
-          sudo /home/bhepple/bin/02-pm-power-tweaks false +          sudo $( which brightness ) 100 
-          sudo /home/bhepple/bin/03-pm-power-hda false +          sudo $( which 02-pm-power-tweaksfalse 
-   +          sudo $( which 03-pm-power-hdafalse
-          logger -t $0 "power connect: starting bluetooth" +
-          modprobe bluetooth +
-          systemctl start bluetooth.target +
-   +
-          modprobe uvcvideo r8169 mii+
           ;;           ;;
   esac   esac
      
   pkill -0 i3blocks && pkill  -RTMIN+9 i3blocks   pkill -0 i3blocks && pkill  -RTMIN+9 i3blocks
-   +      
-  cat $LOG +
-     +
-Put this in ''$HOME/bin/01-pm-power-display'' to dim/brighten the display - requires ''xbacklight'': +
- +
-  #!/bin/sh +
-   +
-  logger -t $0 "$0 $@" +
-  case "$1" in +
-  true) +
-      # called by pm-powersave on power disconnect +
-                   +
-      xbacklight -display :0 -set 1 +
-      logger -t $0 "power disconnect: xbacklight -set 10" +
-      ;; +
-  false) +
-      xbacklight -display :0 -set 40 +
-      logger -t $0 "power connect: xbacklight -set 40" +
-      ALARM_PID_FILE="/var/run/battery-alarm" +
-      [[ -f $ALARM_PID_FILE ]] && { +
-          logger -t $0 "alarm pids = $( cat $ALARM_PID_FILE )" +
-          for PID in $(cat $ALARM_PID_FILE); do +
-              [[ $PID > 0 ]] && kill $PID +
-          done +
-          rm $ALARM_PID_FILE +
-      } +
-      ;; +
-  esac +
-  exit 0 +
 Put this in ''$HOME/bin/03-pm-power-hda'' to maximise battery or performance on the hard disc: Put this in ''$HOME/bin/03-pm-power-hda'' to maximise battery or performance on the hard disc:
  
Line 217: Line 170:
 Put this in ''$HOME/bin/02-pm-power-tweaks'' for general tweaking - most of this originates from ''powertop'': Put this in ''$HOME/bin/02-pm-power-tweaks'' for general tweaking - most of this originates from ''powertop'':
  
-  #!/bin/sh+  #!/usr/bin/env bash
   # BH   # BH
      
Line 223: Line 176:
   case "$1" in   case "$1" in
   true)   true)
-      # called by pm-powersave on power disconnect+      logger -t $0 "power disconnect
 +      systemctl stop bluetooth.target 
 +      rfkill block bluetooth 
 +      BT_PID=$(ps -ef |grep '[/]usr/libexec/bluetooth/bluetoothd' | awk '{print $2}'
 +      [[ "$BT_PID" ]] && kill -9 $BT_PID
      
       echo 5 > /proc/sys/vm/laptop_mode       echo 5 > /proc/sys/vm/laptop_mode
       echo 0 > /proc/sys/kernel/nmi_watchdog       echo 0 > /proc/sys/kernel/nmi_watchdog
-      echo 1 > /sys/devices/system/cpu/sched_smt_power_savings +      echo 1 > /sys/devices/system/cpu/sched_smt_power_savings 
-      echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor+      echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
       echo 1500 > /proc/sys/vm/dirty_writeback_centisecs       echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
       for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 1 > $i; done       for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 1 > $i; done
Line 236: Line 193:
       echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller       echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
       echo 1 > /sys/module/snd_hda_intel/parameters/power_save       echo 1 > /sys/module/snd_hda_intel/parameters/power_save
-      for i in /sys/bus/{pci,i2c}/devices/*/power/control; do echo auto > $i; done+      for i in /sys/bus/pci/devices/*/power/control; do echo auto > $i; done 
 +      iw dev wlp3s0 set power_save on
       ;;       ;;
   false)   false)
 +      logger -t $0 "power connect"
       echo 0 > /proc/sys/vm/laptop_mode       echo 0 > /proc/sys/vm/laptop_mode
       echo 1 > /proc/sys/kernel/nmi_watchdog       echo 1 > /proc/sys/kernel/nmi_watchdog
-      echo 0 > /sys/devices/system/cpu/sched_smt_power_savings +      echo 0 > /sys/devices/system/cpu/sched_smt_power_savings 
-      echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor+      echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
       echo 500 > /proc/sys/vm/dirty_writeback_centisecs       echo 500 > /proc/sys/vm/dirty_writeback_centisecs
       for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 2 > $i; done       for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 2 > $i; done
Line 250: Line 209:
       #echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller       #echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
       #echo 1 > /sys/module/snd_hda_intel/parameters/power_save       #echo 1 > /sys/module/snd_hda_intel/parameters/power_save
-      #for i in /sys/bus/{pci,i2c}/devices/*/power/control; do echo auto > $i; done+      #for i in /sys/bus/pci/devices/*/power/control; do echo auto > $i; done 
 +   
 +      modprobe bluetooth 
 +      rfkill unblock bluetooth 
 +   
 +      systemctl start bluetooth.target 
 +   
 +      modprobe uvcvideo r8169 mii 
 +      iw dev wlp3s0 set power_save off
       ;;       ;;
   esac   esac
      
   exit 0   exit 0
 +  
 +To run stuff on 'resume', put this in ''/etc/systemd/system/bhepple-resume.service'':
 +
 +  [Unit]
 +  Description=Run on 'resume'
 +  After=suspend.target
 +  
 +  [Service]
 +  User=root
 +  Type=oneshot
 +  ExecStart=/sbin/hdparm -y /dev/sda # puts aux disc into standby - should test that it's not '/' !!
 +  
 +  [Install]
 +  WantedBy=suspend.target
 +
 +and run ''systemctl enable bhepple-resume.service''
 +
 +brightness is this:
 +
 +  #!/bin/bash
 +  
 +  # since xbacklight isn't working (nouveau?)
 +  # https://bbs.archlinux.org/viewtopic.php?id=134972 and modified:
 +  
 +  # needs to be run as root
 +  
 +  NEW_VALUE=${1:-0}
 +  
 +  # base dir for backlight class
 +  basedir="/sys/class/backlight/"
 +  
 +  # get the backlight handler
 +  handler=$basedir$(ls $basedir |head -n 1)"/"
 +  
 +  # get current brightness
 +  old_brightness=$(cat $handler"brightness")
 +  
 +  # get max brightness
 +  max_brightness=$(cat $handler"max_brightness")
 +  
 +  # get current brightness %
 +  old_brightness_p=$(( 100 * $old_brightness / $max_brightness ))
 +  
 +  # calculate new brightness %
 +  if [[ $NEW_VALUE == [+-]* ]]; then
 +      new_brightness_p=$(($old_brightness_p + $NEW_VALUE))
 +  else
 +      new_brightness_p=$NEW_VALUE
 +  fi
 +  
 +  # calculate new brightness value
 +  new_brightness=$(( $max_brightness * $new_brightness_p / 100 ))
 +  
 +  (( new_brightness <= max_brightness && new_brightness >= 0 )) && {
 +      # set the new brightness value
 +      echo $new_brightness > $handler"brightness"
 +  }
      
 ====Disable nouveau==== ====Disable nouveau====
laptop_hacks.txt · Last modified: 2020/02/08 16:41 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki