struct buffer_page {
u64 time_stamp; /* page time stamp */
unsigned size; /* size of page data */
+ unsigned write; /* index for next write */
+ unsigned read; /* index for next read */
struct list_head list; /* list of free pages */
void *page; /* Actual data page */
};
spinlock_t lock;
struct lock_class_key lock_key;
struct list_head pages;
- unsigned long head; /* read from head */
- unsigned long tail; /* write to tail */
- unsigned long reader;
- struct buffer_page *head_page;
- struct buffer_page *tail_page;
+ struct buffer_page *head_page; /* read from head */
+ struct buffer_page *tail_page; /* write to tail */
struct buffer_page *reader_page;
unsigned long overrun;
unsigned long entries;
static inline int rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer)
{
- return (cpu_buffer->reader == cpu_buffer->reader_page->size &&
+ return cpu_buffer->reader_page->read == cpu_buffer->reader_page->size &&
(cpu_buffer->tail_page == cpu_buffer->reader_page ||
(cpu_buffer->tail_page == cpu_buffer->head_page &&
- cpu_buffer->head == cpu_buffer->tail)));
+ cpu_buffer->head_page->read ==
+ cpu_buffer->tail_page->write));
}
static inline int rb_null_event(struct ring_buffer_event *event)
return event->type == RINGBUF_TYPE_PADDING;
}
-static inline void *rb_page_index(struct buffer_page *page, unsigned index)
+static inline void *__rb_page_index(struct buffer_page *page, unsigned index)
{
return page->page + index;
}
static inline struct ring_buffer_event *
rb_reader_event(struct ring_buffer_per_cpu *cpu_buffer)
{
- return rb_page_index(cpu_buffer->reader_page,
- cpu_buffer->reader);
+ return __rb_page_index(cpu_buffer->reader_page,
+ cpu_buffer->reader_page->read);
+}
+
+static inline struct ring_buffer_event *
+rb_head_event(struct ring_buffer_per_cpu *cpu_buffer)
+{
+ return __rb_page_index(cpu_buffer->head_page,
+ cpu_buffer->head_page->read);
}
static inline struct ring_buffer_event *
rb_iter_head_event(struct ring_buffer_iter *iter)
{
- return rb_page_index(iter->head_page,
- iter->head);
+ return __rb_page_index(iter->head_page, iter->head);
}
/*
for (head = 0; head < rb_head_size(cpu_buffer);
head += rb_event_length(event)) {
- event = rb_page_index(cpu_buffer->head_page, head);
+ event = __rb_page_index(cpu_buffer->head_page, head);
BUG_ON(rb_null_event(event));
/* Only count data entries */
if (event->type != RINGBUF_TYPE_DATA)
static void rb_reset_head_page(struct ring_buffer_per_cpu *cpu_buffer)
{
- cpu_buffer->head = 0;
+ cpu_buffer->head_page->read = 0;
}
static void rb_reset_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
{
cpu_buffer->read_stamp = cpu_buffer->reader_page->time_stamp;
- cpu_buffer->reader = 0;
+ cpu_buffer->reader_page->read = 0;
}
static inline void rb_inc_iter(struct ring_buffer_iter *iter)
struct ring_buffer *buffer = cpu_buffer->buffer;
struct ring_buffer_event *event;
- /* No locking needed for tail page */
tail_page = cpu_buffer->tail_page;
- tail = cpu_buffer->tail;
+ tail = cpu_buffer->tail_page->write;
if (tail + length > BUF_PAGE_SIZE) {
struct buffer_page *next_page = tail_page;
}
if (tail != BUF_PAGE_SIZE) {
- event = rb_page_index(tail_page, tail);
+ event = __rb_page_index(tail_page, tail);
/* page padding */
event->type = RINGBUF_TYPE_PADDING;
}
tail_page->size = 0;
tail = 0;
cpu_buffer->tail_page = tail_page;
- cpu_buffer->tail = tail;
+ cpu_buffer->tail_page->write = tail;
rb_add_stamp(cpu_buffer, ts);
spin_unlock(&cpu_buffer->lock);
}
BUG_ON(tail + length > BUF_PAGE_SIZE);
- event = rb_page_index(tail_page, tail);
+ event = __rb_page_index(tail_page, tail);
rb_update_event(event, type, length);
return event;
return -1;
/* check to see if we went to the next page */
- if (cpu_buffer->tail) {
+ if (cpu_buffer->tail_page->write) {
/* Still on same page, update timestamp */
event->time_delta = *delta & TS_MASK;
event->array[0] = *delta >> TS_SHIFT;
/* commit the time event */
- cpu_buffer->tail +=
+ cpu_buffer->tail_page->write +=
rb_event_length(event);
cpu_buffer->write_stamp = *ts;
*delta = 0;
ts = ring_buffer_time_stamp(cpu_buffer->cpu);
- if (cpu_buffer->tail) {
+ if (cpu_buffer->tail_page->write) {
delta = ts - cpu_buffer->write_stamp;
if (test_time_stamp(delta)) {
return NULL;
/* If the reserve went to the next page, our delta is zero */
- if (!cpu_buffer->tail)
+ if (!cpu_buffer->tail_page->write)
delta = 0;
event->time_delta = delta;
static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer,
struct ring_buffer_event *event)
{
- cpu_buffer->tail += rb_event_length(event);
- cpu_buffer->tail_page->size = cpu_buffer->tail;
+ cpu_buffer->tail_page->write += rb_event_length(event);
+ cpu_buffer->tail_page->size = cpu_buffer->tail_page->write;
cpu_buffer->write_stamp += event->time_delta;
cpu_buffer->entries++;
}
/* Iterator usage is expected to have record disabled */
if (list_empty(&cpu_buffer->reader_page->list)) {
iter->head_page = cpu_buffer->head_page;
- iter->head = cpu_buffer->head;
+ iter->head = cpu_buffer->head_page->read;
} else {
iter->head_page = cpu_buffer->reader_page;
- iter->head = cpu_buffer->reader;
+ iter->head = cpu_buffer->reader_page->read;
}
if (iter->head)
iter->read_stamp = cpu_buffer->read_stamp;
cpu_buffer = iter->cpu_buffer;
return iter->head_page == cpu_buffer->tail_page &&
- iter->head == cpu_buffer->tail;
+ iter->head == cpu_buffer->tail_page->write;
}
static void
reader = cpu_buffer->reader_page;
/* If there's more to read, return this page */
- if (cpu_buffer->reader < reader->size)
+ if (cpu_buffer->reader_page->read < reader->size)
goto out;
/* Never should we have an index greater than the size */
- WARN_ON(cpu_buffer->reader > reader->size);
+ WARN_ON(cpu_buffer->reader_page->read > reader->size);
/* check if we caught up to the tail */
reader = NULL;
rb_update_read_stamp(cpu_buffer, event);
length = rb_event_length(event);
- cpu_buffer->reader += length;
+ cpu_buffer->reader_page->read += length;
}
static void rb_advance_iter(struct ring_buffer_iter *iter)
* at the tail of the buffer.
*/
BUG_ON((iter->head_page == cpu_buffer->tail_page) &&
- (iter->head + length > cpu_buffer->tail));
+ (iter->head + length > cpu_buffer->tail_page->write));
rb_update_iter_read_stamp(iter, event);
INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
cpu_buffer->reader_page->size = 0;
- cpu_buffer->head = cpu_buffer->tail = cpu_buffer->reader = 0;
+ cpu_buffer->head_page->read = 0;
+ cpu_buffer->tail_page->write = 0;
+ cpu_buffer->reader_page->read = 0;
cpu_buffer->overrun = 0;
cpu_buffer->entries = 0;