ring-buffer: Do not use schedule_work_on() for current CPU
authorSteven Rostedt (Red Hat) <srostedt@redhat.com>
Thu, 7 Mar 2013 14:27:42 +0000 (09:27 -0500)
committerSteven Rostedt <rostedt@goodmis.org>
Fri, 15 Mar 2013 04:35:52 +0000 (00:35 -0400)
The ring buffer updates when done while the ring buffer is active,
needs to be completed on the CPU that is used for the ring buffer
per_cpu buffer. To accomplish this, schedule_work_on() is used to
schedule work on the given CPU.

Now there's no reason to use schedule_work_on() if the process
doing the update happens to be on the CPU that it is processing.
It has already filled the requirement. Instead, just do the work
and continue.

This is needed for tracing_snapshot_alloc() where it may be called
really early in boot, where the work queues have not been set up yet.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/ring_buffer.c

index 65fe2a4f98241bc4295276aee1fbec95463d7ce9..d1c85c5f5f51f0ad27d29aaaf0618cb2473c9b13 100644 (file)
@@ -1679,11 +1679,22 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
                        if (!cpu_buffer->nr_pages_to_update)
                                continue;
 
-                       if (cpu_online(cpu))
+                       /* The update must run on the CPU that is being updated. */
+                       preempt_disable();
+                       if (cpu == smp_processor_id() || !cpu_online(cpu)) {
+                               rb_update_pages(cpu_buffer);
+                               cpu_buffer->nr_pages_to_update = 0;
+                       } else {
+                               /*
+                                * Can not disable preemption for schedule_work_on()
+                                * on PREEMPT_RT.
+                                */
+                               preempt_enable();
                                schedule_work_on(cpu,
                                                &cpu_buffer->update_pages_work);
-                       else
-                               rb_update_pages(cpu_buffer);
+                               preempt_disable();
+                       }
+                       preempt_enable();
                }
 
                /* wait for all the updates to complete */
@@ -1721,12 +1732,22 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
 
                get_online_cpus();
 
-               if (cpu_online(cpu_id)) {
+               preempt_disable();
+               /* The update must run on the CPU that is being updated. */
+               if (cpu_id == smp_processor_id() || !cpu_online(cpu_id))
+                       rb_update_pages(cpu_buffer);
+               else {
+                       /*
+                        * Can not disable preemption for schedule_work_on()
+                        * on PREEMPT_RT.
+                        */
+                       preempt_enable();
                        schedule_work_on(cpu_id,
                                         &cpu_buffer->update_pages_work);
                        wait_for_completion(&cpu_buffer->update_done);
-               } else
-                       rb_update_pages(cpu_buffer);
+                       preempt_disable();
+               }
+               preempt_enable();
 
                cpu_buffer->nr_pages_to_update = 0;
                put_online_cpus();