netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Jacob Keller <jacob.e.keller@intel.com>,
	Vadim Fedorenko <vadfed@meta.com>,
	Jakub Kicinski <kuba@kernel.org>,
	David Ahern <dsahern@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Alexander Duyck <alexanderduyck@fb.com>
Cc: netdev@vger.kernel.org, Richard Cochran <richardcochran@gmail.com>
Subject: Re: [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support
Date: Tue, 8 Oct 2024 17:47:05 +0100	[thread overview]
Message-ID: <09283978-f414-4c77-b48e-f5586fa67edf@linux.dev> (raw)
In-Reply-To: <a64b3bfd-8a85-4523-aad8-e4b534448a0b@intel.com>

On 05/10/2024 00:14, Jacob Keller wrote:
> 
> 
> On 10/3/2024 5:39 AM, Vadim Fedorenko wrote:
>> Add callbacks to support timestamping configuration via ethtool.
>> Add processing of RX timestamps.
>>
>> Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
>>   
>> +/**
>> + * fbnic_ts40_to_ns() - convert descriptor timestamp to PHC time
>> + * @fbn: netdev priv of the FB NIC
>> + * @ts40: timestamp read from a descriptor
>> + *
>> + * Return: u64 value of PHC time in nanoseconds
>> + *
>> + * Convert truncated 40 bit device timestamp as read from a descriptor
>> + * to the full PHC time in nanoseconds.
>> + */
>> +static __maybe_unused u64 fbnic_ts40_to_ns(struct fbnic_net *fbn, u64 ts40)
>> +{
>> +	unsigned int s;
>> +	u64 time_ns;
>> +	s64 offset;
>> +	u8 ts_top;
>> +	u32 high;
>> +
>> +	do {
>> +		s = u64_stats_fetch_begin(&fbn->time_seq);
>> +		offset = READ_ONCE(fbn->time_offset);
>> +	} while (u64_stats_fetch_retry(&fbn->time_seq, s));
>> +
>> +	high = READ_ONCE(fbn->time_high);
>> +
>> +	/* Bits 63..40 from periodic clock reads, 39..0 from ts40 */
>> +	time_ns = (u64)(high >> 8) << 40 | ts40;
>> +
>> +	/* Compare bits 32-39 between periodic reads and ts40,
>> +	 * see if HW clock may have wrapped since last read
>> +	 */
>> +	ts_top = ts40 >> 32;
>> +	if (ts_top < (u8)high && (u8)high - ts_top > U8_MAX / 2)
>> +		time_ns += 1ULL << 40;
>> +
>> +	return time_ns + offset;
>> +}
>> +
> 
> This logic doesn't seem to match the logic used by the cyclecounter
> code, and Its not clear to me if this safe against a race between
> time_high updating and the packet timestamp arriving.
> 
> the timestamp could arrive either before or after the time_high update,
> and the logic needs to ensure the appropriate high bits are applied in
> both cases.

To avoid this race condition we decided to make sure that incoming
timestamps are always later then cached high bits. That will make the
logic above correct.

> Again, I think your use case makes sense to just implement with a
> timecounter and cyclecounter, since you're not modifying the hardware
> cycle counter and are leaving it as free-running.

After discussion with Jakub we decided to keep simple logic without
timecounter + cyclecounter, as it's pretty straight forward.

  reply	other threads:[~2024-10-08 16:47 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
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 [this message]
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=09283978-f414-4c77-b48e-f5586fa67edf@linux.dev \
    --to=vadim.fedorenko@linux.dev \
    --cc=alexanderduyck@fb.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=vadfed@meta.com \
    /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).