linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick
@ 2020-01-02 10:07 Alex Shi
  2020-01-02 10:07 ` [PATCH 2/3] sched/cputime: code cleanup " Alex Shi
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Alex Shi @ 2020-01-02 10:07 UTC (permalink / raw)
  Cc: Ingo Molnar, Peter Zijlstra, Frederic Weisbecker, Wanpeng Li,
	Anna-Maria Gleixner, Thomas Gleixner, linux-kernel

Every time we call irqtime_account_process_tick() is in a interrupt,
Every caller will get and assign a parameter rq = this_rq(), This is
unnecessary and increase the code size a little bit. Move the rq getting
action to irqtime_account_process_tick internally is better.

             base               with this patch
cputime.o    578792 bytes        577888 bytes

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Cc: Anna-Maria Gleixner <anna-maria@linutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
---
 kernel/sched/cputime.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index d43318a489f2..cff3e656566d 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -355,7 +355,7 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
  * softirq as those do not count in task exec_runtime any more.
  */
 static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
-					 struct rq *rq, int ticks)
+					 int ticks)
 {
 	u64 other, cputime = TICK_NSEC * ticks;
 
@@ -381,7 +381,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 		account_system_index_time(p, cputime, CPUTIME_SOFTIRQ);
 	} else if (user_tick) {
 		account_user_time(p, cputime);
-	} else if (p == rq->idle) {
+	} else if (p == this_rq()->idle) {
 		account_idle_time(cputime);
 	} else if (p->flags & PF_VCPU) { /* System time or guest time */
 		account_guest_time(p, cputime);
@@ -392,14 +392,12 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 
 static void irqtime_account_idle_ticks(int ticks)
 {
-	struct rq *rq = this_rq();
-
-	irqtime_account_process_tick(current, 0, rq, ticks);
+	irqtime_account_process_tick(current, 0, ticks);
 }
 #else /* CONFIG_IRQ_TIME_ACCOUNTING */
 static inline void irqtime_account_idle_ticks(int ticks) { }
 static inline void irqtime_account_process_tick(struct task_struct *p, int user_tick,
-						struct rq *rq, int nr_ticks) { }
+						int nr_ticks) { }
 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
 
 /*
@@ -473,13 +471,12 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)
 void account_process_tick(struct task_struct *p, int user_tick)
 {
 	u64 cputime, steal;
-	struct rq *rq = this_rq();
 
 	if (vtime_accounting_enabled_this_cpu())
 		return;
 
 	if (sched_clock_irqtime) {
-		irqtime_account_process_tick(p, user_tick, rq, 1);
+		irqtime_account_process_tick(p, user_tick, 1);
 		return;
 	}
 
@@ -493,7 +490,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
 
 	if (user_tick)
 		account_user_time(p, cputime);
-	else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
+	else if ((p != this_rq()->idle) || (irq_count() != HARDIRQ_OFFSET))
 		account_system_time(p, HARDIRQ_OFFSET, cputime);
 	else
 		account_idle_time(cputime);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] sched/cputime: code cleanup in irqtime_account_process_tick
  2020-01-02 10:07 [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick Alex Shi
@ 2020-01-02 10:07 ` Alex Shi
  2020-01-06 15:53   ` Frederic Weisbecker
  2020-01-02 10:07 ` [PATCH 3/3] sched/cputime: cleanup account_process_tick/account_idle_ticks Alex Shi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Alex Shi @ 2020-01-02 10:07 UTC (permalink / raw)
  Cc: Ingo Molnar, Peter Zijlstra, Frederic Weisbecker, Wanpeng Li,
	Anna-Maria Gleixner, Thomas Gleixner, linux-kernel

In this func, since account_system_time() considers guest time account
and other system time.  we could fold the account_guest_time into
account_system_time() to simply the code.

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Cc: Anna-Maria Gleixner <anna-maria@linutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
---
 kernel/sched/cputime.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index cff3e656566d..46b837e94fce 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -381,13 +381,10 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 		account_system_index_time(p, cputime, CPUTIME_SOFTIRQ);
 	} else if (user_tick) {
 		account_user_time(p, cputime);
-	} else if (p == this_rq()->idle) {
+	} else if ((p != this_rq()->idle) || (irq_count() != HARDIRQ_OFFSET))
+		account_system_time(p, HARDIRQ_OFFSET, cputime);
+	else
 		account_idle_time(cputime);
-	} else if (p->flags & PF_VCPU) { /* System time or guest time */
-		account_guest_time(p, cputime);
-	} else {
-		account_system_index_time(p, cputime, CPUTIME_SYSTEM);
-	}
 }
 
 static void irqtime_account_idle_ticks(int ticks)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] sched/cputime: cleanup account_process_tick/account_idle_ticks
  2020-01-02 10:07 [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick Alex Shi
  2020-01-02 10:07 ` [PATCH 2/3] sched/cputime: code cleanup " Alex Shi
@ 2020-01-02 10:07 ` Alex Shi
  2020-01-06 14:55 ` [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick Peter Zijlstra
  2020-01-17 10:08 ` [tip: sched/core] " tip-bot2 for Alex Shi
  3 siblings, 0 replies; 8+ messages in thread
From: Alex Shi @ 2020-01-02 10:07 UTC (permalink / raw)
  Cc: Ingo Molnar, Peter Zijlstra, Frederic Weisbecker, Wanpeng Li,
	Anna-Maria Gleixner, Thomas Gleixner, linux-kernel

The irqtime_account_process_tick() was introduced for precise ns irq
time account from commit abb74cefa9c6 ("sched: Export ns irqtimes
through /proc/stat") which is necessary since account_process_tick()
still use jiffes at that time.

Now account_process_tick/account_idle_ticks functions do the actual
same actions as irqtime_account_process_tick() to account ns precision
cputime when !sched_clock_irqtime. which could be replaced by
irqtime_account_process_tick();

So we move out irqtime_account_process_tick from IRQ_TIME_ACCOUNTING
config, let it work w/o IRQ_TIME_ACCOUNTING. and remove the duplicated
code in account_process_tick/account_idle_ticks.
And furthmore I removed the function account_idle_ticks by a directly
call.

It can simplify the code, also reduce a bit object size.

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Cc: Anna-Maria Gleixner <anna-maria@linutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
---
 include/linux/kernel_stat.h |  2 +-
 kernel/sched/cputime.c      | 58 ++-------------------------------------------
 kernel/time/tick-sched.c    |  2 +-
 3 files changed, 4 insertions(+), 58 deletions(-)

diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 89f0745c096d..e924bdb8c874 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -113,6 +113,6 @@ static inline void account_process_tick(struct task_struct *tsk, int user)
 extern void account_process_tick(struct task_struct *, int user);
 #endif
 
-extern void account_idle_ticks(unsigned long ticks);
+extern void irqtime_account_process_tick(struct task_struct *, int , int);
 
 #endif /* _LINUX_KERNEL_STAT_H */
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 46b837e94fce..0e0c74c1b3c9 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -332,7 +332,6 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
 	rcu_read_unlock();
 }
 
-#ifdef CONFIG_IRQ_TIME_ACCOUNTING
 /*
  * Account a tick to a process and cpustat
  * @p: the process that the CPU time gets accounted to
@@ -354,7 +353,7 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
  * p->stime and friends are only updated on system time and not on irq
  * softirq as those do not count in task exec_runtime any more.
  */
-static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
+void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 					 int ticks)
 {
 	u64 other, cputime = TICK_NSEC * ticks;
@@ -387,16 +386,6 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 		account_idle_time(cputime);
 }
 
