linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/27] timecounter/cyclecounter struct/interface update
@ 2017-12-15  7:38 Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 01/27] timecounter: Make cyclecounter struct part of timecounter struct Sagar Arun Kamble
                   ` (26 more replies)
  0 siblings, 27 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, John Stultz, Thomas Gleixner,
	Stephen Boyd

This series makes cyclecounter part of timecounter and introduces two
new interface functions timecounter_initialize() for initializing both
timecounter and cyclecounter fields and timecounter_reset() for setting
start time of timecounter. Updates all drivers with new functions and
removes function timecounter_init().

Cc: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
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

Sagar Arun Kamble (27):
  timecounter: Make cyclecounter struct part of timecounter struct
  timecounter: Introduce timecounter_initialize to update timecounter
    and cyclecounter
  microblaze: Use timecounter_initialize interface
  clocksource/arm_arch_timer: Use timecounter_initialize interface
  amd-xgbe: Use timecounter_initialize interface
  bnx2x: Use timecounter_initialize interface
  fec: Use timecounter_initialize interface
  e1000e: Use timecounter_initialize interface
  igb: Use timecounter_initialize interface
  ixgbe: Use timecounter_initialize interface
  net/mlx4: Use timecounter_initialize interface
  net/mlx5: Use timecounter_initialize interface
  qede: Use timecounter_initialize interface
  net: cpts: Use timecounter_initialize interface
  ALSA: hda - Use timecounter_initialize interface
  timecounter: Introduce timecounter_reset
  amd-xgbe: Use timecounter_reset interface
  bnx2x: Use timecounter_reset interface
  net: fec: ptp: Use timecounter_reset interface
  e1000e: Use timecounter_reset interface
  igb: Use timecounter_reset interface
  ixgbe: Use timecounter_reset interface
  net/mlx4: Use timecounter_reset interface
  net/mlx5: Use timecounter_reset interface
  qede: Use timecounter_reset interface
  net: cpts: Use timecounter_reset interface
  timecounter: Remove timecounter_init

 arch/microblaze/kernel/timer.c                     | 23 ++++-----
 drivers/clocksource/arm_arch_timer.c               | 16 +++---
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c           |  5 +-
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c           | 18 +++----
 drivers/net/ethernet/amd/xgbe/xgbe.h               |  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x.h        |  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c   | 24 ++++-----
 drivers/net/ethernet/freescale/fec.h               |  1 -
 drivers/net/ethernet/freescale/fec_ptp.c           | 34 ++++++-------
 drivers/net/ethernet/intel/e1000e/e1000.h          |  5 +-
 drivers/net/ethernet/intel/e1000e/netdev.c         | 34 +++++++------
 drivers/net/ethernet/intel/e1000e/ptp.c            |  2 +-
 drivers/net/ethernet/intel/igb/igb.h               |  5 +-
 drivers/net/ethernet/intel/igb/igb_ptp.c           | 30 ++++++-----
 drivers/net/ethernet/intel/ixgbe/ixgbe.h           |  7 ++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c      |  4 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c       | 58 ++++++++++++----------
 drivers/net/ethernet/mellanox/mlx4/en_clock.c      | 29 +++++------
 drivers/net/ethernet/mellanox/mlx4/mlx4_en.h       |  1 -
 .../net/ethernet/mellanox/mlx5/core/lib/clock.c    | 38 +++++++-------
 drivers/net/ethernet/qlogic/qede/qede_ptp.c        | 21 ++++----
 drivers/net/ethernet/ti/cpts.c                     | 45 ++++++++++-------
 drivers/net/ethernet/ti/cpts.h                     |  4 +-
 include/linux/mlx5/driver.h                        |  1 -
 include/linux/timecounter.h                        | 52 +++++++++++++------
 include/sound/hdaudio.h                            |  1 -
 kernel/time/timecounter.c                          | 49 ++++++++++++------
 sound/hda/hdac_stream.c                            | 17 +++----
 virt/kvm/arm/arch_timer.c                          |  6 +--
 29 files changed, 291 insertions(+), 241 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 50+ messages in thread

* [PATCH 01/27] timecounter: Make cyclecounter struct part of timecounter struct
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2018-01-08 22:20   ` [Intel-wired-lan] " Brown, Aaron F
  2017-12-15  7:38 ` [PATCH 02/27] timecounter: Introduce timecounter_initialize to update timecounter and cyclecounter Sagar Arun Kamble
                   ` (25 subsequent siblings)
  26 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Chris Wilson, Richard Cochran, John Stultz,
	Thomas Gleixner, Stephen Boyd, linux-arm-kernel, netdev,
	intel-wired-lan, linux-rdma, alsa-devel, kvmarm

There is no real need for the users of timecounters to define cyclecounter
and timecounter variables separately. Since timecounter will always be
based on cyclecounter, have cyclecounter struct as member of timecounter
struct.

v2: Rebase.

Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Richard Cochran <richardcochran@gmail.com>
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
Cc: linux-arm-kernel@lists.infradead.org
Cc: netdev@vger.kernel.org
Cc: intel-wired-lan@lists.osuosl.org
Cc: linux-rdma@vger.kernel.org
Cc: alsa-devel@alsa-project.org
Cc: kvmarm@lists.cs.columbia.edu
Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> (Intel drivers)
---
 arch/microblaze/kernel/timer.c                     | 20 ++++++------
 drivers/clocksource/arm_arch_timer.c               | 19 ++++++------
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c           |  3 +-
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c           |  9 +++---
 drivers/net/ethernet/amd/xgbe/xgbe.h               |  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x.h        |  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c   | 20 ++++++------
 drivers/net/ethernet/freescale/fec.h               |  1 -
 drivers/net/ethernet/freescale/fec_ptp.c           | 30 +++++++++---------
 drivers/net/ethernet/intel/e1000e/e1000.h          |  1 -
 drivers/net/ethernet/intel/e1000e/netdev.c         | 27 ++++++++--------
 drivers/net/ethernet/intel/e1000e/ptp.c            |  2 +-
 drivers/net/ethernet/intel/igb/igb.h               |  1 -
 drivers/net/ethernet/intel/igb/igb_ptp.c           | 25 ++++++++-------
 drivers/net/ethernet/intel/ixgbe/ixgbe.h           |  1 -
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c       | 17 +++++-----
 drivers/net/ethernet/mellanox/mlx4/en_clock.c      | 28 ++++++++---------
 drivers/net/ethernet/mellanox/mlx4/mlx4_en.h       |  1 -
 .../net/ethernet/mellanox/mlx5/core/lib/clock.c    | 34 ++++++++++----------
 drivers/net/ethernet/qlogic/qede/qede_ptp.c        | 20 ++++++------
 drivers/net/ethernet/ti/cpts.c                     | 36 ++++++++++++----------
 drivers/net/ethernet/ti/cpts.h                     |  1 -
 include/linux/mlx5/driver.h                        |  1 -
 include/linux/timecounter.h                        |  4 +--
 include/sound/hdaudio.h                            |  1 -
 kernel/time/timecounter.c                          | 28 ++++++++---------
 sound/hda/hdac_stream.c                            |  7 +++--
 virt/kvm/arm/arch_timer.c                          |  6 ++--
 28 files changed, 163 insertions(+), 182 deletions(-)

diff --git a/arch/microblaze/kernel/timer.c b/arch/microblaze/kernel/timer.c
index 7de941c..b7f89e9 100644
--- a/arch/microblaze/kernel/timer.c
+++ b/arch/microblaze/kernel/timer.c
@@ -199,27 +199,25 @@ static u64 xilinx_read(struct clocksource *cs)
 	return (u64)xilinx_clock_read();
 }
 
-static struct timecounter xilinx_tc = {
-	.cc = NULL,
-};
-
 static u64 xilinx_cc_read(const struct cyclecounter *cc)
 {
 	return xilinx_read(NULL);
 }
 
-static struct cyclecounter xilinx_cc = {
-	.read = xilinx_cc_read,
-	.mask = CLOCKSOURCE_MASK(32),
-	.shift = 8,
+static struct timecounter xilinx_tc = {
+	.cc.read = xilinx_cc_read,
+	.cc.mask = CLOCKSOURCE_MASK(32),
+	.cc.mult = 0,
+	.cc.shift = 8,
 };
 
 static int __init init_xilinx_timecounter(void)
 {
-	xilinx_cc.mult = div_sc(timer_clock_freq, NSEC_PER_SEC,
-				xilinx_cc.shift);
+	struct cyclecounter *cc = &xilinx_tc.cc;
+
+	cc->mult = div_sc(timer_clock_freq, NSEC_PER_SEC, cc->shift);
 
-	timecounter_init(&xilinx_tc, &xilinx_cc, sched_clock());
+	timecounter_init(&xilinx_tc, sched_clock());
 
 	return 0;
 }
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 57cb2f0..31543e5 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -179,11 +179,6 @@ static u64 arch_counter_read_cc(const struct cyclecounter *cc)
 	.flags	= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static struct cyclecounter cyclecounter __ro_after_init = {
-	.read	= arch_counter_read_cc,
-	.mask	= CLOCKSOURCE_MASK(56),
-};
-
 struct ate_acpi_oem_info {
 	char oem_id[ACPI_OEM_ID_SIZE + 1];
 	char oem_table_id[ACPI_OEM_TABLE_ID_SIZE + 1];
@@ -915,7 +910,10 @@ static u64 arch_counter_get_cntvct_mem(void)
 	return ((u64) vct_hi << 32) | vct_lo;
 }
 
-static struct arch_timer_kvm_info arch_timer_kvm_info;
+static struct arch_timer_kvm_info arch_timer_kvm_info = {
+	.timecounter.cc.read = arch_counter_read_cc,
+	.timecounter.cc.mask = CLOCKSOURCE_MASK(56),
+};
 
 struct arch_timer_kvm_info *arch_timer_get_kvm_info(void)
 {
@@ -925,6 +923,7 @@ struct arch_timer_kvm_info *arch_timer_get_kvm_info(void)
 static void __init arch_counter_register(unsigned type)
 {
 	u64 start_count;
+	struct cyclecounter *cc = &arch_timer_kvm_info.timecounter.cc;
 
 	/* Register the CP15 based counter if we have one */
 	if (type & ARCH_TIMER_TYPE_CP15) {
@@ -943,10 +942,10 @@ static void __init arch_counter_register(unsigned type)
 		clocksource_counter.flags |= CLOCK_SOURCE_SUSPEND_NONSTOP;
 	start_count = arch_timer_read_counter();
 	clocksource_register_hz(&clocksource_counter, arch_timer_rate);
-	cyclecounter.mult = clocksource_counter.mult;
-	cyclecounter.shift = clocksource_counter.shift;
-	timecounter_init(&arch_timer_kvm_info.timecounter,
-			 &cyclecounter, start_count);
+
+	cc->mult = clocksource_counter.mult;
+	cc->shift = clocksource_counter.shift;
+	timecounter_init(&arch_timer_kvm_info.timecounter, start_count);
 
 	/* 56 bits minimum, so we assume worst case rollover */
 	sched_clock_register(arch_timer_read_counter, 56, arch_timer_rate);
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
index e107e18..5005c87 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
@@ -1622,8 +1622,7 @@ static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
 	xgbe_set_tstamp_time(pdata, 0, 0);
 
 	/* Initialize the timecounter */
-	timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
-			 ktime_to_ns(ktime_get_real()));
+	timecounter_init(&pdata->tstamp_tc, ktime_to_ns(ktime_get_real()));
 
 	return 0;
 }
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
index d06d260..5ea4edf 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
@@ -126,7 +126,7 @@ static u64 xgbe_cc_read(const struct cyclecounter *cc)
 {
 	struct xgbe_prv_data *pdata = container_of(cc,
 						   struct xgbe_prv_data,
-						   tstamp_cc);
+						   tstamp_tc.cc);
 	u64 nsec;
 
 	nsec = pdata->hw_if.get_tstamp_time(pdata);
@@ -211,7 +211,7 @@ static int xgbe_settime(struct ptp_clock_info *info,
 
 	spin_lock_irqsave(&pdata->tstamp_lock, flags);
 
-	timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc, nsec);
+	timecounter_init(&pdata->tstamp_tc, nsec);
 
 	spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
 
@@ -228,7 +228,7 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
 {
 	struct ptp_clock_info *info = &pdata->ptp_clock_info;
 	struct ptp_clock *clock;
-	struct cyclecounter *cc = &pdata->tstamp_cc;
+	struct cyclecounter *cc = &pdata->tstamp_tc.cc;
 	u64 dividend;
 
 	snprintf(info->name, sizeof(info->name), "%s",
@@ -263,8 +263,7 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
 	cc->mult = 1;
 	cc->shift = 0;
 
-	timecounter_init(&pdata->tstamp_tc, &pdata->tstamp_cc,
-			 ktime_to_ns(ktime_get_real()));
+	timecounter_init(&pdata->tstamp_tc, ktime_to_ns(ktime_get_real()));
 
 	/* Disable all timestamping to start */
 	XGMAC_IOWRITE(pdata, MAC_TSCR, 0);
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
index ad102c8..2445103 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
+++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
@@ -1168,7 +1168,6 @@ struct xgbe_prv_data {
 	struct ptp_clock_info ptp_clock_info;
 	struct ptp_clock *ptp_clock;
 	struct hwtstamp_config tstamp_config;
-	struct cyclecounter tstamp_cc;
 	struct timecounter tstamp_tc;
 	unsigned int tstamp_addend;
 	struct work_struct tx_tstamp_work;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
index 352beff..f164fe0 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
@@ -1827,7 +1827,6 @@ struct bnx2x {
 	struct ptp_clock *ptp_clock;
 	struct ptp_clock_info ptp_clock_info;
 	struct work_struct ptp_task;
-	struct cyclecounter cyclecounter;
 	struct timecounter timecounter;
 	bool timecounter_init_done;
 	struct sk_buff *ptp_tx_skb;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 91e2a75..83624ad 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13850,7 +13850,7 @@ static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
 	DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
 
 	/* Re-init the timecounter */
-	timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
+	timecounter_init(&bp->timecounter, ns);
 
 	return 0;
 }
@@ -15254,7 +15254,7 @@ void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
 /* Read the PHC */
 static u64 bnx2x_cyclecounter_read(const struct cyclecounter *cc)
 {
-	struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
+	struct bnx2x *bp = container_of(cc, struct bnx2x, timecounter.cc);
 	int port = BP_PORT(bp);
 	u32 wb_data[2];
 	u64 phc_cycles;
@@ -15269,13 +15269,13 @@ static u64 bnx2x_cyclecounter_read(const struct cyclecounter *cc)
 	return phc_cycles;
 }
 
-static void bnx2x_init_cyclecounter(struct bnx2x *bp)
+static void bnx2x_init_cyclecounter(struct cyclecounter *cc)
 {
-	memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
-	bp->cyclecounter.read = bnx2x_cyclecounter_read;
-	bp->cyclecounter.mask = CYCLECOUNTER_MASK(64);
-	bp->cyclecounter.shift = 0;
-	bp->cyclecounter.mult = 1;
+	memset(cc, 0, sizeof(*cc));
+	cc->read = bnx2x_cyclecounter_read;
+	cc->mask = CYCLECOUNTER_MASK(64);
+	cc->shift = 0;
+	cc->mult = 1;
 }
 
 static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
@@ -15511,8 +15511,8 @@ void bnx2x_init_ptp(struct bnx2x *bp)
 	 * unload / load (e.g. MTU change) while it is running.
 	 */
 	if (!bp->timecounter_init_done) {
-		bnx2x_init_cyclecounter(bp);
-		timecounter_init(&bp->timecounter, &bp->cyclecounter,
+		bnx2x_init_cyclecounter(&bp->timecounter.cc);
+		timecounter_init(&bp->timecounter,
 				 ktime_to_ns(ktime_get_real()));
 		bp->timecounter_init_done = 1;
 	}
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 5385074..d54b501 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -549,7 +549,6 @@ struct fec_enet_private {
 	struct ptp_clock_info ptp_caps;
 	unsigned long last_overflow_check;
 	spinlock_t tmreg_lock;
-	struct cyclecounter cc;
 	struct timecounter tc;
 	int rx_hwtstamp_filter;
 	u32 base_incval;
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index f814397..b1261d1 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -186,13 +186,14 @@ static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable)
 		 * ptp counter, which maybe cause 32-bit wrap. Since the
 		 * (NSEC_PER_SEC - (u32)ts.tv_nsec) is less than 2 second.
 		 * We can ensure the wrap will not cause issue. If the offset
-		 * is bigger than fep->cc.mask would be a error.
+		 * is bigger than fep->tc.cc.mask would be a error.
 		 */
-		val &= fep->cc.mask;
+		val &= fep->tc.cc.mask;
 		writel(val, fep->hwp + FEC_TCCR(fep->pps_channel));
 
 		/* Calculate the second the compare event timestamp */
-		fep->next_counter = (val + fep->reload_period) & fep->cc.mask;
+		fep->next_counter = (val + fep->reload_period) &
+				    fep->tc.cc.mask;
 
 		/* * Enable compare event when overflow */
 		val = readl(fep->hwp + FEC_ATIME_CTRL);
@@ -211,7 +212,8 @@ static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable)
 		 * the third timestamp. Refer the TCCR register detail in the spec.
 		 */
 		writel(fep->next_counter, fep->hwp + FEC_TCCR(fep->pps_channel));
-		fep->next_counter = (fep->next_counter + fep->reload_period) & fep->cc.mask;
+		fep->next_counter = (fep->next_counter + fep->reload_period) &
+				    fep->tc.cc.mask;
 	} else {
 		writel(0, fep->hwp + FEC_TCSR(fep->pps_channel));
 	}
@@ -233,7 +235,7 @@ static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable)
 static u64 fec_ptp_read(const struct cyclecounter *cc)
 {
 	struct fec_enet_private *fep =
-		container_of(cc, struct fec_enet_private, cc);
+		container_of(cc, struct fec_enet_private, tc.cc);
 	const struct platform_device_id *id_entry =
 		platform_get_device_id(fep->pdev);
 	u32 tempval;
@@ -276,14 +278,14 @@ void fec_ptp_start_cyclecounter(struct net_device *ndev)
 	writel(FEC_T_CTRL_ENABLE | FEC_T_CTRL_PERIOD_RST,
 		fep->hwp + FEC_ATIME_CTRL);
 
-	memset(&fep->cc, 0, sizeof(fep->cc));
-	fep->cc.read = fec_ptp_read;
-	fep->cc.mask = CLOCKSOURCE_MASK(31);
-	fep->cc.shift = 31;
-	fep->cc.mult = FEC_CC_MULT;
+	memset(&fep->tc.cc, 0, sizeof(fep->tc.cc));
+	fep->tc.cc.read = fec_ptp_read;
+	fep->tc.cc.mask = CLOCKSOURCE_MASK(31);
+	fep->tc.cc.shift = 31;
+	fep->tc.cc.mult = FEC_CC_MULT;
 
 	/* reset the ns time counter */
-	timecounter_init(&fep->tc, &fep->cc, ktime_to_ns(ktime_get_real()));
+	timecounter_init(&fep->tc, ktime_to_ns(ktime_get_real()));
 
 	spin_unlock_irqrestore(&fep->tmreg_lock, flags);
 }
@@ -434,11 +436,11 @@ static int fec_ptp_settime(struct ptp_clock_info *ptp,
 	/* Get the timer value based on timestamp.
 	 * Update the counter with the masked value.
 	 */
-	counter = ns & fep->cc.mask;
+	counter = ns & fep->tc.cc.mask;
 
 	spin_lock_irqsave(&fep->tmreg_lock, flags);
 	writel(counter, fep->hwp + FEC_ATIME);
-	timecounter_init(&fep->tc, &fep->cc, ns);
+	timecounter_init(&fep->tc, ns);
 	spin_unlock_irqrestore(&fep->tmreg_lock, flags);
 	mutex_unlock(&fep->ptp_clk_mutex);
 	return 0;
@@ -570,7 +572,7 @@ static irqreturn_t fec_pps_interrupt(int irq, void *dev_id)
 
 		/* Update the counter; */
 		fep->next_counter = (fep->next_counter + fep->reload_period) &
-				fep->cc.mask;
+				    fep->tc.cc.mask;
 
 		event.type = PTP_CLOCK_PPS;
 		ptp_clock_event(fep->ptp_clock, &event);
diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
index 2311b31..b59f82a 100644
--- a/drivers/net/ethernet/intel/e1000e/e1000.h
+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
@@ -340,7 +340,6 @@ struct e1000_adapter {
 	unsigned long tx_hwtstamp_start;
 	struct work_struct tx_hwtstamp_work;
 	spinlock_t systim_lock;	/* protects SYSTIML/H regsters */
-	struct cyclecounter cc;
 	struct timecounter tc;
 	struct ptp_clock *ptp_clock;
 	struct ptp_clock_info ptp_clock_info;
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
index 9f18d39..c9f7ba3 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -3536,7 +3536,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 		incperiod = INCPERIOD_96MHZ;
 		incvalue = INCVALUE_96MHZ;
 		shift = INCVALUE_SHIFT_96MHZ;
-		adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
+		adapter->tc.cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
 		break;
 	case e1000_pch_lpt:
 		if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
@@ -3544,13 +3544,13 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 			incperiod = INCPERIOD_96MHZ;
 			incvalue = INCVALUE_96MHZ;
 			shift = INCVALUE_SHIFT_96MHZ;
-			adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
+			adapter->tc.cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
 		} else {
 			/* Stable 25MHz frequency */
 			incperiod = INCPERIOD_25MHZ;
 			incvalue = INCVALUE_25MHZ;
 			shift = INCVALUE_SHIFT_25MHZ;
-			adapter->cc.shift = shift;
+			adapter->tc.cc.shift = shift;
 		}
 		break;
 	case e1000_pch_spt:
@@ -3559,7 +3559,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 			incperiod = INCPERIOD_24MHZ;
 			incvalue = INCVALUE_24MHZ;
 			shift = INCVALUE_SHIFT_24MHZ;
-			adapter->cc.shift = shift;
+			adapter->tc.cc.shift = shift;
 			break;
 		}
 		return -EINVAL;
@@ -3569,13 +3569,13 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 			incperiod = INCPERIOD_24MHZ;
 			incvalue = INCVALUE_24MHZ;
 			shift = INCVALUE_SHIFT_24MHZ;
-			adapter->cc.shift = shift;
+			adapter->tc.cc.shift = shift;
 		} else {
 			/* Stable 38400KHz frequency */
 			incperiod = INCPERIOD_38400KHZ;
 			incvalue = INCVALUE_38400KHZ;
 			shift = INCVALUE_SHIFT_38400KHZ;
-			adapter->cc.shift = shift;
+			adapter->tc.cc.shift = shift;
 		}
 		break;
 	case e1000_82574:
@@ -3584,7 +3584,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 		incperiod = INCPERIOD_25MHZ;
 		incvalue = INCVALUE_25MHZ;
 		shift = INCVALUE_SHIFT_25MHZ;
-		adapter->cc.shift = shift;
+		adapter->tc.cc.shift = shift;
 		break;
 	default:
 		return -EINVAL;
@@ -3955,8 +3955,7 @@ static void e1000e_systim_reset(struct e1000_adapter *adapter)
 
 	/* reset the systim ns time counter */
 	spin_lock_irqsave(&adapter->systim_lock, flags);
-	timecounter_init(&adapter->tc, &adapter->cc,
-			 ktime_to_ns(ktime_get_real()));
+	timecounter_init(&adapter->tc, ktime_to_ns(ktime_get_real()));
 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
 
 	/* restore the previous hwtstamp configuration settings */
@@ -4389,7 +4388,7 @@ static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim)
 static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc)
 {
 	struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
-						     cc);
+						     tc.cc);
 	struct e1000_hw *hw = &adapter->hw;
 	u32 systimel, systimeh;
 	u64 systim;
