hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/Documentation/core-api/refcount-vs-atomic.rst
....@@ -35,7 +35,7 @@
3535 program order (po) relation (on the same CPU). It guarantees that
3636 each ``atomic_*()`` and ``refcount_*()`` operation is atomic and instructions
3737 are executed in program order on a single CPU.
38
-This is implemented using :c:func:`READ_ONCE`/:c:func:`WRITE_ONCE` and
38
+This is implemented using READ_ONCE()/WRITE_ONCE() and
3939 compare-and-swap primitives.
4040
4141 A strong (full) memory ordering guarantees that all prior loads and
....@@ -44,7 +44,7 @@
4444 It also guarantees that all po-earlier stores on the same CPU
4545 and all propagated stores from other CPUs must propagate to all
4646 other CPUs before any po-later instruction is executed on the original
47
-CPU (A-cumulative property). This is implemented using :c:func:`smp_mb`.
47
+CPU (A-cumulative property). This is implemented using smp_mb().
4848
4949 A RELEASE memory ordering guarantees that all prior loads and
5050 stores (all po-earlier instructions) on the same CPU are completed
....@@ -52,7 +52,14 @@
5252 stores on the same CPU and all propagated stores from other CPUs
5353 must propagate to all other CPUs before the release operation
5454 (A-cumulative property). This is implemented using
55
-:c:func:`smp_store_release`.
55
+smp_store_release().
56
+
57
+An ACQUIRE memory ordering guarantees that all post loads and
58
+stores (all po-later instructions) on the same CPU are
59
+completed after the acquire operation. It also guarantees that all
60
+po-later stores on the same CPU must propagate to all other CPUs
61
+after the acquire operation executes. This is implemented using
62
+smp_acquire__after_ctrl_dep().
5663
5764 A control dependency (on success) for refcounters guarantees that
5865 if a reference for an object was successfully obtained (reference
....@@ -71,8 +78,8 @@
7178
7279 Function changes:
7380
74
- * :c:func:`atomic_set` --> :c:func:`refcount_set`
75
- * :c:func:`atomic_read` --> :c:func:`refcount_read`
81
+ * atomic_set() --> refcount_set()
82
+ * atomic_read() --> refcount_read()
7683
7784 Memory ordering guarantee changes:
7885
....@@ -84,8 +91,8 @@
8491
8592 Function changes:
8693
87
- * :c:func:`atomic_inc` --> :c:func:`refcount_inc`
88
- * :c:func:`atomic_add` --> :c:func:`refcount_add`
94
+ * atomic_inc() --> refcount_inc()
95
+ * atomic_add() --> refcount_add()
8996
9097 Memory ordering guarantee changes:
9198
....@@ -96,7 +103,7 @@
96103
97104 Function changes:
98105
99
- * :c:func:`atomic_dec` --> :c:func:`refcount_dec`
106
+ * atomic_dec() --> refcount_dec()
100107
101108 Memory ordering guarantee changes:
102109
....@@ -108,8 +115,8 @@
108115
109116 Function changes:
110117
111
- * :c:func:`atomic_inc_not_zero` --> :c:func:`refcount_inc_not_zero`
112
- * no atomic counterpart --> :c:func:`refcount_add_not_zero`
118
+ * atomic_inc_not_zero() --> refcount_inc_not_zero()
119
+ * no atomic counterpart --> refcount_add_not_zero()
113120
114121 Memory ordering guarantees changes:
115122
....@@ -119,32 +126,43 @@
119126 result of obtaining pointer to the object!
120127
121128
122
-case 5) - decrement-based RMW ops that return a value
123
------------------------------------------------------
129
+case 5) - generic dec/sub decrement-based RMW ops that return a value
130
+---------------------------------------------------------------------
124131
125132 Function changes:
126133
127
- * :c:func:`atomic_dec_and_test` --> :c:func:`refcount_dec_and_test`
128
- * :c:func:`atomic_sub_and_test` --> :c:func:`refcount_sub_and_test`
129
- * no atomic counterpart --> :c:func:`refcount_dec_if_one`
134
+ * atomic_dec_and_test() --> refcount_dec_and_test()
135
+ * atomic_sub_and_test() --> refcount_sub_and_test()
136
+
137
+Memory ordering guarantees changes:
138
+
139
+ * fully ordered --> RELEASE ordering + ACQUIRE ordering on success
140
+
141
+
142
+case 6) other decrement-based RMW ops that return a value
143
+---------------------------------------------------------
144
+
145
+Function changes:
146
+
147
+ * no atomic counterpart --> refcount_dec_if_one()
130148 * ``atomic_add_unless(&var, -1, 1)`` --> ``refcount_dec_not_one(&var)``
131149
132150 Memory ordering guarantees changes:
133151
134152 * fully ordered --> RELEASE ordering + control dependency
135153
136
-.. note:: :c:func:`atomic_add_unless` only provides full order on success.
154
+.. note:: atomic_add_unless() only provides full order on success.
137155
138156
139
-case 6) - lock-based RMW
157
+case 7) - lock-based RMW
140158 ------------------------
141159
142160 Function changes:
143161
144
- * :c:func:`atomic_dec_and_lock` --> :c:func:`refcount_dec_and_lock`
145
- * :c:func:`atomic_dec_and_mutex_lock` --> :c:func:`refcount_dec_and_mutex_lock`
162
+ * atomic_dec_and_lock() --> refcount_dec_and_lock()
163
+ * atomic_dec_and_mutex_lock() --> refcount_dec_and_mutex_lock()
146164
147165 Memory ordering guarantees changes:
148166
149167 * fully ordered --> RELEASE ordering + control dependency + hold
150
- :c:func:`spin_lock` on success
168
+ spin_lock() on success