Esempio n. 1
0
/*
 * Calculate the absolute or boot-relative time from the
 * machine-specific fast timecounter and the published timehands
 * structure read from the shared page.
 *
 * The lockless reading scheme is similar to the one used to read the
 * in-kernel timehands, see sys/kern/kern_tc.c:binuptime().  This code
 * is based on the kernel implementation.
 */
static int
binuptime(struct bintime *bt, struct vdso_timekeep *tk, int abs)
{
    struct vdso_timehands *th;
    uint32_t curr, gen;
    u_int delta;
    int error;

    do {
        if (!tk->tk_enabled)
            return (ENOSYS);

        curr = atomic_load_acq_32(&tk->tk_current);
        th = &tk->tk_th[curr];
        gen = atomic_load_acq_32(&th->th_gen);
        *bt = th->th_offset;
        error = tc_delta(th, &delta);
        if (error == EAGAIN)
            continue;
        if (error != 0)
            return (error);
        bintime_addx(bt, th->th_scale * delta);
        if (abs)
            bintime_add(bt, &th->th_boottime);

        /*
         * Ensure that the load of th_offset is completed
         * before the load of th_gen.
         */
        atomic_thread_fence_acq();
    } while (curr != tk->tk_current || gen == 0 || gen != th->th_gen);
    return (0);
}
Esempio n. 2
0
/*
 * Calculate the absolute or boot-relative time from the
 * machine-specific fast timecounter and the published timehands
 * structure read from the shared page.
 *
 * The lockless reading scheme is similar to the one used to read the
 * in-kernel timehands, see sys/kern/kern_tc.c:binuptime().  This code
 * is based on the kernel implementation.
 */
static int
binuptime(struct bintime *bt, struct vdso_timekeep *tk, int abs)
{
	struct vdso_timehands *th;
	uint32_t curr, gen;

	do {
		if (!tk->tk_enabled)
			return (ENOSYS);

		curr = atomic_load_acq_32(&tk->tk_current);
		th = &tk->tk_th[curr];
		if (th->th_algo != VDSO_TH_ALGO_1)
			return (ENOSYS);
		gen = atomic_load_acq_32(&th->th_gen);
		*bt = th->th_offset;
		bintime_addx(bt, th->th_scale * tc_delta(th));
		if (abs)
			bintime_add(bt, &th->th_boottime);

		/*
		 * Ensure that the load of th_offset is completed
		 * before the load of th_gen.
		 */
		atomic_thread_fence_acq();
	} while (curr != tk->tk_current || gen == 0 || gen != th->th_gen);
	return (0);
}