Commit 7281201922a0063fa60804ce39c277fc98142a47

Authored by Lee Schermerhorn
Committed by Linus Torvalds
1 parent 866707fc27

numa: add generic percpu var numa_node_id() implementation

Rework the generic version of the numa_node_id() function to use the new
generic percpu variable infrastructure.

Guard the new implementation with a new config option:

        CONFIG_USE_PERCPU_NUMA_NODE_ID.

Archs which support this new implemention will default this option to 'y'
when NUMA is configured.  This config option could be removed if/when all
archs switch over to the generic percpu implementation of numa_node_id().
Arch support involves:

  1) converting any existing per cpu variable implementations to use
     this implementation.  x86_64 is an instance of such an arch.
  2) archs that don't use a per cpu variable for numa_node_id() will
     need to initialize the new per cpu variable "numa_node" as cpus
     are brought on-line.  ia64 is an example.
  3) Defining USE_PERCPU_NUMA_NODE_ID in arch dependent Kconfig--e.g.,
     when NUMA is configured.  This is required because I have
     retained the old implementation by default to allow archs to
     be modified incrementally, as desired.

Subsequent patches will convert x86_64 and ia64 to use this implemenation.

Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Mel Gorman <mel@csn.ul.ie>
Reviewed-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Nick Piggin <npiggin@suse.de>
Cc: David Rientjes <rientjes@google.com>
Cc: Eric Whitney <eric.whitney@hp.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 55 additions and 5 deletions Side-by-side Diff

arch/x86/include/asm/topology.h
... ... @@ -170,6 +170,10 @@
170 170 {
171 171 return 0;
172 172 }
  173 +/*
  174 + * indicate override:
  175 + */
  176 +#define numa_node_id numa_node_id
173 177  
174 178 static inline int early_cpu_to_node(int cpu)
175 179 {
include/linux/topology.h
... ... @@ -31,6 +31,7 @@
31 31 #include <linux/bitops.h>
32 32 #include <linux/mmzone.h>
33 33 #include <linux/smp.h>
  34 +#include <linux/percpu.h>
34 35 #include <asm/topology.h>
35 36  
36 37 #ifndef node_has_online_mem
37 38  
... ... @@ -203,8 +204,53 @@
203 204 #ifndef SD_NODE_INIT
204 205 #error Please define an appropriate SD_NODE_INIT in include/asm/topology.h!!!
205 206 #endif
  207 +
206 208 #endif /* CONFIG_NUMA */
207 209  
  210 +#ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
  211 +DECLARE_PER_CPU(int, numa_node);
  212 +
  213 +#ifndef numa_node_id
  214 +/* Returns the number of the current Node. */
  215 +static inline int numa_node_id(void)
  216 +{
  217 + return __this_cpu_read(numa_node);
  218 +}
  219 +#endif
  220 +
  221 +#ifndef cpu_to_node
  222 +static inline int cpu_to_node(int cpu)
  223 +{
  224 + return per_cpu(numa_node, cpu);
  225 +}
  226 +#endif
  227 +
  228 +#ifndef set_numa_node
  229 +static inline void set_numa_node(int node)
  230 +{
  231 + percpu_write(numa_node, node);
  232 +}
  233 +#endif
  234 +
  235 +#ifndef set_cpu_numa_node
  236 +static inline void set_cpu_numa_node(int cpu, int node)
  237 +{
  238 + per_cpu(numa_node, cpu) = node;
  239 +}
  240 +#endif
  241 +
  242 +#else /* !CONFIG_USE_PERCPU_NUMA_NODE_ID */
  243 +
  244 +/* Returns the number of the current Node. */
  245 +#ifndef numa_node_id
  246 +static inline int numa_node_id(void)
  247 +{
  248 + return cpu_to_node(raw_smp_processor_id());
  249 +}
  250 +#endif
  251 +
  252 +#endif /* [!]CONFIG_USE_PERCPU_NUMA_NODE_ID */
  253 +
208 254 #ifndef topology_physical_package_id
209 255 #define topology_physical_package_id(cpu) ((void)(cpu), -1)
210 256 #endif
... ... @@ -216,11 +262,6 @@
216 262 #endif
217 263 #ifndef topology_core_cpumask
218 264 #define topology_core_cpumask(cpu) cpumask_of(cpu)
219   -#endif
220   -
221   -/* Returns the number of the current Node. */
222   -#ifndef numa_node_id
223   -#define numa_node_id() (cpu_to_node(raw_smp_processor_id()))
224 265 #endif
225 266  
226 267 #endif /* _LINUX_TOPOLOGY_H */
... ... @@ -57,6 +57,11 @@
57 57 #include <asm/div64.h>
58 58 #include "internal.h"
59 59  
  60 +#ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
  61 +DEFINE_PER_CPU(int, numa_node);
  62 +EXPORT_PER_CPU_SYMBOL(numa_node);
  63 +#endif
  64 +
60 65 /*
61 66 * Array of node states.
62 67 */