public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: mhiramat@kernel.org, mathieu.desnoyers@efficios.com,
	linux-trace-kernel@vger.kernel.org, maz@kernel.org,
	oliver.upton@linux.dev, joey.gouly@arm.com,
	suzuki.poulose@arm.com, yuzenghui@huawei.com,
	kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	jstultz@google.com, qperret@google.com, will@kernel.org,
	aneesh.kumar@kernel.org, kernel-team@android.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v11 13/30] tracing: Introduce simple_ring_buffer
Date: Wed, 4 Feb 2026 20:06:57 -0500	[thread overview]
Message-ID: <20260204200657.17b3cdf7@robin> (raw)
In-Reply-To: <20260131132848.254084-14-vdonnefort@google.com>

On Sat, 31 Jan 2026 13:28:31 +0000
Vincent Donnefort <vdonnefort@google.com> wrote:
\
> +/**
> + * simple_ring_buffer_swap_reader_page - Swap ring-buffer head with the reader
> + *
> + * This function enables consuming reading. It ensures the current head page will not be overwritten
> + * and can be safely read.
> + *
> + * @cpu_buffer: A simple_rb_per_cpu

And if you're going to do kerneldoc, you need to do it correctly ;-)

You put the description before the parameters.

> + *
> + * Returns 0 on success, -ENODEV if @cpu_buffer was unloaded or -EBUSY if we failed to catch the
> + * head page.
> + */
> +int simple_ring_buffer_swap_reader_page(struct simple_rb_per_cpu *cpu_buffer)
> +{
> +	struct simple_buffer_page *last, *head, *reader;
> +	unsigned long overrun;
> +	int retry = 8;
> +	int ret;
> +
> +	if (!simple_rb_loaded(cpu_buffer))
> +		return -ENODEV;
> +
> +	reader = cpu_buffer->reader_page;
> +
> +	do {
> +		/* Run after the writer to find the head */
> +		ret = simple_rb_find_head(cpu_buffer);
> +		if (ret)
> +			return ret;
> +
> +		head = cpu_buffer->head_page;
> +
> +		/* Connect the reader page around the header page */
> +		reader->link.next = head->link.next;
> +		reader->link.prev = head->link.prev;
> +
> +		/* The last page before the head */
> +		last = simple_bpage_from_link(head->link.prev);
> +
> +		/* The reader page points to the new header page */
> +		simple_bpage_set_head_link(reader);
> +
> +		overrun = cpu_buffer->meta->overrun;
> +	} while (!simple_bpage_unset_head_link(last, reader, SIMPLE_RB_LINK_NORMAL) && retry--);
> +
> +	if (!retry)
> +		return -EINVAL;
> +
> +	cpu_buffer->head_page = simple_bpage_from_link(reader->link.next);
> +	cpu_buffer->head_page->link.prev = &reader->link;
> +	cpu_buffer->reader_page = head;
> +	cpu_buffer->meta->reader.lost_events = overrun - cpu_buffer->last_overrun;
> +	cpu_buffer->meta->reader.id = cpu_buffer->reader_page->id;
> +	cpu_buffer->last_overrun = overrun;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(simple_ring_buffer_swap_reader_page);
> +
> +static struct simple_buffer_page *simple_rb_move_tail(struct simple_rb_per_cpu *cpu_buffer)
> +{
> +	struct simple_buffer_page *tail, *new_tail;
> +
> +	tail = cpu_buffer->tail_page;
> +	new_tail = simple_bpage_next_page(tail);
> +
> +	if (simple_bpage_unset_head_link(tail, new_tail, SIMPLE_RB_LINK_HEAD_MOVING)) {
> +		/*
> +		 * Oh no! we've caught the head. There is none anymore and
> +		 * swap_reader will spin until we set the new one. Overrun must
> +		 * be written first, to make sure we report the correct number
> +		 * of lost events.
> +		 */
> +		simple_rb_meta_inc(cpu_buffer->meta->overrun, new_tail->entries);
> +		simple_rb_meta_inc(cpu_buffer->meta->pages_lost, 1);
> +
> +		simple_bpage_set_head_link(new_tail);
> +		simple_bpage_set_normal_link(tail);
> +	}
> +
> +	simple_bpage_reset(new_tail);
> +	cpu_buffer->tail_page = new_tail;
> +
> +	simple_rb_meta_inc(cpu_buffer->meta->pages_touched, 1);
> +
> +	return new_tail;
> +}
> +
> +static unsigned long rb_event_size(unsigned long length)
> +{
> +	struct ring_buffer_event *event;
> +
> +	return length + RB_EVNT_HDR_SIZE + sizeof(event->array[0]);
> +}
> +
> +static struct ring_buffer_event *
> +rb_event_add_ts_extend(struct ring_buffer_event *event, u64 delta)
> +{
> +	event->type_len = RINGBUF_TYPE_TIME_EXTEND;
> +	event->time_delta = delta & TS_MASK;
> +	event->array[0] = delta >> TS_SHIFT;
> +
> +	return (struct ring_buffer_event *)((unsigned long)event + 8);
> +}
> +
> +static struct ring_buffer_event *
> +simple_rb_reserve_next(struct simple_rb_per_cpu *cpu_buffer, unsigned long length, u64 timestamp)
> +{
> +	unsigned long ts_ext_size = 0, event_size = rb_event_size(length);
> +	struct simple_buffer_page *tail = cpu_buffer->tail_page;
> +	struct ring_buffer_event *event;
> +	u32 write, prev_write;
> +	u64 time_delta;
> +
> +	time_delta = timestamp - cpu_buffer->write_stamp;
> +
> +	if (test_time_stamp(time_delta))
> +		ts_ext_size = 8;
> +
> +	prev_write = tail->write;
> +	write = prev_write + event_size + ts_ext_size;
> +
> +	if (unlikely(write > (PAGE_SIZE - BUF_PAGE_HDR_SIZE)))
> +		tail = simple_rb_move_tail(cpu_buffer);
> +
> +	if (!tail->entries) {
> +		tail->page->time_stamp = timestamp;
> +		time_delta = 0;
> +		ts_ext_size = 0;
> +		write = event_size;
> +		prev_write = 0;
> +	}
> +
> +	tail->write = write;
> +	tail->entries++;
> +
> +	cpu_buffer->write_stamp = timestamp;
> +
> +	event = (struct ring_buffer_event *)(tail->page->data + prev_write);
> +	if (ts_ext_size) {
> +		event = rb_event_add_ts_extend(event, time_delta);
> +		time_delta = 0;
> +	}
> +
> +	event->type_len = 0;
> +	event->time_delta = time_delta;
> +	event->array[0] = event_size - RB_EVNT_HDR_SIZE;
> +
> +	return event;
> +}
> +
> +/**
> + * simple_ring_buffer_reserve - Reserve an entry in @cpu_buffer
> + *

And you don't leave a space between the one line description and the
arguments.

> + * @cpu_buffer:	A simple_rb_per_cpu
> + * @length:	Size of the entry in bytes
> + * @timestamp:	Timestamp of the entry
> + *
> + * Returns the address of the entry where to write data or NULL
> + */
> +void *simple_ring_buffer_reserve(struct simple_rb_per_cpu *cpu_buffer, unsigned long length,
> +				 u64 timestamp)
> +{
> +	struct ring_buffer_event *rb_event;
> +
> +	if (cmpxchg(&cpu_buffer->status, SIMPLE_RB_READY, SIMPLE_RB_WRITING) != SIMPLE_RB_READY)
> +		return NULL;
> +
> +	rb_event = simple_rb_reserve_next(cpu_buffer, length, timestamp);
> +
> +	return &rb_event->array[1];
> +}
> +EXPORT_SYMBOL_GPL(simple_ring_buffer_reserve);
> +

Other than that:

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

-- Steve

  reply	other threads:[~2026-02-05  1:07 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-31 13:28 [PATCH v11 00/30] Tracefs support for pKVM Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 01/30] ring-buffer: Add page statistics to the meta-page Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 02/30] ring-buffer: Store bpage pointers into subbuf_ids Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 03/30] ring-buffer: Introduce ring-buffer remotes Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 04/30] ring-buffer: Add non-consuming read for " Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 05/30] tracing: Introduce trace remotes Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 06/30] tracing: Add reset to " Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 07/30] tracing: Add non-consuming read " Vincent Donnefort
