Thread (17 messages) 17 messages, 8 authors, 2021-08-09

Re: [RFC PATCH v1 1/5] locking/atomic: Implement atomic_fetch_and_or

From: hev <hidden>
Date: 2021-07-29 01:58:16

Hi, Peter,

On Wed, Jul 28, 2021 at 9:21 PM Peter Zijlstra [off-list ref] wrote:
On Wed, Jul 28, 2021 at 03:16:54PM +0200, Peter Zijlstra wrote:
quoted
On Wed, Jul 28, 2021 at 02:58:35PM +0200, Peter Zijlstra wrote:
quoted
The below isn't quite right, because it'll use try_cmpxchg() for
atomic_andnot_or(), which by being a void atomic should be _relaxed. I'm
not entirely sure how to make that happen in a hurry.

---
This seems to do the trick.
Mark suggested this, which is probably nicer still.
Wow, Amazing! so the architecture dependent can be implemented one by one.

Regards
Rui
quoted hunk ↗ jump to hunk
---
diff --git a/scripts/atomic/atomics.tbl b/scripts/atomic/atomics.tbl
index fbee2f6190d9..3aaa0caa6b2d 100755
--- a/scripts/atomic/atomics.tbl
+++ b/scripts/atomic/atomics.tbl
@@ -39,3 +39,4 @@ inc_not_zero          b       v
 inc_unless_negative    b       v
 dec_unless_positive    b       v
 dec_if_positive                i       v
+andnot_or              vF      v       i:m     i:o
diff --git a/scripts/atomic/fallbacks/andnot_or b/scripts/atomic/fallbacks/andnot_or
new file mode 100644
index 000000000000..0fb3a728c0ff
--- /dev/null
+++ b/scripts/atomic/fallbacks/andnot_or
@@ -0,0 +1,24 @@
+local try_order=${order}
+
+#
+# non-value returning atomics are implicity relaxed
+#
+if [ -z "${retstmt}" ]; then
+       try_order="_relaxed"
+fi
+
+cat <<EOF
+static __always_inline ${ret}
+arch_${atomic}_${pfx}andnot_or${sfx}${order}(${atomic}_t *v, ${int} m, ${int} o)
+{
+       ${retstmt}({
+               ${int} N, O = atomic_read(v);
+               do {
+                       N = O;
+                       N &= ~m;
+                       N |= o;
+               } while (!arch_${atomic}_try_cmpxchg${try_order}(v, &O, N));
+               O;
+       });
+}
+EOF
diff --git a/scripts/atomic/fallbacks/fetch_andnot_or b/scripts/atomic/fallbacks/fetch_andnot_or
deleted file mode 100644
index e69de29bb2d1..000000000000
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help