Bug 256594 - AMD Ryzen CPU stutter (responsiveness lag)
Summary: AMD Ryzen CPU stutter (responsiveness lag)
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.0-STABLE
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2021-06-14 08:52 UTC by Jack
Modified: 2024-04-13 19:10 UTC (History)
16 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jack 2021-06-14 08:52:37 UTC
Using current CPU: AMD Ryzen 7 5800X 8-Core Processor              (3800.07-MHz K8-class CPU)

When running X on 13-STABLE, everything has a micro delay. When playing videos, the video keeps stuttering and audio periodically skips. Dragging things are not smooth, screen keeps stalling. An exact description of the problem was reported on the mailing list
https://lists.freebsd.org/pipermail/freebsd-current/2021-March/079235.html

Setting kern.sched.steal_thresh=0 made the problem go away completely.

Anything higher than 0 produces noticeable stuttering and delays in visuals and audio.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2021-06-14 12:11:19 UTC
^Triage: I am not really sure how to assign this.  But in the mean time, give it a little fuller Summary, and put the "performance" Keyword on.
Comment 2 crest 2021-06-14 13:21:53 UTC
I can confirm this observation on a R9 3950X with 32GB, booted from an NVMe SSD and a RTX 3090 even such "simple" things as scrolling in Chromium result in painful stuttering and glaring tearing with i3 as window manager.
Comment 3 Alan Somers freebsd_committer freebsd_triage 2021-06-18 14:06:15 UTC
This was recently discussed on freebsd-current.  CCing some of the folks from that thread.
https://docs.freebsd.org/cgi/getmsg.cgi?fetch=65134+0+archive/2021/freebsd-current/20210328.freebsd-current
Comment 4 Andriy Gapon freebsd_committer freebsd_triage 2021-12-19 09:32:33 UTC
On my setup, also with a Zen 3 CPU,  machdep.idle=mwait seems to improve the situation.
Comment 5 crest 2021-12-19 21:02:50 UTC
(In reply to Jack from comment #0)
I still require the same workaround on my Ryzen 3950X system as well.
Comment 6 Bob Frazier 2022-02-21 18:56:05 UTC
I reported what seems to be a similar bug on 12.2-STABLE

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260898

Workaround:
sysctl kern.eventtimer.timer=HPET
sysctl machdep.idle=mwait

(if necessary disable powerd also)

If this works, it's probably the same bug
Comment 7 Bob Frazier 2022-02-21 19:18:18 UTC
(In reply to Andriy Gapon from comment #4)

can you also try kern.eventtimer.timer=HPET ?

(this seems to make the most difference, especially if you have LAPIC assigned which I think is the default, and my guess is that it's pointing at the root cause of the problem if changing the event timer helps as much as I think it will)
Comment 8 Jack 2022-02-27 04:28:22 UTC
I can confirm that switching to HPET from LAPIC improves the lagging but there's still some scrolling lagginess when I'm trying to drag the scrollbars in windows.
Comment 9 ooonea 2022-04-04 17:14:21 UTC
(In reply to Bob Frazier from comment #6)
This workaround works great. Thank you.
Comment 10 simonytam@gmail.com 2022-12-25 01:49:41 UTC
When I boot into a FreeBSD install USB stick, I am seeing extreme lags in typing. If I hit one key, it will not show up until 2 or 3 seconds later. This makes the whole installation almost impossible when you need to select or enter parameters during the process.

I'm not sure if this is related to the same issue. 

I am on the following specs:

Ryzen 9 6900hs
Nvidia RTX 3050
Lenovo Slim 7 Pro X
Comment 11 crest 2022-12-25 14:53:01 UTC
If you're still stuck try breakout out into the loader prompt by pressing escape during the 10 second countdown in the bootloader menu. On the loader prompt type:

    set kern.sched.steal_thresh=0
    boot

To persist this you can put this line into /boot/loader.conf to apply as early as possible:

    kern.sched.steal_thresh="0"

To apply it slightly later you can add the same line to /etc/sysctl.conf as initially reported in this thread.

The stutter wasn't bad enough during installation on my personal workstation which als moonlights as a gaming rig (AMD Ryzen 9 3950X, 32GB DDR4-3600 RAM, RTX 3090 GPU). It just felt slightly off at the vt(4) console. I couldn't place it at the time. With Xorg and the Nvidia driver loaded the system was still fast when compiling etc., but felt very sluggish and lots of tearing in i3. Supposedly smooth scrolling in browsers etc. was nothing of the sort. To get a pleasant desktop experience without tearing I also had to force the Nvidia driver to use a less efficient form of composition which increased idle power consumption by ~10W, because it keeps the GPU from staying in the lowest power state even when just editing source code in urxvt and gvim.
Comment 12 simonytam@gmail.com 2022-12-26 01:37:36 UTC
Actually, sorry, I just discovered this might be a different bug altogether for the following reasons:

1. I tried setting kern.sched.steal_thresh=0 as per crest@rlwinm.de directions. There is no effect.
2. I tried the install of Release 12.4 instead and there is no more lag. However, I believe this bug affects both 13 and release 12.

I will need to investigate this issue through other channels instead to avoid hijacking the thread.