Repository navigation
scx_lavd: Add optional --queued-wakeup - #3958
1343503048 wants to merge 2 commits into
Conversation
54fb833 to
1ff37eb
Compare
|
@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! |
|
@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
left a comment
There was a problem hiding this comment.
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:
- The wakee is pinned to one CPU or migration-disabled. select_task_rq()
calls the class hook only fornr_cpus_allowed > 1 && !is_migration_disabled(p). Losing these is not acceptable. - sched_ext is bypassing. Transient, so fine.
- 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_cputhere, 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:
- The cost of the new waker tracking, compared to main. I expect it to
be marginal, but we should know it. - 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.
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>
|
@1343503048 -- In addition to my comments, do you have real-world use cases showing how the queued wake-up helps? |
I tested gRPC Java
|
1ff37eb to
834bf80
Compare
LAVD currently disables queued-wakeup because its waker tracking
depends on
currentinops.runnable()identifying the original waker,which asynchronous activation does not guarantee.
Add an experimental
--queued-wakeupoption to enableSCX_OPS_ALLOW_QUEUED_WAKEUP. In this mode, estimate the waker's wakefrequency from eligible
SCX_WAKE_TTWUevents inops.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(), disablingwaker-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-wakeupon kernel7.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
-fargument.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.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.