From: Shaohua Li <shli@fb.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
X86 ML <x86@kernel.org>, <Kernel-team@fb.com>,
"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
John Stultz <john.stultz@linaro.org>
Subject: Re: [PATCH v2 3/3] X86: Add a thread cpu time implementation to vDSO
Date: Thu, 18 Dec 2014 16:30:44 -0800 [thread overview]
Message-ID: <20141219003044.GA2804333@devbig257.prn2.facebook.com> (raw)
In-Reply-To: <CALCETrV2+qkuj3WinOW-Ro_PjtZBhLaXwSHCeWpMpTJnog83EQ@mail.gmail.com>
On Thu, Dec 18, 2014 at 04:22:59PM -0800, Andy Lutomirski wrote:
> On Thu, Dec 18, 2014 at 3:30 PM, Andy Lutomirski <luto@amacapital.net> wrote:
> > On Wed, Dec 17, 2014 at 3:12 PM, Shaohua Li <shli@fb.com> wrote:
> >> This primarily speeds up clock_gettime(CLOCK_THREAD_CPUTIME_ID, ..). We
> >> use the following method to compute the thread cpu time:
> >>
> >> t0 = process start
> >> t1 = most recent context switch time
> >> t2 = time at which the vsyscall is invoked
> >>
> >> thread_cpu_time = sum(time slices between t0 to t1) + (t2 - t1)
> >> = current->se.sum_exec_runtime + now - sched_clock()
> >>
> >> At context switch time We stash away
> >>
> >> adj_sched_time = sum_exec_runtime - sched_clock()
> >>
> >> in a per-cpu struct in the VVAR page and then compute
> >>
> >> thread_cpu_time = adj_sched_time + now
> >>
> >> All computations are done in nanosecs on systems where TSC is stable. If
> >> TSC is unstable, we fallback to a regular syscall.
> >> Benchmark data:
> >>
> >> for (i = 0; i < 100000000; i++) {
> >> clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
> >> sum += ts.tv_sec * NSECS_PER_SEC + ts.tv_nsec;
> >> }
> >
> > A bunch of the time spent processing a CLOCK_THREAD_CPUTIME_ID syscall
> > is spent taking various locks, and I think it could be worth adding a
> > fast path for the read-my-own-clock case in which we just disable
> > preemption and read the thing without any locks.
> >
> > If we're actually going to go the vdso route, I'd like to make the
> > scheduler hooks clean. Peterz and/or John, what's the right way to
> > get an arch-specific callback with sum_exec_runtime and an up to date
> > sched_clock value during a context switch? I'd much rather not add
> > yet another rdtsc instruction to the scheduler.
>
> Bad news: this patch is incorrect, I think. Take a look at
> update_rq_clock -- it does fancy things involving irq time and
> paravirt steal time. So this patch could result in extremely
> non-monotonic results.
Yes, it's not precise. But bear in mind, CONFIG_IRQ_TIME_ACCOUNTING is a
optional feature. Actually it's added not long time ago. I thought it's
acceptable the time isn't precise just like what we have before the
feature is added.
Thanks,
Shaohua
next prev parent reply other threads:[~2014-12-19 0:31 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-17 23:12 [PATCH v2 1/3] X86: make VDSO data support multiple pages Shaohua Li
2014-12-17 23:12 ` [PATCH v2 2/3] X86: add a generic API to let vdso code detect context switch Shaohua Li
2014-12-19 1:05 ` Thomas Gleixner
2014-12-17 23:12 ` [PATCH v2 3/3] X86: Add a thread cpu time implementation to vDSO Shaohua Li
2014-12-18 23:30 ` Andy Lutomirski
2014-12-19 0:22 ` Andy Lutomirski
2014-12-19 0:30 ` Shaohua Li [this message]
2014-12-19 0:32 ` Andy Lutomirski
2014-12-19 0:34 ` Thomas Gleixner
2014-12-19 11:23 ` Peter Zijlstra
2014-12-19 16:48 ` Andy Lutomirski
2014-12-19 17:03 ` Peter Zijlstra
2014-12-19 17:07 ` Andy Lutomirski
2014-12-19 17:27 ` Peter Zijlstra
2014-12-19 17:42 ` Andy Lutomirski
2015-01-02 2:59 ` Shaohua Li
2015-01-02 15:31 ` David Ahern
2015-01-02 17:02 ` Shaohua Li
2015-01-02 17:09 ` David Ahern
2015-01-02 17:17 ` Shaohua Li
2015-01-02 17:26 ` David Ahern
2015-01-02 17:47 ` Andy Lutomirski
2015-01-05 23:23 ` Shaohua Li
2015-01-06 10:18 ` Peter Zijlstra
2015-01-06 16:59 ` Shaohua Li
2015-01-12 19:50 ` Shaohua Li
2014-12-19 17:42 ` Chris Mason
2014-12-19 17:53 ` Andy Lutomirski
2014-12-19 18:16 ` Shaohua Li
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=20141219003044.GA2804333@devbig257.prn2.facebook.com \
--to=shli@fb.com \
--cc=Kernel-team@fb.com \
--cc=hpa@zytor.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--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