From: Thomas Gleixner <tglx@linutronix.de>
To: "Sverdlin, Alexander (Nokia - DE/Ulm)" <alexander.sverdlin@nokia.com>
Cc: "x86@kernel.org" <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com>,
Jason Vas Dias <jason.vas.dias@gmail.com>
Subject: Re: [PATCH] x86/vdso: implement clock_gettime(CLOCK_MONOTONIC_RAW, ...)
Date: Tue, 28 May 2019 11:01:38 -0700 (PDT) [thread overview]
Message-ID: <alpine.DEB.2.21.1905281055240.1859@nanos.tec.linutronix.de> (raw)
In-Reply-To: <20190528080034.31259-1-alexander.sverdlin@nokia.com>
Alexander,
On Tue, 28 May 2019, Sverdlin, Alexander (Nokia - DE/Ulm) wrote:
> Add CLOCK_MONOTONIC_RAW to the existing clock_gettime() vDSO
> implementation. This is based on the ideas of Jason Vas Dias and comments
> of Thomas Gleixner.
Well to some extent, but
> The results from the above test program:
>
> Clock Before After Diff
> ----- ------ ----- ----
> CLOCK_MONOTONIC 355531720 338039373 -5%
> CLOCK_MONOTONIC_RAW 44831738 336064912 +650%
> CLOCK_REALTIME 347665133 338102907 -3%
the preformance regressions for CLOCK_MONOTONIC and CLOCK_REALTIME are just
not acceptable.
> diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c
> index 98c7d12..7c9db26 100644
> --- a/arch/x86/entry/vdso/vclock_gettime.c
> +++ b/arch/x86/entry/vdso/vclock_gettime.c
> @@ -144,6 +144,13 @@ notrace static int do_hres(clockid_t clk, struct timespec *ts)
> struct vgtod_ts *base = >od->basetime[clk];
> u64 cycles, last, sec, ns;
> unsigned int seq;
> + u32 mult = gtod->mult;
> + u32 shift = gtod->shift;
> +
> + if (clk == CLOCK_MONOTONIC_RAW) {
> + mult = gtod->raw_mult;
> + shift = gtod->raw_shift;
> + }
They stem from this extra conditional.
>
> do {
> seq = gtod_read_begin(gtod);
> @@ -153,8 +160,8 @@ notrace static int do_hres(clockid_t clk, struct timespec *ts)
> if (unlikely((s64)cycles < 0))
> return vdso_fallback_gettime(clk, ts);
> if (cycles > last)
> - ns += (cycles - last) * gtod->mult;
> - ns >>= gtod->shift;
> + ns += (cycles - last) * mult;
And this is completely broken because you read the mult/shift values
outside of the sequence count protected region, so a concurrent update of
the timekeeping values will lead to inconsistent state.
Thanks,
tglx
next prev parent reply other threads:[~2019-05-28 18:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-28 8:01 Sverdlin, Alexander (Nokia - DE/Ulm)
2019-05-28 18:01 ` Thomas Gleixner [this message]
2019-06-04 16:42 ` [PATCH v2] " Sverdlin, Alexander (Nokia - DE/Ulm)
2019-06-04 17:39 ` Andy Lutomirski
2019-06-05 14:41 ` [PATCH v3 0/2] x86/vdso: CLOCK_MONOTONIC_RAW implementation Sverdlin, Alexander (Nokia - DE/Ulm)
2019-06-05 14:41 ` [PATCH v3 1/2] x86/vdso: Move mult and shift into struct vgtod_ts Sverdlin, Alexander (Nokia - DE/Ulm)
2019-06-23 10:18 ` Thomas Gleixner
2019-06-24 9:16 ` Sverdlin, Alexander (Nokia - DE/Ulm)
2019-06-24 9:40 ` Thomas Gleixner
2019-06-27 12:00 ` Sverdlin, Alexander (Nokia - DE/Ulm)
2019-06-27 12:07 ` Thomas Gleixner
2019-06-27 12:15 ` Sverdlin, Alexander (Nokia - DE/Ulm)
2019-06-27 12:21 ` Thomas Gleixner
2019-06-05 14:41 ` [PATCH v3 2/2] x86/vdso: implement clock_gettime(CLOCK_MONOTONIC_RAW, ...) Sverdlin, Alexander (Nokia - DE/Ulm)
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.21.1905281055240.1859@nanos.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=alexander.sverdlin@nokia.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jason.vas.dias@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=x86@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®