Re: [PATCH 2/2] x86: fix platform info detection in frequency invariance

From: Dave Hansen
Date: Fri May 20 2022 - 12:44:33 EST


On 5/20/22 09:10, Giovanni Gherdovich wrote:
> if (slv_set_max_freq_ratio(&base_freq, &turbo_freq))
> goto out;
>
> - if (x86_match_cpu(has_glm_turbo_ratio_limits) &&
> - skx_set_max_freq_ratio(&base_freq, &turbo_freq, 1))
> + if (x86_match_cpu(has_glm_turbo_ratio_limits)) {
> + skx_set_max_freq_ratio(&base_freq, &turbo_freq, 1);
> goto out;
> + }
>
> - if (x86_match_cpu(has_knl_turbo_ratio_limits) &&
> - knl_set_max_freq_ratio(&base_freq, &turbo_freq, 1))
> + if (x86_match_cpu(has_knl_turbo_ratio_limits)) {
> + knl_set_max_freq_ratio(&base_freq, &turbo_freq, 1);
> goto out;
> + }
>
> - if (x86_match_cpu(has_skx_turbo_ratio_limits) &&
> - skx_set_max_freq_ratio(&base_freq, &turbo_freq, 4))
> + if (x86_match_cpu(has_skx_turbo_ratio_limits)) {
> + skx_set_max_freq_ratio(&base_freq, &turbo_freq, 4);
> goto out;
> + }
>
> if (core_set_max_freq_ratio(&base_freq, &turbo_freq))
> goto out;

But didn't the last patch in the series carefully change the return
value for knl_set_max_freq_ratio()? Now, the only call site is ignoring
the return value? That seems odd.

Also, this is a mess. These constructs:

static const struct x86_cpu_id has_knl_turbo_ratio_limits[] = {
X86_MATCH(XEON_PHI_KNL),
X86_MATCH(XEON_PHI_KNM),
{}
};

static const struct x86_cpu_id has_skx_turbo_ratio_limits[] = {
X86_MATCH(SKYLAKE_X),
{}
};

static const struct x86_cpu_id has_glm_turbo_ratio_limits[] = {
X86_MATCH(ATOM_GOLDMONT),
X86_MATCH(ATOM_GOLDMONT_D),
X86_MATCH(ATOM_GOLDMONT_PLUS),
{}
};

are rather goofy. A single array like rapl_ids[] that points to the
handler function would do us a lot more good here, say:

static const struct x86_cpu_id has_knl_turbo_ratio_limits[] = {
X86_MATCH(XEON_PHI_KNL, &knl_set_max_freq_ratio),
X86_MATCH(XEON_PHI_KNM, &knl_set_max_freq_ratio),
X86_MATCH(SKYLAKE_X, &skx_set_max_freq_ratio),
X86_MATCH(ATOM_GOLDMONT, &skx_set_max_freq_ratio),
X86_MATCH(ATOM_GOLDMONT_D, &skx_set_max_freq_ratio),
X86_MATCH(ATOM_GOLDMONT_PLUS, &skx_set_max_freq_ratio),
X86_MATCH(ANY, &core_set_max_freq_ratio),
{}
};

That would get rid of all the goofy gotos and actually puts all the
logic in one place. BTW, I'm not 100% sure about the 'ANY' line. I
think that's how those work, but please double-check me on it.

While it's generally best to keep bug fixes to a minimum, I think this
one is worth a bit of a cleanup because it will remove a bunch of spaghetti.