From: Steven Rostedt <rostedt@goodmis.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Masami Hiramatsu <mhiramat@kernel.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
Yordan Karadzhov <y.karadz@gmail.com>,
Tzvetomir Stoyanov <tz.stoyanov@gmail.com>,
Tom Zanussi <zanussi@kernel.org>,
Jason Behmer <jbehmer@google.com>,
Julia Lawall <julia.lawall@inria.fr>,
Clark Williams <williams@redhat.com>,
bristot <bristot@redhat.com>, Daniel Wagner <wagi@monom.org>,
Darren Hart <dvhart@vmware.com>, Jonathan Corbet <corbet@lwn.net>,
"Suresh E. Warrier" <warrier@linux.vnet.ibm.com>
Subject: Re: [RFC][PATCH] ring-buffer: Have nested events still record running time stamp
Date: Thu, 25 Jun 2020 14:35:25 -0400 [thread overview]
Message-ID: <20200625143525.2f3a2902@oasis.local.home> (raw)
In-Reply-To: <1548518134.13177.1593107707149.JavaMail.zimbra@efficios.com>
On Thu, 25 Jun 2020 13:55:07 -0400 (EDT)
Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote
> > Here's the design of this solution:
> >
> > All this is per cpu, and only needs to worry about nested events (not
> > parallel events).
> >
> > The players:
> >
> > write_tail: The index in the buffer where new events can be written to.
> > It is incremented via local_add() to reserve space for a new event.
> >
> > before_stamp: A time stamp set by all events before reserving space.
> >
> > write_stamp: A time stamp updated by events after it has successfully
> > reserved space.
>
> What are the types used for before_stamp and write_stamp ? If those
> are 64-bit integers, how does sharing them between nested contexts
> work on 32-bit architectures ?
Well, write_stamp is updated via local64, which I believe handles this
for us. I probably should make before_stamp handle it as well.
>
> >
> > next_write: A copy of "write_tail" used to help with races.
> >
> > /* Save the current position of write */
> > [A] w = local_read(write_tail);
> > barrier();
> > /* Read both before and write stamps before touching
> > anything */ before = READ_ONCE(before_stamp);
> > after = local_read(write_stamp);
> > barrier();
> >
> > /*
> > * If before and after are the same, then this event is not
> > * preempting a time update. If it is, then reserve space
> > for adding
>
> You should use the term "interrupt" rather than "preempting", because
> as you stated yourself, this algorithm only works with nested
> interrupts, not with preemption.
The two terms are basically interchangeable here, but for consistency,
I will update it. Thanks.
>
> > * a full time stamp (this can turn into a time extend which
> > is
> > * just an extended time delta but fill up the extra space).
> > */
> > if (after != before)
> > abs = true;
> >
> > ts = clock();
> >
> > /* Now update the before_stamp (everyone does this!) */
> > [B] WRITE_ONCE(before_stamp, ts);
> >
> > /* Read the current next_write and update it to what we want
> > write
> > * to be after we reserve space. */
> > next = READ_ONCE(next_write);
> > WRITE_ONCE(next_write, w + len);
> >
> > /* Now reserve space on the buffer */
> > [C] write = local_add_return(len, write_tail);
>
> So the reservation is not "just" an add instruction, it's actually an
> xadd on x86. Is that really faster than a cmpxchg ?
I believe the answer is still yes. But I can run some benchmarks to
make sure.
>
> >
> > /* Set tail to be were this event's data is */
> > tail = write - len;
> >
> > if (w == tail) {
> >
> > /* Nothing preempted this between A and C */
> > [D] local_set(write_stamp, ts);
> > barrier();
> > [E] save_before = READ_ONCE(before_stamp);
> >
> > if (!abs) {
> > /* This did not preempt a time update */
> > delta = ts - a;
>
> What does "a" refer to ? What triggers its update ?
Oops, When I first wrote this, I used "a" and "b" for "after" and
"before" and had "after" and "before" be "after_stamp" and
"before_stamp". I missed this update. Nice catch.
>
> > } else {
> > /* slow path */
> > if (w == next) {
>
> If it's a slow path, why try to play games with a delta timestamp ?
> Space should not be an issue for a slow path like this. It would be
> simpler to just use the full timestamp here.
Hmm, you may be right. Previous iterations of this code had a distinct
difference here, but after restructuring it, I don't think that
distinction is valid anymore. If anything, having this at least lets me
validate that it's doing what I believe it should be doing (as I added
a ton of trace_printk()s into this).
>
> > /* This event preempted the previous
> > event
> > * just after it reserved its
> > buffer.
>
> You mean nesting after [C] but before [D].
Yes. I can add that for clarity, but perhaps I don't need that if I
merge the two.
>
> > * It's timestamp should be
> > "before_stamp" */
>
> It's -> Its
;-)
My email client messed up your formatting of the rest of the email, so
I'll send a separate reply.
-- Steve
next prev parent reply other threads:[~2020-06-25 18:35 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-25 13:44 Steven Rostedt
2020-06-25 13:53 ` Mathieu Desnoyers
2020-06-25 14:37 ` Steven Rostedt
2020-06-25 16:42 ` Korben Rusek
2020-06-25 18:12 ` Steven Rostedt
2020-06-25 17:55 ` Mathieu Desnoyers
2020-06-25 18:35 ` Steven Rostedt [this message]
2020-06-25 19:35 ` Mathieu Desnoyers
2020-06-25 19:58 ` Steven Rostedt
2020-06-26 2:36 ` Steven Rostedt
2020-06-26 3:35 ` Steven Rostedt
2020-06-26 13:58 ` Steven Rostedt
2020-06-26 18:13 ` Mathieu Desnoyers
2020-06-26 18:58 ` Steven Rostedt
2020-06-26 19:39 ` Steven Rostedt
2020-06-30 0:21 ` Steven Rostedt
2020-06-30 3:13 ` Mathieu Desnoyers
2020-06-30 3:26 ` Steven Rostedt
2020-06-25 19:04 ` Steven Rostedt
2020-06-25 19:58 ` Mathieu Desnoyers
2020-06-25 20:42 ` Steven Rostedt
2020-06-25 19:09 ` Steven Rostedt
2020-06-25 20:03 ` Mathieu Desnoyers
2020-06-25 18:09 ` Steven Rostedt
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=20200625143525.2f3a2902@oasis.local.home \
--to=rostedt@goodmis.org \
--cc=acme@redhat.com \
--cc=bristot@redhat.com \
--cc=corbet@lwn.net \
--cc=dvhart@vmware.com \
--cc=jbehmer@google.com \
--cc=jolsa@redhat.com \
--cc=julia.lawall@inria.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=tz.stoyanov@gmail.com \
--cc=wagi@monom.org \
--cc=warrier@linux.vnet.ibm.com \
--cc=williams@redhat.com \
--cc=y.karadz@gmail.com \
--cc=zanussi@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®