2026-02-04 23:52   ` Steven Rostedt
2026-02-10 15:32     ` Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 08/30] tracing: Add init callback " Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 09/30] tracing: Add events " Vincent Donnefort
2026-02-05  0:40   ` Steven Rostedt
2026-01-31 13:28 ` [PATCH v11 10/30] tracing: Add events/ root files " Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 11/30] tracing: Add helpers to create trace remote events Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 12/30] ring-buffer: Export buffer_data_page and macros Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 13/30] tracing: Introduce simple_ring_buffer Vincent Donnefort
2026-02-05  1:06   ` Steven Rostedt [this message]
2026-01-31 13:28 ` [PATCH v11 14/30] tracing: Add a trace remote module for testing Vincent Donnefort
2026-02-05  1:32   ` Steven Rostedt
2026-01-31 13:28 ` [PATCH v11 15/30] tracing: selftests: Add trace remote tests Vincent Donnefort
2026-02-05 17:42   ` Steven Rostedt
2026-02-10 15:54     ` Vincent Donnefort
2026-02-19 14:36       ` Steven Rostedt
2026-01-31 13:28 ` [PATCH v11 16/30] Documentation: tracing: Add tracing remotes Vincent Donnefort
2026-02-05 17:45   ` Steven Rostedt
2026-01-31 13:28 ` [PATCH v11 17/30] tracing: load/unload page callbacks for simple_ring_buffer Vincent Donnefort
2026-02-05 17:47   ` Steven Rostedt
2026-01-31 13:28 ` [PATCH v11 18/30] tracing: Check for undefined symbols in simple_ring_buffer Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 19/30] KVM: arm64: Add PKVM_DISABLE_STAGE2_ON_PANIC Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 20/30] KVM: arm64: Add clock support to nVHE/pKVM hyp Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 21/30] KVM: arm64: Initialise hyp_nr_cpus for nVHE hyp Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 22/30] KVM: arm64: Support unaligned fixmap in the pKVM hyp Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 23/30] KVM: arm64: Add tracing capability for the nVHE/pKVM hyp Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 24/30] KVM: arm64: Add trace remote " Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 25/30] KVM: arm64: Sync boot clock with " Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 26/30] KVM: arm64: Add trace reset to " Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 27/30] KVM: arm64: Add event support to the nVHE/pKVM hyp and trace remote Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 28/30] KVM: arm64: Add hyp_enter/hyp_exit events to nVHE/pKVM hyp Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 29/30] KVM: arm64: Add selftest event support " Vincent Donnefort
2026-01-31 13:28 ` [PATCH v11 30/30] tracing: selftests: Add hypervisor trace remote tests Vincent Donnefort
2026-02-04 22:45 ` [PATCH v11 00/30] Tracefs support for pKVM Steven Rostedt
2026-02-05 17:51   ` 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=20260204200657.17b3cdf7@robin \
    --to=rostedt@goodmis.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=joey.gouly@arm.com \
    --cc=jstultz@google.com \
    --cc=kernel-team@android.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=maz@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=qperret@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=vdonnefort@google.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.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