X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Flibcfs%2Flibcfs_cpu.c;h=127b63ad1f86e09c06a13e8d970539c8cd2a7ffb;hb=e33e3da58972a811e6eafc479f95f6df2baf4b9b;hp=18c4839ca9b9303caba8e443361a15509c2c2147;hpb=454a5f5c5496bdea667223a1608d885024f658af;p=fs%2Flustre-release.git diff --git a/libcfs/libcfs/libcfs_cpu.c b/libcfs/libcfs/libcfs_cpu.c index 18c4839..127b63a 100644 --- a/libcfs/libcfs/libcfs_cpu.c +++ b/libcfs/libcfs/libcfs_cpu.c @@ -678,19 +678,20 @@ EXPORT_SYMBOL(cfs_cpt_spread_node); int cfs_cpt_current(struct cfs_cpt_table *cptab, int remap) { - int cpu = smp_processor_id(); - int cpt = cptab->ctb_cpu2cpt[cpu]; + int cpu; + int cpt; - if (cpt < 0) { - if (!remap) - return cpt; + preempt_disable(); + cpu = smp_processor_id(); + cpt = cptab->ctb_cpu2cpt[cpu]; + if (cpt < 0 && remap) { /* don't return negative value for safety of upper layer, * instead we shadow the unknown cpu to a valid partition ID */ cpt = cpu % cptab->ctb_nparts; } - + preempt_enable(); return cpt; } EXPORT_SYMBOL(cfs_cpt_current); @@ -867,7 +868,14 @@ static struct cfs_cpt_table *cfs_cpt_table_create(int ncpt) if (ncpt <= 0) ncpt = num; - if (ncpt > num_online_cpus() || ncpt > 4 * num) { + if (ncpt > num_online_cpus()) { + rc = -EINVAL; + CERROR("libcfs: CPU partition count %d > cores %d: rc = %d\n", + ncpt, num_online_cpus(), rc); + goto failed; + } + + if (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", ncpt, num); } @@ -896,7 +904,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create(int ncpt) int ncpu = cpumask_weight(part->cpt_cpumask); rc = cfs_cpt_choose_ncpus(cptab, cpt, node_mask, - num - ncpu); + (rem > 0) + num - ncpu); if (rc < 0) { rc = -EINVAL; goto failed_mask; @@ -947,7 +955,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) return ERR_PTR(-ENOMEM); } - str = cfs_trimwhite(pattern_dup); + str = strim(pattern_dup); if (*str == 'n' || *str == 'N') { str++; /* skip 'N' char */ node = 1; /* NUMA pattern */ @@ -1005,7 +1013,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) high = node ? nr_node_ids - 1 : nr_cpu_ids - 1; - for (str = cfs_trimwhite(str), c = 0; /* until break */; c++) { + for (str = strim(str), c = 0; /* until break */; c++) { struct cfs_range_expr *range; struct cfs_expr_list *el; int n; @@ -1044,7 +1052,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) goto err_free_table; } - str = cfs_trimwhite(str + n); + str = strim(str + n); if (str != bracket) { CERROR("Invalid pattern '%s'\n", str); rc = -EINVAL; @@ -1090,7 +1098,7 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern) goto err_free_table; } - str = cfs_trimwhite(bracket + 1); + str = strim(bracket + 1); } kfree(pattern_dup); @@ -1229,7 +1237,7 @@ int cfs_cpu_init(void) failed_alloc_table: put_online_cpus(); - if (cfs_cpt_table) + if (!IS_ERR_OR_NULL(cfs_cpt_table)) cfs_cpt_table_free(cfs_cpt_table); #ifdef CONFIG_HOTPLUG_CPU