clock

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package clock turns the tick counter in a completion into nanoseconds.

It is its own package, with no cgo in it, so that the arithmetic can be tested: the conversion lives on the receive path of the fastest backend and is the easiest thing in it to get quietly wrong.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

A Counter converts the ticks of one queue's completions to nanoseconds, carrying the wraps.

The counter in a completion is narrow -- 41 bits on a ConnectX-6 Dx, which at a nanosecond a tick comes back round every 37 minutes -- so scaling it on its own gives a time that jumps backwards by half an hour several times a day, and one interval of about six hundred years each time it does. Anything watching a link for longer than half an hour meets this, and the whole point of a timestamp is the interval between two of them.

So the wraps are counted here and added back, which makes the result rise for as long as the queue is open. A Counter belongs to one queue and is not safe to share, like everything else on the receive path.

func New

func New(i Info) *Counter

New prepares a Counter for a device's clock.

func (*Counter) NS

func (c *Counter) NS(ticks uint64) uint64

NS converts one completion's ticks.

Timestamps that step backwards a little are ordinary: a card stamps a packet at the port and places it in a queue afterwards, so under loss the two orders come apart. A wrap is a step backwards of half the counter, which is eighteen minutes here, so the two cannot be confused by anything the hardware does.

type Info

type Info struct {
	Mult  uint32
	Shift uint32
	Mask  uint64
}

Info is how a device's timestamps convert, as the driver reports it: a duration is ticks * Mult >> Shift, and the counter is Mask bits wide.

func (Info) OK

func (i Info) OK() bool

OK reports whether the device gave a usable conversion. A device that does not report a clock leaves these zero, and every timestamp it produced would convert to zero -- which is why a queue must not offer timestamps at all unless this is true.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL