mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Zhang, Rui" <rui.zhang@intel.com>
To: "tglx@linutronix.de" <tglx@linutronix.de>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"Tang, Feng" <feng.tang@intel.com>
Cc: "Chen, Tim C" <tim.c.chen@intel.com>,
	"bp@alien8.de" <bp@alien8.de>, "x86@kernel.org" <x86@kernel.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"paulmck@kernel.org" <paulmck@kernel.org>,
	"Woodhouse, David" <dwmw@amazon.co.uk>
Subject: Re: [Patch v2 2/2] x86/tsc: use logical_packages as a better estimation of socket numbers
Date: Fri, 23 Jun 2023 15:36:57 +0000	[thread overview]
Message-ID: <5df3cca321782fecdfcfac9f4139da5a7fdf3277.camel@intel.com> (raw)
In-Reply-To: <87h6qz7et0.ffs@tglx>

Hi, Thomas,

On Thu, 2023-06-22 at 16:27 +0200, Thomas Gleixner wrote:
> On Fri, Jun 16 2023 at 15:18, Feng Tang wrote:
> > On Thu, Jun 15, 2023 at 11:20:21AM +0200, Peter Zijlstra wrote:
> > Yes. Rui is working on a MADT based parsing which may take a while
> > before being stable, given all kinds of fancy firmware out there.
> 
> Please not yet another mad table parser.
> 
> The topology can be evaluated during early boot via:
> 
>   1) The APIC IDs of the possible CPUs.
> 
>   2) CPUID leaf 0xb or 0x1f where the topmost subleaf gives the
> number
>      of bits to shift the APIC ID right for the package/socket
> 
exactly the same in my proposal.

The difference is that I also
1. get the bitshift of the core id and count the number of cores in a
   package.
   On Intel hybrid platforms, using nr_package_cpus / nr_core_cpus to
   get the number of cores in a package (x86_max_cores) is broken.
   e.g. for a 6Pcore + 8Ecore system, package has 20 CPUs and 14 cores.
2. get the maximum number of SMT siblings in each core to set correct
   smp_num_siblings.
   On future hybrid platforms, it is possible that Ecore is used
   as boot CPU. This could result in smp_num_siblings set to 1 during 
   boot cpu startup, and cpu_smt_control set to CPU_SMT_NOT_SUPPORTED.

> Trying to accomodate for anything else than the documented
> enumeration
> is crazy. If fancy firmware is broken then they can keep the pieces.
> 
> So something like the below should just work.
> 
> I fundamentally hate the hackery in topology.c, but cleaning this
> mess
> up is a completely different problem and already worked on.
> 
> Thanks,
> 
>         tglx
> ---
> --- a/arch/x86/include/asm/apic.h
> +++ b/arch/x86/include/asm/apic.h
> @@ -509,9 +509,12 @@ extern int default_check_phys_apicid_pre
>  #ifdef CONFIG_SMP
>  bool apic_id_is_primary_thread(unsigned int id);
>  void apic_smt_update(void);
> +extern unsigned int apic_to_pkg_shift;
> +bool logical_packages_update(u32 apicid);
>  #else
>  static inline bool apic_id_is_primary_thread(unsigned int id) {
> return false; }
>  static inline void apic_smt_update(void) { }
> +static inline bool logical_packages_update(u32 apicid) { return
> true; }
>  #endif
>  
>  struct msi_msg;
> --- a/arch/x86/kernel/acpi/boot.c
> +++ b/arch/x86/kernel/acpi/boot.c
> @@ -177,6 +177,9 @@ static int acpi_register_lapic(int id, u
>                 return -EINVAL;
>         }
>  
> +       if (!logical_packages_update(acpiid))
> +               return -EINVAL;
> +
>         if (!enabled) {
>                 ++disabled_cpus;
>                 return -EINVAL;
> --- a/arch/x86/kernel/cpu/amd.c
> +++ b/arch/x86/kernel/cpu/amd.c
> @@ -692,6 +692,8 @@ static void early_init_amd(struct cpuinf
>                 }
>         }
>  
> +       detect_extended_topology_early(c);
> +
>         if (cpu_has(c, X86_FEATURE_TOPOEXT))
>                 smp_num_siblings = ((cpuid_ebx(0x8000001e) >> 8) &
> 0xff) + 1;
>  }
> --- a/arch/x86/kernel/cpu/topology.c
> +++ b/arch/x86/kernel/cpu/topology.c
> @@ -29,6 +29,8 @@ unsigned int __max_die_per_package __rea
>  EXPORT_SYMBOL(__max_die_per_package);
>  
>  #ifdef CONFIG_SMP
> +unsigned int apic_to_pkg_shift __ro_after_init;
> +
>  /*
>   * Check if given CPUID extended topology "leaf" is implemented
>   */
> @@ -66,7 +68,7 @@ int detect_extended_topology_early(struc
>  {
>  #ifdef CONFIG_SMP
>         unsigned int eax, ebx, ecx, edx;
> -       int leaf;
> +       int leaf, subleaf;
>  
>         leaf = detect_extended_topology_leaf(c);
>         if (leaf < 0)
> @@ -80,6 +82,14 @@ int detect_extended_topology_early(struc
>          */
>         c->initial_apicid = edx;
>         smp_num_siblings = max_t(int, smp_num_siblings,
> LEVEL_MAX_SIBLINGS(ebx));
> +
> +       for (subleaf = 1; subleaf < 8; subleaf++) {
> +               cpuid_count(leaf, subleaf, &eax, &ebx, &ecx, &edx);
> +
> +               if (ebx == 0 || !LEAFB_SUBTYPE(ecx))

Do we ever see ebx == 0 for a valid subtype?
When decoding CPUID.0B/1F, we check for invalid subtype only.

thanks,
rui

      parent reply	other threads:[~2023-06-23 15:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13  5:25 [Patch v2 1/2] smp: Add helper function to mark possible bad package number Feng Tang
2023-06-13  5:25 ` [Patch v2 2/2] x86/tsc: use logical_packages as a better estimation of socket numbers Feng Tang
2023-06-15  9:20   ` Peter Zijlstra
2023-06-16  6:53     ` Zhang, Rui
2023-06-16  8:02       ` Peter Zijlstra
2023-06-16  8:10         ` Peter Zijlstra
2023-06-16  9:19           ` Zhang, Rui
2023-06-16  9:42             ` Peter Zijlstra
2023-06-16 11:23               ` Zhang, Rui
2023-06-16 11:47                 ` Feng Tang
2023-06-16  8:22         ` Peter Zijlstra
2023-06-19 10:42         ` Feng Tang
2023-06-16  7:18     ` Feng Tang
2023-06-22 14:27       ` Thomas Gleixner
2023-06-22 23:07         ` Thomas Gleixner
2023-06-23 15:49           ` Zhang, Rui
     [not found]           ` <ZJW0gi5oQQbxf8Df@feng-clx>
2023-06-25 14:51             ` Feng Tang
2023-06-27 11:14               ` Thomas Gleixner
2023-06-29 13:27                 ` Feng Tang
2023-07-17 13:38                   ` Feng Tang
2023-07-26 19:37                     ` Thomas Gleixner
2023-07-27  1:24                       ` Feng Tang
2023-06-23 15:36         ` Zhang, Rui [this message]

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=5df3cca321782fecdfcfac9f4139da5a7fdf3277.camel@intel.com \
    --to=rui.zhang@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=feng.tang@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@intel.com \
    --cc=x86@kernel.org \
    /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

Powered by JetHome