-static void irqtime_account_idle_ticks(int ticks)
-{
-	irqtime_account_process_tick(current, 0, ticks);
-}
-#else /* CONFIG_IRQ_TIME_ACCOUNTING */
-static inline void irqtime_account_idle_ticks(int ticks) { }
-static inline void irqtime_account_process_tick(struct task_struct *p, int user_tick,
-						int nr_ticks) { }
-#endif /* CONFIG_IRQ_TIME_ACCOUNTING */
-
 /*
  * Use precise platform statistics if available:
  */
@@ -467,53 +456,10 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)
  */
 void account_process_tick(struct task_struct *p, int user_tick)
 {
-	u64 cputime, steal;
-
 	if (vtime_accounting_enabled_this_cpu())
 		return;
 
-	if (sched_clock_irqtime) {
-		irqtime_account_process_tick(p, user_tick, 1);
-		return;
-	}
-
-	cputime = TICK_NSEC;
-	steal = steal_account_process_time(ULONG_MAX);
-
-	if (steal >= cputime)
-		return;
-
-	cputime -= steal;
-
-	if (user_tick)
-		account_user_time(p, cputime);
-	else if ((p != this_rq()->idle) || (irq_count() != HARDIRQ_OFFSET))
-		account_system_time(p, HARDIRQ_OFFSET, cputime);
-	else
-		account_idle_time(cputime);
-}
-
-/*
- * Account multiple ticks of idle time.
- * @ticks: number of stolen ticks
- */
-void account_idle_ticks(unsigned long ticks)
-{
-	u64 cputime, steal;
-
-	if (sched_clock_irqtime) {
-		irqtime_account_idle_ticks(ticks);
-		return;
-	}
-
-	cputime = ticks * TICK_NSEC;
-	steal = steal_account_process_time(ULONG_MAX);
-
-	if (steal >= cputime)
-		return;
-
-	cputime -= steal;
-	account_idle_time(cputime);
+	irqtime_account_process_tick(p, user_tick, 1);
 }
 
 /*
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 8b192e67aabc..92a0979633e9 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -1142,7 +1142,7 @@ static void tick_nohz_account_idle_ticks(struct tick_sched *ts)
 	 * We might be one off. Do not randomly account a huge number of ticks!
 	 */
 	if (ticks && ticks < LONG_MAX)
