linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration
@ 2018-03-26  8:05 Suravee Suthikulpanit
  2018-03-26  8:05 ` [PATCH 1/2] x86/CPU: Modify detect_extended_topology() to return result Suravee Suthikulpanit
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Suravee Suthikulpanit @ 2018-03-26  8:05 UTC (permalink / raw)
  To: linux-kernel, x86; +Cc: tglx, mingo, hpa, bp, Suravee Suthikulpanit

Linux currently provides function detect_extended_topology()
for parsing CPUID Fn0xB and derive CPU topology information.
Therefore, also call this function in AMD code path.

Thanks,
Suravee

Suravee Suthikulpanit (2):
  x86/CPU: Modify detect_extended_topology() to return result
  x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB when available

 arch/x86/include/asm/processor.h |  2 +-
 arch/x86/kernel/cpu/amd.c        | 16 ++++++++++++----
 arch/x86/kernel/cpu/topology.c   |  8 ++++----
 3 files changed, 17 insertions(+), 9 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] x86/CPU: Modify detect_extended_topology() to return result
  2018-03-26  8:05 [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration Suravee Suthikulpanit
@ 2018-03-26  8:05 ` Suravee Suthikulpanit
  2018-03-26  8:05 ` [PATCH 2/2] x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB Suravee Suthikulpanit
  2018-03-27  6:48 ` [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration Ingo Molnar
  2 siblings, 0 replies; 7+ messages in thread
From: Suravee Suthikulpanit @ 2018-03-26  8:05 UTC (permalink / raw)
  To: linux-kernel, x86; +Cc: tglx, mingo, hpa, bp, Suravee Suthikulpanit

Current implementation does not communicate whether it can successfully
detect CPUID Fn0x0000000B information. Therefore, modify the function
to return success or error codes. This will be used by subsequent patches.

Reviewed-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 arch/x86/include/asm/processor.h | 2 +-
 arch/x86/kernel/cpu/topology.c   | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index b0ccd48..2a5d5ed 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -193,7 +193,7 @@ extern u32 get_scattered_cpuid_leaf(unsigned int level,
 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
 extern void init_amd_cacheinfo(struct cpuinfo_x86 *c);
 
-extern void detect_extended_topology(struct cpuinfo_x86 *c);
+extern int detect_extended_topology(struct cpuinfo_x86 *c);
 extern void detect_ht(struct cpuinfo_x86 *c);
 
 #ifdef CONFIG_X86_32
diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c
index b099024..81c0afb 100644
--- a/arch/x86/kernel/cpu/topology.c
+++ b/arch/x86/kernel/cpu/topology.c
@@ -27,7 +27,7 @@
  * exists, use it for populating initial_apicid and cpu topology
  * detection.
  */
-void detect_extended_topology(struct cpuinfo_x86 *c)
+int detect_extended_topology(struct cpuinfo_x86 *c)
 {
 #ifdef CONFIG_SMP
 	unsigned int eax, ebx, ecx, edx, sub_index;
@@ -36,7 +36,7 @@ void detect_extended_topology(struct cpuinfo_x86 *c)
 	static bool printed;
 
 	if (c->cpuid_level < 0xb)
-		return;
+		return -1;
 
 	cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx);
 
@@ -44,7 +44,7 @@ void detect_extended_topology(struct cpuinfo_x86 *c)
 	 * check if the cpuid leaf 0xb is actually implemented.
 	 */
 	if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE))
-		return;
+		return -1;
 
 	set_cpu_cap(c, X86_FEATURE_XTOPOLOGY);
 
@@ -95,6 +95,6 @@ void detect_extended_topology(struct cpuinfo_x86 *c)
 			       c->cpu_core_id);
 		printed = 1;
 	}
-	return;
 #endif
