From 83a2dbe9e50d3a60312fa40f41052b23a3edb3ca Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Wed, 22 Apr 2020 08:58:39 -0400 Subject: [PATCH] LU-9859 libcfs: remove conditional compilation from libcfs_cpu.c libcfs_cpu.c manages CPU partitions. In the !CONFIG_SMP case, most of this disappears and 'static inline's from libcfs_cpu.h are used. However we still allocate a 'struct cfs_cpt_table' which is used to keep the NUMA node mask. Event with SMP disabled Lustre wants to handle any NUMA nodes available. This patch removes all the !CONFIG_SMP code from libcfs_cpu.c and conditionally compiles the whole file only when CONFIG_SMP. We no longer allocate a 'struct cfs_cpt_table' on !CONFIG_SMP, and don't even declare a structure. The name "cfs_cpt_tab" becomes always "NULL", which allows some code to be optimized away. This means that cfs_cpt_tab can sometimes be NULL, so we need to discard the assertion that it isn't. Linux-commit: 7b8e2026fb185e5178f9137c463ff07fc895be5d Test-Parameters: trivial Change-Id: Icb84f23249d086c662de76df6ce9686de0b692aa Signed-off-by: Mr NeilBrown Signed-off-by: Greg Kroah-Hartman Reviewed-on: https://review.whamcloud.com/37881 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Shaun Tancheff Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/libcfs_cpu.h | 135 ++++++++++++++++++++++++++++++++----- libcfs/libcfs/Makefile.in | 6 +- libcfs/libcfs/heap.c | 2 +- libcfs/libcfs/libcfs_cpu.c | 66 ------------------ libcfs/libcfs/module.c | 4 -- 5 files changed, 122 insertions(+), 91 deletions(-) diff --git a/libcfs/include/libcfs/libcfs_cpu.h b/libcfs/include/libcfs/libcfs_cpu.h index 404b07a..e7ff6ae 100644 --- a/libcfs/include/libcfs/libcfs_cpu.h +++ b/libcfs/include/libcfs/libcfs_cpu.h @@ -80,7 +80,13 @@ #include +/* any CPU partition */ +#define CFS_CPT_ANY (-1) + +struct cfs_cpt_table; + #ifdef CONFIG_SMP +extern struct cfs_cpt_table *cfs_cpt_tab; /** virtual processing unit */ struct cfs_cpu_partition { @@ -95,37 +101,27 @@ struct cfs_cpu_partition { /* NUMA node if cpt_nodemask is empty */ int cpt_node; }; -#endif /* CONFIG_SMP */ /** descriptor for CPU partitions */ struct cfs_cpt_table { -#ifdef CONFIG_SMP /* spread rotor for NUMA allocator */ unsigned int ctb_spread_rotor; /* maximum NUMA distance between all nodes in table */ unsigned int ctb_distance; + /* # of CPU partitions */ + int ctb_nparts; /* partitions tables */ struct cfs_cpu_partition *ctb_parts; /* shadow HW CPU to CPU partition ID */ int *ctb_cpu2cpt; + /* all cpus in this partition table */ + cpumask_var_t ctb_cpumask; /* shadow HW node to CPU partition ID */ int *ctb_node2cpt; - /* # of CPU partitions */ - int ctb_nparts; /* all nodes in this partition table */ nodemask_t *ctb_nodemask; -#else - nodemask_t ctb_nodemask; -#endif /* CONFIG_SMP */ - /* all cpus in this partition table */ - cpumask_var_t ctb_cpumask; }; -/* any CPU partition */ -#define CFS_CPT_ANY (-1) - -extern struct cfs_cpt_table *cfs_cpt_tab; - /** * destroy a CPU partition table */ @@ -211,7 +207,6 @@ int cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node); * remove all cpus in NUMA node \a node from CPU partition \a cpt */ void cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node); - /** * add all cpus in node mask \a mask to CPU partition \a cpt * return 1 if successfully set all CPUs, otherwise return 0 @@ -229,6 +224,113 @@ void cfs_cpt_unset_nodemask(struct cfs_cpt_table *cptab, int cpt, */ int cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt); +int cfs_cpu_init(void); +void cfs_cpu_fini(void); + +#else /* !CONFIG_SMP */ + +#define cfs_cpt_tab ((struct cfs_cpt_table *)NULL) + +static inline void cfs_cpt_table_free(struct cfs_cpt_table *cptab) +{ +} + +static inline struct cfs_cpt_table *cfs_cpt_table_alloc(int ncpt) +{ + return NULL; +} + +static inline int cfs_cpt_table_print(struct cfs_cpt_table *cptab, + char *buf, int len) +{ + int rc; + + rc = snprintf(buf, len, "0\t: 0\n"); + len -= rc; + if (len <= 0) + return -EFBIG; + + return rc; +} + +static inline int cfs_cpt_distance_print(struct cfs_cpt_table *cptab, + char *buf, int len) +{ + int rc; + + rc = snprintf(buf, len, "0\t: 0:1\n"); + len -= rc; + if (len <= 0) + return -EFBIG; + + return rc; +} + +static inline cpumask_var_t *cfs_cpt_cpumask(struct cfs_cpt_table *cptab, + int cpt) +{ + return (cpumask_var_t *) cpu_online_mask; +} + +static inline int cfs_cpt_number(struct cfs_cpt_table *cptab) +{ + return 1; +} + +static inline int cfs_cpt_weight(struct cfs_cpt_table *cptab, int cpt) +{ + return 1; +} + +static inline nodemask_t *cfs_cpt_nodemask(struct cfs_cpt_table *cptab, + int cpt) +{ + return &node_online_map; +} + +static inline unsigned int cfs_cpt_distance(struct cfs_cpt_table *cptab, + int cpt1, int cpt2) +{ + return 1; +} + +static inline int cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, + int node) +{ + return 1; +} + +static inline int cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt) +{ + return 0; +} + +static inline int cfs_cpt_current(struct cfs_cpt_table *cptab, int remap) +{ + return 0; +} + +static inline int cfs_cpt_of_node(struct cfs_cpt_table *cptab, int node) +{ + return 0; +} + +static inline int cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt) +{ + return 0; +} + +static inline int cfs_cpu_init(void) +{ + return 0; +} + +static inline void cfs_cpu_fini(void) +{ +} + +#endif /* CONFIG_SMP */ + /* * allocate per-cpu-partition data, returned value is an array of pointers, * variable can be indexed by CPU ID. @@ -368,7 +470,4 @@ cfs_mem_cache_cpt_alloc(struct kmem_cache *cachep, struct cfs_cpt_table *cptab, #define cfs_cpt_for_each(i, cptab) \ for (i = 0; i < cfs_cpt_number(cptab); i++) -int cfs_cpu_init(void); -void cfs_cpu_fini(void); - #endif /* __LIBCFS_CPU_H__ */ diff --git a/libcfs/libcfs/Makefile.in b/libcfs/libcfs/Makefile.in index ad9ac74..5d8737a 100644 --- a/libcfs/libcfs/Makefile.in +++ b/libcfs/libcfs/Makefile.in @@ -13,12 +13,14 @@ default: all libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs)) libcfs-crypto-objs := $(addprefix crypto/,$(libcfs-crypto-objs)) +libcfs-objs-$(CONFIG_SMP) = libcfs_cpu.o libcfs-all-objs := debug.o fail.o module.o tracefile.o \ libcfs_string.o hash.o heap.o \ - workitem.o libcfs_cpu.o \ + workitem.o \ libcfs_mem.o libcfs_lock.o \ linux-crypto.o linux-crypto-adler.o \ - linux-debug.o linux-tracefile.o + linux-debug.o linux-tracefile.o \ + $(libcfs-objs-y) libcfs-objs := $(libcfs-linux-objs) $(libcfs-all-objs) @LLCRYPT_TRUE@libcfs-objs += $(libcfs-crypto-objs) diff --git a/libcfs/libcfs/heap.c b/libcfs/libcfs/heap.c index 4efc4eb..d625cbc 100644 --- a/libcfs/libcfs/heap.c +++ b/libcfs/libcfs/heap.c @@ -174,7 +174,7 @@ cfs_binheap_create(struct cfs_binheap_ops *ops, unsigned int flags, LASSERT(ops->hop_compare != NULL); if (cptab) { LASSERT(cptid == CFS_CPT_ANY || - (cptid >= 0 && cptid < cptab->ctb_nparts)); + (cptid >= 0 && cptid < cfs_cpt_number(cptab))); LIBCFS_CPT_ALLOC(h, cptab, cptid, sizeof(*h)); } else { LIBCFS_ALLOC(h, sizeof(*h)); diff --git a/libcfs/libcfs/libcfs_cpu.c b/libcfs/libcfs/libcfs_cpu.c index 68046a7..58a3a44 100644 --- a/libcfs/libcfs/libcfs_cpu.c +++ b/libcfs/libcfs/libcfs_cpu.c @@ -67,7 +67,6 @@ static char *cpu_pattern = "N"; module_param(cpu_pattern, charp, 0444); MODULE_PARM_DESC(cpu_pattern, "CPU partitions pattern"); -#ifdef CONFIG_SMP struct cfs_cpt_table *cfs_cpt_table_alloc(int ncpt) { struct cfs_cpt_table *cptab; @@ -1232,68 +1231,3 @@ failed_cpu_dead: #endif /* CONFIG_HOTPLUG_CPU */ return ret; } - -#else /* ! CONFIG_SMP */ - -struct cfs_cpt_table *cfs_cpt_table_alloc(int ncpt) -{ - struct cfs_cpt_table *cptab; - - if (ncpt != 1) { - CERROR("Can't support cpu partition number %d\n", ncpt); - return NULL; - } - - LIBCFS_ALLOC(cptab, sizeof(*cptab)); - if (!cptab) - return NULL; - - cpumask_set_cpu(0, cptab->ctb_cpumask); - node_set(0, cptab->ctb_nodemask); - - return cptab; -} -EXPORT_SYMBOL(cfs_cpt_table_alloc); - -int cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len) -{ - int rc; - - rc = snprintf(buf, len, "0\t: 0\n"); - len -= rc; - if (len <= 0) - return -EFBIG; - - return rc; -} -EXPORT_SYMBOL(cfs_cpt_table_print); - -int cfs_cpt_distance_print(struct cfs_cpt_table *cptab, char *buf, int len) -{ - int rc; - - rc = snprintf(buf, len, "0\t: 0:1\n"); - len -= rc; - if (len <= 0) - return -EFBIG; - - return rc; -} -EXPORT_SYMBOL(cfs_cpt_distance_print); - -void cfs_cpu_fini(void) -{ - if (cfs_cpt_table) { - cfs_cpt_table_free(cfs_cpt_table); - cfs_cpt_table = NULL; - } -} - -int cfs_cpu_init(void) -{ - cfs_cpt_table = cfs_cpt_table_alloc(1); - - return cfs_cpt_table ? 0 : -1; -} - -#endif /* !CONFIG_SMP */ diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index c51b493..c908d34 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -406,8 +406,6 @@ static int __proc_cpt_table(void *data, int write, if (write) return -EPERM; - LASSERT(cfs_cpt_tab); - while (1) { LIBCFS_ALLOC(buf, len); if (buf == NULL) @@ -454,8 +452,6 @@ static int __proc_cpt_distance(void *data, int write, if (write) return -EPERM; - LASSERT(cfs_cpt_tab); - while (1) { LIBCFS_ALLOC(buf, len); if (buf == NULL) -- 1.8.3.1