Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
software suspend 2 / nvidia - a success story
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
hothead
Apprentice
Apprentice


Joined: 02 Jul 2004
Posts: 277
Location: /dev/core

PostPosted: Mon Apr 18, 2005 12:55 pm    Post subject: software suspend 2 / nvidia - a success story Reply with quote

Yeah,

after playing around some time (much time) I finally got suspend2 working on my desktop machine.  

The testing phase was first very dissapointing. First problem was that the machine doesn't powered down. I found out that it was because of my gigabit
nic [via-velocity]
which was not blacklisted by the hibernate-script blacklist. So added it to the blacklist and commented out the nvidia driver.
After patching the nvidia driver [patch attached] I used the restart feature of software suspend to figure out if resuming works.
I had success at first go. Because it was allready really late I suspended and switched of the power of the box.

Next morning was the big dissapointed - the machine doesn't resume proper - black screen. I first thought about to abandon the suspend thing. But I'm
a real fighter. Because I have much spare time at the moment I decided to give it another try.

It seems that the restart feature of swsusp2 isn't enough to test if resume works. To make shure that resuming works, you have to power down your machine
and unplug the power supply and wait aprox. 15 min (maybe less should also work) before switching on the power.

So I tried several kernel combinations with different nvidia drivers with this method which was really time consuming.
None working combinations gave me the known blank screen after resuming.

I finally found out that I have to use the newest nvidia driver 1.0.7174,nvidia agp disabled in xorg.conf ( maybe 1.0.7167 does also work). together
with the vesafb. It works for me with kernel 2.6.10 and 2.6.11.7.


The downside of using the newest nvidia driver in comparison to 1.0.6629 isthat I get aprox. 500 glxgears less -> but 2500 are still enough for me.
For me it's worth paying 500 glxgears for resuming with 1G memory full of launched programs in less then a half minute.

Another problem was to get my external firewire harddisk recognized after resuming. I found out that I have to unload 'sd_mod sbp2 ohci1394' to make it
working. But sd_mod doesn't unload if the device is mounted or even if some bindings to the device exist. So I wrote my own suspend script that first
removes the bindings and then unmounts the device.

Below you can find links to a ebuild that applies the suspend patch when using the swsusp2 USE flag. You can also download my kernel kernel and xorg configuration.
Below you can look at the lscpi output to see what hardware I have. I also attached my suspend script which is in my
opinion more easy to understand and adapt than the more extensive hibernate-script.


Regards

hothead

Download section

Software Suspend 2 patch Informatinion at http://suspend2.net/
Alternative Suspend2 Script
Xorg Configuration
Kernel Configuration
nvidia-kernel ebuild with suspend patch (swsusp2 useflag)


System Information

I have a nforce2 mobo (Leadtek K7NCR18D) and a nvidia  GeForce FX 5600XT
graphics card.

lcpi output:

Code:
0000:00:00.0 Host bridge: nVidia Corporation nForce2 AGP (different version?) (rev a2)
0000:00:00.1 RAM memory: nVidia Corporation nForce2 Memory Controller 1 (rev a2)
0000:00:00.2 RAM memory: nVidia Corporation nForce2 Memory Controller 4 (rev a2)
0000:00:00.3 RAM memory: nVidia Corporation nForce2 Memory Controller 3 (rev a2)
0000:00:00.4 RAM memory: nVidia Corporation nForce2 Memory Controller 2 (rev a2)
0000:00:00.5 RAM memory: nVidia Corporation nForce2 Memory Controller 5 (rev a2)
0000:00:01.0 ISA bridge: nVidia Corporation nForce2 ISA Bridge (rev a3)
0000:00:01.1 SMBus: nVidia Corporation nForce2 SMBus (MCP) (rev a2)
0000:00:02.0 USB Controller: nVidia Corporation nForce2 USB Controller (rev a3)
0000:00:02.1 USB Controller: nVidia Corporation nForce2 USB Controller (rev a3)
0000:00:02.2 USB Controller: nVidia Corporation nForce2 USB Controller (rev a3)
0000:00:04.0 Ethernet controller: nVidia Corporation nForce2 Ethernet Controller (rev a1)
0000:00:05.0 Multimedia audio controller: nVidia Corporation nForce Audio Processing Unit (rev a2)
0000:00:06.0 Multimedia audio controller: nVidia Corporation nForce2 AC97 Audio Controler (MCP) (rev a1)
0000:00:08.0 PCI bridge: nVidia Corporation nForce2 External PCI Bridge (rev a3)
0000:00:09.0 IDE interface: nVidia Corporation nForce2 IDE (rev a2)
0000:00:0d.0 FireWire (IEEE 1394): nVidia Corporation nForce2 FireWire (IEEE 1394) Controller (rev a3)
0000:00:1e.0 PCI bridge: nVidia Corporation nForce2 AGP (rev a2)
0000:01:07.0 Ethernet controller: VIA Technologies, Inc. VT6120/VT6121/VT6122 Gigabit Ethernet Adapter (rev 11)
0000:01:08.0 Multimedia audio controller: Creative Labs SB Live! EMU10k1 (rev 0a)
0000:01:08.1 Input device controller: Creative Labs SB Live! MIDI/Game Port (rev 0a)
0000:03:00.0 VGA compatible controller: nVidia Corporation NV31 [GeForce FX 5600XT] (rev a1)

