mirror of https://lore.kernel.org/lkml/
 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>,
	Peter Zijlstra <peterz@infradead.org>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Oleg Nesterov <oleg@redhat.com>,
	Paul Mackerras <paulus@samba.org>,
	Wu Fengguang <fengguang.wu@intel.com>,
	Ingo Molnar <mingo@kernel.org>, Rik van Riel <riel@redhat.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>
Subject: [RFC PATCH 25/30] cputime: Remove temporary irqtime states
Date: Fri, 28 Nov 2014 19:23:55 +0100	[thread overview]
Message-ID: <1417199040-21044-26-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1417199040-21044-1-git-send-email-fweisbec@gmail.com>

Now that the temporary irqtime storage has become unnecessary, lets
remove it.

This involves to move the u64_stat_sync seqlock to the kcpustat directly
in order to keep coherent irqtime reads from the scheduler.

This seqlock can be used as well for other kcpustat. The need hasn't
yet arised as nobody seem to complain about possible erroneous
/proc/cpustat values due to 64 bits values read in two passes in 32 bits
CPUs. But at least we are prepared for that.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 include/linux/kernel_stat.h |  2 ++
 kernel/sched/cputime.c      | 40 ++++++++++++++++++++++------------------
 kernel/sched/sched.h        | 22 ++++++----------------
 3 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 8422b4e..585ced4 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -10,6 +10,7 @@
 #include <linux/vtime.h>
 #include <asm/irq.h>
 #include <linux/cputime.h>
+#include <linux/u64_stats_sync.h>
 
 /*
  * 'kernel_stat.h' contains the definitions needed for doing
@@ -33,6 +34,7 @@ enum cpu_usage_stat {
 
 struct kernel_cpustat {
 	u64 cpustat[NR_STATS];
+	struct u64_stats_sync stats_sync;
 };
 
 struct kernel_stat {
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 6e3beba..f675008 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -8,6 +8,23 @@
 
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
+struct cpu_irqtime {
+	u64			irq_start_time;
+	u64			tick_skip;
+};
+static DEFINE_PER_CPU(struct cpu_irqtime, cpu_irqtime);
+
+static int sched_clock_irqtime;
+
+void enable_sched_clock_irqtime(void)
+{
+	sched_clock_irqtime = 1;
+}
+
+void disable_sched_clock_irqtime(void)
+{
+	sched_clock_irqtime = 0;
+}
 
 /*
  * There are no locks covering percpu hardirq/softirq time.
@@ -20,19 +37,6 @@
  * task when irq is in progress while we read rq->clock. That is a worthy
  * compromise in place of having locks on each irq in account_system_time.
  */
-DEFINE_PER_CPU(struct cpu_irqtime, cpu_irqtime);
-
-static int sched_clock_irqtime;
-
-void enable_sched_clock_irqtime(void)
-{
-	sched_clock_irqtime = 1;
-}
-
-void disable_sched_clock_irqtime(void)
-{
-	sched_clock_irqtime = 0;
-}
 
 /*
  * Called before incrementing preempt_count on {soft,}irq_enter
@@ -40,6 +44,7 @@ void disable_sched_clock_irqtime(void)
  */
 void irqtime_account_irq(struct task_struct *curr)
 {
+	struct kernel_cpustat *kcpustat;
 	u64 *cpustat;
 	unsigned long flags;
 	s64 delta;
@@ -48,7 +53,8 @@ void irqtime_account_irq(struct task_struct *curr)
 	if (!sched_clock_irqtime)
 		return;
 
-	cpustat = kcpustat_this_cpu->cpustat;
+	kcpustat = kcpustat_this_cpu;
+	cpustat = kcpustat->cpustat;
 
 	local_irq_save(flags);
 
@@ -56,7 +62,7 @@ void irqtime_account_irq(struct task_struct *curr)
 	delta = sched_clock_cpu(cpu) - __this_cpu_read(cpu_irqtime.irq_start_time);
 	__this_cpu_add(cpu_irqtime.irq_start_time, delta);
 
-	u64_stats_update_begin(this_cpu_ptr(&cpu_irqtime.stats_sync));
+	u64_stats_update_begin(&kcpustat->stats_sync);
 	/*
 	 * We do not account for softirq time from ksoftirqd here.
 	 * We want to continue accounting softirq time to ksoftirqd thread
@@ -64,16 +70,14 @@ void irqtime_account_irq(struct task_struct *curr)
 	 * that do not consume any time, but still wants to run.
 	 */
 	if (hardirq_count()) {
-		__this_cpu_add(cpu_irqtime.hardirq_time, delta);
 		cpustat[CPUTIME_IRQ] += delta;
 		__this_cpu_add(cpu_irqtime.tick_skip, delta);
 	} else if (in_serving_softirq() && curr != this_cpu_ksoftirqd()) {
-		__this_cpu_add(cpu_irqtime.softirq_time, delta);
 		cpustat[CPUTIME_SOFTIRQ] += delta;
 		__this_cpu_add(cpu_irqtime.tick_skip, delta);
 	}
 
-	u64_stats_update_end(this_cpu_ptr(&cpu_irqtime.stats_sync));
+	u64_stats_update_end(&kcpustat->stats_sync);
 	local_irq_restore(flags);
 }
 EXPORT_SYMBOL_GPL(irqtime_account_irq);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index f613053..1ca6c82 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -8,7 +8,7 @@
 #include <linux/stop_machine.h>
 #include <linux/tick.h>
 #include <linux/slab.h>
