From patchwork Wed Jan 15 10:01:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lifeng Zheng X-Patchwork-Id: 13940194 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 EB7FA1EBFE8; Wed, 15 Jan 2025 10:01:27 +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=1736935290; cv=none; b=NmOebjpXn3sXmdIoJj2wD4mCM2kAHkHMiwMzDdiq5Yh2NdgcgX+HpOE+tx8coD0/Xoyy3E2ZkaTxqVC0Xp++TakaiRPp/YKaDcV/6OSlxH7wollNBHoVUVHxWbr9k8+cveuTDVcTjD0/7vdl/HBujBcouFNa7fLK5C53ni3mYVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736935290; c=relaxed/simple; bh=/Nzt6bJwCHR87D6MgO7OEmZkYkIjMEc763skiJXqvRQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ok7Pr4UvFno579b39AMhK6MJZVmDHU1lZnszxJXQ5/NmP2S/CfiWsAsC0bPpAOIFi++fTjmKg/cMLa9KBTspAuhdTh1Z+3HdvM/apblZS59oP77hsgTL45nbP9+05lqc904hU18WKV088PRxLbQACQAG0VElOTSi0GX2XVCG5Ac= 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 4YY1dB0WN7zbdNG; Wed, 15 Jan 2025 17:57:34 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 28D4E1400E3; Wed, 15 Jan 2025 18:01:25 +0800 (CST) Received: from localhost.huawei.com (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; Wed, 15 Jan 2025 18:01:24 +0800 From: Lifeng Zheng To: , CC: , , , , , , , Subject: [PATCH 1/2] cpufreq: Fix re-boost issue after hotplugging a cpu Date: Wed, 15 Jan 2025 18:01:22 +0800 Message-ID: <20250115100123.241110-2-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250115100123.241110-1-zhenglifeng1@huawei.com> References: <20250115100123.241110-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemh100008.china.huawei.com (7.202.181.93) It turns out that cpuX will stay on the base frequency after performing these operations: 1. boost all cpus: echo 1 > /sys/devices/system/cpu/cpufreq/boost 2. offline the cpu: echo 0 > /sys/devices/system/cpu/cpuX/online 3. deboost all cpus: echo 0 > /sys/devices/system/cpu/cpufreq/boost 4. online the cpu: echo 1 > /sys/devices/system/cpu/cpuX/online 5. boost all cpus again: echo 1 > /sys/devices/system/cpu/cpufreq/boost This is because max_freq_req of the policy is not updated during the online process, and the value of max_freq_req before the last offline is retained. When the CPU is boosted again, freq_qos_update_request() will do nothing because the old value is the same as the new one. This causes the CPU stay on the base frequency. Update max_freq_req (and min_freq_req of course) in cpufreq_online() will solve this problem. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 1a4cae54a01b..03ae879d50b9 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1475,6 +1475,13 @@ static int cpufreq_online(unsigned int cpu) blocking_notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_CREATE_POLICY, policy); + } else { + ret = freq_qos_update_request(policy->min_freq_req, policy->min); + if (ret < 0) + goto out_destroy_policy; + ret = freq_qos_update_request(policy->max_freq_req, policy->max); + if (ret < 0) + goto out_destroy_policy; } if (cpufreq_driver->get && has_target()) { From patchwork Wed Jan 15 10:01:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lifeng Zheng X-Patchwork-Id: 13940195 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 509B8248169; Wed, 15 Jan 2025 10:01:28 +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=1736935290; cv=none; b=NDiFkkGkQA9QvU2DhoXGFuuREK7WjIi9YTwqnOcGhnW5rif4FtCps1enVh/656I28ezBje47ABthVLaYjiBKCyQa+Qk2uyNsM5oQFmCIE8xmG8S6rlfpzqtTnwcYv86WAZr8maGIGHlOUHU7ouq+veFd0UBXksFEbL/Tb5JbbsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736935290; c=relaxed/simple; bh=VA0netJc+k/lvvdFyG1QlH9IhzP4KpqVzmPKZJ/c2bs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ju/EZPDArRl7oNmVfuGdj4RBj/lKPSH4lNrogSQO1Koe2VDE1b2QpkWf9hjp0XWE2W8guXK2YRLdp/j6o33mQgEpuLWPyjBsuXDUt6rA6y5SmV/SDBIKv6XDRT09HAidaq+0thEYA7PRjBvJQwZqcuMEuHb6aBEM4MZrrSvJhG4= 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.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4YY1dz2GS8z2Dkbx; Wed, 15 Jan 2025 17:58:15 +0800 (CST) Received: from kwepemh100008.china.huawei.com (unknown [7.202.181.93]) by mail.maildlp.com (Postfix) with ESMTPS id 928561A0188; Wed, 15 Jan 2025 18:01:25 +0800 (CST) Received: from localhost.huawei.com (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; Wed, 15 Jan 2025 18:01:24 +0800 From: Lifeng Zheng To: , CC: , , , , , , , Subject: [PATCH 2/2] cpufreq: Introduce a more generic way to set default per-policy boost flag Date: Wed, 15 Jan 2025 18:01:23 +0800 Message-ID: <20250115100123.241110-3-zhenglifeng1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250115100123.241110-1-zhenglifeng1@huawei.com> References: <20250115100123.241110-1-zhenglifeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemh100008.china.huawei.com (7.202.181.93) In cpufreq_online() of cpufreq.c, the per-policy boost flag is already set to mirror the cpufreq_driver boost during init but using freq_table to judge if the policy has boost frequency. There are two drawbacks to this approach: 1. It doesn't work for the cpufreq drivers that do not use a frequency table. For now, acpi-cpufreq and amd-pstate have to enable boost in policy initialization. And cppc_cpufreq never set policy to boost when going online no matter what the cpufreq_driver boost flag is. 2. If the cpu goes offline when cpufreq_driver boost enabled and then goes online when cpufreq_driver boost disabled, the per-policy boost flag will unreasonably remain true. Running set_boost at the end of the online process is a more generic way for all cpufreq drivers. Signed-off-by: Lifeng Zheng --- drivers/cpufreq/cpufreq.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 03ae879d50b9..867bda3decfd 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1409,10 +1409,6 @@ static int cpufreq_online(unsigned int cpu) goto out_free_policy; } - /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */ - if (cpufreq_boost_enabled() && policy_has_boost_freq(policy)) - policy->boost_enabled = true; - /* * The initialization has succeeded and the policy is online. * If there is a problem with its frequency table, take it @@ -1576,6 +1572,18 @@ static int cpufreq_online(unsigned int cpu) if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver)) policy->cdev = of_cpufreq_cooling_register(policy); + /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */ + if (cpufreq_boost_supported()) { + policy->boost_enabled = cpufreq_boost_enabled(); + ret = cpufreq_driver->set_boost(policy, policy->boost_enabled); + if (ret) { + /* If the set_boost fails, the online operation is not affected */ + pr_info("%s: CPU%d: Cannot %s BOOST\n", __func__, policy->cpu, + policy->boost_enabled ? "enable" : "disable"); + policy->boost_enabled = !policy->boost_enabled; + } + } + pr_debug("initialization complete\n"); return 0;