Merge tag 'char-misc-5.13-rc1-round2' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / kernel / events / ring_buffer.c
index ef91ae7..5286871 100644 (file)
@@ -674,21 +674,26 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
        if (!has_aux(event))
                return -EOPNOTSUPP;
 
-       /*
-        * We need to start with the max_order that fits in nr_pages,
-        * not the other way around, hence ilog2() and not get_order.
-        */
-       max_order = ilog2(nr_pages);
-
-       /*
-        * PMU requests more than one contiguous chunks of memory
-        * for SW double buffering
-        */
        if (!overwrite) {
-               if (!max_order)
-                       return -EINVAL;
+               /*
+                * Watermark defaults to half the buffer, and so does the
+                * max_order, to aid PMU drivers in double buffering.
+                */
+               if (!watermark)
+                       watermark = nr_pages << (PAGE_SHIFT - 1);
 
-               max_order--;
+               /*
+                * Use aux_watermark as the basis for chunking to
+                * help PMU drivers honor the watermark.
+                */
+               max_order = get_order(watermark);
+       } else {
+               /*
+                * We need to start with the max_order that fits in nr_pages,
+                * not the other way around, hence ilog2() and not get_order.
+                */
+               max_order = ilog2(nr_pages);
+               watermark = 0;
        }
 
        rb->aux_pages = kcalloc_node(nr_pages, sizeof(void *), GFP_KERNEL,
@@ -743,9 +748,6 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
        rb->aux_overwrite = overwrite;
        rb->aux_watermark = watermark;
 
-       if (!rb->aux_watermark && !rb->aux_overwrite)
-               rb->aux_watermark = nr_pages << (PAGE_SHIFT - 1);
-
 out:
        if (!ret)
                rb->aux_pgoff = pgoff;
@@ -804,7 +806,7 @@ struct perf_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
 {
        struct perf_buffer *rb;
        unsigned long size;
-       int i;
+       int i, node;
 
        size = sizeof(struct perf_buffer);
        size += nr_pages * sizeof(void *);
@@ -812,7 +814,8 @@ struct perf_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
        if (order_base_2(size) >= PAGE_SHIFT+MAX_ORDER)
                goto fail;
 
-       rb = kzalloc(size, GFP_KERNEL);
+       node = (cpu == -1) ? cpu : cpu_to_node(cpu);
+       rb = kzalloc_node(size, GFP_KERNEL, node);
        if (!rb)
                goto fail;
 
@@ -906,11 +909,13 @@ struct perf_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
        struct perf_buffer *rb;
        unsigned long size;
        void *all_buf;
+       int node;
 
        size = sizeof(struct perf_buffer);
        size += sizeof(void *);
 
-       rb = kzalloc(size, GFP_KERNEL);
+       node = (cpu == -1) ? cpu : cpu_to_node(cpu);
+       rb = kzalloc_node(size, GFP_KERNEL, node);
        if (!rb)
                goto fail;