+	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB
  2018-03-26  8:05 [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration Suravee Suthikulpanit
  2018-03-26  8:05 ` [PATCH 1/2] x86/CPU: Modify detect_extended_topology() to return result Suravee Suthikulpanit
@ 2018-03-26  8:05 ` Suravee Suthikulpanit
  2018-03-27 12:04   ` Suravee Suthikulpanit
  2018-03-27  6:48 ` [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration Ingo Molnar
  2 siblings, 1 reply; 7+ messages in thread
From: Suravee Suthikulpanit @ 2018-03-26  8:05 UTC (permalink / raw)
  To: linux-kernel, x86; +Cc: tglx, mingo, hpa, bp, Suravee Suthikulpanit

Derive topology information from Extended Topology Enumeration
(CPUID Fn0x0000000B) when the information is available.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 arch/x86/kernel/cpu/amd.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 2c1a9f2..2b40144 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -338,10 +338,18 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
 			c->cu_id = ebx & 0xff;
 
 		if (c->x86 >= 0x17) {
-			c->cpu_core_id = ebx & 0xff;
+			int err = detect_extended_topology(c);
 
-			if (smp_num_siblings > 1)
-				c->x86_max_cores /= smp_num_siblings;
+			if (err) {
+				c->cpu_core_id = ebx & 0xff;
+
+				if (smp_num_siblings > 1)
+					c->x86_max_cores /= smp_num_siblings;
+			} else {
+				int bits = get_count_order(c->x86_max_cores);
+
+				c->x86_coreid_bits = get_count_order(bits);
+			}
 		}
 
 		cacheinfo_amd_init_llc_id(c, cpu, node_id);
@@ -378,7 +386,6 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c)
 	c->phys_proc_id = c->initial_apicid >> bits;
 	/* use socket ID also for last level cache */
 	per_cpu(cpu_llc_id, cpu) = c->phys_proc_id;
-	amd_get_topology(c);
 }
 
 u16 amd_get_nb_id(int cpu)
