From bd3023bf147a661e00394ddee0efc2b2ac2f7887 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Sat, 20 Jan 2018 18:05:44 -0500 Subject: [PATCH] LU-9859 libcfs: merge UMP and SMP libcfs cpu header code Currently we have two headers, linux-cpu.h that contains the SMP version and libcfs_cpu.h contains the UMP version. We can simplify the headers into a single header which handles both cases. Many cleanups for checkpatch violations are done as well. Change-Id: Ifb92e59ad370e991220b5957538b6bab89423e2f Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/30873 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/libcfs_cpu.h | 96 +++++++++------ libcfs/include/libcfs/linux/linux-cpu.h | 47 ------- libcfs/libcfs/libcfs_cpu.c | 37 ++---- libcfs/libcfs/linux/linux-cpu.c | 211 +++++++++++++++++--------------- 4 files changed, 179 insertions(+), 212 deletions(-) diff --git a/libcfs/include/libcfs/libcfs_cpu.h b/libcfs/include/libcfs/libcfs_cpu.h index ee71f3f..a05739d 100644 --- a/libcfs/include/libcfs/libcfs_cpu.h +++ b/libcfs/include/libcfs/libcfs_cpu.h @@ -13,11 +13,6 @@ * General Public License version 2 for more details (a copy is included * in the LICENSE file that accompanied this code). * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA - * * GPL HEADER END */ /* @@ -47,16 +42,16 @@ * * Example: if there are 8 cores on the system, while creating a CPT * with cpu_npartitions=4: - * core[0, 1] = partition[0], core[2, 3] = partition[1] - * core[4, 5] = partition[2], core[6, 7] = partition[3] + * core[0, 1] = partition[0], core[2, 3] = partition[1] + * core[4, 5] = partition[2], core[6, 7] = partition[3] * * cpu_npartitions=1: - * core[0, 1, ... 7] = partition[0] + * core[0, 1, ... 7] = partition[0] * * . User can also specify CPU partitions by string pattern * * Examples: cpu_partitions="0[0,1], 1[2,3]" - * cpu_partitions="N 0[0-3], 1[4-8]" + * cpu_partitions="N 0[0-3], 1[4-8]" * * The first character "N" means following numbers are numa ID * @@ -76,24 +71,55 @@ #ifndef __LIBCFS_CPU_H__ #define __LIBCFS_CPU_H__ +#include +#include #include +#include +#include + #include -#ifndef HAVE_LIBCFS_CPT +#ifdef CONFIG_SMP +/** virtual processing unit */ +struct cfs_cpu_partition { + /* CPUs mask for this partition */ + cpumask_t *cpt_cpumask; + /* nodes mask for this partition */ + nodemask_t *cpt_nodemask; + /* NUMA distance between CPTs */ + unsigned int *cpt_distance; + /* spread rotor for NUMA allocator */ + int cpt_spread_rotor; + /* 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 */ + int ctb_spread_rotor; + /* maximum NUMA distance between all nodes in table */ + unsigned int ctb_distance; + /* partitions tables */ + struct cfs_cpu_partition *ctb_parts; + /* shadow HW CPU to CPU partition ID */ + int *ctb_cpu2cpt; + /* shadow HW node to CPU partition ID */ + int *ctb_node2cpt; /* # of CPU partitions */ - int ctb_nparts; - /* cpu mask */ - cpumask_t ctb_mask; - /* node mask */ - nodemask_t ctb_nodemask; - /* version */ - __u64 ctb_version; + 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_t *ctb_cpumask; }; -#endif /* !HAVE_LIBCFS_CPT */ - /* any CPU partition */ #define CFS_CPT_ANY (-1) @@ -120,7 +146,7 @@ int cfs_cpt_distance_print(struct cfs_cpt_table *cptab, char *buf, int len); */ int cfs_cpt_number(struct cfs_cpt_table *cptab); /** - * return number of HW cores or hypter-threadings in a CPU partition \a cpt + * return number of HW cores or hyper-threadings in a CPU partition \a cpt */ int cfs_cpt_weight(struct cfs_cpt_table *cptab, int cpt); /** @@ -150,13 +176,13 @@ int cfs_cpt_of_node(struct cfs_cpt_table *cptab, int node); /** * NUMA distance between \a cpt1 and \a cpt2 in \a cptab */ -unsigned cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2); +unsigned int cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2); /** * bind current thread on a CPU-partition \a cpt of \a cptab */ int cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt); /** - * add \a cpu to CPU partion @cpt of \a cptab, return 1 for success, + * add \a cpu to CPU partition @cpt of \a cptab, return 1 for success, * otherwise 0 is returned */ int cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu); @@ -168,7 +194,6 @@ void cfs_cpt_unset_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu); * add all cpus in \a mask to CPU partition \a cpt * return 1 if successfully set all CPUs, otherwise return 0 */ - int cfs_cpt_set_cpumask(struct cfs_cpt_table *cptab, int cpt, const cpumask_t *mask); /** @@ -206,15 +231,15 @@ int cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt); /* * allocate per-cpu-partition data, returned value is an array of pointers, * variable can be indexed by CPU ID. - * cptab != NULL: size of array is number of CPU partitions - * cptab == NULL: size of array is number of HW cores + * cptab != NULL: size of array is number of CPU partitions + * cptab == NULL: size of array is number of HW cores */ void *cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size); /* - * destory per-cpu-partition variable + * destroy per-cpu-partition variable */ -void cfs_percpt_free(void *vars); -int cfs_percpt_number(void *vars); +void cfs_percpt_free(void *vars); +int cfs_percpt_number(void *vars); #define cfs_percpt_for_each(var, i, vars) \ for (i = 0; i < cfs_percpt_number(vars) && \ @@ -263,16 +288,17 @@ void cfs_percpt_lock_free(struct cfs_percpt_lock *pcl); /* lock private lock \a index of \a pcl */ void cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index); + /* unlock private lock \a index of \a pcl */ void cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index); -#define CFS_PERCPT_LOCK_KEYS 256 +#define CFS_PERCPT_LOCK_KEYS 256 /* NB: don't allocate keys dynamically, lockdep needs them to be in ".data" */ #define cfs_percpt_lock_alloc(cptab) \ ({ \ - static struct lock_class_key ___keys[CFS_PERCPT_LOCK_KEYS]; \ - struct cfs_percpt_lock *___lk; \ + static struct lock_class_key ___keys[CFS_PERCPT_LOCK_KEYS]; \ + struct cfs_percpt_lock *___lk; \ \ if (cfs_cpt_number(cptab) > CFS_PERCPT_LOCK_KEYS) \ ___lk = cfs_percpt_lock_create(cptab, NULL); \ @@ -341,14 +367,6 @@ 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++) -#ifndef __read_mostly -# define __read_mostly -#endif - -#ifndef ____cacheline_aligned -#define ____cacheline_aligned -#endif - int cfs_cpu_init(void); void cfs_cpu_fini(void); diff --git a/libcfs/include/libcfs/linux/linux-cpu.h b/libcfs/include/libcfs/linux/linux-cpu.h index 0903a0b..ab6b55e 100644 --- a/libcfs/include/libcfs/linux/linux-cpu.h +++ b/libcfs/include/libcfs/linux/linux-cpu.h @@ -39,53 +39,6 @@ #ifndef __LIBCFS_LINUX_CPU_H__ #define __LIBCFS_LINUX_CPU_H__ -#include -#include -#include -#include - -#ifdef CONFIG_SMP - -#define HAVE_LIBCFS_CPT - -/** virtual processing unit */ -struct cfs_cpu_partition { - /* CPUs mask for this partition */ - cpumask_t *cpt_cpumask; - /* nodes mask for this partition */ - nodemask_t *cpt_nodemask; - /* NUMA distance between CPTs */ - unsigned *cpt_distance; - /* spread rotor for NUMA allocator */ - int cpt_spread_rotor; - /* NUMA node if cpt_nodemask is empty */ - int cpt_node; -}; - -/** descriptor for CPU partitions */ -struct cfs_cpt_table { - /* spread rotor for NUMA allocator */ - int ctb_spread_rotor; - /* maximum NUMA distance between all nodes in table */ - unsigned 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_t *ctb_cpumask; - /* shadow HW node to CPU partition ID */ - int *ctb_node2cpt; - /* all nodes in this partition table */ - nodemask_t *ctb_nodemask; -}; - -void cfs_cpu_core_siblings(int cpu, cpumask_t *mask); - -#endif /* CONFIG_SMP */ - #ifndef HAVE_TOPOLOGY_SIBLING_CPUMASK # define topology_sibling_cpumask(cpu) topology_thread_cpumask(cpu) #endif /* HAVE_TOPOLOGY_SIBLING_CPUMASK */ diff --git a/libcfs/libcfs/libcfs_cpu.c b/libcfs/libcfs/libcfs_cpu.c index e829821..ca586b7 100644 --- a/libcfs/libcfs/libcfs_cpu.c +++ b/libcfs/libcfs/libcfs_cpu.c @@ -13,11 +13,6 @@ * General Public License version 2 for more details (a copy is included * in the LICENSE file that accompanied this code). * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA - * * GPL HEADER END */ /* @@ -39,14 +34,12 @@ #include /** Global CPU partition table */ -struct cfs_cpt_table *cfs_cpt_table __read_mostly = NULL; +struct cfs_cpt_table *cfs_cpt_table __read_mostly; EXPORT_SYMBOL(cfs_cpt_table); -#ifndef HAVE_LIBCFS_CPT - -#define CFS_CPU_VERSION_MAGIC 0xbabecafe +#ifndef CONFIG_SMP -#define CFS_CPT_DISTANCE 1 /* Arbitrary positive value */ +#define CFS_CPT_DISTANCE 1 /* Arbitrary positive value */ struct cfs_cpt_table *cfs_cpt_table_alloc(int ncpt) { @@ -58,11 +51,9 @@ struct cfs_cpt_table *cfs_cpt_table_alloc(int ncpt) } LIBCFS_ALLOC(cptab, sizeof(*cptab)); - if (cptab != NULL) { - cptab->ctb_version = CFS_CPU_VERSION_MAGIC; - cpu_set(0, cptab->ctb_cpumask); + if (cptab) { + cpumask_set_cpu(0, cptab->ctb_cpumask); node_set(0, cptab->ctb_nodemask); - cptab->ctb_nparts = ncpt; } return cptab; @@ -71,15 +62,13 @@ EXPORT_SYMBOL(cfs_cpt_table_alloc); void cfs_cpt_table_free(struct cfs_cpt_table *cptab) { - LASSERT(cptab->ctb_version == CFS_CPU_VERSION_MAGIC); - LIBCFS_FREE(cptab, sizeof(*cptab)); } EXPORT_SYMBOL(cfs_cpt_table_free); int cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len) { - int rc = 0; + int rc; rc = snprintf(buf, len, "%d\t: %d\n", 0, 0); len -= rc; @@ -92,9 +81,9 @@ EXPORT_SYMBOL(cfs_cpt_table_print); int cfs_cpt_distance_print(struct cfs_cpt_table *cptab, char *buf, int len) { - int rc = 0; + int rc; - rc = snprintf(buf, len, "%d\t: %d:%d\n", 0, CFS_CPT_DISTANCE); + rc = snprintf(buf, len, "0\t: 0:%d\n", CFS_CPT_DISTANCE); len -= rc; if (len <= 0) return -EFBIG; @@ -123,7 +112,7 @@ EXPORT_SYMBOL(cfs_cpt_online); cpumask_t *cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt) { - return &cptab->ctb_mask; + return &cptab->ctb_cpumask; } EXPORT_SYMBOL(cfs_cpt_cpumask); @@ -133,7 +122,7 @@ nodemask_t *cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt) } EXPORT_SYMBOL(cfs_cpt_nodemask); -unsigned cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2) +unsigned int cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2) { return CFS_CPT_DISTANCE; } @@ -219,7 +208,7 @@ EXPORT_SYMBOL(cfs_cpt_bind); void cfs_cpu_fini(void) { - if (cfs_cpt_table != NULL) { + if (cfs_cpt_table) { cfs_cpt_table_free(cfs_cpt_table); cfs_cpt_table = NULL; } @@ -229,7 +218,7 @@ int cfs_cpu_init(void) { cfs_cpt_table = cfs_cpt_table_alloc(1); - return cfs_cpt_table != NULL ? 0 : -1; + return cfs_cpt_table ? 0 : -1; } -#endif /* HAVE_LIBCFS_CPT */ +#endif /* !CONFIG_SMP */ diff --git a/libcfs/libcfs/linux/linux-cpu.c b/libcfs/libcfs/linux/linux-cpu.c index 8551174..e8cd2a7 100644 --- a/libcfs/libcfs/linux/linux-cpu.c +++ b/libcfs/libcfs/linux/linux-cpu.c @@ -13,11 +13,6 @@ * General Public License version 2 for more details (a copy is included * in the LICENSE file that accompanied this code). * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA - * * GPL HEADER END */ /* @@ -72,25 +67,25 @@ void cfs_cpt_table_free(struct cfs_cpt_table *cptab) { int i; - if (cptab->ctb_cpu2cpt != NULL) { + if (cptab->ctb_cpu2cpt) { LIBCFS_FREE(cptab->ctb_cpu2cpt, nr_cpu_ids * sizeof(cptab->ctb_cpu2cpt[0])); } - if (cptab->ctb_node2cpt != NULL) { + if (cptab->ctb_node2cpt) { LIBCFS_FREE(cptab->ctb_node2cpt, nr_node_ids * sizeof(cptab->ctb_node2cpt[0])); } - for (i = 0; cptab->ctb_parts != NULL && i < cptab->ctb_nparts; i++) { + for (i = 0; cptab->ctb_parts && i < cptab->ctb_nparts; i++) { struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; - if (part->cpt_nodemask != NULL) { + if (part->cpt_nodemask) { LIBCFS_FREE(part->cpt_nodemask, sizeof(*part->cpt_nodemask)); } - if (part->cpt_cpumask != NULL) + if (part->cpt_cpumask) LIBCFS_FREE(part->cpt_cpumask, cpumask_size()); if (part->cpt_distance) { @@ -100,14 +95,14 @@ void cfs_cpt_table_free(struct cfs_cpt_table *cptab) } } - if (cptab->ctb_parts != NULL) { + if (cptab->ctb_parts) { LIBCFS_FREE(cptab->ctb_parts, cptab->ctb_nparts * sizeof(cptab->ctb_parts[0])); } - if (cptab->ctb_nodemask != NULL) + if (cptab->ctb_nodemask) LIBCFS_FREE(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); - if (cptab->ctb_cpumask != NULL) + if (cptab->ctb_cpumask) LIBCFS_FREE(cptab->ctb_cpumask, cpumask_size()); LIBCFS_FREE(cptab, sizeof(*cptab)); @@ -120,7 +115,7 @@ struct cfs_cpt_table *cfs_cpt_table_alloc(int ncpt) int i; LIBCFS_ALLOC(cptab, sizeof(*cptab)); - if (cptab == NULL) + if (!cptab) return NULL; cptab->ctb_nparts = ncpt; @@ -128,12 +123,12 @@ struct cfs_cpt_table *cfs_cpt_table_alloc(int ncpt) LIBCFS_ALLOC(cptab->ctb_cpumask, cpumask_size()); LIBCFS_ALLOC(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); - if (cptab->ctb_cpumask == NULL || cptab->ctb_nodemask == NULL) + if (!cptab->ctb_cpumask || !cptab->ctb_nodemask) goto failed; LIBCFS_ALLOC(cptab->ctb_cpu2cpt, nr_cpu_ids * sizeof(cptab->ctb_cpu2cpt[0])); - if (cptab->ctb_cpu2cpt == NULL) + if (!cptab->ctb_cpu2cpt) goto failed; memset(cptab->ctb_cpu2cpt, -1, @@ -141,14 +136,14 @@ struct cfs_cpt_table *cfs_cpt_table_alloc(int ncpt) LIBCFS_ALLOC(cptab->ctb_node2cpt, nr_node_ids * sizeof(cptab->ctb_node2cpt[0])); - if (cptab->ctb_node2cpt == NULL) + if (!cptab->ctb_node2cpt) goto failed; memset(cptab->ctb_node2cpt, -1, nr_node_ids * sizeof(cptab->ctb_node2cpt[0])); LIBCFS_ALLOC(cptab->ctb_parts, ncpt * sizeof(cptab->ctb_parts[0])); - if (cptab->ctb_parts == NULL) + if (!cptab->ctb_parts) goto failed; for (i = 0; i < ncpt; i++) { @@ -234,7 +229,7 @@ int cfs_cpt_distance_print(struct cfs_cpt_table *cptab, char *buf, int len) tmp += rc; for (j = 0; j < cptab->ctb_nparts; j++) { rc = snprintf(tmp, len, " %d:%d", - j, cptab->ctb_parts[i].cpt_distance[j]); + j, cptab->ctb_parts[i].cpt_distance[j]); len -= rc; if (len <= 0) goto err; @@ -299,7 +294,7 @@ nodemask_t *cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt) } EXPORT_SYMBOL(cfs_cpt_nodemask); -unsigned cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2) +unsigned int cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2) { LASSERT(cpt1 == CFS_CPT_ANY || (cpt1 >= 0 && cpt1 < cptab->ctb_nparts)); LASSERT(cpt2 == CFS_CPT_ANY || (cpt2 >= 0 && cpt2 < cptab->ctb_nparts)); @@ -315,13 +310,13 @@ EXPORT_SYMBOL(cfs_cpt_distance); * Calculate the maximum NUMA distance between all nodes in the * from_mask and all nodes in the to_mask. */ -static unsigned cfs_cpt_distance_calculate(nodemask_t *from_mask, - nodemask_t *to_mask) +static unsigned int cfs_cpt_distance_calculate(nodemask_t *from_mask, + nodemask_t *to_mask) { - unsigned maximum; - unsigned distance; - int to; + unsigned int maximum; + unsigned int distance; int from; + int to; maximum = 0; for_each_node_mask(from, *from_mask) { @@ -352,43 +347,45 @@ static void cfs_cpt_del_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu) static void cfs_cpt_add_node(struct cfs_cpt_table *cptab, int cpt, int node) { - int cpt2; struct cfs_cpu_partition *part; - struct cfs_cpu_partition *part2; if (!node_isset(node, *cptab->ctb_nodemask)) { + unsigned int dist; + /* first time node is added to the CPT table */ node_set(node, *cptab->ctb_nodemask); cptab->ctb_node2cpt[node] = cpt; - cptab->ctb_distance = cfs_cpt_distance_calculate( - cptab->ctb_nodemask, - cptab->ctb_nodemask); + + dist = cfs_cpt_distance_calculate(cptab->ctb_nodemask, + cptab->ctb_nodemask); + cptab->ctb_distance = dist; } part = &cptab->ctb_parts[cpt]; if (!node_isset(node, *part->cpt_nodemask)) { + int cpt2; + /* first time node is added to this CPT */ node_set(node, *part->cpt_nodemask); for (cpt2 = 0; cpt2 < cptab->ctb_nparts; cpt2++) { + struct cfs_cpu_partition *part2; + unsigned int dist; + part2 = &cptab->ctb_parts[cpt2]; - part->cpt_distance[cpt2] = cfs_cpt_distance_calculate( - part->cpt_nodemask, - part2->cpt_nodemask); - part2->cpt_distance[cpt] = cfs_cpt_distance_calculate( - part2->cpt_nodemask, - part->cpt_nodemask); + dist = cfs_cpt_distance_calculate(part->cpt_nodemask, + part2->cpt_nodemask); + part->cpt_distance[cpt2] = dist; + dist = cfs_cpt_distance_calculate(part2->cpt_nodemask, + part->cpt_nodemask); + part2->cpt_distance[cpt] = dist; } } } static void cfs_cpt_del_node(struct cfs_cpt_table *cptab, int cpt, int node) { + struct cfs_cpu_partition *part = &cptab->ctb_parts[cpt]; int cpu; - int cpt2; - struct cfs_cpu_partition *part; - struct cfs_cpu_partition *part2; - - part = &cptab->ctb_parts[cpt]; for_each_cpu(cpu, part->cpt_cpumask) { /* this CPT has other CPU belonging to this node? */ @@ -397,18 +394,24 @@ static void cfs_cpt_del_node(struct cfs_cpt_table *cptab, int cpt, int node) } if (cpu >= nr_cpu_ids && node_isset(node, *part->cpt_nodemask)) { + int cpt2; + /* No more CPUs in the node for this CPT. */ node_clear(node, *part->cpt_nodemask); for (cpt2 = 0; cpt2 < cptab->ctb_nparts; cpt2++) { + struct cfs_cpu_partition *part2; + unsigned int dist; + part2 = &cptab->ctb_parts[cpt2]; if (node_isset(node, *part2->cpt_nodemask)) cptab->ctb_node2cpt[node] = cpt2; - part->cpt_distance[cpt2] = cfs_cpt_distance_calculate( - part->cpt_nodemask, - part2->cpt_nodemask); - part2->cpt_distance[cpt] = cfs_cpt_distance_calculate( - part2->cpt_nodemask, - part->cpt_nodemask); + + dist = cfs_cpt_distance_calculate(part->cpt_nodemask, + part2->cpt_nodemask); + part->cpt_distance[cpt2] = dist; + dist = cfs_cpt_distance_calculate(part2->cpt_nodemask, + part->cpt_nodemask); + part2->cpt_distance[cpt] = dist; } } @@ -424,7 +427,7 @@ static void cfs_cpt_del_node(struct cfs_cpt_table *cptab, int cpt, int node) cptab->ctb_node2cpt[node] = -1; cptab->ctb_distance = cfs_cpt_distance_calculate(cptab->ctb_nodemask, - cptab->ctb_nodemask); + cptab->ctb_nodemask); } } @@ -447,6 +450,7 @@ int cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu) CDEBUG(D_INFO, "CPU %d is already in cpumask\n", cpu); return 0; } + if (cpumask_test_cpu(cpu, cptab->ctb_parts[cpt].cpt_cpumask)) { CDEBUG(D_INFO, "CPU %d is already in partition %d cpumask\n", cpu, cptab->ctb_cpu2cpt[cpu]); @@ -473,13 +477,15 @@ void cfs_cpt_unset_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu) /* caller doesn't know the partition ID */ cpt = cptab->ctb_cpu2cpt[cpu]; if (cpt < 0) { /* not set in this CPT-table */ - CDEBUG(D_INFO, "Try to unset cpu %d which is " - "not in CPT-table %p\n", cpt, cptab); + CDEBUG(D_INFO, + "Try to unset cpu %d which is not in CPT-table %p\n", + cpt, cptab); return; } } else if (cpt != cptab->ctb_cpu2cpt[cpu]) { - CDEBUG(D_INFO, "CPU %d is not in CPU partition %d\n", cpu, cpt); + CDEBUG(D_INFO, + "CPU %d is not in CPU partition %d\n", cpu, cpt); return; } @@ -496,10 +502,11 @@ int cfs_cpt_set_cpumask(struct cfs_cpt_table *cptab, int cpt, { int cpu; - if (cpumask_weight(mask) == 0 || + if (!cpumask_weight(mask) || cpumask_any_and(mask, cpu_online_mask) >= nr_cpu_ids) { - CDEBUG(D_INFO, "No online CPU is found in the CPU mask " - "for CPU partition %d\n", cpt); + CDEBUG(D_INFO, + "No online CPU is found in the CPU mask for CPU partition %d\n", + cpt); return 0; } @@ -598,10 +605,10 @@ int cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt) /* convert CPU partition ID to HW node id */ if (cpt < 0 || cpt >= cptab->ctb_nparts) { - mask = cptab->ctb_nodemask; + mask = cptab->ctb_nodemask; rotor = cptab->ctb_spread_rotor++; } else { - mask = cptab->ctb_parts[cpt].cpt_nodemask; + mask = cptab->ctb_parts[cpt].cpt_nodemask; rotor = cptab->ctb_parts[cpt].cpt_spread_rotor++; node = cptab->ctb_parts[cpt].cpt_node; } @@ -611,7 +618,7 @@ int cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt) rotor %= weight; for_each_node_mask(node, *mask) { - if (rotor-- == 0) + if (!rotor--) return node; } } @@ -630,7 +637,8 @@ int cfs_cpt_current(struct cfs_cpt_table *cptab, int remap) return cpt; /* don't return negative value for safety of upper layer, - * instead we shadow the unknown cpu to a valid partition ID */ + * instead we shadow the unknown cpu to a valid partition ID + */ cpt = cpu % cptab->ctb_nparts; } @@ -673,9 +681,8 @@ int cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt) } if (!cpumask_intersects(cpumask, cpu_online_mask)) { - CDEBUG(D_INFO, "No online CPU found in CPU partition %d, did " - "someone do CPU hotplug on system? You might need to " - "reload Lustre modules to keep system working well.\n", + CDEBUG(D_INFO, + "No online CPU found in CPU partition %d, did someone do CPU hotplug on system? You might need to reload Lustre modules to keep system working well.\n", cpt); return -ENODEV; } @@ -686,7 +693,7 @@ int cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt) rc = set_cpus_allowed_ptr(current, cpumask); set_mems_allowed(*nodemask); - if (rc == 0) + if (!rc) schedule(); /* switch to allowed CPU */ return rc; @@ -730,7 +737,7 @@ static int cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, /* allocate scratch buffer */ LIBCFS_ALLOC(socket_mask, cpumask_size()); LIBCFS_ALLOC(core_mask, cpumask_size()); - if (socket_mask == NULL || core_mask == NULL) { + if (!socket_mask || !core_mask) { rc = -ENOMEM; goto out; } @@ -742,8 +749,8 @@ static int cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, cpumask_and(socket_mask, topology_core_cpumask(cpu), node_mask); while (!cpumask_empty(socket_mask)) { /* get cpumask for hts in the same core */ - cpumask_and(core_mask, - topology_sibling_cpumask(cpu), node_mask); + cpumask_and(core_mask, topology_sibling_cpumask(cpu), + node_mask); for_each_cpu(i, core_mask) { cpumask_clear_cpu(i, socket_mask); @@ -758,7 +765,7 @@ static int cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, goto out; } - if (--number == 0) + if (!--number) goto out; } cpu = cpumask_first(socket_mask); @@ -766,9 +773,9 @@ static int cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, } out: - if (core_mask != NULL) + if (core_mask) LIBCFS_FREE(core_mask, cpumask_size()); - if (socket_mask != NULL) + if (socket_mask) LIBCFS_FREE(socket_mask, cpumask_size()); return rc; } @@ -778,19 +785,20 @@ out: static int cfs_cpt_num_estimate(void) { int nthr = cpumask_weight(topology_sibling_cpumask(smp_processor_id())); - int ncpu = num_online_cpus(); + int ncpu = num_online_cpus(); int ncpt = 1; if (ncpu > CPT_WEIGHT_MIN) - for (ncpt = 2; ncpu > 2 * nthr * ncpt; ncpt++); - /* nothing */ + for (ncpt = 2; ncpu > 2 * nthr * ncpt; ncpt++) + ; /* nothing */ #if (BITS_PER_LONG == 32) /* config many CPU partitions on 32-bit system could consume - * too much memory */ + * too much memory + */ ncpt = min(2, ncpt); #endif - while (ncpu % ncpt != 0) + while (ncpu % ncpt) ncpt--; /* worst case is 1 */ return ncpt; @@ -811,21 +819,19 @@ static struct cfs_cpt_table *cfs_cpt_table_create(int ncpt) ncpt = num; if (ncpt > num_online_cpus() || ncpt > 4 * num) { - CWARN("CPU partition number %d is larger than suggested " - "value (%d), your system may have performance " - "issue or run out of memory while under pressure\n", + CWARN("CPU partition number %d is larger than suggested value (%d), your system may have performance issue or run out of memory while under pressure\n", ncpt, num); } cptab = cfs_cpt_table_alloc(ncpt); - if (cptab == NULL) { + if (!cptab) { CERROR("Failed to allocate CPU map(%d)\n", ncpt); rc = -ENOMEM; goto failed; } LIBCFS_ALLOC(node_mask, cpumask_size()); - if (node_mask == NULL) { + if (!node_mask) { CERROR("Failed to allocate scratch cpumask\n"); rc = -ENOMEM; goto failed; @@ -844,7 +850,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create(int ncpt) num - ncpu); if (rc < 0) { rc = -EINVAL; - goto failed; + goto failed_mask; } ncpu = cpumask_weight(part->cpt_cpumask); @@ -856,17 +862,17 @@ static struct cfs_cpt_table *cfs_cpt_table_create(int ncpt) } LIBCFS_FREE(node_mask, cpumask_size()); - return cptab; -failed: - CERROR("Failed (rc=%d) to setup CPU partition table with %d " - "partitions, online HW NUMA nodes: %d, HW CPU cores: %d.\n", - rc, ncpt, num_online_nodes(), num_online_cpus()); + return cptab; - if (node_mask != NULL) +failed_mask: + if (node_mask) LIBCFS_FREE(node_mask, cpumask_size()); +failed: + CERROR("Failed (rc = %d) to setup CPU partition table with %d partitions, online HW NUMA nodes: %d, HW CPU cores: %d.\n", + rc, ncpt, num_online_nodes(), num_online_cpus()); - if (cptab != NULL) + if (cptab) cfs_cpt_table_free(cptab); return ERR_PTR(rc); @@ -880,14 +886,14 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) char *str; int node = 0; int ncpt = 0; - int cpt = 0; + int cpt = 0; int high; int rc; int c; int i; pattern_dup = kstrdup(pattern, GFP_KERNEL); - if (pattern_dup == NULL) { + if (!pattern_dup) { CERROR("Failed to duplicate pattern '%s'\n", pattern); return ERR_PTR(-ENOMEM); } @@ -909,7 +915,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) } } - if (ncpt == 0) { /* scanning bracket which is mark of partition */ + if (!ncpt) { /* scanning bracket which is mark of partition */ bracket = str; while ((bracket = strchr(bracket, '['))) { bracket++; @@ -917,7 +923,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) } } - if (ncpt == 0 || + if (!ncpt || (node && ncpt > num_online_nodes()) || (!node && ncpt > num_online_cpus())) { CERROR("Invalid pattern '%s', or too many partitions %d\n", @@ -927,7 +933,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) } cptab = cfs_cpt_table_alloc(ncpt); - if (cptab == NULL) { + if (!cptab) { CERROR("Failed to allocate CPU partition table\n"); rc = -ENOMEM; goto err_free_str; @@ -956,14 +962,14 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) int n; bracket = strchr(str, '['); - if (bracket == NULL) { - if (*str != 0) { + if (!bracket) { + if (*str) { CERROR("Invalid pattern '%s'\n", str); rc = -EINVAL; goto err_free_table; } else if (c != ncpt) { CERROR("Expect %d partitions but found %d\n", - ncpt, c); + ncpt, c); rc = -EINVAL; goto err_free_table; } @@ -983,7 +989,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) goto err_free_table; } - if (cfs_cpt_weight(cptab, cpt) != 0) { + if (cfs_cpt_weight(cptab, cpt)) { CERROR("Partition %d has already been set.\n", cpt); rc = -EPERM; goto err_free_table; @@ -997,9 +1003,9 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) } bracket = strchr(str, ']'); - if (bracket == NULL) { - CERROR("Missing right bracket for partition " - "%d in '%s'\n", cpt, str); + if (!bracket) { + CERROR("Missing right bracket for partition %d in '%s'\n", + cpt, str); rc = -EINVAL; goto err_free_table; } @@ -1014,7 +1020,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) list_for_each_entry(range, &el->el_exprs, re_link) { for (i = range->re_lo; i <= range->re_hi; i++) { - if ((i - range->re_lo) % range->re_stride != 0) + if ((i - range->re_lo) % range->re_stride) continue; rc = node ? cfs_cpt_set_node(cptab, cpt, i) @@ -1144,11 +1150,11 @@ int cfs_cpu_init(void) ret = -EINVAL; get_online_cpus(); - if (*cpu_pattern != 0) { + if (*cpu_pattern) { cfs_cpt_table = cfs_cpt_table_create_pattern(cpu_pattern); if (IS_ERR(cfs_cpt_table)) { CERROR("Failed to create cptab from pattern '%s'\n", - cpu_pattern); + cpu_pattern); ret = PTR_ERR(cfs_cpt_table); goto failed; } @@ -1157,11 +1163,12 @@ int cfs_cpu_init(void) cfs_cpt_table = cfs_cpt_table_create(cpu_npartitions); if (IS_ERR(cfs_cpt_table)) { CERROR("Failed to create cptab with npartitions %d\n", - cpu_npartitions); + cpu_npartitions); ret = PTR_ERR(cfs_cpt_table); goto failed; } } + put_online_cpus(); LCONSOLE(0, "HW NUMA nodes: %d, HW CPU cores: %d, npartitions: %d\n", -- 1.8.3.1