Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to reboot twice each time for switching gpu #16

Closed
liorlobel opened this issue Nov 7, 2019 · 10 comments
Closed

Need to reboot twice each time for switching gpu #16

liorlobel opened this issue Nov 7, 2019 · 10 comments

Comments

@liorlobel
Copy link

Hi, thanks for this awesome little program :)
I get this weird issue where each time I either disconnect or connect the eGPU I need to go through not only a shutdown but also a reboot.
I suspect this is an issue with lightdm as the egpu.service is running probably after the display-manager.service, so the startup is stuck, since it uses the old xorg.conf. In support of this, if I drop to a tty, kill lightdm and startx, I get to the DE.
I'm not sure about how to fix it and will be gratful for help.
Thanks,
Lior

@ewagner12
Copy link
Contributor

I can't confirm this on Ubuntu 19.10 with lightdm. Are you using ubuntu or a different distro?

@liorlobel
Copy link
Author

Yes, ubuntu mate 19.10

@ewagner12
Copy link
Contributor

Ok looking at the code and how systemd works it seems like there's a bit of a race condition right now. My laptop is slow to boot so it doesn't load the display manager faster than the switch command executes. I guess your computer is a lot faster than mine. If you want to try a solution would be to add
Before=display-manager.service
to /etc/systemd/system/egpu.service

@hertg
Copy link
Owner

hertg commented Nov 8, 2019

I've had this error too a while ago. But in my case, the problem was that the EGPU didn't connect fast enough so the script didn't recognize it. This is why this dirty workaround exists:

egpu-switcher/egpu-switcher

Lines 101 to 104 in 0cacc0a

if [ $1 = "lspci" ]; then
# giving your egpu some time to actually connect
sleep 5s

This is most definitely a timing issue, but i can't reproduce it with my system. I remember that there also were less problems on my notebook after i disabled the Thunderbolt Security in the BIOS. (See my comment on Thread.io)

I think i already tried to add the Before=display-manager.service while developing, but it didn't help back then. Still worth another try tho :)

@xabolcs
Copy link
Contributor

xabolcs commented Nov 8, 2019

Type oneshot is better for egpu.service than simple (the default).

With simple in my override.conf (see systemctl edit) the ExecPost= command started earlier than the ExecStart ended.

@hertg
Copy link
Owner

hertg commented Nov 8, 2019

Type oneshot is better for egpu.service than simple (the default).

Am I understanding it correctly that oneshot will block the startup until the script is finished, where simple does just run the script asynchronously, so that the display-manager might start while the script is still executing?

If that's correct, this would probably be the fix for this issue. (Would it still be good to define Before=display-manager.service, or would that be unnecessary?)

With simple in my override.conf (see systemctl edit) the ExecPost= command started earlier than the ExecStart ended.

I did not quite get what you mean by that.

@xabolcs
Copy link
Contributor

xabolcs commented Nov 8, 2019

I did not quite get what you mean by that.

I wanted to reuse the egpu-switcher's eGPU detection functionality to decide on what Display Manager should start. 😄

And instead of writing a dependent service, I just wrote an ExecStartPost= step "in" the egpu.service:

● egpu.service - EGPU Service
   Loaded: loaded (/etc/systemd/system/egpu.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/egpu.service.d
           └─override.conf
   Active: inactive (dead) since Fri 2019-11-08 19:49:47 CET; 57s ago
  Process: 2398 ExecStartPost=/mnt/data/data/DEV/PROJECTS/PRIVATE/systemd/egpu/set-display-manager.sh (code=exited, stat
  Process: 1026 ExecStart=/usr/bin/egpu-switcher switch auto (code=exited, status=0/SUCCESS)
  Process: 1008 ExecStartPre=/mnt/data/data/DEV/PROJECTS/PRIVATE/systemd/egpu/generate-checksum.sh (code=exited, status=
 Main PID: 1026 (code=exited, status=0/SUCCESS)

Nov 08 19:49:42 schorschbock-l egpu-switcher[1026]: [info] Using default argument for is_egpu_connected().
Nov 08 19:49:47 schorschbock-l egpu-switcher[1026]: [info] Automatically detecting if egpu is connected...  true
Nov 08 19:49:47 schorschbock-l egpu-switcher[1026]: [info] Create symlink /etc/X11/xorg.conf -> /etc/X11/xorg.conf.egpu
Nov 08 19:49:47 schorschbock-l set-display-manager.sh[2398]: /etc/X11/xorg.conf: OK
Nov 08 19:49:47 schorschbock-l set-display-manager.sh[2398]: Display Manager is lightdm already, nothing to see here!
Nov 08 19:49:47 schorschbock-l systemd[1]: Started EGPU Service.
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

Am I understanding it correctly that oneshot ...

Yup.

From SystemD documentation:

ExecStartPost= commands are only run after the commands specified in ExecStart= have been invoked successfully, as determined by Type= (i.e. the process has been started for Type=simple or Type=idle, the last ExecStart= process exited successfully for Type=oneshot, the initial process exited successfully for Type=forking, "READY=1" is sent for Type=notify, or the BusName= has been taken for Type=dbus).

Btw, the automatic DM selection between LightDM (in eGPU mode) and GDM3 (in internal mode) isn't achieved yet: it needs a restart like in this issue. 😞

@hertg
Copy link
Owner

hertg commented Nov 9, 2019

I just released a rather big update 0.11.1.
The egpu.service is now defined as Type=oneshot.
I hope that this resolves the issue, please feel free to open it again if the update didn't help with your problem. :)

@hertg hertg closed this as completed Nov 9, 2019
@liorlobel
Copy link
Author

Can confirm the issue is solved. Thanks so much :)

@eerozeteen
Copy link

Hi,
I had same issue with my Lenovo x230 @ Manjaro and Beast gdc egpu with Radeon HD7770. "Before=display-manager.service" in egpu.service solve it.
Please consider add it permanently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants