Amateur Topologist

Politics, programming, math, and science.

Fixing screen flickers on Linux with NVIDIA

I use Ubuntu 9.04 for my non-gaming computing typically; I enjoy the increased customizability, and the terminal program included by default is infinitely better than Windows’s shitty cmd.exe. But one of the things that bugged me for a while is that my screen would intermittently flicker black; parts or all of it would just turn black for a fraction of a second and return to normal. I managed to figure that it was only happening when I had the Compiz window compositing manager running, but all the suggestions I was given failed to fix it. Eventually, I tracked it down to PowerMizer, a feature NVIDIA includes with its graphics cards in order to decrease power usage. It’s useful, but sometimes changing power settings on the graphics card can cause the screen to flicker. So I did some quick Googling, and found a fix that works by disabling it entirely. But this will increase power consumption and possibly cause your laptop to heat up (not dangerously so, but enough to be noticeable), so for completeness’s sake I recommend you try these steps first:

  1. Disable Compiz and use your system for a while; by doing so, you should prevent PowerMizer from having to switch the power supply by ensuring the load on your GFX card never passes a certain level. If it’s still flickering, something else is the culprit.
  2. Run Compiz with the –loose-binding option but not with –indirect-rendering. If you’re using fusion-icon, which I heavily recommend, you can right-click it and toggle these under “Compiz Options”. If you’re manually starting it, you’ll need to add/remove these switches to whatever process you use to start it.
  3. Open CompizConfig Settings Manager, and in the Workarounds settings, under Utility, enable Force Synchronization between X and GLX.
  4. If steps 2 or 3 worked, play around with those three settings until you find something that works for you. I personally enable loose binding due to the performance increase it gives me, but your mileage may vary.

If all else fails, read on.

Since you’re reading this, you must be encountering the PowerMizer bug, and it’s time to mess around with PowerMizer. This will involve editing your xorg.conf file a bit, so I (HIGHLY, HIGHLY) recommend you make a backup by running

sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.powermizerbackup

beforehand. Note the capitalization of the X in X11. In case this somehow royally messes up your system and/or config file (which it shouldn’t; it just involves adding one line) you can just copy the backup over the modified version.

With that out of the way, open /etc/X11/xorg.conf for editing. You’ll need to do so as root, so run

gksu gedit /etc/X11/xorg.conf

(or whatever editor you want to use if you don’t like gedit). Now, find the section that starts with

Section "Device"

. It should have the line

Identifier "Device0"

nearby; if it doesn’t, something’s wrong. Start a new line somewhere between

Section "Device"

and the

EndSection

that should come a few lines later, and add

Option "RegistryDwords"

to the beginning of that line. What you put after that determines the settings PowerMizer will apply. There are four ‘parameters’ you can put in the configuration string, each of which has a hexadecimal value; you specify them in the form “parameter1=value1; parameter2=value2; parameter3=value3…”. Since the values are all hexadecimal, you need to include a 0x before each of the values.

  • PerfLevelSrc tells PowerMizer what ‘strategies’ to use on AC and battery power. The two strategies are ‘fixed’ and ‘adaptive’; ‘fixed’ tells PowerMizer to always use the same clock frequency, and ‘adaptive’ tells it to dynamically select one. The value for PerfLevelSrc is of the form xxyy, where xx specifies the battery power strategy and yy specifies the AC power strategy. Fixed is 22, and adaptive is 33.
  • PowerMizerDefault corresponds to the default clock frequency for battery power. 1 corresponds to maximum performance, 3 is maximum battery life, and 2 is an intermediate. Yes, I know it’s backwards.
  • PowerMizerDefaultAC is the same as PowerMizerDefault, but for AC power.
  • PowerMizerEnable enables PowerMizer, obviously. Set this to 1.

So for example, if I wanted mycard to run at maximum frequency on AC power, but adaptive frequency on battery, I would use the line

Option "RegistryDwords" "PowerMizerEnable=0x1; PerfLevelSrc=3322; PowerMizerDefaultAC=0x1"

If I wanted it to always run on minimum power on battery and maximum power on AC, the line would be

Option "RegistryDwords" "PowerMizerEnable=0x1; PerfLevelSrc=2222; PowerMizerDefaultAC=0x1; PowerMizerDefault=0x3"

You get the picture. By way of example, the relevant setting of my xorg.conf file currently reads:

Section "Device"
Identifier     "Device0"
Driver         "nvidia"
VendorName     "NVIDIA Corporation"
Option "RegistryDwords"    "PowerMizerEnable=0x1; PerfLevelSrc=0x2222; PowerMizerDefault=0x3; PowerMizerDefaultAC=0x1"
EndSection

Once you’re done, save and close, and reboot and/or restart X. You can find more information about power settings and such at this site, which is where I got the information on the parameters for RegistryDwords.

Next post »

One ResponseLeave one →

  1. bert

     /  June 3, 2010

    Worked for me. Thanks

    Reply

Leave a Reply