Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 689588

Summary: x11-drivers/nvidia-drivers-430.* : add new power management functions
Product: Gentoo Linux Reporter: Maik <hhfeuer>
Component: Current packagesAssignee: Jeroen Roovers <jer>
Status: UNCONFIRMED ---    
Severity: normal CC: o.freyermuth
Priority: Normal Keywords: NeedPatch
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: working (for me) nvidia-sleep.sh

Description Maik 2019-07-10 08:57:49 UTC
Starting with the v430 driver, the new kernel driver callback /proc/driver/nvidia/suspend was added to save/restore video memory on suspend/hibernate/resume to mitigate FBO corruption on resume:
https://download.nvidia.com/XFree86/Linux-x86_64/430.09/README/powermanagement.html
The driver package contains systemd units and a script.
Comment 1 Maik 2019-07-13 12:21:15 UTC
Created attachment 582756 [details]
working (for me) nvidia-sleep.sh

The nvidia-sleep.sh script included in the driver package is unusable, attaching a much simpler, working one which using chvt and fgconsole for vt switching.
Comment 2 Jeroen Roovers gentoo-dev 2019-07-13 12:35:03 UTC
Comment on attachment 582756 [details]
working (for me) nvidia-sleep.sh

Comments below the lines they relate to.


>#!/bin/bash

Nothing in particular should require bash specific features.

>
>RUN_DIR="/var/run/nvidia-sleep"

1) Shouldn't that be /run/... ?
2) It doesn't seem to make sense to me to create a directory in which a single temporary file will be placed.

>XORG_VT_FILE="${RUN_DIR}"/Xorg.vt_number
>
>case "$1" in
>    suspend|hibernate)
>        /bin/mkdir -p "${RUN_DIR}"
>        /usr/bin/fgconsole > "${XORG_VT_FILE}"
>        /usr/bin/chvt 63
>        if [[ $? -ne 0 ]]; then

This should be replaced with a non-bash test.

>                exit $?
>        fi
>        /bin/echo "$1" > /proc/driver/nvidia/suspend
>        exit $?
>        ;;
>    resume)
>        /bin/echo "$1" > /proc/driver/nvidia/suspend 

1) Looks like the line ends with a space.
2) What if this fails?

>        #
>        # 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}")
>            /bin/rm "${XORG_VT_FILE}"
>            /usr/bin/chvt "${XORG_PID}"
>        fi
>        exit 0
>        ;;
>    *)
>        exit 1
>esac
Comment 3 Maik 2019-07-13 12:50:17 UTC
(In reply to Jeroen Roovers from comment #2)
> Comment on attachment 582756 [details]
> >    resume)
> >        /bin/echo "$1" > /proc/driver/nvidia/suspend 
> 2) What if this fails?
If what fails? echoing? Please clarify.
echoing "resume" to that handle is instructing the driver to restore the video memory from tmp file. If that fails, the result would be the same corruption as it is now without that function. But there's no call back to get the result, AFAIK. Would be informational only, anyway, since you can literally see that it didn't work.
This is just the original script, I basically only replaced a lot of crap with that fgconsole line to get it to work at all, call it WIP.
Comment 4 Maik 2019-07-13 12:55:56 UTC
On second thought: those handles of course only exist if the nvidia driver is loaded so there has to be a check at the start of the script so it bails out if that isn't the case.
Comment 5 Maik 2019-07-13 14:34:09 UTC
A little ToDo-list for nvidia-sleep.sh besides the changes from post #2:
- make sure the handle /proc/driver/nvidia/suspend exists, i.e. the (correct) driver is loaded
- check /proc/driver/nvidia/params that the correct module parameter NVreg_PreserveVideoMemoryAllocations=1 is set
- make sure no Xorg is started on vt63, otherwise use other vt# and make note of it.
- writing to that handle only ever errors out if anything else than suspend,resume or hibernate is written to it, shouldn't happen due to switch case and previous check.