From: Jeremy Linton <jeremy.linton@arm.com>
To: Pengjie Zhang <zhangpengjie2@huawei.com>,
catalin.marinas@arm.com, will@kernel.org, rafael@kernel.org,
lenb@kernel.org, saket.dumbre@intel.com, beata.michalska@arm.com,
zhenglifeng1@huawei.com, sumitg@nvidia.com,
zhanjie9@hisilicon.com, geert+renesas@glider.be,
cuiyunhui@bytedance.com, vanshikonda@os.amperecomputing.com,
ionela.voinescu@arm.com, viresh.kumar@linaro.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
acpica-devel@lists.linux.dev, linuxarm@huawei.com
Cc: prime.zeng@hisilicon.com, wanghuiqiang@huawei.com,
xuwei5@huawei.com, lihuisong@huawei.com, yubowen8@huawei.com,
wangzhi12@huawei.com
Subject: Re: [PATCH v2 2/2] arm64: topology: read CPPC FFH feedback counters in one operation
Date: Thu, 9 Jul 2026 01:11:13 -0500 [thread overview]
Message-ID: <fcf60ce5-7e8c-431d-aea9-218da5445fb5@arm.com> (raw)
In-Reply-To: <20260708082818.808041-3-zhangpengjie2@huawei.com>
Hi,
On 7/8/26 3:28 AM, Pengjie Zhang wrote:
> arm64 implements CPPC FFH feedback-counter reads using AMU counters.
> Because those counters must be sampled on the target CPU, reading the
> delivered and reference counters separately widens the observation window
> between them.
>
> Implement the paired FFH feedback-counter read hook on arm64 and sample
> both AMU counters together before decoding the requested CPC register
> values.
>
> Also factor the FFH bitfield extraction logic into a helper and reuse
> it from the existing single-counter FFH read path.
>
> Tested-by: Sumit Gupta <sumitg@nvidia.com>
> Reviewed-by: Sumit Gupta <sumitg@nvidia.com>
> Tested-by: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
> Reviewed-by: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
> Signed-off-by: Pengjie Zhang <zhangpengjie2@huawei.com>
> ---
> arch/arm64/kernel/topology.c | 92 ++++++++++++++++++++++++++++++++----
> 1 file changed, 84 insertions(+), 8 deletions(-)
>
> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> index b32f13358fbb..d28438f8b83f 100644
> --- a/arch/arm64/kernel/topology.c
> +++ b/arch/arm64/kernel/topology.c
> @@ -373,6 +373,16 @@ core_initcall(init_amu_fie);
> #ifdef CONFIG_ACPI_CPPC_LIB
> #include <acpi/cppc_acpi.h>
>
> +struct amu_ffh_ctrs {
> + u64 corecnt;
> + u64 constcnt;
> +};
> +
> +enum cpc_ffh_ctr_id {
> + CPC_FFH_CTR_CORE = 0x0,
> + CPC_FFH_CTR_CONST = 0x1,
> +};
> +
> static void cpu_read_corecnt(void *val)
> {
> /*
> @@ -397,7 +407,7 @@ static void cpu_read_constcnt(void *val)
> }
>
> static inline
> -int counters_read_on_cpu(int cpu, smp_call_func_t func, u64 *val)
> +int counters_read_on_cpu(int cpu, smp_call_func_t func, void *val)
> {
> /*
> * Abort call on counterless CPU.
> @@ -447,24 +457,90 @@ bool cpc_ffh_supported(void)
> return true;
> }
>
> +static void amu_read_core_const_ctrs(void *val)
> +{
> + struct amu_ffh_ctrs *ctrs = val;
> +
> + /*
> + * cpu_read_constcnt() incurs slight latency due to the
> + * ARM64_WORKAROUND_2457168 check. Read it first to minimize
> + * the sampling skew between the const and core counters.
> + */
> + cpu_read_constcnt(&ctrs->constcnt);
> + cpu_read_corecnt(&ctrs->corecnt);
> +}
> +
> +static u64 cpc_ffh_extract_bits(const struct cpc_reg *reg, u64 val)
> +{
> + val &= GENMASK_ULL(reg->bit_offset + reg->bit_width - 1,
> + reg->bit_offset);
> + val >>= reg->bit_offset;
> +
> + return val;
> +}
> +
> +static void cpc_ffh_ctr_value(const struct cpc_reg *reg,
> + const struct amu_ffh_ctrs *ctrs, u64 *val)
> +{
> + switch ((u64)reg->address) {
> + case CPC_FFH_CTR_CORE:
> + *val = ctrs->corecnt;
> + break;
> + case CPC_FFH_CTR_CONST:
> + *val = ctrs->constcnt;
> + break;
> + }
> +
> + *val = cpc_ffh_extract_bits(reg, *val);
> +}
> +
> +static bool is_amu_ctr_reg(const struct cpc_reg *reg)
> +{
> + return reg->address == CPC_FFH_CTR_CORE ||
> + reg->address == CPC_FFH_CTR_CONST;
> +}
> +
> +int cpc_read_ffh_fb_ctrs(int cpu, struct cpc_reg *reg1, u64 *val1,
> + struct cpc_reg *reg2, u64 *val2)
> +{
> + struct amu_ffh_ctrs ctrs;
> + int ret;
> +
> + if (!is_amu_ctr_reg(reg1) || !is_amu_ctr_reg(reg2))
> + return -EINVAL;
> +
> + ret = counters_read_on_cpu(cpu, amu_read_core_const_ctrs, &ctrs);
> + if (ret) {
> + /*
> + * If AMU is unsupported (-EOPNOTSUPP), translate the error
> + * to -ENODEV. This explicitly tells the generic CPPC layer
> + * to abort immediately and avoid falling back to pointless
> + * single-counter reads.
> + */
> + return ret == -EOPNOTSUPP ? -ENODEV : ret;
> + }
> +
> + cpc_ffh_ctr_value(reg1, &ctrs, val1);
> + cpc_ffh_ctr_value(reg2, &ctrs, val2);
> +
> + return 0;
> +}
> +
> int cpc_read_ffh(int cpu, struct cpc_reg *reg, u64 *val)
> {
> int ret = -EOPNOTSUPP;
>
> switch ((u64)reg->address) {
> - case 0x0:
> + case CPC_FFH_CTR_CORE:
> ret = counters_read_on_cpu(cpu, cpu_read_corecnt, val);
> break;
> - case 0x1:
> + case CPC_FFH_CTR_CONST:
> ret = counters_read_on_cpu(cpu, cpu_read_constcnt, val);
> break;
> }
>
> - if (!ret) {
> - *val &= GENMASK_ULL(reg->bit_offset + reg->bit_width - 1,
> - reg->bit_offset);
> - *val >>= reg->bit_offset;
> - }
> + if (!ret)
> + *val = cpc_ffh_extract_bits(reg, *val);
>
> return ret;
> }
So, more a nitpik that only applies if this set gets respun, but:
I don't think this FFH counter logic belongs in the arm64 topology.c
file, its not really topology related.
next prev parent reply other threads:[~2026-07-09 6:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 8:28 [PATCH v2 0/2] CPPC: reduce FFH feedback-counter sampling skew on arm64 Pengjie Zhang
2026-07-08 8:28 ` [PATCH v2 1/2] ACPI: CPPC: add paired FFH feedback-counter read hook Pengjie Zhang
2026-07-08 8:28 ` [PATCH v2 2/2] arm64: topology: read CPPC FFH feedback counters in one operation Pengjie Zhang
2026-07-09 6:11 ` Jeremy Linton [this message]
2026-07-10 13:35 ` Beata Michalska
2026-07-09 6:07 ` [PATCH v2 0/2] CPPC: reduce FFH feedback-counter sampling skew on arm64 Jeremy Linton
2026-07-10 13:42 ` Beata Michalska
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fcf60ce5-7e8c-431d-aea9-218da5445fb5@arm.com \
--to=jeremy.linton@arm.com \
--cc=acpica-devel@lists.linux.dev \
--cc=beata.michalska@arm.com \
--cc=catalin.marinas@arm.com \
--cc=cuiyunhui@bytedance.com \
--cc=geert+renesas@glider.be \
--cc=ionela.voinescu@arm.com \
--cc=lenb@kernel.org \
--cc=lihuisong@huawei.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=prime.zeng@hisilicon.com \
--cc=rafael@kernel.org \
--cc=saket.dumbre@intel.com \
--cc=sumitg@nvidia.com \
--cc=vanshikonda@os.amperecomputing.com \
--cc=viresh.kumar@linaro.org \
--cc=wanghuiqiang@huawei.com \
--cc=wangzhi12@huawei.com \
--cc=will@kernel.org \
--cc=xuwei5@huawei.com \
--cc=yubowen8@huawei.com \
--cc=zhangpengjie2@huawei.com \
--cc=zhanjie9@hisilicon.com \
--cc=zhenglifeng1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox