Re: [PATCH] perf_counter: allow and require one-page mmap oncounting counters

From: Peter Zijlstra
Date: Wed Mar 25 2009 - 07:48:50 EST


On Wed, 2009-03-25 at 19:15 +1100, Paul Mackerras wrote:
> Impact: bug fix
>
> Currently the mmap code requires that the length of the mmap be at least
> two pages. That is fine for sampling counters, but for counting
> counters the second and subsequent pages are just wasted, since counting
> counters don't generate events.
>
> This changes the code to require that the mmap be one page in length
> for counting counters, and applies the existing check to sampling
> counters.

Does the below work for you Paul?

---
Subject: perf_counter: allow one-page mmap on counters
From: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Date: Wed Mar 25 12:44:16 CET 2009

A brainfart stopped single page mmap()s working. The rest of the code
should be perfectly fine with not having any data pages.

Reported-by: Paul Mackerras <paulus@xxxxxxxxx>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
---
kernel/perf_counter.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

Index: linux-2.6/kernel/perf_counter.c
===================================================================
--- linux-2.6.orig/kernel/perf_counter.c
+++ linux-2.6/kernel/perf_counter.c
@@ -1369,7 +1369,11 @@ static int perf_mmap(struct file *file,
vma_size = vma->vm_end - vma->vm_start;
nr_pages = (vma_size / PAGE_SIZE) - 1;

- if (nr_pages == 0 || !is_power_of_2(nr_pages))
+ /*
+ * If we have data pages ensure they're a power-of-two number, so we
+ * can do bitmasks instead of modulo.
+ */
+ if (nr_pages != 0 && !is_power_of_2(nr_pages))
return -EINVAL;

if (vma_size != PAGE_SIZE * (1 + nr_pages))


--
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/