Whamcloud - gitweb
LU-8703 libcfs: change CPT estimate algorithm
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-cpu.c
index 7db6a0f..59e9986 100644 (file)
@@ -777,33 +777,14 @@ out:
 
 static int cfs_cpt_num_estimate(void)
 {
-       int nnode = num_online_nodes();
+       int nthr = cpumask_weight(topology_sibling_cpumask(smp_processor_id()));
        int ncpu  = num_online_cpus();
-       int ncpt;
+       int ncpt = 1;
 
-       if (ncpu <= CPT_WEIGHT_MIN) {
-               ncpt = 1;
-               goto out;
-       }
-
-       /* generate reasonable number of CPU partitions based on total number
-        * of CPUs, Preferred N should be power2 and match this condition:
-        * 2 * (N - 1)^2 < NCPUS <= 2 * N^2 */
-       for (ncpt = 2; ncpu > 2 * ncpt * ncpt; ncpt <<= 1)
-               ;
+       if (ncpu > CPT_WEIGHT_MIN)
+               for (ncpt = 2; ncpu > 2 * nthr * ncpt; ncpt++);
+                       /* nothing */
 
-       if (ncpt <= nnode) { /* fat numa system */
-               while (nnode > ncpt)
-                       nnode >>= 1;
-
-       } else { /* ncpt > nnode */
-               while ((nnode << 1) <= ncpt)
-                       nnode <<= 1;
-       }
-
-       ncpt = nnode;
-
-out:
 #if (BITS_PER_LONG == 32)
        /* config many CPU partitions on 32-bit system could consume
         * too much memory */
@@ -925,8 +906,11 @@ static struct cfs_cpt_table *cfs_cpt_table_create_pattern(const char *pattern)
        }
 
        if (ncpt == 0) { /* scanning bracket which is mark of partition */
-               for (bracket = str; bracket != NULL; bracket++, ncpt++)
-                       bracket = strchr(bracket, '[');
+               bracket = str;
+               while ((bracket = strchr(bracket, '['))) {
+                       bracket++;
+                       ncpt++;
+               }
        }
 
        if (ncpt == 0 ||