Commit 9bc2ff87 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Peter Zijlstra

jump_label: Simplify and clarify static_key_fast_inc_cpus_locked()

Make the code more obvious and add proper comments to avoid future head
scratching.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20240610124406.548322963@linutronix.de
parent 695ef796
...@@ -162,22 +162,24 @@ bool static_key_slow_inc_cpuslocked(struct static_key *key) ...@@ -162,22 +162,24 @@ bool static_key_slow_inc_cpuslocked(struct static_key *key)
if (static_key_fast_inc_not_disabled(key)) if (static_key_fast_inc_not_disabled(key))
return true; return true;
jump_label_lock(); guard(mutex)(&jump_label_mutex);
if (atomic_read(&key->enabled) == 0) { /* Try to mark it as 'enabling in progress. */
atomic_set(&key->enabled, -1); if (!atomic_cmpxchg(&key->enabled, 0, -1)) {
jump_label_update(key); jump_label_update(key);
/* /*
* Ensure that if the above cmpxchg loop observes our positive * Ensure that when static_key_fast_inc_not_disabled() or
* value, it must also observe all the text changes. * static_key_slow_try_dec() observe the positive value,
* they must also observe all the text changes.
*/ */
atomic_set_release(&key->enabled, 1); atomic_set_release(&key->enabled, 1);
} else { } else {
if (WARN_ON_ONCE(!static_key_fast_inc_not_disabled(key))) { /*
jump_label_unlock(); * While holding the mutex this should never observe
* anything else than a value >= 1 and succeed
*/
if (WARN_ON_ONCE(!static_key_fast_inc_not_disabled(key)))
return false; return false;
}
} }
jump_label_unlock();
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment