mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched_ext: Count cap-rejected local DSQ inserts in SCX_EV_SUB_REJECT
@ 2026-09-25  7:05 luoliang
  2026-09-28 19:06 ` Tejun Heo
  2026-09-29  3:03 ` [PATCH v2] " luoliang
  0 siblings, 2 replies; 6+ messages in thread
From: luoliang @ 2026-09-25  7:05 UTC (permalink / raw)
  To: Tejun Heo
  Cc: David Vernet, Andrea Righi, Changwoo Min, sched-ext,
	linux-kernel, Liang Luo

From: Liang Luo <luoliang@kylinos.cn>

When a task is enqueued on a local DSQ without the caps its enqueue flags
require, __scx_resolve_local_dsq() has three outcomes: admit the task
anyway because the rq is draining offline, the task is migration-disabled
or a migration is pending (counted in SCX_EV_SUB_FORCED_ADMIT), divert it
to the rescue path when the enqueue requested rescue (counted in
SCX_EV_SUB_RESCUE), or divert it to the reject DSQ to be re-enqueued so
that the BPF scheduler can re-decide.

The first two are counted but the last is not, so the number of tasks
diverted to the reject DSQ is missing from the counters exposed via
sysfs, scx_dump_state() and the scx_bpf_events() kfunc. No other
counter covers it: nr_rejected counts tasks refused by ops.init_task()
through task->scx.disallow, and SCX_EV_REENQ_REPEAT only sees a reject
diversion once the same task fails its placement again.

Add SCX_EV_SUB_REJECT and count the reject diversion so that all three
outcomes of a cap-missing local DSQ insert are observable.

Fixes: 75a8c8202c91 ("sched_ext: Add reject DSQ for cap-rejected dispatches")
Signed-off-by: Liang Luo <luoliang@kylinos.cn>
---
 kernel/sched/ext/internal.h | 10 +++++++++-
 kernel/sched/ext/sub.c      |  2 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/ext/internal.h b/kernel/sched/ext/internal.h
index 0bcceab612de..36da1a6560db 100644
--- a/kernel/sched/ext/internal.h
+++ b/kernel/sched/ext/internal.h
@@ -1308,6 +1308,13 @@ struct scx_event_stats {
 	 * caps for its cid and the task entered the rescue path.
 	 */
 	s64		SCX_EV_SUB_RESCUE;
+
+	/*
+	 * The number of times an insert lacked the caps for its cid and was
+	 * diverted to the reject DSQ to be re-enqueued so that the BPF
+	 * scheduler can re-decide.
+	 */
+	s64		SCX_EV_SUB_REJECT;
 };
 
 #define SCX_EVENTS_LIST(SCX_EVENT)					\
