[PATCH v2 09/11] sched_ext: Add an event, BYPASS_DURATION

Changwoo Min
2025-01-26T10:17:00Z

Add a core event, BYPASS_DURATION, which represents the total duration
of bypass modes in nanoseconds.

Signed-off-by: Changwoo Min <changwoo@igalia.com>
---
kernel/sched/ext.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 9a680774c1fc..c71c89cfd1c8 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -1486,6 +1486,11 @@ struct scx_event_stats {
*/
u64 ENQ_SKIP_EXITING;

+ /*
+ * The total duration of bypass modes in nanoseconds.
+ */
+ u64 BYPASS_DURATION;
+
/*
* The number of tasks dispatched in the bypassing mode.
*/
@@ -1547,6 +1552,12 @@ static DEFINE_PER_CPU(struct scx_event_stats, event_stats_cpu);
} while (0)

+/*
+ * The last time the bypass mode started.
+ * This is used to measure BYPASS_DURATION.
+ */
+static unsigned long scx_bypass_timestamp;
+
static void scx_bpf_event_stats(struct scx_event_stats *events, size_t events__sz);

static enum scx_ops_enable_state scx_ops_enable_state(void)
@@ -4935,12 +4946,15 @@ static void scx_ops_bypass(bool bypass)
WARN_ON_ONCE(scx_ops_bypass_depth <= 0);
if (scx_ops_bypass_depth != 1)
goto unlock;
+ scx_bypass_timestamp = ktime_get_ns();
scx_add_event(BYPASS_ACTIVATE, 1);
} else {
scx_ops_bypass_depth--;
WARN_ON_ONCE(scx_ops_bypass_depth < 0);
if (scx_ops_bypass_depth != 0)
goto unlock;
+ scx_add_event(BYPASS_DURATION,
+ ktime_get_ns() - scx_bypass_timestamp);
}

atomic_inc(&scx_ops_breather_depth);
@@ -5531,6 +5545,7 @@ static void scx_dump_state(struct scx_exit_info *ei, size_t dump_len)
scx_dump_event(s, &events, DISPATCH_LOCAL_DSQ_OFFLINE);
scx_dump_event(s, &events, DISPATCH_KEEP_LAST);
scx_dump_event(s, &events, ENQ_SKIP_EXITING);
+ scx_dump_event(s, &events, BYPASS_DURATION);
scx_dump_event(s, &events, BYPASS_DISPATCH);
scx_dump_event(s, &events, BYPASS_ACTIVATE);

@@ -7864,6 +7879,7 @@ __bpf_kfunc void scx_bpf_event_stats(struct scx_event_stats *events,
scx_agg_event(&e_sys, e_cpu, SELECT_CPU_FALLBACK);
scx_agg_event(&e_sys, e_cpu, DISPATCH_LOCAL_DSQ_OFFLINE);
scx_agg_event(&e_sys, e_cpu, DISPATCH_KEEP_LAST);
+ scx_agg_event(&e_sys, e_cpu, BYPASS_DURATION);
scx_agg_event(&e_sys, e_cpu, BYPASS_DISPATCH);
scx_agg_event(&e_sys, e_cpu, BYPASS_ACTIVATE);
}
--
2.48.1