linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Shi <alex.shi@linux.alibaba.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Wanpeng Li <wanpeng.li@hotmail.com>,
	Anna-Maria Gleixner <anna-maria@linutronix.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] sched/cputime: cleanup account_process_tick/account_idle_ticks
Date: Thu,  2 Jan 2020 18:07:54 +0800	[thread overview]
Message-ID: <1577959674-255537-3-git-send-email-alex.shi@linux.alibaba.com> (raw)
In-Reply-To: <1577959674-255537-1-git-send-email-alex.shi@linux.alibaba.com>

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


  parent reply	other threads:[~2020-01-02 10:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Alex Shi [this message]
2020-01-06 14:55 ` [PATCH 1/3] sched/cputime: move rq parameter " Peter Zijlstra
2020-01-17 10:08 ` [tip: sched/core] " tip-bot2 for Alex Shi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1577959674-255537-3-git-send-email-alex.shi@linux.alibaba.com \
    --to=alex.shi@linux.alibaba.com \
    --cc=anna-maria@linutronix.de \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=wanpeng.li@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).