Skip to content

sched: Fix SCX_ENQ_CPU_SELECTED for queued wakeups

Kuba Piecuch lkml sched-ext 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 0 repliesNew
  2. v12 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- Patch 1: Reword the description to distinguish the wakelist path before ->select_task_rq() from the one after it, and fix the ttwu_do_activate() name (Andrea). Add Acked-by from Tejun and Reviewed-by from Andrea.
- Patch 2: Give each ping-pong task its own two CPUs and dispatch to SCX_DSQ_LOCAL. The waker and the wakee then always run on different CPUs, so the test no longer depends on tasks spreading out on their own (Sashiko). Skip on systems with fewer than four CPUs.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2sched/core: Preserve WF_RQ_SELECTED across queued wakeupsinclude/linux/sched.h kernel/sched/core.c+13 -30 replies
2/2selftests/sched_ext: Test SCX_ENQ_CPU_SELECTED with queued wakeupstools/testing/selftests/sched_ext/Makefile tools/testing/selftests/sched_ext/enq_cpu_selected.bpf.c tools/testing/selftests/sched_ext/enq_cpu_selected.c+306 -00 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchTejun HeoAndrea Righi
1/2A-b R-b
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/2] sched: Fix SCX_ENQ_CPU_SELECTED for queued wakeups

SCX_ENQ_CPU_SELECTED is meant to tell ops.enqueue() whether ops.select_cpu() ran for a wakeup. However, wakeups delivered through the ttwu wakelist never have the flag set, because sched_ttwu_pending() drops WF_RQ_SELECTED. Schedulers that set SCX_OPS_ALLOW_QUEUED_WAKEUP therefore cannot tell whether ops.select_cpu() was skipped, and SCX_EV_SELECT_CPU_FALLBACK is undercounted.

Patch 1 carries WF_RQ_SELECTED across the wakelist the same way WF_MIGRATED already is. Patch 2 adds a selftest. In a 4-vCPU VM, without patch 1 the test reports that all of the roughly 100k queued wakeups in a 2s run had ops.select_cpu() called but SCX_ENQ_CPU_SELECTED clear. With patch 1 there are none.

Patch 1 changes kernel/sched/core.c and include/linux/sched.h, but only sched_ext sees the effect. Peter, Tejun: I'll leave it to you to decide whether the series goes through tip or the sched_ext tree.

The bug was found, and the series was drafted, with the help of an AI coding agent.

Changes in v2:
- Patch 1: Reword the description to distinguish the wakelist path before ->select_task_rq() from the one after it, and fix the ttwu_do_activate() name (Andrea). Add Acked-by from Tejun and Reviewed-by from Andrea.
- Patch 2: Give each ping-pong task its own two CPUs and dispatch to SCX_DSQ_LOCAL. The waker and the wakee then always run on different CPUs, so the test no longer depends on tasks spreading out on their own (Sashiko). Skip on systems with fewer than four CPUs.

v1: https://lore.kernel.org/r/[email protected]

Kuba Piecuch (2):
sched/core: Preserve WF_RQ_SELECTED across queued wakeups selftests/sched_ext: Test SCX_ENQ_CPU_SELECTED with queued wakeups

 include/linux/sched.h                         |   6 +-
 kernel/sched/core.c                           |  10 +-
 tools/testing/selftests/sched_ext/Makefile    |   1 +
 .../sched_ext/enq_cpu_selected.bpf.c          | 111 ++++++++++
 .../selftests/sched_ext/enq_cpu_selected.c    | 194 ++++++++++++++++++
 5 files changed, 319 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/sched_ext/enq_cpu_selected.bpf.c
 create mode 100644 tools/testing/selftests/sched_ext/enq_cpu_selected.c

base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b

Signature · 1 line
2.56.0.257.gf7497c7d27-goog