events: Move lockless timer calculation into helper function
[firefly-linux-kernel-4.4.55.git] / kernel / events / core.c
index 5e70f62752a25354aaa9ebfc90a0b35b8ba436b8..c851d707821f1331e99bc57a47cafd6fdba31ca5 100644 (file)
@@ -748,6 +748,7 @@ static u64 perf_event_time(struct perf_event *event)
 
 /*
  * Update the total_time_enabled and total_time_running fields for a event.
+ * The caller of this function needs to hold the ctx->lock.
  */
 static void update_event_times(struct perf_event *event)
 {
@@ -3350,6 +3351,18 @@ static int perf_event_index(struct perf_event *event)
        return event->hw.idx + 1 - PERF_EVENT_INDEX_OFFSET;
 }
 
+static void calc_timer_values(struct perf_event *event,
+                               u64 *running,
+                               u64 *enabled)
+{
+       u64 now, ctx_time;
+
+       now = perf_clock();
+       ctx_time = event->shadow_ctx_time + now;
+       *enabled = ctx_time - event->tstamp_enabled;
+       *running = ctx_time - event->tstamp_running;
+}
+
 /*
  * Callers need to ensure there can be no nesting of this function, otherwise
  * the seqlock logic goes bad. We can not serialize this because the arch
@@ -3569,8 +3582,10 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
        if (vma->vm_flags & VM_WRITE)
                flags |= RING_BUFFER_WRITABLE;
 
-       rb = rb_alloc(nr_pages, event->attr.wakeup_watermark,
-                                  event->cpu, flags);
+       rb = rb_alloc(nr_pages, 
+               event->attr.watermark ? event->attr.wakeup_watermark : 0,
+               event->cpu, flags);
+
        if (!rb) {
                ret = -ENOMEM;
                goto unlock;
@@ -3813,7 +3828,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
 static void perf_output_read(struct perf_output_handle *handle,
                             struct perf_event *event)
 {
-       u64 enabled = 0, running = 0, now, ctx_time;
+       u64 enabled = 0, running = 0;
        u64 read_format = event->attr.read_format;
 
        /*
@@ -3825,12 +3840,8 @@ static void perf_output_read(struct perf_output_handle *handle,
         * because of locking issue as we are called in
         * NMI context
         */
-       if (read_format & PERF_FORMAT_TOTAL_TIMES) {
-               now = perf_clock();
-               ctx_time = event->shadow_ctx_time + now;
-               enabled = ctx_time - event->tstamp_enabled;
-               running = ctx_time - event->tstamp_running;
-       }
+       if (read_format & PERF_FORMAT_TOTAL_TIMES)
+               calc_timer_values(event, &enabled, &running);
 
        if (event->attr.read_format & PERF_FORMAT_GROUP)
                perf_output_read_group(handle, event, enabled, running);