1、64bit的Timestamp Format
The 64-bit timestamp format is used in packet headers and other places with limited word size. It includes a 32-bit unsigned seconds field spanning 136 years and a 32-bit fraction field resolving 232 picoseconds.
1秒 = 1000毫秒 (millisecond) = 1,000,000微秒(microsecond) = 1,000,000,000纳秒(nanosecond) = 1,000,000,000,000皮秒(picosecond)
2、为什么是232 piposeconds?
从时间单位上看,232picosecond 不到四分之一纳秒,为什么单位这么奇怪,不是微秒、纳秒的倍数?
答案隐藏在附录里:
get_time() 函数返回的tstamp是64-bit的timestamp:
typedef unsigned long long tstamp; /* NTP timestamp format */
gettimeofday() 获取的是4字节的秒、4字节微秒:
struct timeval{
long int tv_sec; /* 秒数 */
long int tv_usec; /* 秒数 */
}
所以,U2LFP 直接将struct timeval转换成8字节的timestamp:
#define FRAC 4294967296. /* 2^32 as a double */
#define D2LFP(a) ((tstamp)((a) * FRAC)) /* NTP timestamp */
#define LFP2D(a) ((double)(a) / FRAC)
#define U2LFP(a) (((unsigned long long) \
((a).tv_sec + JAN_1970) << 32) + \
(unsigned long long) \
((a).tv_usec / 1e6 * FRAC))
关注tv_usec部分,tv_usec / 1e6 将微秒转换成秒,再乘以2^32得到64-bit timestamp。
以1微秒为例,转换成的Fraction是: 1 / 1e6 * FRAC = 4294.967296, 取整后 fraction = 4294.
公式反过来:
将Fraction转换成微秒:1 / FRAC * 1e6 = 0.00023283064365386962890625微秒,也就是0.2328纳秒,232.8皮秒。
因此,精度的来源是:将1秒分成2^32份,每份0.00000000023283064365386962890625秒,大约等于232皮秒。
3、5G Qos Monitoring的时间测量采用该64-bit timestamp format进行时延测量,精度 232皮秒。