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.
On Fri, 2022-05-20 at 09:44 -0700, Dave Hansen wrote:
> 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.
Thanks for having a look! You're right. I need to either check these
return values, or not have them at all.
>
> 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.
That's good advice. I'll do that consolidation.
>
> 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.
Thanks,
Giovanni