adopt struct timespec

Replace struct timeval with struct timespec as the main data type for
timestamps. This will allow the NTP code to work with timestamps in
nanosecond resolution.
This commit is contained in:
Miroslav Lichvar
2016-08-17 16:05:53 +02:00
parent 0899ab52dd
commit d0dfa1de9e
46 changed files with 685 additions and 654 deletions

View File

@@ -25,7 +25,7 @@ void
test_unit(void)
{
int i, j, index;
struct timeval tv;
struct timespec ts;
IPAddr ip;
char conf[][100] = {
"clientloglimit 10000",
@@ -44,24 +44,24 @@ test_unit(void)
for (i = 0; i < 500; i++) {
DEBUG_LOG(0, "iteration %d", i);
tv.tv_sec = (time_t)random() & 0x0fffffff;
tv.tv_usec = 0;
ts.tv_sec = (time_t)random() & 0x0fffffff;
ts.tv_nsec = 0;
for (j = 0; j < 1000; j++) {
TST_GetRandomAddress(&ip, IPADDR_UNSPEC, i % 8 ? -1 : i / 8 % 9);
DEBUG_LOG(0, "address %s", UTI_IPToString(&ip));
if (random() % 2) {
index = CLG_LogNTPAccess(&ip, &tv);
index = CLG_LogNTPAccess(&ip, &ts);
TEST_CHECK(index >= 0);
CLG_LimitNTPResponseRate(index);
} else {
index = CLG_LogCommandAccess(&ip, &tv);
index = CLG_LogCommandAccess(&ip, &ts);
TEST_CHECK(index >= 0);
CLG_LimitCommandResponseRate(index);
}
UTI_AddDoubleToTimeval(&tv, (1 << random() % 14) / 100.0, &tv);
UTI_AddDoubleToTimespec(&ts, (1 << random() % 14) / 100.0, &ts);
}
}
@@ -69,8 +69,8 @@ test_unit(void)
TEST_CHECK(ARR_GetSize(records) == 128);
for (i = j = 0; i < 10000; i++) {
tv.tv_sec += 1;
index = CLG_LogNTPAccess(&ip, &tv);
ts.tv_sec += 1;
index = CLG_LogNTPAccess(&ip, &ts);
TEST_CHECK(index >= 0);
if (!CLG_LimitNTPResponseRate(index))
j++;

View File

@@ -29,7 +29,7 @@ test_unit(void)
IPAddr addr;
int i, j, k, l, samples, sel_options;
double offset, delay, disp;
struct timeval tv;
struct timespec ts;
CNF_Initialise(0);
LCL_Initialise();
@@ -61,8 +61,8 @@ test_unit(void)
offset = TST_GetRandomDouble(-1.0, 1.0);
for (k = 0; k < samples; k++) {
SCH_GetLastEventTime(&tv, NULL, NULL);
UTI_AddDoubleToTimeval(&tv, TST_GetRandomDouble(k - samples, k - samples + 1), &tv);
SCH_GetLastEventTime(&ts, NULL, NULL);
UTI_AddDoubleToTimespec(&ts, TST_GetRandomDouble(k - samples, k - samples + 1), &ts);
offset += TST_GetRandomDouble(-1.0e-2, 1.0e-2);
delay = TST_GetRandomDouble(1.0e-6, 1.0e-1);
@@ -71,7 +71,7 @@ test_unit(void)
DEBUG_LOG(0, "source %d sample %d offset %f delay %f disp %f", j, k,
offset, delay, disp);
SRC_AccumulateSample(srcs[j], &tv, offset, delay, disp, delay, disp,
SRC_AccumulateSample(srcs[j], &ts, offset, delay, disp, delay, disp,
1, LEAP_Normal);
}
@@ -124,7 +124,7 @@ test_unit(void)
}
for (j = 0; j < sizeof (srcs) / sizeof (srcs[0]); j++) {
SRC_ReportSource(j, &report, &tv);
SRC_ReportSource(j, &report, &ts);
SRC_DestroyInstance(srcs[j]);
}
}

View File

@@ -150,7 +150,7 @@ apply_step_offset(double offset)
}
static void
offset_convert(struct timeval *raw, double *corr, double *err)
offset_convert(struct timespec *raw, double *corr, double *err)
{
*corr = 0.0;
if (err)