On Thu, 18 Jun 2026 18:45:19 +0200
Morten Brørup <[email protected]> wrote:

> > From: Stephen Hemminger [mailto:[email protected]]
> > Sent: Thursday, 18 June 2026 17.23
> > 
> > On Thu, 18 Jun 2026 10:38:15 -0400
> > Dawid Wesierski <[email protected]> wrote:
> >   
> > > + * @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.  
> 
> +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
> 
> 

Inside rte_pcapng is already all the necessary state and setup.
Just not exposed to user. It does it without divide operation

Reply via email to