Cache getbintime(9) answer in timehands, similarly to getnanotime(9)

and getmicrotime(9).

Suggested and reviewed by:	bde (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
This commit is contained in:
Konstantin Belousov 2016-07-30 09:25:57 +00:00
parent 6cf1bae2d9
commit 50c22263bb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=303548

View File

@ -68,6 +68,7 @@ struct timehands {
uint64_t th_scale;
u_int th_offset_count;
struct bintime th_offset;
struct bintime th_bintime;
struct timeval th_microtime;
struct timespec th_nanotime;
struct bintime th_boottime;
@ -233,9 +234,8 @@ fbclock_bintime(struct bintime *bt)
do {
th = timehands;
gen = atomic_load_acq_int(&th->th_generation);
*bt = th->th_offset;
*bt = th->th_bintime;
bintime_addx(bt, th->th_scale * tc_delta(th));
bintime_add(bt, &th->th_boottime);
atomic_thread_fence_acq();
} while (gen == 0 || gen != th->th_generation);
}
@ -309,8 +309,7 @@ fbclock_getbintime(struct bintime *bt)
do {
th = timehands;
gen = atomic_load_acq_int(&th->th_generation);
*bt = th->th_offset;
bintime_add(bt, &th->th_boottime);
*bt = th->th_bintime;
atomic_thread_fence_acq();
} while (gen == 0 || gen != th->th_generation);
}
@ -385,9 +384,8 @@ bintime(struct bintime *bt)
do {
th = timehands;
gen = atomic_load_acq_int(&th->th_generation);
*bt = th->th_offset;
*bt = th->th_bintime;
bintime_addx(bt, th->th_scale * tc_delta(th));
bintime_add(bt, &th->th_boottime);
atomic_thread_fence_acq();
} while (gen == 0 || gen != th->th_generation);
}
@ -461,8 +459,7 @@ getbintime(struct bintime *bt)
do {
th = timehands;
gen = atomic_load_acq_int(&th->th_generation);
*bt = th->th_offset;
bintime_add(bt, &th->th_boottime);
*bt = th->th_bintime;
atomic_thread_fence_acq();
} while (gen == 0 || gen != th->th_generation);
}
@ -1385,6 +1382,8 @@ tc_windup(struct bintime *new_boottimebin)
if (bt.sec != t)
th->th_boottime.sec += bt.sec - t;
}
th->th_bintime = th->th_offset;
bintime_add(&th->th_bintime, &th->th_boottime);
/* Update the UTC timestamps used by the get*() functions. */
/* XXX shouldn't do this here. Should force non-`get' versions. */
bintime2timeval(&bt, &th->th_microtime);
@ -1804,9 +1803,8 @@ pps_event(struct pps_state *pps, int event)
/* Convert the count to a timespec. */
tcount = pps->capcount - pps->capth->th_offset_count;
tcount &= pps->capth->th_counter->tc_counter_mask;
bt = pps->capth->th_offset;
bt = pps->capth->th_bintime;
bintime_addx(&bt, pps->capth->th_scale * tcount);
bintime_add(&bt, &pps->capth->th_boottime);
bintime2timespec(&bt, &ts);
/* If the timecounter was wound up underneath us, bail out. */