Re: [PATCH 04/19] cpufreq: amd: introduce a new amd pstate driver to support future processors

From: Peter Zijlstra
Date: Thu Sep 09 2021 - 11:02:03 EST


On Wed, Sep 08, 2021 at 10:59:46PM +0800, Huang Rui wrote:

> +struct amd_pstate_perf_funcs {
> + int (*enable)(bool enable);
> + int (*init_perf)(struct amd_cpudata *cpudata);
> + void (*update_perf)(struct amd_cpudata *cpudata,
> + u32 min_perf, u32 des_perf,
> + u32 max_perf, bool fast_switch);
> +};

> +static int
> +amd_pstate_enable(struct amd_pstate_perf_funcs *funcs, bool enable)
> +{
> + if (!funcs)
> + return -EINVAL;
> +
> + return funcs->enable(enable);
> +}

> +static int amd_pstate_init_perf(struct amd_cpudata *cpudata)
> +{
> + struct amd_pstate_perf_funcs *funcs = cpufreq_get_driver_data();
> +
> + if (!funcs)
> + return -EINVAL;
> +
> + return funcs->init_perf(cpudata);
> +}

> +static int
> +amd_pstate_update_perf(struct amd_cpudata *cpudata, u32 min_perf,
> + u32 des_perf, u32 max_perf, bool fast_switch)
> +{
> + struct amd_pstate_perf_funcs *funcs = cpufreq_get_driver_data();
> +
> + if (!funcs)
> + return -EINVAL;
> +
> + funcs->update_perf(cpudata, min_perf, des_perf,
> + max_perf, fast_switch);
> +
> + return 0;
> +}

> +static struct amd_pstate_perf_funcs pstate_funcs = {
> + .enable = pstate_enable,
> + .init_perf = pstate_init_perf,
> + .update_perf = pstate_update_perf,
> +};

> +static int __init amd_pstate_init(void)
> +{
> + int ret;
> + struct amd_pstate_perf_funcs *funcs;

> +
> + funcs = &pstate_funcs;

What is the purpose of this seemingly pointless indirection? Showing off
how good AMD hardware is at doing retpolines or something?