Skip to content

Commit 542980a

Browse files
author
Matthew Wilcox
committed
radix tree test: Convert multiorder tests to XArray
This is the last remaining user of the multiorder functionality of the radix tree. Test the XArray instead. Signed-off-by: Matthew Wilcox <willy@infradead.org>
1 parent b66b5a4 commit 542980a

1 file changed

Lines changed: 49 additions & 56 deletions

File tree

‎tools/testing/radix-tree/multiorder.c‎

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,20 @@ static int item_insert_order(struct xarray *xa, unsigned long index,
3939
return xas_error(&xas);
4040
}
4141

42-
void multiorder_iteration(void)
42+
void multiorder_iteration(struct xarray *xa)
4343
{
44-
RADIX_TREE(tree, GFP_KERNEL);
45-
struct radix_tree_iter iter;
46-
void **slot;
44+
XA_STATE(xas, xa, 0);
45+
struct item *item;
4746
int i, j, err;
4847

49-
printv(1, "Multiorder iteration test\n");
50-
5148
#define NUM_ENTRIES 11
5249
int index[NUM_ENTRIES] = {0, 2, 4, 8, 16, 32, 34, 36, 64, 72, 128};
5350
int order[NUM_ENTRIES] = {1, 1, 2, 3, 4, 1, 0, 1, 3, 0, 7};
5451

52+
printv(1, "Multiorder iteration test\n");
53+
5554
for (i = 0; i < NUM_ENTRIES; i++) {
56-
err = item_insert_order(&tree, index[i], order[i]);
55+
err = item_insert_order(xa, index[i], order[i]);
5756
assert(!err);
5857
}
5958

@@ -62,47 +61,46 @@ void multiorder_iteration(void)
6261
if (j <= (index[i] | ((1 << order[i]) - 1)))
6362
break;
6463

65-
radix_tree_for_each_slot(slot, &tree, &iter, j) {
66-
int height = order[i] / RADIX_TREE_MAP_SHIFT;
67-
int shift = height * RADIX_TREE_MAP_SHIFT;
64+
xas_set(&xas, j);
65+
xas_for_each(&xas, item, ULONG_MAX) {
66+
int height = order[i] / XA_CHUNK_SHIFT;
67+
int shift = height * XA_CHUNK_SHIFT;
6868
unsigned long mask = (1UL << order[i]) - 1;
69-
struct item *item = *slot;
7069

71-
assert((iter.index | mask) == (index[i] | mask));
72-
assert(iter.shift == shift);
70+
assert((xas.xa_index | mask) == (index[i] | mask));
71+
assert(xas.xa_node->shift == shift);
7372
assert(!radix_tree_is_internal_node(item));
7473
assert((item->index | mask) == (index[i] | mask));
7574
assert(item->order == order[i]);
7675
i++;
7776
}
7877
}
7978

80-
item_kill_tree(&tree);
79+
item_kill_tree(xa);
8180
}
8281

83-
void multiorder_tagged_iteration(void)
82+
void multiorder_tagged_iteration(struct xarray *xa)
8483
{
85-
RADIX_TREE(tree, GFP_KERNEL);
86-
struct radix_tree_iter iter;
87-
void **slot;
84+
XA_STATE(xas, xa, 0);
85+
struct item *item;
8886
int i, j;
8987

90-
printv(1, "Multiorder tagged iteration test\n");
91-
9288
#define MT_NUM_ENTRIES 9
9389
int index[MT_NUM_ENTRIES] = {0, 2, 4, 16, 32, 40, 64, 72, 128};
9490
int order[MT_NUM_ENTRIES] = {1, 0, 2, 4, 3, 1, 3, 0, 7};
9591

9692
#define TAG_ENTRIES 7
9793
int tag_index[TAG_ENTRIES] = {0, 4, 16, 40, 64, 72, 128};
9894

95+
printv(1, "Multiorder tagged iteration test\n");
96+
9997
for (i = 0; i < MT_NUM_ENTRIES; i++)
100-
assert(!item_insert_order(&tree, index[i], order[i]));
98+
assert(!item_insert_order(xa, index[i], order[i]));
10199

102-
assert(!radix_tree_tagged(&tree, 1));
100+
assert(!xa_marked(xa, XA_MARK_1));
103101

104102
for (i = 0; i < TAG_ENTRIES; i++)
105-
assert(radix_tree_tag_set(&tree, tag_index[i], 1));
103+
xa_set_mark(xa, tag_index[i], XA_MARK_1);
106104

107105
for (j = 0; j < 256; j++) {
108106
int k;
@@ -114,22 +112,22 @@ void multiorder_tagged_iteration(void)
114112
break;
115113
}
116114

117-
radix_tree_for_each_tagged(slot, &tree, &iter, j, 1) {
115+
xas_set(&xas, j);
116+
xas_for_each_marked(&xas, item, ULONG_MAX, XA_MARK_1) {
118117
unsigned long mask;
119-
struct item *item = *slot;
120118
for (k = i; index[k] < tag_index[i]; k++)
121119
;
122120
mask = (1UL << order[k]) - 1;
123121

124-
assert((iter.index | mask) == (tag_index[i] | mask));
125-
assert(!radix_tree_is_internal_node(item));
122+
assert((xas.xa_index | mask) == (tag_index[i] | mask));
123+
assert(!xa_is_internal(item));
126124
assert((item->index | mask) == (tag_index[i] | mask));
127125
assert(item->order == order[k]);
128126
i++;
129127
}
130128
}
131129

132-
assert(tag_tagged_items(&tree, 0, ~0UL, TAG_ENTRIES, XA_MARK_1,
130+
assert(tag_tagged_items(xa, 0, ULONG_MAX, TAG_ENTRIES, XA_MARK_1,
133131
XA_MARK_2) == TAG_ENTRIES);
134132

135133
for (j = 0; j < 256; j++) {
@@ -142,29 +140,31 @@ void multiorder_tagged_iteration(void)
142140
break;
143141
}
144142

145-
radix_tree_for_each_tagged(slot, &tree, &iter, j, 2) {
146-
struct item *item = *slot;
143+
xas_set(&xas, j);
144+
xas_for_each_marked(&xas, item, ULONG_MAX, XA_MARK_2) {
147145
for (k = i; index[k] < tag_index[i]; k++)
148146
;
149147
mask = (1 << order[k]) - 1;
150148

151-
assert((iter.index | mask) == (tag_index[i] | mask));
152-
assert(!radix_tree_is_internal_node(item));
149+
assert((xas.xa_index | mask) == (tag_index[i] | mask));
150+
assert(!xa_is_internal(item));
153151
assert((item->index | mask) == (tag_index[i] | mask));
154152
assert(item->order == order[k]);
155153
i++;
156154
}
157155
}
158156

159-
assert(tag_tagged_items(&tree, 1, ~0UL, MT_NUM_ENTRIES * 2, XA_MARK_1,
157+
assert(tag_tagged_items(xa, 1, ULONG_MAX, MT_NUM_ENTRIES * 2, XA_MARK_1,
160158
XA_MARK_0) == TAG_ENTRIES);
161159
i = 0;
162-
radix_tree_for_each_tagged(slot, &tree, &iter, 0, 0) {
163-
assert(iter.index == tag_index[i]);
160+
xas_set(&xas, 0);
161+
xas_for_each_marked(&xas, item, ULONG_MAX, XA_MARK_0) {
162+
assert(xas.xa_index == tag_index[i]);
164163
i++;
165164
}
165+
assert(i == TAG_ENTRIES);
166166

167-
item_kill_tree(&tree);
167+
item_kill_tree(xa);
168168
}
169169

170170
bool stop_iteration = false;
@@ -187,52 +187,45 @@ static void *creator_func(void *ptr)
187187

188188
static void *iterator_func(void *ptr)
189189
{
190-
struct radix_tree_root *tree = ptr;
191-
struct radix_tree_iter iter;
190+
XA_STATE(xas, ptr, 0);
192191
struct item *item;
193-
void **slot;
194192

195193
while (!stop_iteration) {
196194
rcu_read_lock();
197-
radix_tree_for_each_slot(slot, tree, &iter, 0) {
198-
item = radix_tree_deref_slot(slot);
199-
200-
if (!item)
195+
xas_for_each(&xas, item, ULONG_MAX) {
196+
if (xas_retry(&xas, item))
201197
continue;
202-
if (radix_tree_deref_retry(item)) {
203-
slot = radix_tree_iter_retry(&iter);
204-
continue;
205-
}
206198

207-
item_sanity(item, iter.index);
199+
item_sanity(item, xas.xa_index);
208200
}
209201
rcu_read_unlock();
210202
}
211203
return NULL;
212204
}
213205

214-
static void multiorder_iteration_race(void)
206+
static void multiorder_iteration_race(struct xarray *xa)
215207
{
216208
const int num_threads = sysconf(_SC_NPROCESSORS_ONLN);
217209
pthread_t worker_thread[num_threads];
218-
RADIX_TREE(tree, GFP_KERNEL);
219210
int i;
220211

221-
pthread_create(&worker_thread[0], NULL, &creator_func, &tree);
212+
pthread_create(&worker_thread[0], NULL, &creator_func, xa);
222213
for (i = 1; i < num_threads; i++)
223-
pthread_create(&worker_thread[i], NULL, &iterator_func, &tree);
214+
pthread_create(&worker_thread[i], NULL, &iterator_func, xa);
224215

225216
for (i = 0; i < num_threads; i++)
226217
pthread_join(worker_thread[i], NULL);
227218

228-
item_kill_tree(&tree);
219+
item_kill_tree(xa);
229220
}
230221

222+
static DEFINE_XARRAY(array);
223+
231224
void multiorder_checks(void)
232225
{
233-
multiorder_iteration();
234-
multiorder_tagged_iteration();
235-
multiorder_iteration_race();
226+
multiorder_iteration(&array);
227+
multiorder_tagged_iteration(&array);
228+
multiorder_iteration_race(&array);
236229

237230
radix_tree_cpu_dead(0);
238231
}

0 commit comments

Comments
 (0)