From: Jakub Kicinski <kuba@kernel.org>
To: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Cc: Jacob Keller <jacob.e.keller@intel.com>,
Vadim Fedorenko <vadfed@meta.com>,
David Ahern <dsahern@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
Alexander Duyck <alexanderduyck@fb.com>,
netdev@vger.kernel.org,
Richard Cochran <richardcochran@gmail.com>
Subject: Re: [PATCH net-next v3 2/5] eth: fbnic: add initial PHC support
Date: Mon, 7 Oct 2024 16:09:17 -0700 [thread overview]
Message-ID: <20241007160917.591c2d5d@kernel.org> (raw)
In-Reply-To: <e6f541f8-ac28-4180-989a-84ee4587e21c@linux.dev>
On Mon, 7 Oct 2024 14:07:17 +0100 Vadim Fedorenko wrote:
> On 05/10/2024 00:05, Jacob Keller wrote:
> > On 10/3/2024 5:39 AM, Vadim Fedorenko wrote:
> >> +/* FBNIC timing & PTP implementation
> >> + * Datapath uses truncated 40b timestamps for scheduling and event reporting.
> >> + * We need to promote those to full 64b, hence we periodically cache the top
> >> + * 32bit of the HW time counter. Since this makes our time reporting non-atomic
> >> + * we leave the HW clock free running and adjust time offsets in SW as needed.
> >> + * Time offset is 64bit - we need a seq counter for 32bit machines.
> >> + * Time offset and the cache of top bits are independent so we don't need
> >> + * a coherent snapshot of both - READ_ONCE()/WRITE_ONCE() + writer side lock
> >> + * are enough.
> >> + */
> >> +
> >
> > If you're going to implement adjustments only in software anyways, can
> > you use a timecounter+cyclecounter instead of re-implementing?
>
> Thanks for pointing this out, I'll make it with timecounter/cyclecounter
Please don't, the clock is synthonized, we only do simple offsetting.
> >> +/* Period of refresh of top bits of timestamp, give ourselves a 8x margin.
> >> + * This should translate to once a minute.
> >> + * The use of nsecs_to_jiffies() should be safe for a <=40b nsec value.
> >> + */
> >> +#define FBNIC_TS_HIGH_REFRESH_JIF nsecs_to_jiffies((1ULL << 40) / 16)
> >> +
> >> +static struct fbnic_dev *fbnic_from_ptp_info(struct ptp_clock_info *ptp)
> >> +{
> >> + return container_of(ptp, struct fbnic_dev, ptp_info);
> >> +}
> >> +
> >> +/* This function is "slow" because we could try guessing which high part
> >> + * is correct based on low instead of re-reading, and skip reading @hi
> >> + * twice altogether if @lo is far enough from 0.
> >> + */
> >> +static u64 __fbnic_time_get_slow(struct fbnic_dev *fbd)
> >> +{
> >> + u32 hi, lo;
> >> +
> >> + lockdep_assert_held(&fbd->time_lock);
> >> +
> >> + do {
> >> + hi = fbnic_rd32(fbd, FBNIC_PTP_CTR_VAL_HI);
> >> + lo = fbnic_rd32(fbd, FBNIC_PTP_CTR_VAL_LO);
> >> + } while (hi != fbnic_rd32(fbd, FBNIC_PTP_CTR_VAL_HI));
> >> +
> >
> > How long does it take hi to overflow? You may be able to get away
> > without looping.
>
> According to comment above it may take up to 8 minutes to overflow, but
> the updates to the cache should be done every minute. We do not expect
> this cycle to happen often.
>
> > I think another way to implement this is to read lo, then hi, then lo
> > again, and if lo2 is smaller than lo, you know hi overflowed and you can
> > re-read hi
>
> That's an option too, I'll think of it, thanks!
The triple read is less neat in case hi jumps by more than 1.
next prev parent reply other threads:[~2024-10-07 23:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-03 12:39 [PATCH net-next v3 0/5] eth: fbnic: add timestamping support Vadim Fedorenko
2024-10-03 12:39 ` [PATCH net-next v3 1/5] eth: fbnic: add software TX " Vadim Fedorenko
2024-10-04 22:55 ` Jacob Keller
2024-10-04 23:18 ` Jacob Keller
2024-10-07 9:56 ` Vadim Fedorenko
2024-10-07 23:52 ` Jacob Keller
2024-10-03 12:39 ` [PATCH net-next v3 2/5] eth: fbnic: add initial PHC support Vadim Fedorenko
2024-10-04 23:05 ` Jacob Keller
2024-10-07 13:07 ` Vadim Fedorenko
2024-10-07 23:09 ` Jakub Kicinski [this message]
2024-10-07 23:49 ` Jacob Keller
2024-10-08 1:16 ` Jakub Kicinski
2024-10-07 23:57 ` Jacob Keller
2024-10-03 12:39 ` [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support Vadim Fedorenko
2024-10-04 23:14 ` Jacob Keller
2024-10-08 16:47 ` Vadim Fedorenko
2024-10-08 17:01 ` Jacob Keller
2024-10-08 17:13 ` Vadim Fedorenko
2024-10-04 23:18 ` Jacob Keller
2024-10-07 10:26 ` Vadim Fedorenko
2024-10-07 23:51 ` Jacob Keller
2024-10-08 9:58 ` Vadim Fedorenko
2024-10-03 12:39 ` [PATCH net-next v3 4/5] eth: fbnic: add TX " Vadim Fedorenko
2024-10-03 12:39 ` [PATCH net-next v3 5/5] eth: fbnic: add ethtool timestamping statistics Vadim Fedorenko
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=20241007160917.591c2d5d@kernel.org \
--to=kuba@kernel.org \
--cc=alexanderduyck@fb.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=vadfed@meta.com \
--cc=vadim.fedorenko@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).