387.34 and earlier - External monitor flashing on configuration change - Quadro M1000M

Setup: Lenovo P50, Gentoo Linux, kernel 4.14.X (all same behaviour); one externally connected monitor (HDMI), tried both Dell U2415 and HP z24i. The laptop has one integrated card (Intel) and one discrete card (nvidia)
The behaviour is the following:
Let’s assume that the system boots correctly and both monitors (internal and external) are working fine.
Any change to the configuration, either by removing the external monitor or using the tools to change any monitor configuration (like layout: relative position of the screens, resolution and so on) causes the monitors to flash several times, often without stopping until reboot.

More details:
The behaviour is way more serious when the laptop is on the docking station, hence the external monitor is connected thru the docking station hdmi plug.
On the same machine (dual boot) windows has no issues.
The behaviour happens when changing the layout using kde systemsetting tool or nvidia-settings. In the latter case, also changing the Force Composition switch triggers the issue.
When using the docking station, one way to stop monitor flashing is to hit several times shift/alt/F12, thus disabling and reenabling composition quickly; however if this stops monitors to flash, often the configuration is not the desired one, so the whole process has to be repeated several times.

The beaviour is more evident with the HP monitor and really annoying with the docking station, this leads me to think that the driver has some timing issues (say, the monitor is still settling after configuration change and the driver thinks it is off or something like this).

The behaviour happens both when using only discrete card (via bios) or when using prime setup.

When this happens, logs are full of messages like this:
[ 34.901] (–) NVIDIA(GPU-0): DFP-0: disconnected
[ 34.901] (–) NVIDIA(GPU-0): DFP-0: Internal TMDS
[ 34.901] (–) NVIDIA(GPU-0): DFP-0: 165.0 MHz maximum pixel clock
[ 34.901] (–) NVIDIA(GPU-0):
[ 35.032] (–) NVIDIA(GPU-0): DELL U2415 (DFP-1): connected
[ 35.032] (–) NVIDIA(GPU-0): DELL U2415 (DFP-1): Internal TMDS
[ 35.032] (–) NVIDIA(GPU-0): DELL U2415 (DFP-1): 340.0 MHz maximum pixel clock
[ 35.032] (–) NVIDIA(GPU-0):
[ 35.033] (–) NVIDIA(GPU-0): DFP-2: disconnected
[ 35.033] (–) NVIDIA(GPU-0): DFP-2: Internal TMDS
[ 35.033] (–) NVIDIA(GPU-0): DFP-2: 165.0 MHz maximum pixel clock
[ 35.033] (–) NVIDIA(GPU-0):
[ 35.033] (–) NVIDIA(GPU-0): DFP-3: disconnected
[ 35.033] (–) NVIDIA(GPU-0): DFP-3: Internal DisplayPort
[ 35.033] (–) NVIDIA(GPU-0): DFP-3: 960.0 MHz maximum pixel clock
[ 35.033] (–) NVIDIA(GPU-0):
[ 35.033] (–) NVIDIA(GPU-0): DFP-4: disconnected
[ 35.033] (–) NVIDIA(GPU-0): DFP-4: Internal DisplayPort
[ 35.033] (–) NVIDIA(GPU-0): DFP-4: 960.0 MHz maximum pixel clock
[ 35.033] (–) NVIDIA(GPU-0):
[ 35.033] (–) NVIDIA(GPU-0): DFP-5: disconnected
[ 35.033] (–) NVIDIA(GPU-0): DFP-5: Internal DisplayPort
[ 35.033] (–) NVIDIA(GPU-0): DFP-5: 960.0 MHz maximum pixel clock
[ 35.033] (–) NVIDIA(GPU-0):
[ 36.304] (II) NVIDIA(0): Setting mode “DP-1: nvidia-auto-select @1920x1200 +1920+0 {ViewPortIn=1920x1200, ViewPortOut=1920x1200+0+0}”
[ 36.480] (–) NVIDIA(GPU-0): DFP-0: disconnected
[ 36.480] (–) NVIDIA(GPU-0): DFP-0: Internal TMDS
[ 36.480] (–) NVIDIA(GPU-0): DFP-0: 165.0 MHz maximum pixel clock
[ 36.480] (–) NVIDIA(GPU-0):
[ 36.611] (–) NVIDIA(GPU-0): DELL U2415 (DFP-1): connected
[ 36.611] (–) NVIDIA(GPU-0): DELL U2415 (DFP-1): Internal TMDS
[ 36.611] (–) NVIDIA(GPU-0): DELL U2415 (DFP-1): 340.0 MHz maximum pixel clock
[ 36.611] (–) NVIDIA(GPU-0):
[ 36.612] (–) NVIDIA(GPU-0): DFP-2: disconnected
[ 36.612] (–) NVIDIA(GPU-0): DFP-2: Internal TMDS
[ 36.612] (–) NVIDIA(GPU-0): DFP-2: 165.0 MHz maximum pixel clock

nvidia-bug-report.log.gz (227 KB)

KWin and the binary nvidia driver have problems currently, look for XID 31 in this forum. That aside, try to disable the kscreen service and manage your screen setup either by nvidia-settings or any other randr manager and see if that helps.

Thanks for the hint, I’ll try to disable the kde management stuff and see what happens. Regarding the XID 31 issue, I’m not sure it can be connected to my problem; looking at logs, in the last 10 days I spotted only 3 entries reporting any XID issue and definitely not when the issue was happening.
Anyway, I’m curious to see what happens by disabling kscreen :)

You are right, the xid and your problem are unrelated but I wanted you to know in case you’re running into other issues.
The kscreen service is KDE’s monitor manager reacting on adding/removing/changing monitors, setting them up. Normally a useful part but a bit touchy especially when using the nvidia binary driver or using other mode setting tools giving sometimes strange results.

Thanks, indeed without kscreen2 the flashing disappeared, at least so far :).