From: Steven Rostedt <rostedt@goodmis.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Linux Trace Kernel <linux-trace-kernel@vger.kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Philippe Proulx <pproulx@efficios.com>
Subject: Re: [PATCH] ring-buffer: Simplify reservation with try_cmpxchg() loop
Date: Sat, 20 Jan 2024 09:34:01 -0500 [thread overview]
Message-ID: <20240120093401.0274a2e8@rorschach.local.home> (raw)
In-Reply-To: <20240120084713.6eb7aa52@rorschach.local.home>
On Sat, 20 Jan 2024 08:47:13 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:
> > I would also consider reducing code complexity as a worthwhile metric
> > in addition to speed. It makes it easier to extend in the future,
> > easier to understand for reviewers, and subtle bugs are less likely
> > to creep in.
>
> Really, it wouldn't make it that much simpler. The addition of the
> cmpxchg() of this patch removed the nasty part of the code.
Now let's look at the difference of the two. You still need to save the
current timestamp in one variable. I have to do it in two, so your
algorithm does have that advantage. I currently have (eliminating the
"always add absolute timestamp" switch):
w = write;
before = before_stamp;
again:
after = write_stamp; (equivalent to your last_tsc)
ts = rdtsc();
if (!w)
delta = 0; // event has same ts as subbuf
else if (before == after)
delta = ts - after;
else {
delta = 0;
inject_absolute = true;
}
before_stamp = ts;
if (!try_cmpxchg(&write, w, w + length))
goto again;
write_stamp = ts;
Now if I were to updated it to use a delta from the last injected
timestamp, where injecting a timestamp only happens on overflow.
#define TS_BITS 27
#define MAX_DELTA ((1 << TS_BITS) - 1)
#define BITMASK (~MAX_DELTA)
w = write;
again:
ts = rdtsc();
delta = ts & MAX_DELTA;
if (ts - (write_stamp & BITMASK) > MAX_DELTA)
inject_absolute = true;
if (!try_cmpxchg(&write, w, w + length))
goto again;
write_stamp = ts;
I admit that it does simplify the code a little, but does it do it
enough to be worth the process of deprecating an ABI with a new one?
-- Steve
next prev parent reply other threads:[~2024-01-20 14:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-18 23:12 [PATCH] ring-buffer: Simplify reservation with try_cmpxchg() loop Steven Rostedt
2024-01-19 14:40 ` Mathieu Desnoyers
2024-01-19 15:37 ` Steven Rostedt
2024-01-19 20:56 ` Mathieu Desnoyers
2024-01-19 21:42 ` Steven Rostedt
2024-01-20 1:49 ` Mathieu Desnoyers
2024-01-20 13:47 ` Steven Rostedt
2024-01-20 14:34 ` Steven Rostedt [this message]
2024-01-25 21:18 ` Mathieu Desnoyers
2024-01-25 22:14 ` 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=20240120093401.0274a2e8@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=pproulx@efficios.com \
/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