mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/5] sched_ext: Support high-performance monotonically non-decreasing clock
@ 2024-11-16 16:01 Changwoo Min
  2024-11-16 16:01 ` [PATCH 1/5] sched_ext: Implement scx_rq_clock_update/stale() Changwoo Min
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Changwoo Min @ 2024-11-16 16:01 UTC (permalink / raw)
  To: tj, void; +Cc: mingo, peterz, changwoo, kernel-dev, linux-kernel

Many BPF schedulers (such as scx_lavd, scx_rusty, scx_bpfland)
frequently call bpf_ktime_get_ns() for tracking tasks' runtime
properties. If supported, bpf_ktime_get_ns() eventually reads a hardware
timestamp counter (TSC). However, reading a hardware TSC is not
performant in some hardware platforms, degrading IPC.

This patchset addresses the performance problem of reading hardware TSC
by leveraging the rq clock in the scheduler core, introducing a
scx_bpf_clock_get_ns() function for BPF schedulers. Whenever the rq clock
is fresh enough, scx_bpf_clock_get_ns() provides the rq clock, which is
already updated by the scheduler core (update_rq_clock), so it can reduce
the reading TSC calls.

When the rq lock is released (rq_unpin_lock) or a long-running
operations are done by the BPF scheduler (ops.running, ops.update_idle),
the rq clock is invalidated, so a subsequent scx_bpf_clock_get_ns() call
gets the fresh sched_clock for the caller.

In addition, scx_bpf_clock_get_ns() guarantees the clock is
monotonically non-decreasing for the same CPU, so the clock cannot go
backward in the same CPU.

Using scx_bpf_clock_get_ns() reduces the number of reading hardware TSC
by 40-70% (65% for scx_lavd, 58% for scx_bpfland, and 43% for scx_rusty)
for the following benchmark.

    perf bench -f simple sched messaging -t -g 20 -l 6000

The patchset begins by managing the status of rq clock in the scheduler
core, then implementing scx_bpf_clock_get_ns(), and finally applying it
to the BPF schedulers.

Changwoo Min (5):
  sched_ext: Implement scx_rq_clock_update/stale()
  sched_ext: Manage the validity of scx_rq_clock
  sched_ext: Implement scx_bpf_clock_get_ns()
  sched_ext: Add scx_bpf_clock_get_ns() for BPF scheduler
  sched_ext: Replace bpf_ktime_get_ns() to scx_bpf_clock_get_ns()

 kernel/sched/core.c                      |  6 +-
 kernel/sched/ext.c                       | 74 ++++++++++++++++++++++++
 kernel/sched/sched.h                     | 22 ++++++-
 tools/sched_ext/include/scx/common.bpf.h |  1 +
 tools/sched_ext/include/scx/compat.bpf.h |  5 ++
 tools/sched_ext/scx_central.bpf.c        |  4 +-
 tools/sched_ext/scx_flatcg.bpf.c         |  2 +-
 7 files changed, 109 insertions(+), 5 deletions(-)

-- 
2.47.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-11-27  0:42 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-16 16:01 [PATCH 0/5] sched_ext: Support high-performance monotonically non-decreasing clock Changwoo Min
2024-11-16 16:01 ` [PATCH 1/5] sched_ext: Implement scx_rq_clock_update/stale() Changwoo Min
2024-11-16 16:01 ` [PATCH 2/5] sched_ext: Manage the validity of scx_rq_clock Changwoo Min
2024-11-16 19:32   ` Peter Zijlstra
2024-11-17 15:46     ` Changwoo Min
2024-11-18  9:41       ` Peter Zijlstra
2024-11-19  1:19         ` Changwoo Min
2024-11-19  8:17           ` Peter Zijlstra
2024-11-19 15:57             ` Changwoo Min
2024-11-27  0:41               ` Changwoo Min
2024-11-16 16:01 ` [PATCH 3/5] sched_ext: Implement scx_bpf_clock_get_ns() Changwoo Min
2024-11-16 19:31   ` Peter Zijlstra
2024-11-17 15:48     ` Changwoo Min
2024-11-18  9:44       ` Peter Zijlstra
2024-11-16 16:01 ` [PATCH 4/5] sched_ext: Add scx_bpf_clock_get_ns() for BPF scheduler Changwoo Min
2024-11-16 16:01 ` [PATCH 5/5] sched_ext: Replace bpf_ktime_get_ns() to scx_bpf_clock_get_ns() Changwoo Min

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®