Skip to content

Commit e16b471

Browse files
chenhuacaiAirFortressIlikara
authored andcommitted
LoongArch: Introduce the numa_memblks conversion
Commit 8748270 ("mm: introduce numa_memblks") has moved numa_memblks from x86 to the generic code, but LoongArch was left out of this conversion. This patch introduces the generic numa_memblks for LoongArch. In detail: 1. Enable NUMA_MEMBLKS (but disable NUMA_EMU) in Kconfig; 2. Use generic definition for numa_memblk and numa_meminfo; 3. Use generic implementation for numa_add_memblk() and its friends; 4. Use generic implementation for numa_set_distance() and its friends; 5. Use generic implementation for memory_add_physaddr_to_nid() and its friends. Note: Disable NUMA_EMU because it needs more efforts and no obvious demand now. Tested-by: Binbin Zhou <[email protected]> Signed-off-by: Yuquan Wang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 6b12743 commit e16b471

File tree

8 files changed

+16
-139
lines changed

8 files changed

+16
-139
lines changed

arch/loongarch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ config LOONGARCH
178178
select MODULES_USE_ELF_RELA if MODULES
179179
select NEED_PER_CPU_EMBED_FIRST_CHUNK
180180
select NEED_PER_CPU_PAGE_FIRST_CHUNK
181+
select NUMA_MEMBLKS if NUMA
181182
select OF
182183
select OF_EARLY_FLATTREE
183184
select PCI

arch/loongarch/include/asm/numa.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,6 @@ extern int numa_off;
2222
extern s16 __cpuid_to_node[CONFIG_NR_CPUS];
2323
extern nodemask_t numa_nodes_parsed __initdata;
2424

25-
struct numa_memblk {
26-
u64 start;
27-
u64 end;
28-
int nid;
29-
};
30-
31-
#define NR_NODE_MEMBLKS (MAX_NUMNODES*2)
32-
struct numa_meminfo {
33-
int nr_blks;
34-
struct numa_memblk blk[NR_NODE_MEMBLKS];
35-
};
36-
37-
extern int __init numa_add_memblk(int nodeid, u64 start, u64 end);
38-
3925
extern void __init early_numa_add_cpu(int cpuid, s16 node);
4026
extern void numa_add_cpu(unsigned int cpu);
4127
extern void numa_remove_cpu(unsigned int cpu);

arch/loongarch/include/asm/sparsemem.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
#define VMEMMAP_SIZE 0 /* 1, For FLATMEM; 2, For SPARSEMEM without VMEMMAP. */
2222
#endif
2323

24-
#ifdef CONFIG_MEMORY_HOTPLUG
25-
int memory_add_physaddr_to_nid(u64 addr);
26-
#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
27-
#endif
28-
2924
#define INIT_MEMBLOCK_RESERVED_REGIONS (INIT_MEMBLOCK_REGIONS + NR_CPUS)
3025

3126
#endif /* _LOONGARCH_SPARSEMEM_H */

arch/loongarch/include/asm/topology.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ extern int pcibus_to_node(struct pci_bus *);
2727

2828
#define cpumask_of_pcibus(bus) (cpu_online_mask)
2929

30-
extern unsigned char node_distances[MAX_NUMNODES][MAX_NUMNODES];
31-
32-
void numa_set_distance(int from, int to, int distance);
33-
34-
#define node_distance(from, to) (node_distances[(from)][(to)])
30+
int __node_distance(int from, int to);
31+
#define node_distance(from, to) __node_distance(from, to)
3532

3633
#else
3734
#define pcibus_to_node(bus) 0

arch/loongarch/kernel/acpi.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,6 @@ void __init acpi_boot_table_init(void)
244244

245245
#ifdef CONFIG_ACPI_NUMA
246246

247-
void __init numa_set_distance(int from, int to, int distance)
248-
{
249-
if ((u8)distance != distance || (from == to && distance != LOCAL_DISTANCE)) {
250-
pr_warn_once("Warning: invalid distance parameter, from=%d to=%d distance=%d\n",
251-
from, to, distance);
252-
return;
253-
}
254-
255-
node_distances[from][to] = distance;
256-
}
257-
258247
/* Callback for Proximity Domain -> CPUID mapping */
259248
void __init
260249
acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)

