Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754725AbbBRTMu (ORCPT ); Wed, 18 Feb 2015 14:12:50 -0500 Received: from cpsmtpb-ews05.kpnxchange.com ([213.75.39.8]:55076 "EHLO cpsmtpb-ews05.kpnxchange.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753539AbbBRTMq (ORCPT ); Wed, 18 Feb 2015 14:12:46 -0500 Message-ID: <1424286764.29983.11.camel@x220> Subject: Re: [PATCH v2 4/4] clock: add perf_clock posix clock From: Paul Bolle To: Stephane Eranian Cc: linux-kernel@vger.kernel.org, acme@redhat.com, peterz@infradead.org, mingo@elte.hu, ak@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, cel@us.ibm.com, sukadev@linux.vnet.ibm.com, sonnyrao@chromium.org, johnmccutchan@google.com, dsahern@gmail.com, adrian.hunter@intel.com, pawel.moll@arm.com Date: Wed, 18 Feb 2015 20:12:44 +0100 In-Reply-To: <1424280109-9801-5-git-send-email-eranian@google.com> References: <1424280109-9801-1-git-send-email-eranian@google.com> <1424280109-9801-5-git-send-email-eranian@google.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4 (3.10.4-4.fc20) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 18 Feb 2015 19:12:44.0693 (UTC) FILETIME=[DFEC1C50:01D04BAE] X-RcptDomain: vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4265 Lines: 137 [s/pawell.moll/pawel.moll/] On Wed, 2015-02-18 at 18:21 +0100, Stephane Eranian wrote: > This patch is a re-packaging of David's Ahern > posix perf clock available here: > > https://github.com/dsahern/linux/blob/perf-full-monty/README.ahern > > The patch itself is based on Pawel Moll's original post: > > https://lkml.org/lkml/2013/3/14/523 > > The new clock is call PERF_CLOCK. To use it > > #include > #include > > struct timespec ts; > > clock_gettime(PERF_CLOCK, &ts); > > Signed-off-by: Stephane Eranian > --- > include/uapi/linux/time.h | 1 + > kernel/time/Kconfig | 6 +++++ > kernel/time/Makefile | 1 + > kernel/time/perf_posix_clock.c | 54 ++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 62 insertions(+) > create mode 100644 kernel/time/perf_posix_clock.c > > diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h > index e75e1b6..9066bf0 100644 > --- a/include/uapi/linux/time.h > +++ b/include/uapi/linux/time.h > @@ -56,6 +56,7 @@ struct itimerval { > #define CLOCK_BOOTTIME_ALARM 9 > #define CLOCK_SGI_CYCLE 10 /* Hardware specific */ > #define CLOCK_TAI 11 > +#define CLOCK_PERF 12 > > #define MAX_CLOCKS 16 > #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC) > diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig > index d626dc9..6e4b707 100644 > --- a/kernel/time/Kconfig > +++ b/kernel/time/Kconfig > @@ -201,5 +201,11 @@ config HIGH_RES_TIMERS > hardware is not capable then this option only increases > the size of the kernel image. > > +config PERF_CLOCK > + tristate "Perf_events posix clock timer source" > + help > + This option adds a new posix clock timer source which uses the same time > + source as the perf_events subsystem. It makes it possible to correlate > + user level samples with perf_events samples. > endmenu > endif > diff --git a/kernel/time/Makefile b/kernel/time/Makefile > index f622cf2..41cd183 100644 > --- a/kernel/time/Makefile > +++ b/kernel/time/Makefile > @@ -14,6 +14,7 @@ obj-$(CONFIG_TICK_ONESHOT) += tick-sched.o > obj-$(CONFIG_TIMER_STATS) += timer_stats.o > obj-$(CONFIG_DEBUG_FS) += timekeeping_debug.o > obj-$(CONFIG_TEST_UDELAY) += test_udelay.o > +obj-$(CONFIG_PERF_CLOCK) += perf_posix_clock.o > > $(obj)/time.o: $(obj)/timeconst.h > > diff --git a/kernel/time/perf_posix_clock.c b/kernel/time/perf_posix_clock.c > new file mode 100644 > index 0000000..03c58b2 > --- /dev/null > +++ b/kernel/time/perf_posix_clock.c > @@ -0,0 +1,54 @@ > +/* > + * Implements CLOCK_PERF. > + * > + * perf_clock is not exported, but for as long as I can remember perf_clock > + * is local_clock which is exported. Make use of that. > + * > + * posix clock implementation by Pawel Moll > + * https://lkml.org/lkml/2013/3/14/523 > + * > + * module by David Ahern, December 2013 > + */ > +#include > +#include > +#include > +#include > +#include > +#include > + > +static int perf_posix_clock_getres(const clockid_t which_clock, > + struct timespec *tp) > +{ > + *tp = ns_to_timespec(TICK_NSEC); > + return 0; > +} > + > +static int perf_posix_clock_get(clockid_t which_clock, struct timespec *tp) > +{ > + *tp = ns_to_timespec(local_clock()); > + return 0; > +} > + > + > +static struct k_clock perf_posix_clock = { > + .clock_getres = perf_posix_clock_getres, > + .clock_get = perf_posix_clock_get, > +}; > + > +static int perf_posix_clock_init(void) > +{ > + /* register this character driver */ > + posix_timers_register_clock(CLOCK_PERF, &perf_posix_clock); > + > + printk(KERN_INFO "perf_clock clock registered\n"); > + > + /* no API to unregister a clock so this module cannot be unloaded */ > + __module_get(THIS_MODULE); > + > + return 0; > +} > + > +module_init(perf_posix_clock_init); > + > +MODULE_AUTHOR("David Ahern"); > +MODULE_LICENSE("GPL"); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/