haimgel / display-switch

Turn a $30 USB switch into a full-featured multi-monitor KVM switch
https://haim.dev/posts/2020-07-28-dual-monitor-kvm/
MIT License
2.85k stars 112 forks source link

Complete Freeze on macOS 10.15.7 when monitors connected #34

Closed christianhuening closed 10 months ago

christianhuening commented 3 years ago

Hi, when running display-switch 0.3.0 on macOS 10.15.7 and i have monitors connected via HDMI, my mac goes into a complete freeze and won't wake up anymore. Only unplugging the monitors and hard-rebooting it, solves the issue.

The logs have this to say:

05:56:08 [INFO] Configuration loaded ("/Users/chris/Library/Preferences/display-switch.ini"): Configuration { usb_device: "046d:c539", input_sources: InputSources { on_usb_connect: Some(Hdmi1(0x11)), on_usb_disconnect: None }, monitor1: None, monitor2: None, monitor3: None, monitor4: None, monitor5: None, monitor6: None }
05:56:08 [ERROR] Did not detect any DDC-compatible displays!
05:57:03 [DEBUG] (1) display_switch::app: Detected device change. Added device: "2109:0813"
05:57:04 [DEBUG] (1) display_switch::app: Detected device change. Added device: "2109:2813"
05:57:04 [DEBUG] (1) display_switch::app: Detected device change. Added device: "1a40:0101"
05:57:05 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
05:57:05 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
05:57:05 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
05:57:06 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:c541"
05:57:06 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05ac:1393"
05:57:06 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:c539"
05:57:06 [INFO] Monitored device ("046d:c539") is connected
05:57:06 [DEBUG] (1) display_switch::display_control: Setting display 'ROG XG279Q' to Hdmi1(0x11)
05:57:06 [ERROR] Failed to set display 'ROG XG279Q' to Hdmi1(0x11) (Io(-1))
05:57:06 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
05:57:07 [DEBUG] (1) display_switch::app: Detected device change. Added device: "2109:d101"
05:57:09 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0b05:1919"
06:02:20 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "05e3:0610"
06:02:20 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0b05:1919"
06:02:20 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0892"
06:02:22 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
06:02:23 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
06:02:56 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0b05:1919"
06:04:44 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "05e3:0610"
06:04:44 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0b05:1919"
06:04:44 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0892"
06:04:45 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
06:04:46 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
06:04:59 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "05e3:0610"
06:04:59 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0892"
06:05:07 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
06:05:08 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0b05:1919"
06:05:08 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
06:05:24 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "05e3:0610"
06:05:24 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0b05:1919"
06:05:24 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0892"
06:05:25 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
06:05:25 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
06:05:43 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0b05:1919"
06:06:41 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "05e3:0610"
06:06:41 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0b05:1919"
06:06:41 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0892"
06:07:12 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
06:07:12 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0b05:1919"
06:07:13 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
06:07:30 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "05e3:0610"
06:07:30 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0b05:1919"
06:07:30 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0892"
06:07:30 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
06:07:31 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
06:07:34 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0b05:1919"
06:08:19 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "05e3:0610"
06:08:19 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0892"
06:08:19 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0b05:1919"
06:08:21 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
06:08:22 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
06:08:45 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0b05:1919"
06:09:12 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "05e3:0610"
06:09:12 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0b05:1919"
06:09:12 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0892"
06:09:13 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
06:09:14 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
06:09:29 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0b05:1919"
06:10:03 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "05e3:0610"
06:10:03 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0892"
06:10:03 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0b05:1919"
06:10:04 [DEBUG] (1) display_switch::app: Detected device change. Added device: "05e3:0610"
06:10:05 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0892"
06:10:06 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0b05:1919"
haimgel commented 3 years ago

This is unfortunate, sorry to hear that. A few questions:

  1. What kind of Mac hardware do you have? I'm especially interested in the graphics card type.
  2. Have you tried a previous version of display-switch before?
  3. Can you try ddcctl and see if it works for you, or also freezes?
christianhuening commented 3 years ago

@haimgel

  1. it's a 13" MacBook Pro from 2019. GPU is Intel Iris Plus Graphics 655 with 1536 MB
  2. No, first attempt
  3. I think it does:
    ddcctl (master) ✔ ./ddcctl -h                                                                                                                                         (christian.huening-prod/kit-system)
    D: NSScreen #751428481 (2560x1440 0°) 109.00 DPI
    D: NSScreen #441056002 (2560x1440 0°) 109.00 DPI
    I: found 2 external displays
    2020-10-01 09:10:37.197 ddcctl[99479:1285798] ddcctl 0.1x - Usage:
michalskalski commented 3 years ago

Same for me:

  1. MacBook Pro 13" 2017. Intel Iris Plus Graphics 650
  2. First attempt, build from current master
  3. Seems to work:
    ./ddcctl -d 1 -i 17
    D: NSScreen #724847437 (2560x1440 0°) 118.00 DPI
    I: found 1 external display
    I: polling display 1's EDID
    I: got edid.serial: 9X2VY63516WL
    I: got edid.name: DELL U2515H
    D: action: i: 17
    D: setting VCP control #96 => 17

    Mac is connected to monitor through USB-C Digital AV Multiport Adapter, on hdmi1 port.

It seems that system hangs when program enters https://github.com/haimgel/ddc-macos-rs/blob/main/src/iokit/io2c_interface.rs#L94 . It does not happen always but often. If there is more info which I could provide please let me know.

abnovak commented 3 years ago

I'm also seeing this issue running on a 2018 Mac Mini, Intel UHD Graphics 630 1536 MB.

ddcctl does work for me on this machine, but I'm looking to switch inputs based on USB devices being plugged in, so I was hoping to be able to use display-switch.

Have the modifications made by @michalskalski been incorporated into this project? TIA!

michalskalski commented 3 years ago

@abnovak Hi I did not proposed back my change here, because I don't fully understand the cause of this issue. Found some similar problems in ddcctl project, but I wanted to better understand sequence of events which leads to kernel panics. I will try come back to it this week.

abnovak commented 3 years ago

Excellent, thanks @michalskalski. I'm happy to test anything if you need it, just let me know.

haimgel commented 3 years ago

@michalskalski great investigation! Did the change that you did fixed the issue reliably?

I've also found this thread, which hints that AMD and Intel video drivers treat this delay at a different scale, e.g. AMD considers it to be nanoseconds and Intel treats it as milliseconds...

I think this is best handled at run-time, rather than as a build-time configuration setting. E.g. this will necessitate detection of the video hardware driver type, and setting the appropriate delay.

Unfortunately, I won't have time to dig deeper into this in the next few weeks, and don't have the hardware to test, but will review/accept PRs.

nazwa commented 3 years ago

I tried to test @michalskalski's solution, but it still caused the freeze me.

~However, my Rust knowledge is close to zero, so could someone check if the following change is sufficient to apply his patch:~

Alright, the previous attempt was wrong. I tried it again with a properly "patched" dependency, but it still caused a freeze... 😢


# THIS STILL DOESN'T HELP 
[patch.crates-io]
ddc-macos = { path = "../ddc-patch" }

After stepping through the code, I can confirm that it's definitely crashing on the I2C request, even with the patch. https://github.com/haimgel/ddc-macos-rs/blob/main/src/monitor.rs#L227

yaojialyu commented 2 years ago

Same issue on MacBook Pro Late 2013 with Big Sur 11.6

haimgel commented 10 months ago

Looks like this issue is no longer present (at least in recent-gen Macs), and I cannot reproduce it. Closing.