Difference between revisions of "User:Saul/Laptop"
m (→Disabling CPUs: Add section.) |
m (→Running on GPU (on-demand) (NEEDS TESTING)) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 85: | Line 85: | ||
PLATFORM_PROFILE_ON_BAT=low-power | PLATFORM_PROFILE_ON_BAT=low-power | ||
+ | </source> | ||
+ | |||
+ | ==== Multiple TLP Configurations ==== | ||
+ | You can setup a system for multiple TLP configurations and a script for changing between them. | ||
+ | |||
+ | <source lang="bash"> | ||
+ | mkdir ~/tlp; | ||
+ | cp /etc/tlp.conf ~/tlp/default.conf; | ||
+ | </source> | ||
+ | |||
+ | Then just copy the default configurations to another file in the '''~/tlp''' directory with the file name as the mode you would like to call it. You will then need the script: '''~/.local/bin/power_mode''' with the following contents: | ||
+ | |||
+ | <source lang="bash"> | ||
+ | #!/bin/bash | ||
+ | MODE="$1"; | ||
+ | TLP_CONFIG_DIR="~/tlp"; | ||
+ | TLP_CONFIG_LOCATION="/etc/tlp.conf"; | ||
+ | |||
+ | # DO NOT EDIT BELOW THIS LINE. | ||
+ | |||
+ | FILE="${TLP_CONFIG_DIR}/${MODE}.conf"; | ||
+ | |||
+ | if ! test -f $FILE; then | ||
+ | echo "No TLP config found for mode: ${MODE}"; | ||
+ | exit 1; | ||
+ | fi | ||
+ | |||
+ | sudo cp $FILE $TLP_CONFIG_LOCATION; | ||
+ | sudo tlp start; | ||
+ | </source> | ||
+ | |||
+ | Then (after making it executable) you can change between your defined power modes: | ||
+ | <source lang="bash"> | ||
+ | power-mode default # you can change default to any other power modes you have created. | ||
</source> | </source> | ||
Line 181: | Line 215: | ||
The Power consumption is the most useful as that immediately tells me what kind of battery life to expect. | The Power consumption is the most useful as that immediately tells me what kind of battery life to expect. | ||
+ | |||
+ | == Fans == | ||
+ | Fans are able to be adjusted but the BIOS does not provide fine tuning options for it. There is a program for windows that provides fine tune adjustments: https://www.legionfancontrol.com/ but the settings do not persist on reboots. | ||
+ | |||
+ | Someone has created a kernel module that allows for getting/setting the fans https://github.com/NUTSU7/Linux-LegionFanControl but it is not quite finished, you need to jump through some hoops to get it to run and it must stay running to keep the fans controlled. | ||
+ | |||
+ | If you don't have pip3, install it: | ||
+ | <source lang="bash"> | ||
+ | wget https://bootstrap.pypa.io/get-pip.py -O get-pip.py | ||
+ | sudo python3 get-pip.py | ||
+ | </source> | ||
+ | |||
+ | Install the packages needed: | ||
+ | <source lang="bash"> | ||
+ | python3 -m pip install -U pyinstaller | ||
+ | python3 -m pip install customtkinter==4.6.3 | ||
+ | python3 -m pip install numpy | ||
+ | python3 -m pip install tk | ||
+ | |||
+ | sudo apt-get install python3-tk | ||
+ | sudo apt-get install python3-pil.imagetk | ||
+ | </source> | ||
+ | |||
+ | Then you can compile the module. Updating the fan speed through the python program works but not outside it for reasons I have no idea why. | ||
+ | |||
+ | <source lang="bash"> | ||
+ | sudo insmod LegionController.ko # Load kernel module | ||
+ | sudo rmmod LegionController.ko # Unload kernel module | ||
+ | |||
+ | cat /sys/kernel/LegionController/powerMode # retrieve the current power mode | ||
+ | # 0 = performance/red | ||
+ | # 1 = auto/balanced/white | ||
+ | # 2 = quiet/blue | ||
+ | |||
+ | echo -n "<MODE>" > /sys/module/LegionController/parameters/cPowerMode && cat /sys/kernel/LegionController/powerMode # Set the power mode (For some reason you need to read from it for it to update.) | ||
+ | |||
+ | cat /sys/kernel/LegionController/fanSpeedCurrent # Get the current fan speed (result is in hundreds of RPM, e.g. 20 = 2000 RPM) | ||
+ | cat /sys/kernel/LegionController/tempCurrentCPU # Get the current CPU temperature in degrees | ||
+ | cat /sys/kernel/LegionController/tempCurrentGPU # Get the current GPU temperature in degrees | ||
+ | |||
+ | echo -n "<RPM>" > /sys/module/LegionController/parameters/cFanCurve # Set the current fan RPM, for some reason this does not work outside the python program even though this is all it does. | ||
+ | </source> | ||
== Conservative Charging == | == Conservative Charging == | ||
Line 246: | Line 322: | ||
# View state | # View state | ||
conservative status | conservative status | ||
+ | </source> | ||
+ | |||
+ | == nvidia-smi == | ||
+ | |||
+ | <source> | ||
+ | $ nvidia-smi | ||
+ | NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver | ||
+ | </source> | ||
+ | |||
+ | Try installing ubuntu drivers. | ||
+ | |||
+ | <source lang="bash"> | ||
+ | sudo ubuntu-drivers autoinstall | ||
+ | </source> | ||
+ | |||
+ | == Running on GPU (on-demand) (NEEDS TESTING) == | ||
+ | When running in hybrid-graphics mode sometimes it is useful to run a command on the dGPU in which case you can prefix the command with: | ||
+ | |||
+ | <source> | ||
+ | __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia <YOUR COMMAND> # This one seems to actually work. | ||
+ | </source> | ||
+ | |||
+ | For example to run a docker image I run: | ||
+ | <source> | ||
+ | _NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia docker run --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi | ||
+ | </source> | ||
+ | |||
+ | |||
+ | Other suggestions for using the GPU included: | ||
+ | <source> | ||
+ | DDPrefersNonDefaultGPU=true | ||
+ | X-KDE-RunOnDiscreteGpu=true | ||
+ | DRI_PRIME=1 | ||
</source> | </source> |
Latest revision as of 23:17, 10 November 2024
Contents
Brightness
At first the brightness controls won't work after a fresh install so here are some steps to try:
- Update all the packages in the update manager, on a fresh install this installs a new kernel version - 5.15.0-41.
- Open the Driver Manager application and use the latest Nvidia one, both 515.48.07 and 470.129.06 worked fine for me.
- Restart the computer
If the brightness controls still do not work after that try the following steps.
sudo nano /etc/default/grub
# Change the line:
# GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
# To become
# GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video.use_native_backlight=1"
sudo update-grub
Then again restart the computer and test again. If it is still not working (it should be) try these next steps:
# WARNING: This next step kills the user interface so make sure you memorize all the steps.
sudo service lightdm stop
# Hit ctrl-alt-f1 to open a session then login using your credentials.
sudo X -configure
sudo cp xorg.conf.new /etc/X11/xorg.conf
sudo reboot
The following notes might be of use if it still is not working but probably won't fix it outright.
The later linux kernels seem to handle the newer hardware better than the older ones so you can try installing mainline and installing a later kernel say 5.16 but make sure to uninstall it again if it does not install without errors. (You can still use it but some things will be broken like dependencies.) Another thing you can try is looking up brightness options for the /etc/X11/xorg.conf file.
Battery
TL;DR;
- Hybrid graphics mode (bios)
- NVIDIA On-Demand mode (nvidia-primus)
- Display 60Hz
- TLP
- sudo systemctl disable docker
The battery life was terrible at first - like less than 3h bad, however this can be fixed to give 10h or more. The first thing to do is ensure the computer is in dynamic graphics mode (set in the bios), this stops forcing the gpu to run all the time. The next thing to do is put nvidia primus (The amd? icon on the bottom right) into NVIDIA On-Demand mode - do not set it to AMD Power Saving Mode because contrary to the name it chews threw a lot of power for some reason. Another thing you can do is change the display to 60hz which saves a bit of battery. The next thing to do is install tlp.
TLP
# Install
sudo apt install tlp tlp-rdw
# Start (alternatively restart the computer)
sudo tlp start
# Verify it is running.
tlp-stat -s
You can further tune tlp by editing /etc/tlp.conf but personally the defaults were good enough for me.
GUI
TLP can be little tricky to figure out what settings need editing, a UI is most helpful for this.
sudo add-apt-repository ppa:linuxuprising/apps;
sudo apt-get update;
sudo apt-get install tlpui;
Then you can open the Tlp-UI application.
My TLP Settings
Usage during work: 10-12 W
# Note that my CPU will not go below a certain level so a low value is safe here.
CPU_SCALING_MAX_FREQ_ON_BAT=1
CPU_ENERGY_PREF_POLICY_ON_BAT=power
SCHED_POWERSAVE_ON_BAT=true
PLATFORM_PROFILE_ON_BAT=low-power
Multiple TLP Configurations
You can setup a system for multiple TLP configurations and a script for changing between them.
mkdir ~/tlp;
cp /etc/tlp.conf ~/tlp/default.conf;
Then just copy the default configurations to another file in the ~/tlp directory with the file name as the mode you would like to call it. You will then need the script: ~/.local/bin/power_mode with the following contents:
#!/bin/bash
MODE="$1";
TLP_CONFIG_DIR="~/tlp";
TLP_CONFIG_LOCATION="/etc/tlp.conf";
# DO NOT EDIT BELOW THIS LINE.
FILE="${TLP_CONFIG_DIR}/${MODE}.conf";
if ! test -f $FILE; then
echo "No TLP config found for mode: ${MODE}";
exit 1;
fi
sudo cp $FILE $TLP_CONFIG_LOCATION;
sudo tlp start;
Then (after making it executable) you can change between your defined power modes:
power-mode default # you can change default to any other power modes you have created.
Debugging
Full output:
sudo tlp-stat
Get power mode:
sudo tlp-stat -p
Get battery status:
sudo tlp-stat -b
CPUFreq
CPUFreq is a good applet for quickly changing between CPU governing profiles.
sudo apt-get install indicator-cpufreq
Disabling CPUs
This is an interesting one, you can disable what CPUs/Cores get used:
# Disable core 4
sudo chcpu -d 4
# Enable core 4
sudo chcpu -e 4
# Disable cores 8-15
sudo chcpu -d 8-15
# Enable cores 8-15
sudo chcpu -e 8-15
Now I only get 1-2 Watts difference between 4 and 16 cores idling, but it is something to fiddle with and see what the results are.
Apparently this will also work on some computers:
# Disable core
sudo echo 0 > /sys/devices/system/cpu/cpu<CPU NUMBER>/online
# Enable core
sudo echo 1 > /sys/devices/system/cpu/cpu<CPU NUMBER>/online
Slimbook
You can install and use slimbook with tlp but be warned it does change a lot of tlp settings on install. I have found that Slimbook uses around 3x the battery power on my laptop. Slimbook will give you a UI for configuring some of tlp's options.
# Backup tlp settings.
sudo cp /etc/tlp.conf /etc/tlp.conf.bak
sudo add-apt-repository ppa:slimbook/slimbook
sudo apt update
sudo apt install slimbookbattery
Docker
Beware if you install docker - it chews through a fair bit of battery life so I have it disabled by default after installing:
sudo systemctl disable docker
If you want to stop it manually you need to run:
sudo service docker stop
sudo ifconfig docker0 down
GPU
To check the power draw run:
nvidia-smi -q -d POWER
When power draw is high the Power Draw field has a value but when power draw is low it has the value Unknown Error. Running this command seems to activate the GPU.
Applets
I have installed a couple of applets (Cinnamon) to help me figure out what is happening to the battery life.
- CPU Temperature Indicator
- Power Consumption Display
The Power consumption is the most useful as that immediately tells me what kind of battery life to expect.
Fans
Fans are able to be adjusted but the BIOS does not provide fine tuning options for it. There is a program for windows that provides fine tune adjustments: https://www.legionfancontrol.com/ but the settings do not persist on reboots.
Someone has created a kernel module that allows for getting/setting the fans https://github.com/NUTSU7/Linux-LegionFanControl but it is not quite finished, you need to jump through some hoops to get it to run and it must stay running to keep the fans controlled.
If you don't have pip3, install it:
wget https://bootstrap.pypa.io/get-pip.py -O get-pip.py
sudo python3 get-pip.py
Install the packages needed:
python3 -m pip install -U pyinstaller
python3 -m pip install customtkinter==4.6.3
python3 -m pip install numpy
python3 -m pip install tk
sudo apt-get install python3-tk
sudo apt-get install python3-pil.imagetk
Then you can compile the module. Updating the fan speed through the python program works but not outside it for reasons I have no idea why.
sudo insmod LegionController.ko # Load kernel module
sudo rmmod LegionController.ko # Unload kernel module
cat /sys/kernel/LegionController/powerMode # retrieve the current power mode
# 0 = performance/red
# 1 = auto/balanced/white
# 2 = quiet/blue
echo -n "<MODE>" > /sys/module/LegionController/parameters/cPowerMode && cat /sys/kernel/LegionController/powerMode # Set the power mode (For some reason you need to read from it for it to update.)
cat /sys/kernel/LegionController/fanSpeedCurrent # Get the current fan speed (result is in hundreds of RPM, e.g. 20 = 2000 RPM)
cat /sys/kernel/LegionController/tempCurrentCPU # Get the current CPU temperature in degrees
cat /sys/kernel/LegionController/tempCurrentGPU # Get the current GPU temperature in degrees
echo -n "<RPM>" > /sys/module/LegionController/parameters/cFanCurve # Set the current fan RPM, for some reason this does not work outside the python program even though this is all it does.
Conservative Charging
Note: I have created a applet for cinnamon for toggling this here.
Linux can also modify and view conservative charging mode using the following commands:
# Enable
echo -n "1" | sudo tee /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode > /dev/null
# Disable
echo -n "0" | sudo tee /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode > /dev/null
# View state
cat /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode
If you want to make a script to handle this create the file ~/.local/bin/conservative and make it executable with the following contents:
#/bin/bash
MODE=$(cat /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode);
if [ "$1" == "status" ]; then
if [ "$MODE" == "1" ]; then
echo "enabled";
else
echo "disabled";
fi
exit 0;
elif [ "$1" == "enable" ]; then
if [ "$MODE" == "1" ]; then
echo "Conservative charging is already enabled.";
exit 1;
fi
echo -n "1" | sudo tee /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode > /dev/null;
exit 0;
elif [ "$1" == "disable" ]; then
if [ "$MODE" == "0" ]; then
echo "Conservative charging is already disabled.";
exit 1;
fi
echo -n "0" | sudo tee /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode > /dev/null;
exit 0;
else
echo "Usage: conservative [status|enable|disable]";
exit 1;
fi
Then you can use it like so:
# Enable
conservative enable
# Disable
conservative disable
# View state
conservative status
nvidia-smi
$ nvidia-smi
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver
Try installing ubuntu drivers.
sudo ubuntu-drivers autoinstall
Running on GPU (on-demand) (NEEDS TESTING)
When running in hybrid-graphics mode sometimes it is useful to run a command on the dGPU in which case you can prefix the command with:
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia <YOUR COMMAND> # This one seems to actually work.
For example to run a docker image I run:
_NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia docker run --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi
Other suggestions for using the GPU included:
DDPrefersNonDefaultGPU=true
X-KDE-RunOnDiscreteGpu=true
DRI_PRIME=1