[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 09/18] xen/amd: introduce amd_process_freq() to get processor frequency


  • To: Penny Zheng <Penny.Zheng@xxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 12 Jun 2025 15:15:59 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: ray.huang@xxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 12 Jun 2025 13:16:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 27.05.2025 10:48, Penny Zheng wrote:
> When _CPC table could not provide processor frequency range
> values for Xen governor, we need to read processor max frequency
> as anchor point.
> So we extract amd cpu core frequency calculation logic from amd_log_freq(),
> and wrap it as a new helper amd_process_freq().
> 
> Signed-off-by: Penny Zheng <Penny.Zheng@xxxxxxx>
> ---
> v1 -> v2:
> - new commit
> ---
> v3 -> v4
> - introduce amd_process_freq()
> ---
> v4 -> v5:
> - make amd_process_freq() static to statisfy Misra demand
> - change "low_mhz", "nom_mhz" and "hi_mhz" parameter to unsigned int
> - fix order of logged frequencies
> ---
>  xen/arch/x86/cpu/amd.c | 58 +++++++++++++++++++++++++++++-------------
>  1 file changed, 40 insertions(+), 18 deletions(-)
> 
> diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
> index 3770d75150..8c985466fa 100644
> --- a/xen/arch/x86/cpu/amd.c
> +++ b/xen/arch/x86/cpu/amd.c
> @@ -611,14 +611,15 @@ static unsigned int attr_const amd_parse_freq(unsigned 
> int family,
>       return freq;
>  }
>  
> -void amd_log_freq(const struct cpuinfo_x86 *c)
> +static void amd_process_freq(const struct cpuinfo_x86 *c,
> +                          unsigned int *low_mhz,
> +                          unsigned int *nom_mhz,
> +                          unsigned int *hi_mhz)
>  {
>       unsigned int idx = 0, h;
>       uint64_t hi, lo, val;
>  
> -     if (c->x86 < 0x10 || c->x86 > 0x1A ||
> -         (c != &boot_cpu_data &&
> -          (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1)))))
> +     if (c->x86 < 0x10 || c->x86 > 0x1A)
>               return;
>  
>       if (c->x86 < 0x17) {
> @@ -699,20 +700,20 @@ void amd_log_freq(const struct cpuinfo_x86 *c)
>  
>       if (idx && idx < h &&
>           !rdmsr_safe(0xC0010064 + idx, val) && (val >> 63) &&
> -         !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
> -             printk("CPU%u: %u (%u ... %u) MHz\n",
> -                    smp_processor_id(),
> -                    amd_parse_freq(c->x86, val),
> -                    amd_parse_freq(c->x86, lo),
> -                    amd_parse_freq(c->x86, hi));
> -     else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
> -             printk("CPU%u: %u ... %u MHz\n",
> -                    smp_processor_id(),
> -                    amd_parse_freq(c->x86, lo),
> -                    amd_parse_freq(c->x86, hi));
> -     else
> -             printk("CPU%u: %u MHz\n", smp_processor_id(),
> -                    amd_parse_freq(c->x86, lo));
> +         !rdmsr_safe(0xC0010064, hi) && (hi >> 63)) {
> +             if (nom_mhz)
> +                     *nom_mhz = amd_parse_freq(c->x86, val);
> +             if (low_mhz)
> +                     *low_mhz = amd_parse_freq(c->x86, lo);
> +             if (hi_mhz)
> +                     *hi_mhz = amd_parse_freq(c->x86, hi);
> +     } else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63)) {
> +             if (low_mhz)
> +                     *low_mhz = amd_parse_freq(c->x86, lo);
> +             if (hi_mhz)
> +                     *hi_mhz = amd_parse_freq(c->x86, hi);
> +     } else if (low_mhz)
> +             *low_mhz = amd_parse_freq(c->x86, lo);
>  }
>  
>  void cf_check early_init_amd(struct cpuinfo_x86 *c)
> @@ -723,6 +724,27 @@ void cf_check early_init_amd(struct cpuinfo_x86 *c)
>       ctxt_switch_levelling(NULL);
>  }
>  
> +void amd_log_freq(const struct cpuinfo_x86 *c)
> +{
> +     unsigned int low_mhz = 0, nom_mhz = 0, hi_mhz = 0;
> +
> +     if (c != &boot_cpu_data &&
> +         (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1))))
> +             return;
> +
> +     amd_process_freq(c, &low_mhz, &nom_mhz, &hi_mhz);
> +
> +     if (!low_mhz && !nom_mhz && !hi_mhz)

With this ...

> +             printk("CPU%u: %u (%u ... %u) MHz\n",
> +                    smp_processor_id(),
> +                    nom_mhz, low_mhz, hi_mhz);

.. aren't you logging three zeroes here? Considering the earlier mistake
of the order of logged frequencies, did you not think of looking at the
resulting output in the hypervisor boot log?

Same issue again below then.

With all instances corrected:
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.