Skip to content

Commit 762834e

Browse files
Yasunori GotoLinus Torvalds
authored andcommitted
[PATCH] Unify pxm_to_node() and node_to_pxm()
Consolidate the various arch-specific implementations of pxm_to_node() and node_to_pxm() into a single generic version. Signed-off-by: Yasunori Goto <[email protected]> Cc: "Luck, Tony" <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Dave Hansen <[email protected]> Cc: "Brown, Len" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d6277db commit 762834e

File tree

12 files changed

+102
-71
lines changed

12 files changed

+102
-71
lines changed

arch/i386/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ config ACPI_SRAT
173173
bool
174174
default y
175175
depends on NUMA && (X86_SUMMIT || X86_GENERICARCH)
176+
select ACPI_NUMA
177+
178+
config HAVE_ARCH_PARSE_SRAT
179+
bool
180+
default y
181+
depends on ACPI_SRAT
176182

177183
config X86_SUMMIT_NUMA
178184
bool

arch/i386/kernel/srat.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#define NODE_ARRAY_OFFSET(x) ((x) % 8) /* 8 bits/char */
4040
#define BMAP_SET(bmap, bit) ((bmap)[NODE_ARRAY_INDEX(bit)] |= 1 << NODE_ARRAY_OFFSET(bit))
4141
#define BMAP_TEST(bmap, bit) ((bmap)[NODE_ARRAY_INDEX(bit)] & (1 << NODE_ARRAY_OFFSET(bit)))
42-
#define MAX_PXM_DOMAINS 256 /* 1 byte and no promises about values */
4342
/* bitmap length; _PXM is at most 255 */
4443
#define PXM_BITMAP_LEN (MAX_PXM_DOMAINS / 8)
4544
static u8 pxm_bitmap[PXM_BITMAP_LEN]; /* bitmap of proximity domains */
@@ -213,19 +212,11 @@ static __init void node_read_chunk(int nid, struct node_memory_chunk_s *memory_c
213212
node_end_pfn[nid] = memory_chunk->end_pfn;
214213
}
215214

216-
static u8 pxm_to_nid_map[MAX_PXM_DOMAINS];/* _PXM to logical node ID map */
217-
218-
int pxm_to_node(int pxm)
219-
{
220-
return pxm_to_nid_map[pxm];
221-
}
222-
223215
/* Parse the ACPI Static Resource Affinity Table */
224216
static int __init acpi20_parse_srat(struct acpi_table_srat *sratp)
225217
{
226218
u8 *start, *end, *p;
227219
int i, j, nid;
228-
u8 nid_to_pxm_map[MAX_NUMNODES];/* logical node ID to _PXM map */
229220

230221
start = (u8 *)(&(sratp->reserved) + 1); /* skip header */
231222
p = start;
@@ -235,10 +226,6 @@ static int __init acpi20_parse_srat(struct acpi_table_srat *sratp)
235226
memset(node_memory_chunk, 0, sizeof(node_memory_chunk));
236227
memset(zholes_size, 0, sizeof(zholes_size));
237228

238-
/* -1 in these maps means not available */
239-
memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map));
240-
memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map));
241-
242229
num_memory_chunks = 0;
243230
while (p < end) {
244231
switch (*p) {
@@ -278,17 +265,15 @@ static int __init acpi20_parse_srat(struct acpi_table_srat *sratp)
278265
nodes_clear(node_online_map);
279266
for (i = 0; i < MAX_PXM_DOMAINS; i++) {
280267
if (BMAP_TEST(pxm_bitmap, i)) {
281-
nid = num_online_nodes();
282-
pxm_to_nid_map[i] = nid;
283-
nid_to_pxm_map[nid] = i;
268+
int nid = acpi_map_pxm_to_node(i);
284269
node_set_online(nid);
285270
}
286271
}
287272
BUG_ON(num_online_nodes() == 0);
288273

289274
/* set cnode id in memory chunk structure */
290275
for (i = 0; i < num_memory_chunks; i++)
291-
node_memory_chunk[i].nid = pxm_to_nid_map[node_memory_chunk[i].pxm];
276+
node_memory_chunk[i].nid = pxm_to_node(node_memory_chunk[i].pxm);
292277

293278
printk("pxm bitmap: ");
294279
for (i = 0; i < sizeof(pxm_bitmap); i++) {

arch/ia64/hp/common/sba_iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ sba_map_ioc_to_node(struct ioc *ioc, acpi_handle handle)
19581958
if (pxm < 0)
19591959
return;
19601960

1961-
node = pxm_to_nid_map[pxm];
1961+
node = pxm_to_node(pxm);
19621962

19631963
if (node >= MAX_NUMNODES || !node_online(node))
19641964
return;

arch/ia64/kernel/acpi.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,6 @@ static int __initdata srat_num_cpus; /* number of cpus */
415415
static u32 __devinitdata pxm_flag[PXM_FLAG_LEN];
416416
#define pxm_bit_set(bit) (set_bit(bit,(void *)pxm_flag))
417417
#define pxm_bit_test(bit) (test_bit(bit,(void *)pxm_flag))
418-
/* maps to convert between proximity domain and logical node ID */
419-
int __devinitdata pxm_to_nid_map[MAX_PXM_DOMAINS];
420-
int __initdata nid_to_pxm_map[MAX_NUMNODES];
421418
static struct acpi_table_slit __initdata *slit_table;
422419

423420
static int get_processor_proximity_domain(struct acpi_table_processor_affinity *pa)
@@ -533,22 +530,17 @@ void __init acpi_numa_arch_fixup(void)
533530
* MCD - This can probably be dropped now. No need for pxm ID to node ID
534531
* mapping with sparse node numbering iff MAX_PXM_DOMAINS <= MAX_NUMNODES.
535532
*/
536-
/* calculate total number of nodes in system from PXM bitmap */
537-
memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map));
538-
memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map));
539533
nodes_clear(node_online_map);
540534
for (i = 0; i < MAX_PXM_DOMAINS; i++) {
541535
if (pxm_bit_test(i)) {
542-
int nid = num_online_nodes();
543-
pxm_to_nid_map[i] = nid;
544-
nid_to_pxm_map[nid] = i;
536+
int nid = acpi_map_pxm_to_node(i);
545537
node_set_online(nid);
546538
}
547539
}
548540

