Re: [PATCH 1/2] evl/sched: Add sched_out handler to sched_class

Philippe Gerum <[email protected]> Mon, 15 Jun 2026 08:28:02 +0200
Newsgroups dev.linux.lists.xenomai
Message-ID <[email protected]>
Jan Kiszka <[email protected]> writes:

> From: Jan Kiszka <[email protected]>
>
> This shall be invoked before a thread switch, providing both the current
> and the next thread as arguments. Some scheduling classes may need it to
> correctly handle their state as the sched_pick may not be invoked when a
> higher-weighted class is providing the next thread.
>
> Signed-off-by: Jan Kiszka <[email protected]>
> ---
>  include/evl/sched.h     | 2 ++
>  kernel/evl/sched/core.c | 5 +++++
>  2 files changed, 7 insertions(+)
>
> diff --git a/include/evl/sched.h b/include/evl/sched.h
> index ae9690860146c..0b16f1b1cf626 100644
> --- a/include/evl/sched.h
> +++ b/include/evl/sched.h
> @@ -120,6 +120,8 @@ struct evl_sched_class {
>  	void (*sched_dequeue)(struct evl_thread *thread);
>  	void (*sched_requeue)(struct evl_thread *thread);
>  	struct evl_thread *(*sched_pick)(struct evl_rq *rq);
> +	void (*sched_out)(struct evl_thread *thread,
> +			  struct evl_thread *next);
>  	void (*sched_yield)(struct evl_thread *thread);
>  	void (*sched_migrate)(struct evl_thread *thread,
>  			      struct evl_rq *rq);
> diff --git a/kernel/evl/sched/core.c b/kernel/evl/sched/core.c
> index eb133e334d30f..0d49fc16bd67e 100644
> --- a/kernel/evl/sched/core.c
> +++ b/kernel/evl/sched/core.c
> @@ -910,6 +910,7 @@ static __always_inline bool test_resched(struct evl_rq *this_rq)
>   */
>  void __evl_schedule(void) /* oob or/and hard irqs off (CPU migration-safe) */
>  {
> +	struct evl_sched_class *prev_schedclass;
>  	struct evl_rq *this_rq = this_evl_rq();
>  	struct evl_thread *prev, *next, *curr;
>  	bool leaving_inband, inband_tail;
> @@ -990,6 +991,10 @@ void __evl_schedule(void) /* oob or/and hard irqs off (CPU migration-safe) */
>  	this_rq->curr = next;
>  	leaving_inband = false;
>  
> +	prev_schedclass = prev->sched_class;
> +	if (prev_schedclass->sched_out)
> +		prev_schedclass->sched_out(prev, next);
> +
>  	/*
>  	 * Careful: we _must_ have updated this_rq->curr before
>  	 * performing the rest of the context switch code

I've been working on this lately too. It turns out that we need more
than this, although this is definitely part of the solution. I'll follow
up on this issue.

-- 
Philippe.