简体   繁体   English

如何使用bash保持GPU关闭?

[英]How can I use bash to keep my GPU turned off?

I'm currently getting familiar with bash scripting. 我目前对bash脚本非常熟悉。 One of my problems is trying to fix a hybrid video on laptop by switching off the powerful GPU every time Linux loads. 我的问题之一是试图通过在每次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都会再次打开,最终变得越来越热,如流明传感器所指示。

My question: What do I have to do to keep said GPU turned off constantly? 我的问题:如何使GPU持续关闭?

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 ? 注意:您确定GPU再次打开? or does it consume more power as reported in this bug ? 还是会消耗此bug中报告的更多电量? if that's the case the workaround is to turn it on and off again. 如果是这种情况,解决方法是重新打开和关闭它。

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. 这个问题可能有很多解决方案,但是可行的方法是将这两行放入脚本中,然后将其添加到crontab中,每5分钟运行一次。 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). 这将导致计算机每五分钟禁用一次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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM