Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa20ae84 authored by Steven Rostedt's avatar Steven Rostedt Committed by Steven Rostedt
Browse files

ring-buffer: move big if statement down



In the hot path of the ring buffer "__rb_reserve_next" there's a big
if statement that does not even return back to the work flow.

	code;

	if (cross to next page) {

		[ lots of code ]

		return;
	}

	more code;

The condition is even the unlikely path, although we do not denote it
with an unlikely because gcc is fine with it. The condition is true when
the write crosses a page boundary, and we need to start at a new page.

Having this if statement makes it hard to read, but calling another
function to do the work is also not appropriate, because we are using a lot
of variables that were set before the if statement, and we do not want to
send them as parameters.

This patch changes it to a goto:

	code;

	if (cross to next page)
		goto next_page;

	more code;

	return;

next_page:

	[ lots of code]

This makes the code easier to understand, and a bit more obvious.

The output from gcc is practically identical. For some reason, gcc decided
to use different registers when I switched it to a goto. But other than that,
the logic is the same.

[ Impact: easier to read code ]

Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 94487d6d
Loading
Loading
Loading
Loading
+111 −107
Original line number Original line Diff line number Diff line
@@ -1159,6 +1159,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
		  unsigned type, unsigned long length, u64 *ts)
		  unsigned type, unsigned long length, u64 *ts)
{
{
	struct buffer_page *tail_page, *head_page, *reader_page, *commit_page;
	struct buffer_page *tail_page, *head_page, *reader_page, *commit_page;
	struct buffer_page *next_page;
	unsigned long tail, write;
	unsigned long tail, write;
	struct ring_buffer *buffer = cpu_buffer->buffer;
	struct ring_buffer *buffer = cpu_buffer->buffer;
	struct ring_buffer_event *event;
	struct ring_buffer_event *event;
@@ -1173,8 +1174,33 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
	tail = write - length;
	tail = write - length;


	/* See if we shot pass the end of this buffer page */
	/* See if we shot pass the end of this buffer page */
	if (write > BUF_PAGE_SIZE) {
	if (write > BUF_PAGE_SIZE)
		struct buffer_page *next_page = tail_page;
		goto next_page;

	/* We reserved something on the buffer */

	if (RB_WARN_ON(cpu_buffer, write > BUF_PAGE_SIZE))
		return NULL;

	event = __rb_page_index(tail_page, tail);
	rb_update_event(event, type, length);

	/* The passed in type is zero for DATA */
	if (likely(!type))
		local_inc(&tail_page->entries);

	/*
	 * If this is a commit and the tail is zero, then update
	 * this page's time stamp.
	 */
	if (!tail && rb_is_commit(cpu_buffer, event))
		cpu_buffer->commit_page->page->time_stamp = *ts;

	return event;

 next_page:

	next_page = tail_page;


	local_irq_save(flags);
	local_irq_save(flags);
	/*
	/*
@@ -1282,28 +1308,6 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,


	/* fail and let the caller try again */
	/* fail and let the caller try again */
	return ERR_PTR(-EAGAIN);
	return ERR_PTR(-EAGAIN);
	}

	/* We reserved something on the buffer */

	if (RB_WARN_ON(cpu_buffer, write > BUF_PAGE_SIZE))
		return NULL;

	event = __rb_page_index(tail_page, tail);
	rb_update_event(event, type, length);

	/* The passed in type is zero for DATA */
	if (likely(!type))
		local_inc(&tail_page->entries);

	/*
	 * If this is a commit and the tail is zero, then update
	 * this page's time stamp.
	 */
	if (!tail && rb_is_commit(cpu_buffer, event))
		cpu_buffer->commit_page->page->time_stamp = *ts;

	return event;


 out_reset:
 out_reset:
	/* reset write */
	/* reset write */