如何使用bash保持GPU关闭?

时间:2021-07-30 09:40:30

I'm currently getting familiar with bash scripting. One of my problems is trying to fix a hybrid video on laptop by switching off the powerful GPU every time Linux loads.

我现在熟悉bash脚本。我的一个问题是尝试通过在每次Linux加载时关闭强大的GPU来修复笔记本电脑上的混合视频。

To do that, I currently edit rc.local by adding the following lines:

为此,我目前通过添加以下行来编辑rc.local:

chown -R $USER:$USER /sys/kernel/debug
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

The problem is, every time the system comes out of sleep mode, the GPU turns back on again, eventually going hotter and hotter, as indicated by lm-sensors.

问题是,每次系统退出睡眠模式时,GPU都会重新开启,最终变得越来越热,如lm-sensors所示。

My question: What do I have to do to keep said GPU turned off constantly?

我的问题:我必须做些什么来保持GPU不断关闭?

2 个解决方案

#1


1  

I think it's a bug and it hasn't been fixed yet, so for now you could call your script on wakeup events by adding something like this to /etc/pm/sleep.d

我认为这是一个错误,它还没有修复,所以现在你可以通过在/etc/pm/sleep.d上添加这样的东西来唤醒唤醒事件。

#!/bin/sh
case "${1}" in
    resume|thaw)
        vga_off.sh
        ;;
esac

Note: Are you sure the GPU turns on again ? or does it consume more power as reported in this bug ? if that's the case the workaround is to turn it on and off again.

注意:您确定GPU再次打开吗?或者它是否消耗了这个bug中报告的更多功率?如果是这种情况,解决方法是再次打开和关闭它。

#2


0  

There are likely many solutions to this problem, but one that would work is to put those two lines into a script, and then add it to your crontab to run every 5 minutes. This would cause the computer to disable the GPU every five minutes, and if it is already disabled it doesn't cause any adverse effect (besides running a short script every 5 minutes, which isn't much).

这个问题可能有很多解决方案,但可行的方法是将这两行放入脚本中,然后将其添加到crontab中,每5分钟运行一次。这将导致计算机每五分钟禁用一次GPU,如果它已经被禁用,它不会造成任何不利影响(除了每5分钟运行一个短脚本,这并不多)。

crontab -e
# Add the following line:
*/5 * * * * /home/user2057368/scripts/GPUTurnOffScript.sh

GPUTurnOffScript.sh can be written as follows:

GPUTurnOffScript.sh可以写成如下:

#!/bin/bash
chown -R $USER:$USER /sys/kernel/debug
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

Then you have to make sure it is executable by changing the permissions

然后,您必须通过更改权限来确保它是可执行的

sudo chmod u+x GPUTurnOffScript.sh

#1


1  

I think it's a bug and it hasn't been fixed yet, so for now you could call your script on wakeup events by adding something like this to /etc/pm/sleep.d

我认为这是一个错误,它还没有修复,所以现在你可以通过在/etc/pm/sleep.d上添加这样的东西来唤醒唤醒事件。

#!/bin/sh
case "${1}" in
    resume|thaw)
        vga_off.sh
        ;;
esac

Note: Are you sure the GPU turns on again ? or does it consume more power as reported in this bug ? if that's the case the workaround is to turn it on and off again.

注意:您确定GPU再次打开吗?或者它是否消耗了这个bug中报告的更多功率?如果是这种情况,解决方法是再次打开和关闭它。

#2


0  

There are likely many solutions to this problem, but one that would work is to put those two lines into a script, and then add it to your crontab to run every 5 minutes. This would cause the computer to disable the GPU every five minutes, and if it is already disabled it doesn't cause any adverse effect (besides running a short script every 5 minutes, which isn't much).

这个问题可能有很多解决方案,但可行的方法是将这两行放入脚本中,然后将其添加到crontab中,每5分钟运行一次。这将导致计算机每五分钟禁用一次GPU,如果它已经被禁用,它不会造成任何不利影响(除了每5分钟运行一个短脚本,这并不多)。

crontab -e
# Add the following line:
*/5 * * * * /home/user2057368/scripts/GPUTurnOffScript.sh

GPUTurnOffScript.sh can be written as follows:

GPUTurnOffScript.sh可以写成如下:

#!/bin/bash
chown -R $USER:$USER /sys/kernel/debug
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

Then you have to make sure it is executable by changing the permissions

然后,您必须通过更改权限来确保它是可执行的

sudo chmod u+x GPUTurnOffScript.sh