Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753720AbdLOHf2 (ORCPT ); Fri, 15 Dec 2017 02:35:28 -0500 Received: from mga06.intel.com ([134.134.136.31]:56931 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753321AbdLOHfR (ORCPT ); Fri, 15 Dec 2017 02:35:17 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,403,1508828400"; d="scan'208";a="158949198" From: Sagar Arun Kamble To: linux-kernel@vger.kernel.org Cc: Sagar Arun Kamble , Richard Cochran , Chris Wilson , John Stultz , Thomas Gleixner , Stephen Boyd Subject: [PATCH 02/27] timecounter: Introduce timecounter_initialize to update timecounter and cyclecounter Date: Fri, 15 Dec 2017 13:08:17 +0530 Message-Id: <1513323522-15021-3-git-send-email-sagar.a.kamble@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1513323522-15021-1-git-send-email-sagar.a.kamble@intel.com> References: <1513323522-15021-1-git-send-email-sagar.a.kamble@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4576 Lines: 111 With cyclecounter coupled with timecounter, we should move to use interface that initializes entire timecounter structure. This patch creates function timecounter_initialize that takes cyclecounter parameters and start time and initializes the timecounter and underlying cyclecounter. Function timecounter_init which requires initialized cyclecounter can be removed once all drivers are migrated to this new interface. Suggested-by: Richard Cochran Signed-off-by: Sagar Arun Kamble Cc: Richard Cochran Cc: Chris Wilson Cc: John Stultz Cc: Thomas Gleixner Cc: Stephen Boyd Cc: linux-kernel@vger.kernel.org --- include/linux/timecounter.h | 41 ++++++++++++++++++++++++++++++++--------- kernel/time/timecounter.c | 18 ++++++++++++++++++ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/include/linux/timecounter.h b/include/linux/timecounter.h index 6daca06..59d3fd7 100644 --- a/include/linux/timecounter.h +++ b/include/linux/timecounter.h @@ -46,13 +46,14 @@ struct cyclecounter { /** * struct timecounter - layer above a %struct cyclecounter which counts nanoseconds * Contains the state needed by timecounter_read() to detect - * cycle counter wrap around. Initialize with - * timecounter_init(). Also used to convert cycle counts into the - * corresponding nanosecond counts with timecounter_cyc2time(). Users - * of this code are responsible for initializing the underlying - * cycle counter hardware, locking issues and reading the time - * more often than the cycle counter wraps around. The nanosecond - * counter will only wrap around after ~585 years. + * cycle counter wrap around. Initialize with timecounter_init() when + * underlying cyclecounter is initialized, with timecounter_initialize() to + * initialize cyclecounter and timecounter fields. Also used to convert + * cycle counts into the corresponding nanosecond counts with + * timecounter_cyc2time(). Users of this code are responsible for + * locking issues and reading the time more often than the cycle counter + * wraps around. The nanosecond counter will only wrap around after ~585 + * years. * * @cc: the cycle counter used by this instance * @cycle_last: most recent cycle counter value seen by @@ -108,8 +109,30 @@ extern void timecounter_init(struct timecounter *tc, u64 start_tstamp); /** - * timecounter_read - return nanoseconds elapsed since timecounter_init() - * plus the initial time stamp + * timecounter_initialize - initialize a time counter and underlying + cyclecounter + * @tc: Pointer to time counter which is to be initialized + * @read: Pointer to function that returns the current cycle value + * @mask: bitmask for two's complement + * subtraction of non 64 bit counters, + * @mult: cycle to nanosecond multiplier + * @shift: cycle to nanosecond divisor (power of two) + * @start_tstamp: Arbitrary initial time stamp. + * + * After this call the current cycle register (roughly) corresponds to + * the initial time stamp. Every call to timecounter_read() increments + * the time stamp counter by the number of elapsed nanoseconds. + */ +extern void timecounter_initialize(struct timecounter *tc, + u64 (*read)(const struct cyclecounter *cc), + u64 mask, + u32 mult, + u32 shift, + u64 start_tstamp); + +/** + * timecounter_read - return nanoseconds elapsed since timecounter_init() or + * timecounter_initialize() plus the initial time stamp * @tc: Pointer to time counter. * * In other words, keeps track of time since the same epoch as diff --git a/kernel/time/timecounter.c b/kernel/time/timecounter.c index 7919acb..6d915752 100644 --- a/kernel/time/timecounter.c +++ b/kernel/time/timecounter.c @@ -29,6 +29,24 @@ void timecounter_init(struct timecounter *tc, u64 start_tstamp) } EXPORT_SYMBOL_GPL(timecounter_init); +void timecounter_initialize(struct timecounter *tc, + u64 (*read)(const struct cyclecounter *cc), + u64 mask, + u32 mult, + u32 shift, + u64 start_tstamp) +{ + struct cyclecounter *cc = &tc->cc; + + cc->read = read; + cc->mask = mask; + cc->mult = mult; + cc->shift = shift; + + timecounter_init(tc, start_tstamp); +} +EXPORT_SYMBOL_GPL(timecounter_initialize); + /** * timecounter_read_delta - get nanoseconds since last call of this function * @tc: Pointer to time counter -- 1.9.1