user997112
user997112

Reputation: 30655

Nanosecond timing across kernel?

I am planning to write some software direct to an FPGA network card, to catch incoming customised network packets.

Eventually I believe I will send the data obtained either to the kernel or to a user application. This is for a latency-critical trading research project.

What kind of nanosecond timing instruments could I use due to the accuracy required and also the fact that I am timing the duration between reception at the PCI-E network card and receivership in the kernel?

This will be on Linux, with "driver" code (I may put the user application at this level to cut latency) written in C.

Upvotes: 0

Views: 608

Answers (3)

Damon
Damon

Reputation: 70206

clock_gettime uses HPET if available, which is simple and as good and as reliable as you can get.

If HPET is not available, you have no reliable timer at that scale anyway, so unluckily the resolution of clock_gettime will be worse, but that's just what it is, and there's not much you can do about it.

Any other source, including tsc, is either lower resolution or unreliable or both.

Upvotes: 1

Martin Beckett
Martin Beckett

Reputation: 96177

On linux access to the CPU clock tick is through the tsc equivalent to the Windows QueryPerformanceCOunter

Upvotes: 1

Kamyar Souri
Kamyar Souri

Reputation: 1923

In software every thing happens on multiples of system clock. I think you can use any time measurement function that returns the number of elapsed clock ticks, clock() for example should give you enough accuracy.

Upvotes: 0

Related Questions