From nobody Mon Feb 9 17:21:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 799DFC6FD1C for ; Fri, 24 Mar 2023 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231422AbjCXKA7 (ORCPT ); Fri, 24 Mar 2023 06:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbjCXKA4 (ORCPT ); Fri, 24 Mar 2023 06:00:56 -0400 Received: from out-47.mta0.migadu.com (out-47.mta0.migadu.com [IPv6:2001:41d0:1004:224b::2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3459A199DB for ; Fri, 24 Mar 2023 03:00:55 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1679652053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bSc0WWKCrF67Pi/HwlNZVSesODSTBfnuSU6f64Y3d4A=; b=eZe+OG47+3TlSHWJlYF8pqZJwWOkYm4wcvj+d/U76tHtu84GBZq+4nEYKUT9dYfTrKuoYD ApeYh3GxTNz+v52A0863zXehU83OexBfz7xAOy/hCTPvsBtAjKYa+T5e/+jXbQhsvVbw5S yKKmUb9jbuA9qR/mP/n0vuPfhdtNCZM= From: Yajun Deng To: rafael@kernel.org, viresh.kumar@linaro.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH] cpufreq: schedutil: Combine two loops into one in sugov_start() Date: Fri, 24 Mar 2023 18:00:23 +0800 Message-Id: <20230324100023.900616-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The sugov_start() function currently contains two for loops that traverse the CPU list and perform some initialization tasks. The first loop initializes each sugov_cpu struct and assigns the CPU number and sugov_policy pointer. The second loop sets up the update_util hook for each CPU based on the policy type. Since both loops operate on the same CPU list, it is possible to combine them into a single for loop. This simplifies the code and reduces the number of times the CPU list needs to be traversed, which can improve performance. Signed-off-by: Yajun Deng --- kernel/sched/cpufreq_schedutil.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedu= til.c index e3211455b203..9a28ebbb9c1e 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -766,14 +766,6 @@ static int sugov_start(struct cpufreq_policy *policy) =20 sg_policy->need_freq_update =3D cpufreq_driver_test_flags(CPUFREQ_NEED_UP= DATE_LIMITS); =20 - for_each_cpu(cpu, policy->cpus) { - struct sugov_cpu *sg_cpu =3D &per_cpu(sugov_cpu, cpu); - - memset(sg_cpu, 0, sizeof(*sg_cpu)); - sg_cpu->cpu =3D cpu; - sg_cpu->sg_policy =3D sg_policy; - } - if (policy_is_shared(policy)) uu =3D sugov_update_shared; else if (policy->fast_switch_enabled && cpufreq_driver_has_adjust_perf()) @@ -784,6 +776,10 @@ static int sugov_start(struct cpufreq_policy *policy) for_each_cpu(cpu, policy->cpus) { struct sugov_cpu *sg_cpu =3D &per_cpu(sugov_cpu, cpu); =20 + memset(sg_cpu, 0, sizeof(*sg_cpu)); + sg_cpu->cpu =3D cpu; + sg_cpu->sg_policy =3D sg_policy; + cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util, uu); } return 0; --=20 2.25.1