rcu: Cleanup rcu_init_geometry() code and arithmetics
authorAlexander Gordeev <agordeev@redhat.com>
Wed, 3 Jun 2015 06:18:25 +0000 (08:18 +0200)
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Wed, 15 Jul 2015 21:45:14 +0000 (14:45 -0700)
This update simplifies rcu_init_geometry() code flow
and makes calculation of the total number of rcu_node
structures more easy to read.

The update relies on the fact num_rcu_lvl[] is never
accessed beyond rcu_num_lvls index by the rest of the
code. Therefore, there is no need initialize the whole
num_rcu_lvl[].

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
kernel/rcu/tree.c

index ad49dbe..37ca8a8 100644 (file)
@@ -4082,7 +4082,6 @@ static void __init rcu_init_geometry(void)
 {
        ulong d;
        int i;
-       int j;
        int rcu_capacity[MAX_RCU_LVLS + 1];
 
        /*
@@ -4135,24 +4134,21 @@ static void __init rcu_init_geometry(void)
        if (nr_cpu_ids > rcu_capacity[MAX_RCU_LVLS])
                panic("rcu_init_geometry: rcu_capacity[] is too small");
 
+       /* Calculate the number of levels in the tree. */
+       for (i = 1; nr_cpu_ids > rcu_capacity[i]; i++) {
+       }
+       rcu_num_lvls = i;
+
        /* Calculate the number of rcu_nodes at each level of the tree. */
-       for (i = 1; i <= MAX_RCU_LVLS; i++)
-               if (nr_cpu_ids <= rcu_capacity[i]) {
-                       for (j = 0; j <= i; j++) {
-                               int cap = rcu_capacity[i - j];
-                               num_rcu_lvl[j] = DIV_ROUND_UP(nr_cpu_ids, cap);
-                       }
-                       rcu_num_lvls = i;
-                       for (j = i + 1; j <= MAX_RCU_LVLS; j++)
-                               num_rcu_lvl[j] = 0;
-                       break;
-               }
+       for (i = 0; i < rcu_num_lvls; i++) {
+               int cap = rcu_capacity[rcu_num_lvls - i];
+               num_rcu_lvl[i] = DIV_ROUND_UP(nr_cpu_ids, cap);
+       }
 
        /* Calculate the total number of rcu_node structures. */
        rcu_num_nodes = 0;
-       for (i = 0; i <= MAX_RCU_LVLS; i++)
+       for (i = 0; i < rcu_num_lvls; i++)
                rcu_num_nodes += num_rcu_lvl[i];
-       rcu_num_nodes -= nr_cpu_ids;
 }
 
 /*