Re: [PATCH] oprofile per-cpu buffer overrun

From: Philippe Elie
Date: Mon Jan 26 2004 - 09:37:01 EST


John Levon wrote:
On Sun, Jan 25, 2004 at 08:07:01PM -0800, Andrew Morton wrote:


When implementing a circular buffer it is better to not constrain the head
and tail indices - just let them grow and wrap without bound. You only need
to bring them in-bounds when you actually use them to index the buffer.

neat!

I'm not sure why that's better.

We win in increment_head/increment_tail:

static void increment_head(struct oprofile_cpu_buffer * b)
{
- unsigned long new_head = b->head_pos + 1;
wmb();
- if (new_head < (b->buffer_size))
- b->head_pos = new_head;
- else
- b->head_pos = 0;
+ b->head_pos++;
}

for this added cost when accessing the buffer:

b->buffer[b->head & b->buffer_size_mask];

Modulo use is not worth but with buffer_size a power of 2
it's probably a win, I'll try and measure this later, not
urgent since the problem is fixed, I added it in our todo.

regards,
Phil

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/