From patchwork Wed Apr 9 09:51:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yaxiong Tian X-Patchwork-Id: 880848 Received: from out203-205-221-164.mail.qq.com (out203-205-221-164.mail.qq.com [203.205.221.164]) (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 A38AE25D206; Wed, 9 Apr 2025 09:56:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.205.221.164 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744192611; cv=none; b=ahxXmXz/BiLt6e1ZsHNjpk8bzE+nw/Mn2G2esz/XIss18376S7b137tpQ+1QQ6eOIamr9BBsgzwTisnQetztpTQ+RCiHRTt742/rWuwYeIt3wFvsXUlXx6AQGVTqT0bGhhNp4gvBnXhlzuWgkldLbk3aJcSSf/GextZb3L5HMZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744192611; c=relaxed/simple; bh=wK1y6dHPy4sbGssX93eGO5NCjBNTcZms0HLXlXqdmeM=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=jtv11MKwsNwKkb1Sa+YJd6JoRktsBib6m3n5wpwSfWzjAQ/OnaKGvbZvj49SBD8LvsvGMzmgDWOVg1M+b/Oqeteqpl0JItVyMyRhzLJPv4qncfBstTlz+dwYsaAcqT6rmZG1L+21Iv9reO3JJkc7OO2WSGEPQbxANKNOCgVNLAQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=uQDWmYB2; arc=none smtp.client-ip=203.205.221.164 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="uQDWmYB2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1744192304; bh=7Y4Q2wgqKIpLG/t08yDgQVZzMfyRABq6eyXLD9OhCis=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=uQDWmYB2tfWuwCCZsRlCVj4aTl+da6p3nlEofHUzzk2CrS7ds5gks04Q65pcDUDhy WiELwRIPqxWSQKPxjSIxazBDaoe4Yunoz6qlArOBVaMyRTXkCvv/dMRr1VKhbIHvLM ejc+Co1WifnhhvkJSDBvmB+KeJPJpjtLyq13WPkg= Received: from localhost.localdomain ([116.128.244.169]) by newxmesmtplogicsvrszb21-0.qq.com (NewEsmtp) with SMTP id CEB04603; Wed, 09 Apr 2025 17:51:43 +0800 X-QQ-mid: xmsmtpt1744192303tvp8i7h6x Message-ID: X-QQ-XMAILINFO: Mg/13mbJq/Ru6Y7pf9rnxlFchTWPyEfj/S7AIffDwpj/H3SURotqVEM0ta4n4o ZtdnahsYqyYJQJPtQtsf81LRHSRFKgO2Dj+sVSh+karuWL2kVQXDdRZimbIHkMVWraPzcPTx2Qil bdVQrfGSrwza+eTwNvLP1jJDB4Tey/GJLKkspk6YU6lysjskwbb1ECNP8w2q0B/zDqgbfcPYFVOP 7trh+3dEOe+rgNoSllQOJJa5su2sWN8qCxUT649mCf/irsowHNNatTcMm6hLWJSrpO675SZ/2Lnd uMlAY8/bcxY+u1lzb5pkgMbjDu15Dx+NLmejAxHB7fSuA+5xdX2ODVHdendZ1plUrQMgnl29808H prWJUXBecvGmi+QuOjMnbD2l2bE/VP0nMAWsdW5hJVBYvwG72nAOCi38Zx8bz0bybIMPBkPsmpHZ UNIMAz7UuojB80IptKuedAcJ6zfBoazA6qYuooGVsWGQNypi3lU4GJF0Hqn3TdUN0xxZsVrW4Cvg PLodkWCUJcfWvY9SGZoNKXnzgU9C5xPX7JFZFOp5ee6bmEiCP4gFvBbkKQkzyAUrt1vNvbXQZKZK RXJIVg48NkltijSl2RzHvDNPeu+SfPw3cpRpMC+SjDV4vXvAVEFK839Kn9arNEWXaFQqyL269wj8 0Nf9dqjRc4dF3REMRGWJ3Mf0LCLlX8IAJLWDKg6JyqMrVQpQQgcNTAH6z1QHcFdJw4HHFSapvlVb XYBv4mLYfL5voJivFH1bf2lxe/OW+533BNTsUbmYm8Mdp+V7GV2k2blvRNcbPni9dMIGijuLf3+c V46QHZ5SsduccyktGbi0FBjLKtbk9smm7fjdMKgetkfxCGMzh6VFejEbTm8wdZQsH+i1FLKKPAEW PF5Q4jVOdImlujCKr6hicre872nrZZWU6oyfyJ4GTa0+SGSuo0vhDb32ZjOcf65WJpULIEipUEsi KY7zC6agAZI08t5lH3oN06jxYC+TdVWCfdzqwdGttuMTx/Jf1xx+aoc9fiQJJS0dz358MXu/0OXP tlNFIBXw== X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Yaxiong Tian To: rafael@kernel.org, viresh.kumar@linaro.org, Pierre.Gondois@arm.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Yaxiong Tian Subject: [PATCH 1/2] cpufreq: cppc: Update and opt comment for cost calculation method Date: Wed, 9 Apr 2025 17:51:41 +0800 X-OQ-MSGID: <20250409095141.1691685-1-iambestgod@qq.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yaxiong Tian commit <1b600da510735a> ("PM: EM: Optimize em_cpu_energy() and remove division") updated the energy calculation method, so the original comment needs to be updated and opt. Signed-off-by: Yaxiong Tian --- drivers/cpufreq/cppc_cpufreq.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index b3d74f9adcf0..756034b21682 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -379,9 +379,18 @@ static unsigned int get_perf_level_count(struct cpufreq_policy *policy) return 1 + max_cap / CPPC_EM_CAP_STEP - min_cap / CPPC_EM_CAP_STEP; } -/* - * The cost is defined as: - * cost = power * max_frequency / frequency +/** + * compute_cost - Calculate the cost for a given CPU and performance level step + * @cpu: Target CPU + * @step: Performance level step + * + * CPPC uses a linear cost model since it only provides relative efficiency ratios: + * Base cost (per CPU): CPPC_EM_COST_GAP * efficiency_class + * Step cost (per level): step * CPPC_EM_COST_STEP + * + * Lower cost implies higher efficiency. The model ensures: + * 1. Higher efficiency CPUs (low efficiency_class) always have lower cost. + * 2. Higher performance levels (larger step) linearly increase cost. */ static inline unsigned long compute_cost(int cpu, int step) { From patchwork Wed Apr 9 09:51:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yaxiong Tian X-Patchwork-Id: 880847 Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) (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 D0E921DF247; Wed, 9 Apr 2025 10:05:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.62.57.252 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744193121; cv=none; b=piZ1HzFKE7X6j+WhnLYysZKMH0Jb6bU0pjNE0Etd33jrqFshPn3kB9wS6o49Wo7IOW6bdg1sPwLZRvUmklx8K0pjyWfc8gZsNpoxqMeH4kj1AXZlWcOAopG+HJlDLaG3cnlZePWhJjm5I+XrvL+zeVdFXuWNaT/XPsayTsygsM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744193121; c=relaxed/simple; bh=dftAXhrtSj6CtjhCfME+c+dNS0JOX5D/+C+I3mPSItA=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=jb1Y9BO8A3t0hP4gnmfPQvTZYaRU41X2Vhcepar3MPJPlK5qW5eej5QIy97Rlcvxd25AHYMA0WpTvbXKBLhj5u4jj9DFJ45h6NEXzW1dr+TOOd5Di7AgwIwXrehqCihkqmurc6RBQKHYdphxerISmqFMB10gsXbrGruEdu/Bk0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=ndC0RNz7; arc=none smtp.client-ip=162.62.57.252 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="ndC0RNz7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1744193111; bh=JRw+TJVVfisiKuNwIGnJ9MSWyLObSQOGDeMTJZPcRVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ndC0RNz7vT64SFOnaVQruznx06fGF6P9wA0huFcB/VwCAQK4TzYmQhECigPjW7w/R rgzDsMQnwkw1txl0O+VyTB7SnFF8bbkmTGsgkHQ8Y2AHTN9vSNWCV9oIVxzSnSJlzW zsrW15yrvSX0LohLPTa86RRxJ3U9DmMgKsEhLSW4= Received: from localhost.localdomain ([116.128.244.169]) by newxmesmtplogicsvrszb21-0.qq.com (NewEsmtp) with SMTP id CF320A71; Wed, 09 Apr 2025 17:51:51 +0800 X-QQ-mid: xmsmtpt1744192311tpyuc4d19 Message-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tian To: rafael@kernel.org, viresh.kumar@linaro.org, Pierre.Gondois@arm.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Yaxiong Tian Subject: [PATCH 2/2] cpufreq: cppc: Add comments for CPPC_EM_COST_GAP calculation Date: Wed, 9 Apr 2025 17:51:50 +0800 X-OQ-MSGID: <20250409095150.1692220-1-iambestgod@qq.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yaxiong Tian The existing comments about CPPC_EM_COST_GAP were too brief. To help other developers better understand its design rationale, this commit adds detailed explanations about it. Signed-off-by: Yaxiong Tian --- drivers/cpufreq/cppc_cpufreq.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 756034b21682..c8e281ca95c0 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -358,7 +358,34 @@ static void cppc_cpufreq_register_em(struct cpufreq_policy *policy); #define CPPC_EM_CAP_STEP (20) /* Increase the cost value by CPPC_EM_COST_STEP every performance state. */ #define CPPC_EM_COST_STEP (1) -/* Add a cost gap correspnding to the energy of 4 CPUs. */ + +/* + * In the current EM (Energy Model), energy consumption is calculated as: + * ps->cost * sum_util; + * + * For CPPC, the cost calculation uses a linear model: cost = a + b * step. + * + * For a task A with utilization 'util' in a performance domain (pd): + * Before placement: + * energy_pd_before = a * sum_util_pd + b * step * sum_util_pd; + * After placement: + * energy_pd_after = a * (sum_util_pd + util) + b * (sum_util_pd + util) * + * (step + util/CPPC_EM_CAP_STEP); + * Energy difference: + * energy_diff = a * util + b * util * step_pd + + * b * (sum_util_pd + util) * util/cap_step + * + * The placement decision depends on the bias 'a' and slope 'b'. Considering the + * extreme case where little cores are nearly full and big cores are nearly idle: + * energy_diff_pd = a_diff * util - b * util * step_pd_small - + * b * util * sum_util_pd_small/cap_step + * + * Ignoring smaller terms, the key condition becomes: + * a_diff > b * sum_util_pd_small / step_cap + * + * Therefore, for a pd domain with 4 CPUs, for ensures the scheduler will prefer + * placing it.we can configure accordingly. + */ #define CPPC_EM_COST_GAP (4 * SCHED_CAPACITY_SCALE * CPPC_EM_COST_STEP \ / CPPC_EM_CAP_STEP)