Ejemplo n.º 1
0
def setup_PRIME():

    try:
        requested_mode = read_requested_mode()
    except VarError as e:
        raise XorgSetupError(
            "Cannot setup PRIME : cannot read requested mode : %s" % str(e))

    if requested_mode == "nvidia":

        print("Running xrandr commands")

        try:
            exec_bash("xrandr --setprovideroutputsource modesetting NVIDIA-0")
            exec_bash("xrandr --auto")
        except BashError as e:
            raise XorgSetupError("Cannot setup PRIME : %s" % str(e))

        print("Running %s" % envs.XSETUP_SCRIPT_NVIDIA)
        try:
            exec_bash(envs.XSETUP_SCRIPT_NVIDIA)
        except BashError as e:
            print("ERROR : cannot run %s : %s" %
                  (envs.XSETUP_SCRIPT_NVIDIA, str(e)))

    elif requested_mode == "intel":

        print("Running %s" % envs.XSETUP_SCRIPT_INTEL)
        try:
            exec_bash(envs.XSETUP_SCRIPT_INTEL)
        except BashError as e:
            print("ERROR : cannot run %s : %s" %
                  (envs.XSETUP_SCRIPT_INTEL, str(e)))
Ejemplo n.º 2
0
def _print_next_mode():

    try:
        requested_mode = read_requested_mode()
    except VarError as e:
        print("Error reading requested GPU mode : %s" % str(e))

    print("GPU mode requested for next login : %s" % requested_mode)
def _get_requested_mode():

    try:
        requested_mode = var.read_requested_mode()
    except var.VarError as e:
        print("Cannot read requested mode : %s" % str(e))
        sys.exit(1)

    return requested_mode
Ejemplo n.º 4
0
def main():

    # Arguments parsing
    parser = argparse.ArgumentParser(
        description=
        "Display Manager setup service for the Optimus Manager tool.\n"
        "https://github.com/Askannz/optimus-manager")
    parser.add_argument('--setup-start',
                        action='store_true',
                        help='Setup Optimus before the login manager starts.')
    parser.add_argument('--setup-stop',
                        action='store_true',
                        help='Cleanup Optimus after the login manager stops.')

    args = parser.parse_args()

    print("Optimus Manager (DM setup) version %s" % envs.VERSION)

    # Config
    try:
        config = load_config()
    except ConfigError as e:
        print("Error loading config file : %s" % str(e))
        sys.exit(1)

    if args.setup_start:

        print("Setting up Optimus configuration")

        # Cleanup
        clean_autogenerated()

        try:
            requested_mode = read_requested_mode()
        except VarError as e:

            print(
                "Cannot read requested mode : %s.\nUsing startup mode instead."
                % str(e))

            try:
                startup_mode = read_startup_mode()
            except VarError as e:
                print(
                    "Cannot read startup mode : %s.\nUsing default startup mode %s instead."
                    % (str(e), envs.DEFAULT_STARTUP_MODE))
                startup_mode = envs.DEFAULT_STARTUP_MODE

            print("Startup mode :", startup_mode)
            if startup_mode == "nvidia_once":
                requested_mode = "nvidia"
                write_startup_mode("intel")
            else:
                requested_mode = startup_mode

        # We are done reading the command
        remove_requested_mode_var()

        print("Requested mode :", requested_mode)

        try:
            if requested_mode == "nvidia":
                switch_to_nvidia(config)
            elif requested_mode == "intel":
                switch_to_intel(config)
        except SwitchError as e:
            print("Cannot switch GPUS : %s" % str(e))
            sys.exit(0)

    elif args.setup_stop:

        print("Cleaning up Optimus configuration")
        clean_autogenerated()

        #
        print("Terminating X11 sessions")
        try:
            terminate_current_x11_sessions()
        except SessionError as e:
            print("Error terminating sessions : %s" % str(e))

        #
        print("Killing remaining X11 servers")
        try:
            kill_current_xorg_servers()
        except XorgError as e:
            print("Error killing X servers : %s" % str(e))

        #
        # There is a known bug causing systemd-logind to keep ownership of the GPU
        # and prevents module unloading
        print("Killing systemd-logind")
        try:
            exec_bash("pkill systemd-logind")
        except BashError:
            pass

        print("Unloading kernel modules")
        try:
            exec_bash(
                "modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia nouveau"
            )
        except BashError as e:
            print("Cannot unload modules : %s" % str(e))
            sys.exit(1)

        # Reset the PCI device corresponding to the Nvidia GPU
        if config["optimus"]["pci_reset"] == "yes":
            if config["optimus"]["switching"] == "bbswitch":
                print("bbswitch is enabled, pci_reset option ignored.")
            else:
                print("Resetting the GPU")
                try:
                    pci.reset_gpu()
                except pci.PCIError as e:
                    print("Error resetting the PCI device : %s" % str(e))

    else:

        print("Invalid argument")