@@ -1331,7 +1338,8 @@ struct scx_event_stats {
 	SCX_EVENT(SCX_EV_SUB_KICK_DENIED);				\
 	SCX_EVENT(SCX_EV_SUB_REENQ_DENIED);				\
 	SCX_EVENT(SCX_EV_SUB_CIDPERF_DENIED);				\
-	SCX_EVENT(SCX_EV_SUB_RESCUE)
+	SCX_EVENT(SCX_EV_SUB_RESCUE);					\
+	SCX_EVENT(SCX_EV_SUB_REJECT)
 
 struct scx_sched;
 
diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c
index 10567196be96..3429b84f319a 100644
--- a/kernel/sched/ext/sub.c
+++ b/kernel/sched/ext/sub.c
@@ -748,6 +748,8 @@ struct scx_dispatch_q *__scx_resolve_local_dsq(struct scx_sched *sch, struct rq
 		return &rq->scx.rescue.dsq;
 	}
 
+	__scx_add_event(sch, SCX_EV_SUB_REJECT, 1);
+
 	p->scx.reenq_reason_caps = missing;
 	p->scx.reenq_reason_cid = cid;
 
-- 
2.43.0


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

* Re: [PATCH] sched_ext: Count cap-rejected local DSQ inserts in SCX_EV_SUB_REJECT
  2026-09-25  7:05 [PATCH] sched_ext: Count cap-rejected local DSQ inserts in SCX_EV_SUB_REJECT luoliang
@ 2026-09-28 19:06 ` Tejun Heo
  2026-09-29  3:00   ` luoliang
  2026-09-29  3:03 ` [PATCH v2] " luoliang
  1 sibling, 1 reply; 6+ messages in thread
From: Tejun Heo @ 2026-09-28 19:06 UTC (permalink / raw)
  To: Liang Luo
  Cc: David Vernet, Andrea Righi, Changwoo Min, sched-ext, linux-kernel

Hello, Liang.

On Fri, Sep 25, 2026 at 03:05:00PM +0800, luoliang@kylinos.cn wrote:
> The first two are counted but the last is not, so the number of tasks
> diverted to the reject DSQ is missing from the counters exposed via
> sysfs, scx_dump_state() and the scx_bpf_events() kfunc.

I have nothing against adding the counter, but we don't count every path,
so an uncounted branch arm isn't a reason by itself. What's the rationale
for counting this one?

> Fixes: 75a8c8202c91 ("sched_ext: Add reject DSQ for cap-rejected dispatches")

This doesn't fix a bug. Can you drop the Fixes: tag?

Thanks.

--
tejun

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

* Re: [PATCH] sched_ext: Count cap-rejected local DSQ inserts in SCX_EV_SUB_REJECT
  2026-09-28 19:06 ` Tejun Heo
@ 2026-09-29  3:00   ` luoliang
  0 siblings, 0 replies; 6+ messages in thread
From: luoliang @ 2026-09-29  3:00 UTC (permalink / raw)
  To: Tejun Heo
  Cc: David Vernet, Andrea Righi, Changwoo Min, sched-ext,
	linux-kernel, Liang Luo

From: Liang Luo <luoliang@kylinos.cn>

Hello Tejun,

Thanks for the review.

On Mon, Sep 28, 2026 at 09:06:21AM -1000, Tejun Heo wrote:
> I have nothing against adding the counter, but we don't count every path,
> so an uncounted branch arm isn't a reason by itself. What's the rationale
> for counting this one?

That's fair - a counter should be justified on its own, not by symmetry
with its siblings. The rationale here is that of the three outcomes, the
reject diversion is the one without preconditions: the other two
require a draining rq, a task that cannot migrate anywhere else, or an
explicit SCX_ENQ_RESCUE opt-in, while every other cap-missing insert
lands in the reject DSQ. With this counter, the events cover all three
outcomes of a cap-missing local insert.

> This doesn't fix a bug. Can you drop the Fixes: tag?

Done in v2.

Thanks.

Liang Luo

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

* [PATCH v2] sched_ext: Count cap-rejected local DSQ inserts in SCX_EV_SUB_REJECT
  2026-09-25  7:05 [PATCH] sched_ext: Count cap-rejected local DSQ inserts in SCX_EV_SUB_REJECT luoliang
  2026-09-28 19:06 ` Tejun Heo
@ 2026-09-29  3:03 ` luoliang
  2026-09-29  5:09   ` Andrea Righi
  1 sibling, 1 reply; 6+ messages in thread
From: luoliang @ 2026-09-29  3:03 UTC (permalink / raw)
  To: Tejun Heo
  Cc: David Vernet, Andrea Righi, Changwoo Min, sched-ext,
	linux-kernel, Liang Luo

From: Liang Luo <luoliang@kylinos.cn>

When a task is enqueued on a local DSQ without the caps its enqueue flags
require, __scx_resolve_local_dsq() has three outcomes: admit the task
anyway because the rq is draining offline, the task is migration-disabled
or a migration is pending (counted in SCX_EV_SUB_FORCED_ADMIT), divert it
to the rescue path when the enqueue requested rescue (counted in
SCX_EV_SUB_RESCUE), or divert it to the reject DSQ to be re-enqueued so
that the BPF scheduler can re-decide.

Unlike the other two, which require a draining rq, a task that cannot
migrate anywhere else, or an explicit SCX_ENQ_RESCUE opt-in, the reject
diversion has no preconditions: every other cap-missing insert lands
there. Its traffic is currently not visible in any counter -
SCX_EV_REENQ_REPEAT only counts it once the same task fails its
placement again, and nr_rejected counts tasks refused by ops.init_task()
through task->scx.disallow.

Add SCX_EV_SUB_REJECT and count the reject diversion so that the events
cover all three outcomes of a cap-missing local insert.

Signed-off-by: Liang Luo <luoliang@kylinos.cn>

---

v2: Rework the rationale in the commit message and drop the Fixes: tag
    per Tejun. No code changes.
---
 kernel/sched/ext/internal.h | 10 +++++++++-
 kernel/sched/ext/sub.c      |  2 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/ext/internal.h b/kernel/sched/ext/internal.h
index 0bcceab612de..36da1a6560db 100644
--- a/kernel/sched/ext/internal.h
+++ b/kernel/sched/ext/internal.h
@@ -1308,6 +1308,13 @@ struct scx_event_stats {
 	 * caps for its cid and the task entered the rescue path.
 	 */
 	s64		SCX_EV_SUB_RESCUE;
+
+	/*
+	 * The number of times an insert lacked the caps for its cid and was
+	 * diverted to the reject DSQ to be re-enqueued so that the BPF
+	 * scheduler can re-decide.
+	 */
+	s64		SCX_EV_SUB_REJECT;
 };
 
 #define SCX_EVENTS_LIST(SCX_EVENT)					\
@@ -1331,7 +1338,8 @@ struct scx_event_stats {
 	SCX_EVENT(SCX_EV_SUB_KICK_DENIED);				\
 	SCX_EVENT(SCX_EV_SUB_REENQ_DENIED);				\
 	SCX_EVENT(SCX_EV_SUB_CIDPERF_DENIED);				\
-	SCX_EVENT(SCX_EV_SUB_RESCUE)
+	SCX_EVENT(SCX_EV_SUB_RESCUE);					\
+	SCX_EVENT(SCX_EV_SUB_REJECT)
 
 struct scx_sched;
 
diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c
index 10567196be96..3429b84f319a 100644
--- a/kernel/sched/ext/sub.c
+++ b/kernel/sched/ext/sub.c
@@ -748,6 +748,8 @@ struct scx_dispatch_q *__scx_resolve_local_dsq(struct scx_sched *sch, struct rq
 		return &rq->scx.rescue.dsq;
 	}
 
+	__scx_add_event(sch, SCX_EV_SUB_REJECT, 1);
+
 	p->scx.reenq_reason_caps = missing;
 	p->scx.reenq_reason_cid = cid;
 
-- 
2.43.0


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

* Re: [PATCH v2] sched_ext: Count cap-rejected local DSQ inserts in SCX_EV_SUB_REJECT
  2026-09-29  3:03 ` [PATCH v2] " luoliang
@ 2026-09-29  5:09   ` Andrea Righi
  2026-09-29  6:12     ` luoliang
  0 siblings, 1 reply; 6+ messages in thread
From: Andrea Righi @ 2026-09-29  5:09 UTC (permalink / raw)
  To: luoliang; +Cc: Tejun Heo, David Vernet, Changwoo Min, sched-ext, linux-kernel

Hi Liang,

On Tue, Sep 29, 2026 at 11:03:56AM +0800, luoliang@kylinos.cn wrote:
> From: Liang Luo <luoliang@kylinos.cn>
> 
> When a task is enqueued on a local DSQ without the caps its enqueue flags
> require, __scx_resolve_local_dsq() has three outcomes: admit the task
> anyway because the rq is draining offline, the task is migration-disabled
> or a migration is pending (counted in SCX_EV_SUB_FORCED_ADMIT), divert it
> to the rescue path when the enqueue requested rescue (counted in
> SCX_EV_SUB_RESCUE), or divert it to the reject DSQ to be re-enqueued so
> that the BPF scheduler can re-decide.
> 
> Unlike the other two, which require a draining rq, a task that cannot
> migrate anywhere else, or an explicit SCX_ENQ_RESCUE opt-in, the reject
> diversion has no preconditions: every other cap-missing insert lands
> there. Its traffic is currently not visible in any counter -
> SCX_EV_REENQ_REPEAT only counts it once the same task fails its
> placement again, and nr_rejected counts tasks refused by ops.init_task()
> through task->scx.disallow.
> 
> Add SCX_EV_SUB_REJECT and count the reject diversion so that the events
> cover all three outcomes of a cap-missing local insert.

I still don't see a need for this event. The BPF scheduler receives
SCX_TASK_REENQ_CAP on cap-related re-enqueues and can count those itself, as
scx_qmap already does. That count isn't identical to the proposed diversion
count, but the commit message doesn't explain why the distinction matters.

Is there a concrete case where this new counter would help diagnose a problem
that the scheduler-side count cannot?

Thanks,
-Andrea

> 
> Signed-off-by: Liang Luo <luoliang@kylinos.cn>
> 
> ---
> 
> v2: Rework the rationale in the commit message and drop the Fixes: tag
>     per Tejun. No code changes.
> ---
>  kernel/sched/ext/internal.h | 10 +++++++++-
>  kernel/sched/ext/sub.c      |  2 ++
>  2 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/ext/internal.h b/kernel/sched/ext/internal.h
> index 0bcceab612de..36da1a6560db 100644
> --- a/kernel/sched/ext/internal.h
> +++ b/kernel/sched/ext/internal.h
> @@ -1308,6 +1308,13 @@ struct scx_event_stats {
>  	 * caps for its cid and the task entered the rescue path.
>  	 */
>  	s64		SCX_EV_SUB_RESCUE;
> +
> +	/*
> +	 * The number of times an insert lacked the caps for its cid and was
> +	 * diverted to the reject DSQ to be re-enqueued so that the BPF
> +	 * scheduler can re-decide.
> +	 */
> +	s64		SCX_EV_SUB_REJECT;
>  };
>  
>  #define SCX_EVENTS_LIST(SCX_EVENT)					\
> @@ -1331,7 +1338,8 @@ struct scx_event_stats {
>  	SCX_EVENT(SCX_EV_SUB_KICK_DENIED);				\
>  	SCX_EVENT(SCX_EV_SUB_REENQ_DENIED);				\
>  	SCX_EVENT(SCX_EV_SUB_CIDPERF_DENIED);				\
> -	SCX_EVENT(SCX_EV_SUB_RESCUE)
> +	SCX_EVENT(SCX_EV_SUB_RESCUE);					\
> +	SCX_EVENT(SCX_EV_SUB_REJECT)
>  
>  struct scx_sched;
>  
> diff --git a/kernel/sched/ext/sub.c b/kernel/sched/ext/sub.c
> index 10567196be96..3429b84f319a 100644
> --- a/kernel/sched/ext/sub.c
> +++ b/kernel/sched/ext/sub.c
> @@ -748,6 +748,8 @@ struct scx_dispatch_q *__scx_resolve_local_dsq(struct scx_sched *sch, struct rq
>  		return &rq->scx.rescue.dsq;
>  	}
>  
> +	__scx_add_event(sch, SCX_EV_SUB_REJECT, 1);
> +
>  	p->scx.reenq_reason_caps = missing;
>  	p->scx.reenq_reason_cid = cid;
>  
> -- 
> 2.43.0
> 
> 

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

* Re: [PATCH v2] sched_ext: Count cap-rejected local DSQ inserts in SCX_EV_SUB_REJECT
  2026-09-29  5:09   ` Andrea Righi
@ 2026-09-29  6:12     ` luoliang
  0 siblings, 0 replies; 6+ messages in thread
From: luoliang @ 2026-09-29  6:12 UTC (permalink / raw)
  To: Andrea Righi
  Cc: Tejun Heo, David Vernet, Changwoo Min, sched-ext, linux-kernel,
	Liang Luo

From: Liang Luo <luoliang@kylinos.cn>

Hello Andrea,

Thanks for the review.

On Tue, Sep 29, 2026 at 07:09:55AM +0200, Andrea Righi wrote:
> I still don't see a need for this event. The BPF scheduler receives
> SCX_TASK_REENQ_CAP on cap-related re-enqueues and can count those itself, as
> scx_qmap already does.

Fair enough - the scheduler-side counting covers this, and I agree the
distinctions are marginal for diagnosis. Withdrawing the patch.

Thanks to you and Tejun for taking a look.

Liang Luo

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

end of thread, other threads:[~2026-09-29  6:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-25  7:05 [PATCH] sched_ext: Count cap-rejected local DSQ inserts in SCX_EV_SUB_REJECT luoliang
2026-09-28 19:06 ` Tejun Heo
2026-09-29  3:00   ` luoliang
2026-09-29  3:03 ` [PATCH v2] " luoliang
2026-09-29  5:09   ` Andrea Righi
2026-09-29  6:12     ` luoliang

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®