Skip to content

scx_lavd: Add optional --queued-wakeup - #3958

Open
1343503048 wants to merge 2 commits into
sched-ext:mainfrom
1343503048:queue_wakeup
Open

1343503048 wants to merge 2 commits into
sched-ext:mainfrom
1343503048:queue_wakeup

Conversation

@1343503048

@1343503048 1343503048 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

LAVD currently disables queued-wakeup because its waker tracking
depends on current in ops.runnable() identifying the original waker,
which asynchronous activation does not guarantee.

Add an experimental --queued-wakeup option to enable
SCX_OPS_ALLOW_QUEUED_WAKEUP. In this mode, estimate the waker's wake
frequency from eligible SCX_WAKE_TTWU events in ops.select_cpu(),
where the original waking context is still available. Wakeups that
bypass select_cpu() are not counted.

Skip waker-dependent accounting in ops.runnable(), disabling
waker-wakee criticality propagation and the RT/DL waker boost. Keep the
option disabled by default because these signals affect LAVD's latency
policy. Reject an explicit request on kernels that lack the required
flag.

Test results

Compare the same binary with and without --queued-wakeup on kernel
7.3.0-rc3, using interleaved runs on an AMD EPYC 9654. No scheduler aborts
or verifier rejections were observed.

The baseline is the option disabled, normalized to 1.00. Positive
improvement means lower wall time or latency, or higher RPS.

[hackbench socket]

Process mode, socketpair communication, 100-byte messages.
CPU affinity and memory placement are restricted to the same NUMA node.
The case suffix denotes the -f argument.

case                load       loops     baseline    improvement
process-socket-8     2-groups   400000       1.00        +13.55%
process-socket-8     4-groups   400000       1.00        +10.28%
process-socket-8     6-groups   300000       1.00        +10.32%

Wall time decreases from 15.5s to 13.4s, 10.7s to 9.6s, and 12.6s to
11.3s, respectively.

[schbench]

Common arguments: -F 64 -s 100.
CPU affinity is restricted to one LLC, with memory bound to its NUMA
node. The no-lock cases use -L.

case              load         metric          baseline  improvement
batch-no-lock     m1/t16/n0     wakeup-p99          1.00      +17.07%
batch-no-lock     m1/t16/n0     wakeup-p99.9        1.00      +17.78%
compute-no-lock   m4/t8/n1      request-p99.9       1.00       +2.18%
compute-lock      m4/t8/n1      request-p99.9       1.00       +0.62%
compute-lock      m4/t8/n1      RPS                 1.00       -4.27%

System CPU time decreases by 7-14% across the tested schbench cases.
The compute-with-lock case shows a throughput regression, with only a
small reduction in request tail latency.

These results compare the complete optional mode, including changes to
waker accounting and criticality propagation. They do not isolate the
contribution of queued activation alone.

@1343503048
1343503048 marked this pull request as ready for review November 2, 2026 02:17
@1343503048
1343503048 force-pushed the queue_wakeup branch 2 times, most recently from 54fb833 to 1ff37eb Compare November 5, 2026 07:28
@1343503048

Copy link
Copy Markdown
Contributor Author

@multics69 Hi, a gentle ping for review.

I'd appreciate your feedback on the optional queued-wakeup mode, particularly whether disabling waker-dependent criticality propagation is an acceptable trade-off. Happy to adjust the approach or add more tests if needed.

Thanks!

@multics69

Copy link
Copy Markdown
Contributor

@1343503048 -- Thanks for the PR and ping. I will find some free cycles next week for this one and the other one. Have a nice weekend!

@multics69 multics69 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @1343503048 , for the PR. Queued wakeups are worth having.
Here are a few suggestions for improvement.

1. ops.select_cpu() vs. ops.runnable()

Moving the waker accounting from ops.runnable() to ops.select_cpu() loses
wakeups, because try_to_wake_up() skips ops.select_cpu() when:

  1. The wakee is pinned to one CPU or migration-disabled. select_task_rq()
    calls the class hook only for nr_cpus_allowed > 1 && !is_migration_disabled(p). Losing these is not acceptable.
  2. sched_ext is bypassing. Transient, so fine.
  3. In queued mode, the wakee is still on its CPU (on_cpu == 1). ttwu
    queues it on that CPU's wake list and returns before
    select_task_rq(). This hits tasks woken right after they block, as in
    request-reply over pipes or sockets. The default mode spins on
    p->on_cpu there, so this may be where much of the hackbench gain
    comes from.

