From: Steven Rostedt <rostedt@goodmis.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, kernel-team@android.com
Subject: Re: [PATCH v9 1/2] ring-buffer: Introducing ring-buffer mapping functions
Date: Thu, 21 Dec 2023 12:51:24 -0500 [thread overview]
Message-ID: <20231221125124.49ee8201@gandalf.local.home> (raw)
In-Reply-To: <20231221173523.3015715-2-vdonnefort@google.com>
On Thu, 21 Dec 2023 17:35:22 +0000
Vincent Donnefort <vdonnefort@google.com> wrote:
> @@ -739,6 +747,22 @@ static __always_inline bool full_hit(struct trace_buffer *buffer, int cpu, int f
> return (dirty * 100) > (full * nr_pages);
> }
>
> +static void rb_update_meta_page(struct ring_buffer_per_cpu *cpu_buffer)
> +{
> + if (unlikely(READ_ONCE(cpu_buffer->mapped))) {
> + /* Ensure the meta_page is ready */
> + smp_rmb();
> + WRITE_ONCE(cpu_buffer->meta_page->entries,
> + local_read(&cpu_buffer->entries));
> + WRITE_ONCE(cpu_buffer->meta_page->overrun,
> + local_read(&cpu_buffer->overrun));
> + WRITE_ONCE(cpu_buffer->meta_page->subbufs_touched,
> + local_read(&cpu_buffer->pages_touched));
> + WRITE_ONCE(cpu_buffer->meta_page->subbufs_lost,
> + local_read(&cpu_buffer->pages_lost));
> + }
> +}
> +
> /*
> * rb_wake_up_waiters - wake up tasks waiting for ring buffer input
> *
> @@ -749,6 +773,18 @@ static void rb_wake_up_waiters(struct irq_work *work)
> {
> struct rb_irq_work *rbwork = container_of(work, struct rb_irq_work, work);
>
> + if (rbwork->is_cpu_buffer) {
> + struct ring_buffer_per_cpu *cpu_buffer;
> +
> + cpu_buffer = container_of(rbwork, struct ring_buffer_per_cpu,
> + irq_work);
> + /*
> + * If the waiter is a cpu_buffer, this might be due to a
> + * userspace mapping. Let's update the meta-page.
> + */
> + rb_update_meta_page(cpu_buffer);
> + }
> +
> wake_up_all(&rbwork->waiters);
> if (rbwork->full_waiters_pending || rbwork->wakeup_full) {
> rbwork->wakeup_full = false;
I think this code would be cleaner if we did:
static void rb_update_meta_page(strucrt rb_irq_work *rbwork)
{
struct ring_buffer_per_cpu *cpu_buffer;
if (!rbwork->is_cpu_buffer)
return;
/*
* If the waiter is a cpu_buffer, this might be due to a
* userspace mapping. Let's update the meta-page.
*/
cpu_buffer = container_of(rbwork, struct ring_buffer_per_cpu,
irq_work);
if (unlikely(READ_ONCE(cpu_buffer->mapped))) {
// I don't think we need the "unlikely"
/* Ensure the meta_page is ready */
smp_rmb();
WRITE_ONCE(cpu_buffer->meta_page->entries,
local_read(&cpu_buffer->entries));
WRITE_ONCE(cpu_buffer->meta_page->overrun,
local_read(&cpu_buffer->overrun));
WRITE_ONCE(cpu_buffer->meta_page->subbufs_touched,
local_read(&cpu_buffer->pages_touched));
WRITE_ONCE(cpu_buffer->meta_page->subbufs_lost,
local_read(&cpu_buffer->pages_lost));
}
}
/*
* rb_wake_up_waiters - wake up tasks waiting for ring buffer input
*
* Schedules a delayed work to wake up any task that is blocked on the
* ring buffer waiters queue.
*/
static void rb_wake_up_waiters(struct irq_work *work)
{
struct rb_irq_work *rbwork = container_of(work, struct rb_irq_work, work);
rb_update_meta_page(cpu_buffer);
wake_up_all(&rbwork->waiters);
if (rbwork->full_waiters_pending || rbwork->wakeup_full) {
rbwork->wakeup_full = false;
rbwork->full_waiters_pending = false;
wake_up_all(&rbwork->full_waiters);
}
}
-- Steve
next prev parent reply other threads:[~2023-12-21 17:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-21 17:35 [PATCH v9 0/2] Introducing trace buffer mapping by user-space Vincent Donnefort
2023-12-21 17:35 ` [PATCH v9 1/2] ring-buffer: Introducing ring-buffer mapping functions Vincent Donnefort
2023-12-21 17:51 ` Steven Rostedt [this message]
2023-12-21 17:58 ` Steven Rostedt
2024-01-04 18:28 ` Steven Rostedt
2023-12-21 17:35 ` [PATCH v9 2/2] tracing: Allow user-space mapping of the ring-buffer Vincent Donnefort
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=20231221125124.49ee8201@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=vdonnefort@google.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