1
0
Fork 0

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: Steven Rostedt <rostedt@goodmis.org>
hifive-unleashed-5.1
Steven Rostedt 2009-05-05 21:16:11 -04:00 committed by Steven Rostedt
parent 94487d6d53
commit aa20ae8444
1 changed files with 114 additions and 110 deletions

View File

@ -1159,6 +1159,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
unsigned type, unsigned long length, u64 *ts)
{
struct buffer_page *tail_page, *head_page, *reader_page, *commit_page;
struct buffer_page *next_page;
unsigned long tail, write;
struct ring_buffer *buffer = cpu_buffer->buffer;
struct ring_buffer_event *event;
@ -1173,8 +1174,33 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
tail = write - length;
/* See if we shot pass the end of this buffer page */
if (write > BUF_PAGE_SIZE) {
struct buffer_page *next_page = tail_page;
if (write > BUF_PAGE_SIZE)
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);
/*
@ -1282,28 +1308,6 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
/* fail and let the caller try again */
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:
/* reset write */