All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Tony Luck <tony.luck@intel.com>,
	Wanpeng Li <wanpeng.li@hotmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
	Fenghua Yu <fenghua.yu@intel.com>, Rik van Riel <riel@redhat.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Stanislaw Gruszka <sgruszka@redhat.com>
Subject: [PATCH 17/37] cputime: Increment kcpustat directly on irqtime account
Date: Sun, 22 Jan 2017 19:19:53 +0100	[thread overview]
Message-ID: <1485109213-8561-18-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1485109213-8561-1-git-send-email-fweisbec@gmail.com>

The irqtime is accounted is nsecs and stored in
cpu_irq_time.hardirq_time and cpu_irq_time.softirq_time. Once the
accumulated amount reaches a new jiffy, this one gets accounted to the
kcpustat.

This was necessary when kcpustat was stored in cputime_t, which could at
worst have a jiffies granularity. But now kcpustat is stored in nsecs
so this whole discretization game with temporary irqtime storage has
become unnecessary.

We can now directly account the irqtime to the kcpustat.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/sched/cputime.c | 50 +++++++++++++++++---------------------------------
 kernel/sched/sched.h   |  7 ++++---
 2 files changed, 21 insertions(+), 36 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 0bdef50..bee6c97 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -44,6 +44,7 @@ void disable_sched_clock_irqtime(void)
 void irqtime_account_irq(struct task_struct *curr)
 {
 	struct irqtime *irqtime = this_cpu_ptr(&cpu_irqtime);
+	u64 *cpustat = kcpustat_this_cpu->cpustat;
 	s64 delta;
 	int cpu;
 
@@ -61,49 +62,35 @@ void irqtime_account_irq(struct task_struct *curr)
 	 * in that case, so as not to confuse scheduler with a special task
 	 * that do not consume any time, but still wants to run.
 	 */
-	if (hardirq_count())
-		irqtime->hardirq_time += delta;
-	else if (in_serving_softirq() && curr != this_cpu_ksoftirqd())
-		irqtime->softirq_time += delta;
+	if (hardirq_count()) {
+		cpustat[CPUTIME_IRQ] += delta;
+		irqtime->tick_delta += delta;
+	} else if (in_serving_softirq() && curr != this_cpu_ksoftirqd()) {
+		cpustat[CPUTIME_SOFTIRQ] += delta;
+		irqtime->tick_delta += delta;
+	}
 
 	u64_stats_update_end(&irqtime->sync);
 }
 EXPORT_SYMBOL_GPL(irqtime_account_irq);
 
-static cputime_t irqtime_account_update(u64 irqtime, int idx, cputime_t maxtime)
+static cputime_t irqtime_tick_accounted(cputime_t maxtime)
 {
-	u64 *cpustat = kcpustat_this_cpu->cpustat;
-	cputime_t irq_cputime;
+	struct irqtime *irqtime = this_cpu_ptr(&cpu_irqtime);
+	cputime_t delta;
 
-	irq_cputime = nsecs_to_cputime64(irqtime - cpustat[idx]);
-	irq_cputime = min(irq_cputime, maxtime);
-	cpustat[idx] += cputime_to_nsecs(irq_cputime);
+	delta = nsecs_to_cputime(irqtime->tick_delta);
+	delta = min(delta, maxtime);
+	irqtime->tick_delta -= cputime_to_nsecs(delta);
 
-	return irq_cputime;
-}
-
-static cputime_t irqtime_account_hi_update(cputime_t maxtime)
-{
-	return irqtime_account_update(__this_cpu_read(cpu_irqtime.hardirq_time),
-				      CPUTIME_IRQ, maxtime);
-}
-
-static cputime_t irqtime_account_si_update(cputime_t maxtime)
-{
-	return irqtime_account_update(__this_cpu_read(cpu_irqtime.softirq_time),
-				      CPUTIME_SOFTIRQ, maxtime);
+	return delta;
 }
 
 #else /* CONFIG_IRQ_TIME_ACCOUNTING */
 
 #define sched_clock_irqtime	(0)
 
-static cputime_t irqtime_account_hi_update(cputime_t dummy)
-{
-	return 0;
-}
-
-static cputime_t irqtime_account_si_update(cputime_t dummy)
+static cputime_t irqtime_tick_accounted(cputime_t dummy)
 {
 	return 0;
 }
@@ -280,10 +267,7 @@ static inline cputime_t account_other_time(cputime_t max)
 	accounted = steal_account_process_time(max);
 
 	if (accounted < max)