-		account_idle_ticks(ticks);
+		irqtime_account_process_tick(current, 0, ticks);
 #endif
 }
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick
  2020-01-02 10:07 [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick Alex Shi
  2020-01-02 10:07 ` [PATCH 2/3] sched/cputime: code cleanup " Alex Shi
  2020-01-02 10:07 ` [PATCH 3/3] sched/cputime: cleanup account_process_tick/account_idle_ticks Alex Shi
@ 2020-01-06 14:55 ` Peter Zijlstra
  2020-01-17 10:08 ` [tip: sched/core] " tip-bot2 for Alex Shi
  3 siblings, 0 replies; 8+ messages in thread
From: Peter Zijlstra @ 2020-01-06 14:55 UTC (permalink / raw)
  To: Alex Shi
  Cc: Ingo Molnar, Frederic Weisbecker, Wanpeng Li,
	Anna-Maria Gleixner, Thomas Gleixner, linux-kernel


Thanks, I think this looks like.

Frederic, if you have time, a second set of eyes would be appreciated.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] sched/cputime: code cleanup in irqtime_account_process_tick
  2020-01-02 10:07 ` [PATCH 2/3] sched/cputime: code cleanup " Alex Shi
@ 2020-01-06 15:53   ` Frederic Weisbecker
  2020-01-07  9:13     ` Peter Zijlstra
  0 siblings, 1 reply; 8+ messages in thread
From: Frederic Weisbecker @ 2020-01-06 15:53 UTC (permalink / raw)
  To: Alex Shi
  Cc: Ingo Molnar, Peter Zijlstra, Frederic Weisbecker, Wanpeng Li,
	Anna-Maria Gleixner, Thomas Gleixner, linux-kernel

On Thu, Jan 02, 2020 at 06:07:53PM +0800, Alex Shi wrote:
> In this func, since account_system_time() considers guest time account
> and other system time.  we could fold the account_guest_time into
> account_system_time() to simply the code.
> 
> Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Wanpeng Li <wanpeng.li@hotmail.com>
> Cc: Anna-Maria Gleixner <anna-maria@linutronix.de>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: linux-kernel@vger.kernel.org
> ---
>  kernel/sched/cputime.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> index cff3e656566d..46b837e94fce 100644
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -381,13 +381,10 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
>  		account_system_index_time(p, cputime, CPUTIME_SOFTIRQ);
>  	} else if (user_tick) {
>  		account_user_time(p, cputime);
> -	} else if (p == this_rq()->idle) {
> +	} else if ((p != this_rq()->idle) || (irq_count() != HARDIRQ_OFFSET))
> +		account_system_time(p, HARDIRQ_OFFSET, cputime);
> +	else

I fear we can't really play the exact same game as account_process_tick() here.
Since this is irqtime precise accounting, we have already computed the
irqtime delta in account_other_time() (or we will at some point in the future)
and substracted it from the ticks to account. This means that the remaining cputime
to account has to be either utime/stime/gtime/idle-time but not interrupt time, or
we may account interrupt time twice. And account_system_time() tries to account
irq time, for example if we interrupt a softirq.

Thanks.


>  		account_idle_time(cputime);
> -	} else if (p->flags & PF_VCPU) { /* System time or guest time */
> -		account_guest_time(p, cputime);
> -	} else {
> -		account_system_index_time(p, cputime, CPUTIME_SYSTEM);
> -	}
>  }
>  
>  static void irqtime_account_idle_ticks(int ticks)
> -- 
> 1.8.3.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] sched/cputime: code cleanup in irqtime_account_process_tick
  2020-01-06 15:53   ` Frederic Weisbecker
@ 2020-01-07  9:13     ` Peter Zijlstra
  2020-01-09 13:30       ` Alex Shi
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Zijlstra @ 2020-01-07  9:13 UTC (permalink / raw)
  To: Frederic Weisbecker
  Cc: Alex Shi, Ingo Molnar, Frederic Weisbecker, Wanpeng Li,
	Anna-Maria Gleixner, Thomas Gleixner, linux-kernel

On Mon, Jan 06, 2020 at 04:53:51PM +0100, Frederic Weisbecker wrote:
> On Thu, Jan 02, 2020 at 06:07:53PM +0800, Alex Shi wrote:
> > In this func, since account_system_time() considers guest time account
> > and other system time.  we could fold the account_guest_time into
> > account_system_time() to simply the code.
> > 
> > Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Frederic Weisbecker <fweisbec@gmail.com>
> > Cc: Wanpeng Li <wanpeng.li@hotmail.com>
> > Cc: Anna-Maria Gleixner <anna-maria@linutronix.de>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: linux-kernel@vger.kernel.org
> > ---
> >  kernel/sched/cputime.c | 9 +++------
> >  1 file changed, 3 insertions(+), 6 deletions(-)
> > 
> > diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> > index cff3e656566d..46b837e94fce 100644
> > --- a/kernel/sched/cputime.c
> > +++ b/kernel/sched/cputime.c
> > @@ -381,13 +381,10 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
> >  		account_system_index_time(p, cputime, CPUTIME_SOFTIRQ);
> >  	} else if (user_tick) {
> >  		account_user_time(p, cputime);
> > -	} else if (p == this_rq()->idle) {
> > +	} else if ((p != this_rq()->idle) || (irq_count() != HARDIRQ_OFFSET))
> > +		account_system_time(p, HARDIRQ_OFFSET, cputime);
> > +	else
> 
> I fear we can't really play the exact same game as account_process_tick() here.
> Since this is irqtime precise accounting, we have already computed the
> irqtime delta in account_other_time() (or we will at some point in the future)
> and substracted it from the ticks to account. This means that the remaining cputime
> to account has to be either utime/stime/gtime/idle-time but not interrupt time, or
> we may account interrupt time twice. And account_system_time() tries to account
> irq time, for example if we interrupt a softirq.

