Frequent 2-Second Freezes When Starting To Type or Moving Mouse in X Session (KDE, Nvidia RTX 2060)

When I start typing, sometimes the screen will freeze for ~2 seconds, and my input will be duplicated. If I tried to type “A”, the input after it resumes will be “AA”. If I tried to type “Apple”, it will be “AApple”. If I try to alt+tab, I will alt+tab two times, not once. If I try to ctrl+w one of my browser windows in firefox, it will close two windows, not one. If I try to type my root password and it freezes, I have no idea what happens, but it ends up being incorrect when I press enter.

This is not consistently what happens when it freezes. Sometimes, the screen will just freeze and resume 2 seconds later with no duplicated input. Occasionally, my input will be dropped altogether.

This also happens when I haven’t moved my mouse for a while. If I move it, the screen will freeze, and when it resumes, my cursor will teleport to where I’ve moved it.

This does not occur in a TTY. This also does not occur when I continuously type without pausing. There doesn’t seem to be a particular amount of time I have to stop typing and resume typing for for this issue to occur. It’s random. It seems to occur more in my terminal emulator than on other programs, and also seems to be worse the longer my session is.

I’m not sure how long this issue has been present for, but it has been present for at least the past week (I haven’t used this computer for several months), and I can’t find any information about it.

I should mention that, a few months ago, I followed this tutorial to get PRIME offloading to work: [HowTo] Set up PRIME (output offload) with NVIDIA proprietary driver - Tutorials - Manjaro Linux Forum

