mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/ext: Add BPF function to fetch rq
@ 2024-07-08 14:01 Hongyan Xia
  2024-07-08 17:12 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Hongyan Xia @ 2024-07-08 14:01 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-kernel

rq contains many useful fields to implement a custom scheduler. For
example, various clock signals like clock_task and clock_pelt can be
used to track load. It also contains stats in other sched_classes, which
are useful to drive scheduling decisions in ext.

Signed-off-by: Hongyan Xia <hongyan.xia2@arm.com>
---
 kernel/sched/ext.c                       | 13 +++++++++++++
 tools/sched_ext/include/scx/common.bpf.h |  1 +
 2 files changed, 14 insertions(+)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 48c553b6f0c3..46438ece2fde 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -5642,6 +5642,18 @@ __bpf_kfunc void scx_bpf_kick_cpu(s32 cpu, u64 flags)
 	local_irq_restore(irq_flags);
 }
 
+/**
+ * scx_bpf_cpu_rq - Fetch the rq of a CPU
+ * @cpu: CPU of the rq
+ */
+__bpf_kfunc struct rq *scx_bpf_cpu_rq(s32 cpu)
+{
+	if (!ops_cpu_valid(cpu, NULL))
+		return NULL;
+
+	return cpu_rq(cpu);
+}
+
 /**
  * scx_bpf_dsq_nr_queued - Return the number of queued tasks
  * @dsq_id: id of the DSQ
@@ -6122,6 +6134,7 @@ __bpf_kfunc_end_defs();
 
 BTF_KFUNCS_START(scx_kfunc_ids_any)
 BTF_ID_FLAGS(func, scx_bpf_kick_cpu)
+BTF_ID_FLAGS(func, scx_bpf_cpu_rq)
 BTF_ID_FLAGS(func, scx_bpf_dsq_nr_queued)
 BTF_ID_FLAGS(func, scx_bpf_destroy_dsq)
 BTF_ID_FLAGS(func, scx_bpf_exit_bstr, KF_TRUSTED_ARGS)
diff --git a/tools/sched_ext/include/scx/common.bpf.h b/tools/sched_ext/include/scx/common.bpf.h
index 85ddc94fb4c1..fecc12aed1b0 100644
--- a/tools/sched_ext/include/scx/common.bpf.h
+++ b/tools/sched_ext/include/scx/common.bpf.h
@@ -37,6 +37,7 @@ void scx_bpf_dispatch_cancel(void) __ksym;
 bool scx_bpf_consume(u64 dsq_id) __ksym;
 u32 scx_bpf_reenqueue_local(void) __ksym;
 void scx_bpf_kick_cpu(s32 cpu, u64 flags) __ksym;
+struct rq *scx_bpf_cpu_rq(s32 cpu) __ksym;
 s32 scx_bpf_dsq_nr_queued(u64 dsq_id) __ksym;
 void scx_bpf_destroy_dsq(u64 dsq_id) __ksym;
 void scx_bpf_exit_bstr(s64 exit_code, char *fmt, unsigned long long *data, u32 data__sz) __ksym __weak;
-- 
2.34.1


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

* Re: [PATCH] sched/ext: Add BPF function to fetch rq
  2024-07-08 14:01 [PATCH] sched/ext: Add BPF function to fetch rq Hongyan Xia
@ 2024-07-08 17:12 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2024-07-08 17:12 UTC (permalink / raw)
  To: Hongyan Xia; +Cc: linux-kernel

Hello,

On Mon, Jul 08, 2024 at 03:01:18PM +0100, Hongyan Xia wrote:
> rq contains many useful fields to implement a custom scheduler. For
> example, various clock signals like clock_task and clock_pelt can be
> used to track load. It also contains stats in other sched_classes, which
> are useful to drive scheduling decisions in ext.
> 
> Signed-off-by: Hongyan Xia <hongyan.xia2@arm.com>

Applied to sched_ext/for-6.11. I moved the new helper below
scx_bpf_task_cpu() as that's the block for more generic accessors.

Thanks.

-- 
tejun

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

end of thread, other threads:[~2024-07-08 17:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-08 14:01 [PATCH] sched/ext: Add BPF function to fetch rq Hongyan Xia
2024-07-08 17:12 ` Tejun Heo

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®