Skip to content

Commit

Permalink
conf.d: remove hard-coded defaults
Browse files Browse the repository at this point in the history
Rationale: default settings are in /usr/share/tlp/defaults.conf now.
  • Loading branch information
linrunner committed Nov 3, 2019
1 parent bcbe938 commit 6bddc13
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 109 deletions.
2 changes: 1 addition & 1 deletion defaults.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ USB_BLACKLIST_PRINTER=1
USB_BLACKLIST_WWAN=0
USB_AUTOSUSPEND_DISABLE_ON_SHUTDOWN=0
RESTORE_DEVICE_STATE_ON_STARTUP=0
RESTORE_THRESHOLDS_ON_BAT=1
RESTORE_THRESHOLDS_ON_BAT=0
NATACPI_ENABLE=1
TPACPI_ENABLE=1
TPSMAPI_ENABLE=1
12 changes: 3 additions & 9 deletions func.d/05-tlp-func-pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ readonly ETHTOOL=ethtool
readonly PCID=/sys/bus/pci/devices
readonly PCIDRV=/sys/bus/pci/drivers

readonly DEFAULT_RUNTIME_PM_DRIVER_BLACKLIST="amdgpu mei_me nouveau nvidia pcieport radeon"
readonly DEFAULT_SOUND_POWER_SAVE_CONTROLLER=Y
readonly DEFAULT_WOL_DISABLE=N

# ----------------------------------------------------------------------------
# Functions

