From: Sagar Arun Kamble <sagar.a.kamble@intel.com>
To: linux-kernel@vger.kernel.org
Cc: Sagar Arun Kamble <sagar.a.kamble@intel.com>,
Richard Cochran <richardcochran@gmail.com>,
Chris Wilson <chris@chris-wilson.co.uk>,
John Stultz <john.stultz@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Stephen Boyd <sboyd@codeaurora.org>
Subject: [PATCH 02/27] timecounter: Introduce timecounter_initialize to update timecounter and cyclecounter
Date: Fri, 15 Dec 2017 13:08:17 +0530 [thread overview]
Message-ID: <1513323522-15021-3-git-send-email-sagar.a.kamble@intel.com> (raw)
In-Reply-To: <1513323522-15021-1-git-send-email-sagar.a.kamble@intel.com>
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 <richardcochran@gmail.com>
Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Stephen Boyd <sboyd@codeaurora.org>
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
next prev parent reply other threads:[~2017-12-15 7:35 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-15 7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 01/27] timecounter: Make cyclecounter struct part of timecounter struct Sagar Arun Kamble
2018-01-08 22:20 ` [Intel-wired-lan] " Brown, Aaron F
2018-01-09 9:01 ` Sagar Arun Kamble
2017-12-15 7:38 ` Sagar Arun Kamble [this message]
2017-12-15 7:38 ` [PATCH 03/27] microblaze: Use timecounter_initialize interface Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 04/27] clocksource/arm_arch_timer: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 05/27] amd-xgbe: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 06/27] bnx2x: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 07/27] fec: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 08/27] e1000e: " Sagar Arun Kamble
2018-01-06 4:31 ` [Intel-wired-lan] " Brown, Aaron F
2017-12-15 7:38 ` [PATCH 09/27] igb: " Sagar Arun Kamble
2018-01-06 5:14 ` [Intel-wired-lan] " Brown, Aaron F
2017-12-15 7:38 ` [PATCH 10/27] ixgbe: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 11/27] net/mlx4: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 12/27] net/mlx5: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 13/27] qede: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 14/27] net: cpts: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 15/27] ALSA: hda - " Sagar Arun Kamble
2017-12-15 11:10 ` [alsa-devel] " Takashi Iwai
2017-12-15 16:51 ` Richard Cochran
2017-12-15 17:10 ` Takashi Iwai
2017-12-26 7:37 ` Sagar Arun Kamble
2017-12-28 16:49 ` Richard Cochran
2018-01-02 6:03 ` Sagar Arun Kamble
2018-01-02 17:15 ` Pierre-Louis Bossart
2018-01-02 18:21 ` Richard Cochran
2018-01-02 19:53 ` Pierre-Louis Bossart
2018-01-05 10:06 ` Sagar Arun Kamble
2018-01-05 15:43 ` Pierre-Louis Bossart
2018-01-09 10:09 ` Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 16/27] timecounter: Introduce timecounter_reset Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 17/27] amd-xgbe: Use timecounter_reset interface Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 18/27] bnx2x: " Sagar Arun Kamble
2017-12-18 14:13 ` Kalluru, Sudarsana
2017-12-15 7:38 ` [PATCH 19/27] net: fec: ptp: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 20/27] e1000e: " Sagar Arun Kamble
2018-01-06 4:30 ` [Intel-wired-lan] " Brown, Aaron F
2017-12-15 7:38 ` [PATCH 21/27] igb: " Sagar Arun Kamble
2018-01-06 4:33 ` [Intel-wired-lan] " Brown, Aaron F
2017-12-15 7:38 ` [PATCH 22/27] ixgbe: " Sagar Arun Kamble
2018-01-06 4:33 ` [Intel-wired-lan] " Brown, Aaron F
2018-01-06 5:11 ` Brown, Aaron F
2017-12-15 7:38 ` [PATCH 23/27] net/mlx4: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 24/27] net/mlx5: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 25/27] qede: " Sagar Arun Kamble
2017-12-18 14:13 ` Kalluru, Sudarsana
2017-12-15 7:38 ` [PATCH 26/27] net: cpts: " Sagar Arun Kamble
2017-12-15 7:38 ` [PATCH 27/27] timecounter: Remove timecounter_init Sagar Arun Kamble
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=1513323522-15021-3-git-send-email-sagar.a.kamble@intel.com \
--to=sagar.a.kamble@intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=sboyd@codeaurora.org \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).