Skip to content

Commit

Permalink
mm: replace all open encodings for NUMA_NO_NODE
Browse files Browse the repository at this point in the history
Patch series "Replace all open encodings for NUMA_NO_NODE", v3.

All these places for replacement were found by running the following
grep patterns on the entire kernel code.  Please let me know if this
might have missed some instances.  This might also have replaced some
false positives.  I will appreciate suggestions, inputs and review.

1. git grep "nid == -1"
2. git grep "node == -1"
3. git grep "nid = -1"
4. git grep "node = -1"

This patch (of 2):

At present there are multiple places where invalid node number is
encoded as -1.  Even though implicitly understood it is always better to
have macros in there.  Replace these open encodings for an invalid node
number with the global macro NUMA_NO_NODE.  This helps remove NUMA
related assumptions like 'invalid node' from various places redirecting
them to a common definition.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Anshuman Khandual <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Acked-by: Jeff Kirsher <[email protected]>	[ixgbe]
Acked-by: Jens Axboe <[email protected]>			[mtip32xx]
Acked-by: Vinod Koul <[email protected]>			[dmaengine.c]
Acked-by: Michael Ellerman <[email protected]>		[powerpc]
Acked-by: Doug Ledford <[email protected]>		[drivers/infiniband]
Cc: Joseph Qi <[email protected]>
Cc: Hans Verkuil <[email protected]>
Cc: Stephen Rothwell <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Anshuman Khandual authored and torvalds committed Mar 6, 2019
1 parent 6ade203 commit 98fa15f
Show file tree
Hide file tree
Showing 39 changed files with 104 additions and 74 deletions.
3 changes: 2 additions & 1 deletion arch/alpha/include/asm/topology.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <linux/smp.h>
#include <linux/threads.h>
#include <linux/numa.h>
#include <asm/machvec.h>

