public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Mike Travis <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, travis@sgi.com, hpa@zytor.com,
	estabrook@sgi.com, gfk@sgi.com, abanman@sgi.com,
	peterz@infradead.org, torvalds@linux-foundation.org,
	dvlasenk@redhat.com, tglx@linutronix.de, rja@sgi.com,
	bp@alien8.de, sivanich@sgi.com, akpm@linux-foundation.org,
	nzimmer@sgi.com, mingo@kernel.org, brgerst@gmail.com,
	luto@amacapital.net, len.brown@intel.com
Subject: [tip:x86/platform] x86/platform/UV: Build GAM reference tables
Date: Wed, 4 May 2016 00:21:32 -0700	[thread overview]
Message-ID: <tip-6e27b91cf46834391c59062d3f26d277cc299f4b@git.kernel.org> (raw)
In-Reply-To: <20160429215405.673495324@asylum.americas.sgi.com>

Commit-ID:  6e27b91cf46834391c59062d3f26d277cc299f4b
Gitweb:     http://git.kernel.org/tip/6e27b91cf46834391c59062d3f26d277cc299f4b
Author:     Mike Travis <travis@sgi.com>
AuthorDate: Fri, 29 Apr 2016 16:54:20 -0500
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 4 May 2016 08:48:50 +0200

x86/platform/UV: Build GAM reference tables

An aspect of the UV4 system architecture changes involve changing the
way sockets, nodes, and pnodes are translated between one another.
Decode the information from the BIOS provided EFI system table to build
the needed conversion tables.

Tested-by: Dimitri Sivanich <sivanich@sgi.com>
Tested-by: John Estabrook <estabrook@sgi.com>
Tested-by: Gary Kroening <gfk@sgi.com>
Tested-by: Nathan Zimmer <nzimmer@sgi.com>
Signed-off-by: Mike Travis <travis@sgi.com>
Reviewed-by: Dimitri Sivanich <sivanich@sgi.com>
Cc: Andrew Banman <abanman@sgi.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Len Brown <len.brown@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <rja@sgi.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20160429215405.673495324@asylum.americas.sgi.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/uv/uv_hub.h   |  18 ++++-
 arch/x86/kernel/apic/x2apic_uv_x.c | 139 +++++++++++++++++++++++++++++++++++++
 2 files changed, 155 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/uv/uv_hub.h b/arch/x86/include/asm/uv/uv_hub.h
index 1978e4b..6900161 100644
--- a/arch/x86/include/asm/uv/uv_hub.h
+++ b/arch/x86/include/asm/uv/uv_hub.h
@@ -149,6 +149,9 @@ struct uv_hub_info_s {
 	unsigned long		global_mmr_base;
 	unsigned long		global_mmr_shift;
 	unsigned long		gpa_mask;
+	unsigned short		*socket_to_node;
+	unsigned short		*socket_to_pnode;
+	unsigned short		*pnode_to_socket;
 	unsigned short		min_socket;
 	unsigned short		min_pnode;
 	unsigned char		hub_revision;
@@ -481,10 +484,21 @@ static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
 	return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset);
 }
 
-/* Extract a PNODE from an APICID (full apicid, not processor subset) */
+/* Convert socket to node */
+static inline int uv_socket_to_node(int socket)
+{
+	unsigned short *s2nid = uv_hub_info->socket_to_node;
+
+	return s2nid ? s2nid[socket - uv_hub_info->min_socket] : socket;
+}
+
+/* Extract/Convert a PNODE from an APICID (full apicid, not processor subset) */
 static inline int uv_apicid_to_pnode(int apicid)
 {
-	return (apicid >> uv_hub_info->apic_pnode_shift);
+	int pnode = apicid >> uv_hub_info->apic_pnode_shift;
+	unsigned short *s2pn = uv_hub_info->socket_to_pnode;
+
+	return s2pn ? s2pn[pnode - uv_hub_info->min_socket] : pnode;
 }
 
 /* Convert an apicid to the socket number on the blade */
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index 128f47e..259c3dd 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -307,6 +307,9 @@ static __initdata unsigned short _min_socket, _max_socket;
 static __initdata unsigned short _min_pnode, _max_pnode, _gr_table_len;
 static __initdata struct uv_gam_range_entry *uv_gre_table;
 static __initdata struct uv_gam_parameters *uv_gp_table;
+static __initdata unsigned short *_socket_to_node;
+static __initdata unsigned short *_socket_to_pnode;
+static __initdata unsigned short *_pnode_to_socket;
 #define	SOCK_EMPTY	((unsigned short)~0)
 
 extern int uv_hub_info_version(void)
@@ -985,6 +988,10 @@ void __init uv_init_hub_info(struct uv_hub_info_s *hub_info)
 	hub_info->hub_revision = uv_hub_info->hub_revision;
 	hub_info->pnode_mask = uv_cpuid.pnode_mask;
 	hub_info->min_pnode = _min_pnode;