OK, I've dropped 2 and 3. Thanks Frederic!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] sched/cputime: code cleanup in irqtime_account_process_tick
  2020-01-07  9:13     ` Peter Zijlstra
@ 2020-01-09 13:30       ` Alex Shi
  0 siblings, 0 replies; 8+ messages in thread
From: Alex Shi @ 2020-01-09 13:30 UTC (permalink / raw)
  To: Peter Zijlstra, Frederic Weisbecker
  Cc: Ingo Molnar, Frederic Weisbecker, Wanpeng Li,
	Anna-Maria Gleixner, Thomas Gleixner, linux-kernel


>> I fear we can't really play the exact same game as account_process_tick() here.
>> Since this is irqtime precise accounting, we have already computed the
>> irqtime delta in account_other_time() (or we will at some point in the future)
>> and substracted it from the ticks to account. This means that the remaining cputime
>> to account has to be either utime/stime/gtime/idle-time but not interrupt time, or
>> we may account interrupt time twice. And account_system_time() tries to account
>> irq time, for example if we interrupt a softirq.
> 
> OK, I've dropped 2 and 3. Thanks Frederic!
> 

Hi Frederic & Peter,

Thanks a lot for the comments and review! 
It's my fault to mess up the account_system_time details. And seems there is no easy way to replace irqtime_account_process_tick or account_process_tick with each other.

but on the other side, the account_idle_ticks could be replaced by irqtime_account_process_tick, or at least to remove irqtime_account_idle_ticks function. Any comments?

Thanks
Alex

---

From 7073e60babc3b42a987b4e89f380956887734233 Mon Sep 17 00:00:00 2001
From: Alex Shi <alex.shi@linux.alibaba.com>
Date: Thu, 9 Jan 2020 20:32:55 +0800
Subject: [PATCH] sched/cputime: remove irqtime_account_idle_ticks

irqtime_account_idle_ticks and irqtime_account_process_tick use in same
condition. We don't bother to name and use a irqtime_account_idle_ticks
for only one calling. Remove the function to simply code and reduce a
bit object size of kernel.

And further more, we could replace account_idle_ticks by
irqtime_account_process_tick too. But feed and check 'current' looks weird.
So this is ok.

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com> 
Cc: Peter Zijlstra <peterz@infradead.org> 
Cc: linux-kernel@vger.kernel.org 
---
 kernel/sched/cputime.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index cff3e656566d..17640d145e44 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -390,12 +390,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 	}
 }
 
-static void irqtime_account_idle_ticks(int ticks)
-{
-	irqtime_account_process_tick(current, 0, ticks);
-}
 #else /* CONFIG_IRQ_TIME_ACCOUNTING */
-static inline void irqtime_account_idle_ticks(int ticks) { }
 static inline void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 						int nr_ticks) { }
 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
@@ -505,7 +500,7 @@ void account_idle_ticks(unsigned long ticks)
 	u64 cputime, steal;
 
 	if (sched_clock_irqtime) {
-		irqtime_account_idle_ticks(ticks);
+		irqtime_account_process_tick(current, 0, ticks);
 		return;
 	}
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [tip: sched/core] sched/cputime: move rq parameter in irqtime_account_process_tick
  2020-01-02 10:07 [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick Alex Shi
                   ` (2 preceding siblings ...)
  2020-01-06 14:55 ` [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick Peter Zijlstra
@ 2020-01-17 10:08 ` tip-bot2 for Alex Shi
  3 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Alex Shi @ 2020-01-17 10:08 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Alex Shi, Peter Zijlstra (Intel), x86, LKML

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

Commit-ID:     9dec1b6949ae9509cdc3edb2d75fda39c9db9fa2
Gitweb:        https://git.kernel.org/tip/9dec1b6949ae9509cdc3edb2d75fda39c9db9fa2
Author:        Alex Shi <alex.shi@linux.alibaba.com>
AuthorDate:    Thu, 02 Jan 2020 18:07:52 +08:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 17 Jan 2020 10:19:21 +01:00

sched/cputime: move rq parameter in irqtime_account_process_tick

Every time we call irqtime_account_process_tick() is in a interrupt,
Every caller will get and assign a parameter rq = this_rq(), This is
unnecessary and increase the code size a little bit. Move the rq getting
action to irqtime_account_process_tick internally is better.

             base               with this patch
cputime.o    578792 bytes        577888 bytes

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/1577959674-255537-1-git-send-email-alex.shi@linux.alibaba.com
---
 kernel/sched/cputime.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index d43318a..cff3e65 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -355,7 +355,7 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
  * softirq as those do not count in task exec_runtime any more.
  */
 static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
-					 struct rq *rq, int ticks)
+					 int ticks)
 {
 	u64 other, cputime = TICK_NSEC * ticks;
 
@@ -381,7 +381,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 		account_system_index_time(p, cputime, CPUTIME_SOFTIRQ);
 	} else if (user_tick) {
 		account_user_time(p, cputime);
-	} else if (p == rq->idle) {
+	} else if (p == this_rq()->idle) {
 		account_idle_time(cputime);
 	} else if (p->flags & PF_VCPU) { /* System time or guest time */
 		account_guest_time(p, cputime);
@@ -392,14 +392,12 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 
 static void irqtime_account_idle_ticks(int ticks)
 {
-	struct rq *rq = this_rq();
-
-	irqtime_account_process_tick(current, 0, rq, ticks);
+	irqtime_account_process_tick(current, 0, ticks);
 }
 #else /* CONFIG_IRQ_TIME_ACCOUNTING */
 static inline void irqtime_account_idle_ticks(int ticks) { }
 static inline void irqtime_account_process_tick(struct task_struct *p, int user_tick,
-						struct rq *rq, int nr_ticks) { }
+						int nr_ticks) { }
 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
 
 /*
@@ -473,13 +471,12 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st)
 void account_process_tick(struct task_struct *p, int user_tick)
 {
 	u64 cputime, steal;
-	struct rq *rq = this_rq();
 
 	if (vtime_accounting_enabled_this_cpu())
 		return;
 
 	if (sched_clock_irqtime) {
-		irqtime_account_process_tick(p, user_tick, rq, 1);
+		irqtime_account_process_tick(p, user_tick, 1);
 		return;
 	}
 
@@ -493,7 +490,7 @@ void account_process_tick(struct task_struct *p, int user_tick)
 
 	if (user_tick)
 		account_user_time(p, cputime);
-	else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
+	else if ((p != this_rq()->idle) || (irq_count() != HARDIRQ_OFFSET))
 		account_system_time(p, HARDIRQ_OFFSET, cputime);
 	else
 		account_idle_time(cputime);

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-01-17 10:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-02 10:07 [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick Alex Shi
2020-01-02 10:07 ` [PATCH 2/3] sched/cputime: code cleanup " Alex Shi
2020-01-06 15:53   ` Frederic Weisbecker
2020-01-07  9:13     ` Peter Zijlstra
2020-01-09 13:30       ` Alex Shi
2020-01-02 10:07 ` [PATCH 3/3] sched/cputime: cleanup account_process_tick/account_idle_ticks Alex Shi
2020-01-06 14:55 ` [PATCH 1/3] sched/cputime: move rq parameter in irqtime_account_process_tick Peter Zijlstra
2020-01-17 10:08 ` [tip: sched/core] " tip-bot2 for Alex Shi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).