#ifdef CONFIG_NUMA
Expand All @@ -29,7 +30,7 @@ static const struct cpumask *cpumask_of_node(int node)
{
int cpu;

if (node == -1)
if (node == NUMA_NO_NODE)
return cpu_all_mask;

cpumask_clear(&node_to_cpumask_map[node]);
Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/kernel/numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void __init build_cpu_to_node_map(void)
cpumask_clear(&node_to_cpu_mask[node]);

for_each_possible_early_cpu(cpu) {
node = -1;
node = NUMA_NO_NODE;
for (i = 0; i < NR_CPUS; ++i)
if (cpu_physical_id(cpu) == node_cpuid[i].phys_id) {
node = node_cpuid[i].nid;
Expand Down
6 changes: 3 additions & 3 deletions arch/ia64/mm/discontig.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void __init setup_per_cpu_areas(void)
* CPUs are put into groups according to node. Walk cpu_map
* and create new groups at node boundaries.
*/
prev_node = -1;
prev_node = NUMA_NO_NODE;
ai->nr_groups = 0;
for (unit = 0; unit < nr_units; unit++) {
cpu = cpu_map[unit];
Expand Down Expand Up @@ -435,7 +435,7 @@ static void __init *memory_less_node_alloc(int nid, unsigned long pernodesize)
{
void *ptr = NULL;
u8 best = 0xff;
int bestnode = -1, node, anynode = 0;
int bestnode = NUMA_NO_NODE, node, anynode = 0;

for_each_online_node(node) {
if (node_isset(node, memory_less_mask))
Expand All @@ -447,7 +447,7 @@ static void __init *memory_less_node_alloc(int nid, unsigned long pernodesize)
anynode = node;
}

if (bestnode == -1)
if (bestnode == NUMA_NO_NODE)
bestnode = anynode;

ptr = memblock_alloc_try_nid(pernodesize, PERCPU_PAGE_SIZE,
Expand Down
3 changes: 2 additions & 1 deletion arch/powerpc/include/asm/pci-bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/pci.h>
#include <linux/list.h>
#include <linux/ioport.h>
#include <linux/numa.h>

struct device_node;

Expand Down Expand Up @@ -265,7 +266,7 @@ extern int pcibios_map_io_space(struct pci_bus *bus);
#ifdef CONFIG_NUMA
#define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE))
#else
#define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1)
#define PHB_SET_NODE(PHB, NODE) ((PHB)->node = NUMA_NO_NODE)
#endif

#endif /* CONFIG_PPC64 */
Expand Down
3 changes: 2 additions & 1 deletion arch/powerpc/kernel/paca.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/export.h>
#include <linux/memblock.h>
#include <linux/sched/task.h>
#include <linux/numa.h>

#include <asm/lppaca.h>
#include <asm/paca.h>
Expand All @@ -36,7 +37,7 @@ static void *__init alloc_paca_data(unsigned long size, unsigned long align,
* which will put its paca in the right place.
*/
if (cpu == boot_cpuid) {
nid = -1;
nid = NUMA_NO_NODE;
memblock_set_bottom_up(true);
} else {
nid = early_cpu_to_node(cpu);
Expand Down
3 changes: 2 additions & 1 deletion arch/powerpc/kernel/pci-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <linux/vmalloc.h>
#include <linux/slab.h>
#include <linux/vgaarb.h>
#include <linux/numa.h>

#include <asm/processor.h>
#include <asm/io.h>
Expand Down Expand Up @@ -132,7 +133,7 @@ struct pci_controller *pcibios_alloc_controller(struct device_node *dev)
int nid = of_node_to_nid(dev);

if (nid < 0 || !node_online(nid))
nid = -1;
nid = NUMA_NO_NODE;

PHB_SET_NODE(phb, nid);
}
Expand Down
14 changes: 7 additions & 7 deletions arch/powerpc/mm/numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static void initialize_distance_lookup_table(int nid,
*/
static int associativity_to_nid(const __be32 *associativity)
{
int nid = -1;
int nid = NUMA_NO_NODE;

if (min_common_depth == -1)
goto out;
Expand All @@ -225,7 +225,7 @@ static int associativity_to_nid(const __be32 *associativity)

/* POWER4 LPAR uses 0xffff as invalid node */
if (nid == 0xffff || nid >= MAX_NUMNODES)
nid = -1;
nid = NUMA_NO_NODE;

if (nid > 0 &&
of_read_number(associativity, 1) >= distance_ref_points_depth) {
Expand All @@ -244,7 +244,7 @@ static int associativity_to_nid(const __be32 *associativity)
*/
static int of_node_to_nid_single(struct device_node *device)
{
int nid = -1;
int nid = NUMA_NO_NODE;
const __be32 *tmp;

tmp = of_get_associativity(device);
Expand All @@ -256,7 +256,7 @@ static int of_node_to_nid_single(struct device_node *device)
/* Walk the device tree upwards, looking for an associativity id */
int of_node_to_nid(struct device_node *device)
{
int nid = -1;
int nid = NUMA_NO_NODE;

of_node_get(device);
while (device) {
Expand Down Expand Up @@ -454,7 +454,7 @@ static int of_drconf_to_nid_single(struct drmem_lmb *lmb)
*/
static int numa_setup_cpu(unsigned long lcpu)
{
int nid = -1;
int nid = NUMA_NO_NODE;
struct device_node *cpu;

/*
Expand Down Expand Up @@ -930,7 +930,7 @@ static int hot_add_drconf_scn_to_nid(unsigned long scn_addr)
{
struct drmem_lmb *lmb;
unsigned long lmb_size;
int nid = -1;
int nid = NUMA_NO_NODE;

lmb_size = drmem_lmb_size();

Expand Down Expand Up @@ -960,7 +960,7 @@ static int hot_add_drconf_scn_to_nid(unsigned long scn_addr)
static int hot_add_node_scn_to_nid(unsigned long scn_addr)
{
struct device_node *memory;
int nid = -1;
int nid = NUMA_NO_NODE;

for_each_node_by_type(memory, "memory") {
unsigned long start, size;
Expand Down
5 changes: 3 additions & 2 deletions arch/powerpc/platforms/powernv/memtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/slab.h>
#include <linux/memory.h>
#include <linux/memory_hotplug.h>
#include <linux/numa.h>
#include <asm/machdep.h>
#include <asm/debugfs.h>

Expand Down Expand Up @@ -223,7 +224,7 @@ static int memtrace_online(void)
ent = &memtrace_array[i];

/* We have onlined this chunk previously */
if (ent->nid == -1)
if (ent->nid == NUMA_NO_NODE)
continue;

/* Remove from io mappings */
Expand Down Expand Up @@ -257,7 +258,7 @@ static int memtrace_online(void)
*/
debugfs_remove_recursive(ent->dir);
pr_info("Added trace memory back to node %d\n", ent->nid);
ent->size = ent->start = ent->nid = -1;
ent->size = ent->start = ent->nid = NUMA_NO_NODE;
}
if (ret)
return ret;
Expand Down
3 changes: 2 additions & 1 deletion arch/sparc/kernel/pci_fire.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/export.h>
#include <linux/irq.h>
#include <linux/of_device.h>
#include <linux/numa.h>

#include <asm/prom.h>
#include <asm/irq.h>
Expand Down Expand Up @@ -416,7 +417,7 @@ static int pci_fire_pbm_init(struct pci_pbm_info *pbm,
struct device_node *dp = op->dev.of_node;
int err;

pbm->numa_node = -1;
pbm->numa_node = NUMA_NO_NODE;

pbm->pci_ops = &sun4u_pci_ops;
pbm->config_space_reg_bits = 12;
Expand Down
3 changes: 2 additions & 1 deletion arch/sparc/kernel/pci_schizo.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <linux/export.h>
#include <linux/interrupt.h>
#include <linux/of_device.h>
#include <linux/numa.h>

#include <asm/iommu.h>
#include <asm/irq.h>
Expand Down Expand Up @@ -1347,7 +1348,7 @@ static int schizo_pbm_init(struct pci_pbm_info *pbm,
pbm->next = pci_pbm_root;
pci_pbm_root = pbm;

pbm->numa_node = -1;
pbm->numa_node = NUMA_NO_NODE;

pbm->pci_ops = &sun4u_pci_ops;
pbm->config_space_reg_bits = 8;
Expand Down
3 changes: 2 additions & 1 deletion arch/sparc/kernel/psycho_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/numa.h>

#include <asm/upa.h>

Expand Down Expand Up @@ -454,7 +455,7 @@ void psycho_pbm_init_common(struct pci_pbm_info *pbm, struct platform_device *op
struct device_node *dp = op->dev.of_node;

pbm->name = dp->full_name;
pbm->numa_node = -1;
pbm->numa_node = NUMA_NO_NODE;
pbm->chip_type = chip_type;
pbm->chip_version = of_getintprop_default(dp, "version#", 0);
pbm->chip_revision = of_getintprop_default(dp, "module-revision#", 0);
Expand Down
3 changes: 2 additions & 1 deletion arch/sparc/kernel/sbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/interrupt.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/numa.h>

#include <asm/page.h>
#include <asm/io.h>
Expand Down Expand Up @@ -561,7 +562,7 @@ static void __init sbus_iommu_init(struct platform_device *op)

op->dev.archdata.iommu = iommu;
op->dev.archdata.stc = strbuf;
op->dev.archdata.numa_node = -1;
op->dev.archdata.numa_node = NUMA_NO_NODE;

reg_base = regs + SYSIO_IOMMUREG_BASE;
iommu->iommu_control = reg_base + IOMMU_CONTROL;
Expand Down
6 changes: 3 additions & 3 deletions arch/sparc/mm/init_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,13 +976,13 @@ static u64 __init memblock_nid_range_sun4u(u64 start, u64 end, int *nid)
{
int prev_nid, new_nid;

prev_nid = -1;
prev_nid = NUMA_NO_NODE;
for ( ; start < end; start += PAGE_SIZE) {
for (new_nid = 0; new_nid < num_node_masks; new_nid++) {
struct node_mem_mask *p = &node_masks[new_nid];

if ((start & p->mask) == p->match) {
if (prev_nid == -1)
if (prev_nid == NUMA_NO_NODE)
prev_nid = new_nid;
break;
}
Expand Down Expand Up @@ -1208,7 +1208,7 @@ int of_node_to_nid(struct device_node *dp)
md = mdesc_grab();

count = 0;
nid = -1;
nid = NUMA_NO_NODE;
mdesc_for_each_node_by_name(md, grp, "group") {
if (!scan_arcs_for_cfg_handle(md, grp, cfg_handle)) {
nid = count;
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/include/asm/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/scatterlist.h>
#include <linux/numa.h>
#include <asm/io.h>
#include <asm/pat.h>
#include <asm/x86_init.h>
Expand Down Expand Up @@ -141,7 +142,7 @@ cpumask_of_pcibus(const struct pci_bus *bus)
int node;

node = __pcibus_to_node(bus);
return (node == -1) ? cpu_online_mask :
return (node == NUMA_NO_NODE) ? cpu_online_mask :
cpumask_of_node(node);
}
#endif
Expand Down
7 changes: 4 additions & 3 deletions arch/x86/kernel/apic/x2apic_uv_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <linux/crash_dump.h>
#include <linux/reboot.h>
#include <linux/memory.h>
#include <linux/numa.h>

#include <asm/uv/uv_mmrs.h>
#include <asm/uv/uv_hub.h>
Expand Down Expand Up @@ -1390,7 +1391,7 @@ static void __init build_socket_tables(void)
}

/* Set socket -> node values: */
lnid = -1;
lnid = NUMA_NO_NODE;
for_each_present_cpu(cpu) {
int nid = cpu_to_node(cpu);
int apicid, sockid;
Expand Down Expand Up @@ -1521,7 +1522,7 @@ static void __init uv_system_init_hub(void)
new_hub->pnode = 0xffff;

new_hub->numa_blade_id = uv_node_to_blade_id(nodeid);
new_hub->memory_nid = -1;
new_hub->memory_nid = NUMA_NO_NODE;
new_hub->nr_possible_cpus = 0;
new_hub->nr_online_cpus = 0;
}
Expand All @@ -1538,7 +1539,7 @@ static void __init uv_system_init_hub(void)

uv_cpu_info_per(cpu)->p_uv_hub_info = uv_hub_info_list(nodeid);
uv_cpu_info_per(cpu)->blade_cpu_id = uv_cpu_hub_info(cpu)->nr_possible_cpus++;
if (uv_cpu_hub_info(cpu)->memory_nid == -1)
if (uv_cpu_hub_info(cpu)->memory_nid == NUMA_NO_NODE)
uv_cpu_hub_info(cpu)->memory_nid = cpu_to_node(cpu);

/* Init memoryless node: */
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/kernel/smpboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <linux/stackprotector.h>
#include <linux/gfp.h>
#include <linux/cpuidle.h>
#include <linux/numa.h>

#include <asm/acpi.h>
#include <asm/desc.h>
Expand Down Expand Up @@ -841,7 +842,7 @@ wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip)
/* reduce the number of lines printed when booting a large cpu count system */
static void announce_cpu(int cpu, int apicid)
{
static int current_node = -1;
static int current_node = NUMA_NO_NODE;
int node = early_cpu_to_node(cpu);
static int width, node_width;

Expand Down
5 changes: 3 additions & 2 deletions drivers/block/mtip32xx/mtip32xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <linux/export.h>
#include <linux/debugfs.h>
#include <linux/prefetch.h>
#include <linux/numa.h>
#include "mtip32xx.h"

#define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32)
Expand Down Expand Up @@ -4018,9 +4019,9 @@ static int get_least_used_cpu_on_node(int node)
/* Helper for selecting a node in round robin mode */
static inline int mtip_get_next_rr_node(void)
{
static int next_node = -1;
static int next_node = NUMA_NO_NODE;

if (next_node == -1) {
if (next_node == NUMA_NO_NODE) {
next_node = first_online_node;
return next_node;
}
Expand Down
4 changes: 3 additions & 1 deletion drivers/dma/dmaengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <linux/acpi_dma.h>
#include <linux/of_dma.h>
#include <linux/mempool.h>
#include <linux/numa.h>

static DEFINE_MUTEX(dma_list_mutex);
static DEFINE_IDA(dma_ida);
Expand Down Expand Up @@ -386,7 +387,8 @@ EXPORT_SYMBOL(dma_issue_pending_all);
static bool dma_chan_is_local(struct dma_chan *chan, int cpu)
{
int node = dev_to_node(chan->device->dev);
return node == -1 || cpumask_test_cpu(cpu, cpumask_of_node(node));
return node == NUMA_NO_NODE ||
cpumask_test_cpu(cpu, cpumask_of_node(node));
}

/**
Expand Down
Loading

0 comments on commit 98fa15f

Please sign in to comment.