From: Peter Zijlstra <peterz@infradead.org>
To: linux-kernel@vger.kernel.org, mingo@kernel.org
Cc: jasonbaron0@gmail.com, bp@alien8.de, luto@amacapital.net,
tglx@linutronix.de, rostedt@goodmis.org, will.deacon@arm.com,
liuj97@gmail.com, rabin@rab.in, ralf@linux-mips.org,
ddaney@caviumnetworks.com, benh@kernel.crashing.org,
michael@ellerman.id.au, heiko.carstens@de.ibm.com,
davem@davemloft.net, peterz@infradead.org
Subject: [RFC][PATCH 2/7] jump_label: Rename JUMP_LABEL_TYPE_*
Date: Fri, 24 Jul 2015 19:52:11 +0200 [thread overview]
Message-ID: <20150724175822.672860585@infradead.org> (raw)
In-Reply-To: <20150724175209.814173117@infradead.org>
[-- Attachment #1: peterz-static-key-rename-jump_type.patch --]
[-- Type: text/plain, Size: 3784 bytes --]
Rename the JUMP_LABEL_TYPE_* macros to be JUMP_TYPE_* and move the
inline helpers into kernel/jump_label.c, since that's the only place
they're ever used.
Also rename the helpers.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/jump_label.h | 25 +++++--------------------
kernel/jump_label.c | 25 ++++++++++++++++---------
2 files changed, 21 insertions(+), 29 deletions(-)
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -101,24 +101,9 @@ static inline int static_key_count(struc
#ifdef HAVE_JUMP_LABEL
-#define JUMP_LABEL_TYPE_FALSE_BRANCH 0UL
-#define JUMP_LABEL_TYPE_TRUE_BRANCH 1UL
-#define JUMP_LABEL_TYPE_MASK 1UL
-
-static
-inline struct jump_entry *jump_label_get_entries(struct static_key *key)
-{
- return (struct jump_entry *)((unsigned long)key->entries
- & ~JUMP_LABEL_TYPE_MASK);
-}
-
-static inline bool jump_label_get_branch_default(struct static_key *key)
-{
- if (((unsigned long)key->entries & JUMP_LABEL_TYPE_MASK) ==
- JUMP_LABEL_TYPE_TRUE_BRANCH)
- return true;
- return false;
-}
+#define JUMP_TYPE_FALSE 0UL
+#define JUMP_TYPE_TRUE 1UL
+#define JUMP_TYPE_MASK 1UL
static __always_inline bool static_key_false(struct static_key *key)
{
@@ -147,10 +132,10 @@ extern void jump_label_apply_nops(struct
#define STATIC_KEY_INIT_TRUE ((struct static_key) \
{ .enabled = ATOMIC_INIT(1), \
- .entries = (void *)JUMP_LABEL_TYPE_TRUE_BRANCH })
+ .entries = (void *)JUMP_TYPE_TRUE })
#define STATIC_KEY_INIT_FALSE ((struct static_key) \
{ .enabled = ATOMIC_INIT(0), \
- .entries = (void *)JUMP_LABEL_TYPE_FALSE_BRANCH })
+ .entries = (void *)JUMP_TYPE_FALSE })
#else /* !HAVE_JUMP_LABEL */
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -56,6 +56,11 @@ jump_label_sort_entries(struct jump_entr
static void jump_label_update(struct static_key *key, int enable);
+static inline bool static_key_type(struct static_key *key)
+{
+ return (unsigned long)key->entries & JUMP_TYPE_MASK;
+}
+
void static_key_slow_inc(struct static_key *key)
{
STATIC_KEY_CHECK_USE();
@@ -64,7 +69,7 @@ void static_key_slow_inc(struct static_k
jump_label_lock();
if (atomic_read(&key->enabled) == 0) {
- if (!jump_label_get_branch_default(key))
+ if (!static_key_type(key))
jump_label_update(key, JUMP_LABEL_JMP);
else
jump_label_update(key, JUMP_LABEL_NOP);
@@ -87,7 +92,7 @@ static void __static_key_slow_dec(struct
atomic_inc(&key->enabled);
schedule_delayed_work(work, rate_limit);
} else {
- if (!jump_label_get_branch_default(key))
+ if (!static_key_type(key))
jump_label_update(key, JUMP_LABEL_NOP);
else
jump_label_update(key, JUMP_LABEL_JMP);
@@ -178,15 +183,17 @@ static void __jump_label_update(struct s
}
}
-static enum jump_label_type jump_label_type(struct static_key *key)
+static inline struct jump_entry *static_key_entries(struct static_key *key)
{
- bool true_branch = jump_label_get_branch_default(key);
- bool state = static_key_enabled(key);
+ return (struct jump_entry *)((unsigned long)key->entries & ~JUMP_TYPE_MASK);
+}
- if ((!true_branch && state) || (true_branch && !state))
- return JUMP_LABEL_JMP;
+static enum jump_label_type jump_label_type(struct static_key *key)
+{
+ bool enabled = static_key_enabled(key);
+ bool type = static_key_type(key);
- return JUMP_LABEL_NOP;
+ return enabled ^ type;
}
void __init jump_label_init(void)
@@ -442,7 +449,7 @@ int jump_label_text_reserved(void *start
static void jump_label_update(struct static_key *key, int enable)
{
struct jump_entry *stop = __stop___jump_table;
- struct jump_entry *entry = jump_label_get_entries(key);
+ struct jump_entry *entry = static_key_entries(key);
#ifdef CONFIG_MODULES
struct module *mod;
next prev parent reply other threads:[~2015-07-24 18:01 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-24 17:52 [RFC][PATCH 0/7] jump_label: Another (better) static_key interface Peter Zijlstra
2015-07-24 17:52 ` [RFC][PATCH 1/7] jump_label: Rename JUMP_LABEL_{EN,DIS}ABLE Peter Zijlstra
2015-07-24 17:52 ` Peter Zijlstra [this message]
2015-07-24 17:52 ` [RFC][PATCH 3/7] jump_label: Add jump_entry_key() helper Peter Zijlstra
2015-07-24 17:52 ` [RFC][PATCH 4/7] jump_label: Add static_key_{en,dis}able() helpers Peter Zijlstra
2015-07-24 17:52 ` [RFC][PATCH 5/7] jump_label: Rework update logic Peter Zijlstra
2015-07-27 9:07 ` Peter Zijlstra
2015-07-27 10:47 ` Peter Zijlstra
2015-07-27 16:30 ` Peter Zijlstra
2015-07-28 5:54 ` Heiko Carstens
2015-07-24 17:52 ` [RFC][PATCH 6/7] jump_label: Add a new static_key interface Peter Zijlstra
2015-07-27 9:24 ` Peter Zijlstra
2015-07-27 9:52 ` Peter Zijlstra
2015-07-27 10:20 ` Heiko Carstens
2015-07-27 10:47 ` Peter Zijlstra
2015-07-27 10:50 ` Peter Zijlstra
2015-07-27 10:52 ` Heiko Carstens
2015-07-27 11:03 ` Peter Zijlstra
2015-07-27 14:39 ` Peter Zijlstra
2015-07-27 10:45 ` Peter Zijlstra
2015-07-27 10:51 ` Heiko Carstens
2015-07-24 17:52 ` [RFC][PATCH 7/7] x86, tsc: Employ static_branch_likely() Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150724175822.672860585@infradead.org \
--to=peterz@infradead.org \
--cc=benh@kernel.crashing.org \
--cc=bp@alien8.de \
--cc=davem@davemloft.net \
--cc=ddaney@caviumnetworks.com \
--cc=heiko.carstens@de.ibm.com \
--cc=jasonbaron0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liuj97@gmail.com \
--cc=luto@amacapital.net \
--cc=michael@ellerman.id.au \
--cc=mingo@kernel.org \
--cc=rabin@rab.in \
--cc=ralf@linux-mips.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®