arch/loongarch/kernel/numa.c

Lines changed: 12 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/mmzone.h>
1212
#include <linux/export.h>
1313
#include <linux/nodemask.h>
14+
#include <linux/numa_memblks.h>
1415
#include <linux/swap.h>
1516
#include <linux/memblock.h>
1617
#include <linux/pfn.h>
@@ -29,10 +30,6 @@
2930
#include "legacy_boot.h"
3031

3132
int numa_off;
32-
unsigned char node_distances[MAX_NUMNODES][MAX_NUMNODES];
33-
EXPORT_SYMBOL(node_distances);
34-
35-
static struct numa_meminfo numa_meminfo;
3633
cpumask_t cpus_on_node[MAX_NUMNODES];
3734
cpumask_t phys_cpus_on_node[MAX_NUMNODES];
3835
EXPORT_SYMBOL(cpus_on_node);
@@ -45,8 +42,6 @@ s16 __cpuid_to_node[CONFIG_NR_CPUS] = {
4542
};
4643
EXPORT_SYMBOL(__cpuid_to_node);
4744

48-
nodemask_t numa_nodes_parsed __initdata;
49-
5045
#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
5146
unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
5247
EXPORT_SYMBOL(__per_cpu_offset);
@@ -147,48 +142,6 @@ void numa_remove_cpu(unsigned int cpu)
147142
cpumask_clear_cpu(cpu, &cpus_on_node[nid]);
148143
}
149144

150-
static int __init numa_add_memblk_to(int nid, u64 start, u64 end,
151-
struct numa_meminfo *mi)
152-
{
153-
/* ignore zero length blks */
154-
if (start == end)
155-
return 0;
156-
157-
/* whine about and ignore invalid blks */
158-
if (start > end || nid < 0 || nid >= MAX_NUMNODES) {
159-
pr_warn("NUMA: Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
160-
nid, start, end - 1);
161-
return 0;
162-
}
163-
164-
if (mi->nr_blks >= NR_NODE_MEMBLKS) {
165-
pr_err("NUMA: too many memblk ranges\n");
166-
return -EINVAL;
167-
}
168-
169-
mi->blk[mi->nr_blks].start = PFN_ALIGN(start);
170-
mi->blk[mi->nr_blks].end = PFN_ALIGN(end - PAGE_SIZE + 1);
171-
mi->blk[mi->nr_blks].nid = nid;
172-
mi->nr_blks++;
173-
return 0;
174-
}
175-
176-
/**
177-
* numa_add_memblk - Add one numa_memblk to numa_meminfo
178-
* @nid: NUMA node ID of the new memblk
179-
* @start: Start address of the new memblk
180-
* @end: End address of the new memblk
181-
*
182-
* Add a new memblk to the default numa_meminfo.
183-
*
184-
* RETURNS:
185-
* 0 on success, -errno on failure.
186-
*/
187-
int __init numa_add_memblk(int nid, u64 start, u64 end)
188-
{
189-
return numa_add_memblk_to(nid, start, end, &numa_meminfo);
190-
}
191-
192145
static void __init node_mem_init(unsigned int node)
193146
{
194147
unsigned long start_pfn, end_pfn;
@@ -207,18 +160,6 @@ static void __init node_mem_init(unsigned int node)
207160

208161
#ifdef CONFIG_ACPI_NUMA
209162

210-
static void __init add_node_intersection(u32 node, u64 start, u64 size, u32 type)
211-
{
212-
static unsigned long num_physpages;
213-
214-
num_physpages += (size >> PAGE_SHIFT);
215-
pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx Bytes\n",
216-
node, type, start, size);
217-
pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n",
218-
start >> PAGE_SHIFT, (start + size) >> PAGE_SHIFT, num_physpages);
219-
memblock_set_node(start, size, &memblock.memory, node);
220-
}
221-
222163
/*
223164
* add_numamem_region
224165
*
@@ -230,28 +171,21 @@ static void __init add_node_intersection(u32 node, u64 start, u64 size, u32 type
230171
*/
231172
static void __init add_numamem_region(u64 start, u64 end, u32 type)
232173
{
233-
u32 i;
234-
u64 ofs = start;
174+
u32 node = pa_to_nid(start);
175+
u64 size = end - start;
176+
static unsigned long num_physpages;
235177

236178
if (start >= end) {
237179
pr_debug("Invalid region: %016llx-%016llx\n", start, end);
238180
return;
239181
}
240182

241-
for (i = 0; i < numa_meminfo.nr_blks; i++) {
242-
struct numa_memblk *mb = &numa_meminfo.blk[i];
243-
244-
if (ofs > mb->end)
245-
continue;
246-
247-
if (end > mb->end) {
248-
add_node_intersection(mb->nid, ofs, mb->end - ofs, type);
249-
ofs = mb->end;
250-
} else {
251-
add_node_intersection(mb->nid, ofs, end - ofs, type);
252-
break;
253-
}
254-
}
183+
num_physpages += (size >> PAGE_SHIFT);
184+
pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx Bytes\n",
185+
node, type, start, size);
186+
pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n",
187+
start >> PAGE_SHIFT, end >> PAGE_SHIFT, num_physpages);
188+
memblock_set_node(start, size, &memblock.memory, node);
255189
}
256190