+	hub_info->min_socket = _min_socket;
+	hub_info->pnode_to_socket = _pnode_to_socket;
+	hub_info->socket_to_node = _socket_to_node;
+	hub_info->socket_to_pnode = _socket_to_pnode;
 	hub_info->gpa_mask = mn.m_val ?
 		(1UL << (mn.m_val + mn.n_val)) - 1 :
 		(1UL << uv_cpuid.gpa_shift) - 1;
@@ -1171,6 +1178,137 @@ static __init void boot_init_possible_blades(struct uv_hub_info_s *hub_info)
 	}
 }
 
+static void __init build_socket_tables(void)
+{
+	struct uv_gam_range_entry *gre = uv_gre_table;
+	int num, nump;
+	int cpu, i, lnid;
+	int minsock = _min_socket;
+	int maxsock = _max_socket;
+	int minpnode = _min_pnode;
+	int maxpnode = _max_pnode;
+	size_t bytes;
+
+	if (!gre) {
+		if (is_uv1_hub() || is_uv2_hub() || is_uv3_hub()) {
+			pr_info("UV: No UVsystab socket table, ignoring\n");
+			return;		/* not required */
+		}
+		pr_crit(
+		"UV: Error: UVsystab address translations not available!\n");
+		BUG();
+	}
+
+	/* build socket id -> node id, pnode */
+	num = maxsock - minsock + 1;
+	bytes = num * sizeof(_socket_to_node[0]);
+	_socket_to_node = kmalloc(bytes, GFP_KERNEL);
+	_socket_to_pnode = kmalloc(bytes, GFP_KERNEL);
+
+	nump = maxpnode - minpnode + 1;
+	bytes = nump * sizeof(_pnode_to_socket[0]);
+	_pnode_to_socket = kmalloc(bytes, GFP_KERNEL);
+	BUG_ON(!_socket_to_node || !_socket_to_pnode || !_pnode_to_socket);
+
+	for (i = 0; i < num; i++)
+		_socket_to_node[i] = _socket_to_pnode[i] = SOCK_EMPTY;
+
+	for (i = 0; i < nump; i++)
+		_pnode_to_socket[i] = SOCK_EMPTY;
+
+	/* fill in pnode/node/addr conversion list values */
+	pr_info("UV: GAM Building socket/pnode/pxm conversion tables\n");
+	for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
+		if (gre->type == UV_GAM_RANGE_TYPE_HOLE)
+			continue;
+		i = gre->sockid - minsock;
+		if (_socket_to_pnode[i] != SOCK_EMPTY)
+			continue;	/* duplicate */
+		_socket_to_pnode[i] = gre->pnode;
+		_socket_to_node[i] = gre->pxm;
+
+		i = gre->pnode - minpnode;
+		_pnode_to_socket[i] = gre->sockid;
+
+		pr_info(
+		"UV: sid:%02x type:%d nasid:%04x pn:%02x pxm:%2d pn2s:%2x\n",
+			gre->sockid, gre->type, gre->nasid,
+			_socket_to_pnode[gre->sockid - minsock],
+			_socket_to_node[gre->sockid - minsock],
+			_pnode_to_socket[gre->pnode - minpnode]);
+	}
+
+	/* check socket -> node values */
+	lnid = -1;
+	for_each_present_cpu(cpu) {
+		int nid = cpu_to_node(cpu);
+		int apicid, sockid;
+
+		if (lnid == nid)
+			continue;
+		lnid = nid;
+		apicid = per_cpu(x86_cpu_to_apicid, cpu);
+		sockid = apicid >> uv_cpuid.socketid_shift;
+		i = sockid - minsock;
+
+		if (nid != _socket_to_node[i]) {
+			pr_warn(
+			"UV: %02x: type:%d socket:%02x PXM:%02x != node:%2d\n",
+				i, sockid, gre->type, _socket_to_node[i], nid);
+			_socket_to_node[i] = nid;
+		}
+	}
+
+	/* Setup physical blade to pnode translation from GAM Range Table */
+	bytes = num_possible_nodes() * sizeof(_node_to_pnode[0]);
+	_node_to_pnode = kmalloc(bytes, GFP_KERNEL);
+	BUG_ON(!_node_to_pnode);
+
+	for (lnid = 0; lnid < num_possible_nodes(); lnid++) {
+		unsigned short sockid;
+
+		for (sockid = minsock; sockid <= maxsock; sockid++) {
+			if (lnid == _socket_to_node[sockid - minsock]) {
+				_node_to_pnode[lnid] =
+					_socket_to_pnode[sockid - minsock];
+				break;
+			}
+		}
+		if (sockid > maxsock) {
+			pr_err("UV: socket for node %d not found!\n", lnid);
+			BUG();
+		}
+	}
+
+	/*
+	 * If socket id == pnode or socket id == node for all nodes,
+	 *   system runs faster by removing corresponding conversion table.
+	 */
+	pr_info("UV: Checking socket->node/pnode for identity maps\n");
+	if (minsock == 0) {
+		for (i = 0; i < num; i++)
+			if (_socket_to_node[i] == SOCK_EMPTY ||
+				i != _socket_to_node[i])
+				break;
+		if (i >= num) {
+			kfree(_socket_to_node);
+			_socket_to_node = NULL;
+			pr_info("UV: 1:1 socket_to_node table removed\n");
+		}
+	}
+	if (minsock == minpnode) {
+		for (i = 0; i < num; i++)
+			if (_socket_to_pnode[i] != SOCK_EMPTY &&
+				_socket_to_pnode[i] != i + minpnode)
+				break;
+		if (i >= num) {
+			kfree(_socket_to_pnode);
+			_socket_to_pnode = NULL;
+			pr_info("UV: 1:1 socket_to_pnode table removed\n");
+		}
+	}
+}
+
 void __init uv_system_init(void)
 {
 	struct uv_hub_info_s hub_info = {0};
@@ -1193,6 +1331,7 @@ void __init uv_system_init(void)
 
 	uv_bios_init();			/* get uv_systab for decoding */
 	decode_uv_systab();
+	build_socket_tables();
 	uv_init_hub_info(&hub_info);
 	uv_possible_blades = num_possible_nodes();
 	if (!_node_to_pnode)

  reply	other threads:[~2016-05-04  7:22 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29 21:54 [PATCH 00/21] X86_64, UV: Update kernel for SGI UV4 support Mike Travis
2016-04-29 21:54 ` [PATCH 01/21] X86_64, UV: Add Initial UV4 definitions Mike Travis
2016-05-04  7:15   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 02/21] X86_64, UV: Add UV Architecture Defines Mike Travis
2016-05-04  7:15   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 03/21] X86_64, UV: Add UV4 Specific Defines Mike Travis
2016-05-04  7:16   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 04/21] X86_64, UV: Add UV MMR Illegal Access Function Mike Travis
2016-05-04  7:16   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 05/21] X86_64, UV: Prep for UV4 MMR updates Mike Travis
2016-05-04  7:16   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 06/21] X86_64, UV: Add UV4 Specific MMR definitions Mike Travis
2016-05-04  7:17   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 07/21] X86_64, UV: Disable Obsolete APIC ID fixup code used only on UV1 Mike Travis
2016-05-03  7:35   ` Ingo Molnar
2016-05-03 14:43     ` Mike Travis
2016-04-29 21:54 ` [PATCH 08/21] X86_64, UV: Clean up redunduncies after merge of UV4 MMR definitions Mike Travis
2016-05-04  7:17   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 09/21] X86_64, UV: Update MMIOH setup function to work for both UV3 and UV4 Mike Travis
2016-05-04  7:18   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 10/21] X86_64, UV: Create per cpu info structs to replace per hub info structs Mike Travis
2016-05-04  7:18   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 11/21] X86_64, UV: Move scir info to the per cpu info struct Mike Travis
2016-05-04  7:18   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 12/21] X86_64, UV: Move blade local processor ID " Mike Travis
2016-05-04  7:19   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 13/21] X86_64, UV: Allocate common per node hub info structs on local node Mike Travis
2016-05-04  7:19   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 14/21] X86_64, UV: Fold blade info into per node hub info structs Mike Travis
2016-05-04  7:19   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 15/21] X86_64, UV: Add UV4 addressing discovery function Mike Travis
2016-05-04  7:20   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 16/21] X86_64, UV: Add obtaining GAM Range Table from UV BIOS Mike Travis
2016-05-04  7:20   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 17/21] X86_64, UV: Support UV4 socket address changes Mike Travis
2016-05-04  7:21   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 18/21] X86_64, UV: Build GAM reference tables Mike Travis
2016-05-04  7:21   ` tip-bot for Mike Travis [this message]
2016-04-29 21:54 ` [PATCH 19/21] X86_64, UV: Update physical address conversions for UV4 Mike Travis
2016-05-04  7:21   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Mike Travis
2016-04-29 21:54 ` [PATCH 20/21] X86_64, UV: Remove Obsolete GRU MMR address translation Mike Travis
2016-05-04  7:22   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Dimitri Sivanich
2016-04-29 21:54 ` [PATCH 21/21] X86_64, UV: Fix incorrect nodes and pnodes for cpuless and memoryless nodes Mike Travis
2016-05-04  7:22   ` [tip:x86/platform] x86/platform/UV: " tip-bot for Dimitri Sivanich

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=tip-6e27b91cf46834391c59062d3f26d277cc299f4b@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=abanman@sgi.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=estabrook@sgi.com \
    --cc=gfk@sgi.com \
    --cc=hpa@zytor.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=nzimmer@sgi.com \
    --cc=peterz@infradead.org \
    --cc=rja@sgi.com \
    --cc=sivanich@sgi.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=travis@sgi.com \
    /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