Messages in this thread | | | Date | Wed, 1 Oct 2014 00:17:26 +0200 (CEST) | From | Thomas Gleixner <> | Subject | Re: [PATCH] tile: add clock_gettime support to vDSO |
| |
On Tue, 30 Sep 2014, Chris Metcalf wrote:
> This change adds support for clock_gettime with CLOCK_REALTIME > and CLOCK_MONOTONIC using vDSO. In addition, with this change > we switch to use seqlocks instead of integer counters.
I'd rather split that into two patches. One changing the code to use the seqlock and the other to add the clock_gettime() stuff.
> void update_vsyscall(struct timekeeper *tk) > @@ -263,20 +260,30 @@ void update_vsyscall(struct timekeeper *tk) > struct timespec wall_time = tk_xtime(tk); > struct timespec *wtm = &tk->wall_to_monotonic; > struct clocksource *clock = tk->clock; > + struct timespec ts; > > if (clock != &cycle_counter_cs) > return; > > - /* Userspace gettimeofday will spin while this value is odd. */ > - ++vdso_data->tb_update_count; > - smp_wmb(); > + write_seqcount_begin(&vdso_data->tb_seq); > + > vdso_data->xtime_tod_stamp = clock->cycle_last; > vdso_data->xtime_clock_sec = wall_time.tv_sec; > vdso_data->xtime_clock_nsec = wall_time.tv_nsec; > - vdso_data->wtom_clock_sec = wtm->tv_sec; > - vdso_data->wtom_clock_nsec = wtm->tv_nsec; > + > + ts = timespec_add(wall_time, *wtm); > + vdso_data->wtom_clock_sec = ts.tv_sec; > + vdso_data->wtom_clock_nsec = ts.tv_nsec; > + > vdso_data->mult = clock->mult; > vdso_data->shift = clock->shift; > - smp_wmb(); > - ++vdso_data->tb_update_count; > + > + ts = __current_kernel_time(); > + vdso_data->xtime_clock_coarse_sec = ts.tv_sec; > + vdso_data->xtime_clock_coarse_nsec = ts.tv_nsec; > + ts = timespec_add(ts, *wtm); > + vdso_data->wtom_clock_coarse_sec = ts.tv_sec; > + vdso_data->wtom_clock_coarse_nsec = ts.tv_nsec;
I'm fine with the code, but you might think about doing the math and preparation stuff outside of the seqcount protected region to a shadow struct and then do a simple memcpy inside of the seqcount protected region. Nothing significant, but it might be worthwhile as a follow up or preparatory change.
> +static inline int do_monotonic(struct vdso_data *vdso, struct timespec *ts) > { > + int count; > cycles_t cycles; > - unsigned long count, sec, ns; > - volatile struct vdso_data *vdso_data; > + unsigned long ns; > + > + do { > + count = read_seqcount_begin(&vdso->tb_seq); > + cycles = get_cycles() - vdso->xtime_tod_stamp; > + ns = (cycles * vdso->mult) >> vdso->shift; > + ts->tv_sec = vdso->wtom_clock_sec; > + ts->tv_nsec = vdso->wtom_clock_nsec; > + } while (unlikely(read_seqcount_retry(&vdso->tb_seq, count)));
I doubt that the unlikely makes any difference.
Otherwise this looks good.
Thanks,
tglx
| |