549541
/* set logical node id in memory chunk structure */
550542
for (i = 0; i < num_node_memblks; i++)
551-
node_memblk[i].nid = pxm_to_nid_map[node_memblk[i].nid];
543+
node_memblk[i].nid = pxm_to_node(node_memblk[i].nid);
552544

553545
/* assign memory bank numbers for each chunk on each node */
554546
for_each_online_node(i) {
@@ -562,7 +554,7 @@ void __init acpi_numa_arch_fixup(void)
562554

563555
/* set logical node id in cpu structure */
564556
for (i = 0; i < srat_num_cpus; i++)
565-
node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid];
557+
node_cpuid[i].nid = pxm_to_node(node_cpuid[i].nid);
566558

567559
printk(KERN_INFO "Number of logical nodes in system = %d\n",
568560
num_online_nodes());
@@ -575,11 +567,11 @@ void __init acpi_numa_arch_fixup(void)
575567
for (i = 0; i < slit_table->localities; i++) {
576568
if (!pxm_bit_test(i))
577569
continue;
578-
node_from = pxm_to_nid_map[i];
570+
node_from = pxm_to_node(i);
579571
for (j = 0; j < slit_table->localities; j++) {
580572
if (!pxm_bit_test(j))
581573
continue;
582-
node_to = pxm_to_nid_map[j];
574+
node_to = pxm_to_node(j);
583575
node_distance(node_from, node_to) =
584576
slit_table->entry[i * slit_table->localities + j];
585577
}
@@ -785,9 +777,9 @@ int acpi_map_cpu2node(acpi_handle handle, int cpu, long physid)
785777

786778
/*
787779
* Assuming that the container driver would have set the proximity
788-
* domain and would have initialized pxm_to_nid_map[pxm_id] && pxm_flag
780+
* domain and would have initialized pxm_to_node(pxm_id) && pxm_flag
789781
*/
790-
node_cpuid[cpu].nid = (pxm_id < 0) ? 0 : pxm_to_nid_map[pxm_id];
782+
node_cpuid[cpu].nid = (pxm_id < 0) ? 0 : pxm_to_node(pxm_id);
791783

792784
node_cpuid[cpu].phys_id = physid;
793785
#endif
@@ -966,7 +958,7 @@ acpi_map_iosapic(acpi_handle handle, u32 depth, void *context, void **ret)
966958
if (pxm < 0)
967959
return AE_OK;
968960

969-
node = pxm_to_nid_map[pxm];
961+
node = pxm_to_node(pxm);
970962

971963
if (node >= MAX_NUMNODES || !node_online(node) ||
972964
cpus_empty(node_to_cpumask(node)))

arch/ia64/pci/pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pci_acpi_scan_root(struct acpi_device *device, int domain, int bus)
352352
pxm = acpi_get_pxm(controller->acpi_handle);
353353
#ifdef CONFIG_NUMA
354354
if (pxm >= 0)
355-
controller->node = pxm_to_nid_map[pxm];
355+
controller->node = pxm_to_node(pxm);
356356
#endif
357357

358358
acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_window,

arch/ia64/sn/kernel/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int __init pxm_to_nasid(int pxm)
139139
int i;
140140
int nid;
141141

142-
nid = pxm_to_nid_map[pxm];
142+
nid = pxm_to_node(pxm);
143143
for (i = 0; i < num_node_memblks; i++) {
144144
if (node_memblk[i].nid == nid) {
145145
return NASID_GET(node_memblk[i].start_paddr);
@@ -704,7 +704,7 @@ void __init build_cnode_tables(void)
704704
* cnode == node for all C & M bricks.
705705
*/
706706
for_each_online_node(node) {
707-
nasid = pxm_to_nasid(nid_to_pxm_map[node]);
707+
nasid = pxm_to_nasid(node_to_pxm(node));
708708
sn_cnodeid_to_nasid[node] = nasid;
709709
physical_node_map[nasid] = node;
710710
}

arch/x86_64/mm/srat.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,21 @@
3030
static struct acpi_table_slit *acpi_slit;
3131

3232
static nodemask_t nodes_parsed __initdata;
33-
static nodemask_t nodes_found __initdata;
3433
static struct bootnode nodes[MAX_NUMNODES] __initdata;
3534
static struct bootnode nodes_add[MAX_NUMNODES] __initdata;
3635
static int found_add_area __initdata;
3736
int hotadd_percent __initdata = 0;
3837
#ifndef RESERVE_HOTADD
3938
#define hotadd_percent 0 /* Ignore all settings */
4039
#endif
41-
static u8 pxm2node[256] = { [0 ... 255] = 0xff };
4240

4341
/* Too small nodes confuse the VM badly. Usually they result
4442
from BIOS bugs. */
4543
#define NODE_MIN_SIZE (4*1024*1024)
4644

47-
static int node_to_pxm(int n);
48-
49-
int pxm_to_node(int pxm)
50-
{
51-
if ((unsigned)pxm >= 256)
52-
return -1;
53-
/* Extend 0xff to (int)-1 */
54-
return (signed char)pxm2node[pxm];
55-
}
56-
5745
static __init int setup_node(int pxm)
5846
{
59-
unsigned node = pxm2node[pxm];
60-
if (node == 0xff) {
61-
if (nodes_weight(nodes_found) >= MAX_NUMNODES)
62-
return -1;
63-
node = first_unset_node(nodes_found);
64-
node_set(node, nodes_found);
65-
pxm2node[pxm] = node;
66-
}
67-
return pxm2node[pxm];
47+
return acpi_map_pxm_to_node(pxm);
6848
}
6949

7050
static __init int conflicting_nodes(unsigned long start, unsigned long end)
@@ -440,17 +420,6 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end)
440420
return 0;
441421
}
442422

443-
static int node_to_pxm(int n)
444-
{
445-
int i;
446-
if (pxm2node[n] == n)
447-
return n;
448-
for (i = 0; i < 256; i++)
449-
if (pxm2node[i] == n)
450-
return i;
451-
return 0;
452-
}
453-
454423
void __init srat_reserve_add_area(int nodeid)
455424
{
456425
if (found_add_area && nodes_add[nodeid].end) {

drivers/acpi/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ config ACPI_THERMAL
162162
config ACPI_NUMA
163163
bool "NUMA support"
164164
depends on NUMA
165-
depends on (IA64 || X86_64)
165+
depends on (X86 || IA64)
166166
default y if IA64_GENERIC || IA64_SGI_SN2
167167

168168
config ACPI_ASUS

drivers/acpi/numa.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,60 @@
3636
#define _COMPONENT ACPI_NUMA
3737
ACPI_MODULE_NAME("numa")
3838

39+
static nodemask_t nodes_found_map = NODE_MASK_NONE;
40+
#define PXM_INVAL -1
41+
#define NID_INVAL -1
42+
43+
/* maps to convert between proximity domain and logical node ID */
44+
int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS]
45+
= { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL };
46+
int __cpuinitdata node_to_pxm_map[MAX_NUMNODES]
47+
= { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
48+
3949
extern int __init acpi_table_parse_madt_family(enum acpi_table_id id,
4050
unsigned long madt_size,
4151
int entry_id,
4252
acpi_madt_entry_handler handler,
4353
unsigned int max_entries);
4454

55+
int __cpuinit pxm_to_node(int pxm)
56+
{
57+
if (pxm < 0)
58+
return NID_INVAL;
59+
return pxm_to_node_map[pxm];
60+
}
61+
62+
int __cpuinit node_to_pxm(int node)
63+
{
64+
if (node < 0)
65+
return PXM_INVAL;
66+
return node_to_pxm_map[node];
67+
}
68+
69+
int __cpuinit acpi_map_pxm_to_node(int pxm)
70+
{
71+
int node = pxm_to_node_map[pxm];
72+
73+
if (node < 0){
74+
if (nodes_weight(nodes_found_map) >= MAX_NUMNODES)
75+
return NID_INVAL;
76+
node = first_unset_node(nodes_found_map);
77+
pxm_to_node_map[pxm] = node;
78+
node_to_pxm_map[node] = pxm;
79+
node_set(node, nodes_found_map);
80+
}
81+
82+
return node;
83+
}
84+
85+
void __cpuinit acpi_unmap_pxm_to_node(int node)
86+
{
87+
int pxm = node_to_pxm_map[node];
88+
pxm_to_node_map[pxm] = NID_INVAL;
89+
node_to_pxm_map[node] = PXM_INVAL;
90+
node_clear(node, nodes_found_map);
91+
}
92+
4593
void __init acpi_table_print_srat_entry(acpi_table_entry_header * header)
4694
{
4795

include/acpi/acpi_numa.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef __ACPI_NUMA_H
2+
#define __ACPI_NUMA_H
3+
4+
#ifdef CONFIG_ACPI_NUMA
5+
#include <linux/kernel.h>
6+
7+
/* Proximity bitmap length */
8+
#if MAX_NUMNODES > 256
9+
#define MAX_PXM_DOMAINS MAX_NUMNODES
10+
#else
11+
#define MAX_PXM_DOMAINS (256) /* Old pxm spec is defined 8 bit */
12+
#endif
13+
14+
extern int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS];
15+
extern int __cpuinitdata node_to_pxm_map[MAX_NUMNODES];
16+
17+
extern int __cpuinit pxm_to_node(int);
18+
extern int __cpuinit node_to_pxm(int);
19+
extern int __cpuinit acpi_map_pxm_to_node(int);
20+
extern void __cpuinit acpi_unmap_pxm_to_node(int);
21+
22+
#endif /* CONFIG_ACPI_NUMA */
23+
#endif /* __ACP_NUMA_H */

include/asm-x86_64/numa.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ struct bootnode {
88
};
99

1010
extern int compute_hash_shift(struct bootnode *nodes, int numnodes);
11-
extern int pxm_to_node(int nid);
1211

1312
#define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))
1413

include/linux/acpi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <acpi/acpi.h>
3838
#include <acpi/acpi_bus.h>
3939
#include <acpi/acpi_drivers.h>
40+
#include <acpi/acpi_numa.h>
4041
#include <asm/acpi.h>
4142

4243

@@ -407,10 +408,18 @@ void acpi_table_print_madt_entry (acpi_table_entry_header *madt);
407408
void acpi_table_print_srat_entry (acpi_table_entry_header *srat);
408409

409410
/* the following four functions are architecture-dependent */
411+
#ifdef CONFIG_HAVE_ARCH_PARSE_SRAT
412+
#define NR_NODE_MEMBLKS MAX_NUMNODES
413+
#define acpi_numa_slit_init(slit) do {} while (0)
414+
#define acpi_numa_processor_affinity_init(pa) do {} while (0)
415+
#define acpi_numa_memory_affinity_init(ma) do {} while (0)
416+
#define acpi_numa_arch_fixup() do {} while (0)
417+
#else
410418
void acpi_numa_slit_init (struct acpi_table_slit *slit);
411419
void acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa);
412420
void acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma);
413421
void acpi_numa_arch_fixup(void);
422+
#endif
414423

415424
#ifdef CONFIG_ACPI_HOTPLUG_CPU
416425
/* Arch dependent functions for cpu hotplug support */

0 commit comments

Comments
 (0)