Skip to content

Instantly share code, notes, and snippets.

@vadimstasiev
Created July 19, 2022 16:57
Show Gist options
  • Select an option

  • Save vadimstasiev/bea4718d05b2502933c7294ef1de16e9 to your computer and use it in GitHub Desktop.

Select an option

Save vadimstasiev/bea4718d05b2502933c7294ef1de16e9 to your computer and use it in GitHub Desktop.
Archived: Linux Nvidia Overclocking on Optimus-enabled laptop

Original Source of these documents and files: https://forums.developer.nvidia.com/t/option-coolbits-is-not-used-optimus-enabled-laptop-running-an-rtx-2070-manjaro-linux/111771/13

Brief instructions

DISCLAIMER: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Prerequisites:

The script assumes you have a valid ${HOME}/.xinitrc to start your X session. If you can't start your window manager with startx command, then first learn how to do it. It also assumes you have all the proper drivers and nvidia-settings installed. Refer to the wiki pages of your distro for further instructions on this topic.

Migration of existing Xorg configuration:

It is always a good idea to backup your configuration files.

Check all your configuration files: /etc/X11/xorg.conf and/or files inside /etc/X11/xorg.conf.d/. If you have any custom options inside sections of type "Device" and "Screen", merge them with the sections inside the 10-nvidia.conf provided in this package, unless you have a multihead setup. In that case, I do not know how to properly merge the configuration files, but it should be relatively easy to do (probably keeping the external monitor section intact and merging the rest).

If you have any "ServerLayout" section, remove it. Chances are it only contains configurations required to setup PRIME or PRIME Render Offload. If you know you have other unrelated options inside it, migrate them to offload.layout and prime.layout.

You also need to check the BusID of your video cards, they are required inside 10-nvidia.conf. Refer to Arch Wiki for more information on how to check it: https://wiki.archlinux.org/index.php/Xorg#More_than_one_graphics_card Change the values inside 10-nvidia.conf to match the ones of your system.

After updating 10-nvidia.conf, offload.layout, and prime.layout with all the specific configurations of your system, you can move these files to /etc/X11/xorg.conf.d.

Also create a symbolic link to the Render Offload layout: sudo ln -sf /etc/X11/xorg.conf.d/offload.layout /etc/X11/xorg.conf.d/00-layout.conf

With all of that done, your startx command should work as usual.

Script configuration and usage

There are three variables you must edit inside startx-oc.sh:

  1. glx_offset: the desired graphics clock offset;
  2. mem_offset: the desired memory clock offset;
  3. perf_level: maximum performance level of your card (e.g. 2).

Further instructions and suggestions are given inside startx-oc.sh.

To use it, make sure it has permission to excute: chmod +x startx-oc.sh and simply execute it with ./startx-oc.sh. It will ask for your password one time to allow sudo. It is possible to circumvent this requirement, but I don't mind it, so it is up to you if you want to modify everything to work without password.

Good luck! Hexengraf

Section "Device"
Identifier "iGPU"
Driver "modesetting"
BusID "PCI:0:2:0" # change it to match the one of your system
EndSection
Section "Screen"
Identifier "iGPU"
Device "iGPU"
EndSection
Section "Device"
Identifier "dGPU"
Driver "nvidia"
BusID "PCI:1:0:0" # change it to match the one of your system
Option "Coolbits" "24" # change it to what you need
EndSection
Section "Screen"
Identifier "dGPU"
Device "dGPU"
Option "AllowEmptyInitialConfiguration"
EndSection
Section "ServerLayout"
Identifier "layout"
Screen 0 "iGPU"
Option "AllowNVIDIAGPUScreens"
EndSection
Section "ServerLayout"
Identifier "layout"
Screen 0 "dGPU"
Inactive "iGPU"
EndSection
#!/bin/sh
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following
# conditions:
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Author: Hexengraf
# Offset values. To search for stable values, use a separate Xorg session with PRIME.
# DO _NOT_ USE UNTESTED VALUES HERE!
glx_offset=170
mem_offset=300
# Maximum performance level (offsets are only assigned to the max level).
# Check the correct value in nvidia-settings, PowerMizer page.
perf_level=4
# Path to nvidia-settings.
# xinit requires a command starting with /, so a full path is necessary.
nvset_path=$(which nvidia-settings)
echo "Configuring Xorg to use PRIME..."
sudo ln -sf /etc/X11/xorg.conf.d/prime.layout /etc/X11/xorg.conf.d/00-layout.conf
# You can add more commands related to overclock here. For instance, cpu undervolting:
# sudo intel-undervolt apply
# First Xorg session: only assigns the offsets and closes.
# You can add more assignments beyond clock offsets. Just append them to the command.
xinit ${nvset_path} -a GPUGraphicsClockOffset[${perf_level}]=${glx_offset} \
-a GPUMemoryTransferRateOffset[${perf_level}]=${mem_offset}
echo "Configuring Xorg to use Render Offload..."
sudo ln -sf /etc/X11/xorg.conf.d/offload.layout /etc/X11/xorg.conf.d/00-layout.conf
# Second Xorg session: real session with window manager.
startx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment