All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/2] cputime: remove duplicate code in account_process_tick
@ 2019-07-22  7:38 Alex Shi
  2019-07-22  7:38 ` [PATCH v3 2/2] cputime: remove rq parameter from irqtime_account_process_tick func Alex Shi
  2019-07-23  6:10 ` [PATCH v3 1/2] cputime: remove duplicate code in account_process_tick Alex Shi
  0 siblings, 2 replies; 3+ messages in thread
From: Alex Shi @ 2019-07-22  7:38 UTC (permalink / raw)
  Cc: Alex Shi, Ingo Molnar, Peter Zijlstra, Frederic Weisbecker,
	Wanpeng Li, Thomas Gleixner, linux-kernel

The irqtime_account_process_tick path was introduced for precise ns irq
time account from commit abb74cefa9c6 ("sched: Export ns irqtimes
through /proc/stat") while account_process_tick still use jiffes. This
divide isn't necessary especially now both paths are ns precison.

Move out the irqtime_account_process_tick func from IRQ_TIME_ACCOUNTING.
So it do generally same things as account_process_tick whenever if
IRQ_TIME_ACCOUNTING set or if sched_clock_irqtime enabled.

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: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
---
 kernel/sched/cputime.c | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 2305ce89a26c..5086b24d7bee 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
@@ -390,6 +389,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 	}
 }
 
+#ifdef CONFIG_IRQ_TIME_ACCOUNTING
 static void irqtime_account_idle_ticks(int ticks)
 {
 	struct rq *rq = this_rq();
@@ -398,8 +398,6 @@ static void irqtime_account_idle_ticks(int 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) { }
 #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
 
 /*
@@ -474,31 +472,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_cpu_enabled())
 		return;
 
-	if (sched_clock_irqtime) {
-		irqtime_account_process_tick(p, user_tick, rq, 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 != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
-		account_system_time(p, HARDIRQ_OFFSET, cputime);
-	else
-		account_idle_time(cputime);
+	irqtime_account_process_tick(p, user_tick, rq, 1);
 }
 
 /*
-- 
2.19.1.856.g8858448bb


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

* [PATCH v3 2/2] cputime: remove rq parameter from irqtime_account_process_tick func
  2019-07-22  7:38 [PATCH v3 1/2] cputime: remove duplicate code in account_process_tick Alex Shi
@ 2019-07-22  7:38 ` Alex Shi
  2019-07-23  6:10 ` [PATCH v3 1/2] cputime: remove duplicate code in account_process_tick Alex Shi
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Shi @ 2019-07-22  7:38 UTC (permalink / raw)
  Cc: Alex Shi, Ingo Molnar, Peter Zijlstra, Frederic Weisbecker,
	Wanpeng Li, Thomas Gleixner, linux-kernel

Using the per cpu rq in function internal is better and meaningful, don't
need get and pass it from outside as a parameter.

It also reduce the object size. with defconfig + CONFIG_IRQ_TIME_ACCOUNTING
             base		with this patch
cputime.o    10632 bytes	10568 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: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
---
 kernel/sched/cputime.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 5086b24d7bee..4e7a1841be86 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -354,9 +354,10 @@ 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;
+	struct rq *rq;
 
 	/*
 	 * When returning from idle, many ticks can get accounted at
@@ -370,6 +371,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 		return;
 
 	cputime -= other;
+	rq = this_rq();
 
 	if (this_cpu_ksoftirqd() == p) {
 		/*
@@ -392,9 +394,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
 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) { }
@@ -472,12 +472,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)
 {
-	struct rq *rq = this_rq();
-
 	if (vtime_accounting_cpu_enabled())
 		return;
 
-	irqtime_account_process_tick(p, user_tick, rq, 1);
+	irqtime_account_process_tick(p, user_tick, 1);
 }
 
 /*
-- 
2.19.1.856.g8858448bb


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

* Re: [PATCH v3 1/2] cputime: remove duplicate code in account_process_tick
  2019-07-22  7:38 [PATCH v3 1/2] cputime: remove duplicate code in account_process_tick Alex Shi
  2019-07-22  7:38 ` [PATCH v3 2/2] cputime: remove rq parameter from irqtime_account_process_tick func Alex Shi
@ 2019-07-23  6:10 ` Alex Shi
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Shi @ 2019-07-23  6:10 UTC (permalink / raw)
  Cc: Ingo Molnar, Peter Zijlstra, Frederic Weisbecker, Wanpeng Li,
	Thomas Gleixner, linux-kernel


Forget this patchset. I sent out a new 3 patches.

Thanks
Alex


在 2019/7/22 下午3:38, Alex Shi 写道:
> The irqtime_account_process_tick path was introduced for precise ns irq
> time account from commit abb74cefa9c6 ("sched: Export ns irqtimes
> through /proc/stat") while account_process_tick still use jiffes. This
> divide isn't necessary especially now both paths are ns precison.
> 
> Move out the irqtime_account_process_tick func from IRQ_TIME_ACCOUNTING.
> So it do generally same things as account_process_tick whenever if
> IRQ_TIME_ACCOUNTING set or if sched_clock_irqtime enabled.

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

end of thread, other threads:[~2019-07-23  6:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22  7:38 [PATCH v3 1/2] cputime: remove duplicate code in account_process_tick Alex Shi
2019-07-22  7:38 ` [PATCH v3 2/2] cputime: remove rq parameter from irqtime_account_process_tick func Alex Shi
2019-07-23  6:10 ` [PATCH v3 1/2] cputime: remove duplicate code in account_process_tick Alex Shi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.