pcapng: add user-supplied timestamp support
PATCH v3 1/1 pcapng: add user-supplied timestamp support
From: Marek Kasiewicz <[email protected]>
Add rte_pcapng_copy_ts() which accepts a timestamp parameter in nanoseconds since the Unix epoch. When non-zero, the supplied value is used directly. This allows applications to provide hardware PTP timestamps from the NIC, enabling accurate packet capture with PTP-domain timing rather than host-local TSC values.
The existing rte_pcapng_copy() function is preserved as a static inline wrapper that passes zero, keeping the original TSC-based behaviour for callers that do not have a hardware timestamp.
To support both timestamp sources, the per-mbuf timestamp now carries a sentinel bit: when rte_pcapng_copy_ts() is called with ts == 0 it stores the current TSC with bit 63 set. rte_pcapng_write_packets() detects the sentinel, clears it and converts TSC -> epoch ns using the per-file clock before writing. A timestamp supplied by the caller has bit 63 clear and is written unchanged. The sentinel space is safe because the TSC counter does not reach bit 63 for centuries and epoch-ns values stay below bit 63 until the year 2554.
--- .mailmap | 2 ++ lib/pcapng/rte_pcapng.c | 42 +++++++++++++++++++++++++++------------- lib/pcapng/rte_pcapng.h | 43 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 15 deletions(-)
.mailmap +2 -0
@@ -366,6 +366,7 @@ David Zeng <[email protected]> Davide Caratti <[email protected]> Dawid Gorecki <[email protected]> Dawid Jurczak <[email protected]> +Dawid Wesierski <[email protected]> Wesierski, Dawid <[email protected]> Dawid Zielinski <[email protected]> Dawid Łukwiński <[email protected]> Daxue Gao <[email protected]>
@@ -1014,6 +1015,7 @@ Marcin Wilk <[email protected]> Marcin Wojtas <[email protected]> Marcin Zapolski <[email protected]> Marco Varlese <[email protected]> +Marek Kasiewicz <[email protected]> Marek Mical <[email protected]> Marek Zalfresso-jundzillo <[email protected]> Maria Lingemark <[email protected]>
lib/pcapng/rte_pcapng.c +29 -13
72 lines not on this page · raw message
lib/pcapng/rte_pcapng.h +41 -2
64 lines not on this page · raw message
Signature · 9 lines
2.47.3 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
Quoted 5 lines · On Thu, 18 Jun 2026 10:38:15 -0400 Dawid Wesierski <[email protected]>…
+ * @param ts
+ * Packet timestamp in nanoseconds since the Unix epoch. If zero, the + * current TSC is captured and converted to epoch ns by + * rte_pcapng_write_packets() when the packet is written.*
It might help users if a helper rte_tsc_to_epoch() was exposed.
Quoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, 18 June 2026 17.23On Thu, 18 Jun 2026 10:38:15 -0400
Dawid Wesierski <[email protected]> wrote:
Quoted 8 lines
Quoted 2 lines
+ * @param ts
+ * Packet timestamp in nanoseconds since the Unix epoch. If zero,the
Quoted 3 lines
+ * current TSC is captured and converted to epoch ns by
+ *rte_pcapng_write_packets()when the packet is written.
*It might help users if a helper
rte_tsc_to_epoch()was exposed.
+1
Please note that such a helper would need to compensate for rte_rdtsc() drift.
Simplified:
int64_t rte_tsc_to_ns(tsc)
{
struct timespec ts = clock_gettime(CLOCK_REALTIME); int64_t now_ns = ts.tv_sec * NS_PER_S + ts.tv_nsec; int64_t now_tsc = rte_rdtsc();
int64_t diff_tsc = tsc - tsc_now;
return now_ns + diff_tsc * NS_PER_S / rte_get_tsc_hz();
}
A performance optimized version would take "now_ns" and "now_tsc" as parameters.
And with "now_ns" passed as a parameter, the function also works with other clocks, such as CLOCK_MONOTONIC.
Also see this discussion on the Grout mailing list:
https://inbox.dpdk.org/grout/[email protected]/T/#m465a04ca2e8219612dd9c3efb4198d23d5813422
Quoted 30 lines · On Thu, 18 Jun 2026 18:45:19 +0200 Morten Brørup <[email protected]>…
Quoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, 18 June 2026 17.23On Thu, 18 Jun 2026 10:38:15 -0400
Dawid Wesierski <[email protected]> wrote:Quoted 8 lines
Quoted 2 lines
+ * @param ts
+ * Packet timestamp in nanoseconds since the Unix epoch. If zero,the
Quoted 3 lines
+ * current TSC is captured and converted to epoch ns by
+ *rte_pcapng_write_packets()when the packet is written.
*It might help users if a helper
rte_tsc_to_epoch()was exposed.+1
Please note that such a helper would need to compensate for
rte_rdtsc()drift.Simplified:
int64_trte_tsc_to_ns(tsc)
{
struct timespec ts =clock_gettime(CLOCK_REALTIME);int64_tnow_ns= ts.tv_sec *NS_PER_S+ ts.tv_nsec;int64_tnow_tsc=rte_rdtsc();
int64_tdiff_tsc= tsc -tsc_now;
returnnow_ns+diff_tsc*NS_PER_S/rte_get_tsc_hz();
}
Quoted 7 lines
A performance optimized version would take "
now_ns" and "now_tsc" as parameters.
And with "now_ns" passed as a parameter, the function also works with other clocks, such asCLOCK_MONOTONIC.Also see this discussion on the Grout mailing list:
https://inbox.dpdk.org/grout/[email protected]/T/#m465a04ca2e8219612dd9c3efb4198d23d5813422
Inside rte_pcapng is already all the necessary state and setup. Just not exposed to user. It does it without divide operation
PATCH v4 1/1 pcapng: add user-supplied timestamp support
In reply to Dawid WesierskiFrom: "Wesierski, Dawid" <[email protected]>
Introduce rte_pcapng_copy_ts() alongside the existing rte_pcapng_copy() so that callers with a hardware PTP or pre-captured timestamp can inject an exact epoch-ns value directly into the packet record.
Timestamp handling in rte_pcapng_copy_ts():
- ts != 0: caller-supplied nanoseconds since the Unix epoch, stored as-is.
- ts == 0: TSC captured at copy time with bit 63 set as a sentinel. rte_pcapng_write_packets() detects the sentinel and converts the TSC to epoch ns using the file's calibrated clock. The TSC will not reach bit 63 for centuries, and epoch-ns values stay below bit 63 until 2554, so the bit is safe to use as a disambiguation flag.
rte_pcapng_copy() is retained as a real exported function (not an inline wrapper) so the stable ABI symbol is preserved. It simply calls rte_pcapng_copy_ts(..., 0) to capture the current TSC.
rte_pcapng_tsc_to_ns() is added as a new experimental helper (addressing review requests from Stephen Hemminger and Morten Brørup). It exposes the same calibrated, drift-compensated, divide-free TSC-to-epoch-ns conversion used internally by rte_pcapng_write_packets(), allowing callers to convert a TSC captured at packet arrival time before passing it to rte_pcapng_copy_ts().
---
Hi Stephen, Morten,
Thank you very much for your review and comments.
I have prepared a v4 patch.
ABI failure > I have restored rte_pcapng_copy() as a real exported function instead of a static inline wrapper. This should fix the iol-abi-testing failure. It now simply calls rte_pcapng_copy_ts(..., 0) internally.
As suggested, I've added a new experimental function uint64_t rte_pcapng_tsc_to_ns(const rte_pcapng_t *self, uint64_t tsc); I exposed the internal calibrated clock state maintained by the pcapng.
Regards,
Dawid Węsierski.
.mailmap | 2 ++ lib/pcapng/rte_pcapng.c | 71 +++++++++++++++++++++++++++++++++-------- lib/pcapng/rte_pcapng.h | 64 +++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 13 deletions(-)
.mailmap +2 -0
@@ -366,6 +366,7 @@ David Zeng <[email protected]> Davide Caratti <[email protected]> Dawid Gorecki <[email protected]> Dawid Jurczak <[email protected]> +Dawid Wesierski <[email protected]> Wesierski, Dawid <[email protected]> Dawid Zielinski <[email protected]> Dawid Łukwiński <[email protected]> Daxue Gao <[email protected]>
@@ -1014,6 +1015,7 @@ Marcin Wilk <[email protected]> Marcin Wojtas <[email protected]> Marcin Zapolski <[email protected]> Marco Varlese <[email protected]> +Marek Kasiewicz <[email protected]> Marek Mical <[email protected]> Marek Zalfresso-jundzillo <[email protected]> Maria Lingemark <[email protected]>
lib/pcapng/rte_pcapng.c +58 -13
107 lines not on this page · raw message
lib/pcapng/rte_pcapng.h +64 -0
79 lines not on this page · raw message
Signature · 9 lines
2.47.3 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
Quoted 18 lines · On Tue, 23 Jun 2026 10:10:11 -0400 Dawid Wesierski <[email protected]>…
lib/pcapng/rte_pcapng.c +18
-0+/* +* Compatibility wrapper: captures current TSC (converted at write time). +* Equivalent to rte_pcapng_copy_ts(..., 0). +*/ +RTE_EXPORT_SYMBOL (rte_pcapng_copy) +struct rte_mbuf * +rte_pcapng_copy (uint16_t port_id,uint32_t queue, +const struct rte_mbuf *md, +struct rte_mempool *mp, +uint32_t length, +enum rte_pcapng_direction direction, +const char *comment) +{ +return rte_pcapng_copy_ts (port_id, queue, md, mp, length, direction, + comment,0 ); +} + +/*
lib/pcapng/rte_pcapng.c rte_pcapng_copy(uint16_t port_id, uint32_t queue, · line 749
Quoted 10 lines
lib/pcapng/rte_pcapng.c +10
-0+* Convert a TSC value to nanoseconds since the Unix epoch using the +* calibrated clock of the capture file. Uses the same pre-computed +* reciprocal multiplier as the internal write path (no integer division). +*/ +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_tsc_to_ns, 26.07) +uint64_t +rte_pcapng_tsc_to_ns (const rte_pcapng_t *self,uint64_t tsc) +{ +return tsc_to_ns_epoch (&self->clock, tsc); +}
Why not just use function versioning on rte_pcapng_copy() to add new parameter?
Also should add a coverage test app/test/test_pcapng.c
PATCH v5 1/1 pcapng: add user-supplied timestamp support
In reply to Dawid WesierskiIntroduce rte_pcapng_copy_ts() alongside the existing rte_pcapng_copy() so that callers with a hardware PTP or pre-captured timestamp can inject an exact epoch-ns value directly into the packet record.
Timestamp handling in rte_pcapng_copy_ts():
- ts != 0: caller-supplied nanoseconds since the Unix epoch, stored as-is.
- ts == 0: TSC captured at copy time with bit 63 set as a sentinel. rte_pcapng_write_packets() detects the sentinel and converts the TSC to epoch ns using the file's calibrated clock. The TSC will not reach bit 63 for centuries, and epoch-ns values stay below bit 63 until 2554, so the bit is safe to use as a disambiguation flag.
rte_pcapng_copy() is retained as a real exported function (not an inline wrapper) so the stable ABI symbol is preserved. It simply calls rte_pcapng_copy_ts(..., 0) to capture the current TSC.
rte_pcapng_tsc_to_ns() is added as a new experimental helper (addressing review requests from Stephen Hemminger and Morten Brørup). It exposes the same calibrated, drift-compensated, divide-free TSC-to-epoch-ns conversion used internally by rte_pcapng_write_packets(), allowing callers to convert a TSC captured at packet arrival time before passing it to rte_pcapng_copy_ts().
---
Hi Stephen, Morten,
Thank you for the feedback on the previous versions,
In this version i added unit Tests test case in app/test/test_pcapng.c to verify the TSC-to-NS conversion and the custom timestamp injection.
Regards,
Dawid Węsierski
.mailmap | 2 + app/test/test_pcapng.c | 108 ++++++++++++++++++++++++++++++++++++++++ lib/pcapng/rte_pcapng.c | 42 +++++++++++++--- lib/pcapng/rte_pcapng.h | 53 ++++++++++++++++++++ 4 files changed, 199 insertions(+), 6 deletions(-)
.mailmap +2 -0
@@ -366,6 +366,7 @@ David Zeng <[email protected]> Davide Caratti <[email protected]> Dawid Gorecki <[email protected]> Dawid Jurczak <[email protected]> +Dawid Wesierski <[email protected]> Wesierski, Dawid <[email protected]> Dawid Zielinski <[email protected]> Dawid Łukwiński <[email protected]> Daxue Gao <[email protected]>
@@ -1014,6 +1015,7 @@ Marcin Wilk <[email protected]> Marcin Wojtas <[email protected]> Marcin Zapolski <[email protected]> Marco Varlese <[email protected]> +Marek Kasiewicz <[email protected]> Marek Mical <[email protected]> Marek Zalfresso-jundzillo <[email protected]> Maria Lingemark <[email protected]>
app/test/test_pcapng.c +108 -0
120 lines not on this page · raw message
lib/pcapng/rte_pcapng.c +36 -6
76 lines not on this page · raw message
lib/pcapng/rte_pcapng.h +53 -0
59 lines not on this page · raw message
Signature · 9 lines
2.47.3 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
lib/pcapng/rte_pcapng.c rte_pcapng_copy(uint16_t port_id, uint32_t queue, · line 722
Quoted 7 lines · On Wed, 24 Jun 2026 17:57:01 -0400 Dawid Wesierski <[email protected]>…
lib/pcapng/rte_pcapng.c +7
-0+/* +* Use caller provided timestamp. +* If none provided, use current TSC and set flag. +*/ +if (timestamp ==0 ) + timestamp =rte_get_tsc_cycles () |PCAPNG_TSC_FLAG ; +
If you are going to use high bit as flag, then probably need to enforce that that bit is not set on input from user.
lib/pcapng/rte_pcapng.c rte_pcapng_copy(uint16_t port_id, uint32_t queue, · line 581
Quoted 11 lines · On Wed, 24 Jun 2026 17:57:01 -0400 Dawid Wesierski <[email protected]>…
lib/pcapng/rte_pcapng.c +10
-0+ +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_copy_ts, 26.07) +struct rte_mbuf * +rte_pcapng_copy_ts (uint16_t port_id,uint32_t queue, +const struct rte_mbuf *md, +struct rte_mempool *mp, +uint32_t length, +enum rte_pcapng_direction direction, +const char *comment, +uint64_t timestamp) {
I don't think you understood previous feedback.
- use API versioning to provide additional argument to rte_pcapng_copy
- do not introduce another function
The whole adjustment stuff just exists because the scaling parameters are not available in rte_pcapng_copy() which is stateless and doesn't want to have to lookup something in callback pdump_copy_burst.
Would like to have a more generic mechanism in future where timestamp comes from hardware if available on rx. Then would need to have per-port scaling conversion function.
Thanks again for the review,
For v6 I have added the input validation we ccheck if the timestamp PCAPNG_TSC_FLAG is not set on caller-provided input.
Regarding API versioning my concern is around source-level compatibility. Any application that calls rte_pcapng_copy() would need to be updated to pass the additional timestamp argument right?
Is breaking source-level compatibility for existing callers ofrte_pcapng_copy() acceptable here?
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
Quoted 11 lines · On Fri, 26 Jun 2026 06:22:04 -0400 Dawid Wesierski <[email protected]>…
Thanks again for the review,
For v6 I have added the input validation we ccheck if the timestamp
PCAPNG_TSC_FLAGis not set on caller-provided input.Regarding API versioning my concern is around source-level compatibility. Any application that calls
rte_pcapng_copy()would need to be updated to pass the additional timestamp argument right?Is breaking source-level compatibility for existing callers of
rte_pcapng_copy()acceptable here?
DPDK does not guarantee API compatibility across releases; only ABI. As long as there is a release note this is fine.
At this point, might have to wait for 26.11 release anyway.
Also, this is not an API that is commonly used by applications.
PATCH v6 1/1 pcapng: add user-supplied timestamp support
In reply to Dawid WesierskiAdd a timestamp parameter to rte_pcapng_copy() so that callers with a hardware PTP or pre-captured timestamp can inject an exact epoch-ns value directly into the packet record.
Timestamp handling:
- ts != 0: caller-supplied nanoseconds since the Unix epoch, stored as-is.
- ts == 0: TSC captured at copy time with bit 63 set as a sentinel. rte_pcapng_write_packets() detects the sentinel and converts the TSC to epoch ns using the file's calibrated clock. The TSC will not reach bit 63 for centuries, and epoch-ns values stay below bit 63 until 2554, so the bit is safe to use as a disambiguation flag.
Adding the parameter changes the ABI, so rte_pcapng_copy() is versioned.
rte_pcapng_tsc_to_ns() is added as a new experimental helper. It exposes the same calibrated, drift-compensated, divide-free TSC-to-epoch-ns conversion used internally by rte_pcapng_write_packets(), allows callers to convert a TSC captured at packet arrival time before passing it to rte_pcapng_copy().
--- .mailmap | 2 + app/test/test_pcapng.c | 112 +++++++++++++++++++++++++++++++++++++++- lib/graph/graph_pcap.c | 2 +- lib/pcapng/meson.build | 1 + lib/pcapng/rte_pcapng.c | 59 +++++++++++++++++---- lib/pcapng/rte_pcapng.h | 22 +++++++- lib/pdump/rte_pdump.c | 2 +- 7 files changed, 185 insertions(+), 15 deletions(-)
.mailmap +2 -0
@@ -366,6 +366,7 @@ David Zeng <[email protected]> Davide Caratti <[email protected]> Dawid Gorecki <[email protected]> Dawid Jurczak <[email protected]> +Dawid Wesierski <[email protected]> Wesierski, Dawid <[email protected]> Dawid Zielinski <[email protected]> Dawid Łukwiński <[email protected]> Daxue Gao <[email protected]>
@@ -1014,6 +1015,7 @@ Marcin Wilk <[email protected]> Marcin Wojtas <[email protected]> Marcin Zapolski <[email protected]> Marco Varlese <[email protected]> +Marek Kasiewicz <[email protected]> Marek Mical <[email protected]> Marek Zalfresso-jundzillo <[email protected]> Maria Lingemark <[email protected]>
app/test/test_pcapng.c +110 -2
136 lines not on this page · raw message
lib/graph/graph_pcap.c +1 -1
@@ -216,7 +216,7 @@ graph_pcap_dispatch(struct rte_graph *graph,struct rte_mbuf *mc; mbuf = (struct rte_mbuf *)objs[i]; - mc =rte_pcapng_copy (mbuf->port,0 , mbuf, pkt_mp, mbuf->pkt_len,0 , comment); + mc =rte_pcapng_copy (mbuf->port,0 , mbuf, pkt_mp, mbuf->pkt_len,0 , comment,0 );if (mc ==NULL )break ;
lib/pcapng/meson.build +1 -0
@@ -3,5 +3,6 @@ sources = files('rte_pcapng.c') headers = files('rte_pcapng.h') +use_function_versioning = true deps += ['ethdev']
lib/pcapng/rte_pcapng.c +49 -10
103 lines not on this page · raw message
lib/pcapng/rte_pcapng.h +21 -1
@@ -129,6 +129,9 @@ enum rte_pcapng_direction {* @param comment * Optional per packet comment. * Truncated to UINT16_MAX characters. +* @param timestamp +* Nanoseconds since the Unix epoch. If zero, TSC is captured and +* converted at write time. * * @return * - The pointer to the new mbuf formatted for pcapng_write
@@ -138,7 +141,24 @@ struct rte_mbuf * rte_pcapng_copy(uint16_t port_id, uint32_t queue, const struct rte_mbuf *m, struct rte_mempool *mp, uint32_t length, - enum rte_pcapng_direction direction, const char *comment); + enum rte_pcapng_direction direction, + const char *comment, uint64_t timestamp); + +/** +* Convert a TSC value to nanoseconds since the Unix epoch. +* +* Uses the calibrated clock of the capture file. +* +* @param self +* The handle to the packet capture file +* @param tsc +* The TSC value to convert +* @return +* Nanoseconds since Unix epoch +*/ +__rte_experimental +uint64_t +rte_pcapng_tsc_to_ns (const rte_pcapng_t *self,uint64_t tsc);/**
lib/pdump/rte_pdump.c +1 -1
@@ -176,7 +176,7 @@ pdump_copy_burst(uint16_t port_id, uint16_t queue_id,*/ if (cbs->ver ==V2 ) p =rte_pcapng_copy (port_id, queue_id, pkts[i], mp, cbs->snaplen, - direction,NULL ); + direction,NULL ,0 );else p =rte_pktmbuf_copy (pkts[i], mp,0 , cbs->snaplen);
Signature · 9 lines
2.47.3 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
Quoted 14 lines · On Mon, 29 Jun 2026 05:37:33 -0400 Dawid Wesierski <[email protected]>…
Add a timestamp parameter to
rte_pcapng_copy()so that callers with a hardware PTP or pre-captured timestamp can inject an exact epoch-ns value directly into the packet record.Timestamp handling:
- ts != 0: caller-supplied nanoseconds since the Unix epoch, stored as-is.
- ts == 0: TSC captured at copy time with bit 63 set as a sentinel.rte_pcapng_write_packets()detects the sentinel and converts the TSC to epoch ns using the file's calibrated clock. The TSC will not reach bit 63 for centuries, and epoch-ns values stay below bit 63 until 2554, so the bit is safe to use as a disambiguation flag.Adding the parameter changes the ABI, so
rte_pcapng_copy()is versioned.
Quoted 8 lines
rte_pcapng_tsc_to_ns()is added as a new experimental helper. It exposes the same calibrated, drift-compensated, divide-free TSC-to-epoch-ns conversion used internally byrte_pcapng_write_packets(), allows callers to convert a TSC captured at packet arrival time before passing it torte_pcapng_copy().Signed-off-by Marek Kasiewicz <[email protected]>Signed-off-by Dawid Wesierski <[email protected]>---
Looks good, I would like to make some follow on patches to replace the tsc_to_ns routines with something in EAL since it is generally useful to get time in nanoseconds.
PATCH v7 1/1 pcapng: add user-supplied timestamp support
In reply to Dawid WesierskiAdd a timestamp parameter to rte_pcapng_copy(). An application that has a better time for the packet than the TSC at copy time, for example a hardware Rx timestamp, can then give it in nanoseconds since the Unix epoch.
If the timestamp is 0, rte_pcapng_copy() stores the TSC with bit 63 set, and rte_pcapng_write_packets() converts it with the clock of the capture file, as before. A different value goes into the file as it is. The epoch time in nanoseconds sets bit 63 only in the year 2262, so rte_pcapng_copy() rejects a timestamp that sets it.
Add rte_pcapng_tsc_to_ns() to expose the conversion of the capture file clock: a caller can take the TSC at packet arrival, convert it, and give the result to rte_pcapng_copy().
This changes the API of rte_pcapng_copy(). The ABI version changes in 26.11, so the old symbol is not kept.
---
v7:
* Rebased on main for 26.11, after "pcapng: revert use of reciprocal divide for timestamps": the TSC conversion is pcapng_timestamp().
* Removed the function versioning of rte_pcapng_copy(): 26.11 changes the ABI version to 27, and a release note covers the API change. Added the release notes for the API change and the new helper.
* Kept rte_pcapng_tsc_to_ns(), as asked in the v3 review, and tested it against the wall clock.
* Check bit 63 of the timestamp before the mbuf copy, and correct the year in the commit message: epoch nanoseconds reach bit 63 in 2262.
* Test: check that a timestamp with bit 63 is rejected, do not close the capture file two times on an error, and pass the new argument in test_long_timestamp().
* v6 has the state "Accepted" in patchwork, but it is not in main.
v6:
* Rejected a caller timestamp that sets bit 63.
v5:
* Used function versioning on rte_pcapng_copy() instead of a new function, and added a test.
app/test/test_pcapng.c | 115 ++++++++++++++++++++++++- doc/guides/prog_guide/pcapng_lib.rst | 2 + doc/guides/rel_notes/release_26_11.rst | 10 +++ lib/graph/graph_pcap.c | 2 +- lib/pcapng/rte_pcapng.c | 43 +++++++-- lib/pcapng/rte_pcapng.h | 33 ++++++- lib/pdump/rte_pdump.c | 2 +- 7 files changed, 192 insertions(+), 15 deletions(-)
app/test/test_pcapng.c +112 -3
@@ -18,6 +18,8 @@#endif #include <rte_bus_vdev.h> +#include <rte_cycles.h> +#include <rte_errno.h> #include <rte_ethdev.h> #include <rte_ether.h> #include <rte_ip.h>
@@ -303,7 +305,7 @@ fill_pcapng_file(rte_pcapng_t *pcapng)mbuf1_resize (&mbfs,rte_rand_max (MAX_DATA_SIZE )); mc =rte_pcapng_copy (port_id,0 , orig, mp,rte_pktmbuf_pkt_len (orig), -RTE_PCAPNG_DIRECTION_IN , comment); +RTE_PCAPNG_DIRECTION_IN , comment,0 );if (mc ==NULL ) {printf ("Cannot copy packet\n" );return -1 ;
@@ -654,7 +656,7 @@ test_write_before_open(void)for (i =0 ; i < (int )count; i++) { clones[i] =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp,rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), -RTE_PCAPNG_DIRECTION_IN ,NULL ); +RTE_PCAPNG_DIRECTION_IN ,NULL ,0 );if (clones[i] ==NULL ) {fprintf (stderr,"Cannot copy packet before open\n" );rte_pktmbuf_free_bulk (clones, i);
@@ -714,6 +716,112 @@ test_write_before_open(void)return -1 ; } +static int +test_pcapng_timestamp (void ) +{ +char file_name[PATH_MAX ] ="/tmp/pcapng_test_XXXXXX.pcapng" ; +char errbuf[PCAP_ERRBUF_SIZE ]; +rte_pcapng_t *pcapng =NULL ; +struct dummy_mbuf mbfs; +struct pcap_pkthdr h; +struct rte_mbuf *mc; +uint64_t pcap_ts, ns, now_ns, tsc_ns; +pcap_t *pcap; +int ret, tmp_fd; + + tmp_fd =mkstemps (file_name,strlen (".pcapng" )); +if (tmp_fd ==-1 ) { +perror ("mkstemps() failure" ); +return -1 ; + } + + pcapng =rte_pcapng_fdopen (tmp_fd,NULL ,NULL ,"pcapng_ts_test" ,NULL ); +if (pcapng ==NULL ) { +printf ("rte_pcapng_fdopen failed\n" ); +close (tmp_fd); + goto fail; + } + + ret =rte_pcapng_add_interface (pcapng, port_id,DLT_EN10MB ,NULL ,NULL ,NULL ); +if (ret <0 ) { +printf ("can not add port %u\n" , port_id); + goto fail; + } + +/* The helper converts with the clock of the file: close to the wall clock. */ + tsc_ns =rte_pcapng_tsc_to_ns (pcapng,rte_get_tsc_cycles ()); + now_ns =current_timestamp (); +if (tsc_ns +NS_PER_S /10 < now_ns || tsc_ns > now_ns +NS_PER_S /10 ) { +printf ("rte_pcapng_tsc_to_ns: %" PRIu64" ns, wall clock %" PRIu64" ns\n" , + tsc_ns, now_ns); + goto fail; + } + +mbuf1_prepare (&mbfs); + +/* Bit 63 marks a TSC value, so a caller timestamp must not set it. */ + mc =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp, +rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), +RTE_PCAPNG_DIRECTION_IN ,NULL ,UINT64_C (1 ) <<63 ); +if (mc !=NULL || rte_errno !=EINVAL ) { +printf ("rte_pcapng_copy accepted a timestamp with bit 63 set\n" ); +rte_pktmbuf_free (mc); + goto fail; + } + +/* One second ahead, so that it cannot be the TSC of the copy. */ + pcap_ts =current_timestamp () +NS_PER_S ; + mc =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp, +rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), +RTE_PCAPNG_DIRECTION_IN ,"custom_ts" , pcap_ts); +if (mc ==NULL ) { +printf ("rte_pcapng_copy failed\n" ); + goto fail; + } + + ret =rte_pcapng_write_packets (pcapng, &mc,1 ); +rte_pktmbuf_free (mc); +if (ret <=0 ) { +printf ("Write of custom timestamp packet failed\n" ); + goto fail; + } + +rte_pcapng_close (pcapng); + pcapng =NULL ; + + pcap =pcap_open_offline_with_tstamp_precision (file_name, +PCAP_TSTAMP_PRECISION_NANO , + errbuf); +if (pcap ==NULL ) { +printf ("pcap_open_offline failed: %s\n" , errbuf); + goto fail; + } + +if (pcap_next (pcap, &h) ==NULL ) { +printf ("No packets in file\n" ); +pcap_close (pcap); + goto fail; + } +pcap_close (pcap); + +/* With nanosecond precision, tv_usec holds nanoseconds. */ + ns = (uint64_t )h.ts.tv_sec *NS_PER_S + h.ts.tv_usec; +if (ns != pcap_ts) { +printf ("Timestamp mismatch: expected %" PRIu64" got %" PRIu64"\n" , + pcap_ts, ns); + goto fail; + } + +remove (file_name); +return 0 ; + +fail: +if (pcapng) +rte_pcapng_close (pcapng); +remove (file_name); +return -1 ; +} +static void test_cleanup (void ) {
@@ -758,7 +866,7 @@ test_long_timestamp(void) mc =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp,rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), -RTE_PCAPNG_DIRECTION_IN ,NULL ); +RTE_PCAPNG_DIRECTION_IN ,NULL ,0 );TEST_ASSERT (mc !=NULL ,"rte_pcapng_copy failed" ); tmp_fd =mkstemps (file_name,strlen (".pcapng" ));
@@ -826,6 +934,7 @@ unit_test_suite test_pcapng_suite = {TEST_CASE (test_write_packets),TEST_CASE (test_write_before_open),TEST_CASE (test_long_timestamp), +TEST_CASE (test_pcapng_timestamp), TEST_CASES_END() } };
doc/guides/prog_guide/pcapng_lib.rst +2 -0
@@ -32,6 +32,8 @@ to determine the lower bound based on MTU. Collecting packets is done in two parts. The function ``rte_pcapng_copy`` is used to format and copy mbuf data and ``rte_pcapng_write_packets`` writes a burst of packets to the output file. +The timestamp of each packet is the TSC at the time of ``rte_pcapng_copy``, +or the time in nanoseconds that the caller gives to ``rte_pcapng_copy``. The function ``rte_pcapng_write_stats`` can be used to write statistics information into the output file.
doc/guides/rel_notes/release_26_11.rst +10 -0
@@ -206,6 +206,11 @@ New Features when using ``RTE_UNCORE_PM_ENV_AUTO_DETECT``, instead of defaulting only to the Intel uncore driver. +* **Added TSC conversion helper in pcapng.** + + Added ``rte_pcapng_tsc_to_ns`` to convert a TSC value + to nanoseconds since the Unix epoch with the clock of a capture file. + Removed Items -------------
@@ -461,6 +466,11 @@ API Changes * ``rte_tel_data_add_dict_uint_hex`` * ``rte_telemetry_register_cmd_arg`` +* pcapng: Added a ``timestamp`` parameter to ``rte_pcapng_copy``. + The application can give the time of the packet, + for example a hardware Rx timestamp, in nanoseconds since the Unix epoch. + The value 0 keeps the previous behavior: the TSC at copy time is used. + ABI Changes -----------
lib/graph/graph_pcap.c +1 -1
@@ -216,7 +216,7 @@ graph_pcap_dispatch(struct rte_graph *graph,struct rte_mbuf *mc; mbuf = (struct rte_mbuf *)objs[i]; - mc =rte_pcapng_copy (mbuf->port,0 , mbuf, pkt_mp, mbuf->pkt_len,0 , comment); + mc =rte_pcapng_copy (mbuf->port,0 , mbuf, pkt_mp, mbuf->pkt_len,0 , comment,0 );if (mc ==NULL )break ;
lib/pcapng/rte_pcapng.c +35 -8
85 lines not on this page · raw message
lib/pcapng/rte_pcapng.h +31 -2
@@ -129,16 +129,45 @@ enum rte_pcapng_direction {* @param comment * Optional per packet comment. * Truncated to UINT16_MAX characters. +* @param timestamp +* Time of the packet in nanoseconds since the Unix epoch, +* for example a hardware timestamp. Bit 63 must be zero. +* If zero, the current TSC is used, +* and rte_pcapng_write_packets() converts it to the epoch. * * @return * - The pointer to the new mbuf formatted for pcapng_write -* - NULL on error such as invalid port or out of memory. +* - NULL on error such as invalid port, invalid timestamp +* or out of memory. */ struct rte_mbuf *rte_pcapng_copy (uint16_t port_id,uint32_t queue,const struct rte_mbuf *m,struct rte_mempool *mp,uint32_t length, -enum rte_pcapng_direction direction,const char *comment); +enum rte_pcapng_direction direction, +const char *comment,uint64_t timestamp); + +/** +* @warning +* @b EXPERIMENTAL: this API may change, or be removed, without prior notice. +* +* Convert a TSC value to nanoseconds since the Unix epoch. +* +* Uses the calibrated clock of the capture file, the same conversion +* that rte_pcapng_write_packets() applies to a TSC timestamp. +* A caller can take the TSC at packet arrival, convert it, +* and give the result to rte_pcapng_copy(). +* +* @param self +* The handle to the packet capture file. +* @param tsc +* The TSC value to convert. +* @return +* Nanoseconds since the Unix epoch. +*/ +__rte_experimental +uint64_t +rte_pcapng_tsc_to_ns (const rte_pcapng_t *self,uint64_t tsc);/**
lib/pdump/rte_pdump.c +1 -1
@@ -176,7 +176,7 @@ pdump_copy_burst(uint16_t port_id, uint16_t queue_id,*/ if (cbs->ver ==V2 ) p =rte_pcapng_copy (port_id, queue_id, pkts[i], mp, cbs->snaplen, - direction,NULL ); + direction,NULL ,0 );else p =rte_pktmbuf_copy (pkts[i], mp,0 , cbs->snaplen);
base-commit: 2a58f6ea787ad47e97790fc77ec0fe8e17d615c0
Signature · 9 lines
2.43.0 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
lib/pcapng/rte_pcapng.c rte_pcapng_mbuf_size(uint32_t length) · line 454
Quoted 8 lines · On Wed, 14 Oct 2026 17:21:01 +0000 Dawid Wesierski <[email protected]>…
lib/pcapng/rte_pcapng.c +7
-0+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_tsc_to_ns, 26.11) +uint64_t +rte_pcapng_tsc_to_ns (const rte_pcapng_t *self,uint64_t tsc) +{ +return pcapng_timestamp (self, tsc); +} +
Since the tsc_to_ns is independent of the pcapng handle, I had some patches in other work which made it not require pcapng_open and/or move it to EAL. What do you think?
Quoted 14 lines · On Wed, 14 Oct 2026 10:38:58 -0700 Stephen Hemminger…
lib/pcapng/rte_pcapng.c rte_pcapng_mbuf_size(uint32_t length) · line 454
Quoted 7 lines · On Wed, 14 Oct 2026 17:21:01 +0000 Dawid Wesierski <[email protected]>…
lib/pcapng/rte_pcapng.c +7
-0+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_tsc_to_ns, 26.11) +uint64_t +rte_pcapng_tsc_to_ns (const rte_pcapng_t *self,uint64_t tsc) +{ +return pcapng_timestamp (self, tsc); +} +Since the
tsc_to_nsis independent of the pcapng handle, I had some patches in other work which made it not requirepcapng_openand/or move it to EAL. What do you think?
Agreed. The conversion uses only the TSC and wall clock reference that rte_pcapng_fdopen() takes. Nothing else in the handle is necessary. A helper in EAL is better: other code can use it too, for example rpcapd, to stamp a packet with its capture time and not with the time of the burst.
Our application does not need rte_pcapng_tsc_to_ns(). It gives the PTP time of the NIC to rte_pcapng_copy(). Thus I will send v8 without rte_pcapng_tsc_to_ns(), and the patch then does only the API change of rte_pcapng_copy(). Your helper can come in its own series, with its users.
One point for your helper, and for any code that reads back the block from rte_pcapng_copy() before rte_pcapng_write_packets(): with this patch, the timestamp field holds the TSC with bit 63 set, or the caller time in nanoseconds with bit 63 clear.
A question on the schedule. 26.11-rc1 is out, and this patch changes the API of rte_pcapng_copy(). v6 has the state Accepted in patchwork since June, but it is not in main. Can v8 go into 26.11? If it must wait for the next ABI version, please tell me. We will then keep it in our DPDK patch set until that release.
v8 is tested with pcapng_autotest (also with ASan) on 26.11-rc1, and with dpdk-dumpcap on testpmd for the TSC path.
Thanks,
Dawid
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
PATCH v8 1/1 pcapng: add user-supplied timestamp support
In reply to Stephen HemmingerAdd a timestamp parameter to rte_pcapng_copy(). An application that has a better time for the packet than the TSC at copy time, for example a hardware Rx timestamp, can then give it in nanoseconds since the Unix epoch.
If the timestamp is 0, rte_pcapng_copy() stores the TSC with bit 63 set, and rte_pcapng_write_packets() converts it with the clock of the capture file, as before. A different value goes into the file as it is. The epoch time in nanoseconds sets bit 63 only in the year 2262, so rte_pcapng_copy() rejects a timestamp that sets it.
This changes the API of rte_pcapng_copy(). The ABI version changes in 26.11, so the old symbol is not kept.
---
v8:
- Remove rte_pcapng_tsc_to_ns(). The conversion does not need the capture file handle, and it can come later in EAL or without pcapng_open (Stephen Hemminger). The test no longer uses it.
- Say in the doc comment that rte_errno is EINVAL for a timestamp with bit 63 set, and say it in the release note.
- Rebase on 26.11-rc1.
v7:
- Rebase on main after the revert of the reciprocal divide.
app/test/test_pcapng.c | 105 ++++++++++++++++++++++++- doc/guides/prog_guide/pcapng_lib.rst | 3 + doc/guides/rel_notes/release_26_11.rst | 6 ++ lib/graph/graph_pcap.c | 2 +- lib/pcapng/rte_pcapng.c | 36 +++++++-- lib/pcapng/rte_pcapng.h | 12 ++- lib/pdump/rte_pdump.c | 2 +- 7 files changed, 151 insertions(+), 15 deletions(-)
app/test/test_pcapng.c +102 -3
@@ -18,6 +18,7 @@#endif #include <rte_bus_vdev.h> +#include <rte_errno.h> #include <rte_ethdev.h> #include <rte_ether.h> #include <rte_ip.h>
@@ -303,7 +304,7 @@ fill_pcapng_file(rte_pcapng_t *pcapng)mbuf1_resize (&mbfs,rte_rand_max (MAX_DATA_SIZE )); mc =rte_pcapng_copy (port_id,0 , orig, mp,rte_pktmbuf_pkt_len (orig), -RTE_PCAPNG_DIRECTION_IN , comment); +RTE_PCAPNG_DIRECTION_IN , comment,0 );if (mc ==NULL ) {printf ("Cannot copy packet\n" );return -1 ;
@@ -654,7 +655,7 @@ test_write_before_open(void)for (i =0 ; i < (int )count; i++) { clones[i] =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp,rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), -RTE_PCAPNG_DIRECTION_IN ,NULL ); +RTE_PCAPNG_DIRECTION_IN ,NULL ,0 );if (clones[i] ==NULL ) {fprintf (stderr,"Cannot copy packet before open\n" );rte_pktmbuf_free_bulk (clones, i);
@@ -714,6 +715,103 @@ test_write_before_open(void)return -1 ; } +static int +test_pcapng_timestamp (void ) +{ +char file_name[PATH_MAX ] ="/tmp/pcapng_test_XXXXXX.pcapng" ; +char errbuf[PCAP_ERRBUF_SIZE ]; +rte_pcapng_t *pcapng =NULL ; +struct dummy_mbuf mbfs; +struct pcap_pkthdr h; +struct rte_mbuf *mc; +uint64_t pcap_ts, ns; +pcap_t *pcap; +int ret, tmp_fd; + + tmp_fd =mkstemps (file_name,strlen (".pcapng" )); +if (tmp_fd ==-1 ) { +perror ("mkstemps() failure" ); +return -1 ; + } + + pcapng =rte_pcapng_fdopen (tmp_fd,NULL ,NULL ,"pcapng_ts_test" ,NULL ); +if (pcapng ==NULL ) { +printf ("rte_pcapng_fdopen failed\n" ); +close (tmp_fd); + goto fail; + } + + ret =rte_pcapng_add_interface (pcapng, port_id,DLT_EN10MB ,NULL ,NULL ,NULL ); +if (ret <0 ) { +printf ("can not add port %u\n" , port_id); + goto fail; + } + +mbuf1_prepare (&mbfs); + +/* Bit 63 marks a TSC value, so a caller timestamp must not set it. */ + mc =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp, +rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), +RTE_PCAPNG_DIRECTION_IN ,NULL ,UINT64_C (1 ) <<63 ); +if (mc !=NULL || rte_errno !=EINVAL ) { +printf ("rte_pcapng_copy accepted a timestamp with bit 63 set\n" ); +rte_pktmbuf_free (mc); + goto fail; + } + +/* One second ahead, so that it cannot be the TSC of the copy. */ + pcap_ts =current_timestamp () +NS_PER_S ; + mc =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp, +rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), +RTE_PCAPNG_DIRECTION_IN ,"custom_ts" , pcap_ts); +if (mc ==NULL ) { +printf ("rte_pcapng_copy failed\n" ); + goto fail; + } + + ret =rte_pcapng_write_packets (pcapng, &mc,1 ); +rte_pktmbuf_free (mc); +if (ret <=0 ) { +printf ("Write of custom timestamp packet failed\n" ); + goto fail; + } + +rte_pcapng_close (pcapng); + pcapng =NULL ; + + pcap =pcap_open_offline_with_tstamp_precision (file_name, +PCAP_TSTAMP_PRECISION_NANO , + errbuf); +if (pcap ==NULL ) { +printf ("pcap_open_offline failed: %s\n" , errbuf); + goto fail; + } + +if (pcap_next (pcap, &h) ==NULL ) { +printf ("No packets in file\n" ); +pcap_close (pcap); + goto fail; + } +pcap_close (pcap); + +/* With nanosecond precision, tv_usec holds nanoseconds. */ + ns = (uint64_t )h.ts.tv_sec *NS_PER_S + h.ts.tv_usec; +if (ns != pcap_ts) { +printf ("Timestamp mismatch: expected %" PRIu64" got %" PRIu64"\n" , + pcap_ts, ns); + goto fail; + } + +remove (file_name); +return 0 ; + +fail: +if (pcapng) +rte_pcapng_close (pcapng); +remove (file_name); +return -1 ; +} +static void test_cleanup (void ) {
@@ -758,7 +856,7 @@ test_long_timestamp(void) mc =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp,rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), -RTE_PCAPNG_DIRECTION_IN ,NULL ); +RTE_PCAPNG_DIRECTION_IN ,NULL ,0 );TEST_ASSERT (mc !=NULL ,"rte_pcapng_copy failed" ); tmp_fd =mkstemps (file_name,strlen (".pcapng" ));
@@ -826,6 +924,7 @@ unit_test_suite test_pcapng_suite = {TEST_CASE (test_write_packets),TEST_CASE (test_write_before_open),TEST_CASE (test_long_timestamp), +TEST_CASE (test_pcapng_timestamp), TEST_CASES_END() } };
doc/guides/prog_guide/pcapng_lib.rst +3 -0
@@ -32,6 +32,9 @@ to determine the lower bound based on MTU. Collecting packets is done in two parts. The function ``rte_pcapng_copy`` is used to format and copy mbuf data and ``rte_pcapng_write_packets`` writes a burst of packets to the output file. +The timestamp of each packet is the time in nanoseconds +that the caller gives to ``rte_pcapng_copy``. +If the caller gives 0, it is the TSC at the time of ``rte_pcapng_copy``. The function ``rte_pcapng_write_stats`` can be used to write statistics information into the output file.
doc/guides/rel_notes/release_26_11.rst +6 -0
@@ -545,6 +545,12 @@ API Changes * ``rte_tel_data_add_dict_uint_hex`` * ``rte_telemetry_register_cmd_arg`` +* pcapng: Added a ``timestamp`` parameter to ``rte_pcapng_copy``. + The application can give the time of the packet, + for example a hardware Rx timestamp, in nanoseconds since the Unix epoch. + The value 0 keeps the previous behavior: the TSC at copy time is used. + A timestamp with bit 63 set is rejected. + ABI Changes -----------
lib/graph/graph_pcap.c +1 -1
@@ -216,7 +216,7 @@ graph_pcap_dispatch(struct rte_graph *graph,struct rte_mbuf *mc; mbuf = (struct rte_mbuf *)objs[i]; - mc =rte_pcapng_copy (mbuf->port,0 , mbuf, pkt_mp, mbuf->pkt_len,0 , comment); + mc =rte_pcapng_copy (mbuf->port,0 , mbuf, pkt_mp, mbuf->pkt_len,0 , comment,0 );if (mc ==NULL )break ;
lib/pcapng/rte_pcapng.c +28 -8
@@ -36,6 +36,9 @@/* upper bound for strings in pcapng option data */ #define PCAPNG_STR_MAX UINT16_MAX +/* Flag to indicate timestamp is in TSC cycles (bit 63) */ +#define PCAPNG_TSC_FLAG (1ULL << 63) +/* Format of the capture file handle */ struct rte_pcapng {int outfd;/* output file */
@@ -515,12 +518,12 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,struct rte_mempool *mp, uint32_t length, enum rte_pcapng_direction direction, - const char *comment) + const char *comment, + uint64_t timestamp) { struct pcapng_enhance_packet_block *epb;uint32_t orig_len, pkt_len, padding, flags;struct pcapng_option *opt; -uint64_t timestamp;uint16_t optlen;struct rte_mbuf *mc;bool rss_hash;
@@ -532,6 +535,12 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,*/ RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id,NULL );#endif +/* Bit 63 marks a TSC value, see rte_pcapng_write_packets(). */ +if (unlikely (timestamp &PCAPNG_TSC_FLAG )) { + rte_errno =EINVAL ; +return NULL ; + } + orig_len =rte_pktmbuf_pkt_len (md);/* Take snapshot of the data */
@@ -652,8 +661,13 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,/* Interface index is filled in later during write */ mc->port = port_id; -/* Put timestamp in cycles here - adjust in packet write */ - timestamp =rte_get_tsc_cycles (); +/* +* Without a caller timestamp, put the TSC here and set the flag. +* rte_pcapng_write_packets() converts it to epoch nanoseconds. +*/ +if (timestamp ==0 ) + timestamp =rte_get_tsc_cycles () |PCAPNG_TSC_FLAG ; + epb->timestamp_hi = timestamp >>32 ; epb->timestamp_lo = (uint32_t )timestamp; epb->capture_length = pkt_len;
@@ -699,12 +713,18 @@ rte_pcapng_write_packets(rte_pcapng_t *self,return -1 ; } -/* adjust timestamp recorded in packet */ +/* +* If rte_pcapng_copy() stored the TSC (flag bit set), +* convert it to PCAP epoch units. Else the caller gave +* the time in nanoseconds since the epoch: keep it. +*/ cycles = (uint64_t )epb->timestamp_hi <<32 ; cycles += epb->timestamp_lo; - timestamp =pcapng_timestamp (self, cycles); - epb->timestamp_hi = timestamp >>32 ; - epb->timestamp_lo = (uint32_t )timestamp; +if (cycles &PCAPNG_TSC_FLAG ) { + timestamp =pcapng_timestamp (self, cycles & ~PCAPNG_TSC_FLAG ); + epb->timestamp_hi = timestamp >>32 ; + epb->timestamp_lo = (uint32_t )timestamp; + }/* * Handle case of highly fragmented and large burst size
lib/pcapng/rte_pcapng.h +10 -2
@@ -129,16 +129,24 @@ enum rte_pcapng_direction {* @param comment * Optional per packet comment. * Truncated to UINT16_MAX characters. +* @param timestamp +* Time of the packet in nanoseconds since the Unix epoch, +* for example a hardware timestamp. Bit 63 must be zero. +* If zero, the current TSC is used, +* and rte_pcapng_write_packets() converts it to the epoch. * * @return * - The pointer to the new mbuf formatted for pcapng_write -* - NULL on error such as invalid port or out of memory. +* - NULL on error such as invalid port, invalid timestamp +* or out of memory. rte_errno is EINVAL if bit 63 of +* the timestamp is set. */ struct rte_mbuf *rte_pcapng_copy (uint16_t port_id,uint32_t queue,const struct rte_mbuf *m,struct rte_mempool *mp,uint32_t length, -enum rte_pcapng_direction direction,const char *comment); +enum rte_pcapng_direction direction, +const char *comment,uint64_t timestamp);/**
lib/pdump/rte_pdump.c +1 -1
@@ -176,7 +176,7 @@ pdump_copy_burst(uint16_t port_id, uint16_t queue_id,*/ if (cbs->ver ==V2 ) p =rte_pcapng_copy (port_id, queue_id, pkts[i], mp, cbs->snaplen, - direction,NULL ); + direction,NULL ,0 );else p =rte_pktmbuf_copy (pkts[i], mp,0 , cbs->snaplen);
base-commit: 9a45341f18a1ab47af7123e63d942b90c1b79f38
Signature · 9 lines
2.43.0 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
cover pcapng timestamp conversion and user-supplied timestamps
This extends the proposed user-supplied timestamps.
The pcapng library converts the TSC into nanoseconds since 1/1/1970, because that is what the pcapng file format records. Make that function available for more general use.
The third patch is Dawid's v8, rebased on the first two.
Some rework was needed to fit in because because adding
new parameter to existing function creates lot of API and deprecation headaches so rte_pcapng_copy_ts() is added as a new experimental function instead.
Dawid Wesierski (1):
pcapng: add user-supplied timestamp support
Stephen Hemminger (2):
eal: add function to convert TSC to epoch time
pcapng: use EAL TSC to epoch conversion
app/test/test_pcapng.c | 108 +++++++++++++++++++++++++++-- doc/api/doxy-api-index.md | 1 + doc/guides/prog_guide/pcapng_lib.rst | 4 ++ doc/guides/rel_notes/release_26_11.rst | 13 ++++ lib/eal/common/eal_common_timer.c | 59 ++++++++++++++++ lib/eal/include/rte_time.h | 34 +++++++++ lib/pcapng/rte_pcapng.c | 122 ++++++++++++++++++--------------- lib/pcapng/rte_pcapng.h | 54 ++++++++++++++- 8 files changed, 333 insertions(+), 62 deletions(-)
Dawid Wesierski (1):
pcapng: add user-supplied timestamp support
Stephen Hemminger (2):
eal: add function to convert TSC to epoch time
pcapng: use EAL TSC to epoch conversion
app/test/test_pcapng.c | 108 +++++++++++++++++++++- doc/api/doxy-api-index.md | 1 + doc/guides/prog_guide/pcapng_lib.rst | 4 + doc/guides/rel_notes/release_26_11.rst | 13 +++ lib/eal/common/eal_common_timer.c | 59 ++++++++++++ lib/eal/include/rte_time.h | 34 +++++++ lib/pcapng/rte_pcapng.c | 122 +++++++++++++------------ lib/pcapng/rte_pcapng.h | 54 ++++++++++- 8 files changed, 333 insertions(+), 62 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/3 eal: add function to convert TSC to epoch time
The pcapng library converts the TSC into nanoseconds since 1/1/1970, because that is what the pcapng file format records. Nothing about that conversion is specific to packet capture: it needs the TSC frequency and a reference point relating the TSC to the wall clock, both of which EAL already has or can take at init.
Record the TSC alongside a CLOCK_REALTIME reading while the TSC frequency is being determined, and add rte_tsc_to_ns() to convert any TSC value using that reference point. The seconds are computed before the remainder is scaled, so the multiply by NS_PER_S cannot overflow.
The reference point is taken per process rather than shared through the memory config, so a secondary process may differ from the primary by the sampling error.
--- doc/api/doxy-api-index.md | 1 + doc/guides/rel_notes/release_26_11.rst | 6 +++ lib/eal/common/eal_common_timer.c | 59 ++++++++++++++++++++++++++ lib/eal/include/rte_time.h | 34 +++++++++++++++ 4 files changed, 100 insertions(+)
doc/api/doxy-api-index.md +1 -0
@@ -73,6 +73,7 @@ The public API headers are grouped by topics: - **timers**: [cycles](@ref rte_cycles.h), + [time](@ref rte_time.h), [timer](@ref rte_timer.h), [alarm](@ref rte_alarm.h)
doc/guides/rel_notes/release_26_11.rst +6 -0
@@ -73,6 +73,12 @@ New Features Added the experimental ``rte_cpu_socket_id()`` function to map an OS logical CPU ID to the NUMA socket containing that CPU. +* **Added API to convert TSC to epoch time.** + + Added the experimental ``rte_tsc_to_ns()`` function in ``rte_time.h`` + to convert a TSC value into nanoseconds since 1/1/1970, + using a reference point recorded during EAL initialization. + * **Added pile stack and mempool driver.** Introduced pile, a lock-free, stack-like implementation,
lib/eal/common/eal_common_timer.c +59 -0
97 lines not on this page · raw message
lib/eal/include/rte_time.h +34 -0
@@ -5,9 +5,17 @@ #ifndef _RTE_TIME_H_ #define _RTE_TIME_H_ +/** + * @file + * + * Time and cycle counter conversion. + */ + #include <stdint.h> #include <time.h> +#include <rte_compat.h> + #ifdef __cplusplus extern "C" { #endif
@@ -102,6 +110,32 @@ rte_ns_to_timespec(uint64_t nsec)return ts; } +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Convert a TSC value into nanoseconds since the Unix epoch. +* +* EAL records the TSC alongside a CLOCK_REALTIME reading during +* initialization, and this converts using that reference point and the +* TSC frequency. Values sampled before initialization are also handled, +* and the result tracks the wall clock as it was at init: later changes +* to the system time are not reflected. +* +* Each process takes its own reference point, so values converted in a +* secondary process may differ from the primary by the sampling error. +* +* Must be called after rte_eal_init(), which fails if the TSC frequency +* cannot be determined. +* +* @param tsc +* A value read from rte_get_tsc_cycles() or rte_rdtsc(). +* @return +* Nanoseconds since 1/1/1970. +*/ +__rte_experimental +uint64_t rte_tsc_to_ns(uint64_t tsc); + #ifdef __cplusplus }#endif
Signature · 1 line
2.53.0
PATCH 2/3 pcapng: use EAL TSC to epoch conversion
In reply to Stephen HemmingerThe pcapng library carried its own TSC to nanoseconds conversion along with the reference point it needs: the TSC and wall clock sampled when the capture file was opened. EAL now records an equivalent reference point at init and exposes rte_tsc_to_ns(), so the local copy is redundant.
Convert timestamps with rte_tsc_to_ns() and drop the per-handle reference point. The interface statistics block still reports when the file was opened rather than when EAL started, so that time is kept in the handle, now derived from the TSC like every other timestamp.
--- app/test/test_pcapng.c | 8 +++---- lib/pcapng/rte_pcapng.c | 52 +++++------------------------------------ 2 files changed, 10 insertions(+), 50 deletions(-)
app/test/test_pcapng.c +4 -4
@@ -648,8 +648,8 @@ test_write_before_open(void)mbuf1_prepare (&mbfs);mbuf1_resize (&mbfs,rte_rand_max (MAX_DATA_SIZE )); -/* Copy packets BEFORE opening the pcapng file. -* This exercises the negative TSC delta path. +/* Copy packets BEFORE opening the pcapng file, so their +* timestamps precede the capture start time. */ for (i =0 ; i < (int )count; i++) { clones[i] = rte_pcapng_copy(port_id, 0, &mbfs.mb[0], mp,
@@ -662,7 +662,7 @@ test_write_before_open(void) } } -/* Small delay so fdopen's tsc_base is measurably after the copies */ +/* Small delay so the capture start is measurably after the copies */ rte_delay_us_block (100 ); now =current_timestamp ();
@@ -689,7 +689,7 @@ test_write_before_open(void) goto fail; } -/* Write the pre-captured packets — timestamps precede tsc_base */ +/* Write the pre-captured packets */ len =rte_pcapng_write_packets (pcapng, clones, count);rte_pktmbuf_free_bulk (clones, count);if (len <=0 ) {
lib/pcapng/rte_pcapng.c +6 -46
99 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 3/3 pcapng: add user-supplied timestamp support
In reply to Stephen HemmingerFrom: Dawid Wesierski <[email protected]>
An application may have a better time for a packet than the TSC at copy time, for example a hardware Rx timestamp, but rte_pcapng_copy() always timestamps with the TSC.
Add rte_pcapng_copy_ts(), which takes the time of the packet in nanoseconds since the Unix epoch. Both entry points share one
implementation: rte_pcapng_copy() reads the TSC and sets bit 63 to mark it, and rte_pcapng_write_packets() converts a marked value with rte_tsc_to_ns(). Epoch time in nanoseconds sets bit 63 only in the year 2262, so rte_pcapng_copy_ts() rejects a timestamp that sets it.
rte_pcapng_copy() keeps its signature, so no API or ABI is broken and no deprecation notice is needed. The new function is experimental.
--- app/test/test_pcapng.c | 100 +++++++++++++++++++++++++ doc/guides/prog_guide/pcapng_lib.rst | 4 + doc/guides/rel_notes/release_26_11.rst | 7 ++ lib/pcapng/rte_pcapng.c | 72 +++++++++++++++--- lib/pcapng/rte_pcapng.h | 54 ++++++++++++- 5 files changed, 224 insertions(+), 13 deletions(-)
app/test/test_pcapng.c +100 -0
@@ -18,6 +18,7 @@#endif #include <rte_bus_vdev.h> +#include <rte_errno.h> #include <rte_ethdev.h> #include <rte_ether.h> #include <rte_ip.h>
@@ -714,6 +715,104 @@ test_write_before_open(void)return -1 ; } +static int +test_pcapng_timestamp (void ) +{ +char file_name[PATH_MAX ] ="/tmp/pcapng_test_XXXXXX.pcapng" ; +char errbuf[PCAP_ERRBUF_SIZE ]; +rte_pcapng_t *pcapng =NULL ; +struct dummy_mbuf mbfs; +struct pcap_pkthdr h; +struct rte_mbuf *mc; +uint64_t pcap_ts, ns; +pcap_t *pcap; +int ret, tmp_fd; + + tmp_fd =mkstemps (file_name,strlen (".pcapng" )); +if (tmp_fd ==-1 ) { +perror ("mkstemps() failure" ); +return -1 ; + } + + pcapng =rte_pcapng_fdopen (tmp_fd,NULL ,NULL ,"pcapng_ts_test" ,NULL ); +if (pcapng ==NULL ) { +printf ("rte_pcapng_fdopen failed\n" ); +close (tmp_fd); + goto fail; + } + + ret =rte_pcapng_add_interface (pcapng, port_id,DLT_EN10MB ,NULL ,NULL ,NULL ); +if (ret <0 ) { +printf ("can not add port %u\n" , port_id); + goto fail; + } + +mbuf1_prepare (&mbfs); + +/* Bit 63 marks a TSC value, so a caller timestamp must not set it. */ + mc =rte_pcapng_copy_ts (port_id,0 , &mbfs.mb[0 ], mp, +rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), +RTE_PCAPNG_DIRECTION_IN ,NULL , +UINT64_C (1 ) <<63 ); +if (mc !=NULL || rte_errno !=EINVAL ) { +printf ("rte_pcapng_copy_ts accepted a timestamp with bit 63 set\n" ); +rte_pktmbuf_free (mc); + goto fail; + } + +/* One second ahead, so that it cannot be the TSC of the copy. */ + pcap_ts =current_timestamp () +NS_PER_S ; + mc =rte_pcapng_copy_ts (port_id,0 , &mbfs.mb[0 ], mp, +rte_pktmbuf_pkt_len (&mbfs.mb[0 ]), +RTE_PCAPNG_DIRECTION_IN ,"custom_ts" , pcap_ts); +if (mc ==NULL ) { +printf ("rte_pcapng_copy_ts failed\n" ); + goto fail; + } + + ret =rte_pcapng_write_packets (pcapng, &mc,1 ); +rte_pktmbuf_free (mc); +if (ret <=0 ) { +printf ("Write of custom timestamp packet failed\n" ); + goto fail; + } + +rte_pcapng_close (pcapng); + pcapng =NULL ; + + pcap =pcap_open_offline_with_tstamp_precision (file_name, +PCAP_TSTAMP_PRECISION_NANO , + errbuf); +if (pcap ==NULL ) { +printf ("pcap_open_offline failed: %s\n" , errbuf); + goto fail; + } + +if (pcap_next (pcap, &h) ==NULL ) { +printf ("No packets in file\n" ); +pcap_close (pcap); + goto fail; + } +pcap_close (pcap); + +/* With nanosecond precision, tv_usec holds nanoseconds. */ + ns = (uint64_t )h.ts.tv_sec *NS_PER_S + h.ts.tv_usec; +if (ns != pcap_ts) { +printf ("Timestamp mismatch: expected %" PRIu64" got %" PRIu64"\n" , + pcap_ts, ns); + goto fail; + } + +remove (file_name); +return 0 ; + +fail: +if (pcapng) +rte_pcapng_close (pcapng); +remove (file_name); +return -1 ; +} +static void test_cleanup (void ) {
@@ -826,6 +925,7 @@ unit_test_suite test_pcapng_suite = {TEST_CASE (test_write_packets),TEST_CASE (test_write_before_open),TEST_CASE (test_long_timestamp), +TEST_CASE (test_pcapng_timestamp), TEST_CASES_END() } };
doc/guides/prog_guide/pcapng_lib.rst +4 -0
@@ -32,6 +32,10 @@ to determine the lower bound based on MTU. Collecting packets is done in two parts. The function ``rte_pcapng_copy`` is used to format and copy mbuf data and ``rte_pcapng_write_packets`` writes a burst of packets to the output file. +The timestamp of each packet is the TSC at the time of ``rte_pcapng_copy``. +An application that has a better time for the packet, +for example a hardware timestamp, +can give it in nanoseconds to ``rte_pcapng_copy_ts`` instead. The function ``rte_pcapng_write_stats`` can be used to write statistics information into the output file.
doc/guides/rel_notes/release_26_11.rst +7 -0
@@ -79,6 +79,13 @@ New Features to convert a TSC value into nanoseconds since 1/1/1970, using a reference point recorded during EAL initialization. +* **Added pcapng support for user-supplied timestamps.** + + Added the experimental ``rte_pcapng_copy_ts()`` function, + which takes the time of the packet in nanoseconds since the Unix epoch, + for example a hardware Rx timestamp. + ``rte_pcapng_copy()`` is unchanged and still uses the TSC at copy time. + * **Added pile stack and mempool driver.** Introduced pile, a lock-free, stack-like implementation,
lib/pcapng/rte_pcapng.c +60 -12
112 lines not on this page · raw message
lib/pcapng/rte_pcapng.h +53 -1
65 lines not on this page · raw message
Signature · 1 line
2.53.0
Thanks, Stephen.
The proposed rte_pcapng_copy_ts() API matches the interface used by MTL. OpenVisualCloud/Media-Transport-Library#1849 checks MTL's packet timestamp output.
I have no objections to patch 3/3.
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
Re: [PATCH 0/3] pcapng timestamp conversion and user-supplied timestamps
In reply to Stephen HemmingerQuoted 10 lines · On Tue, 20 Oct 2026 10:55:41 -0700 Stephen Hemminger…
This extends the proposed user-supplied timestamps.
The pcapng library converts the TSC into nanoseconds since 1/1/1970, because that is what the pcapng file format records. Make that function available for more general use.
The third patch is Dawid's v8, rebased on the first two.
Some rework was needed to fit in because because adding
new parameter to existing function creates lot of API and deprecation headaches sorte_pcapng_copy_ts()is added as a new experimental function instead.
FYI - AI says its own review is bogus..
1/3 Error, clock_gettime() failure: noise. CLOCK_REALTIME with a valid timespec cannot fail on Linux, FreeBSD, or the Windows shim. This is the same class as the pthread_mutex_init() false positive. Both suggested fixes are worse than the code. Failing EAL init over an unreachable path is overkill. rte_panic() in a library is unacceptable. The eal_tsc_base == 0 sentinel is also wrong, because base 0 already has a meaning.
1/3 Warning, missing test: weak. rte_tsc_to_ns() is already exercised through test_pcapng (test_write_before_open, test_long_timestamp). The suggested test is broken: it reads ts1/ts2 and never uses them. It only checks the frequency, not the epoch offset, which is the thing the API adds.
3/3 “Error” on 1ULL << 63: the bot raised it and then concluded “Not a finding”. That is exactly the retract-inline pattern AGENTS.md already forbids. Its own Pass 2 then claims nothing like that was left in, so the self-check is false.
3/3 testpmd hook: it invents a testpmd --pcap=<file> mode, which does not exist. It then talks itself out of the finding and ends with “No action required”. This should have been omitted.
2/3 “None”: should have been omitted entirely, not acknowledged as clean.