From nobody Wed Oct 8 23:09:10 2025 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37ECA253F30; Mon, 23 Jun 2025 13:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; cv=none; b=EdyGR2v/PhWKVvmgUEj8mRD9eI6ULsvoKUBLAB8O5DHLRka6XmS3h63hvcEL8qXh74Wnh6uUMLHhUXwTjuS9tAaW/hIyfcq0DJjl8A5AAzaUpJerLShQX63zBClYhJSElBz4MWpaJ67SS4BY4ukrGIPxC7I9K9aMHr6kR3qhyjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; c=relaxed/simple; bh=joFxsYCC6faUzY7yWeUR1R4xjeuO+x1xGhAFHeU9a+Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pq/1eehk6pmg4VEQnrqKiw6aQH28q18Fa058OHZAsGInePhPsRH3unTh9ZKupADZAmaCTnnEN8qmV33c7yKbgFZr9iesTl82fXjztrPQA0Ni0/ChWSi+S1zclEPJWh/oDtGiVr6ZLSdqLYTkvXPfz4WXrdislrjYgGtbT5YL+sM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4bQppN0Mshz10XJ2; Mon, 23 Jun 2025 21:29:32 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 8912514027D; Mon, 23 Jun 2025 21:34:08 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:07 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 1/7] cpufreq: Disable cpufreq-based invariance when fail to register driver Date: Mon, 23 Jun 2025 21:33:56 +0800 Message-ID: <20250623133402.3120230-2-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.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 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" The cpufreq-based invariance is enabled in cpufreq_register_driver(), but never disabled after that when fail. Add a static_branch_disable_cpuslocked() to do that as cpufreq_unregister_driver() does. Fixes: 874f63531064 ("cpufreq: report whether cpufreq supports Frequency In= variance (FI)") Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index d7426e1d8bdd..1bc665b5bba8 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2991,6 +2991,7 @@ int cpufreq_register_driver(struct cpufreq_driver *dr= iver_data) err_boost_unreg: remove_boost_sysfs_file(); err_null_driver: + static_branch_disable_cpuslocked(&cpufreq_freq_invariance); write_lock_irqsave(&cpufreq_driver_lock, flags); cpufreq_driver =3D NULL; write_unlock_irqrestore(&cpufreq_driver_lock, flags); --=20 2.33.0 From nobody Wed Oct 8 23:09:10 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9561F347DD; Mon, 23 Jun 2025 13:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; cv=none; b=d+diINkLHIM9OAMBBXlESxLsCj9iFN9obBbMFJCdIFMFI7tGrAX2aS/iHI01Glkzm/l8ohS555NesucHeRUgPH4o2r3Q/QseaAVuOO5V/bfZaoJHpA8USLH6N+dVcXJbT2FQvuZy2xcibQAaWqhwr/IKJKwyBviG7lJ8W4htapw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; c=relaxed/simple; bh=nNs90852AvD7c/IM+vWeq4W0y61YMO+WoWSS8I/UFII=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h9G+5ziwVNNFx7h9MgpOD6V8IPryHhvcu7OqisF0S/SvcidtaV/B/DkBgLgF929YcPXaHSBH1mrzQWleGXqGg9GAqC5WNdDej/ec1vIxwYWVT2GMGmCUd0NutzvDKhsDbVH+NaRwnE1/qjJo7wJ7gQWX2WPyj0ZXj/9rhH92+qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4bQpq81nVXz2Cff7; Mon, 23 Jun 2025 21:30:12 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id EC216180042; Mon, 23 Jun 2025 21:34:08 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:08 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 2/7] cpufreq: Init policy->rwsem before it may be possibly used Date: Mon, 23 Jun 2025 21:33:57 +0800 Message-ID: <20250623133402.3120230-3-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.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 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" In cpufreq_policy_put_kobj(), policy->rwsem is used. But in cpufreq_policy_alloc(), if freq_qos_add_notifier() returns an error, error path via err_kobj_remove or err_min_qos_notifier will be reached and cpufreq_policy_put_kobj() will be called before policy->rwsem is initialized. Thus, the calling of init_rwsem() should be moved to where before these two error paths can be reached. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 1bc665b5bba8..efc1f4ac85cb 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1284,6 +1284,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(un= signed int cpu) goto err_free_real_cpus; } =20 + init_rwsem(&policy->rwsem); + freq_constraints_init(&policy->constraints); =20 policy->nb_min.notifier_call =3D cpufreq_notifier_min; @@ -1306,7 +1308,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(un= signed int cpu) } =20 INIT_LIST_HEAD(&policy->policy_list); - init_rwsem(&policy->rwsem); spin_lock_init(&policy->transition_lock); init_waitqueue_head(&policy->transition_wait); INIT_WORK(&policy->update, handle_update); --=20 2.33.0 From nobody Wed Oct 8 23:09:10 2025 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37E56253F20; Mon, 23 Jun 2025 13:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685653; cv=none; b=CZ1gNbI0vczJ7VgQ0YH4sKmG+V1RtXmzvyYRi/z9EV1KH1qLNj6uKmdUzS5iNNRbI3WmlsjfGYZomob//knJcKHD/Xl4VmVk4fmaYH6v42VHoMvcXM6h4DfB5BslCgkO8PI9/jRr+V3c9vGBFuB8I66O6M1o8ashThHfDXSh/O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685653; c=relaxed/simple; bh=beerym7k8zgy8EcfEIxlVoGUrkuzmwMRI1FujU6b5rw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZnXYmQQX9o4JlWujsrH2NkiWJRq0CkVThtGyu2A54frgAG6eZgvL6VPGs71/GNy4mT6zYfnfBCRVXqdnsdra6A6sYzoFk8QUxcYf+jN2VcbGMrrBoB/+1b3P5bk3iIgXJB/bYj9XTymC2/QoktNobIUwJNH+hVECmxwywj0o3gQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4bQppN68Fjz10XJM; Mon, 23 Jun 2025 21:29:32 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 5B4DE18006C; Mon, 23 Jun 2025 21:34:09 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:08 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 3/7] cpufreq: Contain scaling_cur_freq.attr in cpufreq_attrs Date: Mon, 23 Jun 2025 21:33:58 +0800 Message-ID: <20250623133402.3120230-4-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.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 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" After commit c034b02e213d ("cpufreq: expose scaling_cur_freq sysfs file for set_policy() drivers"), the file scaling_cur_freq is exposed to all drivers. No need to create this file separately. It's better to be contained in cpufreq_attrs. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index efc1f4ac85cb..2303890de0ba 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -967,6 +967,7 @@ static struct attribute *cpufreq_attrs[] =3D { &cpuinfo_min_freq.attr, &cpuinfo_max_freq.attr, &cpuinfo_transition_latency.attr, + &scaling_cur_freq.attr, &scaling_min_freq.attr, &scaling_max_freq.attr, &affected_cpus.attr, @@ -1095,10 +1096,6 @@ static int cpufreq_add_dev_interface(struct cpufreq_= policy *policy) return ret; } =20 - ret =3D sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); - if (ret) - return ret; - if (cpufreq_driver->bios_limit) { ret =3D sysfs_create_file(&policy->kobj, &bios_limit.attr); if (ret) --=20 2.33.0 From nobody Wed Oct 8 23:09:10 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF7F12472AF; Mon, 23 Jun 2025 13:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685653; cv=none; b=r7ZL1cvQ2qr9wVBnc4xGNZeFP+v1xiX7M9Zj4MWmInMeSElg+RdOW3pp3kvjI0wfcInyqPg8EffVPgIc75OLcUAMWbiyJRQnihjwZu0VpG3YkuAbtIJQ9xCvqtQvUzuSDvfTcVPXZQ/tKxbUdR1XdCdi/kFmK/3pKIsh/TyWmtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685653; c=relaxed/simple; bh=9AIFoa5M6hngoUo+a4+718LmWvntA7lviAeBcZrm/qg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XtUaD86ZE4R84QriMnAdP4H2jvxSNUwEeexXyfE82dtYyakaG3CeUwhPfHmUgOEeJgxUrJoskAubUNaPVlue1X3rO3JPdX5YFuShdawmmCLUufUrWhNHr7IhmbfAh24TVsSYI+y5kPtcwXp3wID4GiYyIQmyeHKGwusdT8oY5ZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4bQptN2WBbztSdC; Mon, 23 Jun 2025 21:33:00 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id BE92A1402CD; Mon, 23 Jun 2025 21:34:09 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:09 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 4/7] cpufreq: Remove duplicate check in __cpufreq_offline() Date: Mon, 23 Jun 2025 21:33:59 +0800 Message-ID: <20250623133402.3120230-5-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.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 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" The has_target() checks in __cpufreq_offline() are duplicate. Remove one of them and put the operations of exiting governor together with storing last governor's name. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2303890de0ba..c4891bf5dc84 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1692,14 +1692,13 @@ static void __cpufreq_offline(unsigned int cpu, str= uct cpufreq_policy *policy) return; } =20 - if (has_target()) + if (has_target()) { strscpy(policy->last_governor, policy->governor->name, CPUFREQ_NAME_LEN); - else - policy->last_policy =3D policy->policy; - - if (has_target()) cpufreq_exit_governor(policy); + } else { + policy->last_policy =3D policy->policy; + } =20 /* * Perform the ->offline() during light-weight tear-down, as --=20 2.33.0 From nobody Wed Oct 8 23:09:10 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B298A25486D; Mon, 23 Jun 2025 13:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; cv=none; b=LjD4jmHtyvmr3OG70CZljpHuofwfQhRxvchUHpONHnQT9nZqwGryoIyiL0HBFGjSYhrTQ1FAKh/c0E0T9IUsO2xWUh4svVKUuMlxUcoRPExZVlRB16I/Yh7bNkw4TBITpckB31H95cl6ZIRdjvtdndlJKDSpEvucuSdywolLZPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685655; c=relaxed/simple; bh=I4j90nIvS+36ELpcNLDkF27lo+PEoOZZJOU0bx2PPJ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n7cdbWbTayNpcSgatHapuKgl0NflVQRZp/KiI6K3WrYgidycW1OS2OD+G7q+5Xu1Rag24P899pQ8tjMaPCwEXHrM62E0BaebYvEPGWlrxUkI1LJanUy2SK7Ct0VEajBM8220py34y3sD+SHK1PZ4AfdaUP8Q8y7DVfWxjxsZyW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4bQprv0fwyz1W3Rl; Mon, 23 Jun 2025 21:31:43 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 2634D1A0188; Mon, 23 Jun 2025 21:34:10 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:09 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 5/7] cpufreq: Move the check of cpufreq_driver->get into cpufreq_verify_current_freq() Date: Mon, 23 Jun 2025 21:34:00 +0800 Message-ID: <20250623133402.3120230-6-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.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 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" Move the check of cpufreq_driver->get into cpufreq_verify_current_freq() in case of calling it without check. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index c4891bf5dc84..9b2578b905a5 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1800,6 +1800,9 @@ static unsigned int cpufreq_verify_current_freq(struc= t cpufreq_policy *policy, b { unsigned int new_freq; =20 + if (!cpufreq_driver->get) + return 0; + new_freq =3D cpufreq_driver->get(policy->cpu); if (!new_freq) return 0; @@ -1922,10 +1925,7 @@ unsigned int cpufreq_get(unsigned int cpu) =20 guard(cpufreq_policy_read)(policy); =20 - if (cpufreq_driver->get) - return __cpufreq_get(policy); - - return 0; + return __cpufreq_get(policy); } EXPORT_SYMBOL(cpufreq_get); =20 @@ -2479,8 +2479,7 @@ int cpufreq_start_governor(struct cpufreq_policy *pol= icy) =20 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); =20 - if (cpufreq_driver->get) - cpufreq_verify_current_freq(policy, false); + cpufreq_verify_current_freq(policy, false); =20 if (policy->governor->start) { ret =3D policy->governor->start(policy); --=20 2.33.0 From nobody Wed Oct 8 23:09:10 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E52F9252903; Mon, 23 Jun 2025 13:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685654; cv=none; b=DXKmKhctZKJBC+FW5Ha/sNJK3goNoBggzaPAwmIarji1Ma0tTAAZ/T2cfnSXpaaaAhRSAUhB179kW6xmsxM2meMVip+GNQgsMNpHHVEA1dHT7G0AS5SrOPPNNAfVKw21n/k0hf7h0VvhsdIdzPPK8io4k950dDGK3+Hh2z8MmjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685654; c=relaxed/simple; bh=l/KiLKDUrKKoN6SbfCY3rO8y/+cn3dSOneFbm10HWCo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NMDsU8BqPiGrZYDKHEmo274J0WFHe3suZruAR4W7k9j4kDDvIbQoBOJv8xeB0UXckiQeoIwliApW1L/GhPxKntLPvkb5VSMIWZwiO59tUhuHXlprb5LHfStrtr7/Z9CbSbwtSaheM5VLaHU42kx/hqdsCkADsk1wTdZl3f802xM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4bQptP1VZlztSfF; Mon, 23 Jun 2025 21:33:01 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 9AB5218006C; Mon, 23 Jun 2025 21:34:10 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:09 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 6/7] cpufreq: Refactor code about starting governor in cpufreq_set_policy() Date: Mon, 23 Jun 2025 21:34:01 +0800 Message-ID: <20250623133402.3120230-7-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.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 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" Refactor code about starting governor without functional change in cpufreq_set_policy() to make it more readable. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 9b2578b905a5..7b82ffb50283 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2698,15 +2698,19 @@ static int cpufreq_set_policy(struct cpufreq_policy= *policy, /* start new governor */ policy->governor =3D new_gov; ret =3D cpufreq_init_governor(policy); - if (!ret) { - ret =3D cpufreq_start_governor(policy); - if (!ret) { - pr_debug("governor change\n"); - return 0; - } + if (ret) + goto start_old_gov; + + ret =3D cpufreq_start_governor(policy); + if (ret) { cpufreq_exit_governor(policy); + goto start_old_gov; } =20 + pr_debug("governor change\n"); + return 0; + +start_old_gov: /* new governor failed, so re-start old one */ pr_debug("starting governor %s failed\n", policy->governor->name); if (old_gov) { --=20 2.33.0 From nobody Wed Oct 8 23:09:10 2025 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21662253B58; Mon, 23 Jun 2025 13:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685654; cv=none; b=RfHYkNFrc9mX8BCgmLxH1uLt09OqUgri5PgG67/KRAGXnP1q8TYEsFJh7BNZS7ilcVUhTHkgxjPlpR8SWUfaVHLylsmOh+JlS0lM9ff8O3xmV+39r7oY5UZhvgf6jDyALbDM29vij7KSFuXbiBDc1ysfDHra/QiLv4uob2vG8MA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750685654; c=relaxed/simple; bh=AxUz7IYwHHxE4JE7pm9jcypXdfWucVTWW86pgzSsZtw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CiPqvI9HNfnVJFUeIZG/caBB/3vpaUUBFUTdLyBMb+r/xb1yDh3VSsd4osr3ZiqroooakfSdDwAwjGOZ0SwkApZ7/Kc+hw7xBtKSWBCHr9UgjsWlhFr/lCPWTJUX9hRXzJMuOCLd3UpXarfbT2xrfvWqqKqucdpchZlqPgvERJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4bQppQ3ZRSz10XKG; Mon, 23 Jun 2025 21:29:34 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 006641402DB; Mon, 23 Jun 2025 21:34:11 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemh100008.china.huawei.com (7.202.181.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 23 Jun 2025 21:34:10 +0800 From: Lifeng Zheng To: , , CC: , , , , , , , Subject: [PATCH 7/7] cpufreq: Exit governor when failed to start old governor Date: Mon, 23 Jun 2025 21:34:02 +0800 Message-ID: <20250623133402.3120230-8-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250623133402.3120230-1-zhenglifeng1@huawei.com> References: <20250623133402.3120230-1-zhenglifeng1@huawei.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 X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemh100008.china.huawei.com (7.202.181.93) Content-Type: text/plain; charset="utf-8" Detect the result of starting old governor in cpufreq_set_policy(). If it fails, exit the governor and clear policy->governor. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 7b82ffb50283..2b431845a8a3 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2715,10 +2715,12 @@ static int cpufreq_set_policy(struct cpufreq_policy= *policy, pr_debug("starting governor %s failed\n", policy->governor->name); if (old_gov) { policy->governor =3D old_gov; - if (cpufreq_init_governor(policy)) + if (cpufreq_init_governor(policy)) { policy->governor =3D NULL; - else - cpufreq_start_governor(policy); + } else if (cpufreq_start_governor(policy)) { + cpufreq_exit_governor(policy); + policy->governor =3D NULL; + } } =20 return ret; --=20 2.33.0