mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 10:41:38 -04:00
static keys: Introduce 'struct static_key', static_key_true()/false() and static_key_slow_[inc|dec]()
So here's a boot tested patch on top of Jason's series that does
all the cleanups I talked about and turns jump labels into a
more intuitive to use facility. It should also address the
various misconceptions and confusions that surround jump labels.
Typical usage scenarios:
#include <linux/static_key.h>
struct static_key key = STATIC_KEY_INIT_TRUE;
if (static_key_false(&key))
do unlikely code
else
do likely code
Or:
if (static_key_true(&key))
do likely code
else
do unlikely code
The static key is modified via:
static_key_slow_inc(&key);
...
static_key_slow_dec(&key);
The 'slow' prefix makes it abundantly clear that this is an
expensive operation.
I've updated all in-kernel code to use this everywhere. Note
that I (intentionally) have not pushed through the rename
blindly through to the lowest levels: the actual jump-label
patching arch facility should be named like that, so we want to
decouple jump labels from the static-key facility a bit.
On non-jump-label enabled architectures static keys default to
likely()/unlikely() branches.
Signed-off-by: Ingo Molnar <[email protected]>
Acked-by: Jason Baron <[email protected]>
Acked-by: Steven Rostedt <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Linus Torvalds <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
This commit is contained in:
parent
1cfa60dc7d
commit
c5905afb0e
31 changed files with 298 additions and 205 deletions
|
|
@ -162,13 +162,13 @@ static int sched_feat_show(struct seq_file *m, void *v)
|
|||
|
||||
#ifdef HAVE_JUMP_LABEL
|
||||
|
||||
#define jump_label_key__true jump_label_key_enabled
|
||||
#define jump_label_key__false jump_label_key_disabled
|
||||
#define jump_label_key__true STATIC_KEY_INIT_TRUE
|
||||
#define jump_label_key__false STATIC_KEY_INIT_FALSE
|
||||
|
||||
#define SCHED_FEAT(name, enabled) \
|
||||
jump_label_key__##enabled ,
|
||||
|
||||
struct jump_label_key sched_feat_keys[__SCHED_FEAT_NR] = {
|
||||
struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
|
||||
#include "features.h"
|
||||
};
|
||||
|
||||
|
|
@ -176,14 +176,14 @@ struct jump_label_key sched_feat_keys[__SCHED_FEAT_NR] = {
|
|||
|
||||
static void sched_feat_disable(int i)
|
||||
{
|
||||
if (jump_label_enabled(&sched_feat_keys[i]))
|
||||
jump_label_dec(&sched_feat_keys[i]);
|
||||
if (static_key_enabled(&sched_feat_keys[i]))
|
||||
static_key_slow_dec(&sched_feat_keys[i]);
|
||||
}
|
||||
|
||||
static void sched_feat_enable(int i)
|
||||
{
|
||||
if (!jump_label_enabled(&sched_feat_keys[i]))
|
||||
jump_label_inc(&sched_feat_keys[i]);
|
||||
if (!static_key_enabled(&sched_feat_keys[i]))
|
||||
static_key_slow_inc(&sched_feat_keys[i]);
|
||||
}
|
||||
#else
|
||||
static void sched_feat_disable(int i) { };
|
||||
|
|
@ -894,7 +894,7 @@ static void update_rq_clock_task(struct rq *rq, s64 delta)
|
|||
delta -= irq_delta;
|
||||
#endif
|
||||
#ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
|
||||
if (static_branch((¶virt_steal_rq_enabled))) {
|
||||
if (static_key_false((¶virt_steal_rq_enabled))) {
|
||||
u64 st;
|
||||
|
||||
steal = paravirt_steal_clock(cpu_of(rq));
|
||||
|
|
@ -2756,7 +2756,7 @@ void account_idle_time(cputime_t cputime)
|
|||
static __always_inline bool steal_account_process_tick(void)
|
||||
{
|
||||
#ifdef CONFIG_PARAVIRT
|
||||
if (static_branch(¶virt_steal_enabled)) {
|
||||
if (static_key_false(¶virt_steal_enabled)) {
|
||||
u64 steal, st = 0;
|
||||
|
||||
steal = paravirt_steal_clock(smp_processor_id());
|
||||
|
|
|
|||
|
|
@ -1399,20 +1399,20 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)
|
|||
#ifdef CONFIG_CFS_BANDWIDTH
|
||||
|
||||
#ifdef HAVE_JUMP_LABEL
|
||||
static struct jump_label_key __cfs_bandwidth_used;
|
||||
static struct static_key __cfs_bandwidth_used;
|
||||
|
||||
static inline bool cfs_bandwidth_used(void)
|
||||
{
|
||||
return static_branch(&__cfs_bandwidth_used);
|
||||
return static_key_false(&__cfs_bandwidth_used);
|
||||
}
|
||||
|
||||
void account_cfs_bandwidth_used(int enabled, int was_enabled)
|
||||
{
|
||||
/* only need to count groups transitioning between enabled/!enabled */
|
||||
if (enabled && !was_enabled)
|
||||
jump_label_inc(&__cfs_bandwidth_used);
|
||||
static_key_slow_inc(&__cfs_bandwidth_used);
|
||||
else if (!enabled && was_enabled)
|
||||
jump_label_dec(&__cfs_bandwidth_used);
|
||||
static_key_slow_dec(&__cfs_bandwidth_used);
|
||||
}
|
||||
#else /* HAVE_JUMP_LABEL */
|
||||
static bool cfs_bandwidth_used(void)
|
||||
|
|
|
|||
|
|
@ -611,7 +611,7 @@ static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
|
|||
* Tunables that become constants when CONFIG_SCHED_DEBUG is off:
|
||||
*/
|
||||
#ifdef CONFIG_SCHED_DEBUG
|
||||
# include <linux/jump_label.h>
|
||||
# include <linux/static_key.h>
|
||||
# define const_debug __read_mostly
|
||||
#else
|
||||
# define const_debug const
|
||||
|
|
@ -630,18 +630,18 @@ enum {
|
|||
#undef SCHED_FEAT
|
||||
|
||||
#if defined(CONFIG_SCHED_DEBUG) && defined(HAVE_JUMP_LABEL)
|
||||
static __always_inline bool static_branch__true(struct jump_label_key *key)
|
||||
static __always_inline bool static_branch__true(struct static_key *key)
|
||||
{
|
||||
return likely(static_branch(key)); /* Not out of line branch. */
|
||||
return static_key_true(key); /* Not out of line branch. */
|
||||
}
|
||||
|
||||
static __always_inline bool static_branch__false(struct jump_label_key *key)
|
||||
static __always_inline bool static_branch__false(struct static_key *key)
|
||||
{
|
||||
return unlikely(static_branch(key)); /* Out of line branch. */
|
||||
return static_key_false(key); /* Out of line branch. */
|
||||
}
|
||||
|
||||
#define SCHED_FEAT(name, enabled) \
|
||||
static __always_inline bool static_branch_##name(struct jump_label_key *key) \
|
||||
static __always_inline bool static_branch_##name(struct static_key *key) \
|
||||
{ \
|
||||
return static_branch__##enabled(key); \
|
||||
}
|
||||
|
|
@ -650,7 +650,7 @@ static __always_inline bool static_branch_##name(struct jump_label_key *key) \
|
|||
|
||||
#undef SCHED_FEAT
|
||||
|
||||
extern struct jump_label_key sched_feat_keys[__SCHED_FEAT_NR];
|
||||
extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];
|
||||
#define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))
|
||||
#else /* !(SCHED_DEBUG && HAVE_JUMP_LABEL) */
|
||||
#define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
|
||||
|
|
|
|||
Loading…
Reference in a new issue