public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Tejun Heo <tj@kernel.org>
Cc: void@manifault.com, multics69@gmail.com,
	linux-kernel@vger.kernel.org, sched-ext@meta.com
Subject: Re: [PATCH 5/5] sched_ext: Make scx_has_op a bitmap
Date: Wed, 9 Apr 2025 09:57:59 +0200	[thread overview]
Message-ID: <Z_Yoh6Is2BaxwdyC@gpd3> (raw)
In-Reply-To: <20250408230616.2369765-6-tj@kernel.org>

On Tue, Apr 08, 2025 at 01:06:05PM -1000, Tejun Heo wrote:
> scx_has_op is used to encode which ops are implemented by the BPF scheduler
> into an array of static_keys. While this saves a bit of branching overhead,
> that is unlikely to be noticeable compared to the overall cost. As the
> global static_keys can't work with the planned hierarchical multiple
> scheduler support, replace the static_key array with a bitmap.
> 
> In repeated hackbench runs before and after static_keys removal on an AMD
> Ryzen 3900X, I couldn't tell any measurable performance difference.

At this point I'm wondering if we should just do something like:

 #define SCX_HAS_OP(op) (scx_ops.op != NULL)

Do you think the bitmap can provide some measurable benefits? For the most
frequently used hot paths (enqueue, dispatch, select_cpu, running,
stopping) we likely have to fetch scx_ops.op anyway, so cache-wise the
difference should be minimal.

Thanks,
-Andrea

