From: Chris Metcalf <cmetcalf@tilera.com>
To: <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
John Stultz <john.stultz@linaro.org>,
Henrik Austad <henrik@austad.us>
Subject: [PATCH v2 1/2] tile: switch to using seqlocks for the vDSO time code
Date: Wed, 1 Oct 2014 16:48:29 -0400 [thread overview]
Message-ID: <201410012113.s91LD3vb022726@farm-0039.internal.tilera.com> (raw)
In-Reply-To: <201409301938.s8UJcfY4018093@lab-40.internal.tilera.com>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
---
arch/tile/include/asm/vdso.h | 5 ++--
arch/tile/kernel/time.c | 16 +++++-------
arch/tile/kernel/vdso/vgettimeofday.c | 46 ++++++++++++-----------------------
3 files changed, 24 insertions(+), 43 deletions(-)
v2: split apart seqlock and new functionality into separate commits
diff --git a/arch/tile/include/asm/vdso.h b/arch/tile/include/asm/vdso.h
index 9f6a78d665fa..d64b0d58a7e9 100644
--- a/arch/tile/include/asm/vdso.h
+++ b/arch/tile/include/asm/vdso.h
@@ -15,6 +15,7 @@
#ifndef __TILE_VDSO_H__
#define __TILE_VDSO_H__
+#include <linux/seqlock.h>
#include <linux/types.h>
/*
@@ -26,8 +27,8 @@
*/
struct vdso_data {
- __u64 tz_update_count; /* Timezone atomicity ctr */
- __u64 tb_update_count; /* Timebase atomicity ctr */
+ seqcount_t tz_seq; /* Timezone seqlock */
+ seqcount_t tb_seq; /* Timebase seqlock */
__u64 xtime_tod_stamp; /* TOD clock for xtime */
__u64 xtime_clock_sec; /* Kernel time second */
__u64 xtime_clock_nsec; /* Kernel time nanosecond */
diff --git a/arch/tile/kernel/time.c b/arch/tile/kernel/time.c
index 462dcd0c1700..0661045f718d 100644
--- a/arch/tile/kernel/time.c
+++ b/arch/tile/kernel/time.c
@@ -249,13 +249,10 @@ cycles_t ns2cycles(unsigned long nsecs)
void update_vsyscall_tz(void)
{
- /* Userspace gettimeofday will spin while this value is odd. */
- ++vdso_data->tz_update_count;
- smp_wmb();
+ write_seqcount_begin(&vdso_data->tz_seq);
vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
vdso_data->tz_dsttime = sys_tz.tz_dsttime;
- smp_wmb();
- ++vdso_data->tz_update_count;
+ write_seqcount_end(&vdso_data->tz_seq);
}
void update_vsyscall(struct timekeeper *tk)
@@ -267,9 +264,8 @@ void update_vsyscall(struct timekeeper *tk)
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;
@@ -277,6 +273,6 @@ void update_vsyscall(struct timekeeper *tk)
vdso_data->wtom_clock_nsec = wtm->tv_nsec;
vdso_data->mult = clock->mult;
vdso_data->shift = clock->shift;
- smp_wmb();
- ++vdso_data->tb_update_count;
+
+ write_seqcount_end(&vdso_data->tb_seq);
}
diff --git a/arch/tile/kernel/vdso/vgettimeofday.c b/arch/tile/kernel/vdso/vgettimeofday.c
index 51ec8e46f5f9..efd00165d654 100644
--- a/arch/tile/kernel/vdso/vgettimeofday.c
+++ b/arch/tile/kernel/vdso/vgettimeofday.c
@@ -53,49 +53,33 @@ inline unsigned long get_datapage(void)
int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
{
cycles_t cycles;
- unsigned long count, sec, ns;
- volatile struct vdso_data *vdso_data;
+ unsigned count;
+ unsigned long sec, ns;
+ struct vdso_data *vdso = (struct vdso_data *)get_datapage();
- vdso_data = (struct vdso_data *)get_datapage();
/* The use of the timezone is obsolete, normally tz is NULL. */
if (unlikely(tz != NULL)) {
- while (1) {
- /* Spin until the update finish. */
- count = vdso_data->tz_update_count;
- if (count & 1)
- continue;
-
- tz->tz_minuteswest = vdso_data->tz_minuteswest;
- tz->tz_dsttime = vdso_data->tz_dsttime;
-
- /* Check whether updated, read again if so. */
- if (count == vdso_data->tz_update_count)
- break;
- }
+ do {
+ count = read_seqcount_begin(&vdso->tz_seq);
+ tz->tz_minuteswest = vdso->tz_minuteswest;
+ tz->tz_dsttime = vdso->tz_dsttime;
+ } while (unlikely(read_seqcount_retry(&vdso->tz_seq, count)));
}
if (unlikely(tv == NULL))
return 0;
- while (1) {
- /* Spin until the update finish. */
- count = vdso_data->tb_update_count;
- if (count & 1)
- continue;
-
- cycles = (get_cycles() - vdso_data->xtime_tod_stamp);
- ns = (cycles * vdso_data->mult) >> vdso_data->shift;
- sec = vdso_data->xtime_clock_sec;
- ns += vdso_data->xtime_clock_nsec;
+ do {
+ count = read_seqcount_begin(&vdso->tb_seq);
+ cycles = (get_cycles() - vdso->xtime_tod_stamp);
+ ns = (cycles * vdso->mult) >> vdso->shift;
+ sec = vdso->xtime_clock_sec;
+ ns += vdso->xtime_clock_nsec;
if (ns >= NSEC_PER_SEC) {
ns -= NSEC_PER_SEC;
sec += 1;
}
-
- /* Check whether updated, read again if so. */
- if (count == vdso_data->tb_update_count)
- break;
- }
+ } while (unlikely(read_seqcount_retry(&vdso->tb_seq, count)));
tv->tv_sec = sec;
tv->tv_usec = ns / 1000;
--
1.8.3.1
next prev parent reply other threads:[~2014-10-01 21:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-30 19:29 [PATCH] tile: add clock_gettime support to vDSO Chris Metcalf
2014-09-30 22:17 ` Thomas Gleixner
2014-09-30 22:30 ` John Stultz
2014-10-01 20:48 ` Chris Metcalf [this message]
2014-10-01 21:02 ` [PATCH v2 2/2] " 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=201410012113.s91LD3vb022726@farm-0039.internal.tilera.com \
--to=cmetcalf@tilera.com \
--cc=henrik@austad.us \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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®