From: Liam R. Howlett Date: Tue, 6 May 2025 15:34:24 +0000 (-0400) Subject: ditch debug and some cleanup X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b9cfa9c314a7d2f1d85c4d09e0b5801bb47ae51f;p=users%2Fjedix%2Flinux-maple.git ditch debug and some cleanup Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index e9e0914bdece..33baf4f62649 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3158,24 +3158,20 @@ void mns_node_part_leaf_init(struct ma_node_part *part, if (wr_mas->r_min < wr_mas->mas->index) { part->pivots[0] = wr_mas->mas->index - 1; part->slots[0] = wr_mas->content; - printk("%s zero piv is %lu\n", __func__,part->pivots[part->size]); part->size++; } part->pivots[part->size] = wr_mas->mas->last; part->slots[part->size] = wr_mas->entry; - printk("%s one piv is %lu\n", __func__,part->pivots[part->size]); part->size++; if (wr_mas->end_piv > wr_mas->mas->last) { part->pivots[part->size] = wr_mas->end_piv; part->slots[part->size] = src->slots[wr_mas->offset_end]; - printk("%s last piv is %lx\n", __func__,part->pivots[part->size]); part->size++; } part->skip = wr_mas->offset_end - wr_mas->mas->offset + 1; - printk("skip %u\n", part->skip); part->leaf = true; } @@ -3404,8 +3400,6 @@ void mni_finalise(struct ma_node_info *p, struct split_data *sd) unsigned long max_gap; unsigned char len; - if (!sd->is_alloc) - printk("\n\n\nNOT ALLOC\n\n\n"); len = mt_slots[p->type] - p->offset; if (len) { memset(p->slots + p->offset, 0, len * sizeof(void *)); @@ -3469,13 +3463,8 @@ finalise_leaf: if (p->offset <= mt_pivots[p->type]) { ma_set_meta(p->node, p->type, 0, p->offset - 1); } - if (p->max != ULONG_MAX) { - if (p->slots[p->offset - 1] == NULL) { - printk("last slot %u has %lu\n", p->offset - 1, - p->pivots[p->offset - 1]); - } + if (p->max != ULONG_MAX) BUG_ON(p->slots[p->offset - 1] == NULL); - } } else { unsigned long gap_off = 0; if (p->gaps) { @@ -3584,8 +3573,6 @@ void mns_assemble(struct ma_node_state *states, unsigned char len) if (last_dst != ns->dst) { WARN_ON_ONCE(!max); ns->dst->min = max + 1; - printk("%p max set to %lu\n", last_dst->node, last_dst->max); - printk("%p min set to %lu\n", ns->dst->node, ns->dst->min); } last_dst = ns->dst; @@ -3617,9 +3604,7 @@ void mns_assemble(struct ma_node_state *states, unsigned char len) if (ns->start + size > mt_pivots[ns->info->type]) { piv_overflow = 1; max = ns->info->max; - printk("max fro ns->info->max\n"); } else { - printk("max from %lu\n", size - 1 ); max = s_piv[size - 1]; } } @@ -3650,7 +3635,6 @@ static inline void mas_wr_converged(struct ma_node_info *src, { unsigned char off = 0; - printk("\t%s\n", __func__); sd->len = 0; mni_node_init(dst, mas_pop_node(mas), src->type); if (src->insert_off) { @@ -3667,12 +3651,12 @@ static inline void mas_wr_converged(struct ma_node_info *src, off += part->skip; if (src->end >= off) { - unsigned char start = off; - unsigned char size = src->end - start + 1; - mns_mni_init(&sd->states[sd->len], dst, start, size); + unsigned char size; + + size = src->end - off + 1; + mns_mni_init(&sd->states[sd->len], dst, off, size); sd->states[sd->len].info = src; sd->len++; - off += size - 1; } mns_assemble(sd->states, sd->len); @@ -3694,19 +3678,14 @@ static void split_state_setup(struct ma_node_info *src, unsigned char copied; /* Configure one state */ - printk("\t set up state %u\n", sd->len); - printk("\t insert from %u - %u\n", sd->insert, sd->insert_end); state = &sd->states[sd->len]; if (sd->offset >= sd->insert && sd->offset <= sd->insert_end) { copied = min(part->size - part->pos, sd->space); state->part = part; - printk("insert part at %u first entry is %p\n", sd->offset, part->slots[0]); - printk("Size is %u/%u\n", copied, part->size); mns_mni_init(state, dst, part->pos , copied); state->use_part = true; part->pos += copied; src->offset = sd->src_ins_end + 1; - printk("Set src %p offset to %u\n", src->node, src->offset); } else { state->info = src; if (sd->offset < sd->insert_end) { @@ -3714,21 +3693,17 @@ static void split_state_setup(struct ma_node_info *src, * First part of node, may split across node * boundaries though */ - printk("%d\n", __LINE__); copied = min(sd->space, sd->insert - sd->offset); } else { - printk("%d\n", __LINE__); copied = min(sd->space, (src->end - src->offset + 1)); } BUG_ON(copied == 0); - printk("src offset is %u\n", src->offset); mns_mni_init(state, dst, src->offset, copied); src->offset += copied; } sd->offset += copied; sd->space -= copied; - printk("offset %u split %u\n", sd->offset, sd->split); } /* @@ -3768,7 +3743,6 @@ static void mt_wr_split_data(struct ma_node_info *src, struct ma_node_state *state; - printk("%s\n", __func__); /* Offset into the destination data where the insert ends */ sd->insert_end = sd->insert + part->size - 1; to = left; @@ -3811,7 +3785,6 @@ static void mt_wr_split_data(struct ma_node_info *src, sd->split = 255; } sd->len++; - printk("node off %u src end %u\n", src->offset, src->end); } while (src->offset <= src->end); } @@ -3820,17 +3793,14 @@ static inline bool can_rebalance_right(struct ma_state *tmp_mas, struct ma_node_info *parent, struct ma_node_info *src2, struct split_data *sd) { - printk("\t%s %u %u\n", __func__, parent->insert_off, parent->end); if (parent->insert_off >= parent->end) /* No right node */ return false; tmp_mas->offset++; - printk("Check %p[%u]\n", tmp_mas->node, tmp_mas->offset); mas_descend(tmp_mas); mni_mas_init(src2, tmp_mas); mni_set_end(src2); sd->split = mas_wr_rebalance_calc(src2->end + sd->new_end, src2->type); - printk("split is %u\n", sd->split); if (!sd->split) { mas_ascend(tmp_mas); tmp_mas->offset--; @@ -3844,17 +3814,14 @@ static inline bool can_rebalance_left(struct ma_state *tmp_mas, struct ma_node_info *parent, struct ma_node_info *src2, struct split_data *sd) { - printk("\t%s %u %u\n", __func__, parent->insert_off, parent->end); if (!parent->insert_off) /* No left node */ return false; tmp_mas->offset--; - printk("Check %p[%u]\n", tmp_mas->node, tmp_mas->offset); mas_descend(tmp_mas); mni_mas_init(src2, tmp_mas); mni_set_end(src2); sd->split = mas_wr_rebalance_calc(src2->end + sd->new_end, src2->type); - printk("split is %u\n", sd->split); if (!sd->split) { mas_ascend(tmp_mas); tmp_mas->offset++; @@ -3962,7 +3929,6 @@ static void mas_wr_rebalance_two(struct ma_wr_state *wr_mas, struct ma_node_info *dst; struct ma_node_state *state; - printk("\t\t%s \n", __func__); sd->insert_end = sd->insert + part->size - 1; if (!left_store) { char len; @@ -3971,21 +3937,16 @@ static void mas_wr_rebalance_two(struct ma_wr_state *wr_mas, * Store to the right implies left is going to donate data to * the right node */ - printk("store is in right\n"); state = &sd->states[sd->len]; left->min = src2->min; right->max = src->max; sd->offset = src2->end + 1; state->info = src2; - printk("cp from %p\n", src2->node); /* The first state to copy is the left node */ - printk("cp to left %u+%u\n", 0, sd->split); mns_mni_init(state, left, 0, sd->split); if (ma_is_leaf(src->type) && mns_ends_in_null(state)) { - printk("ends in null\n"); sd->split--; state->size--; - printk("NEW cp to left %u-%u\n", 0, sd->split); } sd->len++; @@ -3993,14 +3954,10 @@ static void mas_wr_rebalance_two(struct ma_wr_state *wr_mas, len = src2->end + 1 - sd->split; sd->states[sd->len].info = src2; mns_mni_init(&sd->states[sd->len], right, sd->split, len); - printk("cp to right %u-%u (%u + 1 - %u\n", sd->split, len, src2->end, sd->split); sd->len++; sd->space = mt_slots[right->type]; dst = right; - printk("src ins end is %u\n", wr_mas->offset_end); - printk("\n"); } else { - printk("store left\n"); sd->space = sd->split; sd->offset = 0; left->min = src->min; @@ -4009,30 +3966,19 @@ static void mas_wr_rebalance_two(struct ma_wr_state *wr_mas, } do { - printk("cp from %p starting at %u\n", src->node, src->offset); split_state_setup(src, dst, part, sd); - printk("state %d: cp %p[%u] + %u to %s\n", sd->len, src->node, - sd->states[sd->len].start, - sd->states[sd->len].size, dst == left ? "left" : "right"); sd->len++; } while (src->offset <= src->end); - printk("\n\nend of loop\n"); if (left_store) { char len; - if (sd->offset >= sd->insert && sd->offset <= sd->insert_end) - printk("BING\n"); - state = &sd->states[sd->len]; sd->split = (sd->new_end + 1) / 2; - printk("sd is at offset %u splut %u\n", sd->offset, sd->split); len = sd->split - sd->offset; state->info = src2; - printk("cp from %p to right %u + %u to left\n", src2->node, 0, len); mns_mni_init(state, left, 0, len); if (ma_is_leaf(src->type) && mns_ends_in_null(state)) { - printk("ends in null\n"); sd->split--; sd->offset--; sd->space++; @@ -4040,17 +3986,10 @@ static void mas_wr_rebalance_two(struct ma_wr_state *wr_mas, len--; } - printk("state %d: cp %p[%u] + %u to %s\n", sd->len, src->node, - sd->states[sd->len].start, - sd->states[sd->len].size, dst == left ? "left" : "right"); - printk("cp the right->to right->%u + %u\n", len, src2->end + 1); sd->len++; /* Stored to the left, copy the last of the right->in src2 */ sd->states[sd->len].info = src2; mns_mni_init(&sd->states[sd->len], right, len, src2->end + 1 - len); - printk("state %d: cp %p[%u] + %u to %s\n", sd->len, src->node, - sd->states[sd->len].start, - sd->states[sd->len].size, dst == left ? "left" : "right"); sd->len++; } @@ -4069,10 +4008,8 @@ static void mas_wr_rebalance_reduce(struct ma_wr_state *wr_mas, struct split_data *sd, bool left_store) { - printk("\t\t%s\n", __func__); sd->insert_end = sd->insert + part->size - 1; if (!left_store) { - printk("store right\n"); left->min = src2->min; left->max = src->max; sd->offset = src2->end + 1; @@ -4082,7 +4019,6 @@ static void mas_wr_rebalance_reduce(struct ma_wr_state *wr_mas, mns_mni_init(&sd->states[sd->len], left, 0, src2->end + 1); sd->len++; } else { - printk("store left\n"); sd->space = sd->split; sd->offset = 0; left->min = src->min; @@ -4091,17 +4027,12 @@ static void mas_wr_rebalance_reduce(struct ma_wr_state *wr_mas, do { - printk("cp from %p starting at %u\n", src->node, src->offset); split_state_setup(src, left, part, sd); - printk("state %d: cp %p[%u] + %u to %s\n", sd->len, src->node, - sd->states[sd->len].start, - sd->states[sd->len].size, "always left"); sd->len++; } while (src->offset <= src->end); if (left_store) { sd->states[sd->len].info = src2; - printk("cp right->%u + %u to left\n", 0, src2->end + 1); mns_mni_init(&sd->states[sd->len], left, 0, src2->end + 1); sd->len++; } @@ -4132,122 +4063,81 @@ static void mas_wr_rebalance(struct ma_wr_state *wr_mas) * Rebalancing will pull data from the right first, keeping the tree * compact to the left side. */ - mt_dump(mas->tree, mt_dump_dec); - printk("Rebalance %p offset %u - %u\n", mas->node, mas->offset, wr_mas->offset_end); - printk("Store %p %lu - %lu\n", wr_mas->entry, mas->index, mas->last); - height = mas_mt_height(mas); - mni_mas_init(&src, mas); src.end = mas->end; - printk("HERE\n"); mns_node_part_leaf_init(&part, wr_mas, &src); sd.new_end = mas->end + part.size - part.skip + 1; sd.src_ins_end = wr_mas->offset_end; sd.len = 0; mni_node_init(&left, mas_pop_node(mas), wr_mas->type); - printk("left is %p\n", left.node); if (mt_is_alloc(mas->tree)) sd.is_alloc = true; else sd.is_alloc = false; do { - printk("\tloop\n"); tmp_mas = *mas; mas_wr_ascend_init(&tmp_mas, &parent); if (can_rebalance_right(&tmp_mas, &parent, &src2, &sd)) { - printk("rebalance right, split is %u\n", sd.split); - printk("rebalance with %p\n", src2.node); /* Left will be src, right will be src2 */ sd.insert = mas->offset; - printk("insert is at %u\n", sd.insert); left_store = true; } else { /* Won't fail here */ MAS_BUG_ON(mas, can_rebalance_left(&tmp_mas, &parent, &src2, &sd) == false); - printk("rebalance left, split is %u\n", sd.split); - printk("rebalance with %p\n", src2.node); /* Left will be src2, right will be src */ sd.insert = mas->offset + src2.end + 1; } - printk("rebalance %p %p\n", src.node, src2.node); sd.new_end += src2.end + 1; - printk("new end %u\n", sd.new_end); - if (sd.new_end < mt_min_slots[left.type]) { - printk("Not enough tdata\n"); - exit(0); - } - printk("Total data is %u\n", sd.new_end); - printk("sd insert is %u\n", sd.insert); if (sd.new_end >= mt_slots[left.type]) { - if (sd.new_end - sd.split < mt_min_slots[left.type]) { - printk("Too big split\n"); - exit(0); - } mni_node_init(&right, mas_pop_node(mas), mte_node_type(mas->node)); - printk("right is %p\n", right.node); - printk("%s end with %lu - %lu\n", __func__, mas->index, mas->last); mas_wr_rebalance_two(wr_mas, &left, &right, &src, &src2, &part, &sd, left_store); mas_ascend(mas); mas->end = parent.end; mas->offset = parent.insert_off; - printk("Replacing 2 nodes (%d), break\n", sd.new_end); - printk("mas is %p\n", mas->node); break; } - printk("REDUCE %p %p\n", src.node, src2.node); mas_wr_rebalance_reduce(wr_mas, &left, &src, &src2, &part, &sd, left_store); - - /* Must go again */ mas_ascend(mas); mas->end = parent.end; mas->offset = parent.insert_off; - printk("\tmas is now at %p[%u]\n", mas->node, mas->offset); - sd.len = 0; - sd.new_end = mas->end + part.size - part.skip + 1; - sd.offset = mas->offset; - sd.src_ins_end = mas->offset + 1; if (ma_is_root(parent.node)) { - printk("Parent IS root, so abort rest\n"); if (parent.end != 1) break; /* Converged */ - printk("left needs to be new root\n"); src.enode = mas->node; left.node->parent = mas_mn(mas)->parent; mas->node = left.enode; mas->depth = mas_mt_height(mas) - 1; if (mas->depth == 1) - mas_set_height(mas); + mas_set_height(mas); goto new_root; } - if (mas->end > mt_min_slots[parent.type]) { - printk("Decrease %p to %u\n", parent.node, parent.end - 1); - + if (mas->end > mt_min_slots[parent.type]) break; /* Converged */ - } + /* Must go again */ + sd.len = 0; + sd.new_end = mas->end + part.size - part.skip + 1; + sd.offset = mas->offset; + sd.src_ins_end = mas->offset + 1; mni_mas_init(&src, mas); src.end = mas->end; mni_node_init(&left, mas_pop_node(mas), mte_node_type(mas->node)); - printk("\nAGAIN, parent %p[%u] src %p\n", parent.node, parent.insert_off, src.node); - printk("height is %u\n", height); } while (height--); mas_wr_converged(&parent, &new_parent, &part, mas, &sd); src.enode = parent.enode; - printk("Replace %p with %p\n", parent.node, mte_to_node(new_parent.enode)); mas->node = new_parent.enode; new_root: mas_wmb_replace(mas, src.enode); mtree_range_walk(mas); - mt_dump(mas->tree, mt_dump_dec); mt_validate(mas->tree); } diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index 5d0a95b328c9..db6fe093f711 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -2630,7 +2630,6 @@ static noinline void __init check_fuzzer(struct maple_tree *mt) mtree_test_load(mt, 1); mtree_test_store_range(mt, 1, 22, (void *)0x3); mtree_test_insert(mt, 1, (void *)0x3); - mt_dump(mt, mt_dump_dec); mtree_test_erase(mt, 1); mtree_test_load(mt, 53); mtree_test_load(mt, 1); diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index ad89fce34736..2164e6990a2e 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -27,7 +27,7 @@ #include "../../../lib/test_maple_tree.c" #define RCU_RANGE_COUNT 1000 -#define RCU_MT_BUG_ON(_test, _y) {if (_y) { {if (_test->stop != true) MT_BUG_ON(_test->mt, _y);} _test->stop = true; }} +#define RCU_MT_BUG_ON(test, y) {if (y) { test->stop = true; } MT_BUG_ON(test->mt, y); } struct rcu_test_struct2 { struct maple_tree *mt; @@ -725,11 +725,8 @@ static noinline void __init check_erase_testset(struct maple_tree *mt) /* Shrinking tree test. */ - for (int i = 13; i < ARRAY_SIZE(set); i++) { - mt_dump(mt, mt_dump_dec); - printk("STORE %lu -> %p\n", set[i], entry[i%2]); + for (int i = 13; i < ARRAY_SIZE(set); i++) erase_check_insert(mt, i); - } mt_set_non_kernel(99); for (int i = 18; i < ARRAY_SIZE(set); i++) { @@ -34382,7 +34379,6 @@ static void *rcu_reader_fwd(void *ptr) bool toggled, modified, deleted, added; int i; void *entry, *prev = NULL; - struct maple_node *p_node = NULL; MA_STATE(mas, test->mt, 0, 0); rcu_reader_register(test); @@ -34431,14 +34427,6 @@ static void *rcu_reader_fwd(void *ptr) } } - if (mas.index != r_start) { - alt = xa_mk_value(index + i * 2 + 1 + - RCU_RANGE_COUNT); - printk("Error: mas %p %lu-%lu %p != %lu-%lu %p %p line %d i %d, pnode %p\n", - mte_to_node(mas.node), mas.index, mas.last, entry, - r_start, r_end, expected, alt, - __LINE__, i, p_node); - } RCU_MT_BUG_ON(test, mas.index != r_start); if (mas.last != r_end) { printk("last is wrong: %lx vs %lx\n", mas.last, r_end); @@ -34487,7 +34475,6 @@ static void *rcu_reader_fwd(void *ptr) } i++; - p_node = mte_to_node(mas.node); } rcu_read_unlock(); usleep(test->pause); @@ -34568,8 +34555,8 @@ static void *rcu_reader_rev(void *ptr) alt = xa_mk_value(index + i * 2 + 1 + RCU_RANGE_COUNT); mt_dump(test->mt, mt_dump_dec); - printk("Error: mas %p %lu-%lu %p != %lu-%lu %p %p line %d i %d\n", - mas.node, mas.index, mas.last, entry, + printk("Error: %lu-%lu %p != %lu-%lu %p %p line %d i %d\n", + mas.index, mas.last, entry, r_start, r_end, expected, alt, line, i); } @@ -36383,7 +36370,6 @@ void farmer_tests(void) struct maple_node *node; DEFINE_MTREE(tree); - goto skip; mt_dump(&tree, mt_dump_dec); mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | MT_FLAGS_USE_RCU); @@ -36441,7 +36427,6 @@ void farmer_tests(void) mtree_destroy(&tree); /* RCU testing */ -skip: mt_init_flags(&tree, 0); check_erase_testset(&tree); mtree_destroy(&tree); @@ -36558,10 +36543,10 @@ static void regression_tests(void) void maple_tree_tests(void) { - //maple_tree_seed(); - //maple_tree_harvest(); + maple_tree_seed(); + maple_tree_harvest(); #if !defined(BENCH) - //regression_tests(); + regression_tests(); farmer_tests(); #endif }