lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <8e5d6ed7d70ff7187a33130231783ed2c1d70841.1696761522.git.chunguang.xu@shopee.com>
Date:   Sun,  8 Oct 2023 18:49:36 +0800
From:   "brookxu.cn" <brookxu.cn@...il.com>
To:     bsingharora@...il.com, juri.lelli@...hat.com, peterz@...radead.org,
        vincent.guittot@...aro.org
Cc:     linux-kernel@...r.kernel.org
Subject: [PATCH 1/3] delayacct: introduce delayacct_enabled() to simplify implement

From: Chunguang Xu <chunguang.xu@...pee.com>

Introduce delayacct_enabled() to simplify the code and make it
more concise.

Signed-off-by: Chunguang Xu <chunguang.xu@...pee.com>
---
 include/linux/delayacct.h | 74 +++++++++++----------------------------
 kernel/delayacct.c        |  2 +-
 2 files changed, 21 insertions(+), 55 deletions(-)

diff --git a/include/linux/delayacct.h b/include/linux/delayacct.h
index 6639f48dac36..660e534ce7c4 100644
--- a/include/linux/delayacct.h
+++ b/include/linux/delayacct.h
@@ -94,137 +94,103 @@ static inline void delayacct_tsk_init(struct task_struct *tsk)
 		__delayacct_tsk_init(tsk);
 }
 
+static inline bool delayacct_enabled(void)
+{
+	return static_branch_unlikely(&delayacct_key);
+}
+
 /* Free tsk->delays. Called from bad fork and __put_task_struct
  * where there's no risk of tsk->delays being accessed elsewhere
  */
 static inline void delayacct_tsk_free(struct task_struct *tsk)
 {
-	if (tsk->delays)
+	if (delayacct_enabled())
 		kmem_cache_free(delayacct_cache, tsk->delays);
 	tsk->delays = NULL;
 }
 
 static inline void delayacct_blkio_start(void)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_blkio_start();
 }
 
 static inline void delayacct_blkio_end(struct task_struct *p)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (p->delays)
+	if (delayacct_enabled())
 		__delayacct_blkio_end(p);
 }
 
 static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
 {
-	if (tsk->delays)
+	if (delayacct_enabled())
 		return __delayacct_blkio_ticks(tsk);
 	return 0;
 }
 
 static inline void delayacct_freepages_start(void)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_freepages_start();
 }
 
 static inline void delayacct_freepages_end(void)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_freepages_end();
 }
 
 static inline void delayacct_thrashing_start(bool *in_thrashing)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_thrashing_start(in_thrashing);
 }
 
 static inline void delayacct_thrashing_end(bool *in_thrashing)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_thrashing_end(in_thrashing);
 }
 
 static inline void delayacct_swapin_start(void)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_swapin_start();
 }
 
 static inline void delayacct_swapin_end(void)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_swapin_end();
 }
 
 static inline void delayacct_compact_start(void)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_compact_start();
 }
 
 static inline void delayacct_compact_end(void)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_compact_end();
 }
 
 static inline void delayacct_wpcopy_start(void)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_wpcopy_start();
 }
 
 static inline void delayacct_wpcopy_end(void)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (current->delays)
+	if (delayacct_enabled())
 		__delayacct_wpcopy_end();
 }
 
 static inline void delayacct_irq(struct task_struct *task, u32 delta)
 {
-	if (!static_branch_unlikely(&delayacct_key))
-		return;
-
-	if (task->delays)
+	if (delayacct_enabled())
 		__delayacct_irq(task, delta);
 }
 
diff --git a/kernel/delayacct.c b/kernel/delayacct.c
index 6f0c358e73d8..ce10b7c1ee43 100644
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -161,7 +161,7 @@ int delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
 	d->cpu_run_virtual_total =
 		(tmp < (s64)d->cpu_run_virtual_total) ?	0 : tmp;
 
-	if (!tsk->delays)
+	if (!delayacct_enabled())
 		return 0;
 
 	/* zero XXX_total, non-zero XXX_count implies XXX stat overflowed */
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