mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Chris Metcalf <cmetcalf@tilera.com>
Cc: linux-kernel@vger.kernel.org,
	John Stultz <john.stultz@linaro.org>,
	Henrik Austad <henrik@austad.us>
Subject: Re: [PATCH] tile: add clock_gettime support to vDSO
Date: Wed, 1 Oct 2014 00:17:26 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.11.1410010004560.4455@nanos> (raw)
In-Reply-To: <201409301938.s8UJcfY4018093@lab-40.internal.tilera.com>

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

  reply	other threads:[~2014-09-30 22:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-30 19:29 Chris Metcalf
2014-09-30 22:17 ` Thomas Gleixner [this message]
2014-09-30 22:30 ` John Stultz
2014-10-01 20:48   ` [PATCH v2 1/2] tile: switch to using seqlocks for the vDSO time code Chris Metcalf
2014-10-01 21:02   ` [PATCH v2 2/2] tile: add clock_gettime support to vDSO Chris Metcalf
2014-10-02 14:32   ` [PATCH v3 " Chris Metcalf
2014-10-02 17:41     ` John Stultz
2014-10-02 14:48   ` [PATCH v3 1/2] tile: switch to using seqlocks for the vDSO time code Chris Metcalf
2014-10-01 21:24 ` [PATCH] tile: add clock_gettime support to vDSO Henrik Austad
2014-10-02 14:17   ` Chris Metcalf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.11.1410010004560.4455@nanos \
    --to=tglx@linutronix.de \
    --cc=cmetcalf@tilera.com \
    --cc=henrik@austad.us \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®