Output of inxi -Fazy:

      Kernel: 5.4.67-1-MANJARO x86_64 bits: 64 compiler: gcc v: 10.2.0 
      parameters: BOOT_IMAGE=/boot/vmlinuz-5.4-x86_64 
      root=UUID=3d3aec24-d9b7-4604-99fb-f179d038058b rw quiet apparmor=1 
      security=apparmor resume=UUID=16fa0077-f554-4dba-9be9-a5b73eca95f3 
      Desktop: KDE Plasma 5.19.5 tk: Qt 5.15.1 wm: kwin_x11 dm: SDDM 
      Distro: Manjaro Linux 
      Type: Laptop System: ASUSTeK product: ROG Strix G531GV_G531GV v: 1.0 
      serial: <filter> 
      Mobo: ASUSTeK model: G531GV v: 1.0 serial: <filter> 
      UEFI: American Megatrends v: G531GV.306 date: 09/24/2019 
      ID-1: BAT0 charge: 60.5 Wh condition: 61.0/66.0 Wh (92%) volts: 15.7/15.7 
      model: ASUSTeK ASUS Battery type: Li-ion serial: N/A status: Not charging 
      Device-1: hidpp_battery_0 model: Logitech M720 Triathlon Multi-Device Mouse 
      serial: <filter> charge: 55% (should be ignored) rechargeable: yes 
      status: Discharging 
      Topology: 6-Core model: Intel Core i7-9750H bits: 64 type: MT MCP 
      arch: Kaby Lake family: 6 model-id: 9E (158) stepping: A (10) microcode: D6 
      L2 cache: 12.0 MiB 
      flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx 
      bogomips: 62431 
      Speed: 800 MHz min/max: 800/4500 MHz Core speeds (MHz): 1: 801 2: 800 3: 800 
      4: 800 5: 800 6: 800 7: 800 8: 800 9: 800 10: 800 11: 800 12: 800 
      Vulnerabilities: Type: itlb_multihit status: KVM: Split huge pages 
      Type: l1tf 
      mitigation: PTE Inversion; VMX: conditional cache flushes, SMT vulnerable 
      Type: mds mitigation: Clear CPU buffers; SMT vulnerable 
      Type: meltdown mitigation: PTI 
      Type: spec_store_bypass 
      mitigation: Speculative Store Bypass disabled via prctl and seccomp 
      Type: spectre_v1 
      mitigation: usercopy/swapgs barriers and __user pointer sanitization 
      Type: spectre_v2 mitigation: Full generic retpoline, IBPB: conditional, 
      IBRS_FW, STIBP: conditional, RSB filling 
      Type: srbds mitigation: Microcode 
      Type: tsx_async_abort status: Not affected 
      Device-1: Intel UHD Graphics 630 vendor: ASUSTeK driver: i915 v: kernel 
      bus ID: 00:02.0 chip ID: 8086:3e9b 
      Device-2: NVIDIA TU106M [GeForce RTX 2060 Mobile] vendor: ASUSTeK 
      driver: nvidia v: 440.100 alternate: nouveau,nvidia_drm bus ID: 01:00.0 
      chip ID: 10de:1f11 
      Display: x11 server: X.Org 1.20.9 compositor: kwin_x11 
      driver: modesetting,nvidia display ID: :0 screens: 1 
      Screen-1: 0 s-res: 1920x1080 s-dpi: 75 s-size: 652x366mm (25.7x14.4") 
      s-diag: 748mm (29.4") 
      Monitor-1: eDP-1-1 res: 1920x1080 hz: 120 dpi: 142 
      size: 344x194mm (13.5x7.6") diag: 395mm (15.5") 
      OpenGL: renderer: GeForce RTX 2060/PCIe/SSE2 v: 4.6.0 NVIDIA 440.100 
      direct render: Yes 
      Device-1: Intel Cannon Lake PCH cAVS vendor: ASUSTeK driver: snd_hda_intel 
      v: kernel alternate: snd_soc_skl,snd_sof_pci bus ID: 00:1f.3 
      chip ID: 8086:a348 
      Sound Server: ALSA v: k5.4.67-1-MANJARO 
      Device-1: Intel Wireless-AC 9560 [Jefferson Peak] driver: iwlwifi v: kernel 
      port: 5000 bus ID: 00:14.3 chip ID: 8086:a370 
      IF: wlo1 state: up mac: <filter> 
      Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet 
      vendor: ASUSTeK driver: r8169 v: kernel port: 3000 bus ID: 03:00.0 
      chip ID: 10ec:8168 
      IF: eno2 state: up speed: 100 Mbps duplex: full mac: <filter> 
      Local Storage: total: 942.70 GiB used: 566.96 GiB (60.1%) 
      SMART Message: Required tool smartctl not installed. Check --recommends 
      ID-1: /dev/nvme0n1 vendor: Intel model: SSDPEKNW512G8 size: 476.94 GiB 
      block size: physical: 512 B logical: 512 B speed: 31.6 Gb/s lanes: 4 
      serial: <filter> rev: 002C scheme: GPT 
      ID-2: /dev/sda type: USB vendor: Samsung model: Portable SSD T5 
      size: 465.76 GiB block size: physical: 512 B logical: 512 B serial: <filter> 
      scheme: GPT 
      ID-1: / raw size: 448.84 GiB size: 440.79 GiB (98.21%) 
      used: 117.64 GiB (26.7%) fs: ext4 dev: /dev/sda3 
      Kernel: swappiness: 60 (default) cache pressure: 100 (default) 
      ID-1: swap-1 type: partition size: 15.62 GiB used: 16.6 MiB (0.1%) 
      priority: -2 dev: /dev/sda1 
      System Temperatures: cpu: 49.0 C mobo: N/A gpu: nvidia temp: 44 C 
      Fan Speeds (RPM): cpu: 2500 
      Processes: 311 Uptime: 4h 30m Memory: 15.49 GiB used: 4.28 GiB (27.6%) 
      Init: systemd v: 246 Compilers: gcc: 10.2.0 alt: 8 clang: 10.0.1 
      Packages: 1515 pacman: 1508 lib: 422 flatpak: 4 snap: 3 Shell: Bash 
      v: 5.0.18 running in: konsole inxi: 3.1.05 

Some potentially relevant logs:

I don’t have an ~/xsession-errors file, but in my /etc/var/log/Xorg.0.log file, these lines seem suspect:

 6870.730] (EE) client bug: timer event6 debounce: scheduled expiry is in the past (-12ms), your system is too slow 
[  6870.730] (EE) client bug: timer event6 debounce short: scheduled expiry is in the past (-25ms), your system is too slow 
[  6872.220] (EE) client bug: timer event6 debounce: scheduled expiry is in the past (-2ms), your system is too slow 
[  6872.220] (EE) client bug: timer event6 debounce short: scheduled expiry is in the past (-15ms), your system is too slow 
[  6907.067] (EE) event15 - ELAN1405:00 04F3:30DF Touchpad: client bug: event processing lagging behind by 14ms, your system is too slow 
[  6927.530] (EE) event15 - ELAN1405:00 04F3:30DF Touchpad: client bug: event processing lagging behind by 12ms, your system is too slow 
[  7004.595] (EE) event15 - ELAN1405:00 04F3:30DF Touchpad: client bug: event processing lagging behind by 14ms, your system is too slow 
[  7135.977] (EE) event5  - ASUSTeK Computer Inc. N-KEY Device: client bug: event processing lagging behind by 27ms, your system is too slow 
[  7266.260] (II) event15 - ELAN1405:00 04F3:30DF Touchpad: SYN_DROPPED event - some input events have been lost. 
[  7302.713] (II) event6  - Logitech M720 Triathlon: SYN_DROPPED event - some input events have been lost.

Problem solved.

I reversed the steps of the tutorial to undo all of the changes made, then uninstalled all of my graphics drivers. I then installed the 450xx hybrid intel and nvidia drivers through KDE’s GUI. I rebooted the machine. My display manager was fixed, and the freezes were gone, but I could only use my iGPU. The drivers didn’t switch to Nvidia when doing graphically demanding tasks, like playing games on Steam.

I should mention that my X Nvidia Server Settings application wouldn’t load throughout this process at some points, but it works now after everything I’ve done.

I then installed optimus-manager and rebooted again. I attempted to switch with optimus-manager —switch nvidia, but was met with:

ERROR: a GPU setup was initiated but Xorg post-start hook did not run.
Log at /var/log/optimus-manager/switch/switch-20200516T172801.log
If your login manager is GDM, make sure to follow those instructions: … -gdm-users
If your display manager is neither GDM, SDDM nor LightDM, or if you don't use one, read the wiki: … leshooting
Cannot execute command because of previous errors.

As I was running SDDM, and after following the few instructions regarding KDE/SDDM on the github page and it still throwing the same error, I searched the error. I followed the advice of the last poster in this thread and everything works fine now: optimus manager the latest GPU setup attempt failed at Xorg pre-start / Newbie Corner / Arch Linux Forums

However, if I close the lid of my laptop while having switched to Nvidia, it will return to a black-screened X session where I can only move my cursor around. At this point, I had to move to my tty to run systemctl reboot.

Before closing my laptop, I must run prime-offload in the terminal emulator or tty, then optimus-manager —switch intel, type y to log out, and just to be sure, type prime-switch in the tty. This will prevent the issue from occurring.

It’s not particularly simple or elegant, but hey, it works. And no annoying freezes. Plus a normal-sized DM. I couldn’t ask for anything more.