257191
static void __init init_node_memblock(void)
@@ -293,24 +227,6 @@ static void __init init_node_memblock(void)
293227
}
294228
}
295229

296-
static void __init numa_default_distance(void)
297-
{
298-
int row, col;
299-
300-
for (row = 0; row < MAX_NUMNODES; row++)
301-
for (col = 0; col < MAX_NUMNODES; col++) {
302-
if (col == row)
303-
node_distances[row][col] = LOCAL_DISTANCE;
304-
else
305-
/* We assume that one node per package here!
306-
*
307-
* A SLIT should be used for multiple nodes
308-
* per package to override default setting.
309-
*/
310-
node_distances[row][col] = REMOTE_DISTANCE;
311-
}
312-
}
313-
314230
/*
315231
* fake_numa_init() - For Non-ACPI systems
316232
* Return: 0 on success, -errno on failure.
@@ -335,11 +251,11 @@ int __init init_numa_memory(void)
335251
for (i = 0; i < NR_CPUS; i++)
336252
set_cpuid_to_node(i, NUMA_NO_NODE);
337253

338-
numa_default_distance();
254+
numa_reset_distance();
339255
nodes_clear(numa_nodes_parsed);
340256
nodes_clear(node_possible_map);
341257
nodes_clear(node_online_map);
342-
memset(&numa_meminfo, 0, sizeof(numa_meminfo));
258+
WARN_ON(memblock_clear_hotplug(0, PHYS_ADDR_MAX));
343259

344260
/* Parse SRAT and SLIT if provided by firmware. */
345261
ret = acpi_disabled ? fake_numa_init() : acpi_numa_init();

arch/loongarch/mm/init.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,6 @@ void arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap)
114114
page += vmem_altmap_offset(altmap);
115115
__remove_pages(start_pfn, nr_pages, altmap);
116116
}
117-
118-
#ifdef CONFIG_NUMA
119-
int memory_add_physaddr_to_nid(u64 start)
120-
{
121-
return pa_to_nid(start);
122-
}
123-
EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
124-
#endif
125117
#endif
126118

127119
#ifdef CONFIG_SPARSEMEM_VMEMMAP

mm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ config NUMA_MEMBLKS
12901290
config NUMA_EMU
12911291
bool "NUMA emulation"
12921292
depends on NUMA_MEMBLKS
1293+
depends on X86 || GENERIC_ARCH_NUMA
12931294
help
12941295
Enable NUMA emulation. A flat machine will be split
12951296
into virtual nodes when booted with "numa=fake=N", where N is the

0 commit comments

Comments
 (0)