Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
发挥NVIDIA PRIME的全部功力:真·自动切换(四)
Experiences and Insight
1683
views ·
0
replies ·
To
floor
Go
risez
deepin
2020-10-03 03:53
Author
本帖最后由 risez 于 2020-10-2 22:37 编辑
通用电源管理:只要使用PRIME方案即可生效,无需真自动切换功能
无论你的独显是否支持真自动切换功能,只要PRIME方案在你的机器上可以用就应该做本节要讲述的操作。如果不做,将导致电脑在挂起/休眠并恢复、或者挂起/休眠失败并紧急恢复之后PRIME失效,表现为:无法在nvidia-smi找到Xorg进程;无法调用独显跑应用程序;如果已经有应用程序在独显上跑,恢复后应用程序工作异常甚至崩溃。解决方法:重启Xorg,包括注销、杀死Xorg进程两种方法。
那种解决方法治标不治本,所以需要用到本节所提到的方法,而且使用该方法还可以更好地配合PRIME的自动切换功能进行电源管理。依次输入下面的命令:
sudo systemctl enable nvidia-suspend.service
sudo systemctl enable nvidia-hibernate.service
sudo systemctl enable nvidia-resume.service
Copy the Code
没有这些服务?尝试:
ls /usr/share/doc/NVIDIA_GLX-1.0/samples/systemd/
Copy the Code
如果有输出,执行下列命令:
sudo install /usr/share/doc/NVIDIA_GLX-1.0/samples/systemd/nvidia-suspend.service /etc/systemd/system
sudo install /usr/share/doc/NVIDIA_GLX-1.0/samples/systemd/nvidia-hibernate.service /etc/systemd/system
sudo install /usr/share/doc/NVIDIA_GLX-1.0/samples/systemd/nvidia-resume.service /etc/systemd/system
sudo install /usr/share/doc/NVIDIA_GLX-1.0/samples/systemd/nvidia /lib/systemd/system-sleep
sudo install /usr/share/doc/NVIDIA_GLX-1.0/samples/systemd/nvidia-sleep.sh /usr/bin
Copy the Code
如果还没有,使用find命令查找服务文件是否存在:
sudo find / -iname "服务文件名"
Copy the Code
还没有?来硬核的:
cd /usr/lib/systemd/system/
sudo nano nvidia-suspend.service
Copy the Code
添加以下内容:
[Unit]
Description=NVIDIA system suspend actions
Before=systemd-suspend.service
[Service]
Type=oneshot
ExecStart=/usr/bin/logger -t suspend -s "nvidia-suspend.service"
ExecStart=/usr/bin/nvidia-sleep.sh "suspend"
[Install]
RequiredBy=systemd-suspend.service
Copy the Code
继续创建新文件nvidia-hibernate.service:
[Unit]
Description=NVIDIA system hibernate actions
Before=systemd-hibernate.service
[Service]
Type=oneshot
ExecStart=/usr/bin/logger -t hibernate -s "nvidia-hibernate.service"
ExecStart=/usr/bin/nvidia-sleep.sh "hibernate"
[Install]
RequiredBy=systemd-hibernate.service
Copy the Code
再创建nvidia-resume.service:
[Unit]
Description=NVIDIA system resume actions
After=systemd-suspend.service
After=systemd-hibernate.service
[Service]
Type=oneshot
ExecStart=/usr/bin/logger -t suspend -s "nvidia-resume.service"
ExecStart=/usr/bin/nvidia-sleep.sh "resume"
[Install]
RequiredBy=systemd-suspend.service
RequiredBy=systemd-hibernate.service
Copy the Code
再创建/usr/bin/nvidia-sleep.sh:
#!/bin/bash
if [ ! -f /proc/driver/nvidia/suspend ]; then
exit 0
fi
RUN_DIR="/var/run/nvidia-sleep"
XORG_VT_FILE="${RUN_DIR}"/Xorg.vt_number
PATH="/bin:/usr/bin"
case "$1" in
suspend|hibernate)
mkdir -p "${RUN_DIR}"
fgconsole > "${XORG_VT_FILE}"
chvt 63
if [[ $? -ne 0 ]]; then
exit $?
fi
echo "$1" > /proc/driver/nvidia/suspend
exit $?
;;
resume)
echo "$1" > /proc/driver/nvidia/suspend
#
# Check if Xorg was determined to be running at the time
# of suspend, and whether its VT was recorded. If so,
# attempt to switch back to this VT.
#
if [[ -f "${XORG_VT_FILE}" ]]; then
XORG_PID=$(cat "${XORG_VT_FILE}")
rm "${XORG_VT_FILE}"
chvt "${XORG_PID}"
fi
exit 0
;;
*)
exit 1
esac
Copy the Code
最后创建/lib/systemd/system-sleep/nvidia:
#!/bin/sh
case "$1" in
post)
/usr/bin/nvidia-sleep.sh "resume"
;;
esac
Copy the Code
更改这些文件的权限:
sudo chmod 644 nvidia-suspend.service
sudo chmod 644 nvidia-hibernate.service
sudo chmod 644 nvidia-resume.service
sudo chmod 755 /usr/bin/nvidia-sleep.sh
sudo chmod 755 /lib/systemd/system-sleep/nvidia
Copy the Code
编辑/etc/modprobe.d/nvidia.conf,追加如下内容:
options nvidia "NVreg_PreserveVideoMemoryAllocations=1"
Copy the Code
检查你的挂起模式:
cat /sys/power/mem_sleep
Copy the Code
如果输出:
s2idle [deep]
Copy the Code
那就是设置好了,如果不是,且在之后的测试中电源管理不起效,则需要添加内核参数,以grub的添加方式为例,编辑/etc/default/grub,在GRUB_CMDLINE_LINUX_DEFAULT=后的参数中追加mem_sleep_default=deep,类似于下面这样,注意我的配置仅供参考,切勿直接复制粘贴:
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet nouveau.modeset=0 mem_sleep_default=deep"
Copy the Code
刷新grub:
grub-mkconfig -o /boot/grub/grub.cfg #等价于update-grub
Copy the Code
重启你的电脑使配置生效。
注意:如果重启后卡在启动lightdm进程上,请自行想办法修改/lib/udev/rules.d/80-nvidia-pm.rules,注释除function 0外的其它设备的启用代码并删除设备。
本文所有部分链接:
一:https://bbs.deepin.org/post/203224#=1##pid786085
二:https://bbs.deepin.org/post/203225#=1##pid786087
三:https://bbs.deepin.org/post/203226#=1##pid786088
四:https://bbs.deepin.org/post/203227#=1##pid786089
五:https://bbs.deepin.org/post/203228#=1##pid786090
Reply
Like 1
Favorite
View the author
All Replies
No replies yet
Please
sign
in first
Featured Collection
Change
[Tutorial] deepin25 WSL Offline Installation Guide
UOS AI 2.8 Released! Three New Intelligent Agents & Major Evolution
Solid Q&A | deepin 25 Common Questions – The Immutable System Edition
New Thread
Popular Ranking
Change
The settings menu needs to be translated into Russian.
the Network section no longer appears
Error during system installation
Deepin IDE?
Deepin Native Apps not launching in the latest version
Music player with sample rate and bit depth
Popular Events
More
通用电源管理:只要使用PRIME方案即可生效,无需真自动切换功能
本文所有部分链接:
一:https://bbs.deepin.org/post/203224#=1##pid786085
二:https://bbs.deepin.org/post/203225#=1##pid786087
三:https://bbs.deepin.org/post/203226#=1##pid786088
四:https://bbs.deepin.org/post/203227#=1##pid786089
五:https://bbs.deepin.org/post/203228#=1##pid786090