From nobody Tue Dec 16 09:03:07 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 977FF17F3 for ; Mon, 15 Jan 2024 14:34:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8ADF8FEC; Mon, 15 Jan 2024 06:35:26 -0800 (PST) Received: from e126645.arm.com (e126645.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 13F2E3F6C4; Mon, 15 Jan 2024 06:34:37 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Shrikanth Hegde , Pierre Gondois , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Huang Ying Subject: [PATCH v2 1/3] sched/topology: Annotate RCU pointers properly Date: Mon, 15 Jan 2024 15:34:24 +0100 Message-Id: <20240115143427.1820628-2-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240115143427.1820628-1-pierre.gondois@arm.com> References: <20240115143427.1820628-1-pierre.gondois@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Cleanup RCU-related spare errors by annotating RCU pointers. sched_domains_numa_distance: error: incompatible types in comparison expression (different address spaces): int [noderef] __rcu * int * sched_domains_numa_masks: error: incompatible types in comparison expression (different address spaces): struct cpumask **[noderef] __rcu * struct cpumask *** The cast to (void *) adds the following sparse warning: warning: cast removes address space '__rcu' of expression but this should be normal. Fixes: 0fb3978b0aac ("sched/numa: Fix NUMA topology for systems with CPU-le= ss nodes") Signed-off-by: Pierre Gondois --- kernel/sched/topology.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 10d1391e7416..2a2da9b33e31 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1542,8 +1542,8 @@ static int sched_domains_numa_levels; static int sched_domains_curr_level; =20 int sched_max_numa_distance; -static int *sched_domains_numa_distance; -static struct cpumask ***sched_domains_numa_masks; +static int __rcu *sched_domains_numa_distance; +static struct cpumask ** __rcu *sched_domains_numa_masks; #endif =20 /* @@ -1988,8 +1988,8 @@ void sched_init_numa(int offline_node) =20 static void sched_reset_numa(void) { - int nr_levels, *distances; - struct cpumask ***masks; + int nr_levels, __rcu *distances; + struct cpumask ** __rcu *masks; =20 nr_levels =3D sched_domains_numa_levels; sched_domains_numa_levels =3D 0; @@ -2003,7 +2003,7 @@ static void sched_reset_numa(void) int i, j; =20 synchronize_rcu(); - kfree(distances); + kfree((void *)distances); for (i =3D 0; i < nr_levels && masks; i++) { if (!masks[i]) continue; @@ -2011,7 +2011,7 @@ static void sched_reset_numa(void) kfree(masks[i][j]); kfree(masks[i]); } - kfree(masks); + kfree((void *)masks); } if (sched_domain_topology_saved) { kfree(sched_domain_topology); --=20 2.25.1 From nobody Tue Dec 16 09:03:07 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01BD117743 for ; Mon, 15 Jan 2024 14:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3A047150C; Mon, 15 Jan 2024 06:35:29 -0800 (PST) Received: from e126645.arm.com (e126645.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B64623F6C4; Mon, 15 Jan 2024 06:34:40 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Shrikanth Hegde , Pierre Gondois , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Huang Ying Subject: [PATCH v2 2/3] sched/fair: Use rq in idle_cpu_without() Date: Mon, 15 Jan 2024 15:34:25 +0100 Message-Id: <20240115143427.1820628-3-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240115143427.1820628-1-pierre.gondois@arm.com> References: <20240115143427.1820628-1-pierre.gondois@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" idle_cpu_without() could receive a 'struct rq' instead of a CPU number to avoid converting the CPU number to a 'struct rq' two times. Indeed update_sg_wakeup_stats() already makes the conversion. idle_cpu_without() is also renamed to idle_rq_without() to match the input parameter. Reviewed-by: Shrikanth Hegde Signed-off-by: Pierre Gondois --- kernel/sched/fair.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d7a3c63a2171..97d9e0d32337 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10105,23 +10105,21 @@ static unsigned int task_running_on_cpu(int cpu, = struct task_struct *p) } =20 /** - * idle_cpu_without - would a given CPU be idle without p ? - * @cpu: the processor on which idleness is tested. + * idle_rq_without - would a given rq be idle without p ? + * @rq: the rq on which idleness is tested. * @p: task which should be ignored. * - * Return: 1 if the CPU would be idle. 0 otherwise. + * Return: 1 if the rq would be idle. 0 otherwise. */ -static int idle_cpu_without(int cpu, struct task_struct *p) +static int idle_rq_without(struct rq *rq, struct task_struct *p) { - struct rq *rq =3D cpu_rq(cpu); - if (rq->curr !=3D rq->idle && rq->curr !=3D p) return 0; =20 /* * rq->nr_running can't be used but an updated version without the * impact of p on cpu must be used instead. The updated nr_running - * be computed and tested before calling idle_cpu_without(). + * be computed and tested before calling idle_rq_without(). */ =20 #ifdef CONFIG_SMP @@ -10166,9 +10164,9 @@ static inline void update_sg_wakeup_stats(struct sc= hed_domain *sd, sgs->sum_nr_running +=3D nr_running; =20 /* - * No need to call idle_cpu_without() if nr_running is not 0 + * No need to call idle_rq_without() if nr_running is not 0 */ - if (!nr_running && idle_cpu_without(i, p)) + if (!nr_running && idle_rq_without(rq, p)) sgs->idle_cpus++; =20 /* Check if task fits in the CPU */ --=20 2.25.1 From nobody Tue Dec 16 09:03:07 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A6421798E for ; Mon, 15 Jan 2024 14:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 02C4A1515; Mon, 15 Jan 2024 06:35:32 -0800 (PST) Received: from e126645.arm.com (e126645.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7ECDB3F6C4; Mon, 15 Jan 2024 06:34:43 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Shrikanth Hegde , Pierre Gondois , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Huang Ying Subject: [PATCH v2 3/3] sched/fair: Use rq in update_blocked_averages() Date: Mon, 15 Jan 2024 15:34:26 +0100 Message-Id: <20240115143427.1820628-4-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240115143427.1820628-1-pierre.gondois@arm.com> References: <20240115143427.1820628-1-pierre.gondois@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" update_blocked_averages() could receive a 'struct rq' instead of a CPU number to avoid converting the CPU number to a 'struct rq' multiple times. Suggested-by: Shrikanth Hegde Signed-off-by: Pierre Gondois --- kernel/sched/fair.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 97d9e0d32337..c70bb993f473 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9349,10 +9349,9 @@ static unsigned long task_h_load(struct task_struct = *p) } #endif =20 -static void update_blocked_averages(int cpu) +static void update_blocked_averages(struct rq *rq) { bool decayed =3D false, done =3D true; - struct rq *rq =3D cpu_rq(cpu); struct rq_flags rf; =20 rq_lock_irqsave(rq, &rf); @@ -12026,7 +12025,7 @@ static bool update_nohz_stats(struct rq *rq) if (!time_after(jiffies, READ_ONCE(rq->last_blocked_load_update_tick))) return true; =20 - update_blocked_averages(cpu); + update_blocked_averages(rq); =20 return rq->has_blocked_load; } @@ -12286,7 +12285,7 @@ static int newidle_balance(struct rq *this_rq, stru= ct rq_flags *rf) raw_spin_rq_unlock(this_rq); =20 t0 =3D sched_clock_cpu(this_cpu); - update_blocked_averages(this_cpu); + update_blocked_averages(this_rq); =20 rcu_read_lock(); for_each_domain(this_cpu, sd) { @@ -12376,7 +12375,7 @@ static __latent_entropy void run_rebalance_domains(= struct softirq_action *h) return; =20 /* normal load balance */ - update_blocked_averages(this_rq->cpu); + update_blocked_averages(this_rq); rebalance_domains(this_rq, idle); } =20 --=20 2.25.1