From: Changwoo Min <changwoo@igalia.com>
To: tj@kernel.org, void@manifault.com, arighi@nvidia.com
Cc: kernel-dev@igalia.com, linux-kernel@vger.kernel.org,
Changwoo Min <changwoo@igalia.com>
Subject: [PATCH v3 02/11] sched_ext: Add an event, SCX_EV_SELECT_CPU_FALLBACK
Date: Fri, 31 Jan 2025 16:09:29 +0900 [thread overview]
Message-ID: <20250131070938.95551-3-changwoo@igalia.com> (raw)
In-Reply-To: <20250131070938.95551-1-changwoo@igalia.com>
Add a core event, SCX_EV_SELECT_CPU_FALLBACK, which represents how many times
ops.select_cpu() returns a CPU that the task can't use.
__scx_add_event() is used since the caller holds an rq lock,
so the preemption has already been disabled.
Signed-off-by: Changwoo Min <changwoo@igalia.com>
---
include/linux/sched/ext.h | 1 +
kernel/sched/ext.c | 14 ++++++++++++++
2 files changed, 15 insertions(+)
diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h
index 1d70a9867fb1..f7545430a548 100644
--- a/include/linux/sched/ext.h
+++ b/include/linux/sched/ext.h
@@ -146,6 +146,7 @@ struct sched_ext_entity {
u32 weight;
s32 sticky_cpu;
s32 holding_cpu;
+ s32 selected_cpu;
u32 kf_mask; /* see scx_kf_mask above */
struct task_struct *kf_tasks[2]; /* see SCX_CALL_OP_TASK() */
atomic_long_t ops_state;
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 4e28e88e88d4..4d3b32aca48d 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -1444,6 +1444,11 @@ static struct task_struct *scx_task_iter_next_locked(struct scx_task_iter *iter)
* Collection of event counters. Event types are placed in descending order.
*/
struct scx_event_stats {
+ /*
+ * If ops.select_cpu() returns a CPU which can't be used by the task,
+ * the core scheduler code silently picks a fallback CPU.
+ */
+ u64 SCX_EV_SELECT_CPU_FALLBACK;
};
/*
@@ -2170,6 +2175,11 @@ static void enqueue_task_scx(struct rq *rq, struct task_struct *p, int enq_flags
do_enqueue_task(rq, p, enq_flags, sticky_cpu);
out:
rq->scx.flags &= ~SCX_RQ_IN_WAKEUP;
+
+ if ((enq_flags & SCX_ENQ_CPU_SELECTED) &&
+ (cpu_of(rq) != p->scx.selected_cpu)) {
+ __scx_add_event(SCX_EV_SELECT_CPU_FALLBACK, 1);
+ }
}
static void ops_dequeue(struct task_struct *p, u64 deq_flags)
@@ -3240,6 +3250,7 @@ static int select_task_rq_scx(struct task_struct *p, int prev_cpu, int wake_flag
cpu = SCX_CALL_OP_TASK_RET(SCX_KF_ENQUEUE | SCX_KF_SELECT_CPU,
select_cpu, p, prev_cpu, wake_flags);
+ p->scx.selected_cpu = cpu;
*ddsp_taskp = NULL;
if (ops_cpu_valid(cpu, "from ops.select_cpu()"))
return cpu;
@@ -3250,6 +3261,7 @@ static int select_task_rq_scx(struct task_struct *p, int prev_cpu, int wake_flag
s32 cpu;
cpu = scx_select_cpu_dfl(p, prev_cpu, wake_flags, &found);
+ p->scx.selected_cpu = cpu;
if (found) {
p->scx.slice = SCX_SLICE_DFL;
p->scx.ddsp_dsq_id = SCX_DSQ_LOCAL;
@@ -4957,6 +4969,7 @@ static void scx_dump_state(struct scx_exit_info *ei, size_t dump_len)
dump_line(&s, "--------------");
scx_bpf_events(&events, sizeof(events));
+ scx_dump_event(s, &events, SCX_EV_SELECT_CPU_FALLBACK);
if (seq_buf_has_overflowed(&s) && dump_len >= sizeof(trunc_marker))
memcpy(ei->dump + dump_len - sizeof(trunc_marker),
@@ -7090,6 +7103,7 @@ __bpf_kfunc void scx_bpf_events(struct scx_event_stats *events,
memset(&e_sys, 0, sizeof(e_sys));
for_each_possible_cpu(cpu) {
e_cpu = per_cpu_ptr(&event_stats_cpu, cpu);
+ scx_agg_event(&e_sys, e_cpu, SCX_EV_SELECT_CPU_FALLBACK);
}
/*
--
2.48.1
next prev parent reply other threads:[~2025-01-31 7:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-31 7:09 [PATCH v3 00/11] sched_ext: Implement core event counters Changwoo Min
2025-01-31 7:09 ` [PATCH v3 01/11] sched_ext: Implement event counter infrastructure Changwoo Min
2025-01-31 7:09 ` Changwoo Min [this message]
2025-02-02 17:34 ` [PATCH v3 02/11] sched_ext: Add an event, SCX_EV_SELECT_CPU_FALLBACK Tejun Heo
2025-01-31 7:09 ` [PATCH v3 03/11] sched_ext: Add an event, SCX_EV_DISPATCH_LOCAL_DSQ_OFFLINE Changwoo Min
2025-01-31 7:09 ` [PATCH v3 04/11] sched_ext: Add an event, SCX_EV_DISPATCH_KEEP_LAST Changwoo Min
2025-02-02 17:24 ` Tejun Heo
2025-01-31 7:09 ` [PATCH v3 05/11] sched_ext: Add an event, SCX_EV_ENQ_SKIP_EXITING Changwoo Min
2025-02-02 17:20 ` Tejun Heo
2025-02-03 15:46 ` Changwoo Min
2025-01-31 7:09 ` [PATCH v3 06/11] sched_ext: Add an event, SCX_EV_BYPASS_ACTIVATE Changwoo Min
2025-01-31 7:09 ` [PATCH v3 07/11] sched_ext: Add an event, SCX_EV_BYPASS_DISPATCH Changwoo Min
2025-02-02 17:33 ` Tejun Heo
2025-02-03 15:51 ` Changwoo Min
2025-01-31 7:09 ` [PATCH v3 08/11] sched_ext: Add an event, SCX_EV_BYPASS_DURATION Changwoo Min
2025-02-02 17:35 ` Tejun Heo
2025-02-03 15:48 ` Changwoo Min
2025-01-31 7:09 ` [PATCH v3 09/11] sched_ext: Add scx_bpf_events() and scx_read_event() for BPF schedulers Changwoo Min
2025-01-31 7:09 ` [PATCH v3 10/11] sched_ext: Print core event count in scx_central scheduler Changwoo Min
2025-01-31 7:09 ` [PATCH v3 11/11] sched_ext: Print core event count in scx_qmap scheduler Changwoo Min
2025-02-02 17:37 ` [PATCH v3 00/11] sched_ext: Implement core event counters Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250131070938.95551-3-changwoo@igalia.com \
--to=changwoo@igalia.com \
--cc=arighi@nvidia.com \
--cc=kernel-dev@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®