From: Shradha Shah <sshah@solarflare.com>
To: David Miller <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-net-drivers@solarflare.com>
Subject: [PATCH net-next 03/13] sfc: Rewrite adjustment of PPS event in a clearer way
Date: Mon, 3 Feb 2014 23:33:53 +0000 [thread overview]
Message-ID: <52F02761.3060004@solarflare.com> (raw)
In-Reply-To: <52F02469.50302@solarflare.com>
From: Ben Hutchings <bhutchings@solarflare.com>
There is substantial latency in generation and handling of PPS events
from the NIC, which we have to correct for before passing a host
timestamp to the PPS subsystem. We compare clocks with the MC,
giving us two offsets to subtract from the timestamp generated by
pps_get_ts():
(a) Time from the last good sync (where we got host and NIC timestamps
for nearly the same instant) to the time we called pps_get_ts()
(b) Time from NIC top of second to the last good sync
We currently calculate (a) + (b) in a quite confusing way.
Instead, calculate (a) completely, then add (b) to it.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: Shradha Shah <sshah@solarflare.com>
---
drivers/net/ethernet/sfc/ptp.c | 47 +++++++++++++++++++--------------------
1 files changed, 23 insertions(+), 24 deletions(-)
diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
index 7d0de50..28275e3 100644
--- a/drivers/net/ethernet/sfc/ptp.c
+++ b/drivers/net/ethernet/sfc/ptp.c
@@ -766,37 +766,36 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),
return -EAGAIN;
}
- /* Convert the NIC time into kernel time. No correction is required-
- * this time is the output of a firmware process.
- */
- mc_time = ptp->nic_to_kernel_time(ptp->timeset[last_good].major,
- ptp->timeset[last_good].minor, 0);
-
- /* Calculate delay from actual PPS to last_time */
- delta = ktime_to_timespec(mc_time);
- delta.tv_nsec +=
- last_time->ts_real.tv_nsec -
- (ptp->timeset[last_good].host_start & MC_NANOSECOND_MASK);
-
- /* It is possible that the seconds rolled over between taking
+ /* Calculate delay from last good sync (host time) to last_time.
+ * It is possible that the seconds rolled over between taking
* the start reading and the last value written by the host. The
* timescales are such that a gap of more than one second is never
- * expected.
+ * expected. delta is *not* normalised.
*/
start_sec = ptp->timeset[last_good].host_start >> MC_NANOSECOND_BITS;
last_sec = last_time->ts_real.tv_sec & MC_SECOND_MASK;
- if (start_sec != last_sec) {
- if (((start_sec + 1) & MC_SECOND_MASK) != last_sec) {
- netif_warn(efx, hw, efx->net_dev,
- "PTP bad synchronisation seconds\n");
- return -EAGAIN;
- } else {
- delta.tv_sec = 1;
- }
- } else {
- delta.tv_sec = 0;
+ if (start_sec != last_sec &&
+ ((start_sec + 1) & MC_SECOND_MASK) != last_sec) {
+ netif_warn(efx, hw, efx->net_dev,
+ "PTP bad synchronisation seconds\n");
+ return -EAGAIN;
}
+ delta.tv_sec = (last_sec - start_sec) & 1;
+ delta.tv_nsec =
+ last_time->ts_real.tv_nsec -
+ (ptp->timeset[last_good].host_start & MC_NANOSECOND_MASK);
+
+ /* Convert the NIC time at last good sync into kernel time.
+ * No correction is required - this time is the output of a
+ * firmware process.
+ */
+ mc_time = ptp->nic_to_kernel_time(ptp->timeset[last_good].major,
+ ptp->timeset[last_good].minor, 0);
+
+ /* Calculate delay from NIC top of second to last_time */
+ delta.tv_nsec += ktime_to_timespec(mc_time).tv_nsec;
+ /* Set PPS timestamp to match NIC top of second */
ptp->host_time_pps = *last_time;
pps_sub_ts(&ptp->host_time_pps, delta);
next prev parent reply other threads:[~2014-02-03 23:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-03 23:21 [PATCH net-next 00/13] Cleanup patches Shradha Shah
2014-02-03 23:33 ` [PATCH net-next 01/13] sfc: Removed adhoc scheme to rate limit PTP event queue overflow message Shradha Shah
2014-02-03 23:33 ` [PATCH net-next 02/13] sfc: Cache skb->data in local variable in efx_ptp_rx() Shradha Shah
2014-02-03 23:33 ` Shradha Shah [this message]
2014-02-03 23:34 ` [PATCH net-next 04/13] sfc: Replace TSOH_OFFSET with the equivalent NET_IP_ALIGN Shradha Shah
2014-02-03 23:34 ` [PATCH net-next 06/13] sfc: Remove unused definitions of EF10 user-mode DMA descriptors Shradha Shah
2014-02-03 23:34 ` [PATCH net-next 05/13] sfc: Rename 'use_options' variable in tso_start() to clearer 'use_opt_desc' Shradha Shah
2014-02-03 23:34 ` [PATCH net-next 07/13] sfc: Correct comment about number of TX queues used on EF10 Shradha Shah
2014-02-03 23:35 ` [PATCH net-next 08/13] sfc: Preserve rx_frm_trunc counters when resizing DMA rings Shradha Shah
2014-02-03 23:35 ` [PATCH net-next 09/13] sfc: Use canonical pointer type for MAC address in efx_set_mac_address() Shradha Shah
2014-02-03 23:35 ` [PATCH net-next 10/13] sfc: Update product naming Shradha Shah
2014-02-03 23:35 ` [PATCH net-next 11/13] sfc: Cosmetic changes to self-test from the out-of-tree driver Shradha Shah
2014-02-03 23:36 ` [PATCH net-next 12/13] sfc: Fail self-test with -EBUSY, not -EIO, if the device is busy Shradha Shah
2014-02-03 23:36 ` [PATCH net-next 13/13] sfc: Add/remove blank lines to taste Shradha Shah
2014-02-03 23:56 ` [PATCH net-next 00/13] Cleanup patches David Miller
-- strict thread matches above, loose matches on Subject: below --
2014-02-12 18:56 [PATCH net-next 00/13] Cleanup patches for the SFC driver Shradha Shah
2014-02-12 18:58 ` [PATCH net-next 03/13] sfc: Rewrite adjustment of PPS event in a clearer way Shradha Shah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52F02761.3060004@solarflare.com \
--to=sshah@solarflare.com \
--cc=davem@davemloft.net \
--cc=linux-net-drivers@solarflare.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.