Expand All @@ -44,9 +40,9 @@ set_runtime_pm () { # set runtime power management
fi

# driver specific blacklist:
# - undefined = use internal default from $DEFAULT_PM_DRIVER_BLACKLIST
# - undefined = use intrinsic default from /usr/share/tlp/defaults.conf
# - empty = disable feature
drv_bl="${RUNTIME_PM_DRIVER_BLACKLIST-${DEFAULT_RUNTIME_PM_DRIVER_BLACKLIST}}"
drv_bl="$RUNTIME_PM_DRIVER_BLACKLIST"

# pci address blacklisting
pci_bl_adr=${RUNTIME_PM_BLACKLIST:-}
Expand Down Expand Up @@ -173,7 +169,7 @@ set_sound_power_mode () { # set sound chip power modes
return 0
fi

cpwr=${SOUND_POWER_SAVE_CONTROLLER:-${DEFAULT_SOUND_POWER_SAVE_CONTROLLER}}
cpwr="$SOUND_POWER_SAVE_CONTROLLER"

check_sysfs "set_sound_power_mode" "/sys/module"

Expand Down Expand Up @@ -220,8 +216,6 @@ get_ethifaces () { # get all eth devices -- retval: $_ethifaces
disable_wake_on_lan () { # disable WOL
local ei

WOL_DISABLE=${WOL_DISABLE:-${DEFAULT_WOL_DISABLE}}

if [ "$WOL_DISABLE" = "Y" ]; then
get_ethifaces
for ei in $_ethifaces; do
Expand Down
34 changes: 9 additions & 25 deletions func.d/15-tlp-func-disk
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
readonly AHCID=$PCID'/*/ata*'
readonly BLOCKD='/sys/block/nvme* /sys/block/sd*'

readonly DEFAULT_DISK_DEVICES="nvme0n1 sda"
readonly DEFAULT_DISK_IDLE_SECS_ON_AC=0
readonly DEFAULT_DISK_IDLE_SECS_ON_BAT=2
readonly DEFAULT_DISK_IOSCHED="keep"
readonly DEFAULT_MAX_LOST_WORK_SECS=15
readonly DEFAULT_AHCI_RUNTIME_PM_TIMEOUT="15"

readonly DISK_TYPES_NO_APM_CHANGE="usb ieee1394"
readonly DISK_NOP_WORDS="_ keep"

Expand Down Expand Up @@ -106,9 +99,6 @@ set_disk_apm_level () { # set disk apm level
local pwrmode="$1"
local dev log_message

# when undefined use default
: ${DISK_DEVICES=${DEFAULT_DISK_DEVICES}}

# quit when disabled
if [ -z "$DISK_DEVICES" ]; then
echo_debug "disk" "set_disk_apm_level($pwrmode).disabled"
Expand Down Expand Up @@ -163,9 +153,6 @@ set_disk_spindown_timeout () { # set disk spindown timeout
local pwrmode="$1"
local dev log_message

# when undefined use default
: ${DISK_DEVICES=${DEFAULT_DISK_DEVICES}}

# quit when disabled
if [ -z "$DISK_DEVICES" ]; then
echo_debug "disk" "set_disk_spindown_timeout($pwrmode).disabled"
Expand Down Expand Up @@ -221,9 +208,6 @@ spindown_disk () { # stop spindle motor -- $1: dev
set_disk_iosched () { # set disk io scheduler
local dev log_message

# when undefined use default
: ${DISK_DEVICES=${DEFAULT_DISK_DEVICES}}

# quit when disabled
if [ -z "$DISK_DEVICES" ]; then
echo_debug "disk" "set_disk_iosched.disabled"
Expand All @@ -243,13 +227,13 @@ set_disk_iosched () { # set disk io scheduler

# pairwise iteration DISK_DEVICES[1,n], schedlist[1,m]; m > 0
# for j in [1,min(n,m)] : disk_dev[j], schedlistj]
# for j in [min(n,m)+1,n] : disk_dev[j], %DEFAULT_DISK_IO_SCHEDULER
# for j in [min(n,m)+1,n] : disk_dev[j], %keep
for dev in $DISK_DEVICES; do
local sched schedctrl
get_disk_dev $dev

# get sched from argv, use default scheduler when list is too short
sched=${1:-${DEFAULT_DISK_IOSCHED}}
# get sched from argv, use "keep" when list is too short
sched=${1:-keep}
schedctrl="/sys/block/$_disk_dev/queue/scheduler"
log_message="set_disk_iosched: $_disk_dev [$_disk_id] $sched"

Expand All @@ -264,7 +248,7 @@ set_disk_iosched () { # set disk io scheduler
echo_debug "disk" "${log_message}; rc=$?"
fi

# using %DEFAULT_DISK_IO_SCHEDULER when argv is empty
# using "keep" when argv is empty
[ $# -eq 0 ] || shift
done

Expand Down Expand Up @@ -342,7 +326,7 @@ set_ahci_runtime_pm () { # set ahci runtime power management
fi

# calc timeout in millisecs
timeout="${AHCI_RUNTIME_PM_TIMEOUT-${DEFAULT_AHCI_RUNTIME_PM_TIMEOUT}}"
timeout="$AHCI_RUNTIME_PM_TIMEOUT"
[ -z "$timeout" ] || timeout=$((timeout * 1000))

# check values
Expand Down Expand Up @@ -409,9 +393,9 @@ set_laptopmode () { # set kernel laptop mode -- $1: 0=ac mode, 1=battery mode
local isec

if [ "$1" = "1" ]; then
isec=${DISK_IDLE_SECS_ON_BAT:-${DEFAULT_DISK_IDLE_SECS_ON_BAT}}
isec="$DISK_IDLE_SECS_ON_BAT"
else
isec=${DISK_IDLE_SECS_ON_AC:-${DEFAULT_DISK_IDLE_SECS_ON_AC}}
isec="$DISK_IDLE_SECS_ON_AC"
fi
# replace with empty string if non-numeric chars are contained
isec=$(printf '%s' "$isec" | grep -E '^[0-9]+$')
Expand All @@ -437,9 +421,9 @@ set_dirty_parms () { # set filesystem buffer params
check_sysfs "set_dirty_parms" "/proc/sys/vm"

if [ "$1" = "1" ]; then
age=${MAX_LOST_WORK_SECS_ON_BAT:-${DEFAULT_MAX_LOST_WORK_SECS}}
age=${MAX_LOST_WORK_SECS_ON_BAT:-0}
else
age=${MAX_LOST_WORK_SECS_ON_AC:-${DEFAULT_MAX_LOST_WORK_SECS}}
age=${MAX_LOST_WORK_SECS_ON_AC:-0}
fi

# calc age in centisecs, non numeric values result in "0"
Expand Down
16 changes: 0 additions & 16 deletions func.d/20-tlp-func-usb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ readonly USB_TIMEOUT_MS=2000
readonly USB_WWAN_VENDORS="0bdb 05c6 1199 2cb7"
readonly USB_DONE=usb_done

readonly DEFAULT_USB_AUTOSUSPEND=0
readonly DEFAULT_USB_BLACKLIST_BTUSB=0
readonly DEFAULT_USB_BLACKLIST_PHONE=0
readonly DEFAULT_USB_BLACKLIST_PRINTER=1
readonly DEFAULT_USB_BLACKLIST_WWAN=0

# ----------------------------------------------------------------------------
# Functions

Expand Down Expand Up @@ -78,8 +72,6 @@ usb_suspend_device () { # enable/disable usb autosuspend for a single device

if [ -z "$exc" ]; then
# check for bluetooth devices
: ${USB_BLACKLIST_BTUSB:=${DEFAULT_USB_BLACKLIST_BTUSB}}

if [ "$USB_BLACKLIST_BTUSB" = "1" ] \
&& [ "$dclass" = "e0" ] \
&& [ "$(read_sysf $usbdev/bDeviceSubClass)" = "01" ] \
Expand All @@ -103,8 +95,6 @@ usb_suspend_device () { # enable/disable usb autosuspend for a single device

if [ -z "$exc" ]; then
# check for phone devices
: ${USB_BLACKLIST_PHONE:=${DEFAULT_USB_BLACKLIST_PHONE}}

if [ "$USB_BLACKLIST_PHONE" = "1" ]; then
if [ "$vendor" = "0fca" ]; then
# RIM
Expand Down Expand Up @@ -169,8 +159,6 @@ usb_suspend_device () { # enable/disable usb autosuspend for a single device

if [ -z "$exc" ]; then
# check for printers
: ${USB_BLACKLIST_PRINTER:=${DEFAULT_USB_BLACKLIST_PRINTER}}

if [ "$USB_BLACKLIST_PRINTER" = "1" ]; then
if [ "$dclass" = "00" ]; then
# check for printer subdevices
Expand All @@ -187,8 +175,6 @@ usb_suspend_device () { # enable/disable usb autosuspend for a single device

if [ -z "$exc" ]; then
# check for wwan devices
: ${USB_BLACKLIST_WWAN:=${DEFAULT_USB_BLACKLIST_WWAN}}

if [ "$USB_BLACKLIST_WWAN" = "1" ]; then
if [ "$dclass" != "00" ]; then
# check for cdc subdevices
Expand Down Expand Up @@ -249,8 +235,6 @@ set_usb_suspend () { # enable/disable usb autosuspend for all devices

check_sysfs "set_usb_suspend" "$USBD"

: ${USB_AUTOSUSPEND:=${DEFAULT_USB_AUTOSUSPEND}}

if [ "$USB_AUTOSUSPEND" = "1" ]; then
# autosuspend is configured --> iterate devices
for usbdev in $USBD/*; do
Expand Down
4 changes: 1 addition & 3 deletions func.d/30-tlp-func-rf-sw
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ readonly RDW_KILL="rdw_kill"

readonly RFSTATEFILE=$VARDIR/rfkill_saved

readonly DEFAULT_RESTORE_DEVICE_STATE_ON_STARTUP=0

# ----------------------------------------------------------------------------
# Functions

Expand Down Expand Up @@ -383,7 +381,7 @@ set_radio_device_states () { # set/initialize all radio states

# save/restore mode is disabled by default
if [ "$1" != "radiosw" ]; then
restore=${RESTORE_DEVICE_STATE_ON_STARTUP:-${DEFAULT_RESTORE_DEVICE_STATE_ON_STARTUP}}
restore="$RESTORE_DEVICE_STATE_ON_STARTUP"
else
restore=0
fi
Expand Down
10 changes: 3 additions & 7 deletions func.d/35-tlp-func-batt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ readonly TPACPIDIR=/sys/devices/platform/thinkpad_acpi
readonly SMAPIBATDIR=/sys/devices/platform/smapi
readonly ACPIBATDIR=/sys/class/power_supply

readonly DEFAULT_NATACPI_ENABLE=1
readonly DEFAULT_TPACPI_ENABLE=1
readonly DEFAULT_TPSMAPI_ENABLE=1

# ----------------------------------------------------------------------------
# Functions

Expand Down Expand Up @@ -103,7 +99,7 @@ check_battery_features () { # determine which battery feature APIs/tools are

if readable_sysf $ps/charge_start_threshold; then
# charge_start_threshold exists and is actually readable
if [ "${NATACPI_ENABLE:-${DEFAULT_NATACPI_ENABLE}}" = "1" ]; then
if [ "$NATACPI_ENABLE" = "1" ]; then
_natacpi=1
_bm_thresh="natacpi"
else
Expand Down Expand Up @@ -149,7 +145,7 @@ check_battery_features () { # determine which battery feature APIs/tools are
$TPACPIBAT -g FD 1 > /dev/null 2>&1
_tpacpi=$?

if [ $_tpacpi -eq 0 ] && [ "${TPACPI_ENABLE:-${DEFAULT_TPACPI_ENABLE}}" = "0" ]; then
if [ $_tpacpi -eq 0 ] && [ "$TPACPI_ENABLE" = "0" ]; then
# tpacpi disabled by configuration
_tpacpi=32
fi
Expand All @@ -173,7 +169,7 @@ check_battery_features () { # determine which battery feature APIs/tools are
# --- 3. check for tp-smapi external kernel module [ThinkPads only]
if [ -d $SMAPIBATDIR ]; then
# module loaded --> tp-smapi available
if [ "${TPSMAPI_ENABLE:-${DEFAULT_TPSMAPI_ENABLE}}" = "0" ]; then
if [ "$TPSMAPI_ENABLE" = "0" ]; then
# tpsmapi disabled by configuration
_tpsmapi=32
elif supports_tpsmapi_and_tpacpi; then
Expand Down
14 changes: 5 additions & 9 deletions func.d/40-tlp-func-bay
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ readonly DOCKGLOB="/sys/devices/platform/dock.?"

readonly BAYSTATEFILE=$RUNDIR/bay_saved

readonly DEFAULT_BAY_POWEROFF_ON_AC=0
readonly DEFAULT_BAY_POWEROFF_ON_BAT=0
readonly DEFAULT_BAY_DEVICE=sr0

# ----------------------------------------------------------------------------
# Functions

Expand Down Expand Up @@ -61,9 +57,9 @@ poweroff_drivebay () { # power off optical drive in drive bay
local pwr optdrv syspath

if [ "$1" = "1" ]; then
pwr=${BAY_POWEROFF_ON_BAT:-${DEFAULT_BAY_POWEROFF_ON_BAT}}
pwr="$BAY_POWEROFF_ON_BAT"
else
pwr=${BAY_POWEROFF_ON_AC:-${DEFAULT_BAY_POWEROFF_ON_AC}}
pwr="$BAY_POWEROFF_ON_AC"
fi

# Run only if forced or enabled
Expand Down Expand Up @@ -98,7 +94,7 @@ poweroff_drivebay () { # power off optical drive in drive bay
[ "$2" = "1" ] && echo "No drive in bay (or power already off)."
else
# Check for optical drive
optdrv=${BAY_DEVICE-${DEFAULT_BAY_DEVICE}}
optdrv="$BAY_DEVICE"
if [ -z "$optdrv" ]; then
echo_debug "pm" "poweroff_drivebay($1).opt_drive_not_configured"
[ "$2" = "1" ] && echo "Error: no optical drive configured (BAY_DEVICE=\"\")." 1>&2
Expand Down Expand Up @@ -149,8 +145,8 @@ poweroff_drivebay () { # power off optical drive in drive bay
suspend_drivebay () { # Save power state of drive bay before suspend
# $1: 0=ac mode, 1=battery mode

if [ "$1" = "1" ] && [ "${BAY_POWEROFF_ON_BAT:-${DEFAULT_BAY_POWEROFF_ON_BAT}}" = "1" ] || \
[ "$1" = "0" ] && [ "${BAY_POWEROFF_ON_AC:-${DEFAULT_BAY_POWEROFF_ON_AC}}" = "1" ]; then
if [ "$1" = "1" ] && [ "$BAY_POWEROFF_ON_BAT" = "1" ] || \
[ "$1" = "0" ] && [ "$BAY_POWEROFF_ON_AC" = "1" ]; then
# setting corresponding to mode is active -> save state
get_drivebay_device

Expand Down
25 changes: 8 additions & 17 deletions func.d/45-tlp-func-gpu
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ readonly IGPU_FREQ_TABLE=i915_ring_freq_table

readonly RADD=/sys/module/radeon

readonly DEFAULT_RADEON_POWER_PROFILE_ON_AC=default
readonly DEFAULT_RADEON_POWER_PROFILE_ON_BAT=default
readonly DEFAULT_RADEON_DPM_PERF_LEVEL_ON_AC=auto
readonly DEFAULT_RADEON_DPM_PERF_LEVEL_ON_BAT=auto

# ----------------------------------------------------------------------------
# Functions

Expand Down Expand Up @@ -120,19 +115,17 @@ set_radeon_profile () { # set radeon power profile
# Use new radeon dynamic power management method (dpm)
if [ "$1" = "1" ]; then
pwr=${RADEON_DPM_STATE_ON_BAT:-}
level=${RADEON_DPM_PERF_LEVEL_ON_BAT-${DEFAULT_RADEON_DPM_PERF_LEVEL_ON_BAT}}
level=${RADEON_DPM_PERF_LEVEL_ON_BAT:-}
else
pwr=${RADEON_DPM_STATE_ON_AC:-}
level=${RADEON_DPM_PERF_LEVEL_ON_AC-${DEFAULT_RADEON_DPM_PERF_LEVEL_ON_AC}}
level=${RADEON_DPM_PERF_LEVEL_ON_AC:-}
fi

if [ -z "$pwr" ]; then
# do nothing if unconfigured
if [ -z "$pwr" ] || [ -z "$level" ]; then
# do nothing if (partially) unconfigured
echo_debug "pm" "set_radeon_profile($1).not_configured: $card"
return 0
fi

if [ -n "$pwr" ]; then
else
write_sysf "$pwr" $card/power_dpm_state; rc1=$?
write_sysf "$level" $card/power_dpm_force_performance_level; rc2=$?
echo_debug "pm" "set_radeon_profile($1): $card: state=${pwr}: rc=$rc1; perf=${level}: rc=$rc2"
Expand All @@ -143,18 +136,16 @@ set_radeon_profile () { # set radeon power profile
elif [ -f $card/power_method ] && [ -f $card/power_profile ]; then
# Use old radeon power profile method
if [ "$1" = "1" ]; then
pwr=${RADEON_POWER_PROFILE_ON_BAT-${DEFAULT_RADEON_POWER_PROFILE_ON_BAT}}
pwr=${RADEON_POWER_PROFILE_ON_BAT:-}
else
pwr=${RADEON_POWER_PROFILE_ON_AC-${DEFAULT_RADEON_POWER_PROFILE_ON_AC}}
pwr=${RADEON_POWER_PROFILE_ON_AC:-}
fi

if [ -z "$pwr" ]; then
# do nothing if unconfigured
echo_debug "pm" "set_radeon_profile($1).not_configured: $card"
return 0
fi

if [ -n "$pwr" ]; then
else
write_sysf "profile" $card/power_method; rc1=$?
write_sysf "$pwr" $card/power_profile; rc2=$?
echo_debug "pm" "set_radeon_profile($1): $card; method=profile: rc=$rc1; profile=${pwr}: rc=$rc2"
Expand Down
8 changes: 1 addition & 7 deletions tlp-func-base.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ readonly RE_PARAM='^[A-Z_]+[0-9]*=[0-9a-zA-Z _\-:]*$'
# power supplies: ignore MacBook Pro 2017 sbs-charger and hid devices
readonly RE_PS_IGNORE='sbs-charger|hidpp_battery|hid-'

readonly DEBUG_TAGS_ALL="arg bat disk lock nm path pm ps rf run sysfs udev usb"

readonly DEFAULT_TLP_ENABLE=0
readonly DEFAULT_TLP_PERSISTENT_DEFAULT=0
readonly DEBUG_TAGS_ALL="arg bat cfg disk lock nm path pm ps rf run sysfs udev usb"

# ----------------------------------------------------------------------------
# Control
Expand Down Expand Up @@ -169,8 +166,6 @@ check_tlp_enabled () { # check if TLP is enabled in config file
# $1: 1=verbose
# rc: 0=disabled/1=enabled

: ${TLP_ENABLE:=${DEFAULT_TLP_ENABLE}}

if [ "$TLP_ENABLE" = "1" ]; then
return 0
else
Expand Down Expand Up @@ -699,7 +694,6 @@ get_power_state () { # get current power mode -- rc: 0=ac, 1=battery
local rc=$?

: ${TLP_DEFAULT_MODE:=}
: ${TLP_PERSISTENT_DEFAULT:=${DEFAULT_TLP_PERSISTENT_DEFAULT}}

if [ -n "$TLP_DEFAULT_MODE" ] \
&& [ "$TLP_PERSISTENT_DEFAULT" = "1" ]; then
Expand Down
Loading

0 comments on commit 6bddc13

Please sign in to comment.