For pmus that don't support scatter-gather for AUX data in hardware, it
might still make sense to implement software double buffering to avoid
losing data while the user is reading data out. For this purpose, add
a pmu capability that guarantees multiple high-order chunks for AUX buffer,
so that the pmu driver can do switchover tricks.

Signed-off-by: Alexander Shishkin <alexander.shish...@linux.intel.com>
---
 include/linux/perf_event.h  |  1 +
 kernel/events/ring_buffer.c | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 4d9ede200f..71be27169c 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -171,6 +171,7 @@ struct perf_event;
  */
 #define PERF_PMU_CAP_NO_INTERRUPT              0x01
 #define PERF_PMU_CAP_AUX_NO_SG                 0x02
+#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF          0x04
 
 /**
  * struct pmu - generic performance monitoring unit
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index d10919ca42..f5ee3669f8 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -286,9 +286,22 @@ int rb_alloc_aux(struct ring_buffer *rb, struct perf_event 
*event,
        if (!has_aux(event))
                return -ENOTSUPP;
 
-       if (event->pmu->capabilities & PERF_PMU_CAP_AUX_NO_SG)
+       if (event->pmu->capabilities & PERF_PMU_CAP_AUX_NO_SG) {
                order = get_order(nr_pages * PAGE_SIZE);
 
+               /*
+                * PMU requests more than one contiguous chunks of memory
+                * for SW double buffering
+                */
+               if ((event->pmu->capabilities & PERF_PMU_CAP_AUX_SW_DOUBLEBUF) 
&&
+                   !overwrite) {
+                       if (!order)
+                               return -EINVAL;
+
+                       order--;
+               }
+       }
+
        rb->aux_pages = kzalloc_node(nr_pages * sizeof(void *), GFP_KERNEL, 
node);
        if (!rb->aux_pages)
                return -ENOMEM;
-- 
2.1.0.rc1

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

Reply via email to