From: Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
To: Adrian Hunter <adrian.hunter-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
ajh mls <ajhmls-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Richard Cochran
<richardcochran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Steven Rostedt <rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org>,
Ingo Molnar <mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Paul Mackerras <paulus-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>,
Arnaldo Carvalho de Melo
<acme-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
John Stultz <john.stultz-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Masami Hiramatsu
<masami.hiramatsu.pt-FCd8Q96Dh0JBDgjK7y7TUQ@public.gmane.org>,
Christopher Covington
<cov-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
Namhyung Kim <namhyung-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
David Ahern <dsahern-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
Tomeu Vizoso <tomeu-XCtybt49RKsYaV1qd6yewg@public.gmane.org>,
"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH v5] perf: Use monotonic clock as a source for timestamps
Date: Thu, 12 Feb 2015 16:38:08 +0100 [thread overview]
Message-ID: <20150212153808.GR24151@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20150212102814.GK2896-IIpfhp3q70z/8w/KjCw3T+5/BudmfyzbbVWyRVo5IupeoWH0uzbU5w@public.gmane.org>
On Thu, Feb 12, 2015 at 11:28:14AM +0100, Peter Zijlstra wrote:
> > and you would have to check the clocksource is TSC.
>
> It implicitly does that; it has that sched_clock_stable() thing, but
> yeah I suppose someone could change the clocksource even though the tsc
> is stable.
>
> Not using TSC when its available is quite crazy though.. but sure.
Something like this on top then.. it might have a few header issues, the
whole asm/tsc.h vs clocksource.h thing looks like pain.
I haven't tried to compile it, maybe we can move cycle_t into types and
fwd declare struct clocksource or whatnot.
Of course, all this is quite horrible on the timekeeping side; it might
be tglx and/or jstutlz are having spasms just reading it :-)
---
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1967,17 +1967,19 @@ static void local_clock_user_time(struct
cyc2ns_read_end(data);
}
-extern void notrace __ktime_get_mono_fast(u64 *offset, u32 *mult, u16 *shift);
+extern bool notrace __ktime_get_mono_fast(cycle_t (*read)(struct clocksource *cs),
+ u64 *offset, u32 *mult, u16 *shift);
static void ktime_fast_mono_user_time(struct perf_event_mmap_page *userpg, u64 now)
{
+ if (!__ktime_get_mono_fast(read_tsc, &userpg->time_zero,
+ &userpg->time_mult,
+ &userpg->time_shift))
+ return;
+
userpg->cap_user_time = 1;
userpg->cap_user_time_zero = 1;
- __ktime_get_mono_fast(&userpg->time_zero,
- &userpg->time_mult,
- &userpg->time_shift);
-
userpg->offset = userpg->time_zero - now;
}
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -334,7 +334,8 @@ u64 notrace ktime_get_mono_fast_ns(void)
}
EXPORT_SYMBOL_GPL(ktime_get_mono_fast_ns);
-void notrace __ktime_get_mono_fast(u64 *offset, u32 *mult, u16 *shift)
+bool notrace __ktime_get_mono_fast(cycle_t (*read)(struct clocksource *),
+ u64 *offset, u32 *mult, u16 *shift)
{
struct tk_read_base *tkr;
unsigned int seq;
@@ -345,6 +346,9 @@ void notrace __ktime_get_mono_fast(u64 *
seq = raw_read_seqcount(&tk_fast_mono.seq);
tkr = tk_fast_mono.base + (seq & 0x01);
+ if (tkr->read != read)
+ return false;
+
cycle_now = tkr->read(tkr->clock);
delta = clocksource_delta(cycle_now, tkr->cycle_last, tkr->mask);
@@ -362,6 +366,8 @@ void notrace __ktime_get_mono_fast(u64 *
*offset = now - nsec;
} while (read_seqcount_retry(&tk_fast_mono.seq, seq));
+
+ return true;
}
#ifdef CONFIG_GENERIC_TIME_VSYSCALL_OLD
diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h
index 94605c0e9cee..68e4039a58ea 100644
--- a/arch/x86/include/asm/tsc.h
+++ b/arch/x86/include/asm/tsc.h
@@ -32,6 +32,8 @@ static inline cycles_t get_cycles(void)
return ret;
}
+extern void cycle_t read_tsc(struct clocksource *);
+
static __always_inline cycles_t vget_cycles(void)
{
/*
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 505449700e0c..c580998f0160 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -965,7 +965,7 @@ static struct clocksource clocksource_tsc;
* checking the result of read_tsc() - cycle_last for being negative.
* That works because CLOCKSOURCE_MASK(64) does not mask out any bit.
*/
-static cycle_t read_tsc(struct clocksource *cs)
+cycle_t read_tsc(struct clocksource *cs)
{
return (cycle_t)get_cycles();
}
WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: Adrian Hunter <adrian.hunter@intel.com>
Cc: Pawel Moll <pawel.moll@arm.com>, ajh mls <ajhmls@gmail.com>,
Richard Cochran <richardcochran@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>, Paul Mackerras <paulus@samba.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
John Stultz <john.stultz@linaro.org>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Christopher Covington <cov@codeaurora.org>,
Namhyung Kim <namhyung@kernel.org>,
David Ahern <dsahern@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Tomeu Vizoso <tomeu@tomeuvizoso.net>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>
Subject: Re: [PATCH v5] perf: Use monotonic clock as a source for timestamps
Date: Thu, 12 Feb 2015 16:38:08 +0100 [thread overview]
Message-ID: <20150212153808.GR24151@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20150212102814.GK2896@worktop.programming.kicks-ass.net>
On Thu, Feb 12, 2015 at 11:28:14AM +0100, Peter Zijlstra wrote:
> > and you would have to check the clocksource is TSC.
>
> It implicitly does that; it has that sched_clock_stable() thing, but
> yeah I suppose someone could change the clocksource even though the tsc
> is stable.
>
> Not using TSC when its available is quite crazy though.. but sure.
Something like this on top then.. it might have a few header issues, the
whole asm/tsc.h vs clocksource.h thing looks like pain.
I haven't tried to compile it, maybe we can move cycle_t into types and
fwd declare struct clocksource or whatnot.
Of course, all this is quite horrible on the timekeeping side; it might
be tglx and/or jstutlz are having spasms just reading it :-)
---
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1967,17 +1967,19 @@ static void local_clock_user_time(struct
cyc2ns_read_end(data);
}
-extern void notrace __ktime_get_mono_fast(u64 *offset, u32 *mult, u16 *shift);
+extern bool notrace __ktime_get_mono_fast(cycle_t (*read)(struct clocksource *cs),
+ u64 *offset, u32 *mult, u16 *shift);
static void ktime_fast_mono_user_time(struct perf_event_mmap_page *userpg, u64 now)
{
+ if (!__ktime_get_mono_fast(read_tsc, &userpg->time_zero,
+ &userpg->time_mult,
+ &userpg->time_shift))
+ return;
+
userpg->cap_user_time = 1;
userpg->cap_user_time_zero = 1;
- __ktime_get_mono_fast(&userpg->time_zero,
- &userpg->time_mult,
- &userpg->time_shift);
-
userpg->offset = userpg->time_zero - now;
}
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -334,7 +334,8 @@ u64 notrace ktime_get_mono_fast_ns(void)
}
EXPORT_SYMBOL_GPL(ktime_get_mono_fast_ns);
-void notrace __ktime_get_mono_fast(u64 *offset, u32 *mult, u16 *shift)
+bool notrace __ktime_get_mono_fast(cycle_t (*read)(struct clocksource *),
+ u64 *offset, u32 *mult, u16 *shift)
{
struct tk_read_base *tkr;
unsigned int seq;
@@ -345,6 +346,9 @@ void notrace __ktime_get_mono_fast(u64 *
seq = raw_read_seqcount(&tk_fast_mono.seq);
tkr = tk_fast_mono.base + (seq & 0x01);
+ if (tkr->read != read)
+ return false;
+
cycle_now = tkr->read(tkr->clock);
delta = clocksource_delta(cycle_now, tkr->cycle_last, tkr->mask);
@@ -362,6 +366,8 @@ void notrace __ktime_get_mono_fast(u64 *
*offset = now - nsec;
} while (read_seqcount_retry(&tk_fast_mono.seq, seq));
+
+ return true;
}
#ifdef CONFIG_GENERIC_TIME_VSYSCALL_OLD
diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h
index 94605c0e9cee..68e4039a58ea 100644
--- a/arch/x86/include/asm/tsc.h
+++ b/arch/x86/include/asm/tsc.h
@@ -32,6 +32,8 @@ static inline cycles_t get_cycles(void)
return ret;
}
+extern void cycle_t read_tsc(struct clocksource *);
+
static __always_inline cycles_t vget_cycles(void)
{
/*
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 505449700e0c..c580998f0160 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -965,7 +965,7 @@ static struct clocksource clocksource_tsc;
* checking the result of read_tsc() - cycle_last for being negative.
* That works because CLOCKSOURCE_MASK(64) does not mask out any bit.
*/
-static cycle_t read_tsc(struct clocksource *cs)
+cycle_t read_tsc(struct clocksource *cs)
{
return (cycle_t)get_cycles();
}
next prev parent reply other threads:[~2015-02-12 15:38 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-06 16:51 [PATCH v4 0/3] perf: User/kernel time correlation and event generation Pawel Moll
2014-11-06 16:51 ` [PATCH v4 1/3] perf: Use monotonic clock as a source for timestamps Pawel Moll
2015-01-05 13:00 ` Peter Zijlstra
[not found] ` <20150105130035.GP30905-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2015-01-21 15:52 ` Pawel Moll
2015-01-21 15:52 ` Pawel Moll
[not found] ` <1421855543.14076.68.camel-5wv7dgnIgG8@public.gmane.org>
2015-01-21 19:48 ` Pawel Moll
2015-01-21 19:48 ` Pawel Moll
[not found] ` <1421869684.14076.105.camel-5wv7dgnIgG8@public.gmane.org>
2015-01-21 20:07 ` Pawel Moll
2015-01-21 20:07 ` Pawel Moll
[not found] ` <1415292718-19785-2-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>
2014-11-27 15:05 ` Pawel Moll
2014-11-27 15:05 ` Pawel Moll
[not found] ` <1417100750.4371.1.camel-5wv7dgnIgG8@public.gmane.org>
2014-12-11 13:39 ` Pawel Moll
2014-12-11 13:39 ` Pawel Moll
[not found] ` <1418305153.4037.1.camel-5wv7dgnIgG8@public.gmane.org>
2015-01-05 13:01 ` Peter Zijlstra
2015-01-05 13:01 ` Peter Zijlstra
2015-01-21 15:47 ` Pawel Moll
2015-01-16 12:41 ` Adrian Hunter
2015-01-16 12:41 ` Adrian Hunter
2015-01-21 20:27 ` [PATCH v5] " Pawel Moll
2015-01-21 20:27 ` Pawel Moll
[not found] ` <1421872037-12559-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>
2015-02-02 16:52 ` Pawel Moll
2015-02-02 16:52 ` Pawel Moll
[not found] ` <CAN+dfcT_6zZZ4oeyngUE5N0Wtx2B9CvXsfU71m+cuyXpq2KBdw@mail.gmail.com>
[not found] ` <CAN+dfcT_6zZZ4oeyngUE5N0Wtx2B9CvXsfU71m+cuyXpq2KBdw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-03 9:20 ` Pawel Moll
2015-02-03 9:20 ` Pawel Moll
[not found] ` <1422955245.4944.26.camel-5wv7dgnIgG8@public.gmane.org>
2015-02-11 16:12 ` Peter Zijlstra
2015-02-11 16:12 ` Peter Zijlstra
[not found] ` <20150211161256.GH2896-IIpfhp3q70z/8w/KjCw3T+5/BudmfyzbbVWyRVo5IupeoWH0uzbU5w@public.gmane.org>
2015-02-12 10:04 ` Adrian Hunter
2015-02-12 10:04 ` Adrian Hunter
[not found] ` <54DC7AC6.5010605-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-02-12 10:28 ` Peter Zijlstra
2015-02-12 10:28 ` Peter Zijlstra
[not found] ` <20150212102814.GK2896-IIpfhp3q70z/8w/KjCw3T+5/BudmfyzbbVWyRVo5IupeoWH0uzbU5w@public.gmane.org>
2015-02-12 15:38 ` Peter Zijlstra [this message]
2015-02-12 15:38 ` Peter Zijlstra
[not found] ` <20150212153808.GR24151-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2015-02-13 0:25 ` John Stultz
2015-02-13 0:25 ` John Stultz
2015-02-13 7:07 ` Adrian Hunter
2015-02-13 7:07 ` Adrian Hunter
[not found] ` <1415292718-19785-1-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>
2014-11-06 16:51 ` [PATCH v4 2/3] perf: Userspace event Pawel Moll
2014-11-06 16:51 ` Pawel Moll
[not found] ` <1415292718-19785-3-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>
2015-01-05 13:12 ` Peter Zijlstra
2015-01-05 13:12 ` Peter Zijlstra
[not found] ` <20150105131237.GR30905-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2015-01-21 16:01 ` Pawel Moll
2015-01-21 16:01 ` Pawel Moll
2014-11-06 16:51 ` [PATCH v4 3/3] perf: Sample additional clock value Pawel Moll
[not found] ` <1415292718-19785-4-git-send-email-pawel.moll-5wv7dgnIgG8@public.gmane.org>
2015-01-05 13:45 ` Peter Zijlstra
2015-01-05 13:45 ` Peter Zijlstra
2015-01-05 19:17 ` John Stultz
[not found] ` <20150105134514.GS30905-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2015-01-21 17:12 ` Pawel Moll
2015-01-21 17:12 ` Pawel Moll
[not found] ` <1421860365.14076.91.camel-5wv7dgnIgG8@public.gmane.org>
2015-01-21 17:44 ` John Stultz
2015-01-21 17:44 ` John Stultz
[not found] ` <CALAqxLV6ggCO81ntWuYuDjrqNeMePkZBpq92G9-iwMHm7ONuFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-21 17:54 ` Pawel Moll
2015-01-21 17:54 ` Pawel Moll
[not found] ` <1421862883.14076.99.camel-5wv7dgnIgG8@public.gmane.org>
2015-01-21 18:05 ` John Stultz
2015-01-21 18:05 ` John Stultz
2015-01-23 17:06 ` Pawel Moll
2015-01-23 17:06 ` Pawel Moll
[not found] ` <1422032767.14076.151.camel-5wv7dgnIgG8@public.gmane.org>
2015-01-23 18:05 ` David Ahern
2015-01-23 18:05 ` David Ahern
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=20150212153808.GR24151@twins.programming.kicks-ass.net \
--to=peterz-wegcikhe2lqwvfeawa7xhq@public.gmane.org \
--cc=acme-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=adrian.hunter-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=ajhmls-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=cov-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=dsahern-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=john.stultz-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=masami.hiramatsu.pt-FCd8Q96Dh0JBDgjK7y7TUQ@public.gmane.org \
--cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=namhyung-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=paulus-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org \
--cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
--cc=richardcochran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org \
--cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
--cc=tomeu-XCtybt49RKsYaV1qd6yewg@public.gmane.org \
/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.