All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang@amd.com>
To: "Borislav Petkov" <bp@suse.de>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Robert Richter" <rric@kernel.org>,
	"Jacob Shin" <jacob.w.shin@gmail.com>,
	"John Stultz" <john.stultz@linaro.org>,
	"Frédéric Weisbecker" <fweisbec@gmail.com>
Cc: <linux-kernel@vger.kernel.org>, <spg_linux_kernel@amd.com>,
	<x86@kernel.org>, Guenter Roeck <linux@roeck-us.net>,
	Andreas Herrmann <herrmann.der.user@googlemail.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>,
	Borislav Petkov <bp@alien8.de>,
	"Fengguang Wu" <fengguang.wu@intel.com>,
	Aaron Lu <aaron.lu@intel.com>, Huang Rui <ray.huang@amd.com>
Subject: [PATCH 2/4] x86/amd: add accessor for number of cores per compute unit
Date: Thu, 7 Jan 2016 10:26:12 +0800	[thread overview]
Message-ID: <1452133574-3407-3-git-send-email-ray.huang@amd.com> (raw)
In-Reply-To: <1452133574-3407-1-git-send-email-ray.huang@amd.com>

Add an accessor function amd_get_cores_per_cu() which returns the
number of cores per compute unit.

In a subsequent patch, we will use this function in both x86 perf and
fam15h driver.

Signed-off-by: Huang Rui <ray.huang@amd.com>
---
 arch/x86/include/asm/processor.h |  1 +
 arch/x86/kernel/cpu/amd.c        | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 6752225..9bf48b2 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -810,6 +810,7 @@ static inline int mpx_disable_management(void)
 
 extern u16 amd_get_nb_id(int cpu);
 extern u32 amd_get_nodes_per_socket(void);
+extern u32 amd_get_cores_per_cu(void);
 
 static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
 {
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 97db1b6..d6e320f 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -27,6 +27,9 @@
  */
 static u32 nodes_per_socket = 1;
 
+/* cores_per_cu: stores the number of cores per compute unit */
+static u32 cores_per_cu = 1;
+
 static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p)
 {
 	u32 gprs[8] = { 0 };
@@ -299,7 +302,6 @@ static int nearby_node(int apicid)
 #ifdef CONFIG_SMP
 static void amd_get_topology(struct cpuinfo_x86 *c)
 {
-	u32 cores_per_cu = 1;
 	u8 node_id;
 	int cpu = smp_processor_id();
 
@@ -313,7 +315,6 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
 		/* get compute unit information */
 		smp_num_siblings = ((ebx >> 8) & 3) + 1;
 		c->compute_unit_id = ebx & 0xff;
-		cores_per_cu += ((ebx >> 8) & 3);
 	} else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {
 		u64 value;
 
@@ -391,6 +392,13 @@ u32 amd_get_nodes_per_socket(void)
 }
 EXPORT_SYMBOL_GPL(amd_get_nodes_per_socket);
 
+/* this function returns the number of cores per compute unit */
+u32 amd_get_cores_per_cu(void)
+{
+	return cores_per_cu;
+}
+EXPORT_SYMBOL_GPL(amd_get_cores_per_cu);
+
 static void srat_detect_node(struct cpuinfo_x86 *c)
 {
 #ifdef CONFIG_NUMA
@@ -523,10 +531,11 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
 		use_mwaitx_delay();
 
 	if (boot_cpu_has(X86_FEATURE_TOPOEXT)) {
-		u32 ecx;
+		u32 eax, ebx, ecx, edx;
 
-		ecx = cpuid_ecx(0x8000001e);
+		cpuid(0x8000001e, &eax, &ebx, &ecx, &edx);
 		nodes_per_socket = ((ecx >> 8) & 7) + 1;
+		cores_per_cu = ((ebx >> 8) & 3) + 1;
 	} else if (boot_cpu_has(X86_FEATURE_NODEID_MSR)) {
 		u64 value;
 
-- 
1.9.1


  parent reply	other threads:[~2016-01-07  2:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-07  2:26 [PATCH 0/4] perf/x86/power: Introduce AMD accumlated power reporting mechanism Huang Rui
2016-01-07  2:26 ` [PATCH 1/4] x86/amd: move nodes_per_socket into bsp_init_amd Huang Rui
2016-01-07  2:26 ` Huang Rui [this message]
2016-01-07  2:26 ` [PATCH 3/4] x86/cpufeature: add AMD Accumulated Power Mechanism feature flag Huang Rui
2016-01-07  2:26 ` [PATCH 4/4] perf/x86/amd/power: Add AMD accumulated power reporting mechanism Huang Rui
2016-01-07  3:14   ` kbuild test robot
2016-01-07  4:40     ` Huang Rui

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=1452133574-3407-3-git-send-email-ray.huang@amd.com \
    --to=ray.huang@amd.com \
    --cc=Aravind.Gopalakrishnan@amd.com \
    --cc=aaron.lu@intel.com \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=fengguang.wu@intel.com \
    --cc=fweisbec@gmail.com \
    --cc=herrmann.der.user@googlemail.com \
    --cc=jacob.w.shin@gmail.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rric@kernel.org \
    --cc=spg_linux_kernel@amd.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tglx@linutronix.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.