2021-05-05 13:14:56

by Peter Zijlstra

[permalink] [raw]
Subject: [PATCH 5/6] delayacct: Add static_branch in scheduler hooks

Cheaper when delayacct is disabled.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
include/linux/delayacct.h | 8 ++++++++
kernel/delayacct.c | 3 +++
2 files changed, 11 insertions(+)

--- a/include/linux/delayacct.h
+++ b/include/linux/delayacct.h
@@ -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);
@@ -114,6 +116,9 @@ static inline void delayacct_tsk_free(st

static inline void delayacct_blkio_start(void)
{
+ if (!static_branch_likely(&delayacct_key))
+ return;
+
delayacct_set_flag(DELAYACCT_PF_BLKIO);
if (current->delays)
__delayacct_blkio_start();
@@ -121,6 +126,9 @@ static inline void 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(DELAYACCT_PF_BLKIO);
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -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;

@@ -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)



2021-05-06 14:07:53

by Johannes Weiner

[permalink] [raw]
Subject: Re: [PATCH 5/6] delayacct: Add static_branch in scheduler hooks

On Wed, May 05, 2021 at 12:59:45PM +0200, Peter Zijlstra wrote:
> Cheaper when delayacct is disabled.
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>

Acked-by: Johannes Weiner <[email protected]>

2021-05-10 08:43:53

by Balbir Singh

[permalink] [raw]
Subject: Re: [PATCH 5/6] delayacct: Add static_branch in scheduler hooks

On Wed, May 05, 2021 at 12:59:45PM +0200, Peter Zijlstra wrote:
> Cheaper when delayacct is disabled.
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> ---

Acked-by: Balbir Singh <[email protected]>

Subject: [tip: sched/core] delayacct: Add static_branch in scheduler hooks

The following commit has been merged into the sched/core branch of tip:

Commit-ID: eee4d9fee2544389e5ce5697ed92db67c86d7a9f
Gitweb: https://git.kernel.org/tip/eee4d9fee2544389e5ce5697ed92db67c86d7a9f
Author: Peter Zijlstra <[email protected]>
AuthorDate: Tue, 04 May 2021 22:43:36 +02:00
Committer: Peter Zijlstra <[email protected]>
CommitterDate: Wed, 12 May 2021 11:43:25 +02:00

delayacct: Add static_branch in scheduler hooks

Cheaper when delayacct is disabled.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Thomas Gleixner <[email protected]>
Reviewed-by: Ingo Molnar <[email protected]>
Acked-by: Balbir Singh <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
include/linux/delayacct.h | 8 ++++++++
kernel/delayacct.c | 3 +++
2 files changed, 11 insertions(+)

diff --git a/include/linux/delayacct.h b/include/linux/delayacct.h
index 21651f9..57fefa5 100644
--- a/include/linux/delayacct.h
+++ b/include/linux/delayacct.h
@@ -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);
@@ -114,6 +116,9 @@ 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();
@@ -121,6 +126,9 @@ static inline void delayacct_blkio_start(void)

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);
diff --git a/kernel/delayacct.c b/kernel/delayacct.c
index 3a0b910..63012fd 100644
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -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;

@@ -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)

2021-05-12 11:17:47

by Mel Gorman

[permalink] [raw]
Subject: Re: [PATCH 5/6] delayacct: Add static_branch in scheduler hooks

On Wed, May 05, 2021 at 12:59:45PM +0200, Peter Zijlstra wrote:
> Cheaper when delayacct is disabled.
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>

Acked-by: Mel Gorman <[email protected]>

--
Mel Gorman
SUSE Labs