[PERF] VulkanVblankThr at nice 0: dropped frames under CPU load (much worse with Linux 7.3's default cgroup_mode)

オープン
#1,072 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
28/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
linux

調査の方向性

Start by reproducing with stress-ng --cpu $(nproc) and comparing /proc/<tid>/schedstat for VulkanVblankThr at nice 0 versus chrt -r -p 90, as the report does. The attached tools include vblank_ab.sh, cgmode_ab.sh, plot_ab.py and xr_pacing_probe.c; use the A/B block method to separate scheduling changes from run-to-run noise. Done would be a SteamVR-side policy that gives this thread realtime priority when CAP_SYS_NICE is available, with dropped-frame counts near the SCHED_RR 90 column under the same load.

索引モデルが issue の本文から書いたものです。

説明

perf

Describe the bug

vrcompositor's VulkanVblankThr runs as SCHED_OTHER at nice 0 (RenderThread and SignalThread get nice -10). On Linux 7.3.4, when every CPU thread is busy, it spends 250-445 ms of each second runnable but waiting for a CPU, and the compositor drops roughly 400 to 1200 frames a minute (of 5400 at 90 Hz). If I give that one thread a realtime priority with chrt, the waiting goes to under 0.3 ms a second and the drops to 20-60 a minute. They come back as soon as I undo it. nice -10 is not enough: 173 a minute under the load where SCHED_RR 90 gets 20.

Linux 7.3's new default cgroup weight mode makes it much worse (concur, https://github.com/torvalds/linux/commit/fb1050ac8e40aaa014291b5b53612d27890c2b09): a cgroup's weight now grows with the number of its runnable threads, so a 32-thread job weighs far more against a single nice 0 thread in another cgroup than it used to. Switching back to the old formula inside one session (echo smp > /sys/kernel/debug/sched/cgroup_mode) takes the drops from 1049 a minute to 127.

To Reproduce

  1. Start SteamVR and an app (I used hello_xr -g Vulkan from the OpenXR SDK), headset awake, frame timing graph open
  2. stress-ng --cpu $(nproc) in a terminal
  3. ps -T -o tid,cls,rtprio,ni,comm -p $(pgrep -x vrcompositor) | grep Vblank for the thread id, then sudo chrt -r -p 90 <tid>: most of the drops stop
  4. sudo chrt -o -p 0 <tid>: they come back
  5. cat /proc/$(pgrep -x vrcompositor)/task/<tid>/schedstat before and after each step: the second number is the time in ns the thread was runnable but not running

vblank_ab.sh in the attached tools zip does the switching in 90 s blocks (A B B A) and prints the numbers below; cgmode_ab.sh switches the kernel's mode instead.

Expected behavior

CPU load elsewhere on the machine doesn't turn into hundreds of dropped frames a minute. A realtime priority for VulkanVblankThr when vrcompositor has CAP_SYS_NICE would do that here.

System Information (please complete the following information):

  • Distribution: Arch Linux, kernel 7.3.4
  • SteamVR version: 2.19.3 beta (build 26655409). Same thread policy and the same picture on 2.18.4.
  • Steam client version: 1794536281
  • Opted into Steam client beta?: No
  • Graphics driver version: NVIDIA 620.70.06, open kernel modules
  • Gist for SteamVR System Information: not attached; I can add one if it helps. Bigscreen Beyond 2e at 90 Hz, Lighthouse tracking, KWin 6.8.2 (Wayland, DRM lease), Mesa 26.2.7.

Performance Data (optional, but very helpful):

  • CPU: i9-14900KS (32 threads)
  • GPU: RTX 4090
  • Gist for perf top: perf sched latency for the thread is in the results zip. Per wakeup under load: 1.1 ms on average and up to 51 ms at nice 0, 1.6 µs on average at SCHED_RR 90.
  • Link to gpuvis trace: none captured. I can make one if it helps.

Dropped frames per minute (sum of m_nNumDroppedFrames). VulkanVblankThr was switched every 90 s between nice 0 (A) and SCHED_RR 90 (B) in the order A B B A, the first 5 s of each block not counted; brackets give the lowest and highest block. SteamVR 2.19.3 unless noted:

App, load nice 0 (as shipped) SCHED_RR 90
my test app, stress-ng --cpu 32, 8 blocks 1216 (1084-1383) 20 (16-23)
my test app, kernel build (make -j32), 4 blocks 764 57
hello_xr, stress-ng --cpu 32, 4 blocks 422 28
SteamVR 2.18.4, my test app, stress-ng --cpu 32, 4 blocks of 60 s 801 22

The thread is busy: at SCHED_RR 90 it uses 77-79 ms of CPU per second with hello_xr and 178-195 with my test app.

The kernel's part: cgroup weight mode switched every 60 s inside one session (S C C S S C C S), same load, thread as shipped unless noted:

smp (formula of 7.2 and earlier) concur (7.3 default)
my test app 127 1049
my test app, VulkanVblankThr at SCHED_RR 90 (4 blocks) 1 12
hello_xr 57 416

Screenshots

Dropped frames per 5 s for the first row of each table (drawn by plot_ab.py):

stress-drops cgroup-mode-nice0-drops

Additional context

  • My test app is xr_pacing_probe.c in the tools zip: about 2 ms of CPU and 4.5 ms of GPU work per frame.
  • Measured on my daily desktop with its usual background jobs running. The comparison inside each session is the evidence.
  • RenderThread and SignalThread at SCHED_RR 99 instead of nice -10 made it worse under the same load: 1275 dropped frames a minute against 986 with the vblank thread at nice 0, 42 against 16 with it at SCHED_RR 90 (renderthread-rr99.txt in the results zip).

steamvr-vblank-tools.zip

vblank-results.zip

Note: Commenters who are also experiencing this issue are encouraged to include the "System Information" and "Perf Data" sections in their replies.

主要言語
Shell
スター
1.2k
フォーク
58
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ValveSoftware/SteamVR-for-Linux のほかの issue

ValveSoftware/SteamVR-for-Linux の issue をすべて見る

似ている issue

Shell/Bash の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。