2. Propagation must stay

lat_cri propagation in both directions and the RT/DL waker boost are
core to LAVD. Please keep them.

3. Suggestion: tp_btf/sched_waking

It fires in try_to_wake_up(), in the waker's context and under
p->pi_lock, before the on_cpu shortcut and select_task_rq(), so it
covers all three cases above. It sees every wakeup that reaches
ops.runnable() with SCX_ENQ_WAKEUP, since ttwu_queue() and
sched_ttwu_pending() both run after it. Fork and exec do not fire it
(fork fires sched_wakeup_new, and exec is not a wakeup), so they behave
as today.

The wakee is its argument and the waker is bpf_get_current_task_btf().
Please move the whole waker block from ops.runnable() there, including
propagation and the irq-wakeup flags. Then nothing is disabled in queued
mode, and the select_cpu() accounting, the early return in ops.runnable()
and the third commit can go. Using it in both modes also closes case 1
in the default mode.

What differs from ops.runnable():

  • It fires on every wakeup, and also before init_task and after exit.
    Reject non-ext wakees first. Do not reject RT/DL wakers, which set
    WOKEN_BY_RT_DL. Do the ctx lookups last and quietly.
  • It also fires when the wakee had not blocked yet (ttwu_runnable()).
    Please take this case into account. The wakee may then still be on its
    CPU and race with its own callbacks, because only p->pi_lock is held,
    not its rq lock. Use READ_ONCE()/WRITE_ONCE() on the shared fields.
  • There are no enq_flags. SCX_ENQ_WAKEUP is implied, and the
    PREEMPT/REENQ/LAST filter has nothing to catch in ttwu, so it can be
    dropped.

4. Option

Please do not fail when --queued-wakeup is given on a kernel without
SCX_OPS_ALLOW_QUEUED_WAKEUP. Print a warning and run without it.
Failing ties the deployment to the kernel version, and the default mode
is a safe fallback.

5. Testing

Please show two things separately:

  1. The cost of the new waker tracking, compared to main. I expect it to
    be marginal, but we should know it.
  2. The gain from queued activation alone. NO_TTWU_QUEUE in
    /sys/kernel/debug/sched/features keeps every wakeup synchronous even
    with the flag set, which may help to isolate it.

For workloads, please use wakeup-heavy micro-benchmarks, including one
with many RT wakeups for the rejection path, plus application-level
benchmarks if possible. The latter will show when the flag is worth
turning on.

6. README

The README is not kept up to date anyway, so please drop the README
change.

Zhang Qiao added 2 commits November 18, 2026 11:48
Wake-list activation can run on the wakee's CPU, where current no
longer identifies the waker. CPU selection also misses pinned tasks
and wakeups queued before the kernel selects a CPU.

Track the wakeup before activation so LAVD sees the original waker in
either mode and can propagate latency criticality in both directions.
A wakee may still be runnable at that point. Keep the pending boosts
in separate fields and consume them atomically so a concurrent wakeup
cannot clobber unrelated flags or be lost between a read and a clear.

Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
Wakeup-heavy workloads can avoid waiting for a remote task to finish
switching out by letting the kernel queue its activation on that CPU.

Allow queued activation when requested. Warn and use synchronous
activation when the kernel lacks SCX_OPS_ALLOW_QUEUED_WAKEUP.

Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
@multics69

Copy link
Copy Markdown
Contributor

@1343503048 -- In addition to my comments, do you have real-world use cases showing how the queued wake-up helps?

@1343503048

Copy link
Copy Markdown
Contributor Author

@1343503048 -- In addition to my comments, do you have real-world use cases showing how the queued wake-up helps?

I tested gRPC Java HelloWorld with ghz over loopback to exercise the handoff from Netty I/O threads to application workers. I used the same scx_lavd run with --queued-wakeup and toggled only the kernel feature between NO_TTWU_QUEUE and TTWU_QUEUE.

workload Mean latency, off → on p99 latency, off → on
10k RPC/s 0.355 → 0.340 ms (−4.2%) 5.140 → 4.815 ms (−6.3%)
20k RPC/s (near saturation) 1.713 → 1.628 ms (−5.0%) 7.850 → 7.235 ms (−7.8%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants