rcuja: print info about allocated/freed/fallback nodes
[userspace-rcu.git] / rcuja / rcuja.c
index b9c8a6377f07ee97a70b3587ea35ba24d922d678..e59ebe395f465dc9c7646a931de9b01411da012b 100644 (file)
@@ -246,6 +246,8 @@ enum ja_recompact {
 
 static
 unsigned long node_fallback_count_distribution[JA_ENTRY_PER_NODE];
+static
+unsigned long nr_nodes_allocated, nr_nodes_freed;
 
 static
 struct cds_ja_inode *_ja_node_mask_ptr(struct cds_ja_inode_flag *node)
@@ -300,12 +302,14 @@ struct cds_ja_inode *alloc_cds_ja_node(const struct cds_ja_type *ja_type)
                return NULL;
        }
        memset(p, 0, len);
+       uatomic_inc(&nr_nodes_allocated);
        return p;
 }
 
 void free_cds_ja_node(struct cds_ja_inode *node)
 {
        free(node);
+       uatomic_inc(&nr_nodes_freed);
 }
 
 #define __JA_ALIGN_MASK(v, mask)       (((v) + (mask)) & ~(mask))
@@ -977,11 +981,14 @@ void ja_node_sum_distribution_2d(enum ja_recompact mode,
                nr_2d_01[JA_BITS_PER_BYTE][JA_BITS_PER_BYTE],
                nr_2d_00[JA_BITS_PER_BYTE][JA_BITS_PER_BYTE];
        unsigned int bitsel[2] = { 0, 1 };
-       unsigned int bit_i, bit_j, overall_best_distance = UINT_MAX;
+       unsigned int bit_i, bit_j;
+       int overall_best_distance = INT_MAX;
        unsigned int distrib_nr_child = 0;
 
        memset(nr_2d_11, 0, sizeof(nr_2d_11));
        memset(nr_2d_10, 0, sizeof(nr_2d_10));
+       memset(nr_2d_01, 0, sizeof(nr_2d_01));
+       memset(nr_2d_00, 0, sizeof(nr_2d_00));
 
        switch (type->type_class) {
        case RCU_JA_LINEAR:
@@ -1134,20 +1141,21 @@ void ja_node_sum_distribution_2d(enum ja_recompact mode,
         */
        for (bit_i = 0; bit_i < JA_BITS_PER_BYTE; bit_i++) {
                for (bit_j = 0; bit_j < bit_i; bit_j++) {
-                       unsigned int distance_to_best[4];
+                       int distance_to_best[4];
 
-                       distance_to_best[0] = nr_2d_11[bit_i][bit_j];
-                       distance_to_best[1] = nr_2d_10[bit_i][bit_j];
-                       distance_to_best[2] = nr_2d_01[bit_i][bit_j];
-                       distance_to_best[3] = nr_2d_00[bit_i][bit_j];
+                       distance_to_best[0] = (nr_2d_11[bit_i][bit_j] << 2U) - distrib_nr_child;
+                       distance_to_best[1] = (nr_2d_10[bit_i][bit_j] << 2U) - distrib_nr_child;
+                       distance_to_best[2] = (nr_2d_01[bit_i][bit_j] << 2U) - distrib_nr_child;
+                       distance_to_best[3] = (nr_2d_00[bit_i][bit_j] << 2U) - distrib_nr_child;
 
-                       /* Consider worse distance to best */
-                       if (distance_to_best[1] > distance_to_best[0])
+                       /* Consider worse distance above best */
+                       if (distance_to_best[1] > 0 && distance_to_best[1] > distance_to_best[0])
                                distance_to_best[0] = distance_to_best[1];
-                       if (distance_to_best[2] > distance_to_best[0])
+                       if (distance_to_best[2] > 0 && distance_to_best[2] > distance_to_best[0])
                                distance_to_best[0] = distance_to_best[2];
-                       if (distance_to_best[3] > distance_to_best[0])
+                       if (distance_to_best[3] > 0 && distance_to_best[3] > distance_to_best[0])
                                distance_to_best[0] = distance_to_best[3];
+
                        /*
                         * If our worse distance is better than overall,
                         * we become new best candidate.
@@ -1473,7 +1481,7 @@ fallback_toosmall:
                 * node within a pool has unused entries. It should
                 * therefore _never_ be too small.
                 */
-               //TODO assert(0);
+               assert(0);
 
                /* Fall-through */
        case JA_RECOMPACT_ADD_NEXT:
@@ -2408,6 +2416,10 @@ int cds_ja_destroy(struct cds_ja *ja,
                fprintf(stderr,
                        "[warning] RCU Judy Array used %lu fallback node(s)\n",
                        uatomic_read(&ja->nr_fallback));
+       fprintf(stderr, "Nodes allocated: %lu, Nodes freed: %lu. Fallback ratio: %g\n",
+               uatomic_read(&nr_nodes_allocated),
+               uatomic_read(&nr_nodes_freed),
+               (double) uatomic_read(&ja->nr_fallback) / (double) uatomic_read(&nr_nodes_allocated));
        print_debug_fallback_distribution();
        free(ja);
        return 0;
This page took 0.024802 seconds and 4 git commands to generate.