Optimize nv_kthread_q batching and reduce per-item wakeup overhead#1050
Open
arch-fan wants to merge 1 commit intoNVIDIA:mainfrom
Open
Optimize nv_kthread_q batching and reduce per-item wakeup overhead#1050arch-fan wants to merge 1 commit intoNVIDIA:mainfrom
arch-fan wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change reduces the scheduling overhead of
nv_kthread_q, which is used acrossnvidia,nvidia-drm,nvidia-modeset, andnvidia-uvm.The previous implementation used a counting semaphore and dequeued exactly one item
per wakeup. This change switches the queue to a
wait_queue_head_t+pending_countmodel and drains queued items in batches.
What changed
wait_queue_head_t q_wait_queueatomic_t pending_count0 -> 1transition.list_splice_init()and process itin one pass.
tools/nv-kthread-q-bench/Why
nv_kthread_qsits on hot paths used by deferred work, bottom halves, and driver-sideevent handling. Waking the worker once per queued item adds avoidable scheduler and
locking overhead when the queue receives bursts of small work items.
Batch draining reduces:
Expected impact
This is primarily a latency/overhead optimization.
Potential user-visible impact:
This is not expected to materially increase peak GPU throughput by itself.
Testing
Build validation
Built successfully against the local Xanmod kernel development tree:
Generated successfully:
nvidia.konvidia-drm.konvidia-modeset.konvidia-uvm.koQueue model benchmark
Built and ran:
Observed results on this machine:
121.24 ns/item -> 32.17 ns/item3.77ximprovement89.46 ns/item -> 55.67 ns/item1.61ximprovementLimitations
Notes
The change is intentionally scoped to the queue internals and preserves the external
behavior of
nv_kthread_q.