Skip to contentSkip to conversation

delayacct: use macro to simplify delayacct_end calls

PATCH In review Ye Liu 2 participants 3 messages Apr 14, 2025 – Apr 21, 2025

Subsystems (2)
lore
Share & tools
lore

Ye Liu

author
#0 lore raw

PATCH 1/1 delayacct: use macro to simplify delayacct_end calls

From: Ye Liu <[email protected]>

Replace repetitive calls to delayacct_end() with a new macro DELAYACCT_END to reduce code duplication.
No functional changes.

---
 kernel/delayacct.c | 50 +++++++++++++---------------------------------
 1 file changed, 14 insertions(+), 36 deletions(-)
kernel/delayacct.c +14 -36
index eb63a021ac04..3d7ca3928be2 100644
@@ -18,6 +18,14 @@ DEFINE_STATIC_KEY_FALSE(delayacct_key);
 int delayacct_on __read_mostly;	/* Delay accounting turned on/off */
 struct kmem_cache *delayacct_cache;
 
+#define DELAYACCT_END(task, type) \
+	delayacct_end(&(task)->delays->lock, \
+		      &(task)->delays->type##_start, \
+		      &(task)->delays->type##_delay, \
+		      &(task)->delays->type##_count, \
+		      &(task)->delays->type##_delay_max, \
+		      &(task)->delays->type##_delay_min)
+
 static void set_delayacct(bool enabled)
 {
 	if (enabled) {
@@ -123,12 +131,7 @@ void __delayacct_blkio_start(void)
  */
 void __delayacct_blkio_end(struct task_struct *p)
 {
-	delayacct_end(&p->delays->lock,
-		      &p->delays->blkio_start,
-		      &p->delays->blkio_delay,
-		      &p->delays->blkio_count,
-		      &p->delays->blkio_delay_max,
-		      &p->delays->blkio_delay_min);
+	DELAYACCT_END(p, blkio);
 }
 
 int delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
@@ -231,12 +234,7 @@ void __delayacct_freepages_start(void)
 
 void __delayacct_freepages_end(void)
 {
-	delayacct_end(&current->delays->lock,
-		      &current->delays->freepages_start,
-		      &current->delays->freepages_delay,
-		      &current->delays->freepages_count,
-		      &current->delays->freepages_delay_max,
-		      &current->delays->freepages_delay_min);
+	DELAYACCT_END(current, freepages);
 }
 
 void __delayacct_thrashing_start(bool *in_thrashing)
@@ -255,12 +253,7 @@ void __delayacct_thrashing_end(bool *in_thrashing)
 		return;
 
 	current->in_thrashing = 0;
-	delayacct_end(&current->delays->lock,
-		      &current->delays->thrashing_start,
-		      &current->delays->thrashing_delay,
-		      &current->delays->thrashing_count,
-		      &current->delays->thrashing_delay_max,
-		      &current->delays->thrashing_delay_min);
+	DELAYACCT_END(current, thrashing);
 }
 
 void __delayacct_swapin_start(void)
@@ -270,12 +263,7 @@ void __delayacct_swapin_start(void)
 
 void __delayacct_swapin_end(void)
 {
-	delayacct_end(&current->delays->lock,
-		      &current->delays->swapin_start,
-		      &current->delays->swapin_delay,
-		      &current->delays->swapin_count,
-		      &current->delays->swapin_delay_max,
-		      &current->delays->swapin_delay_min);
+	DELAYACCT_END(current, swapin);
 }
 
 void __delayacct_compact_start(void)
@@ -285,12 +273,7 @@ void __delayacct_compact_start(void)
 
 void __delayacct_compact_end(void)
 {
-	delayacct_end(&current->delays->lock,
-		      &current->delays->compact_start,
-		      &current->delays->compact_delay,
-		      &current->delays->compact_count,
-		      &current->delays->compact_delay_max,
-		      &current->delays->compact_delay_min);
+	DELAYACCT_END(current, compact);
 }
 
 void __delayacct_wpcopy_start(void)
@@ -300,12 +283,7 @@ void __delayacct_wpcopy_start(void)
 
 void __delayacct_wpcopy_end(void)
 {
-	delayacct_end(&current->delays->lock,
-		      &current->delays->wpcopy_start,
-		      &current->delays->wpcopy_delay,
-		      &current->delays->wpcopy_count,
-		      &current->delays->wpcopy_delay_max,
-		      &current->delays->wpcopy_delay_min);
+	DELAYACCT_END(current, wpcopy);
 }
 
 void __delayacct_irq(struct task_struct *task, u32 delta)
Signature · 1 line
2.25.1
#1 lore raw

Hi Ye Liu

Quoted 3 lines

Replace repetitive calls to delayacct_end() with a new macro DELAYACCT_END to reduce code duplication.
No functional changes.

Please CC [email protected] and [email protected] next time.

I think it's a good idea to use macros to reduce code duplication in functions. So what about also use macros to define
void __delayacct_##type##_end().

Thanks!

author
#2 lore raw
Quoted 11 lines · 在 2025/4/20 11:58, [email protected] 写道:

Hi Ye Liu

Quoted 3 lines

Replace repetitive calls to delayacct_end() with a new macro DELAYACCT_END to reduce code duplication.
No functional changes.

Please CC [email protected] and [email protected] next time.

I think it's a good idea to use macros to reduce code duplication in functions. So what about also use macros to define
void __delayacct_##type##_end().

Most functions can be replaced with macros, but considering that the parameters of __delayacct_thrashing_end in this batch of functions are inconsistent, is it worth using macro definitions only for other functions? Or do you have any good ideas?

void __delayacct_blkio_end(struct task_struct *p) void __delayacct_freepages_end(void)
void __delayacct_thrashing_end(bool *in_thrashing) void __delayacct_swapin_end(void)
void __delayacct_compact_end(void)
void __delayacct_wpcopy_end(void)

Thanks,
Ye Liu

Quoted 1 line

Thanks!