Skip to content

Commit

Permalink
delayacct: Add static_branch in scheduler hooks
Browse files Browse the repository at this point in the history
Cheaper when delayacct is disabled.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Balbir Singh <bsingharora@gmail.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Link: https://lkml.kernel.org/r/20210505111525.248028369@infradead.org
  • Loading branch information
Peter Zijlstra committed May 12, 2021
1 parent 63b3f96 commit eee4d9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/linux/delayacct.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ struct task_delay_info {

#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/jump_label.h>

#ifdef CONFIG_TASK_DELAY_ACCT
DECLARE_STATIC_KEY_TRUE(delayacct_key);
extern int delayacct_on; /* Delay accounting turned on/off */
extern struct kmem_cache *delayacct_cache;
extern void delayacct_init(void);
Expand Down Expand Up @@ -114,13 +116,19 @@ static inline void delayacct_tsk_free(struct task_struct *tsk)

static inline void delayacct_blkio_start(void)
{
if (!static_branch_likely(&delayacct_key))
return;

delayacct_set_flag(current, DELAYACCT_PF_BLKIO);
if (current->delays)
__delayacct_blkio_start();
}

static inline void delayacct_blkio_end(struct task_struct *p)
{
if (!static_branch_likely(&delayacct_key))
return;

if (p->delays)
__delayacct_blkio_end(p);
delayacct_clear_flag(p, DELAYACCT_PF_BLKIO);
Expand Down
3 changes: 3 additions & 0 deletions kernel/delayacct.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/delayacct.h>
#include <linux/module.h>

DEFINE_STATIC_KEY_TRUE(delayacct_key);
int delayacct_on __read_mostly = 1; /* Delay accounting turned on/off */
struct kmem_cache *delayacct_cache;

Expand All @@ -28,6 +29,8 @@ void delayacct_init(void)
{
delayacct_cache = KMEM_CACHE(task_delay_info, SLAB_PANIC|SLAB_ACCOUNT);
delayacct_tsk_init(&init_task);
if (!delayacct_on)
static_branch_disable(&delayacct_key);
}

void __delayacct_tsk_init(struct task_struct *tsk)
Expand Down

0 comments on commit eee4d9f

Please sign in to comment.