_________________
Got a question? - http://justfuckinggoogleit.com/


Last edited by hothead on Thu Apr 21, 2005 2:13 pm; edited 2 times in total
Back to top
View user's profile Send private message
baeksu
l33t
l33t


Joined: 26 Sep 2004
Posts: 609
Location: Seoul, Korea

PostPosted: Wed Apr 20, 2005 4:04 am    Post subject: Reply with quote

Thanks for the info, but the ftp gives '530 - Login incorrect'.

I myself am still using 6111 version, cause that's the only one I can patch for swsusp2 (found the patch on a forums somewhere).
_________________
Gnome:
1. A legendary being.
2. A never ending quest to make unix friendly to people who don't want unix and excruciating for those that do.
Back to top
View user's profile Send private message
hothead
Apprentice
Apprentice


Joined: 02 Jul 2004
Posts: 277
Location: /dev/core

PostPosted: Wed Apr 20, 2005 1:07 pm    Post subject: Reply with quote

:x seems the server of my provider is down ...

modified nvidia-kernel-1.0.7174.ebuild:

Code:
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/media-video/nvidia-kernel/nvidia-kernel-1.0.7174.ebuild,v 1.2 2005/04/02 18:14:08 eradicator Exp $

inherit eutils linux-mod

X86_PKG_V="pkg0"
AMD64_PKG_V="pkg2"
NV_V="${PV/1.0./1.0-}"
X86_NV_PACKAGE="NVIDIA-Linux-x86-${NV_V}"
AMD64_NV_PACKAGE="NVIDIA-Linux-x86_64-${NV_V}"

DESCRIPTION="Linux kernel module for the NVIDIA X11 driver"
HOMEPAGE="http://www.nvidia.com/"
SRC_URI="x86? (ftp://download.nvidia.com/XFree86/Linux-x86/${NV_V}/${X86_NV_PACKAGE}-${X86_PKG_V}.run)
   amd64? (http://download.nvidia.com/XFree86/Linux-x86_64/${NV_V}/${AMD64_NV_PACKAGE}-${AMD64_PKG_V}.run)"

if use x86; then
   PKG_V="${X86_PKG_V}"
   NV_PACKAGE="${X86_NV_PACKAGE}"
elif use amd64; then
   PKG_V="${AMD64_PKG_V}"
   NV_PACKAGE="${AMD64_NV_PACKAGE}"
fi

S="${WORKDIR}/${NV_PACKAGE}-${PKG_V}/usr/src/nv"

LICENSE="NVIDIA"
SLOT="0"
KEYWORDS="-* ~x86 ~amd64"
RESTRICT="nostrip"
IUSE="swsusp2"

DEPEND="virtual/linux-sources"
export _POSIX2_VERSION="199209"

MODULE_NAMES="nvidia(video:${S})"
BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} SYSOUT=${KV_OUT_DIR}"

mtrr_check() {
   ebegin "Checking for MTRR support"
   linux_chkconfig_present MTRR
   eend $?

   if [[ $? -ne 0 ]] ; then
      eerror "This version needs MTRR support for most chipsets!"
      eerror "Please enable MTRR support in your kernel config, found at:"
      eerror
      eerror "  Processor type and features"
      eerror "    [*] MTRR (Memory Type Range Register) support"
      eerror
      eerror "and recompile your kernel ..."
      die "MTRR support not detected!"
   fi
}

pkg_setup() {
   linux-mod_pkg_setup
   mtrr_check;
}