-		accounted += irqtime_account_hi_update(max - accounted);
-
-	if (accounted < max)
-		accounted += irqtime_account_si_update(max - accounted);
+		accounted += irqtime_tick_accounted(max - accounted);
 
 	return accounted;
 }
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 6eeae7e..8ff5cc5 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -4,6 +4,7 @@
 #include <linux/sched/rt.h>
 #include <linux/u64_stats_sync.h>
 #include <linux/sched/deadline.h>
+#include <linux/kernel_stat.h>
 #include <linux/binfmts.h>
 #include <linux/mutex.h>
 #include <linux/spinlock.h>
@@ -1827,8 +1828,7 @@ static inline void nohz_balance_exit_idle(unsigned int cpu) { }
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
 struct irqtime {
-	u64			hardirq_time;
-	u64			softirq_time;
+	u64			tick_delta;
 	u64			irq_start_time;
 	struct u64_stats_sync	sync;
 };
@@ -1838,12 +1838,13 @@ DECLARE_PER_CPU(struct irqtime, cpu_irqtime);
 static inline u64 irq_time_read(int cpu)
 {
 	struct irqtime *irqtime = &per_cpu(cpu_irqtime, cpu);
+	u64 *cpustat = kcpustat_cpu(cpu).cpustat;
 	unsigned int seq;
 	u64 total;
 
 	do {
 		seq = __u64_stats_fetch_begin(&irqtime->sync);
-		total = irqtime->softirq_time + irqtime->hardirq_time;
+		total = cpustat[CPUTIME_SOFTIRQ] + cpustat[CPUTIME_IRQ];
 	} while (__u64_stats_fetch_retry(&irqtime->sync, seq));
 
 	return total;
-- 
2.7.4

  parent reply	other threads:[~2017-01-22 18:28 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-22 18:19 [PATCH 00/37] cputime: Convert core use of cputime_t to nsecs v3 Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 01/37] jiffies: Reuse TICK_NSEC instead of NSEC_PER_JIFFY Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 02/37] time: Introduce jiffies64_to_nsecs() Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 03/37] sched: Remove unused INIT_CPUTIME macro Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 04/37] cputime: Convert kcpustat to nsecs Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 05/37] macintosh/rack-meter: Remove cputime_t internal use Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 06/37] cputime: Convert guest time accounting to nsecs Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 07/37] cputime: Special API to return old-typed cputime Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 08/37] cputime: Convert task/group cputime to nsecs Frederic Weisbecker
2017-01-28 11:57   ` Stanislaw Gruszka
2017-01-28 15:28     ` Frederic Weisbecker
2017-01-30 13:54       ` Stanislaw Gruszka
2017-01-30 15:38         ` Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 09/37] alpha: Convert obsolete cputime_t " Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 10/37] x86: Convert obsolete cputime type " Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 11/37] isdn: " Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 12/37] binfmt: " Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 13/37] acct: " Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 14/37] delaycct: " Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 15/37] tsacct: " Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 16/37] signal: " Frederic Weisbecker
2017-01-22 18:19 ` Frederic Weisbecker [this message]
2017-01-22 18:19 ` [PATCH 18/37] posix-timers: Use TICK_NSEC instead of a dynamically ad-hoc calculated version Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 19/37] posix-timers: Convert internals to use nsecs Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 20/37] itimer: Convert internal cputime_t units to nsec Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 21/37] sched: Remove temporary cputime_t accessors Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 22/37] cputime: Push time to account_user_time() in nsecs Frederic Weisbecker
2017-01-22 18:19 ` [PATCH 23/37] cputime: Push time to account_steal_time() " Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 24/37] cputime: Push time to account_idle_time() " Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 25/37] cputime: Push time to account_system_time() " Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 26/37] cputime: Complete nsec conversion of tick based accounting Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 27/37] vtime: Return nsecs instead of cputime_t to account Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 28/37] cputime: Remove jiffies based cputime Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 29/37] ia64: Move nsecs based cputime headers to the last arch using it Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 30/37] ia64: Convert vtime to use nsec units directly Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 31/37] ia64: Remove unused cputime definitions Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 32/37] s390: Make arch_cpu_idle_time() to return nsecs Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 33/37] powerpc: Remove unused cputime definitions Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 34/37] s390: " Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 35/37] cputime: Remove unused nsec_to_cputime Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 36/37] cputime: Remove asm generic headers Frederic Weisbecker
2017-01-22 18:20 ` [PATCH 37/37] s390: Prevent from cputime leaks Frederic Weisbecker
2017-01-23  9:44   ` Martin Schwidefsky
2017-01-25 15:25     ` Frederic Weisbecker
2017-01-25 15:40       ` Martin Schwidefsky

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=1485109213-8561-18-git-send-email-fweisbec@gmail.com \
    --to=fweisbec@gmail.com \
    --cc=benh@kernel.crashing.org \
    --cc=fenghua.yu@intel.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=sgruszka@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --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 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.