Linux Audio

Check our new training course

Loading...
v6.2
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 *
 4 * ia64 kernel NUMA specific stuff
 5 *
 6 * Copyright (C) 2002 Erich Focht <efocht@ess.nec.de>
 7 * Copyright (C) 2004 Silicon Graphics, Inc.
 8 *   Jesse Barnes <jbarnes@sgi.com>
 9 */
10#include <linux/topology.h>
11#include <linux/module.h>
12#include <asm/processor.h>
13#include <asm/smp.h>
14
15u16 cpu_to_node_map[NR_CPUS] __cacheline_aligned;
16EXPORT_SYMBOL(cpu_to_node_map);
17
18cpumask_t node_to_cpu_mask[MAX_NUMNODES] __cacheline_aligned;
19EXPORT_SYMBOL(node_to_cpu_mask);
20
21void map_cpu_to_node(int cpu, int nid)
22{
23	int oldnid;
24	if (nid < 0) { /* just initialize by zero */
25		cpu_to_node_map[cpu] = 0;
26		return;
27	}
28	/* sanity check first */
29	oldnid = cpu_to_node_map[cpu];
30	if (cpumask_test_cpu(cpu, &node_to_cpu_mask[oldnid])) {
31		return; /* nothing to do */
32	}
33	/* we don't have cpu-driven node hot add yet...
34	   In usual case, node is created from SRAT at boot time. */
35	if (!node_online(nid))
36		nid = first_online_node;
37	cpu_to_node_map[cpu] = nid;
38	cpumask_set_cpu(cpu, &node_to_cpu_mask[nid]);
39	return;
40}
41
42void unmap_cpu_from_node(int cpu, int nid)
43{
44	WARN_ON(!cpumask_test_cpu(cpu, &node_to_cpu_mask[nid]));
45	WARN_ON(cpu_to_node_map[cpu] != nid);
46	cpu_to_node_map[cpu] = 0;
47	cpumask_clear_cpu(cpu, &node_to_cpu_mask[nid]);
48}
49
50
51/**
52 * build_cpu_to_node_map - setup cpu to node and node to cpumask arrays
53 *
54 * Build cpu to node mapping and initialize the per node cpu masks using
55 * info from the node_cpuid array handed to us by ACPI.
56 */
57void __init build_cpu_to_node_map(void)
58{
59	int cpu, i, node;
60
61	for(node=0; node < MAX_NUMNODES; node++)
62		cpumask_clear(&node_to_cpu_mask[node]);
63
64	for_each_possible_early_cpu(cpu) {
65		node = NUMA_NO_NODE;
66		for (i = 0; i < NR_CPUS; ++i)
67			if (cpu_physical_id(cpu) == node_cpuid[i].phys_id) {
68				node = node_cpuid[i].nid;
69				break;
70			}
71		map_cpu_to_node(cpu, node);
72	}
73}
v5.9
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 *
 4 * ia64 kernel NUMA specific stuff
 5 *
 6 * Copyright (C) 2002 Erich Focht <efocht@ess.nec.de>
 7 * Copyright (C) 2004 Silicon Graphics, Inc.
 8 *   Jesse Barnes <jbarnes@sgi.com>
 9 */
10#include <linux/topology.h>
11#include <linux/module.h>
12#include <asm/processor.h>
13#include <asm/smp.h>
14
15u16 cpu_to_node_map[NR_CPUS] __cacheline_aligned;
16EXPORT_SYMBOL(cpu_to_node_map);
17
18cpumask_t node_to_cpu_mask[MAX_NUMNODES] __cacheline_aligned;
19EXPORT_SYMBOL(node_to_cpu_mask);
20
21void map_cpu_to_node(int cpu, int nid)
22{
23	int oldnid;
24	if (nid < 0) { /* just initialize by zero */
25		cpu_to_node_map[cpu] = 0;
26		return;
27	}
28	/* sanity check first */
29	oldnid = cpu_to_node_map[cpu];
30	if (cpumask_test_cpu(cpu, &node_to_cpu_mask[oldnid])) {
31		return; /* nothing to do */
32	}
33	/* we don't have cpu-driven node hot add yet...
34	   In usual case, node is created from SRAT at boot time. */
35	if (!node_online(nid))
36		nid = first_online_node;
37	cpu_to_node_map[cpu] = nid;
38	cpumask_set_cpu(cpu, &node_to_cpu_mask[nid]);
39	return;
40}
41
42void unmap_cpu_from_node(int cpu, int nid)
43{
44	WARN_ON(!cpumask_test_cpu(cpu, &node_to_cpu_mask[nid]));
45	WARN_ON(cpu_to_node_map[cpu] != nid);
46	cpu_to_node_map[cpu] = 0;
47	cpumask_clear_cpu(cpu, &node_to_cpu_mask[nid]);
48}
49
50
51/**
52 * build_cpu_to_node_map - setup cpu to node and node to cpumask arrays
53 *
54 * Build cpu to node mapping and initialize the per node cpu masks using
55 * info from the node_cpuid array handed to us by ACPI.
56 */
57void __init build_cpu_to_node_map(void)
58{
59	int cpu, i, node;
60
61	for(node=0; node < MAX_NUMNODES; node++)
62		cpumask_clear(&node_to_cpu_mask[node]);
63
64	for_each_possible_early_cpu(cpu) {
65		node = NUMA_NO_NODE;
66		for (i = 0; i < NR_CPUS; ++i)
67			if (cpu_physical_id(cpu) == node_cpuid[i].phys_id) {
68				node = node_cpuid[i].nid;
69				break;
70			}
71		map_cpu_to_node(cpu, node);
72	}
73}