From: Daniel Thompson <daniel.thompson@linaro.org>
To: Thomas Gleixner <tglx@linutronix.de>,
John Stultz <john.stultz@linaro.org>
Cc: Daniel Thompson <daniel.thompson@linaro.org>,
linux-kernel@vger.kernel.org, patches@linaro.org,
linaro-kernel@lists.linaro.org,
Sumit Semwal <sumit.semwal@linaro.org>,
Stephen Boyd <sboyd@codeaurora.org>,
Steven Rostedt <rostedt@goodmis.org>,
Russell King <linux@arm.linux.org.uk>,
Will Deacon <will.deacon@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>
Subject: [PATCH v5 3/5] sched_clock: Remove suspend from clock_read_data
Date: Mon, 2 Mar 2015 15:56:42 +0000 [thread overview]
Message-ID: <1425311804-3392-4-git-send-email-daniel.thompson@linaro.org> (raw)
In-Reply-To: <1425311804-3392-1-git-send-email-daniel.thompson@linaro.org>
Currently cd.read_data.suspended is read by the hotpath function
sched_clock(). This variable need not be accessed on the hotpath. In
fact, once it is removed, we can remove the conditional branches from
sched_clock() and install a dummy read_sched_clock function to suspend
the clock.
The new master copy of the function pointer (actual_read_sched_clock) is
introduced and is used for all reads of the clock hardware except those
within sched_clock itself.
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
---
kernel/time/sched_clock.c | 40 +++++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 15 deletions(-)
diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
index 695b2ac2e8b4..5d6407951fb8 100644
--- a/kernel/time/sched_clock.c
+++ b/kernel/time/sched_clock.c
@@ -28,10 +28,9 @@
* @read_sched_clock: Current clock source (or dummy source when suspended)
* @mult: Multipler for scaled math conversion
* @shift: Shift value for scaled math conversion
- * @suspended: Flag to indicate if the clock is suspended (stopped)
*
* Care must be taken when updating this structure; it is read by
- * some very hot code paths. It occupies <=48 bytes and, when combined
+ * some very hot code paths. It occupies <=40 bytes and, when combined
* with the seqcount used to synchronize access, comfortably fits into
* a 64 byte cache line.
*/
@@ -42,7 +41,6 @@ struct clock_read_data {
u64 (*read_sched_clock)(void);
u32 mult;
u32 shift;
- bool suspended;
};
/**
@@ -64,6 +62,7 @@ struct clock_data {
struct clock_read_data read_data;
ktime_t wrap_kt;
unsigned long rate;
+ u64 (*actual_read_sched_clock)(void);
};
static struct hrtimer sched_clock_timer;
@@ -83,6 +82,8 @@ static u64 notrace jiffy_sched_clock_read(void)
static struct clock_data cd ____cacheline_aligned = {
.read_data = { .mult = NSEC_PER_SEC / HZ,
.read_sched_clock = jiffy_sched_clock_read, },
+ .actual_read_sched_clock = jiffy_sched_clock_read,
+
};
static inline u64 notrace cyc_to_ns(u64 cyc, u32 mult, u32 shift)
@@ -99,12 +100,9 @@ unsigned long long notrace sched_clock(void)
do {
seq = raw_read_seqcount_begin(&cd.seq);
- res = rd->epoch_ns;
- if (!rd->suspended) {
- cyc = rd->read_sched_clock();
- cyc = (cyc - rd->epoch_cyc) & rd->sched_clock_mask;
- res += cyc_to_ns(cyc, rd->mult, rd->shift);
- }
+ cyc = (rd->read_sched_clock() - rd->epoch_cyc) &
+ rd->sched_clock_mask;
+ res = rd->epoch_ns + cyc_to_ns(cyc, rd->mult, rd->shift);
} while (read_seqcount_retry(&cd.seq, seq));
return res;
@@ -120,7 +118,7 @@ static void notrace update_sched_clock(void)
u64 ns;
struct clock_read_data *rd = &cd.read_data;
- cyc = rd->read_sched_clock();
+ cyc = cd.actual_read_sched_clock();
ns = rd->epoch_ns +
cyc_to_ns((cyc - rd->epoch_cyc) & rd->sched_clock_mask,
rd->mult, rd->shift);
@@ -166,10 +164,11 @@ void __init sched_clock_register(u64 (*read)(void), int bits,
/* update epoch for new counter and update epoch_ns from old counter*/
new_epoch = read();
- cyc = rd->read_sched_clock();
+ cyc = cd.actual_read_sched_clock();
ns = rd->epoch_ns +
cyc_to_ns((cyc - rd->epoch_cyc) & rd->sched_clock_mask,
rd->mult, rd->shift);
+ cd.actual_read_sched_clock = read;
raw_write_seqcount_begin(&cd.seq);
rd->read_sched_clock = read;
@@ -209,7 +208,7 @@ void __init sched_clock_postinit(void)
* If no sched_clock function has been provided at that point,
* make it the final one one.
*/
- if (cd.read_data.read_sched_clock == jiffy_sched_clock_read)
+ if (cd.actual_read_sched_clock == jiffy_sched_clock_read)
sched_clock_register(jiffy_sched_clock_read, BITS_PER_LONG, HZ);
update_sched_clock();
@@ -223,13 +222,24 @@ void __init sched_clock_postinit(void)
hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL);
}
+/*
+ * Clock read function for use when the clock is suspended.
+ *
+ * This function makes it appear to sched_clock() as if the clock
+ * stopped counting at its last update.
+ */
+static u64 notrace suspended_sched_clock_read(void)
+{
+ return cd.read_data.epoch_cyc;
+}
+
static int sched_clock_suspend(void)
{
struct clock_read_data *rd = &cd.read_data;
update_sched_clock();
hrtimer_cancel(&sched_clock_timer);
- rd->suspended = true;
+ rd->read_sched_clock = suspended_sched_clock_read;
return 0;
}
@@ -237,9 +247,9 @@ static void sched_clock_resume(void)
{
struct clock_read_data *rd = &cd.read_data;
- rd->epoch_cyc = rd->read_sched_clock();
+ rd->epoch_cyc = cd.actual_read_sched_clock();
hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL);
- rd->suspended = false;
+ rd->read_sched_clock = cd.actual_read_sched_clock;
}
static struct syscore_ops sched_clock_ops = {
--
2.1.0
next prev parent reply other threads:[~2015-03-02 15:57 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-21 16:53 [RFC PATCH] sched_clock: Avoid tearing during read from NMI Daniel Thompson
2015-01-21 17:29 ` John Stultz
2015-01-21 20:20 ` Daniel Thompson
2015-01-21 20:58 ` Stephen Boyd
2015-01-22 13:06 ` [PATCH v2] sched_clock: Avoid deadlock " Daniel Thompson
2015-01-30 19:03 ` [PATCH v3 0/4] sched_clock: Optimize and avoid " Daniel Thompson
2015-01-30 19:03 ` [PATCH v3 1/4] sched_clock: Match scope of read and write seqcounts Daniel Thompson
2015-01-30 19:03 ` [PATCH v3 2/4] sched_clock: Optimize cache line usage Daniel Thompson
2015-02-05 1:14 ` Stephen Boyd
2015-02-05 10:21 ` Daniel Thompson
2015-01-30 19:03 ` [PATCH v3 3/4] sched_clock: Remove suspend from clock_read_data Daniel Thompson
2015-01-30 19:03 ` [PATCH v3 4/4] sched_clock: Avoid deadlock during read from NMI Daniel Thompson
2015-02-05 1:23 ` Stephen Boyd
2015-02-05 1:48 ` Steven Rostedt
2015-02-05 6:23 ` Stephen Boyd
2015-02-05 0:50 ` [PATCH v3 0/4] sched_clock: Optimize and avoid " Stephen Boyd
2015-02-05 9:05 ` Daniel Thompson
2015-02-08 12:09 ` Daniel Thompson
2015-02-09 22:08 ` Stephen Boyd
2015-02-08 12:02 ` [PATCH v4 0/5] " Daniel Thompson
2015-02-08 12:02 ` [PATCH v4 1/5] sched_clock: Match scope of read and write seqcounts Daniel Thompson
2015-02-08 12:02 ` [PATCH v4 2/5] sched_clock: Optimize cache line usage Daniel Thompson
2015-02-09 1:28 ` Will Deacon
2015-02-09 9:47 ` Daniel Thompson
2015-02-10 2:37 ` Stephen Boyd
2015-02-08 12:02 ` [PATCH v4 3/5] sched_clock: Remove suspend from clock_read_data Daniel Thompson
2015-02-08 12:02 ` [PATCH v4 4/5] sched_clock: Remove redundant notrace from update function Daniel Thompson
2015-02-08 12:02 ` [PATCH v4 5/5] sched_clock: Avoid deadlock during read from NMI Daniel Thompson
2015-02-13 3:49 ` [PATCH v4 0/5] sched_clock: Optimize and avoid " Stephen Boyd
2015-03-02 15:56 ` [PATCH v5 " Daniel Thompson
2015-03-02 15:56 ` [PATCH v5 1/5] sched_clock: Match scope of read and write seqcounts Daniel Thompson
2015-03-02 15:56 ` [PATCH v5 2/5] sched_clock: Optimize cache line usage Daniel Thompson
2015-03-02 15:56 ` Daniel Thompson [this message]
2015-03-02 15:56 ` [PATCH v5 4/5] sched_clock: Remove redundant notrace from update function Daniel Thompson
2015-03-02 15:56 ` [PATCH v5 5/5] sched_clock: Avoid deadlock during read from NMI Daniel Thompson
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=1425311804-3392-4-git-send-email-daniel.thompson@linaro.org \
--to=daniel.thompson@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=john.stultz@linaro.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=patches@linaro.org \
--cc=rostedt@goodmis.org \
--cc=sboyd@codeaurora.org \
--cc=sumit.semwal@linaro.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.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®