-#include <linux/u64_stats_sync.h>
+#include <linux/kernel_stat.h>
 
 #include "cpupri.h"
 #include "cpudeadline.h"
@@ -1521,28 +1521,18 @@ enum rq_nohz_flag_bits {
 #endif
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
-
-struct cpu_irqtime {
-	u64			hardirq_time;
-	u64			softirq_time;
-	u64			irq_start_time;
-	u64			tick_skip;
-	struct u64_stats_sync	stats_sync;
-};
-
-DECLARE_PER_CPU(struct cpu_irqtime, cpu_irqtime);
-
 /* Must be called with preemption disabled */
 static inline u64 irq_time_read(int cpu)
 {
+	struct kernel_cpustat *kcpustat = &kcpustat_cpu(cpu);
 	u64 irq_time;
 	unsigned seq;
 
 	do {
-		seq = __u64_stats_fetch_begin(&per_cpu(cpu_irqtime, cpu).stats_sync);
-		irq_time = per_cpu(cpu_irqtime.softirq_time, cpu) +
-			   per_cpu(cpu_irqtime.hardirq_time, cpu);
-	} while (__u64_stats_fetch_retry(&per_cpu(cpu_irqtime, cpu).stats_sync, seq));
+		seq = __u64_stats_fetch_begin(&kcpustat->stats_sync);
+		irq_time = kcpustat->cpustat[CPUTIME_SOFTIRQ] +
+			   kcpustat->cpustat[CPUTIME_IRQ];
+	} while (__u64_stats_fetch_retry(&kcpustat->stats_sync, seq));
 
 	return irq_time;
 }
-- 
2.1.3


  parent reply	other threads:[~2014-11-28 18:26 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-28 18:23 [RFC PATCH 00/30] cputime: Convert task/cpu cputime accounting to nsecs Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 01/30] jiffies: Remove HZ > USEC_PER_SEC special case Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 02/30] time: Introduce jiffies64_to_nsecs() Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 03/30] cputime: Introduce nsecs_to_cputime64() Frederic Weisbecker
2014-12-01 14:05   ` Martin Schwidefsky
2014-11-28 18:23 ` [RFC PATCH 04/30] s390: Convert open coded idle time seqcount Frederic Weisbecker
2014-12-01 13:46   ` Heiko Carstens
2014-11-28 18:23 ` [RFC PATCH 05/30] s390: Translate cputime magic constants to macros Frederic Weisbecker
2014-12-01 13:47   ` Heiko Carstens
2014-12-01 16:23     ` Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 06/30] s390: Introduce cputime64_to_nsecs() Frederic Weisbecker
2014-12-01 12:24   ` Heiko Carstens
2014-12-01 13:58     ` Martin Schwidefsky
2014-12-01 16:23     ` Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 07/30] cputime: Convert kcpustat to nsecs Frederic Weisbecker
2014-12-01 14:14   ` Martin Schwidefsky
2014-12-01 16:10     ` Frederic Weisbecker
2014-12-01 16:48       ` Martin Schwidefsky
2014-12-01 17:15         ` Thomas Gleixner
2014-12-01 17:27           ` Martin Schwidefsky
2014-12-01 19:59             ` Frederic Weisbecker
2014-12-01 20:14           ` Christian Borntraeger
2014-12-01 20:21             ` Thomas Gleixner
2014-11-28 18:23 ` [RFC PATCH 08/30] apm32: Fix cputime == jiffies assumption Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 09/30] alpha: Fix jiffies based cputime assumption Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 10/30] cputime: Convert guest time accounting to nsecs Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 11/30] cputime: Special API to return old-typed cputime Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 12/30] cputime: Convert task/group cputime to nsecs Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 13/30] alpha: Convert obsolete cputime_t " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 14/30] x86: Convert obsolete cputime type " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 15/30] isdn: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 16/30] binfmt: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 17/30] acct: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 18/30] delaycct: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 19/30] tsacct: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 20/30] signal: " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 21/30] cputime: Remove task_cputime_t_scaled Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 22/30] u64_stats_sync: Introduce preempt-unsafe readers Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 23/30] cputime: Convert irq_time_accounting to use u64_stats_sync Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 24/30] cputime: Increment kcpustat directly on irqtime account Frederic Weisbecker
2014-12-01 14:41   ` Martin Schwidefsky
2014-12-01 16:15     ` Frederic Weisbecker
2014-12-01 16:50       ` Martin Schwidefsky
2014-11-28 18:23 ` Frederic Weisbecker [this message]
2014-11-28 18:23 ` [RFC PATCH 26/30] cputime: Push time to account_user_time() in nanosecs Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 27/30] cputime: Push time to account_steal_time() " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 28/30] cputime: Push time to account_idle_time() " Frederic Weisbecker
2014-11-28 18:23 ` [RFC PATCH 29/30] cputime: Push time to account_guest_time() " Frederic Weisbecker
2014-11-28 18:24 ` [RFC PATCH 30/30] cputime: Push time to account_system_time() " Frederic Weisbecker

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=1417199040-21044-26-git-send-email-fweisbec@gmail.com \
    --to=fweisbec@gmail.com \
    --cc=benh@kernel.crashing.org \
    --cc=fengguang.wu@intel.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.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

all inboxes | Powered by JetHome®