From: Vincent Donnefort <vdonnefort@google.com>
To: rostedt@goodmis.org, mhiramat@kernel.org,
linux-trace-kernel@vger.kernel.org, maz@kernel.org,
oliver.upton@linux.dev
Cc: kvmarm@lists.linux.dev, will@kernel.org, qperret@google.com,
kernel-team@android.com, linux-kernel@vger.kernel.org,
Vincent Donnefort <vdonnefort@google.com>
Subject: [PATCH 01/13] ring-buffer: Check for empty ring-buffer with rb_num_of_entries()
Date: Wed, 11 Sep 2024 10:30:17 +0100 [thread overview]
Message-ID: <20240911093029.3279154-2-vdonnefort@google.com> (raw)
In-Reply-To: <20240911093029.3279154-1-vdonnefort@google.com>
Currently there are two ways of identifying an empty ring-buffer. One
relying on the current status of the commit / reader page
(rb_per_cpu_empty()) and the other on the write and read counters
(rb_num_of_entries() used in rb_get_reader_page()).
with rb_num_of_entries(). This intends to ease later
introduction of ring-buffer writers which are out of the kernel control
and with whom, the only information available is through the meta-page
counters.
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index cebd879a30cb..7abe671effbf 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3941,40 +3941,22 @@ int ring_buffer_write(struct trace_buffer *buffer,
}
EXPORT_SYMBOL_GPL(ring_buffer_write);
-static bool rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer)
+/*
+ * The total entries in the ring buffer is the running counter
+ * of entries entered into the ring buffer, minus the sum of
+ * the entries read from the ring buffer and the number of
+ * entries that were overwritten.
+ */
+static inline unsigned long
+rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
{
- struct buffer_page *reader = cpu_buffer->reader_page;
- struct buffer_page *head = rb_set_head_page(cpu_buffer);
- struct buffer_page *commit = cpu_buffer->commit_page;
-
- /* In case of error, head will be NULL */
- if (unlikely(!head))
- return true;
-
- /* Reader should exhaust content in reader page */
- if (reader->read != rb_page_size(reader))
- return false;
-
- /*
- * If writers are committing on the reader page, knowing all
- * committed content has been read, the ring buffer is empty.
- */
- if (commit == reader)
- return true;
-
- /*
- * If writers are committing on a page other than reader page
- * and head page, there should always be content to read.
- */
- if (commit != head)
- return false;
+ return local_read(&cpu_buffer->entries) -
+ (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
+}
- /*
- * Writers are committing on the head page, we just need
- * to care about there're committed data, and the reader will
- * swap reader page with head page when it is to read data.
- */
- return rb_page_commit(commit) == 0;
+static bool rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer)
+{
+ return !rb_num_of_entries(cpu_buffer);
}
/**
@@ -4120,19 +4102,6 @@ void ring_buffer_record_enable_cpu(struct trace_buffer *buffer, int cpu)
}
EXPORT_SYMBOL_GPL(ring_buffer_record_enable_cpu);
-/*
- * The total entries in the ring buffer is the running counter
- * of entries entered into the ring buffer, minus the sum of
- * the entries read from the ring buffer and the number of
- * entries that were overwritten.
- */
-static inline unsigned long
-rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
-{
- return local_read(&cpu_buffer->entries) -
- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
-}
-
/**
* ring_buffer_oldest_event_ts - get the oldest event timestamp from the buffer
* @buffer: The ring buffer
--
2.46.0.598.g6f2099f65c-goog
next prev parent reply other threads:[~2024-09-11 9:30 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 9:30 [PATCH 00/13] Tracefs support for pKVM Vincent Donnefort
2024-09-11 9:30 ` Vincent Donnefort [this message]
2024-09-11 9:30 ` [PATCH 02/13] ring-buffer: Introducing ring-buffer writer Vincent Donnefort
2024-09-12 12:55 ` kernel test robot
2024-09-11 9:30 ` [PATCH 03/13] ring-buffer: Expose buffer_data_page material Vincent Donnefort
2024-09-11 9:30 ` [PATCH 04/13] timekeeping: Add the boot clock to system time snapshot Vincent Donnefort
2024-09-13 22:28 ` John Stultz
2024-10-02 15:15 ` Thomas Gleixner
2024-09-11 9:30 ` [PATCH 05/13] KVM: arm64: Support unaligned fixmap in the nVHE hyp Vincent Donnefort
2024-09-11 9:30 ` [PATCH 06/13] KVM: arm64: Add clock support " Vincent Donnefort
2024-09-13 22:41 ` John Stultz
2024-09-16 12:26 ` Vincent Donnefort
2024-09-11 9:30 ` [PATCH 07/13] KVM: arm64: Add tracing support for the pKVM hyp Vincent Donnefort
2024-09-11 9:30 ` [PATCH 08/13] KVM: arm64: Add hyp tracing to tracefs Vincent Donnefort
2024-09-11 9:30 ` [PATCH 09/13] KVM: arm64: Add clock for hyp tracefs Vincent Donnefort
2024-09-13 23:21 ` John Stultz
2024-09-16 12:39 ` Vincent Donnefort
2024-09-11 9:30 ` [PATCH 10/13] KVM: arm64: Add raw interface " Vincent Donnefort
2024-09-11 9:30 ` [PATCH 11/13] KVM: arm64: Add trace " Vincent Donnefort
2024-09-11 9:30 ` [PATCH 12/13] KVM: arm64: Add support for hyp events Vincent Donnefort
2024-09-11 9:30 ` [PATCH 13/13] KVM: arm64: Add kselftest for tracefs hyp tracefs Vincent Donnefort
2025-01-07 19:54 ` [PATCH 00/13] Tracefs support for pKVM Steven Rostedt
2025-01-07 21:46 ` 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=20240911093029.3279154-2-vdonnefort@google.com \
--to=vdonnefort@google.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=mhiramat@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=rostedt@goodmis.org \
--cc=will@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