Re: [PATCH v2 03/20] provide get_xtime_and_monotonic_offset() anduse it in hrtimer.c

From: Thomas Gleixner
Date: Mon Jan 31 2011 - 06:39:00 EST


On Thu, 27 Jan 2011, Torben Hohn wrote:

> 2 places in hrtimer need to take the xtime_lock, but we want it
> to be private to kernel/time...
>
> we just provide a function, which gets the values with proper
> read locking the xtime_lock.

Proper sentences start with an uppercase letter.

> @@ -617,10 +612,7 @@ static void retrigger_next_event(void *arg)
> if (!hrtimer_hres_active())
> return;
>
> - do {
> - seq = read_seqbegin(&xtime_lock);
> - wtm = __get_wall_to_monotonic();
> - } while (read_seqretry(&xtime_lock, seq));
> + get_xtime_and_monotonic_offset(NULL, &wtm);
> set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec);

Leaves an unused variable seq. Please do NOT ignore compiler warnings.

> base = &__get_cpu_var(hrtimer_bases);
> diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
> index e4fd957..6085fa5 100644
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -957,3 +957,24 @@ void do_timer(unsigned long ticks)
> jiffies_64 += ticks;
> update_wall_time();
> }
> +
> +/**
> + * get_xtime_and_monotonic_offset() - get xtime and wall_to_monotonic
> + * @xts: pointer to struct timespec, filled with the current_time
> + * @tom: pointer to struct timespec, filled with the wall_to_monotonic offset
> + *
> + * this function does proper locking.
> + * and it allows passing NULL, when one is not interested in the value.
> + */
> +void get_xtime_and_monotonic_offset(struct timespec *xts, struct timespec *tom)
> +{
> + unsigned long seq;
> +
> + do {
> + seq = read_seqbegin(&xtime_lock);
> + if (xts)
> + *xts = xtime;
> + if (tom)
> + *tom = wall_to_monotonic;

That's silly. We can hand in realtime_offset in
retrigger_next_event(). No need for these conditionals.

> + } while (read_seqretry(&xtime_lock, seq));
> +}

Thanks,

tglx

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/