Thread (8 messages) 8 messages, 3 authors, 2022-11-04

Re: [PATCH v2 1/3] jump_label: Add static_key_fast_inc()

From: Peter Zijlstra <peterz@infradead.org>
Date: 2022-11-03 21:42:22
Also in: lkml

On Thu, Nov 03, 2022 at 09:25:22PM +0000, Dmitry Safonov wrote:
A helper to add another user for an existing enabled static key.
Utter lack of clue what for.
+/***
+ * static_key_fast_inc - adds a user for a static key
+ * @key: static key that must be already enabled
+ *
+ * The caller must make sure that the static key can't get disabled while
+ * in this function. It doesn't patch jump labels, only adds a user to
+ * an already enabled static key.
+ */
+static inline void static_key_fast_inc(struct static_key *key)
+{
+	STATIC_KEY_CHECK_USE(key);
+	WARN_ON_ONCE(atomic_read(&key->enabled) < 1);
+	atomic_inc(&key->enabled);
+}
And no, that's racy as heck. We have things like atomic_inc_not_zero(),
I suggest looking into it.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help