src_unpack() {
   local NV_PATCH_PREFIX="${FILESDIR}/${PV}/NVIDIA_kernel-1.0-${PV##*.}"

   if [[ ${KV_MINOR} -eq 6 && ${KV_PATCH} -lt 7 ]] ; then
      echo
      ewarn "Your kernel version is ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}"
      ewarn "This is not officially supported for ${P}. It is likely you"
      ewarn "will not be able to compile or use the kernel module."
      ewarn "It is recommended that you upgrade your kernel to a version >= 2.6.7"
      echo
      ewarn "DO NOT file bug reports for kernel versions less than 2.6.7 as they will be ignored."
   fi

   cd ${WORKDIR}
   bash ${DISTDIR}/${NV_PACKAGE}-${PKG_V}.run --extract-only

   # Add patches below, with a breif description.
   cd ${S}
   # Any general patches should go here
   # Shutup pointer arith warnings
   use x86 && epatch ${NV_PATCH_PREFIX//7174/7167}-x86-shutup-warnings.patch
   use amd64 && epatch ${NV_PATCH_PREFIX//7174/7167}-amd64-shutup-warnings.patch

   # Software Suspend hack
   use swsusp2 && epatch ${FILESDIR}/${PV}/suspend.patch   

   # Patches from Zander goes here
   # (http://www.nvnews.net/vbulletin/forumdisplay.php?f=14, or possibly
   #  archived here: http://www.minion.de/files/1.0-7167/)
   #epatch ${NV_PATCH_PREFIX}-1233959.patch
   #epatch ${NV_PATCH_PREFIX}-1237815.patch

   # Now any patches specific to the 2.6 kernel should go here
   if kernel_is 2 6 ; then
      einfo "Applying 2.6 kernel patches"
      # Fix the /usr/src/linux/include/asm not existing on koutput issue #58294
      epatch ${NV_PATCH_PREFIX//7174/7167}-conftest-koutput-includes.patch
      # Fix calling of smp_processor_id() when preempt is enabled
      epatch ${NV_PATCH_PREFIX//7174/7167}-disable-preempt-on-smp_processor_id.patch
   fi

   # if you set this then it's your own fault when stuff breaks :)
   [[ -n ${USE_CRAZY_OPTS} ]] && sed -i "s:-O:${CFLAGS}:" Makefile.*

   # If greater than 2.6.5 use M= instead of SUBDIR=
   cd ${S}; convert_to_m Makefile.kbuild
}

src_install() {
   linux-mod_src_install

   # Add the aliases
   sed -e 's:\${PACKAGE}:'${PF}':g' ${FILESDIR}/nvidia > ${WORKDIR}/nvidia
   insinto /etc/modules.d
   newins ${WORKDIR}/nvidia nvidia

   # Docs
   dodoc ${S}/../../share/doc/README

   # The device creation script
   into /
   newsbin ${S}/makedevices.sh NVmakedevices.sh
}

pkg_postinst() {
   if [[ "${ROOT}" = "/" && ! -e /dev/.devfsd && \
        ! -e /dev/.udev && -x /sbin/NVmakedevices.sh ]] ; then
      /sbin/NVmakedevices.sh >/dev/null 2>&1
   fi

   linux-mod_pkg_postinst
}


suspend patch, put into ${FILESDIR}/${PV}.
After that you should run 'ebuild nvidia-kernel-1.0.7174.ebuild digest' and 'USE=swsusp2 emerge nvidia-kernel' && emerge nvidia-glx.

Code:
diff -Nru NVIDIA-Linux-x86-1.0-7174-pkg0/usr/src/nv/nv.c NVIDIA-Linux-x86-1.0-7174-pkg0.mod/usr/src/nv/nv.c
--- NVIDIA-Linux-x86-1.0-7174-pkg0/usr/src/nv/nv.c   2005-03-22 15:36:23.000000000 +0000
+++ NVIDIA-Linux-x86-1.0-7174-pkg0.mod/usr/src/nv/nv.c   2005-04-14 20:35:37.000000000 +0000
@@ -3417,7 +3417,8 @@
     if ((!lnv) || (lnv->dev != dev))
     {
         nv_printf(NV_DBG_WARNINGS, "NVRM: ACPI: invalid device!\n");
-        return -1;
+        //return -1;
+   return 0;
     }
 
     nv = NV_STATE_PTR(lnv);
@@ -3425,6 +3426,7 @@
     switch (state)
     {
         case PM_SUSPEND_MEM:
+   case 1:
             nv_printf(NV_DBG_INFO, "NVRM: ACPI: received suspend event\n");
             status = rm_power_management(nv, 0, NV_PM_ACPI_STANDBY);
             break;


and here is the script

Code:
#!/bin/bash
# created by Ruben Jenster <webmaster@hotheads.de>

##################################################
# configuration
##################################################

# if you use a usb keyboard escape and reboot action will not be possible during suspend
MODULE_UNLOAD="forcedeth via_velocity ohci_hcd ehci_hcd sd_mod sbp2 ohci1394"
MODULE_LOAD="ehci_hcd ohci_hcd forcedeth via_velocity ohci1394"
MODULE_RELOAD=""
SERVICE_STOP="LCDd alsasound"
SERVICE_START="lcdproc alsasound jackd"
SERVICE_RESTART=""

NET_UMOUNT="yes" # umounts samba and nfs shares
DEV_UMOUNT="/media/Backup" # remove all mountpoints that match the pattern
DEV_MOUNT="" #doesn't work for hotpluggable devices, cause it takes to much time for them to register - may be polling

GRUB_CONFIG_CHANGE="yes"
GRUB_CONFIG="grub.conf"
GRUB_CONFIG_NORMAL="grub-normal.conf"
GRUB_CONFIG_SUSPENDED="grub-suspended.conf"

SWSUSP="yes"
SWSUSP_RESET_REBOOT="yes" # set reboot parameter do disabled [0] on sucessfull resume
SWSUSP_ENABLE_ESCAPE="yes" # allow escape during suspend

SYNTAX="gentoo" # possible: bash, gentoo

#######################################
# functions
#######################################

case $SYNTAX in
   "gentoo")
      source /sbin/functions.sh
      BEGIN="ebegin"
      END="eend $?"
      ERROR="eerror"
      INFO="einfo"
        ;;
   "bash")
      BEGIN="echo"
      END=""
      ERROR="echo"
      INFO="echo"
      ;;
esac

[[ $EUID != 0 ]] && $ERROR "You have to be root to run this script!" && exit 1

info(){
   $INFO "swsusp2 [run] run the whole script"
   $INFO "swsusp2 [--function FUNCTION] (-f short option) run a specific function"
}

net_umount(){
   if [ $NET_UMOUNT = yes ];then
      $BEGIN "Umounting network filesystems"
      umount -a -t nfs
      umount -a -t smb
      $END   
   fi
}

dev_umount(){
   for DEVICE in $DEV_UMOUNT
    do
      BIND_DEVICES="$(cat /etc/mtab | grep bind | egrep -o ${DEVICE}[a-zA-Z0-9/-]*)"
      for  BIND_DEVICE in $BIND_DEVICES
       do
         $BEGIN "Removing bindings for $DEVICE"
         umount $BIND_DEVICE
         $END
      done   
      
      HARD_DEVICES="$(cat /etc/mtab | grep -v bind | egrep -o ${DEVICE}[a-zA-Z0-9/-]*)"
      for HARD_DEVICE   in $HARD_DEVICES
       do
         $BEGIN "Umounting $HARD_DEVICE"
         umount $HARD_DEVICE
         $END
      done
   done
}

module_unload(){
   for MODULE in $MODULE_UNLOAD
    do
      if [ -d /sys/module/$MODULE ]; then
         $BEGIN "Unloading $MODULE"
         modprobe -r $MODULE
         $END
      fi
   done
}

service_stop(){
   for SERVICE in $SERVICE_STOP
    do
      if /etc/init.d/$SERVICE status | grep started >/dev/null; then
         $BEGIN "Stopping $SERVICE"
         /etc/init.d/$SERVICE stop
         $END
      fi
   done
}

grub_config_suspended(){
   if [ $GRUB_CONFIG_CHANGE = yes ]; then
      $BEGIN "Link $GRUB_CONFIG $GRUB_CONFIG_SUSPENDED"
      if cat  /etc/fstab | grep /boot >/dev/null && ! cat /etc/mtab | grep /boot >/dev/null; then
         mount /boot
      fi
      cd /boot/grub
      ln -sf  $GRUB_CONFIG_SUSPENDED $GRUB_CONFIG
      cd /
      if cat /etc/mtab | grep /boot >/dev/null; then
         umount /boot
      fi
      $END
   fi
}

swsusp_enable_escape(){
   if [ $SWSUSP_ENABLE_ESCAPE = yes ]; then
      echo 1 > /proc/software_suspend/enable_escape
   fi
}

swsusp2(){
   if [ $SWSUSP = yes ]; then
      chvt 63
      echo > /proc/software_suspend/do_suspend
   fi
}

service_start(){
   for SERVICE in $SERVICE_START
    do
      if /etc/init.d/$SERVICE status | grep stopped >/dev/null; then
         $BEGIN "Starting $SERVICE"
         /etc/init.d/$SERVICE start
         $END
      fi
   done
}

service_restart(){
   for SERVICE in $SERVICE_RESTART
    do
      $BEGIN "Restarting $SERVICE"
      /etc/init.d/$SERVICE restart
      $END
   done
}

module_reload(){
   for MODULE in $MODULE_RELOAD
    do
      if [ -d /sys/module/$MODULE ]; then
         $BEGIN "Reloading $MODULE"
         rmmod $MODULE
         modprobe $MODULE
         $END
      fi
   done
}

module_load(){
   for MODULE in $MODULE_LOAD
    do
      if ! [ -d /sys/module/$MODULE ]; then
         $BEGIN "Loading $MODULE"
         modprobe $MODULE
         $END
      fi
   done
}

swsusp_reset_reboot(){
   if [ $SWSUSP_RESET_REBOOT = yes ]; then
      $BEGIN "Set software suspend reboot to off"
      echo 0 > /proc/software_suspend/reboot
      $END
   fi
}

grub_config_normal(){
   if [ $GRUB_CONFIG_CHANGE = yes ]; then
      $BEGIN "Linking $GRUB_CONFIG to $GRUB_CONFIG_NORMAL"
      if cat  /etc/fstab | grep /boot >/dev/null && ! cat /etc/mtab | grep /boot >/dev/null; then
         mount /boot
      fi
      cd /boot/grub
      ln -sf $GRUB_CONFIG_NORMAL $GRUB_CONFIG
      cd /
      if cat /etc/mtab | grep /boot >/dev/null; then
         umount /boot
      fi
      $END
   fi
}

dev_mount(){
   for DEVICE in $DEV_MOUNT
    do
      if cat /etc/fstab | grep $DEVICE >/dev/null && ! cat /etc/mtab | grep $DEVICE >/dev/null; then
         $BEGIN "Mounting $DEVICE"
         mount $DEVICE
         $END
      fi
   done
}

############################################
# actions
############################################

case $1 in
   "--function")
      $2
      ;;
   "-f")
      $2
      ;;
   "run")
      # chvt 1 (can be executed before suspending) chvt 7 -> makes X working
      # chvt 1 (can be executed before suspending) chvt 7 chvt 1 -> makes console working
      chvt 1
      net_umount
      dev_umount
      module_unload
      service_stop
      grub_config_suspended
      swsusp_enable_escape
      swsusp2
      grub_config_suspended
      chvt 7
      module_reload
      module_load
      service_start
      service_restart
      swsusp_reset_reboot
      grub_config_normal
      dev_mount
      ;;
   *)
      info
      ;;
esac


xorg.conf should contain
Code:
Option          "NvAGP"                         "0"

in the device section

the graphics section of the kernel configuration should look like that
Code:
#
# Graphics support
#
CONFIG_FB=y
CONFIG_FB_MODE_HELPERS=y
CONFIG_FB_VESA=y
CONFIG_VIDEO_SELECT=y
#
# Console display driver support
#
CONFIG_VGA_CONSOLE=y
CONFIG_DUMMY_CONSOLE=y
CONFIG_FRAMEBUFFER_CONSOLE=y

_________________
Got a question? - http://justfuckinggoogleit.com/
Back to top
View user's profile Send private message
Sheepdogj15
Guru
Guru


Joined: 07 Jan 2005
Posts: 430
Location: Backyard

PostPosted: Wed Apr 20, 2005 9:22 pm    Post subject: Reply with quote

ooh, i have similar hardware (nforce3 ultra rather than nforce2). i'll try this out sometime, as i've been wanting a way to bring my system into standby/suspend.
_________________
Sheepdog
Why Risk It? | Samba Howto
Back to top
View user's profile Send private message
Aciel
Tux's lil' helper
Tux's lil' helper


Joined: 07 Jan 2004
Posts: 91

PostPosted: Thu Sep 01, 2005 5:22 pm    Post subject: Reply with quote

The link to the nvidia-kernel ebuild isn't working. Could someone please put up a new one?

Cheers,
John
Back to top
View user's profile Send private message
GaMMa
l33t
l33t


Joined: 23 Aug 2002
Posts: 684
Location: USA

PostPosted: Thu Oct 06, 2005 3:36 am    Post subject: Reply with quote

I got things working. Here's my quick guide and things I used, PM me if there are questions

kernel: archck-sources make sure agpgart is NOT selected.
xorg.conf: make sure Option "NvAGP" "1" in Section "Device"
nvidia-kernel: Make swsusp2 work with nvidia-kernel Also add
Code:
# apply patch that permits the driver to suspend
use suspend2 && epatch ${FILESDIR}/${PV}/suspend.patch
in the src_unpack() section and make sure you have suspend2 as a USE flag.

Things should work fine after that. Enjoy!
_________________
Ubuntu Linux Dapper Drake running Gnome-2.14.1
[Website | Screenshot | Portage Guide]
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum