Skip to content

Commit 516df05

Browse files
committed
lib/assoc_array: Remove smp_read_barrier_depends()
Now that smp_read_barrier_depends() is implied by READ_ONCE(), the several smp_read_barrier_depends() calls may be removed from lib/assoc_array.c. This commit makes this change and marks the READ_ONCE() calls that head address dependencies. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Alexander Kuleshov <kuleshovmail@gmail.com> Cc: David Howells <dhowells@redhat.com>
1 parent 243d1a7 commit 516df05

1 file changed

Lines changed: 12 additions & 25 deletions

File tree

‎lib/assoc_array.c‎

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ static int assoc_array_subtree_iterate(const struct assoc_array_ptr *root,
3838
if (assoc_array_ptr_is_shortcut(cursor)) {
3939
/* Descend through a shortcut */
4040
shortcut = assoc_array_ptr_to_shortcut(cursor);
41-
smp_read_barrier_depends();
42-
cursor = READ_ONCE(shortcut->next_node);
41+
cursor = READ_ONCE(shortcut->next_node); /* Address dependency. */
4342
}
4443

4544
node = assoc_array_ptr_to_node(cursor);
46-
smp_read_barrier_depends();
4745
slot = 0;
4846

4947
/* We perform two passes of each node.
@@ -55,15 +53,12 @@ static int assoc_array_subtree_iterate(const struct assoc_array_ptr *root,
5553
*/
5654
has_meta = 0;
5755
for (; slot < ASSOC_ARRAY_FAN_OUT; slot++) {
58-
ptr = READ_ONCE(node->slots[slot]);
56+
ptr = READ_ONCE(node->slots[slot]); /* Address dependency. */
5957
has_meta |= (unsigned long)ptr;
6058
if (ptr && assoc_array_ptr_is_leaf(ptr)) {
61-
/* We need a barrier between the read of the pointer
62-
* and dereferencing the pointer - but only if we are
63-
* actually going to dereference it.
59+
/* We need a barrier between the read of the pointer,
60+
* which is supplied by the above READ_ONCE().
6461
*/
65-
smp_read_barrier_depends();
66-
6762
/* Invoke the callback */
6863
ret = iterator(assoc_array_ptr_to_leaf(ptr),
6964
iterator_data);
@@ -86,10 +81,8 @@ static int assoc_array_subtree_iterate(const struct assoc_array_ptr *root,
8681

8782
continue_node:
8883
node = assoc_array_ptr_to_node(cursor);
89-
smp_read_barrier_depends();
90-
9184
for (; slot < ASSOC_ARRAY_FAN_OUT; slot++) {
92-
ptr = READ_ONCE(node->slots[slot]);
85+
ptr = READ_ONCE(node->slots[slot]); /* Address dependency. */
9386
if (assoc_array_ptr_is_meta(ptr)) {
9487
cursor = ptr;
9588
goto begin_node;
@@ -98,16 +91,15 @@ static int assoc_array_subtree_iterate(const struct assoc_array_ptr *root,
9891

9992
finished_node:
10093
/* Move up to the parent (may need to skip back over a shortcut) */
101-
parent = READ_ONCE(node->back_pointer);
94+
parent = READ_ONCE(node->back_pointer); /* Address dependency. */
10295
slot = node->parent_slot;
10396
if (parent == stop)
10497
return 0;
10598

10699
if (assoc_array_ptr_is_shortcut(parent)) {
107100
shortcut = assoc_array_ptr_to_shortcut(parent);
108-
smp_read_barrier_depends();
109101
cursor = parent;
110-
parent = READ_ONCE(shortcut->back_pointer);
102+
parent = READ_ONCE(shortcut->back_pointer); /* Address dependency. */
111103
slot = shortcut->parent_slot;
112104
if (parent == stop)
113105
return 0;
@@ -147,7 +139,7 @@ int assoc_array_iterate(const struct assoc_array *array,
147139
void *iterator_data),
148140
void *iterator_data)
149141
{
150-
struct assoc_array_ptr *root = READ_ONCE(array->root);
142+
struct assoc_array_ptr *root = READ_ONCE(array->root); /* Address dependency. */
151143

152144
if (!root)
153145
return 0;
@@ -194,7 +186,7 @@ assoc_array_walk(const struct assoc_array *array,
194186

195187
pr_devel("-->%s()\n", __func__);
196188

197-
cursor = READ_ONCE(array->root);
189+
cursor = READ_ONCE(array->root); /* Address dependency. */
198190
if (!cursor)
199191
return assoc_array_walk_tree_empty;
200192

@@ -216,11 +208,9 @@ assoc_array_walk(const struct assoc_array *array,
216208

217209
consider_node:
218210
node = assoc_array_ptr_to_node(cursor);
219-
smp_read_barrier_depends();
220-
221211
slot = segments >> (level & ASSOC_ARRAY_KEY_CHUNK_MASK);
222212
slot &= ASSOC_ARRAY_FAN_MASK;
223-
ptr = READ_ONCE(node->slots[slot]);
213+
ptr = READ_ONCE(node->slots[slot]); /* Address dependency. */
224214

225215
pr_devel("consider slot %x [ix=%d type=%lu]\n",
226216
slot, level, (unsigned long)ptr & 3);
@@ -254,7 +244,6 @@ assoc_array_walk(const struct assoc_array *array,
254244
cursor = ptr;
255245
follow_shortcut:
256246
shortcut = assoc_array_ptr_to_shortcut(cursor);
257-
smp_read_barrier_depends();
258247
pr_devel("shortcut to %d\n", shortcut->skip_to_level);
259248
sc_level = level + ASSOC_ARRAY_LEVEL_STEP;
260249
BUG_ON(sc_level > shortcut->skip_to_level);
@@ -294,7 +283,7 @@ assoc_array_walk(const struct assoc_array *array,
294283
} while (sc_level < shortcut->skip_to_level);
295284

296285
/* The shortcut matches the leaf's index to this point. */
297-
cursor = READ_ONCE(shortcut->next_node);
286+
cursor = READ_ONCE(shortcut->next_node); /* Address dependency. */
298287
if (((level ^ sc_level) & ~ASSOC_ARRAY_KEY_CHUNK_MASK) != 0) {
299288
level = sc_level;
300289
goto jumped;
@@ -331,20 +320,18 @@ void *assoc_array_find(const struct assoc_array *array,
331320
return NULL;
332321

333322
node = result.terminal_node.node;
334-
smp_read_barrier_depends();
335323

336324
/* If the target key is available to us, it's has to be pointed to by
337325
* the terminal node.
338326
*/
339327
for (slot = 0; slot < ASSOC_ARRAY_FAN_OUT; slot++) {
340-
ptr = READ_ONCE(node->slots[slot]);
328+
ptr = READ_ONCE(node->slots[slot]); /* Address dependency. */
341329
if (ptr && assoc_array_ptr_is_leaf(ptr)) {
342330
/* We need a barrier between the read of the pointer
343331
* and dereferencing the pointer - but only if we are
344332
* actually going to dereference it.
345333
*/
346334
leaf = assoc_array_ptr_to_leaf(ptr);
347-
smp_read_barrier_depends();
348335
if (ops->compare_object(leaf, index_key))
349336
return (void *)leaf;
350337
}

0 commit comments

Comments
 (0)