Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6b78cb54 authored by Tejun Heo's avatar Tejun Heo
Browse files

x86-64, NUMA: Unify emulated apicid -> node mapping transformation



NUMA emulation changes node mappings and thus apicid -> node mapping
needs to be updated accordingly.  srat_64 and amdtopology_64 did this
separately; however, all the necessary information is the mapping from
emulated nodes to physical nodes which is available in
emu_nid_to_phys[].

Implement common __apicid_to_node[] transformation in numa_emulation()
and drop duplicate implementations.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Shaohui Zheng <shaohui.zheng@intel.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: H. Peter Anvin <hpa@linux.intel.com>
parent 1cca5340
Loading
Loading
Loading
Loading
+0 −9
Original line number Original line Diff line number Diff line
@@ -196,10 +196,6 @@ int __init amd_numa_init(void)
}
}


#ifdef CONFIG_NUMA_EMU
#ifdef CONFIG_NUMA_EMU
static s16 fake_apicid_to_node[MAX_LOCAL_APIC] __initdata = {
	[0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
};

/*
/*
 * For NUMA emulation, fake proximity domain (_PXM) to node id mappings must be
 * For NUMA emulation, fake proximity domain (_PXM) to node id mappings must be
 * setup to represent the physical topology but reflect the emulated
 * setup to represent the physical topology but reflect the emulated
@@ -224,20 +220,15 @@ void __init amd_fake_nodes(const struct bootnode *nodes, int nr_nodes)
	for (i = 0; i < nr_nodes; i++) {
	for (i = 0; i < nr_nodes; i++) {
		int index;
		int index;
		int nid;
		int nid;
		int j;


		nid = find_node_by_addr(nodes[i].start);
		nid = find_node_by_addr(nodes[i].start);
		if (nid == NUMA_NO_NODE)
		if (nid == NUMA_NO_NODE)
			continue;
			continue;


		index = nodeids[nid] << bits;
		index = nodeids[nid] << bits;
		if (fake_apicid_to_node[index + apicid_base] == NUMA_NO_NODE)
			for (j = apicid_base; j < cores + apicid_base; j++)
				fake_apicid_to_node[index + j] = i;
#ifdef CONFIG_ACPI_NUMA
#ifdef CONFIG_ACPI_NUMA
		__acpi_map_pxm_to_node(nid, i);
		__acpi_map_pxm_to_node(nid, i);
#endif
#endif
	}
	}
	memcpy(__apicid_to_node, fake_apicid_to_node, sizeof(__apicid_to_node));
}
}
#endif /* CONFIG_NUMA_EMU */
#endif /* CONFIG_NUMA_EMU */
+15 −1
Original line number Original line Diff line number Diff line
@@ -858,7 +858,7 @@ static bool __init numa_emulation(int acpi, int amd)
	static struct numa_meminfo ei __initdata;
	static struct numa_meminfo ei __initdata;
	static struct numa_meminfo pi __initdata;
	static struct numa_meminfo pi __initdata;
	const u64 max_addr = max_pfn << PAGE_SHIFT;
	const u64 max_addr = max_pfn << PAGE_SHIFT;
	int i, ret;
	int i, j, ret;


	memset(&ei, 0, sizeof(ei));
	memset(&ei, 0, sizeof(ei));
	pi = numa_meminfo;
	pi = numa_meminfo;
@@ -894,6 +894,20 @@ static bool __init numa_emulation(int acpi, int amd)
	/* commit */
	/* commit */
	numa_meminfo = ei;
	numa_meminfo = ei;


	/*
	 * Transform __apicid_to_node table to use emulated nids by
	 * reverse-mapping phys_nid.  The maps should always exist but fall
	 * back to zero just in case.
	 */
	for (i = 0; i < ARRAY_SIZE(__apicid_to_node); i++) {
		if (__apicid_to_node[i] == NUMA_NO_NODE)
			continue;
		for (j = 0; j < ARRAY_SIZE(emu_nid_to_phys); j++)
			if (__apicid_to_node[i] == emu_nid_to_phys[j])
				break;
		__apicid_to_node[i] = j < ARRAY_SIZE(emu_nid_to_phys) ? j : 0;
	}

	/* make sure all emulated nodes are mapped to a physical node */
	/* make sure all emulated nodes are mapped to a physical node */
	for (i = 0; i < ARRAY_SIZE(emu_nid_to_phys); i++)
	for (i = 0; i < ARRAY_SIZE(emu_nid_to_phys); i++)
		if (emu_nid_to_phys[i] == NUMA_NO_NODE)
		if (emu_nid_to_phys[i] == NUMA_NO_NODE)
+1 −23
Original line number Original line Diff line number Diff line
@@ -265,9 +265,6 @@ int __init x86_acpi_numa_init(void)
static int fake_node_to_pxm_map[MAX_NUMNODES] __initdata = {
static int fake_node_to_pxm_map[MAX_NUMNODES] __initdata = {
	[0 ... MAX_NUMNODES-1] = PXM_INVAL
	[0 ... MAX_NUMNODES-1] = PXM_INVAL
};
};
static s16 fake_apicid_to_node[MAX_LOCAL_APIC] __initdata = {
	[0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
};


/*
/*
 * In NUMA emulation, we need to setup proximity domain (_PXM) to node ID
 * In NUMA emulation, we need to setup proximity domain (_PXM) to node ID
@@ -279,7 +276,7 @@ static s16 fake_apicid_to_node[MAX_LOCAL_APIC] __initdata = {
 */
 */
void __init acpi_fake_nodes(const struct bootnode *fake_nodes, int num_nodes)
void __init acpi_fake_nodes(const struct bootnode *fake_nodes, int num_nodes)
{
{
	int i, j;
	int i;


	for (i = 0; i < num_nodes; i++) {
	for (i = 0; i < num_nodes; i++) {
		int nid, pxm;
		int nid, pxm;
@@ -291,29 +288,10 @@ void __init acpi_fake_nodes(const struct bootnode *fake_nodes, int num_nodes)
		if (pxm == PXM_INVAL)
		if (pxm == PXM_INVAL)
			continue;
			continue;
		fake_node_to_pxm_map[i] = pxm;
		fake_node_to_pxm_map[i] = pxm;
		/*
		 * For each apicid_to_node mapping that exists for this real
		 * node, it must now point to the fake node ID.
		 */
		for (j = 0; j < MAX_LOCAL_APIC; j++)
			if (__apicid_to_node[j] == nid &&
			    fake_apicid_to_node[j] == NUMA_NO_NODE)
				fake_apicid_to_node[j] = i;
	}
	}


	/*
	 * If there are apicid-to-node mappings for physical nodes that do not
	 * have a corresponding emulated node, it should default to a guaranteed
	 * value.
	 */
	for (i = 0; i < MAX_LOCAL_APIC; i++)
		if (__apicid_to_node[i] != NUMA_NO_NODE &&
		    fake_apicid_to_node[i] == NUMA_NO_NODE)
			fake_apicid_to_node[i] = 0;

	for (i = 0; i < num_nodes; i++)
	for (i = 0; i < num_nodes; i++)
		__acpi_map_pxm_to_node(fake_node_to_pxm_map[i], i);
		__acpi_map_pxm_to_node(fake_node_to_pxm_map[i], i);
	memcpy(__apicid_to_node, fake_apicid_to_node, sizeof(__apicid_to_node));


	for (i = 0; i < num_nodes; i++)
	for (i = 0; i < num_nodes; i++)
		if (fake_nodes[i].start != fake_nodes[i].end)
		if (fake_nodes[i].start != fake_nodes[i].end)