Whamcloud - gitweb
LU-9859 libcfs: remove conditional compilation from libcfs_cpu.c 81/37881/10
authorMr NeilBrown <neilb@suse.de>
Wed, 22 Apr 2020 12:58:39 +0000 (08:58 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 7 May 2020 05:46:06 +0000 (05:46 +0000)
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 <neilb@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-on: https://review.whamcloud.com/37881
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/libcfs_cpu.h
libcfs/libcfs/Makefile.in
libcfs/libcfs/heap.c
libcfs/libcfs/libcfs_cpu.c
libcfs/libcfs/module.c

index 404b07a..e7ff6ae 100644 (file)
 
 #include <libcfs/linux/linux-cpu.h>
 
+/* 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__ */
index ad9ac74..5d8737a 100644 (file)
@@ -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)
index 4efc4eb..d625cbc 100644 (file)
@@ -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));
index 68046a7..58a3a44 100644 (file)
@@ -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 */
index c51b493..c908d34 100644 (file)
@@ -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)