@@ -823,6 +830,7 @@ static void init_amd(struct cpuinfo_x86 *c)
 	/* Multi core CPU? */
 	if (c->extended_cpuid_level >= 0x80000008) {
 		amd_detect_cmp(c);
+		amd_get_topology(c);
 		srat_detect_node(c);
 	}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration
  2018-03-26  8:05 [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration Suravee Suthikulpanit
  2018-03-26  8:05 ` [PATCH 1/2] x86/CPU: Modify detect_extended_topology() to return result Suravee Suthikulpanit
  2018-03-26  8:05 ` [PATCH 2/2] x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB Suravee Suthikulpanit
@ 2018-03-27  6:48 ` Ingo Molnar
  2018-03-27  6:52   ` David Rientjes
  2 siblings, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2018-03-27  6:48 UTC (permalink / raw)
  To: Suravee Suthikulpanit; +Cc: linux-kernel, x86, tglx, mingo, hpa, bp


* Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> wrote:

> Linux currently provides function detect_extended_topology()
> for parsing CPUID Fn0xB and derive CPU topology information.
> Therefore, also call this function in AMD code path.
> 
> Thanks,
> Suravee
> 
> Suravee Suthikulpanit (2):
>   x86/CPU: Modify detect_extended_topology() to return result
>   x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB when available
> 
>  arch/x86/include/asm/processor.h |  2 +-
>  arch/x86/kernel/cpu/amd.c        | 16 ++++++++++++----
>  arch/x86/kernel/cpu/topology.c   |  8 ++++----
>  3 files changed, 17 insertions(+), 9 deletions(-)

Which tree is this again? The second patch does not apply to -linus or -tip.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration
  2018-03-27  6:48 ` [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration Ingo Molnar
@ 2018-03-27  6:52   ` David Rientjes
  2018-03-27 11:34     ` Suravee Suthikulpanit
  0 siblings, 1 reply; 7+ messages in thread
From: David Rientjes @ 2018-03-27  6:52 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Suravee Suthikulpanit, linux-kernel, x86, tglx, mingo, hpa, bp

On Tue, 27 Mar 2018, Ingo Molnar wrote:

> > Linux currently provides function detect_extended_topology()
> > for parsing CPUID Fn0xB and derive CPU topology information.
> > Therefore, also call this function in AMD code path.
> > 
> > Thanks,
> > Suravee
> > 
> > Suravee Suthikulpanit (2):
> >   x86/CPU: Modify detect_extended_topology() to return result
> >   x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB when available
> > 
> >  arch/x86/include/asm/processor.h |  2 +-
> >  arch/x86/kernel/cpu/amd.c        | 16 ++++++++++++----
> >  arch/x86/kernel/cpu/topology.c   |  8 ++++----
> >  3 files changed, 17 insertions(+), 9 deletions(-)
> 
> Which tree is this again? The second patch does not apply to -linus or -tip.
> 

I was wondering the exact same thing today when this came across.  I found 
it's based on Suravee's other patch series posted today entitled "x86/CPU: 
Update AMD Last-Level-Cache Information".

https://marc.info/?l=linux-kernel&m=152204614503522
1522046116-22578-1-git-send-email-suravee.suthikulpanit@amd.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration
  2018-03-27  6:52   ` David Rientjes
@ 2018-03-27 11:34     ` Suravee Suthikulpanit
  0 siblings, 0 replies; 7+ messages in thread
From: Suravee Suthikulpanit @ 2018-03-27 11:34 UTC (permalink / raw)
  To: David Rientjes, Ingo Molnar; +Cc: linux-kernel, x86, tglx, mingo, hpa, bp

Hi All,

On 3/27/18 1:52 PM, David Rientjes wrote:
> On Tue, 27 Mar 2018, Ingo Molnar wrote:
> 
>>> Linux currently provides function detect_extended_topology()
>>> for parsing CPUID Fn0xB and derive CPU topology information.
>>> Therefore, also call this function in AMD code path.
>>>
>>> Thanks,
>>> Suravee
>>>
>>> Suravee Suthikulpanit (2):
>>>    x86/CPU: Modify detect_extended_topology() to return result
>>>    x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB when available
>>>
>>>   arch/x86/include/asm/processor.h |  2 +-
>>>   arch/x86/kernel/cpu/amd.c        | 16 ++++++++++++----
>>>   arch/x86/kernel/cpu/topology.c   |  8 ++++----
>>>   3 files changed, 17 insertions(+), 9 deletions(-)
>>
>> Which tree is this again? The second patch does not apply to -linus or -tip.
>>
> 
> I was wondering the exact same thing today when this came across.  I found
> it's based on Suravee's other patch series posted today entitled "x86/CPU:
> Update AMD Last-Level-Cache Information".
> 
> https://marc.info/?l=linux-kernel&m=152204614503522
> 1522046116-22578-1-git-send-email-suravee.suthikulpanit@amd.com
> 

Sorry for failing to mention the dependency on the other series here
(https://lkml.org/lkml/2018/3/26/24).

Suravee

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB
  2018-03-26  8:05 ` [PATCH 2/2] x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB Suravee Suthikulpanit
@ 2018-03-27 12:04   ` Suravee Suthikulpanit
  0 siblings, 0 replies; 7+ messages in thread
From: Suravee Suthikulpanit @ 2018-03-27 12:04 UTC (permalink / raw)
  To: linux-kernel, x86; +Cc: tglx, mingo, hpa, bp

Hi All,

On 3/26/18 3:05 PM, Suravee Suthikulpanit wrote:
> Derive topology information from Extended Topology Enumeration
> (CPUID Fn0x0000000B) when the information is available.
> 
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> ---
>   arch/x86/kernel/cpu/amd.c | 16 ++++++++++++----
>   1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
> index 2c1a9f2..2b40144 100644
> --- a/arch/x86/kernel/cpu/amd.c
> +++ b/arch/x86/kernel/cpu/amd.c
> @@ -338,10 +338,18 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
>   			c->cu_id = ebx & 0xff;
>   
>   		if (c->x86 >= 0x17) {
> -			c->cpu_core_id = ebx & 0xff;
> +			int err = detect_extended_topology(c);
>   
> -			if (smp_num_siblings > 1)
> -				c->x86_max_cores /= smp_num_siblings;
> +			if (err) {
> +				c->cpu_core_id = ebx & 0xff;
> +
> +				if (smp_num_siblings > 1)
> +					c->x86_max_cores /= smp_num_siblings;
> +			} else {
> +				int bits = get_count_order(c->x86_max_cores);
> +
> +				c->x86_coreid_bits = get_count_order(bits);
> +			}
>   		}

I made a mistake here in the attempt to clean up the code. I'll send out V2 to fix this.

Thanks,
Suravee

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-03-27 12:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-26  8:05 [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration Suravee Suthikulpanit
2018-03-26  8:05 ` [PATCH 1/2] x86/CPU: Modify detect_extended_topology() to return result Suravee Suthikulpanit
2018-03-26  8:05 ` [PATCH 2/2] x86/CPU/AMD: Derive CPU topology from CPUID Fn0xB Suravee Suthikulpanit
2018-03-27 12:04   ` Suravee Suthikulpanit
2018-03-27  6:48 ` [PATCH 0/2] x86/CPU/AMD: Add support for Extended Topology Enumeration Ingo Molnar
2018-03-27  6:52   ` David Rientjes
2018-03-27 11:34     ` Suravee Suthikulpanit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).