Skip to content

Commit a24f2fb

Browse files
committed
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 <zhoubinbin@loongson.cn> Signed-off-by: Yuquan Wang <wangyuquan1236@phytium.com.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 9559d58 commit a24f2fb

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
@@ -189,6 +189,7 @@ config LOONGARCH
189189
select MODULES_USE_ELF_RELA if MODULES
190190
select NEED_PER_CPU_EMBED_FIRST_CHUNK
191191
select NEED_PER_CPU_PAGE_FIRST_CHUNK
192+
select NUMA_MEMBLKS if NUMA
192193
select OF
193194
select OF_EARLY_FLATTREE
194195
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
@@ -19,11 +19,8 @@ extern int pcibus_to_node(struct pci_bus *);
1919

2020
#define cpumask_of_pcibus(bus) (cpu_online_mask)
2121

22-
extern unsigned char node_distances[MAX_NUMNODES][MAX_NUMNODES];
23-
24-
void numa_set_distance(int from, int to, int distance);
25-
26-
#define node_distance(from, to) (node_distances[(from)][(to)])
22+
int __node_distance(int from, int to);
23+
#define node_distance(from, to) __node_distance(from, to)
2724

2825
#else
2926
#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>
@@ -27,10 +28,6 @@
2728
#include <asm/time.h>
2829

2930
int numa_off;
30-
unsigned char node_distances[MAX_NUMNODES][MAX_NUMNODES];
31-
EXPORT_SYMBOL(node_distances);
32-
33-
static struct numa_meminfo numa_meminfo;
3431
cpumask_t cpus_on_node[MAX_NUMNODES];
3532
cpumask_t phys_cpus_on_node[MAX_NUMNODES];
3633
EXPORT_SYMBOL(cpus_on_node);
@@ -43,8 +40,6 @@ s16 __cpuid_to_node[CONFIG_NR_CPUS] = {
4340
};
4441
EXPORT_SYMBOL(__cpuid_to_node);
4542

46-
nodemask_t numa_nodes_parsed __initdata;
47-
4843
#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
4944
unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
5045
EXPORT_SYMBOL(__per_cpu_offset);
@@ -145,48 +140,6 @@ void numa_remove_cpu(unsigned int cpu)
145140
cpumask_clear_cpu(cpu, &cpus_on_node[nid]);
146141
}
147142

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

206159
#ifdef CONFIG_ACPI_NUMA
207160

208-
static void __init add_node_intersection(u32 node, u64 start, u64 size, u32 type)
209-
{
210-
static unsigned long num_physpages;
211-
212-
num_physpages += (size >> PAGE_SHIFT);
213-
pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx Bytes\n",
214-
node, type, start, size);
215-
pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n",
216-
start >> PAGE_SHIFT, (start + size) >> PAGE_SHIFT, num_physpages);
217-
memblock_set_node(start, size, &memblock.memory, node);
218-
}
219-
220161
/*
221162
* add_numamem_region
222163
*
@@ -228,28 +169,21 @@ static void __init add_node_intersection(u32 node, u64 start, u64 size, u32 type
228169
*/
229170
static void __init add_numamem_region(u64 start, u64 end, u32 type)
230171
{
231-
u32 i;
232-
u64 ofs = start;
172+
u32 node = pa_to_nid(start);
173+
u64 size = end - start;
174+
static unsigned long num_physpages;
233175

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

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

255189
static void __init init_node_memblock(void)
@@ -291,24 +225,6 @@ static void __init init_node_memblock(void)
291225
}
292226
}
293227

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

336-
numa_default_distance();
252+
numa_reset_distance();
337253
nodes_clear(numa_nodes_parsed);
338254
nodes_clear(node_possible_map);
339255
nodes_clear(node_online_map);
340-
memset(&numa_meminfo, 0, sizeof(numa_meminfo));
256+
WARN_ON(memblock_clear_hotplug(0, PHYS_ADDR_MAX));
341257

342258
/* Parse SRAT and SLIT if provided by firmware. */
343259
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
@@ -106,14 +106,6 @@ void arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap)
106106
page += vmem_altmap_offset(altmap);
107107
__remove_pages(start_pfn, nr_pages, altmap);
108108
}
109-
110-
#ifdef CONFIG_NUMA
111-
int memory_add_physaddr_to_nid(u64 start)
112-
{
113-
return pa_to_nid(start);
114-
}
115-
EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
116-
#endif
117109
#endif
118110

119111
#ifdef CONFIG_SPARSEMEM_VMEMMAP

mm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ config NUMA_MEMBLKS
13171317
config NUMA_EMU
13181318
bool "NUMA emulation"
13191319
depends on NUMA_MEMBLKS
1320+
depends on X86 || GENERIC_ARCH_NUMA
13201321
help
13211322
Enable NUMA emulation. A flat machine will be split
13221323
into virtual nodes when booted with "numa=fake=N", where N is the

0 commit comments

Comments
 (0)