> 
> Signed-off-by: Tejun Heo <tj@kernel.org>
> ---
>  kernel/sched/ext.c | 22 ++++++++++------------
>  1 file changed, 10 insertions(+), 12 deletions(-)
> 
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index f0ed0cec4c98..8ae85ec6d9a2 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -928,8 +928,7 @@ DEFINE_STATIC_KEY_FALSE(__scx_switched_all);
>  static struct sched_ext_ops scx_ops;
>  static bool scx_warned_zero_slice;
>  
> -static struct static_key_false scx_has_op[SCX_OPI_END] =
> -	{ [0 ... SCX_OPI_END-1] = STATIC_KEY_FALSE_INIT };
> +static DECLARE_BITMAP(scx_has_op, SCX_OPI_END);
>  
>  static atomic_t scx_exit_kind = ATOMIC_INIT(SCX_EXIT_DONE);
>  static struct scx_exit_info *scx_exit_info;
> @@ -1055,7 +1054,7 @@ static __printf(3, 4) void __scx_exit(enum scx_exit_kind kind, s64 exit_code,
>  #define scx_error(fmt, args...)							\
>  	__scx_error(SCX_EXIT_ERROR, fmt, ##args)
>  
> -#define SCX_HAS_OP(op)	static_branch_likely(&scx_has_op[SCX_OP_IDX(op)])
> +#define SCX_HAS_OP(op)	test_bit(SCX_OP_IDX(op), scx_has_op)
>  
>  static long jiffies_delta_msecs(unsigned long at, unsigned long now)
>  {
> @@ -1774,7 +1773,7 @@ static void touch_core_sched_dispatch(struct rq *rq, struct task_struct *p)
>  	lockdep_assert_rq_held(rq);
>  
>  #ifdef CONFIG_SCHED_CORE
> -	if (SCX_HAS_OP(core_sched_before))
> +	if (unlikely(SCX_HAS_OP(core_sched_before)))
>  		touch_core_sched(rq, p);
>  #endif
>  }
> @@ -2156,7 +2155,7 @@ static void do_enqueue_task(struct rq *rq, struct task_struct *p, u64 enq_flags,
>  		goto local;
>  	}
>  
> -	if (!SCX_HAS_OP(enqueue))
> +	if (unlikely(!SCX_HAS_OP(enqueue)))
>  		goto global;
>  
>  	/* DSQ bypass didn't trigger, enqueue on the BPF scheduler */
> @@ -2972,7 +2971,7 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
>  	if (consume_global_dsq(rq))
>  		goto has_tasks;
>  
> -	if (!SCX_HAS_OP(dispatch) || scx_rq_bypassing(rq) || !scx_rq_online(rq))
> +	if (unlikely(!SCX_HAS_OP(dispatch)) || scx_rq_bypassing(rq) || !scx_rq_online(rq))
>  		goto no_tasks;
>  
>  	dspc->rq = rq;
> @@ -3373,7 +3372,7 @@ static int select_task_rq_scx(struct task_struct *p, int prev_cpu, int wake_flag
>  		return prev_cpu;
>  
>  	rq_bypass = scx_rq_bypassing(task_rq(p));
> -	if (SCX_HAS_OP(select_cpu) && !rq_bypass) {
> +	if (likely(SCX_HAS_OP(select_cpu)) && !rq_bypass) {
>  		s32 cpu;
>  		struct task_struct **ddsp_taskp;
>  
> @@ -4638,7 +4637,7 @@ static void scx_disable_workfn(struct kthread_work *work)
>  	struct task_struct *p;
>  	struct rhashtable_iter rht_iter;
>  	struct scx_dispatch_q *dsq;
> -	int i, kind, cpu;
> +	int kind, cpu;
>  
>  	kind = atomic_read(&scx_exit_kind);
>  	while (true) {
> @@ -4731,8 +4730,7 @@ static void scx_disable_workfn(struct kthread_work *work)
>  
>  	/* no task is on scx, turn off all the switches and flush in-progress calls */
>  	static_branch_disable(&__scx_enabled);
> -	for (i = SCX_OPI_BEGIN; i < SCX_OPI_END; i++)
> -		static_branch_disable(&scx_has_op[i]);
> +	bitmap_zero(scx_has_op, SCX_OPI_END);
>  	scx_idle_disable();
>  	synchronize_rcu();
>  
> @@ -5328,7 +5326,7 @@ static int scx_enable(struct sched_ext_ops *ops, struct bpf_link *link)
>  
>  	for (i = SCX_OPI_CPU_HOTPLUG_BEGIN; i < SCX_OPI_CPU_HOTPLUG_END; i++)
>  		if (((void (**)(void))ops)[i])
> -			static_branch_enable_cpuslocked(&scx_has_op[i]);
> +			set_bit(i, scx_has_op);
>  
>  	check_hotplug_seq(ops);
>  	scx_idle_update_selcpu_topology(ops);
> @@ -5369,7 +5367,7 @@ static int scx_enable(struct sched_ext_ops *ops, struct bpf_link *link)
>  
>  	for (i = SCX_OPI_NORMAL_BEGIN; i < SCX_OPI_NORMAL_END; i++)
>  		if (((void (**)(void))ops)[i])
> -			static_branch_enable(&scx_has_op[i]);
> +			set_bit(i, scx_has_op);
>  
>  	if (scx_ops.cpu_acquire || scx_ops.cpu_release)
>  		scx_ops.flags |= SCX_OPS_HAS_CPU_PREEMPT;
> -- 
> 2.49.0
> 

  reply	other threads:[~2025-04-09  7:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 23:06 [PATCHSET sched_ext/for-6.16] sched_ext: Reduce usage of static_keys Tejun Heo
2025-04-08 23:06 ` [PATCH 1/5] sched_ext: Indentation updates Tejun Heo
2025-04-08 23:06 ` [PATCH 2/5] sched_ext: Remove scx_ops_enq_* static_keys Tejun Heo
2025-04-08 23:06 ` [PATCH 3/5] sched_ext: Remove scx_ops_cpu_preempt static_key Tejun Heo
2025-04-08 23:06 ` [PATCH 4/5] sched_ext: Remove scx_ops_allow_queued_wakeup static_key Tejun Heo
2025-04-08 23:06 ` [PATCH 5/5] sched_ext: Make scx_has_op a bitmap Tejun Heo
2025-04-09  7:57   ` Andrea Righi [this message]
2025-04-09 18:51     ` Tejun Heo
2025-04-09 18:58       ` Andrea Righi
2025-04-09  1:37 ` [PATCHSET sched_ext/for-6.16] sched_ext: Reduce usage of static_keys Changwoo Min
2025-04-09 19:06 ` 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=Z_Yoh6Is2BaxwdyC@gpd3 \
    --to=arighi@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=multics69@gmail.com \
    --cc=sched-ext@meta.com \
    --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