@@ -4449,10 +4448,10 @@ static int e1000_sw_init(struct e1000_adapter *adapter)
 
 	/* Setup hardware time stamping cyclecounter */
 	if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
-		adapter->cc.read = e1000e_cyclecounter_read;
-		adapter->cc.mask = CYCLECOUNTER_MASK(64);
-		adapter->cc.mult = 1;
-		/* cc.shift set in e1000e_get_base_tininca() */
+		adapter->tc.cc.read = e1000e_cyclecounter_read;
+		adapter->tc.cc.mask = CYCLECOUNTER_MASK(64);
+		adapter->tc.cc.mult = 1;
+		/* tc.cc.shift set in e1000e_get_base_tininca() */
 
 		spin_lock_init(&adapter->systim_lock);
 		INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
diff --git a/drivers/net/ethernet/intel/e1000e/ptp.c b/drivers/net/ethernet/intel/e1000e/ptp.c
index b366885..03d5f2a 100644
--- a/drivers/net/ethernet/intel/e1000e/ptp.c
+++ b/drivers/net/ethernet/intel/e1000e/ptp.c
@@ -222,7 +222,7 @@ static int e1000e_phc_settime(struct ptp_clock_info *ptp,
 
 	/* reset the timecounter */
 	spin_lock_irqsave(&adapter->systim_lock, flags);
-	timecounter_init(&adapter->tc, &adapter->cc, ns);
+	timecounter_init(&adapter->tc, ns);
 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
 
 	return 0;
diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
index 9284569..4eac4f2 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -565,7 +565,6 @@ struct igb_adapter {
 	unsigned long last_rx_timestamp;
 	unsigned int ptp_flags;
 	spinlock_t tmreg_lock;
-	struct cyclecounter cc;
 	struct timecounter tc;
 	u32 tx_hwtstamp_timeouts;
 	u32 tx_hwtstamp_skipped;
diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index 841c2a0..0745eff 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -79,7 +79,7 @@
 /* SYSTIM read access for the 82576 */
 static u64 igb_ptp_read_82576(const struct cyclecounter *cc)
 {
-	struct igb_adapter *igb = container_of(cc, struct igb_adapter, cc);
+	struct igb_adapter *igb = container_of(cc, struct igb_adapter, tc.cc);
 	struct e1000_hw *hw = &igb->hw;
 	u64 val;
 	u32 lo, hi;
@@ -96,7 +96,7 @@ static u64 igb_ptp_read_82576(const struct cyclecounter *cc)
 /* SYSTIM read access for the 82580 */
 static u64 igb_ptp_read_82580(const struct cyclecounter *cc)
 {
-	struct igb_adapter *igb = container_of(cc, struct igb_adapter, cc);
+	struct igb_adapter *igb = container_of(cc, struct igb_adapter, tc.cc);
 	struct e1000_hw *hw = &igb->hw;
 	u32 lo, hi;
 	u64 val;
@@ -330,7 +330,7 @@ static int igb_ptp_settime_82576(struct ptp_clock_info *ptp,
 
 	spin_lock_irqsave(&igb->tmreg_lock, flags);
 
-	timecounter_init(&igb->tc, &igb->cc, ns);
+	timecounter_init(&igb->tc, ns);
 
 	spin_unlock_irqrestore(&igb->tmreg_lock, flags);
 
@@ -1126,10 +1126,10 @@ void igb_ptp_init(struct igb_adapter *adapter)
 		adapter->ptp_caps.gettime64 = igb_ptp_gettime_82576;
 		adapter->ptp_caps.settime64 = igb_ptp_settime_82576;
 		adapter->ptp_caps.enable = igb_ptp_feature_enable;
-		adapter->cc.read = igb_ptp_read_82576;
-		adapter->cc.mask = CYCLECOUNTER_MASK(64);
-		adapter->cc.mult = 1;
-		adapter->cc.shift = IGB_82576_TSYNC_SHIFT;
+		adapter->tc.cc.read = igb_ptp_read_82576;
+		adapter->tc.cc.mask = CYCLECOUNTER_MASK(64);
+		adapter->tc.cc.mult = 1;
+		adapter->tc.cc.shift = IGB_82576_TSYNC_SHIFT;
 		adapter->ptp_flags |= IGB_PTP_OVERFLOW_CHECK;
 		break;
 	case e1000_82580:
@@ -1145,10 +1145,10 @@ void igb_ptp_init(struct igb_adapter *adapter)
 		adapter->ptp_caps.gettime64 = igb_ptp_gettime_82576;
 		adapter->ptp_caps.settime64 = igb_ptp_settime_82576;
 		adapter->ptp_caps.enable = igb_ptp_feature_enable;
-		adapter->cc.read = igb_ptp_read_82580;
-		adapter->cc.mask = CYCLECOUNTER_MASK(IGB_NBITS_82580);
-		adapter->cc.mult = 1;
-		adapter->cc.shift = 0;
+		adapter->tc.cc.read = igb_ptp_read_82580;
+		adapter->tc.cc.mask = CYCLECOUNTER_MASK(IGB_NBITS_82580);
+		adapter->tc.cc.mult = 1;
+		adapter->tc.cc.shift = 0;
 		adapter->ptp_flags |= IGB_PTP_OVERFLOW_CHECK;
 		break;
 	case e1000_i210:
@@ -1289,8 +1289,7 @@ void igb_ptp_reset(struct igb_adapter *adapter)
 
 		igb_ptp_write_i210(adapter, &ts);
 	} else {
-		timecounter_init(&adapter->tc, &adapter->cc,
-				 ktime_to_ns(ktime_get_real()));
+		timecounter_init(&adapter->tc, ktime_to_ns(ktime_get_real()));
 	}
 out:
 	spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
index 468c355..5c391a0 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
@@ -738,7 +738,6 @@ struct ixgbe_adapter {
 	unsigned long last_rx_ptp_check;
 	unsigned long last_rx_timestamp;
 	spinlock_t tmreg_lock;
-	struct cyclecounter hw_cc;
 	struct timecounter hw_tc;
 	u32 base_incval;
 	u32 tx_hwtstamp_timeouts;
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index ae312c4..6e9f2c0 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -179,7 +179,7 @@
 static void ixgbe_ptp_setup_sdp_x540(struct ixgbe_adapter *adapter)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
-	int shift = adapter->hw_cc.shift;
+	int shift = adapter->hw_tc.cc.shift;
 	u32 esdp, tsauxc, clktiml, clktimh, trgttiml, trgttimh, rem;
 	u64 ns = 0, clock_edge = 0;
 
@@ -237,7 +237,7 @@ static void ixgbe_ptp_setup_sdp_x540(struct ixgbe_adapter *adapter)
 
 /**
  * ixgbe_ptp_read_X550 - read cycle counter value
- * @hw_cc: cyclecounter structure
+ * @cc: cyclecounter structure
  *
  * This function reads SYSTIME registers. It is called by the cyclecounter
  * structure to convert from internal representation into nanoseconds. We need
@@ -245,10 +245,10 @@ static void ixgbe_ptp_setup_sdp_x540(struct ixgbe_adapter *adapter)
  * result of SYSTIME is 32bits of "billions of cycles" and 32 bits of
  * "cycles", rather than seconds and nanoseconds.
  */
-static u64 ixgbe_ptp_read_X550(const struct cyclecounter *hw_cc)
+static u64 ixgbe_ptp_read_X550(const struct cyclecounter *cc)
 {
 	struct ixgbe_adapter *adapter =
-			container_of(hw_cc, struct ixgbe_adapter, hw_cc);
+			container_of(cc, struct ixgbe_adapter, hw_tc.cc);
 	struct ixgbe_hw *hw = &adapter->hw;
 	struct timespec64 ts;
 
@@ -285,7 +285,7 @@ static u64 ixgbe_ptp_read_X550(const struct cyclecounter *hw_cc)
 static u64 ixgbe_ptp_read_82599(const struct cyclecounter *cc)
 {
 	struct ixgbe_adapter *adapter =
-		container_of(cc, struct ixgbe_adapter, hw_cc);
+		container_of(cc, struct ixgbe_adapter, hw_tc.cc);
 	struct ixgbe_hw *hw = &adapter->hw;
 	u64 stamp = 0;
 
@@ -508,7 +508,7 @@ static int ixgbe_ptp_settime(struct ptp_clock_info *ptp,
 
 	/* reset the timecounter */
 	spin_lock_irqsave(&adapter->tmreg_lock, flags);
-	timecounter_init(&adapter->hw_tc, &adapter->hw_cc, ns);
+	timecounter_init(&adapter->hw_tc, ns);
 	spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
 
 	if (adapter->ptp_setup_sdp)
@@ -1164,7 +1164,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
 
 	/* need lock to prevent incorrect read while modifying cyclecounter */
 	spin_lock_irqsave(&adapter->tmreg_lock, flags);
-	memcpy(&adapter->hw_cc, &cc, sizeof(adapter->hw_cc));
+	memcpy(&adapter->hw_tc.cc, &cc, sizeof(adapter->hw_tc.cc));
 	spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
 }
 
@@ -1195,8 +1195,7 @@ void ixgbe_ptp_reset(struct ixgbe_adapter *adapter)
 	ixgbe_ptp_start_cyclecounter(adapter);
 
 	spin_lock_irqsave(&adapter->tmreg_lock, flags);
-	timecounter_init(&adapter->hw_tc, &adapter->hw_cc,
-			 ktime_to_ns(ktime_get_real()));
+	timecounter_init(&adapter->hw_tc, ktime_to_ns(ktime_get_real()));
 	spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
 
 	adapter->last_overflow_check = jiffies;
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
index 0247885..35987b5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
@@ -38,13 +38,13 @@
 
 /* mlx4_en_read_clock - read raw cycle counter (to be used by time counter)
  */
-static u64 mlx4_en_read_clock(const struct cyclecounter *tc)
+static u64 mlx4_en_read_clock(const struct cyclecounter *cc)
 {
 	struct mlx4_en_dev *mdev =
-		container_of(tc, struct mlx4_en_dev, cycles);
+		container_of(cc, struct mlx4_en_dev, clock.cc);
 	struct mlx4_dev *dev = mdev->dev;
 
-	return mlx4_read_clock(dev) & tc->mask;
+	return mlx4_read_clock(dev) & cc->mask;
 }
 
 u64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe)
@@ -138,7 +138,7 @@ static int mlx4_en_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta)
 
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
 	timecounter_read(&mdev->clock);
-	mdev->cycles.mult = neg_adj ? mult - diff : mult + diff;
+	mdev->clock.cc.mult = neg_adj ? mult - diff : mult + diff;
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
 
 	return 0;
@@ -207,7 +207,7 @@ static int mlx4_en_phc_settime(struct ptp_clock_info *ptp,
 
 	/* reset the timecounter */
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
-	timecounter_init(&mdev->clock, &mdev->cycles, ns);
+	timecounter_init(&mdev->clock, ns);
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
 
 	return 0;
@@ -274,17 +274,17 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
 
 	seqlock_init(&mdev->clock_lock);
 
-	memset(&mdev->cycles, 0, sizeof(mdev->cycles));
-	mdev->cycles.read = mlx4_en_read_clock;
-	mdev->cycles.mask = CLOCKSOURCE_MASK(48);
-	mdev->cycles.shift = freq_to_shift(dev->caps.hca_core_clock);
-	mdev->cycles.mult =
-		clocksource_khz2mult(1000 * dev->caps.hca_core_clock, mdev->cycles.shift);
-	mdev->nominal_c_mult = mdev->cycles.mult;
+	memset(&mdev->clock.cc, 0, sizeof(mdev->clock.cc));
+	mdev->clock.cc.read = mlx4_en_read_clock;
+	mdev->clock.cc.mask = CLOCKSOURCE_MASK(48);
+	mdev->clock.cc.shift = freq_to_shift(dev->caps.hca_core_clock);
+	mdev->clock.cc.mult =
+		clocksource_khz2mult(1000 * dev->caps.hca_core_clock,
+				     mdev->clock.cc.shift);
+	mdev->nominal_c_mult = mdev->clock.cc.mult;
 
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
-	timecounter_init(&mdev->clock, &mdev->cycles,
-			 ktime_to_ns(ktime_get_real()));
+	timecounter_init(&mdev->clock, ktime_to_ns(ktime_get_real()));
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
 
 	/* Configure the PHC */
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
index 1856e27..e301dcf 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
@@ -422,7 +422,6 @@ struct mlx4_en_dev {
 	spinlock_t              uar_lock;
 	u8			mac_removed[MLX4_MAX_PORTS + 1];
 	u32			nominal_c_mult;
-	struct cyclecounter	cycles;
 	seqlock_t		clock_lock;
 	struct timecounter	clock;
 	unsigned long		last_overflow_check;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
index fa8aed6..8cb6838 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
@@ -64,7 +64,7 @@ enum {
 
 static u64 read_internal_timer(const struct cyclecounter *cc)
 {
-	struct mlx5_clock *clock = container_of(cc, struct mlx5_clock, cycles);
+	struct mlx5_clock *clock = container_of(cc, struct mlx5_clock, tc.cc);
 	struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev,
 						  clock);
 
@@ -122,7 +122,7 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp,
 	unsigned long flags;
 
 	write_lock_irqsave(&clock->lock, flags);
-	timecounter_init(&clock->tc, &clock->cycles, ns);
+	timecounter_init(&clock->tc, ns);
 	write_unlock_irqrestore(&clock->lock, flags);
 
 	return 0;
@@ -177,8 +177,8 @@ static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta)
 
 	write_lock_irqsave(&clock->lock, flags);
 	timecounter_read(&clock->tc);
-	clock->cycles.mult = neg_adj ? clock->nominal_c_mult - diff :
-				       clock->nominal_c_mult + diff;
+	clock->tc.cc.mult = neg_adj ? clock->nominal_c_mult - diff :
+				      clock->nominal_c_mult + diff;
 	write_unlock_irqrestore(&clock->lock, flags);
 
 	return 0;
@@ -281,8 +281,8 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp,
 		write_lock_irqsave(&clock->lock, flags);
 		nsec_now = timecounter_cyc2time(&clock->tc, cycles_now);
 		nsec_delta = ns - nsec_now;
-		cycles_delta = div64_u64(nsec_delta << clock->cycles.shift,
-					 clock->cycles.mult);
+		cycles_delta = div64_u64(nsec_delta << clock->tc.cc.shift,
+					 clock->tc.cc.mult);
 		write_unlock_irqrestore(&clock->lock, flags);
 		time_stamp = cycles_now + cycles_delta;
 		field_select = MLX5_MTPPS_FS_PIN_MODE |
@@ -440,8 +440,8 @@ void mlx5_pps_event(struct mlx5_core_dev *mdev,
 		write_lock_irqsave(&clock->lock, flags);
 		nsec_now = timecounter_cyc2time(&clock->tc, cycles_now);
 		nsec_delta = ns - nsec_now;
-		cycles_delta = div64_u64(nsec_delta << clock->cycles.shift,
-					 clock->cycles.mult);
+		cycles_delta = div64_u64(nsec_delta << clock->tc.cc.shift,
+					 clock->tc.cc.mult);
 		clock->pps_info.start[pin] = cycles_now + cycles_delta;
 		schedule_work(&clock->pps_info.out_work);
 		write_unlock_irqrestore(&clock->lock, flags);
@@ -454,6 +454,7 @@ void mlx5_pps_event(struct mlx5_core_dev *mdev,
 void mlx5_init_clock(struct mlx5_core_dev *mdev)
 {
 	struct mlx5_clock *clock = &mdev->clock;
+	struct cyclecounter *cc = &clock->tc.cc;
 	u64 ns;
 	u64 frac = 0;
 	u32 dev_freq;
@@ -464,21 +465,18 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev)
 		return;
 	}
 	rwlock_init(&clock->lock);
-	clock->cycles.read = read_internal_timer;
-	clock->cycles.shift = MLX5_CYCLES_SHIFT;
-	clock->cycles.mult = clocksource_khz2mult(dev_freq,
-						  clock->cycles.shift);
-	clock->nominal_c_mult = clock->cycles.mult;
-	clock->cycles.mask = CLOCKSOURCE_MASK(41);
+	cc->read = read_internal_timer;
+	cc->shift = MLX5_CYCLES_SHIFT;
+	cc->mult = clocksource_khz2mult(dev_freq, cc->shift);
+	clock->nominal_c_mult = cc->mult;
+	cc->mask = CLOCKSOURCE_MASK(41);
 
-	timecounter_init(&clock->tc, &clock->cycles,
-			 ktime_to_ns(ktime_get_real()));
+	timecounter_init(&clock->tc, ktime_to_ns(ktime_get_real()));
 
 	/* Calculate period in seconds to call the overflow watchdog - to make
 	 * sure counter is checked at least once every wrap around.
 	 */
-	ns = cyclecounter_cyc2ns(&clock->cycles, clock->cycles.mask,
-				 frac, &frac);
+	ns = cyclecounter_cyc2ns(cc, cc->mask, frac, &frac);
 	do_div(ns, NSEC_PER_SEC / 2 / HZ);
 	clock->overflow_period = ns;
 
diff --git a/drivers/net/ethernet/qlogic/qede/qede_ptp.c b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
index 9b2280b..95bb8a8 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ptp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
@@ -34,7 +34,6 @@
 struct qede_ptp {
 	const struct qed_eth_ptp_ops	*ops;
 	struct ptp_clock_info		clock_info;
-	struct cyclecounter		cc;
 	struct timecounter		tc;
 	struct ptp_clock		*clock;
 	struct work_struct		work;
@@ -132,7 +131,7 @@ static int qede_ptp_settime(struct ptp_clock_info *info,
 
 	/* Re-init the timecounter */
 	spin_lock_bh(&ptp->lock);
-	timecounter_init(&ptp->tc, &ptp->cc, ns);
+	timecounter_init(&ptp->tc, ns);
 	spin_unlock_bh(&ptp->lock);
 
 	return 0;
@@ -196,7 +195,7 @@ static u64 qede_ptp_read_cc(const struct cyclecounter *cc)
 	u64 phc_cycles;
 	int rc;
 
-	ptp = container_of(cc, struct qede_ptp, cc);
+	ptp = container_of(cc, struct qede_ptp, tc.cc);
 	edev = ptp->edev;
 	rc = ptp->ops->read_cc(edev->cdev, &phc_cycles);
 	if (rc)
@@ -428,14 +427,13 @@ static int qede_ptp_init(struct qede_dev *edev, bool init_tc)
 	 * unload / load (e.g. MTU change) while it is running.
 	 */
 	if (init_tc) {
-		memset(&ptp->cc, 0, sizeof(ptp->cc));
-		ptp->cc.read = qede_ptp_read_cc;
-		ptp->cc.mask = CYCLECOUNTER_MASK(64);
-		ptp->cc.shift = 0;
-		ptp->cc.mult = 1;
-
-		timecounter_init(&ptp->tc, &ptp->cc,
-				 ktime_to_ns(ktime_get_real()));
+		memset(&ptp->tc.cc, 0, sizeof(ptp->tc.cc));
+		ptp->tc.cc.read = qede_ptp_read_cc;
+		ptp->tc.cc.mask = CYCLECOUNTER_MASK(64);
+		ptp->tc.cc.shift = 0;
+		ptp->tc.cc.mult = 1;
+
+		timecounter_init(&ptp->tc, ktime_to_ns(ktime_get_real()));
 	}
 
 	return rc;
diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index e7b76f6..b8fe843 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -182,7 +182,7 @@ static u64 cpts_systim_read(const struct cyclecounter *cc)
 	u64 val = 0;
 	struct cpts_event *event;
 	struct list_head *this, *next;
-	struct cpts *cpts = container_of(cc, struct cpts, cc);
+	struct cpts *cpts = container_of(cc, struct cpts, tc.cc);
 
 	cpts_write32(cpts, TS_PUSH, ts_push);
 	if (cpts_fifo_read(cpts, CPTS_EV_PUSH))
@@ -224,7 +224,7 @@ static int cpts_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
 
 	timecounter_read(&cpts->tc);
 
-	cpts->cc.mult = neg_adj ? mult - diff : mult + diff;
+	cpts->tc.cc.mult = neg_adj ? mult - diff : mult + diff;
 
 	spin_unlock_irqrestore(&cpts->lock, flags);
 
@@ -268,7 +268,7 @@ static int cpts_ptp_settime(struct ptp_clock_info *ptp,
 	ns = timespec64_to_ns(ts);
 
 	spin_lock_irqsave(&cpts->lock, flags);
-	timecounter_init(&cpts->tc, &cpts->cc, ns);
+	timecounter_init(&cpts->tc, ns);
 	spin_unlock_irqrestore(&cpts->lock, flags);
 
 	return 0;
@@ -447,7 +447,7 @@ int cpts_register(struct cpts *cpts)
 	cpts_write32(cpts, CPTS_EN, control);
 	cpts_write32(cpts, TS_PEND_EN, int_enable);
 
-	timecounter_init(&cpts->tc, &cpts->cc, ktime_to_ns(ktime_get_real()));
+	timecounter_init(&cpts->tc, ktime_to_ns(ktime_get_real()));
 
 	cpts->clock = ptp_clock_register(&cpts->info, cpts->dev);
 	if (IS_ERR(cpts->clock)) {
@@ -486,6 +486,7 @@ void cpts_unregister(struct cpts *cpts)
 
 static void cpts_calc_mult_shift(struct cpts *cpts)
 {
+	struct cyclecounter *cc = &cpts->tc.cc;
 	u64 frac, maxsec, ns;
 	u32 freq;
 
@@ -494,7 +495,7 @@ static void cpts_calc_mult_shift(struct cpts *cpts)
 	/* Calc the maximum number of seconds which we can run before
 	 * wrapping around.
 	 */
-	maxsec = cpts->cc.mask;
+	maxsec = cc->mask;
 	do_div(maxsec, freq);
 	/* limit conversation rate to 10 sec as higher values will produce
 	 * too small mult factors and so reduce the conversion accuracy
@@ -507,18 +508,19 @@ static void cpts_calc_mult_shift(struct cpts *cpts)
 	dev_info(cpts->dev, "cpts: overflow check period %lu (jiffies)\n",
 		 cpts->ov_check_period);
 
-	if (cpts->cc.mult || cpts->cc.shift)
+	if (cc->mult || cc->shift)
 		return;
 
-	clocks_calc_mult_shift(&cpts->cc.mult, &cpts->cc.shift,
+	clocks_calc_mult_shift(&cc->mult, &cc->shift,
 			       freq, NSEC_PER_SEC, maxsec);
 
 	frac = 0;
-	ns = cyclecounter_cyc2ns(&cpts->cc, freq, cpts->cc.mask, &frac);
+	ns = cyclecounter_cyc2ns(cc, freq, cc->mask, &frac);
 
 	dev_info(cpts->dev,
 		 "CPTS: ref_clk_freq:%u calc_mult:%u calc_shift:%u error:%lld nsec/sec\n",
-		 freq, cpts->cc.mult, cpts->cc.shift, (ns - NSEC_PER_SEC));
+		 freq, cc->mult, cc->shift,
+		 (ns - NSEC_PER_SEC));
 }
 
 static int cpts_of_parse(struct cpts *cpts, struct device_node *node)
@@ -527,13 +529,13 @@ static int cpts_of_parse(struct cpts *cpts, struct device_node *node)
 	u32 prop;
 
 	if (!of_property_read_u32(node, "cpts_clock_mult", &prop))
-		cpts->cc.mult = prop;
+		cpts->tc.cc.mult = prop;
 
 	if (!of_property_read_u32(node, "cpts_clock_shift", &prop))
-		cpts->cc.shift = prop;
+		cpts->tc.cc.shift = prop;
 
-	if ((cpts->cc.mult && !cpts->cc.shift) ||
-	    (!cpts->cc.mult && cpts->cc.shift))
+	if ((cpts->tc.cc.mult && !cpts->tc.cc.shift) ||
+	    (!cpts->tc.cc.mult && cpts->tc.cc.shift))
 		goto of_error;
 
 	return 0;
@@ -569,15 +571,15 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs,
 
 	clk_prepare(cpts->refclk);
 
-	cpts->cc.read = cpts_systim_read;
-	cpts->cc.mask = CLOCKSOURCE_MASK(32);
+	cpts->tc.cc.read = cpts_systim_read;
+	cpts->tc.cc.mask = CLOCKSOURCE_MASK(32);
 	cpts->info = cpts_info;
 
 	cpts_calc_mult_shift(cpts);
-	/* save cc.mult original value as it can be modified
+	/* save tc.cc.mult original value as it can be modified
 	 * by cpts_ptp_adjfreq().
 	 */
-	cpts->cc_mult = cpts->cc.mult;
+	cpts->cc_mult = cpts->tc.cc.mult;
 
 	return cpts;
 }
diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h
index 73d73fa..a7174eb 100644
--- a/drivers/net/ethernet/ti/cpts.h
+++ b/drivers/net/ethernet/ti/cpts.h
@@ -117,7 +117,6 @@ struct cpts {
 	struct ptp_clock *clock;
 	spinlock_t lock; /* protects time registers */
 	u32 cc_mult; /* for the nominal frequency */
-	struct cyclecounter cc;
 	struct timecounter tc;
 	int phc_index;
 	struct clk *refclk;
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index a886b51..c81c615 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -780,7 +780,6 @@ struct mlx5_pps {
 
 struct mlx5_clock {
 	rwlock_t                   lock;
-	struct cyclecounter        cycles;
 	struct timecounter         tc;
 	struct hwtstamp_config     hwtstamp_config;
 	u32                        nominal_c_mult;
diff --git a/include/linux/timecounter.h b/include/linux/timecounter.h
index 2496ad4..6daca06 100644
--- a/include/linux/timecounter.h
+++ b/include/linux/timecounter.h
@@ -62,7 +62,7 @@ struct cyclecounter {
  * @frac:		accumulated fractional nanoseconds
  */
 struct timecounter {
-	const struct cyclecounter *cc;
+	struct cyclecounter cc;
 	u64 cycle_last;
 	u64 nsec;
 	u64 mask;
@@ -98,7 +98,6 @@ static inline void timecounter_adjtime(struct timecounter *tc, s64 delta)
 /**
  * timecounter_init - initialize a time counter
  * @tc:			Pointer to time counter which is to be initialized/reset
- * @cc:			A cycle counter, ready to be used.
  * @start_tstamp:	Arbitrary initial time stamp.
  *
  * After this call the current cycle register (roughly) corresponds to
@@ -106,7 +105,6 @@ static inline void timecounter_adjtime(struct timecounter *tc, s64 delta)
  * the time stamp counter by the number of elapsed nanoseconds.
  */
 extern void timecounter_init(struct timecounter *tc,
-			     const struct cyclecounter *cc,
 			     u64 start_tstamp);
 
 /**
diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h
index 68169e3..3061f44 100644
--- a/include/sound/hdaudio.h
+++ b/include/sound/hdaudio.h
@@ -445,7 +445,6 @@ struct hdac_stream {
 	unsigned long start_wallclk;	/* start + minimum wallclk */
 	unsigned long period_wallclk;	/* wallclk for period */
 	struct timecounter  tc;
-	struct cyclecounter cc;
 	int delay_negative_threshold;
 
 	struct list_head list;
diff --git a/kernel/time/timecounter.c b/kernel/time/timecounter.c
index 8afd789..7919acb 100644
--- a/kernel/time/timecounter.c
+++ b/kernel/time/timecounter.c
@@ -18,11 +18,10 @@
 #include <linux/export.h>
 #include <linux/timecounter.h>
 
-void timecounter_init(struct timecounter *tc,
-		      const struct cyclecounter *cc,
-		      u64 start_tstamp)
+void timecounter_init(struct timecounter *tc, u64 start_tstamp)
 {
-	tc->cc = cc;
+	struct cyclecounter *cc = &tc->cc;
+
 	tc->cycle_last = cc->read(cc);
 	tc->nsec = start_tstamp;
 	tc->mask = (1ULL << cc->shift) - 1;
@@ -43,17 +42,18 @@ void timecounter_init(struct timecounter *tc,
  */
 static u64 timecounter_read_delta(struct timecounter *tc)
 {
+	struct cyclecounter *cc = &tc->cc;
 	u64 cycle_now, cycle_delta;
 	u64 ns_offset;
 
 	/* read cycle counter: */
-	cycle_now = tc->cc->read(tc->cc);
+	cycle_now = cc->read(cc);
 
 	/* calculate the delta since the last timecounter_read_delta(): */
-	cycle_delta = (cycle_now - tc->cycle_last) & tc->cc->mask;
+	cycle_delta = (cycle_now - tc->cycle_last) & cc->mask;
 
 	/* convert to nanoseconds: */
-	ns_offset = cyclecounter_cyc2ns(tc->cc, cycle_delta,
+	ns_offset = cyclecounter_cyc2ns(cc, cycle_delta,
 					tc->mask, &tc->frac);
 
 	/* update time stamp of timecounter_read_delta() call: */
@@ -89,10 +89,10 @@ static u64 cc_cyc2ns_backwards(const struct cyclecounter *cc,
 	return ns;
 }
 
-u64 timecounter_cyc2time(struct timecounter *tc,
-			 u64 cycle_tstamp)
+u64 timecounter_cyc2time(struct timecounter *tc, u64 cycle_tstamp)
 {
-	u64 delta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;
+	struct cyclecounter *cc = &tc->cc;
+	u64 delta = (cycle_tstamp - tc->cycle_last) & cc->mask;
 	u64 nsec = tc->nsec, frac = tc->frac;
 
 	/*
@@ -100,11 +100,11 @@ u64 timecounter_cyc2time(struct timecounter *tc,
 	 * than tc->cycle_last, detect when it is too far in the
 	 * future and treat it as old time stamp instead.
 	 */
-	if (delta > tc->cc->mask / 2) {
-		delta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;
-		nsec -= cc_cyc2ns_backwards(tc->cc, delta, tc->mask, frac);
+	if (delta > cc->mask / 2) {
+		delta = (tc->cycle_last - cycle_tstamp) & cc->mask;
+		nsec -= cc_cyc2ns_backwards(cc, delta, tc->mask, frac);
 	} else {
-		nsec += cyclecounter_cyc2ns(tc->cc, delta, tc->mask, &frac);
+		nsec += cyclecounter_cyc2ns(cc, delta, tc->mask, &frac);
 	}
 
 	return nsec;
diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c
index e1472c7..9426c1a 100644
--- a/sound/hda/hdac_stream.c
+++ b/sound/hda/hdac_stream.c
@@ -467,7 +467,8 @@ int snd_hdac_stream_set_params(struct hdac_stream *azx_dev,
 
 static u64 azx_cc_read(const struct cyclecounter *cc)
 {
-	struct hdac_stream *azx_dev = container_of(cc, struct hdac_stream, cc);
+	struct hdac_stream *azx_dev = container_of(cc, struct hdac_stream,
+						   tc.cc);
 
 	return snd_hdac_chip_readl(azx_dev->bus, WALLCLK);
 }
@@ -476,7 +477,7 @@ static void azx_timecounter_init(struct hdac_stream *azx_dev,
 				 bool force, u64 last)
 {
 	struct timecounter *tc = &azx_dev->tc;
-	struct cyclecounter *cc = &azx_dev->cc;
+	struct cyclecounter *cc = &azx_dev->tc.cc;
 	u64 nsec;
 
 	cc->read = azx_cc_read;
@@ -496,7 +497,7 @@ static void azx_timecounter_init(struct hdac_stream *azx_dev,
 	cc->shift = 0;
 
 	nsec = 0; /* audio time is elapsed time since trigger */
-	timecounter_init(tc, cc, nsec);
+	timecounter_init(tc, nsec);
 	if (force) {
 		/*
 		 * force timecounter to use predefined value,
diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
index f9555b1..5683c0c 100644
--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -53,7 +53,7 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level,
 
 u64 kvm_phys_timer_read(void)
 {
-	return timecounter->cc->read(timecounter->cc);
+	return timecounter->cc.read(&timecounter->cc);
 }
 
 static void soft_timer_start(struct hrtimer *hrt, u64 ns)
@@ -138,7 +138,7 @@ static u64 kvm_timer_compute_delta(struct arch_timer_context *timer_ctx)
 	if (now < cval) {
 		u64 ns;
 
-		ns = cyclecounter_cyc2ns(timecounter->cc,
+		ns = cyclecounter_cyc2ns(&timecounter->cc,
 					 cval - now,
 					 timecounter->mask,
 					 &timecounter->frac);
@@ -728,7 +728,7 @@ int kvm_timer_hyp_init(void)
 	info = arch_timer_get_kvm_info();
 	timecounter = &info->timecounter;
 
-	if (!timecounter->cc) {
+	if (!timecounter->cc.mask) {
 		kvm_err("kvm_arch_timer: uninitialized timecounter\n");
 		return -ENODEV;
 	}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 02/27] timecounter: Introduce timecounter_initialize to update timecounter and cyclecounter
  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
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 03/27] microblaze: Use timecounter_initialize interface Sagar Arun Kamble
                   ` (24 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Chris Wilson, John Stultz,
	Thomas Gleixner, Stephen Boyd

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

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 03/27] microblaze: Use timecounter_initialize interface
  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
  2017-12-15  7:38 ` [PATCH 02/27] timecounter: Introduce timecounter_initialize to update timecounter and cyclecounter Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 04/27] clocksource/arm_arch_timer: " Sagar Arun Kamble
                   ` (23 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Michal Simek, Daniel Lezcano,
	Neil Armstrong, Nicolai Stange, Arnd Bergmann, Rob Herring,
	Thomas Gleixner

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update xilinx_tc init with
this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Neil Armstrong <narmstrong@baylibre.com>
Cc: Nicolai Stange <nicstange@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
---
 arch/microblaze/kernel/timer.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/arch/microblaze/kernel/timer.c b/arch/microblaze/kernel/timer.c
index b7f89e9..b32a896 100644
--- a/arch/microblaze/kernel/timer.c
+++ b/arch/microblaze/kernel/timer.c
@@ -204,20 +204,21 @@ static u64 xilinx_cc_read(const struct cyclecounter *cc)
 	return xilinx_read(NULL);
 }
 
-static struct timecounter xilinx_tc = {
-	.cc.read = xilinx_cc_read,
-	.cc.mask = CLOCKSOURCE_MASK(32),
-	.cc.mult = 0,
-	.cc.shift = 8,
-};
+static struct timecounter xilinx_tc;
 
 static int __init init_xilinx_timecounter(void)
 {
-	struct cyclecounter *cc = &xilinx_tc.cc;
+	u32 mult = 0;
+	u32 shift = 8;
 
-	cc->mult = div_sc(timer_clock_freq, NSEC_PER_SEC, cc->shift);
+	mult = div_sc(timer_clock_freq, NSEC_PER_SEC, shift);
 
-	timecounter_init(&xilinx_tc, sched_clock());
+	timecounter_initialize(&xilinx_tc,
+			       xilinx_cc_read,
+			       CLOCKSOURCE_MASK(32),
+			       mult,
+			       shift,
+			       sched_clock());
 
 	return 0;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 04/27] clocksource/arm_arch_timer: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (2 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 03/27] microblaze: Use timecounter_initialize interface Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 05/27] amd-xgbe: " Sagar Arun Kamble
                   ` (22 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Mark Rutland, Marc Zyngier,
	Daniel Lezcano, Thomas Gleixner, linux-arm-kernel

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update arch_timer_kvm_info
timecounter init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/clocksource/arm_arch_timer.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 31543e5..d96393f 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -910,10 +910,7 @@ static u64 arch_counter_get_cntvct_mem(void)
 	return ((u64) vct_hi << 32) | vct_lo;
 }
 
-static struct arch_timer_kvm_info arch_timer_kvm_info = {
-	.timecounter.cc.read = arch_counter_read_cc,
-	.timecounter.cc.mask = CLOCKSOURCE_MASK(56),
-};
+static struct arch_timer_kvm_info arch_timer_kvm_info;
 
 struct arch_timer_kvm_info *arch_timer_get_kvm_info(void)
 {
@@ -923,7 +920,6 @@ struct arch_timer_kvm_info *arch_timer_get_kvm_info(void)
 static void __init arch_counter_register(unsigned type)
 {
 	u64 start_count;
-	struct cyclecounter *cc = &arch_timer_kvm_info.timecounter.cc;
 
 	/* Register the CP15 based counter if we have one */
 	if (type & ARCH_TIMER_TYPE_CP15) {
@@ -943,9 +939,12 @@ static void __init arch_counter_register(unsigned type)
 	start_count = arch_timer_read_counter();
 	clocksource_register_hz(&clocksource_counter, arch_timer_rate);
 
-	cc->mult = clocksource_counter.mult;
-	cc->shift = clocksource_counter.shift;
-	timecounter_init(&arch_timer_kvm_info.timecounter, start_count);
+	timecounter_initialize(&arch_timer_kvm_info.timecounter,
+			       arch_counter_read_cc,
+			       CLOCKSOURCE_MASK(56),
+			       clocksource_counter.mult,
+			       clocksource_counter.shift,
+			       start_count);
 
 	/* 56 bits minimum, so we assume worst case rollover */
 	sched_clock_register(arch_timer_read_counter, 56, arch_timer_rate);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 05/27] amd-xgbe: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (3 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 04/27] clocksource/arm_arch_timer: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 06/27] bnx2x: " Sagar Arun Kamble
                   ` (21 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel; +Cc: Sagar Arun Kamble, Richard Cochran, Tom Lendacky, netdev

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update xgbe tstamp_tc
timecounter init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
index 5ea4edf..486437b 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
@@ -228,7 +228,6 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
 {
 	struct ptp_clock_info *info = &pdata->ptp_clock_info;
 	struct ptp_clock *clock;
-	struct cyclecounter *cc = &pdata->tstamp_tc.cc;
 	u64 dividend;
 
 	snprintf(info->name, sizeof(info->name), "%s",
@@ -258,12 +257,12 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
 	pdata->tstamp_addend = div_u64(dividend, pdata->ptpclk_rate);
 
 	/* Setup the timecounter */
-	cc->read = xgbe_cc_read;
-	cc->mask = CLOCKSOURCE_MASK(64);
-	cc->mult = 1;
-	cc->shift = 0;
-
-	timecounter_init(&pdata->tstamp_tc, ktime_to_ns(ktime_get_real()));
+	timecounter_initialize(&pdata->tstamp_tc,
+			       xgbe_cc_read,
+			       CLOCKSOURCE_MASK(64),
+			       1,
+			       0,
+			       ktime_to_ns(ktime_get_real()));
 
 	/* Disable all timestamping to start */
 	XGMAC_IOWRITE(pdata, MAC_TSCR, 0);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 06/27] bnx2x: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (4 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 05/27] amd-xgbe: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 07/27] fec: " Sagar Arun Kamble
                   ` (20 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Ariel Elior,
	everest-linux-l2, netdev

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update bnx2x timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Ariel Elior <ariel.elior@cavium.com>
Cc: everest-linux-l2@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 83624ad..1e10a81 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -15269,15 +15269,6 @@ static u64 bnx2x_cyclecounter_read(const struct cyclecounter *cc)
 	return phc_cycles;
 }
 
-static void bnx2x_init_cyclecounter(struct cyclecounter *cc)
-{
-	memset(cc, 0, sizeof(*cc));
-	cc->read = bnx2x_cyclecounter_read;
-	cc->mask = CYCLECOUNTER_MASK(64);
-	cc->shift = 0;
-	cc->mult = 1;
-}
-
 static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
 {
 	struct bnx2x_func_state_params func_params = {NULL};
@@ -15511,9 +15502,12 @@ void bnx2x_init_ptp(struct bnx2x *bp)
 	 * unload / load (e.g. MTU change) while it is running.
 	 */
 	if (!bp->timecounter_init_done) {
-		bnx2x_init_cyclecounter(&bp->timecounter.cc);
-		timecounter_init(&bp->timecounter,
-				 ktime_to_ns(ktime_get_real()));
+		timecounter_initialize(&bp->timecounter,
+				       bnx2x_cyclecounter_read,
+				       CYCLECOUNTER_MASK(64),
+				       1,
+				       0,
+				       ktime_to_ns(ktime_get_real()));
 		bp->timecounter_init_done = 1;
 	}
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 07/27] fec: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (5 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 06/27] bnx2x: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 08/27] e1000e: " Sagar Arun Kamble
                   ` (19 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel; +Cc: Sagar Arun Kamble, Richard Cochran, Fugang Duan, netdev

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update fec ethernet
timecounter init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Fugang Duan <fugang.duan@nxp.com>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/freescale/fec_ptp.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index b1261d1..1ba7216 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -278,14 +278,13 @@ void fec_ptp_start_cyclecounter(struct net_device *ndev)
 	writel(FEC_T_CTRL_ENABLE | FEC_T_CTRL_PERIOD_RST,
 		fep->hwp + FEC_ATIME_CTRL);
 
-	memset(&fep->tc.cc, 0, sizeof(fep->tc.cc));
-	fep->tc.cc.read = fec_ptp_read;
-	fep->tc.cc.mask = CLOCKSOURCE_MASK(31);
-	fep->tc.cc.shift = 31;
-	fep->tc.cc.mult = FEC_CC_MULT;
-
-	/* reset the ns time counter */
-	timecounter_init(&fep->tc, ktime_to_ns(ktime_get_real()));
+	/* Initialize the ns time counter */
+	timecounter_initialize(&fep->tc,
+			       fec_ptp_read,
+			       CLOCKSOURCE_MASK(31),
+			       FEC_CC_MULT,
+			       31,
+			       ktime_to_ns(ktime_get_real()));
 
 	spin_unlock_irqrestore(&fep->tmreg_lock, flags);
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 08/27] e1000e: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (6 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 07/27] fec: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` 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
                   ` (18 subsequent siblings)
  26 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Jeff Kirsher,
	intel-wired-lan, netdev

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update e1000e timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/intel/e1000e/e1000.h  |  4 ++++
 drivers/net/ethernet/intel/e1000e/netdev.c | 31 +++++++++++++++++-------------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
index b59f82a..d6b0e59 100644
--- a/drivers/net/ethernet/intel/e1000e/e1000.h
+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
@@ -341,6 +341,10 @@ struct e1000_adapter {
 	struct work_struct tx_hwtstamp_work;
 	spinlock_t systim_lock;	/* protects SYSTIML/H regsters */
 	struct timecounter tc;
+	u64 (*cc_read)(const struct cyclecounter *cc);
+	u64 cc_mask;
+	u32 cc_mult;
+	u32 cc_shift;
 	struct ptp_clock *ptp_clock;
 	struct ptp_clock_info ptp_clock_info;
 	struct pm_qos_request pm_qos_req;
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
index c9f7ba3..6be1327 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -3536,7 +3536,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 		incperiod = INCPERIOD_96MHZ;
 		incvalue = INCVALUE_96MHZ;
 		shift = INCVALUE_SHIFT_96MHZ;
-		adapter->tc.cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
+		adapter->cc_shift = shift + INCPERIOD_SHIFT_96MHZ;
 		break;
 	case e1000_pch_lpt:
 		if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
@@ -3544,13 +3544,13 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 			incperiod = INCPERIOD_96MHZ;
 			incvalue = INCVALUE_96MHZ;
 			shift = INCVALUE_SHIFT_96MHZ;
-			adapter->tc.cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
+			adapter->cc_shift = shift + INCPERIOD_SHIFT_96MHZ;
 		} else {
 			/* Stable 25MHz frequency */
 			incperiod = INCPERIOD_25MHZ;
 			incvalue = INCVALUE_25MHZ;
 			shift = INCVALUE_SHIFT_25MHZ;
-			adapter->tc.cc.shift = shift;
+			adapter->cc_shift = shift;
 		}
 		break;
 	case e1000_pch_spt:
@@ -3559,7 +3559,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 			incperiod = INCPERIOD_24MHZ;
 			incvalue = INCVALUE_24MHZ;
 			shift = INCVALUE_SHIFT_24MHZ;
-			adapter->tc.cc.shift = shift;
+			adapter->cc_shift = shift;
 			break;
 		}
 		return -EINVAL;
@@ -3569,13 +3569,13 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 			incperiod = INCPERIOD_24MHZ;
 			incvalue = INCVALUE_24MHZ;
 			shift = INCVALUE_SHIFT_24MHZ;
-			adapter->tc.cc.shift = shift;
+			adapter->cc_shift = shift;
 		} else {
 			/* Stable 38400KHz frequency */
 			incperiod = INCPERIOD_38400KHZ;
 			incvalue = INCVALUE_38400KHZ;
 			shift = INCVALUE_SHIFT_38400KHZ;
-			adapter->tc.cc.shift = shift;
+			adapter->cc_shift = shift;
 		}
 		break;
 	case e1000_82574:
@@ -3584,7 +3584,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
 		incperiod = INCPERIOD_25MHZ;
 		incvalue = INCVALUE_25MHZ;
 		shift = INCVALUE_SHIFT_25MHZ;
-		adapter->tc.cc.shift = shift;
+		adapter->cc_shift = shift;
 		break;
 	default:
 		return -EINVAL;
@@ -3953,9 +3953,14 @@ static void e1000e_systim_reset(struct e1000_adapter *adapter)
 		return;
 	}
 
-	/* reset the systim ns time counter */
+	/* reinitialize the systim ns time counter */
 	spin_lock_irqsave(&adapter->systim_lock, flags);
-	timecounter_init(&adapter->tc, ktime_to_ns(ktime_get_real()));
+	timecounter_initialize(&adapter->tc,
+			       adapter->cc_read,
+			       adapter->cc_mask,
+			       adapter->cc_mult,
+			       adapter->cc_shift,
+			       ktime_to_ns(ktime_get_real()));
 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
 
 	/* restore the previous hwtstamp configuration settings */
@@ -4448,10 +4453,10 @@ static int e1000_sw_init(struct e1000_adapter *adapter)
 
 	/* Setup hardware time stamping cyclecounter */
 	if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
-		adapter->tc.cc.read = e1000e_cyclecounter_read;
-		adapter->tc.cc.mask = CYCLECOUNTER_MASK(64);
-		adapter->tc.cc.mult = 1;
-		/* tc.cc.shift set in e1000e_get_base_tininca() */
+		adapter->cc_read = e1000e_cyclecounter_read;
+		adapter->cc_mask = CYCLECOUNTER_MASK(64);
+		adapter->cc_mult = 1;
+		/* cc_shift set in e1000e_get_base_tininca() */
 
 		spin_lock_init(&adapter->systim_lock);
 		INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 09/27] igb: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (7 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 08/27] e1000e: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` 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
                   ` (17 subsequent siblings)
  26 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Jeff Kirsher,
	intel-wired-lan, netdev

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update igb ptp timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/intel/igb/igb.h     |  4 ++++
 drivers/net/ethernet/intel/igb/igb_ptp.c | 23 ++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
index 4eac4f2..4ef5632 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -566,6 +566,10 @@ struct igb_adapter {
 	unsigned int ptp_flags;
 	spinlock_t tmreg_lock;
 	struct timecounter tc;
+	u64 (*cc_read)(const struct cyclecounter *cc);
+	u64 cc_mask;
+	u32 cc_mult;
+	u32 cc_shift;
 	u32 tx_hwtstamp_timeouts;
 	u32 tx_hwtstamp_skipped;
 	u32 rx_hwtstamp_cleared;
diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index 0745eff..f6c1a8d 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -1126,10 +1126,10 @@ void igb_ptp_init(struct igb_adapter *adapter)
 		adapter->ptp_caps.gettime64 = igb_ptp_gettime_82576;
 		adapter->ptp_caps.settime64 = igb_ptp_settime_82576;
 		adapter->ptp_caps.enable = igb_ptp_feature_enable;
-		adapter->tc.cc.read = igb_ptp_read_82576;
-		adapter->tc.cc.mask = CYCLECOUNTER_MASK(64);
-		adapter->tc.cc.mult = 1;
-		adapter->tc.cc.shift = IGB_82576_TSYNC_SHIFT;
+		adapter->cc_read = igb_ptp_read_82576;
+		adapter->cc_mask = CYCLECOUNTER_MASK(64);
+		adapter->cc_mult = 1;
+		adapter->cc_shift = IGB_82576_TSYNC_SHIFT;
 		adapter->ptp_flags |= IGB_PTP_OVERFLOW_CHECK;
 		break;
 	case e1000_82580:
@@ -1145,10 +1145,10 @@ void igb_ptp_init(struct igb_adapter *adapter)
 		adapter->ptp_caps.gettime64 = igb_ptp_gettime_82576;
 		adapter->ptp_caps.settime64 = igb_ptp_settime_82576;
 		adapter->ptp_caps.enable = igb_ptp_feature_enable;
-		adapter->tc.cc.read = igb_ptp_read_82580;
-		adapter->tc.cc.mask = CYCLECOUNTER_MASK(IGB_NBITS_82580);
-		adapter->tc.cc.mult = 1;
-		adapter->tc.cc.shift = 0;
+		adapter->cc_read = igb_ptp_read_82580;
+		adapter->cc_mask = CYCLECOUNTER_MASK(IGB_NBITS_82580);
+		adapter->cc_mult = 1;
+		adapter->cc_shift = 0;
 		adapter->ptp_flags |= IGB_PTP_OVERFLOW_CHECK;
 		break;
 	case e1000_i210:
@@ -1289,7 +1289,12 @@ void igb_ptp_reset(struct igb_adapter *adapter)
 
 		igb_ptp_write_i210(adapter, &ts);
 	} else {
-		timecounter_init(&adapter->tc, ktime_to_ns(ktime_get_real()));
+		timecounter_initialize(&adapter->tc,
+				       adapter->cc_read,
+				       adapter->cc_mask,
+				       adapter->cc_mult,
+				       adapter->cc_shift,
+				       ktime_to_ns(ktime_get_real()));
 	}
 out:
 	spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 10/27] ixgbe: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (8 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 09/27] igb: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 11/27] net/mlx4: " Sagar Arun Kamble
                   ` (16 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Jeff Kirsher,
	intel-wired-lan, netdev

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update ixgbe ptp timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h      |  6 +++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  4 +--
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c  | 45 +++++++++++++++------------
 3 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
index 5c391a0..67e8b5c 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
@@ -739,6 +739,10 @@ struct ixgbe_adapter {
 	unsigned long last_rx_timestamp;
 	spinlock_t tmreg_lock;
 	struct timecounter hw_tc;
+	u64 (*cc_read)(const struct cyclecounter *cc);
+	u64 cc_mask;
+	u32 cc_mult;
+	u32 cc_shift;
 	u32 base_incval;
 	u32 tx_hwtstamp_timeouts;
 	u32 tx_hwtstamp_skipped;
@@ -994,7 +998,7 @@ static inline void ixgbe_ptp_rx_hwtstamp(struct ixgbe_ring *rx_ring,
 
 int ixgbe_ptp_set_ts_config(struct ixgbe_adapter *adapter, struct ifreq *ifr);
 int ixgbe_ptp_get_ts_config(struct ixgbe_adapter *adapter, struct ifreq *ifr);
-void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter);
+void ixgbe_ptp_start_timecounter(struct ixgbe_adapter *adapter);
 void ixgbe_ptp_reset(struct ixgbe_adapter *adapter);
 void ixgbe_ptp_check_pps_event(struct ixgbe_adapter *adapter);
 #ifdef CONFIG_PCI_IOV
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 62a1891..86a337b 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -7332,7 +7332,7 @@ static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
 	adapter->last_rx_ptp_check = jiffies;
 
 	if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
-		ixgbe_ptp_start_cyclecounter(adapter);
+		ixgbe_ptp_start_timecounter(adapter);
 
 	switch (link_speed) {
 	case IXGBE_LINK_SPEED_10GB_FULL:
@@ -7400,7 +7400,7 @@ static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
 		adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
 
 	if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
-		ixgbe_ptp_start_cyclecounter(adapter);
+		ixgbe_ptp_start_timecounter(adapter);
 
 	e_info(drv, "NIC Link is Down\n");
 	netif_carrier_off(netdev);
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index 6e9f2c0..073c1ef 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -1075,7 +1075,8 @@ static void ixgbe_ptp_link_speed_adjust(struct ixgbe_adapter *adapter,
 }
 
 /**
- * ixgbe_ptp_start_cyclecounter - create the cycle counter from hw
+ * ixgbe_ptp_start_timecounter - create the cycle counter from hw and
+ *				 initialize corresponding timecounter.
  * @adapter: pointer to the adapter structure
  *
  * This function should be called to set the proper values for the TIMINCA
@@ -1084,10 +1085,9 @@ static void ixgbe_ptp_link_speed_adjust(struct ixgbe_adapter *adapter,
  * structure. It should be called whenever a new TIMINCA value is necessary,
  * such as during initialization or when the link speed changes.
  */
-void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
+void ixgbe_ptp_start_timecounter(struct ixgbe_adapter *adapter)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
-	struct cyclecounter cc;
 	unsigned long flags;
 	u32 incval = 0;
 	u32 tsauxc = 0;
@@ -1104,9 +1104,9 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
 	 * proper fix to this problem would require modification of the
 	 * timecounter delta calculations.
 	 */
-	cc.mask = CLOCKSOURCE_MASK(64);
-	cc.mult = 1;
-	cc.shift = 0;
+	adapter->cc_mask = CLOCKSOURCE_MASK(64);
+	adapter->cc_mult = 1;
+	adapter->cc_shift = 0;
 
 	switch (hw->mac.type) {
 	case ixgbe_mac_X550EM_x:
@@ -1118,13 +1118,13 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
 		 */
 		fuse0 = IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0));
 		if (!(fuse0 & IXGBE_FUSES0_300MHZ)) {
-			cc.mult = 3;
-			cc.shift = 2;
+			adapter->cc_mult = 3;
+			adapter->cc_shift = 2;
 		}
 		/* fallthrough */
 	case ixgbe_mac_x550em_a:
 	case ixgbe_mac_X550:
-		cc.read = ixgbe_ptp_read_X550;
+		adapter->cc_read = ixgbe_ptp_read_X550;
 
 		/* enable SYSTIME counter */
 		IXGBE_WRITE_REG(hw, IXGBE_SYSTIMR, 0);
@@ -1139,17 +1139,21 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
 		IXGBE_WRITE_FLUSH(hw);
 		break;
 	case ixgbe_mac_X540:
-		cc.read = ixgbe_ptp_read_82599;
+		adapter->cc_read = ixgbe_ptp_read_82599;
 
-		ixgbe_ptp_link_speed_adjust(adapter, &cc.shift, &incval);
+		ixgbe_ptp_link_speed_adjust(adapter,
+					    &adapter->cc_shift,
+					    &incval);
 		IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, incval);
 		break;
 	case ixgbe_mac_82599EB:
-		cc.read = ixgbe_ptp_read_82599;
+		adapter->cc_read = ixgbe_ptp_read_82599;
 
-		ixgbe_ptp_link_speed_adjust(adapter, &cc.shift, &incval);
+		ixgbe_ptp_link_speed_adjust(adapter,
+					    &adapter->cc_shift,
+					    &incval);
 		incval >>= IXGBE_INCVAL_SHIFT_82599;
-		cc.shift -= IXGBE_INCVAL_SHIFT_82599;
+		adapter->cc_shift -= IXGBE_INCVAL_SHIFT_82599;
 		IXGBE_WRITE_REG(hw, IXGBE_TIMINCA,
 				BIT(IXGBE_INCPER_SHIFT_82599) | incval);
 		break;
@@ -1164,7 +1168,12 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
 
 	/* need lock to prevent incorrect read while modifying cyclecounter */
 	spin_lock_irqsave(&adapter->tmreg_lock, flags);
-	memcpy(&adapter->hw_tc.cc, &cc, sizeof(adapter->hw_tc.cc));
+	timecounter_initialize(&adapter->tc,
+			       adapter->cc_read,
+			       adapter->cc_mask,
+			       adapter->cc_mult,
+			       adapter->cc_shift,
+			       ktime_to_ns(ktime_get_real()));
 	spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
 }
 
@@ -1192,11 +1201,7 @@ void ixgbe_ptp_reset(struct ixgbe_adapter *adapter)
 	if (hw->mac.type == ixgbe_mac_82598EB)
 		return;
 
-	ixgbe_ptp_start_cyclecounter(adapter);
-
-	spin_lock_irqsave(&adapter->tmreg_lock, flags);
-	timecounter_init(&adapter->hw_tc, ktime_to_ns(ktime_get_real()));
-	spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
+	ixgbe_ptp_start_timecounter(adapter);
 
 	adapter->last_overflow_check = jiffies;
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 11/27] net/mlx4: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (9 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 10/27] ixgbe: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 12/27] net/mlx5: " Sagar Arun Kamble
                   ` (15 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Tariq Toukan, netdev, linux-rdma

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update mlx4 timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Tariq Toukan <tariqt@mellanox.com>
Cc: netdev@vger.kernel.org
Cc: linux-rdma@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/mellanox/mlx4/en_clock.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
index 35987b5..dd736cc 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
@@ -264,6 +264,7 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
 {
 	struct mlx4_dev *dev = mdev->dev;
 	unsigned long flags;
+	u32 mult, shift;
 
 	/* mlx4_en_init_timestamp is called for each netdev.
 	 * mdev->ptp_clock is common for all ports, skip initialization if
@@ -274,17 +275,17 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
 
 	seqlock_init(&mdev->clock_lock);
 
-	memset(&mdev->clock.cc, 0, sizeof(mdev->clock.cc));
-	mdev->clock.cc.read = mlx4_en_read_clock;
-	mdev->clock.cc.mask = CLOCKSOURCE_MASK(48);
-	mdev->clock.cc.shift = freq_to_shift(dev->caps.hca_core_clock);
-	mdev->clock.cc.mult =
-		clocksource_khz2mult(1000 * dev->caps.hca_core_clock,
-				     mdev->clock.cc.shift);
+	shift = freq_to_shift(dev->caps.hca_core_clock);
+	mult = clocksource_khz2mult(1000 * dev->caps.hca_core_clock, shift);
 	mdev->nominal_c_mult = mdev->clock.cc.mult;
 
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
-	timecounter_init(&mdev->clock, ktime_to_ns(ktime_get_real()));
+	timecounter_initialize(&mdev->clock,
+			       mlx4_en_read_clock,
+			       CLOCKSOURCE_MASK(48),
+			       mult,
+			       shift,
+			       ktime_to_ns(ktime_get_real()));
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
 
 	/* Configure the PHC */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 12/27] net/mlx5: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (10 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 11/27] net/mlx4: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 13/27] qede: " Sagar Arun Kamble
                   ` (14 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Saeed Mahameed, Matan Barak,
	Leon Romanovsky, Eugenia Emantayev, Eitan Rabin, Feras Daoud,
	Miroslav Lichvar, netdev, linux-rdma

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update mlx5 timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Saeed Mahameed <saeedm@mellanox.com>
Cc: Matan Barak <matanb@mellanox.com>
Cc: Leon Romanovsky <leonro@mellanox.com>
Cc: Eugenia Emantayev <eugenia@mellanox.com>
Cc: Eitan Rabin <rabin@mellanox.com>
Cc: Feras Daoud <ferasda@mellanox.com>
Cc: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: netdev@vger.kernel.org
Cc: linux-rdma@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
index 8cb6838..071f78a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
@@ -458,6 +458,7 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev)
 	u64 ns;
 	u64 frac = 0;
 	u32 dev_freq;
+	u32 mult, shift;
 
 	dev_freq = MLX5_CAP_GEN(mdev, device_frequency_khz);
 	if (!dev_freq) {
@@ -465,13 +466,16 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev)
 		return;
 	}
 	rwlock_init(&clock->lock);
-	cc->read = read_internal_timer;
-	cc->shift = MLX5_CYCLES_SHIFT;
-	cc->mult = clocksource_khz2mult(dev_freq, cc->shift);
-	clock->nominal_c_mult = cc->mult;
-	cc->mask = CLOCKSOURCE_MASK(41);
-
-	timecounter_init(&clock->tc, ktime_to_ns(ktime_get_real()));
+	shift = MLX5_CYCLES_SHIFT;
+	mult = clocksource_khz2mult(dev_freq, shift);
+	clock->nominal_c_mult = mult;
+
+	timecounter_initialize(&clock->tc,
+			       read_internal_timer,
+			       CLOCKSOURCE_MASK(41),
+			       mult,
+			       shift,
+			       ktime_to_ns(ktime_get_real()));
 
 	/* Calculate period in seconds to call the overflow watchdog - to make
 	 * sure counter is checked at least once every wrap around.
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 13/27] qede: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (11 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 12/27] net/mlx5: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 14/27] net: cpts: " Sagar Arun Kamble
                   ` (13 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Ariel Elior,
	everest-linux-l2, netdev

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update qede timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Ariel Elior <Ariel.Elior@cavium.com>
Cc: everest-linux-l2@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/qlogic/qede/qede_ptp.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qede/qede_ptp.c b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
index 95bb8a8..0d054dc 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ptp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
@@ -427,13 +427,12 @@ static int qede_ptp_init(struct qede_dev *edev, bool init_tc)
 	 * unload / load (e.g. MTU change) while it is running.
 	 */
 	if (init_tc) {
-		memset(&ptp->tc.cc, 0, sizeof(ptp->tc.cc));
-		ptp->tc.cc.read = qede_ptp_read_cc;
-		ptp->tc.cc.mask = CYCLECOUNTER_MASK(64);
-		ptp->tc.cc.shift = 0;
-		ptp->tc.cc.mult = 1;
-
-		timecounter_init(&ptp->tc, ktime_to_ns(ktime_get_real()));
+		timecounter_initialize(&ptp->tc,
+				       qede_ptp_read_cc,
+				       CYCLECOUNTER_MASK(64),
+				       1,
+				       0,
+				       ktime_to_ns(ktime_get_real()));
 	}
 
 	return rc;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 14/27] net: cpts: Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (12 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 13/27] qede: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 15/27] ALSA: hda - " Sagar Arun Kamble
                   ` (12 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, David S. Miller, Grygorii Strashko,
	Richard Cochran, Bhumika Goyal, Thomas Gleixner, Ivan Khoronzhuk,
	netdev

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update cpts timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Bhumika Goyal <bhumirks@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/ti/cpts.c | 29 +++++++++++++++++------------
 drivers/net/ethernet/ti/cpts.h |  3 +++
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index b8fe843..e6afc94 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -447,7 +447,12 @@ int cpts_register(struct cpts *cpts)
 	cpts_write32(cpts, CPTS_EN, control);
 	cpts_write32(cpts, TS_PEND_EN, int_enable);
 
-	timecounter_init(&cpts->tc, ktime_to_ns(ktime_get_real()));
+	timecounter_initialize(&cpts->tc,
+			       cpts_systim_read,
+			       cpts->mask,
+			       cpts->mult,
+			       cpts->shift,
+			       ktime_to_ns(ktime_get_real()));
 
 	cpts->clock = ptp_clock_register(&cpts->info, cpts->dev);
 	if (IS_ERR(cpts->clock)) {
@@ -484,7 +489,8 @@ void cpts_unregister(struct cpts *cpts)
 }
 EXPORT_SYMBOL_GPL(cpts_unregister);
 
-static void cpts_calc_mult_shift(struct cpts *cpts)
+static void cpts_calc_mult_shift(struct cpts *cpts, u64 mask,
+				 u32 *mult, u32 *shift)
 {
 	struct cyclecounter *cc = &cpts->tc.cc;
 	u64 frac, maxsec, ns;
@@ -495,7 +501,7 @@ static void cpts_calc_mult_shift(struct cpts *cpts)
 	/* Calc the maximum number of seconds which we can run before
 	 * wrapping around.
 	 */
-	maxsec = cc->mask;
+	maxsec = mask;
 	do_div(maxsec, freq);
 	/* limit conversation rate to 10 sec as higher values will produce
 	 * too small mult factors and so reduce the conversion accuracy
@@ -508,18 +514,18 @@ static void cpts_calc_mult_shift(struct cpts *cpts)
 	dev_info(cpts->dev, "cpts: overflow check period %lu (jiffies)\n",
 		 cpts->ov_check_period);
 
-	if (cc->mult || cc->shift)
+	if (*mult || *shift)
 		return;
 
-	clocks_calc_mult_shift(&cc->mult, &cc->shift,
+	clocks_calc_mult_shift(mult, shift,
 			       freq, NSEC_PER_SEC, maxsec);
 
 	frac = 0;
-	ns = cyclecounter_cyc2ns(cc, freq, cc->mask, &frac);
+	ns = cyclecounter_cyc2ns(cc, freq, mask, &frac);
 
 	dev_info(cpts->dev,
 		 "CPTS: ref_clk_freq:%u calc_mult:%u calc_shift:%u error:%lld nsec/sec\n",
-		 freq, cc->mult, cc->shift,
+		 freq, *mult, *shift,
 		 (ns - NSEC_PER_SEC));
 }
 
@@ -571,15 +577,14 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs,
 
 	clk_prepare(cpts->refclk);
 
-	cpts->tc.cc.read = cpts_systim_read;
-	cpts->tc.cc.mask = CLOCKSOURCE_MASK(32);
+	cpts->mask = CLOCKSOURCE_MASK(32);
 	cpts->info = cpts_info;
 
-	cpts_calc_mult_shift(cpts);
-	/* save tc.cc.mult original value as it can be modified
+	cpts_calc_mult_shift(cpts, cpts->mask, &cpts->mult, &cpts->shift);
+	/* save mult original value as it can be modified
 	 * by cpts_ptp_adjfreq().
 	 */
-	cpts->cc_mult = cpts->tc.cc.mult;
+	cpts->cc_mult = cpts->mult;
 
 	return cpts;
 }
diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h
index a7174eb..da50d34 100644
--- a/drivers/net/ethernet/ti/cpts.h
+++ b/drivers/net/ethernet/ti/cpts.h
@@ -118,6 +118,9 @@ struct cpts {
 	spinlock_t lock; /* protects time registers */
 	u32 cc_mult; /* for the nominal frequency */
 	struct timecounter tc;
+	u64 mask;
+	u32 mult;
+	u32 shift;
 	int phc_index;
 	struct clk *refclk;
 	struct list_head events;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (13 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 14/27] net: cpts: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15 11:10   ` [alsa-devel] " Takashi Iwai
  2017-12-15  7:38 ` [PATCH 16/27] timecounter: Introduce timecounter_reset Sagar Arun Kamble
                   ` (11 subsequent siblings)
  26 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Jaroslav Kysela,
	Takashi Iwai, Thomas Gleixner, Vinod Koul, alsa-devel

With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update azx timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vinod Koul <vinod.koul@intel.com>
Cc: alsa-devel@alsa-project.org
Cc: linux-kernel@vger.kernel.org
---
 sound/hda/hdac_stream.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c
index 9426c1a..ad91dde 100644
--- a/sound/hda/hdac_stream.c
+++ b/sound/hda/hdac_stream.c
@@ -477,12 +477,8 @@ static void azx_timecounter_init(struct hdac_stream *azx_dev,
 				 bool force, u64 last)
 {
 	struct timecounter *tc = &azx_dev->tc;
-	struct cyclecounter *cc = &azx_dev->tc.cc;
 	u64 nsec;
 
-	cc->read = azx_cc_read;
-	cc->mask = CLOCKSOURCE_MASK(32);
-
 	/*
 	 * Converting from 24 MHz to ns means applying a 125/3 factor.
 	 * To avoid any saturation issues in intermediate operations,
@@ -493,11 +489,13 @@ static void azx_timecounter_init(struct hdac_stream *azx_dev,
 	 * overflows occur after about 4 hours or less, not a option.
 	 */
 
-	cc->mult = 125; /* saturation after 195 years */
-	cc->shift = 0;
-
 	nsec = 0; /* audio time is elapsed time since trigger */
-	timecounter_init(tc, nsec);
+	timecounter_initialize(tc,
+			       azx_cc_read,
+			       CLOCKSOURCE_MASK(32),
+			       125, /* saturation after 195 years */
+			       0,
+			       nsec);
 	if (force) {
 		/*
 		 * force timecounter to use predefined value,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 16/27] timecounter: Introduce timecounter_reset
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (14 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 15/27] ALSA: hda - " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 17/27] amd-xgbe: Use timecounter_reset interface Sagar Arun Kamble
                   ` (10 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Chris Wilson, John Stultz,
	Thomas Gleixner, Stephen Boyd

timecounter_init initializes the cyclecounter and sets the start time.
Sometimes drivers using timecounter just want to update start time.
This patch creates new function timecounter_reset that just resets the
timecounter start time and associated state.

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 | 17 +++++++++++++++--
 kernel/time/timecounter.c   |  9 +++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/include/linux/timecounter.h b/include/linux/timecounter.h
index 59d3fd7..e0fd741 100644
--- a/include/linux/timecounter.h
+++ b/include/linux/timecounter.h
@@ -98,7 +98,7 @@ static inline void timecounter_adjtime(struct timecounter *tc, s64 delta)
 
 /**
  * timecounter_init - initialize a time counter
- * @tc:			Pointer to time counter which is to be initialized/reset
+ * @tc:			Pointer to time counter which is to be initialized
  * @start_tstamp:	Arbitrary initial time stamp.
  *
  * After this call the current cycle register (roughly) corresponds to
@@ -131,8 +131,21 @@ extern void timecounter_initialize(struct timecounter *tc,
 				   u64 start_tstamp);
 
 /**
+ * timecounter_reset - reset a time counter
+ * @tc:			Pointer to time counter which is to be reset
+ * @start_tstamp:	Arbitrary initial time stamp.
+ *
+ * After this call the current cycle register (roughly) corresponds to
+ * the supplied time stamp. Every call to timecounter_read() increments
+ * the time stamp counter by the number of elapsed nanoseconds.
+ */
+extern void timecounter_reset(struct timecounter *tc,
+			      u64 start_tstamp);
+
+/**
  * timecounter_read - return nanoseconds elapsed since timecounter_init() or
- *                    timecounter_initialize() plus the initial time stamp
+ *                    timecounter_initialize() or timecounter_reset() 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 6d915752..3f62fe0 100644
--- a/kernel/time/timecounter.c
+++ b/kernel/time/timecounter.c
@@ -47,6 +47,15 @@ void timecounter_initialize(struct timecounter *tc,
 }
 EXPORT_SYMBOL_GPL(timecounter_initialize);
 
+void timecounter_reset(struct timecounter *tc,
+		       u64 start_tstamp)
+{
+	tc->cycle_last = tc->cc.read(&tc->cc);
+	tc->nsec = start_tstamp;
+	tc->frac = 0;
+}
+EXPORT_SYMBOL_GPL(timecounter_reset);
+
 /**
  * timecounter_read_delta - get nanoseconds since last call of this function
  * @tc:         Pointer to time counter
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 17/27] amd-xgbe: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (15 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 16/27] timecounter: Introduce timecounter_reset Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 18/27] bnx2x: " Sagar Arun Kamble
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel; +Cc: Sagar Arun Kamble, Richard Cochran, Tom Lendacky, netdev

With new interface timecounter_reset we can update the start time for
timecounter. Update xgbe_config_tstamp and xgbe_settime with this new
function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 4 ++--
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
index 5005c87..aee99de 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
@@ -1621,8 +1621,8 @@ static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
 	xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
 	xgbe_set_tstamp_time(pdata, 0, 0);
 
-	/* Initialize the timecounter */
-	timecounter_init(&pdata->tstamp_tc, ktime_to_ns(ktime_get_real()));
+	/* Reset the timecounter */
+	timecounter_reset(&pdata->tstamp_tc, ktime_to_ns(ktime_get_real()));
 
 	return 0;
 }
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
index 486437b..5fcde50 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
@@ -211,7 +211,7 @@ static int xgbe_settime(struct ptp_clock_info *info,
 
 	spin_lock_irqsave(&pdata->tstamp_lock, flags);
 
-	timecounter_init(&pdata->tstamp_tc, nsec);
+	timecounter_reset(&pdata->tstamp_tc, nsec);
 
 	spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 18/27] bnx2x: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (16 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 17/27] amd-xgbe: Use timecounter_reset interface Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-18 14:13   ` Kalluru, Sudarsana
  2017-12-15  7:38 ` [PATCH 19/27] net: fec: ptp: " Sagar Arun Kamble
                   ` (8 subsequent siblings)
  26 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Ariel Elior,
	everest-linux-l2, netdev

With new interface timecounter_reset we can update the start time for
timecounter. Update bnx2x_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Ariel Elior <ariel.elior@cavium.com>
Cc: everest-linux-l2@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 1e10a81..e30e736 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13849,8 +13849,8 @@ static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
 
 	DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
 
-	/* Re-init the timecounter */
-	timecounter_init(&bp->timecounter, ns);
+	/* Reset the timecounter */
+	timecounter_reset(&bp->timecounter, ns);
 
 	return 0;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 19/27] net: fec: ptp: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (17 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 18/27] bnx2x: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 20/27] e1000e: " Sagar Arun Kamble
                   ` (7 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel; +Cc: Sagar Arun Kamble, Richard Cochran, Fugang Duan, netdev

With new interface timecounter_reset we can update the start time for
timecounter. Update fec_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Fugang Duan <fugang.duan@nxp.com>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/freescale/fec_ptp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index 1ba7216..d03ea0e 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -419,7 +419,6 @@ static int fec_ptp_settime(struct ptp_clock_info *ptp,
 {
 	struct fec_enet_private *fep =
 	    container_of(ptp, struct fec_enet_private, ptp_caps);
-
 	u64 ns;
 	unsigned long flags;
 	u32 counter;
@@ -439,7 +438,7 @@ static int fec_ptp_settime(struct ptp_clock_info *ptp,
 
 	spin_lock_irqsave(&fep->tmreg_lock, flags);
 	writel(counter, fep->hwp + FEC_ATIME);
-	timecounter_init(&fep->tc, ns);
+	timecounter_reset(&fep->tc, ns);
 	spin_unlock_irqrestore(&fep->tmreg_lock, flags);
 	mutex_unlock(&fep->ptp_clk_mutex);
 	return 0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 20/27] e1000e: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (18 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 19/27] net: fec: ptp: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` 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
                   ` (6 subsequent siblings)
  26 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Jeff Kirsher,
	intel-wired-lan, netdev

With new interface timecounter_reset we can update the start time for
timecounter. Update e1000e_phc_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/intel/e1000e/ptp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/e1000e/ptp.c b/drivers/net/ethernet/intel/e1000e/ptp.c
index 03d5f2a..5b368aa 100644
--- a/drivers/net/ethernet/intel/e1000e/ptp.c
+++ b/drivers/net/ethernet/intel/e1000e/ptp.c
@@ -222,7 +222,7 @@ static int e1000e_phc_settime(struct ptp_clock_info *ptp,
 
 	/* reset the timecounter */
 	spin_lock_irqsave(&adapter->systim_lock, flags);
-	timecounter_init(&adapter->tc, ns);
+	timecounter_reset(&adapter->tc, ns);
 	spin_unlock_irqrestore(&adapter->systim_lock, flags);
 
 	return 0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 21/27] igb: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (19 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 20/27] e1000e: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` 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
                   ` (5 subsequent siblings)
  26 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Jeff Kirsher,
	intel-wired-lan, netdev

With new interface timecounter_reset we can update the start time for
timecounter. Update igb_ptp_settime_82576 with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/intel/igb/igb_ptp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index f6c1a8d..90344b2 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -330,7 +330,7 @@ static int igb_ptp_settime_82576(struct ptp_clock_info *ptp,
 
 	spin_lock_irqsave(&igb->tmreg_lock, flags);
 
-	timecounter_init(&igb->tc, ns);
+	timecounter_reset(&igb->tc, ns);
 
 	spin_unlock_irqrestore(&igb->tmreg_lock, flags);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 22/27] ixgbe: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (20 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 21/27] igb: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` 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
                   ` (4 subsequent siblings)
  26 siblings, 2 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Jeff Kirsher,
	intel-wired-lan, netdev

With new interface timecounter_reset we can update the start time for
timecounter. Update ixgbe_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index 073c1ef..35f85ef 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -508,7 +508,7 @@ static int ixgbe_ptp_settime(struct ptp_clock_info *ptp,
 
 	/* reset the timecounter */
 	spin_lock_irqsave(&adapter->tmreg_lock, flags);
-	timecounter_init(&adapter->hw_tc, ns);
+	timecounter_reset(&adapter->hw_tc, ns);
 	spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
 
 	if (adapter->ptp_setup_sdp)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 23/27] net/mlx4: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (21 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 22/27] ixgbe: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 24/27] net/mlx5: " Sagar Arun Kamble
                   ` (3 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Tariq Toukan, netdev, linux-rdma

With new interface timecounter_reset we can update the start time for
timecounter. Update mlx4_en_phc_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Tariq Toukan <tariqt@mellanox.com>
Cc: netdev@vger.kernel.org
Cc: linux-rdma@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/mellanox/mlx4/en_clock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
index dd736cc..bfed4ac 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
@@ -207,7 +207,7 @@ static int mlx4_en_phc_settime(struct ptp_clock_info *ptp,
 
 	/* reset the timecounter */
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
-	timecounter_init(&mdev->clock, ns);
+	timecounter_reset(&mdev->clock, ns);
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
 
 	return 0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 24/27] net/mlx5: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (22 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 23/27] net/mlx4: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 25/27] qede: " Sagar Arun Kamble
                   ` (2 subsequent siblings)
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Saeed Mahameed, Matan Barak,
	Leon Romanovsky, Eugenia Emantayev, Eitan Rabin, Feras Daoud,
	Tariq Toukan, Thomas Gleixner, netdev, linux-rdma

With new interface timecounter_reset we can update the start time for
timecounter. Update mlx5_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Saeed Mahameed <saeedm@mellanox.com>
Cc: Matan Barak <matanb@mellanox.com>
Cc: Leon Romanovsky <leonro@mellanox.com>
Cc: Eugenia Emantayev <eugenia@mellanox.com>
Cc: Eitan Rabin <rabin@mellanox.com>
Cc: Feras Daoud <ferasda@mellanox.com>
Cc: Tariq Toukan <tariqt@mellanox.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: netdev@vger.kernel.org
Cc: linux-rdma@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
index 071f78a..e490522 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
@@ -122,7 +122,7 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp,
 	unsigned long flags;
 
 	write_lock_irqsave(&clock->lock, flags);
-	timecounter_init(&clock->tc, ns);
+	timecounter_reset(&clock->tc, ns);
 	write_unlock_irqrestore(&clock->lock, flags);
 
 	return 0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 25/27] qede: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (23 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 24/27] net/mlx5: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` 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
  26 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, Ariel Elior,
	everest-linux-l2, netdev

With new interface timecounter_reset we can update the start time for
timecounter. Update qede_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Ariel Elior <Ariel.Elior@cavium.com>
Cc: everest-linux-l2@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/qlogic/qede/qede_ptp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qede/qede_ptp.c b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
index 0d054dc..c2de311 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ptp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
@@ -129,9 +129,9 @@ static int qede_ptp_settime(struct ptp_clock_info *info,
 
 	DP_VERBOSE(edev, QED_MSG_DEBUG, "PTP settime called, ns = %llu\n", ns);
 
-	/* Re-init the timecounter */
+	/* Reset the timecounter */
 	spin_lock_bh(&ptp->lock);
-	timecounter_init(&ptp->tc, ns);
+	timecounter_reset(&ptp->tc, ns);
 	spin_unlock_bh(&ptp->lock);
 
 	return 0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 26/27] net: cpts: Use timecounter_reset interface
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (24 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 25/27] qede: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  2017-12-15  7:38 ` [PATCH 27/27] timecounter: Remove timecounter_init Sagar Arun Kamble
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, David S. Miller, Grygorii Strashko,
	Bhumika Goyal, Richard Cochran, Thomas Gleixner, netdev

With new interface timecounter_reset we can update the start time for
timecounter. Update cpts_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Bhumika Goyal <bhumirks@gmail.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/ti/cpts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index e6afc94..41bac4d 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -268,7 +268,7 @@ static int cpts_ptp_settime(struct ptp_clock_info *ptp,
 	ns = timespec64_to_ns(ts);
 
 	spin_lock_irqsave(&cpts->lock, flags);
-	timecounter_init(&cpts->tc, ns);
+	timecounter_reset(&cpts->tc, ns);
 	spin_unlock_irqrestore(&cpts->lock, flags);
 
 	return 0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* [PATCH 27/27] timecounter: Remove timecounter_init
  2017-12-15  7:38 [PATCH 00/27] timecounter/cyclecounter struct/interface update Sagar Arun Kamble
                   ` (25 preceding siblings ...)
  2017-12-15  7:38 ` [PATCH 26/27] net: cpts: " Sagar Arun Kamble
@ 2017-12-15  7:38 ` Sagar Arun Kamble
  26 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-15  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sagar Arun Kamble, Richard Cochran, John Stultz, Thomas Gleixner,
	Stephen Boyd

With all timecounter users now initializing timecounter using
timecounter_initialize remove timecounter_init function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
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 | 20 +++-----------------
 kernel/time/timecounter.c   | 16 ++++------------
 2 files changed, 7 insertions(+), 29 deletions(-)

diff --git a/include/linux/timecounter.h b/include/linux/timecounter.h
index e0fd741..e3e1d1e 100644
--- a/include/linux/timecounter.h
+++ b/include/linux/timecounter.h
@@ -46,8 +46,7 @@ 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() when
- *	underlying cyclecounter is initialized, with timecounter_initialize() to
+ *	cycle counter wrap around. Initialize 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
@@ -97,18 +96,6 @@ static inline void timecounter_adjtime(struct timecounter *tc, s64 delta)
 }
 
 /**
- * timecounter_init - initialize a time counter
- * @tc:			Pointer to time counter which is to be initialized
- * @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_init(struct timecounter *tc,
-			     u64 start_tstamp);
-
-/**
  * timecounter_initialize - initialize a time counter and underlying
 			    cyclecounter
  * @tc:			Pointer to time counter which is to be initialized
@@ -143,9 +130,8 @@ extern void timecounter_reset(struct timecounter *tc,
 			      u64 start_tstamp);
 
 /**
- * timecounter_read - return nanoseconds elapsed since timecounter_init() or
- *                    timecounter_initialize() or timecounter_reset() plus
- *		      the initial time stamp
+ * timecounter_read - return nanoseconds elapsed since timecounter_initialize()
+ *		      or timecounter_reset() 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 3f62fe0..0a02ef0 100644
--- a/kernel/time/timecounter.c
+++ b/kernel/time/timecounter.c
@@ -18,17 +18,6 @@
 #include <linux/export.h>
 #include <linux/timecounter.h>
 
-void timecounter_init(struct timecounter *tc, u64 start_tstamp)
-{
-	struct cyclecounter *cc = &tc->cc;
-
-	tc->cycle_last = cc->read(cc);
-	tc->nsec = start_tstamp;
-	tc->mask = (1ULL << cc->shift) - 1;
-	tc->frac = 0;
-}
-EXPORT_SYMBOL_GPL(timecounter_init);
-
 void timecounter_initialize(struct timecounter *tc,
 			    u64 (*read)(const struct cyclecounter *cc),
 			    u64 mask,
@@ -43,7 +32,10 @@ void timecounter_initialize(struct timecounter *tc,
 	cc->mult = mult;
 	cc->shift = shift;
 
-	timecounter_init(tc, start_tstamp);
+	tc->cycle_last = cc->read(cc);
+	tc->nsec = start_tstamp;
+	tc->mask = (1ULL << cc->shift) - 1;
+	tc->frac = 0;
 }
 EXPORT_SYMBOL_GPL(timecounter_initialize);
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize  interface
  2017-12-15  7:38 ` [PATCH 15/27] ALSA: hda - " Sagar Arun Kamble
@ 2017-12-15 11:10   ` Takashi Iwai
  2017-12-15 16:51     ` Richard Cochran
  0 siblings, 1 reply; 50+ messages in thread
From: Takashi Iwai @ 2017-12-15 11:10 UTC (permalink / raw)
  To: Sagar Arun Kamble
  Cc: linux-kernel, alsa-devel, Vinod Koul, Richard Cochran, Thomas Gleixner

On Fri, 15 Dec 2017 08:38:30 +0100,
Sagar Arun Kamble wrote:
> 
> With new interface timecounter_initialize we can initialize timecounter
> fields and underlying cyclecounter together. Update azx timecounter
> init with this new function.
> 
> Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Cc: Jaroslav Kysela <perex@perex.cz>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Vinod Koul <vinod.koul@intel.com>
> Cc: alsa-devel@alsa-project.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  sound/hda/hdac_stream.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c
> index 9426c1a..ad91dde 100644
> --- a/sound/hda/hdac_stream.c
> +++ b/sound/hda/hdac_stream.c
> @@ -477,12 +477,8 @@ static void azx_timecounter_init(struct hdac_stream *azx_dev,
>  				 bool force, u64 last)
>  {
>  	struct timecounter *tc = &azx_dev->tc;
> -	struct cyclecounter *cc = &azx_dev->tc.cc;
>  	u64 nsec;
>  
> -	cc->read = azx_cc_read;
> -	cc->mask = CLOCKSOURCE_MASK(32);
> -
>  	/*
>  	 * Converting from 24 MHz to ns means applying a 125/3 factor.
>  	 * To avoid any saturation issues in intermediate operations,
> @@ -493,11 +489,13 @@ static void azx_timecounter_init(struct hdac_stream *azx_dev,
>  	 * overflows occur after about 4 hours or less, not a option.
>  	 */
>  
> -	cc->mult = 125; /* saturation after 195 years */
> -	cc->shift = 0;
> -
>  	nsec = 0; /* audio time is elapsed time since trigger */
> -	timecounter_init(tc, nsec);
> +	timecounter_initialize(tc,
> +			       azx_cc_read,
> +			       CLOCKSOURCE_MASK(32),
> +			       125, /* saturation after 195 years */
> +			       0,
> +			       nsec);

Hmm, a function with so many arguments is difficult to remember and is
often error-prone.  By this transition, it becomes harder to read
through.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2017-12-15 11:10   ` [alsa-devel] " Takashi Iwai
@ 2017-12-15 16:51     ` Richard Cochran
  2017-12-15 17:10       ` Takashi Iwai
  0 siblings, 1 reply; 50+ messages in thread
From: Richard Cochran @ 2017-12-15 16:51 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Sagar Arun Kamble, linux-kernel, alsa-devel, Vinod Koul, Thomas Gleixner

On Fri, Dec 15, 2017 at 12:10:47PM +0100, Takashi Iwai wrote:

> > -	struct cyclecounter *cc = &azx_dev->tc.cc;

> > -	cc->read = azx_cc_read;
> > -	cc->mask = CLOCKSOURCE_MASK(32);

> > -	cc->mult = 125; /* saturation after 195 years */
> > -	cc->shift = 0;

I want to get away from this mess of open coded structure
initialization and use a proper functional interface instead.

> >  	nsec = 0; /* audio time is elapsed time since trigger */
> > -	timecounter_init(tc, nsec);
> > +	timecounter_initialize(tc,
> > +			       azx_cc_read,
> > +			       CLOCKSOURCE_MASK(32),
> > +			       125, /* saturation after 195 years */
> > +			       0,
> > +			       nsec);
> 
> Hmm, a function with so many arguments is difficult to remember and is
> often error-prone.  By this transition, it becomes harder to read
> through.

Please suggest a better way.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2017-12-15 16:51     ` Richard Cochran
@ 2017-12-15 17:10       ` Takashi Iwai
  2017-12-26  7:37         ` Sagar Arun Kamble
  0 siblings, 1 reply; 50+ messages in thread
From: Takashi Iwai @ 2017-12-15 17:10 UTC (permalink / raw)
  To: Richard Cochran
  Cc: Sagar Arun Kamble, linux-kernel, alsa-devel, Vinod Koul, Thomas Gleixner

On Fri, 15 Dec 2017 17:51:25 +0100,
Richard Cochran wrote:
> 
> On Fri, Dec 15, 2017 at 12:10:47PM +0100, Takashi Iwai wrote:
> 
> > > -	struct cyclecounter *cc = &azx_dev->tc.cc;
> 
> > > -	cc->read = azx_cc_read;
> > > -	cc->mask = CLOCKSOURCE_MASK(32);
> 
> > > -	cc->mult = 125; /* saturation after 195 years */
> > > -	cc->shift = 0;
> 
> I want to get away from this mess of open coded structure
> initialization and use a proper functional interface instead.

I agree that a proper functional interface would be better, too.
But not a form like foo(501, 21, 10, 499, 5678).  
In C syntax, you may more easily pass a wrong value than open codes.

> > >  	nsec = 0; /* audio time is elapsed time since trigger */
> > > -	timecounter_init(tc, nsec);
> > > +	timecounter_initialize(tc,
> > > +			       azx_cc_read,
> > > +			       CLOCKSOURCE_MASK(32),
> > > +			       125, /* saturation after 195 years */
> > > +			       0,
> > > +			       nsec);
> > 
> > Hmm, a function with so many arguments is difficult to remember and is
> > often error-prone.  By this transition, it becomes harder to read
> > through.
> 
> Please suggest a better way.

I have no good idea ATM, sorry.

Or can we provide simpler versions for covering some defaults?  At
least reducing the number of arguments would make things easier.


Takashi

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [PATCH 25/27] qede: Use timecounter_reset interface
  2017-12-15  7:38 ` [PATCH 25/27] qede: " Sagar Arun Kamble
@ 2017-12-18 14:13   ` Kalluru, Sudarsana
  0 siblings, 0 replies; 50+ messages in thread
From: Kalluru, Sudarsana @ 2017-12-18 14:13 UTC (permalink / raw)
  To: Sagar Arun Kamble, linux-kernel
  Cc: Richard Cochran, Elior, Ariel, Dept-Eng Everest Linux L2, netdev

Acked-by: Sudarsana Kalluru <Sudarsana.Kalluru@cavium.com>

-----Original Message-----
From: Sagar Arun Kamble [mailto:sagar.a.kamble@intel.com] 
Sent: 15 December 2017 13:09
To: linux-kernel@vger.kernel.org
Cc: Sagar Arun Kamble <sagar.a.kamble@intel.com>; Richard Cochran <richardcochran@gmail.com>; Elior, Ariel <Ariel.Elior@cavium.com>; Dept-Eng Everest Linux L2 <Dept-EngEverestLinuxL2@cavium.com>; netdev@vger.kernel.org
Subject: [PATCH 25/27] qede: Use timecounter_reset interface

With new interface timecounter_reset we can update the start time for timecounter. Update qede_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Ariel Elior <Ariel.Elior@cavium.com>
Cc: everest-linux-l2@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/qlogic/qede/qede_ptp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qede/qede_ptp.c b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
index 0d054dc..c2de311 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ptp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
@@ -129,9 +129,9 @@ static int qede_ptp_settime(struct ptp_clock_info *info,
 
 	DP_VERBOSE(edev, QED_MSG_DEBUG, "PTP settime called, ns = %llu\n", ns);
 
-	/* Re-init the timecounter */
+	/* Reset the timecounter */
 	spin_lock_bh(&ptp->lock);
-	timecounter_init(&ptp->tc, ns);
+	timecounter_reset(&ptp->tc, ns);
 	spin_unlock_bh(&ptp->lock);
 
 	return 0;
--
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* RE: [PATCH 18/27] bnx2x: Use timecounter_reset interface
  2017-12-15  7:38 ` [PATCH 18/27] bnx2x: " Sagar Arun Kamble
@ 2017-12-18 14:13   ` Kalluru, Sudarsana
  0 siblings, 0 replies; 50+ messages in thread
From: Kalluru, Sudarsana @ 2017-12-18 14:13 UTC (permalink / raw)
  To: Sagar Arun Kamble, linux-kernel
  Cc: Richard Cochran, Elior, Ariel, Dept-Eng Everest Linux L2, netdev

Acked-by: Sudarsana Kalluru <Sudarsana.Kalluru@cavium.com>

-----Original Message-----
From: Sagar Arun Kamble [mailto:sagar.a.kamble@intel.com] 
Sent: 15 December 2017 13:09
To: linux-kernel@vger.kernel.org
Cc: Sagar Arun Kamble <sagar.a.kamble@intel.com>; Richard Cochran <richardcochran@gmail.com>; Elior, Ariel <Ariel.Elior@cavium.com>; Dept-Eng Everest Linux L2 <Dept-EngEverestLinuxL2@cavium.com>; netdev@vger.kernel.org
Subject: [PATCH 18/27] bnx2x: Use timecounter_reset interface

With new interface timecounter_reset we can update the start time for timecounter. Update bnx2x_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Ariel Elior <ariel.elior@cavium.com>
Cc: everest-linux-l2@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 1e10a81..e30e736 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13849,8 +13849,8 @@ static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
 
 	DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
 
-	/* Re-init the timecounter */
-	timecounter_init(&bp->timecounter, ns);
+	/* Reset the timecounter */
+	timecounter_reset(&bp->timecounter, ns);
 
 	return 0;
 }
--
1.9.1

^ permalink raw reply related	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2017-12-15 17:10       ` Takashi Iwai
@ 2017-12-26  7:37         ` Sagar Arun Kamble
  2017-12-28 16:49           ` Richard Cochran
  0 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2017-12-26  7:37 UTC (permalink / raw)
  To: Takashi Iwai, Richard Cochran
  Cc: linux-kernel, alsa-devel, Vinod Koul, Thomas Gleixner



On 12/15/2017 10:40 PM, Takashi Iwai wrote:
> On Fri, 15 Dec 2017 17:51:25 +0100,
> Richard Cochran wrote:
>> On Fri, Dec 15, 2017 at 12:10:47PM +0100, Takashi Iwai wrote:
>>
>>>> -	struct cyclecounter *cc = &azx_dev->tc.cc;
>>>> -	cc->read = azx_cc_read;
>>>> -	cc->mask = CLOCKSOURCE_MASK(32);
>>>> -	cc->mult = 125; /* saturation after 195 years */
>>>> -	cc->shift = 0;
>> I want to get away from this mess of open coded structure
>> initialization and use a proper functional interface instead.
> I agree that a proper functional interface would be better, too.
> But not a form like foo(501, 21, 10, 499, 5678).
> In C syntax, you may more easily pass a wrong value than open codes.
>
>>>>   	nsec = 0; /* audio time is elapsed time since trigger */
>>>> -	timecounter_init(tc, nsec);
>>>> +	timecounter_initialize(tc,
>>>> +			       azx_cc_read,
>>>> +			       CLOCKSOURCE_MASK(32),
>>>> +			       125, /* saturation after 195 years */
>>>> +			       0,
>>>> +			       nsec);
>>> Hmm, a function with so many arguments is difficult to remember and is
>>> often error-prone.  By this transition, it becomes harder to read
>>> through.
>> Please suggest a better way.
> I have no good idea ATM, sorry.
>
> Or can we provide simpler versions for covering some defaults?  At
> least reducing the number of arguments would make things easier.
Thought about specifying 1. cyclecounter read func 2. frequency 3. width 
of counter as parameters here
which can get rid of mult, shift params. But this is not easy as most of 
the drivers do not specify
cyclecounter frequency and instead hard-code the mult/shift factors.
How about passing initialized cyclecounter struct?
>
> Takashi

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2017-12-26  7:37         ` Sagar Arun Kamble
@ 2017-12-28 16:49           ` Richard Cochran
  2018-01-02  6:03             ` Sagar Arun Kamble
  0 siblings, 1 reply; 50+ messages in thread
From: Richard Cochran @ 2017-12-28 16:49 UTC (permalink / raw)
  To: Sagar Arun Kamble
  Cc: Takashi Iwai, linux-kernel, alsa-devel, Vinod Koul, Thomas Gleixner

On Tue, Dec 26, 2017 at 01:07:35PM +0530, Sagar Arun Kamble wrote:
> > Or can we provide simpler versions for covering some defaults?  At
> > least reducing the number of arguments would make things easier.
> Thought about specifying 1. cyclecounter read func 2. frequency 3. width of
> counter as parameters here
> which can get rid of mult, shift params. But this is not easy as most of the
> drivers do not specify
> cyclecounter frequency and instead hard-code the mult/shift factors.

You are talking about using clocks_calc_mult_shift() here, right? (See
the usage example in drivers/net/ethernet/ti/cpts.c).

This is a good idea, and it is worth getting the driver authors' input
to figure out the correct parameters.

I bet we can use that almost everywhere.  If there are any drivers
that cannot be converted, then we can leave some sort of low level
legacy initialization method.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2017-12-28 16:49           ` Richard Cochran
@ 2018-01-02  6:03             ` Sagar Arun Kamble
  2018-01-02 17:15               ` Pierre-Louis Bossart
  0 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2018-01-02  6:03 UTC (permalink / raw)
  To: Richard Cochran
  Cc: Takashi Iwai, linux-kernel, alsa-devel, Vinod Koul, Thomas Gleixner



On 12/28/2017 10:19 PM, Richard Cochran wrote:
> On Tue, Dec 26, 2017 at 01:07:35PM +0530, Sagar Arun Kamble wrote:
>>> Or can we provide simpler versions for covering some defaults?  At
>>> least reducing the number of arguments would make things easier.
>> Thought about specifying 1. cyclecounter read func 2. frequency 3. width of
>> counter as parameters here
>> which can get rid of mult, shift params. But this is not easy as most of the
>> drivers do not specify
>> cyclecounter frequency and instead hard-code the mult/shift factors.
> You are talking about using clocks_calc_mult_shift() here, right? (See
> the usage example in drivers/net/ethernet/ti/cpts.c).
Yes
> This is a good idea, and it is worth getting the driver authors' input
> to figure out the correct parameters.
>
> I bet we can use that almost everywhere.  If there are any drivers
> that cannot be converted, then we can leave some sort of low level
> legacy initialization method.
Agree
> Thanks,
> Richard
>

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2018-01-02  6:03             ` Sagar Arun Kamble
@ 2018-01-02 17:15               ` Pierre-Louis Bossart
  2018-01-02 18:21                 ` Richard Cochran
  0 siblings, 1 reply; 50+ messages in thread
From: Pierre-Louis Bossart @ 2018-01-02 17:15 UTC (permalink / raw)
  To: Sagar Arun Kamble, Richard Cochran
  Cc: Takashi Iwai, Vinod Koul, alsa-devel, Thomas Gleixner, linux-kernel

On 1/2/18 12:03 AM, Sagar Arun Kamble wrote:
> 
> 
> On 12/28/2017 10:19 PM, Richard Cochran wrote:
>> On Tue, Dec 26, 2017 at 01:07:35PM +0530, Sagar Arun Kamble wrote:
>>>> Or can we provide simpler versions for covering some defaults?  At
>>>> least reducing the number of arguments would make things easier.
>>> Thought about specifying 1. cyclecounter read func 2. frequency 3. 
>>> width of
>>> counter as parameters here
>>> which can get rid of mult, shift params. But this is not easy as most 
>>> of the
>>> drivers do not specify
>>> cyclecounter frequency and instead hard-code the mult/shift factors.
>> You are talking about using clocks_calc_mult_shift() here, right? (See
>> the usage example in drivers/net/ethernet/ti/cpts.c).
> Yes
>> This is a good idea, and it is worth getting the driver authors' input
>> to figure out the correct parameters.

I wrote the code for HDaudio and I remember wasting time trying to 
figure out the gory details of the cycle counter stuff when all I wanted 
was a conversion from a 24MHz counter to ns values using a 125/3 
operation in the right order - as explained in the comments

If there was a helper to set those mult/shift values it'd make the 
HDaudio code clearer (and also help support newer modes of operation 
with a 12 and 6 MHz MCLK).

The initial proposal with hard-coded values in arguments instead of 
structure members didn't really make the code clearer.


>>
>> I bet we can use that almost everywhere.  If there are any drivers
>> that cannot be converted, then we can leave some sort of low level
>> legacy initialization method.
> Agree
>> Thanks,
>> Richard
>>
> 
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2018-01-02 17:15               ` Pierre-Louis Bossart
@ 2018-01-02 18:21                 ` Richard Cochran
  2018-01-02 19:53                   ` Pierre-Louis Bossart
  0 siblings, 1 reply; 50+ messages in thread
From: Richard Cochran @ 2018-01-02 18:21 UTC (permalink / raw)
  To: Pierre-Louis Bossart
  Cc: Sagar Arun Kamble, Takashi Iwai, Vinod Koul, alsa-devel,
	Thomas Gleixner, linux-kernel

On Tue, Jan 02, 2018 at 11:15:45AM -0600, Pierre-Louis Bossart wrote:
> I wrote the code for HDaudio and I remember wasting time trying to figure
> out the gory details of the cycle counter stuff when all I wanted was a
> conversion from a 24MHz counter to ns values using a 125/3 operation in the
> right order - as explained in the comments

Would using clocks_calc_mult_shift() work for you?

Thanks,
Richard

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2018-01-02 18:21                 ` Richard Cochran
@ 2018-01-02 19:53                   ` Pierre-Louis Bossart
  2018-01-05 10:06                     ` Sagar Arun Kamble
  0 siblings, 1 reply; 50+ messages in thread
From: Pierre-Louis Bossart @ 2018-01-02 19:53 UTC (permalink / raw)
  To: Richard Cochran
  Cc: alsa-devel, Takashi Iwai, linux-kernel, Vinod Koul,
	Thomas Gleixner, Sagar Arun Kamble

On 1/2/18 12:21 PM, Richard Cochran wrote:
> On Tue, Jan 02, 2018 at 11:15:45AM -0600, Pierre-Louis Bossart wrote:
>> I wrote the code for HDaudio and I remember wasting time trying to figure
>> out the gory details of the cycle counter stuff when all I wanted was a
>> conversion from a 24MHz counter to ns values using a 125/3 operation in the
>> right order - as explained in the comments
> 
> Would using clocks_calc_mult_shift() work for you?

In theory yes, but I'd need to re-check what the results would be.
I remember applying the 1/3 factor separately to avoid wrap-around after 
4 hours [1], but I can't remember the details on the analysis. I can't 
figure out what the 'maxsec' argument should be either.

[1] 
http://elixir.free-electrons.com/linux/latest/source/sound/hda/hdac_stream.c#L486

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2018-01-02 19:53                   ` Pierre-Louis Bossart
@ 2018-01-05 10:06                     ` Sagar Arun Kamble
  2018-01-05 15:43                       ` Pierre-Louis Bossart
  0 siblings, 1 reply; 50+ messages in thread
From: Sagar Arun Kamble @ 2018-01-05 10:06 UTC (permalink / raw)
  To: Pierre-Louis Bossart, Richard Cochran
  Cc: alsa-devel, Takashi Iwai, linux-kernel, Vinod Koul, Thomas Gleixner



On 1/3/2018 1:23 AM, Pierre-Louis Bossart wrote:
> On 1/2/18 12:21 PM, Richard Cochran wrote:
>> On Tue, Jan 02, 2018 at 11:15:45AM -0600, Pierre-Louis Bossart wrote:
>>> I wrote the code for HDaudio and I remember wasting time trying to 
>>> figure
>>> out the gory details of the cycle counter stuff when all I wanted was a
>>> conversion from a 24MHz counter to ns values using a 125/3 operation 
>>> in the
>>> right order - as explained in the comments
>>
>> Would using clocks_calc_mult_shift() work for you?
>
> In theory yes, but I'd need to re-check what the results would be.
> I remember applying the 1/3 factor separately to avoid wrap-around 
> after 4 hours [1], but I can't remember the details on the analysis. I 
> can't figure out what the 'maxsec' argument should be either.
>
I am not sure if I understood the wrap-around correctly. Is 
AZX_REG_WALL_CLK 64bit or 32bit and in the comments which 20 bits are 
being referred.

Keeping maxsec at lower value will ensure good precision but the mult 
factor derived then might lead to overflow if the interval of counter 
read is big.
Keeping maxsec high will reduce the mult factor and will marginally 
impact the precision (of the order of 6 decimal places of fraction nano 
second).

For 24mhz clock I am getting following scale factors at different maxsec 
values. I think these are as good as 125/3
125/3 gives scale factor of 41.666666666666666666666666666667

maxsec, mult, shift, scale factor (mult/(2^shift))
0, 2796202667, 26,     41.66666667163372039794921875
3600, 87381333, 21,   41.666666507720947265625
14400, 21845333, 19, 41.6666660308837890625

I see sound driver uses only timecounter_read so conversions should be fine.
If there are usages of timecounter_cyc2time then we will have to take 
care of updating the timecounter often as
timecounter API internally counts time backwards if counter is spaced 
more than 1/2 the range.

Thanks
Sagar
> [1] 
> http://elixir.free-electrons.com/linux/latest/source/sound/hda/hdac_stream.c#L486 
>

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2018-01-05 10:06                     ` Sagar Arun Kamble
@ 2018-01-05 15:43                       ` Pierre-Louis Bossart
  2018-01-09 10:09                         ` Sagar Arun Kamble
  0 siblings, 1 reply; 50+ messages in thread
From: Pierre-Louis Bossart @ 2018-01-05 15:43 UTC (permalink / raw)
  To: Sagar Arun Kamble, Richard Cochran
  Cc: alsa-devel, Takashi Iwai, linux-kernel, Vinod Koul, Thomas Gleixner

On 1/5/18 4:06 AM, Sagar Arun Kamble wrote:
> 
> 
> On 1/3/2018 1:23 AM, Pierre-Louis Bossart wrote:
>> On 1/2/18 12:21 PM, Richard Cochran wrote:
>>> On Tue, Jan 02, 2018 at 11:15:45AM -0600, Pierre-Louis Bossart wrote:
>>>> I wrote the code for HDaudio and I remember wasting time trying to 
>>>> figure
>>>> out the gory details of the cycle counter stuff when all I wanted was a
>>>> conversion from a 24MHz counter to ns values using a 125/3 operation 
>>>> in the
>>>> right order - as explained in the comments
>>>
>>> Would using clocks_calc_mult_shift() work for you?
>>
>> In theory yes, but I'd need to re-check what the results would be.
>> I remember applying the 1/3 factor separately to avoid wrap-around 
>> after 4 hours [1], but I can't remember the details on the analysis. I 
>> can't figure out what the 'maxsec' argument should be either.
>>
> I am not sure if I understood the wrap-around correctly. Is 
> AZX_REG_WALL_CLK 64bit or 32bit and in the comments which 20 bits are 
> being referred.

it's a 32-bit counter.
off the top of my head, the idea was that the integer arithmetic should 
not degrade the precision (42ns) and that means you need to be careful 
with the fractional part, especially if the errors with the fractional 
part accumulate over time (I think this was the case when I looked 
several years ago). That's the main reason why I did the division by 3 
last, after the read, so that the precision is not impacted by the 
interval between two reads.

You also need to be careful with the multiplication factor otherwise you 
will exceed the 64-bit resolution. For example with the 14400 factor, 
you cannot handle a counter larger than 2^64/14400, which gives you 
14826 hours or 1.69 years. It's one of those 'nobody will ever need more 
than 640KB' value. The 125 factor gives you 195 years without saturating.

> 
> Keeping maxsec at lower value will ensure good precision but the mult 
> factor derived then might lead to overflow if the interval of counter 
> read is big.
> Keeping maxsec high will reduce the mult factor and will marginally 
> impact the precision (of the order of 6 decimal places of fraction nano 
> second).
> 
> For 24mhz clock I am getting following scale factors at different maxsec 
> values. I think these are as good as 125/3
> 125/3 gives scale factor of 41.666666666666666666666666666667
> 
> maxsec, mult, shift, scale factor (mult/(2^shift))
> 0, 2796202667, 26,     41.66666667163372039794921875
> 3600, 87381333, 21,   41.666666507720947265625
> 14400, 21845333, 19, 41.6666660308837890625
> 
> I see sound driver uses only timecounter_read so conversions should be 
> fine.
> If there are usages of timecounter_cyc2time then we will have to take 
> care of updating the timecounter often as
> timecounter API internally counts time backwards if counter is spaced 
> more than 1/2 the range.
> 
> Thanks
> Sagar
>> [1] 
>> http://elixir.free-electrons.com/linux/latest/source/sound/hda/hdac_stream.c#L486 
>>
> 

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [Intel-wired-lan] [PATCH 20/27] e1000e: Use timecounter_reset interface
  2017-12-15  7:38 ` [PATCH 20/27] e1000e: " Sagar Arun Kamble
@ 2018-01-06  4:30   ` Brown, Aaron F
  0 siblings, 0 replies; 50+ messages in thread
From: Brown, Aaron F @ 2018-01-06  4:30 UTC (permalink / raw)
  To: Kamble, Sagar A, linux-kernel
  Cc: intel-wired-lan, Richard Cochran, Kamble, Sagar A, netdev

> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> Behalf Of Sagar Arun Kamble
> Sent: Thursday, December 14, 2017 11:39 PM
> To: linux-kernel@vger.kernel.org
> Cc: intel-wired-lan@lists.osuosl.org; Richard Cochran
> <richardcochran@gmail.com>; Kamble, Sagar A
> <sagar.a.kamble@intel.com>; netdev@vger.kernel.org
> Subject: [Intel-wired-lan] [PATCH 20/27] e1000e: Use timecounter_reset
> interface
> 
> With new interface timecounter_reset we can update the start time for
> timecounter. Update e1000e_phc_settime with this new function.
> 
> Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> Cc: intel-wired-lan@lists.osuosl.org
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/net/ethernet/intel/e1000e/ptp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
Tested-by: Aaron Brown <aaron.f.brown@intel.com>

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [Intel-wired-lan] [PATCH 08/27] e1000e: Use timecounter_initialize interface
  2017-12-15  7:38 ` [PATCH 08/27] e1000e: " Sagar Arun Kamble
@ 2018-01-06  4:31   ` Brown, Aaron F
  0 siblings, 0 replies; 50+ messages in thread
From: Brown, Aaron F @ 2018-01-06  4:31 UTC (permalink / raw)
  To: Kamble, Sagar A, linux-kernel
  Cc: intel-wired-lan, Richard Cochran, Kamble, Sagar A, netdev

> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> Behalf Of Sagar Arun Kamble
> Sent: Thursday, December 14, 2017 11:38 PM
> To: linux-kernel@vger.kernel.org
> Cc: intel-wired-lan@lists.osuosl.org; Richard Cochran
> <richardcochran@gmail.com>; Kamble, Sagar A
> <sagar.a.kamble@intel.com>; netdev@vger.kernel.org
> Subject: [Intel-wired-lan] [PATCH 08/27] e1000e: Use timecounter_initialize
> interface
> 
> With new interface timecounter_initialize we can initialize timecounter
> fields and underlying cyclecounter together. Update e1000e timecounter
> init with this new function.
> 
> Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> Cc: intel-wired-lan@lists.osuosl.org
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/net/ethernet/intel/e1000e/e1000.h  |  4 ++++
>  drivers/net/ethernet/intel/e1000e/netdev.c | 31 +++++++++++++++++-----
> --------
>  2 files changed, 22 insertions(+), 13 deletions(-)
> 

Tested-by: Aaron Brown <aaron.f.brown@intel.com>

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [Intel-wired-lan] [PATCH 21/27] igb: Use timecounter_reset interface
  2017-12-15  7:38 ` [PATCH 21/27] igb: " Sagar Arun Kamble
@ 2018-01-06  4:33   ` Brown, Aaron F
  0 siblings, 0 replies; 50+ messages in thread
From: Brown, Aaron F @ 2018-01-06  4:33 UTC (permalink / raw)
  To: Kamble, Sagar A, linux-kernel
  Cc: intel-wired-lan, Richard Cochran, Kamble, Sagar A, netdev

> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> Behalf Of Sagar Arun Kamble
> Sent: Thursday, December 14, 2017 11:39 PM
> To: linux-kernel@vger.kernel.org
> Cc: intel-wired-lan@lists.osuosl.org; Richard Cochran
> <richardcochran@gmail.com>; Kamble, Sagar A
> <sagar.a.kamble@intel.com>; netdev@vger.kernel.org
> Subject: [Intel-wired-lan] [PATCH 21/27] igb: Use timecounter_reset
> interface
> 
> With new interface timecounter_reset we can update the start time for
> timecounter. Update igb_ptp_settime_82576 with this new function.
> 
> Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> Cc: intel-wired-lan@lists.osuosl.org
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/net/ethernet/intel/igb/igb_ptp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Tested-by: Aaron Brown <aaron.f.brown@intel.com>

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [Intel-wired-lan] [PATCH 22/27] ixgbe: Use timecounter_reset interface
  2017-12-15  7:38 ` [PATCH 22/27] ixgbe: " Sagar Arun Kamble
@ 2018-01-06  4:33   ` Brown, Aaron F
  2018-01-06  5:11   ` Brown, Aaron F
  1 sibling, 0 replies; 50+ messages in thread
From: Brown, Aaron F @ 2018-01-06  4:33 UTC (permalink / raw)
  To: Kamble, Sagar A, linux-kernel
  Cc: intel-wired-lan, Richard Cochran, Kamble, Sagar A, netdev

> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> Behalf Of Sagar Arun Kamble
> Sent: Thursday, December 14, 2017 11:39 PM
> To: linux-kernel@vger.kernel.org
> Cc: intel-wired-lan@lists.osuosl.org; Richard Cochran
> <richardcochran@gmail.com>; Kamble, Sagar A
> <sagar.a.kamble@intel.com>; netdev@vger.kernel.org
> Subject: [Intel-wired-lan] [PATCH 22/27] ixgbe: Use timecounter_reset
> interface
> 
> With new interface timecounter_reset we can update the start time for
> timecounter. Update ixgbe_ptp_settime with this new function.
> 
> Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> Cc: intel-wired-lan@lists.osuosl.org
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Tested-by: Aaron Brown <aaron.f.brown@intel.com>

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [Intel-wired-lan] [PATCH 22/27] ixgbe: Use timecounter_reset interface
  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
  1 sibling, 0 replies; 50+ messages in thread
From: Brown, Aaron F @ 2018-01-06  5:11 UTC (permalink / raw)
  To: Kamble, Sagar A, linux-kernel
  Cc: intel-wired-lan, Richard Cochran, Kamble, Sagar A, netdev



> -----Original Message-----
> From: Brown, Aaron F
> Sent: Friday, January 5, 2018 8:34 PM
> To: 'Sagar Arun Kamble' <sagar.a.kamble@intel.com>; linux-
> kernel@vger.kernel.org
> Cc: intel-wired-lan@lists.osuosl.org; Richard Cochran
> <richardcochran@gmail.com>; Kamble, Sagar A
> <sagar.a.kamble@intel.com>; netdev@vger.kernel.org
> Subject: RE: [Intel-wired-lan] [PATCH 22/27] ixgbe: Use timecounter_reset
> interface
> 
> > From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> > Behalf Of Sagar Arun Kamble
> > Sent: Thursday, December 14, 2017 11:39 PM
> > To: linux-kernel@vger.kernel.org
> > Cc: intel-wired-lan@lists.osuosl.org; Richard Cochran
> > <richardcochran@gmail.com>; Kamble, Sagar A
> > <sagar.a.kamble@intel.com>; netdev@vger.kernel.org
> > Subject: [Intel-wired-lan] [PATCH 22/27] ixgbe: Use timecounter_reset
> > interface
> >
> > With new interface timecounter_reset we can update the start time for
> > timecounter. Update ixgbe_ptp_settime with this new function.
> >
> > Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
> > Cc: Richard Cochran <richardcochran@gmail.com>
> > Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> > Cc: intel-wired-lan@lists.osuosl.org
> > Cc: netdev@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > ---
> >  drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> 
> Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Strike my Tested-by: for this (ixgbe) instance.  It was meant for igb.

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [Intel-wired-lan] [PATCH 09/27] igb: Use timecounter_initialize interface
  2017-12-15  7:38 ` [PATCH 09/27] igb: " Sagar Arun Kamble
@ 2018-01-06  5:14   ` Brown, Aaron F
  0 siblings, 0 replies; 50+ messages in thread
From: Brown, Aaron F @ 2018-01-06  5:14 UTC (permalink / raw)
  To: Kamble, Sagar A, linux-kernel
  Cc: intel-wired-lan, Richard Cochran, Kamble, Sagar A, netdev

> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> Behalf Of Sagar Arun Kamble
> Sent: Thursday, December 14, 2017 11:38 PM
> To: linux-kernel@vger.kernel.org
> Cc: intel-wired-lan@lists.osuosl.org; Richard Cochran
> <richardcochran@gmail.com>; Kamble, Sagar A
> <sagar.a.kamble@intel.com>; netdev@vger.kernel.org
> Subject: [Intel-wired-lan] [PATCH 09/27] igb: Use timecounter_initialize
> interface
> 
> With new interface timecounter_initialize we can initialize timecounter
> fields and underlying cyclecounter together. Update igb ptp timecounter
> init with this new function.
> 
> Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
> Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> Cc: intel-wired-lan@lists.osuosl.org
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/net/ethernet/intel/igb/igb.h     |  4 ++++
>  drivers/net/ethernet/intel/igb/igb_ptp.c | 23 ++++++++++++++---------
>  2 files changed, 18 insertions(+), 9 deletions(-)
> 

Tested-by: Aaron Brown <aaron.f.brown@intel.com>

^ permalink raw reply	[flat|nested] 50+ messages in thread

* RE: [Intel-wired-lan] [PATCH 01/27] timecounter: Make cyclecounter struct part of timecounter struct
  2017-12-15  7:38 ` [PATCH 01/27] timecounter: Make cyclecounter struct part of timecounter struct Sagar Arun Kamble
@ 2018-01-08 22:20   ` Brown, Aaron F
  2018-01-09  9:01     ` Sagar Arun Kamble
  0 siblings, 1 reply; 50+ messages in thread
From: Brown, Aaron F @ 2018-01-08 22:20 UTC (permalink / raw)
  To: Kamble, Sagar A, linux-kernel
  Cc: alsa-devel, linux-rdma, netdev, Richard Cochran, Stephen Boyd,
	Chris Wilson, John Stultz, intel-wired-lan, Thomas Gleixner,
	Kamble, Sagar A, kvmarm, linux-arm-kernel

> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> Behalf Of Sagar Arun Kamble
> Sent: Thursday, December 14, 2017 11:38 PM
> To: linux-kernel@vger.kernel.org
> Cc: alsa-devel@alsa-project.org; linux-rdma@vger.kernel.org;
> netdev@vger.kernel.org; Richard Cochran <richardcochran@gmail.com>;
> Stephen Boyd <sboyd@codeaurora.org>; Chris Wilson <chris@chris-
> wilson.co.uk>; John Stultz <john.stultz@linaro.org>; intel-wired-
> lan@lists.osuosl.org; Thomas Gleixner <tglx@linutronix.de>; Kamble, Sagar A
> <sagar.a.kamble@intel.com>; kvmarm@lists.cs.columbia.edu; linux-arm-
> kernel@lists.infradead.org
> Subject: [Intel-wired-lan] [PATCH 01/27] timecounter: Make cyclecounter
> struct part of timecounter struct
> 
> There is no real need for the users of timecounters to define cyclecounter
> and timecounter variables separately. Since timecounter will always be
> based on cyclecounter, have cyclecounter struct as member of timecounter
> struct.
> 
> v2: Rebase.
> 
> Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Richard Cochran <richardcochran@gmail.com>
> 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
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: netdev@vger.kernel.org
> Cc: intel-wired-lan@lists.osuosl.org
> Cc: linux-rdma@vger.kernel.org
> Cc: alsa-devel@alsa-project.org
> Cc: kvmarm@lists.cs.columbia.edu
> Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> (Intel drivers)
> ---
>  arch/microblaze/kernel/timer.c                     | 20 ++++++------
>  drivers/clocksource/arm_arch_timer.c               | 19 ++++++------
>  drivers/net/ethernet/amd/xgbe/xgbe-dev.c           |  3 +-
>  drivers/net/ethernet/amd/xgbe/xgbe-ptp.c           |  9 +++---
>  drivers/net/ethernet/amd/xgbe/xgbe.h               |  1 -
>  drivers/net/ethernet/broadcom/bnx2x/bnx2x.h        |  1 -
>  drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c   | 20 ++++++------
>  drivers/net/ethernet/freescale/fec.h               |  1 -
>  drivers/net/ethernet/freescale/fec_ptp.c           | 30 +++++++++---------
>  drivers/net/ethernet/intel/e1000e/e1000.h          |  1 -
>  drivers/net/ethernet/intel/e1000e/netdev.c         | 27 ++++++++--------
>  drivers/net/ethernet/intel/e1000e/ptp.c            |  2 +-
>  drivers/net/ethernet/intel/igb/igb.h               |  1 -
>  drivers/net/ethernet/intel/igb/igb_ptp.c           | 25 ++++++++-------
>  drivers/net/ethernet/intel/ixgbe/ixgbe.h           |  1 -
>  drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c       | 17 +++++-----
>  drivers/net/ethernet/mellanox/mlx4/en_clock.c      | 28 ++++++++---------
>  drivers/net/ethernet/mellanox/mlx4/mlx4_en.h       |  1 -
>  .../net/ethernet/mellanox/mlx5/core/lib/clock.c    | 34 ++++++++++----------
>  drivers/net/ethernet/qlogic/qede/qede_ptp.c        | 20 ++++++------
>  drivers/net/ethernet/ti/cpts.c                     | 36 ++++++++++++----------
>  drivers/net/ethernet/ti/cpts.h                     |  1 -
>  include/linux/mlx5/driver.h                        |  1 -
>  include/linux/timecounter.h                        |  4 +--
>  include/sound/hdaudio.h                            |  1 -
>  kernel/time/timecounter.c                          | 28 ++++++++---------
>  sound/hda/hdac_stream.c                            |  7 +++--
>  virt/kvm/arm/arch_timer.c                          |  6 ++--
>  28 files changed, 163 insertions(+), 182 deletions(-)
> 

For Intel e1000e and igb drivers:
Tested-by: Aaron Brown <aaron.f.brown@intel.com>

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [Intel-wired-lan] [PATCH 01/27] timecounter: Make cyclecounter struct part of timecounter struct
  2018-01-08 22:20   ` [Intel-wired-lan] " Brown, Aaron F
@ 2018-01-09  9:01     ` Sagar Arun Kamble
  0 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2018-01-09  9:01 UTC (permalink / raw)
  To: Brown, Aaron F, linux-kernel
  Cc: alsa-devel, linux-rdma, netdev, Richard Cochran, Stephen Boyd,
	Chris Wilson, John Stultz, intel-wired-lan, Thomas Gleixner,
	kvmarm, linux-arm-kernel

Thanks Aaron.

Regards,
Sagar

On 1/9/2018 3:50 AM, Brown, Aaron F wrote:
>> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
>> Behalf Of Sagar Arun Kamble
>> Sent: Thursday, December 14, 2017 11:38 PM
>> To: linux-kernel@vger.kernel.org
>> Cc: alsa-devel@alsa-project.org; linux-rdma@vger.kernel.org;
>> netdev@vger.kernel.org; Richard Cochran <richardcochran@gmail.com>;
>> Stephen Boyd <sboyd@codeaurora.org>; Chris Wilson <chris@chris-
>> wilson.co.uk>; John Stultz <john.stultz@linaro.org>; intel-wired-
>> lan@lists.osuosl.org; Thomas Gleixner <tglx@linutronix.de>; Kamble, Sagar A
>> <sagar.a.kamble@intel.com>; kvmarm@lists.cs.columbia.edu; linux-arm-
>> kernel@lists.infradead.org
>> Subject: [Intel-wired-lan] [PATCH 01/27] timecounter: Make cyclecounter
>> struct part of timecounter struct
>>
>> There is no real need for the users of timecounters to define cyclecounter
>> and timecounter variables separately. Since timecounter will always be
>> based on cyclecounter, have cyclecounter struct as member of timecounter
>> struct.
>>
>> v2: Rebase.
>>
>> Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
>> Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
>> Cc: Richard Cochran <richardcochran@gmail.com>
>> 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
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: netdev@vger.kernel.org
>> Cc: intel-wired-lan@lists.osuosl.org
>> Cc: linux-rdma@vger.kernel.org
>> Cc: alsa-devel@alsa-project.org
>> Cc: kvmarm@lists.cs.columbia.edu
>> Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> (Intel drivers)
>> ---
>>   arch/microblaze/kernel/timer.c                     | 20 ++++++------
>>   drivers/clocksource/arm_arch_timer.c               | 19 ++++++------
>>   drivers/net/ethernet/amd/xgbe/xgbe-dev.c           |  3 +-
>>   drivers/net/ethernet/amd/xgbe/xgbe-ptp.c           |  9 +++---
>>   drivers/net/ethernet/amd/xgbe/xgbe.h               |  1 -
>>   drivers/net/ethernet/broadcom/bnx2x/bnx2x.h        |  1 -
>>   drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c   | 20 ++++++------
>>   drivers/net/ethernet/freescale/fec.h               |  1 -
>>   drivers/net/ethernet/freescale/fec_ptp.c           | 30 +++++++++---------
>>   drivers/net/ethernet/intel/e1000e/e1000.h          |  1 -
>>   drivers/net/ethernet/intel/e1000e/netdev.c         | 27 ++++++++--------
>>   drivers/net/ethernet/intel/e1000e/ptp.c            |  2 +-
>>   drivers/net/ethernet/intel/igb/igb.h               |  1 -
>>   drivers/net/ethernet/intel/igb/igb_ptp.c           | 25 ++++++++-------
>>   drivers/net/ethernet/intel/ixgbe/ixgbe.h           |  1 -
>>   drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c       | 17 +++++-----
>>   drivers/net/ethernet/mellanox/mlx4/en_clock.c      | 28 ++++++++---------
>>   drivers/net/ethernet/mellanox/mlx4/mlx4_en.h       |  1 -
>>   .../net/ethernet/mellanox/mlx5/core/lib/clock.c    | 34 ++++++++++----------
>>   drivers/net/ethernet/qlogic/qede/qede_ptp.c        | 20 ++++++------
>>   drivers/net/ethernet/ti/cpts.c                     | 36 ++++++++++++----------
>>   drivers/net/ethernet/ti/cpts.h                     |  1 -
>>   include/linux/mlx5/driver.h                        |  1 -
>>   include/linux/timecounter.h                        |  4 +--
>>   include/sound/hdaudio.h                            |  1 -
>>   kernel/time/timecounter.c                          | 28 ++++++++---------
>>   sound/hda/hdac_stream.c                            |  7 +++--
>>   virt/kvm/arm/arch_timer.c                          |  6 ++--
>>   28 files changed, 163 insertions(+), 182 deletions(-)
>>
> For Intel e1000e and igb drivers:
> Tested-by: Aaron Brown <aaron.f.brown@intel.com>

^ permalink raw reply	[flat|nested] 50+ messages in thread

* Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface
  2018-01-05 15:43                       ` Pierre-Louis Bossart
@ 2018-01-09 10:09                         ` Sagar Arun Kamble
  0 siblings, 0 replies; 50+ messages in thread
From: Sagar Arun Kamble @ 2018-01-09 10:09 UTC (permalink / raw)
  To: Pierre-Louis Bossart, Richard Cochran
  Cc: alsa-devel, Takashi Iwai, linux-kernel, Vinod Koul, Thomas Gleixner



On 1/5/2018 9:13 PM, Pierre-Louis Bossart wrote:
> On 1/5/18 4:06 AM, Sagar Arun Kamble wrote:
>>
>>
>> On 1/3/2018 1:23 AM, Pierre-Louis Bossart wrote:
>>> On 1/2/18 12:21 PM, Richard Cochran wrote:
>>>> On Tue, Jan 02, 2018 at 11:15:45AM -0600, Pierre-Louis Bossart wrote:
>>>>> I wrote the code for HDaudio and I remember wasting time trying to 
>>>>> figure
>>>>> out the gory details of the cycle counter stuff when all I wanted 
>>>>> was a
>>>>> conversion from a 24MHz counter to ns values using a 125/3 
>>>>> operation in the
>>>>> right order - as explained in the comments
>>>>
>>>> Would using clocks_calc_mult_shift() work for you?
>>>
>>> In theory yes, but I'd need to re-check what the results would be.
>>> I remember applying the 1/3 factor separately to avoid wrap-around 
>>> after 4 hours [1], but I can't remember the details on the analysis. 
>>> I can't figure out what the 'maxsec' argument should be either.
>>>
>> I am not sure if I understood the wrap-around correctly. Is 
>> AZX_REG_WALL_CLK 64bit or 32bit and in the comments which 20 bits are 
>> being referred.
>
> it's a 32-bit counter.
> off the top of my head, the idea was that the integer arithmetic 
> should not degrade the precision (42ns) and that means you need to be 
> careful with the fractional part, especially if the errors with the 
> fractional part accumulate over time (I think this was the case when I 
> looked several years ago). That's the main reason why I did the 
> division by 3 last, after the read, so that the precision is not 
> impacted by the interval between two reads.
>
timecounter interface ensures to add the fractional ns time so it has 
good precision. In the table below 3600 indicates interval of 1min 
between two counter reads
and 14400 indicates that interval of 4 minutes.  Shift factor controls 
the ns precision we want.
Considering duration of 195 years of interval between counter reads at 
24mhz we get mult=83 and shift=1 which will give cycle duration = 41.5.
What is the maximum duration of interval over which this read can be 
done in audio driver.
> You also need to be careful with the multiplication factor otherwise 
> you will exceed the 64-bit resolution. For example with the 14400 
> factor, you cannot handle a counter larger than 2^64/14400, which 
> gives you 14826 hours or 1.69 years. It's one of those 'nobody will 
> ever need more than 640KB' value. The 125 factor gives you 195 years 
> without saturating.
>
>>
>> Keeping maxsec at lower value will ensure good precision but the mult 
>> factor derived then might lead to overflow if the interval of counter 
>> read is big.
>> Keeping maxsec high will reduce the mult factor and will marginally 
>> impact the precision (of the order of 6 decimal places of fraction 
>> nano second).
>>
>> For 24mhz clock I am getting following scale factors at different 
>> maxsec values. I think these are as good as 125/3
>> 125/3 gives scale factor of 41.666666666666666666666666666667
>>
>> maxsec, mult, shift, scale factor (mult/(2^shift))
>> 0, 2796202667, 26,     41.66666667163372039794921875
>> 3600, 87381333, 21,   41.666666507720947265625
>> 14400, 21845333, 19, 41.6666660308837890625
>>
>> I see sound driver uses only timecounter_read so conversions should 
>> be fine.
>> If there are usages of timecounter_cyc2time then we will have to take 
>> care of updating the timecounter often as
>> timecounter API internally counts time backwards if counter is spaced 
>> more than 1/2 the range.
>>
>> Thanks
>> Sagar
>>> [1] 
>>> http://elixir.free-electrons.com/linux/latest/source/sound/hda/hdac_stream.c#L486 
>>>
>>
>

^ permalink raw reply	[flat|nested] 50+ messages in thread

end of thread, other threads:[~2018-01-09 10:12 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 02/27] timecounter: Introduce timecounter_initialize to update timecounter and cyclecounter Sagar Arun Kamble
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

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).