perf_counter: Rename list_entry -> group_entry, counter_list -> group_list
[deliverable/linux.git] / kernel / perf_counter.c
index 215845243a691f47ac3846ab8fcefcd3187dfc65..13ad73aed4ca3dd119e36c1c4c3f599756db66bb 100644 (file)
@@ -106,16 +106,16 @@ hw_perf_group_sched_in(struct perf_counter *group_leader,
 
 void __weak perf_counter_print_debug(void)     { }
 
-static DEFINE_PER_CPU(int, disable_count);
+static DEFINE_PER_CPU(int, perf_disable_count);
 
 void __perf_disable(void)
 {
-       __get_cpu_var(disable_count)++;
+       __get_cpu_var(perf_disable_count)++;
 }
 
 bool __perf_enable(void)
 {
-       return !--__get_cpu_var(disable_count);
+       return !--__get_cpu_var(perf_disable_count);
 }
 
 void perf_disable(void)
@@ -258,9 +258,9 @@ list_add_counter(struct perf_counter *counter, struct perf_counter_context *ctx)
         * leader's sibling list:
         */
        if (group_leader == counter)
-               list_add_tail(&counter->list_entry, &ctx->counter_list);
+               list_add_tail(&counter->group_entry, &ctx->group_list);
        else {
-               list_add_tail(&counter->list_entry, &group_leader->sibling_list);
+               list_add_tail(&counter->group_entry, &group_leader->sibling_list);
                group_leader->nr_siblings++;
        }
 
@@ -279,13 +279,13 @@ list_del_counter(struct perf_counter *counter, struct perf_counter_context *ctx)
 {
        struct perf_counter *sibling, *tmp;
 
-       if (list_empty(&counter->list_entry))
+       if (list_empty(&counter->group_entry))
                return;
        ctx->nr_counters--;
        if (counter->attr.inherit_stat)
                ctx->nr_stat--;
 
-       list_del_init(&counter->list_entry);
+       list_del_init(&counter->group_entry);
        list_del_rcu(&counter->event_entry);
 
        if (counter->group_leader != counter)
@@ -296,10 +296,9 @@ list_del_counter(struct perf_counter *counter, struct perf_counter_context *ctx)
         * upgrade the siblings to singleton counters by adding them
         * to the context list directly:
         */
-       list_for_each_entry_safe(sibling, tmp,
-                                &counter->sibling_list, list_entry) {
+       list_for_each_entry_safe(sibling, tmp, &counter->sibling_list, group_entry) {
 
-               list_move_tail(&sibling->list_entry, &ctx->counter_list);
+               list_move_tail(&sibling->group_entry, &ctx->group_list);
                sibling->group_leader = sibling;
        }
 }
@@ -343,7 +342,7 @@ group_sched_out(struct perf_counter *group_counter,
        /*
         * Schedule out siblings (if any):
         */
-       list_for_each_entry(counter, &group_counter->sibling_list, list_entry)
+       list_for_each_entry(counter, &group_counter->sibling_list, group_entry)
                counter_sched_out(counter, cpuctx, ctx);
 
        if (group_counter->attr.exclusive)
@@ -435,7 +434,7 @@ retry:
        /*
         * If the context is active we need to retry the smp call.
         */
-       if (ctx->nr_active && !list_empty(&counter->list_entry)) {
+       if (ctx->nr_active && !list_empty(&counter->group_entry)) {
                spin_unlock_irq(&ctx->lock);
                goto retry;
        }
@@ -445,7 +444,7 @@ retry:
         * can remove the counter safely, if the call above did not
         * succeed.
         */
-       if (!list_empty(&counter->list_entry)) {
+       if (!list_empty(&counter->group_entry)) {
                list_del_counter(counter, ctx);
        }
        spin_unlock_irq(&ctx->lock);
@@ -497,7 +496,7 @@ static void update_group_times(struct perf_counter *leader)
        struct perf_counter *counter;
 
        update_counter_times(leader);
-       list_for_each_entry(counter, &leader->sibling_list, list_entry)
+       list_for_each_entry(counter, &leader->sibling_list, group_entry)
                update_counter_times(counter);
 }
 
@@ -643,7 +642,7 @@ group_sched_in(struct perf_counter *group_counter,
        /*
         * Schedule in siblings as one group (if any):
         */
-       list_for_each_entry(counter, &group_counter->sibling_list, list_entry) {
+       list_for_each_entry(counter, &group_counter->sibling_list, group_entry) {
                if (counter_sched_in(counter, cpuctx, ctx, cpu)) {
                        partial_group = counter;
                        goto group_error;
@@ -657,7 +656,7 @@ group_error:
         * Groups can be scheduled in as one unit only, so undo any
         * partial group before returning:
         */
-       list_for_each_entry(counter, &group_counter->sibling_list, list_entry) {
+       list_for_each_entry(counter, &group_counter->sibling_list, group_entry) {
                if (counter == partial_group)
                        break;
                counter_sched_out(counter, cpuctx, ctx);
@@ -678,7 +677,7 @@ static int is_software_only_group(struct perf_counter *leader)
        if (!is_software_counter(leader))
                return 0;
 
-       list_for_each_entry(counter, &leader->sibling_list, list_entry)
+       list_for_each_entry(counter, &leader->sibling_list, group_entry)
                if (!is_software_counter(counter))
                        return 0;
 
@@ -842,7 +841,7 @@ retry:
        /*
         * we need to retry the smp call.
         */
-       if (ctx->is_active && list_empty(&counter->list_entry)) {
+       if (ctx->is_active && list_empty(&counter->group_entry)) {
                spin_unlock_irq(&ctx->lock);
                goto retry;
        }
@@ -852,7 +851,7 @@ retry:
         * can add the counter safely, if it the call above did not
         * succeed.
         */
-       if (list_empty(&counter->list_entry))
+       if (list_empty(&counter->group_entry))
                add_counter_to_ctx(counter, ctx);
        spin_unlock_irq(&ctx->lock);
 }
@@ -872,7 +871,7 @@ static void __perf_counter_mark_enabled(struct perf_counter *counter,
 
        counter->state = PERF_COUNTER_STATE_INACTIVE;
        counter->tstamp_enabled = ctx->time - counter->total_time_enabled;
-       list_for_each_entry(sub, &counter->sibling_list, list_entry)
+       list_for_each_entry(sub, &counter->sibling_list, group_entry)
                if (sub->state >= PERF_COUNTER_STATE_INACTIVE)
                        sub->tstamp_enabled =
                                ctx->time - sub->total_time_enabled;
@@ -1032,7 +1031,7 @@ void __perf_counter_sched_out(struct perf_counter_context *ctx,
 
        perf_disable();
        if (ctx->nr_active) {
-               list_for_each_entry(counter, &ctx->counter_list, list_entry) {
+               list_for_each_entry(counter, &ctx->group_list, group_entry) {
                        if (counter != counter->group_leader)
                                counter_sched_out(counter, cpuctx, ctx);
                        else
@@ -1252,7 +1251,7 @@ __perf_counter_sched_in(struct perf_counter_context *ctx,
         * First go through the list and put on any pinned groups
         * in order to give them the best chance of going on.
         */
-       list_for_each_entry(counter, &ctx->counter_list, list_entry) {
+       list_for_each_entry(counter, &ctx->group_list, group_entry) {
                if (counter->state <= PERF_COUNTER_STATE_OFF ||
                    !counter->attr.pinned)
                        continue;
@@ -1276,7 +1275,7 @@ __perf_counter_sched_in(struct perf_counter_context *ctx,
                }
        }
 
-       list_for_each_entry(counter, &ctx->counter_list, list_entry) {
+       list_for_each_entry(counter, &ctx->group_list, group_entry) {
                /*
                 * Ignore counters in OFF or ERROR state, and
                 * ignore pinned counters since we did them already.
@@ -1369,7 +1368,7 @@ static void perf_ctx_adjust_freq(struct perf_counter_context *ctx)
        u64 interrupts, freq;
 
        spin_lock(&ctx->lock);
-       list_for_each_entry(counter, &ctx->counter_list, list_entry) {
+       list_for_each_entry(counter, &ctx->group_list, group_entry) {
                if (counter->state != PERF_COUNTER_STATE_ACTIVE)
                        continue;
 
@@ -1441,8 +1440,8 @@ static void rotate_ctx(struct perf_counter_context *ctx)
         * Rotate the first entry last (works just fine for group counters too):
         */
        perf_disable();
-       list_for_each_entry(counter, &ctx->counter_list, list_entry) {
-               list_move_tail(&counter->list_entry, &ctx->counter_list);
+       list_for_each_entry(counter, &ctx->group_list, group_entry) {
+               list_move_tail(&counter->group_entry, &ctx->group_list);
                break;
        }
        perf_enable();
@@ -1498,7 +1497,7 @@ static void perf_counter_enable_on_exec(struct task_struct *task)
 
        spin_lock(&ctx->lock);
 
-       list_for_each_entry(counter, &ctx->counter_list, list_entry) {
+       list_for_each_entry(counter, &ctx->group_list, group_entry) {
                if (!counter->attr.enable_on_exec)
                        continue;
                counter->attr.enable_on_exec = 0;
@@ -1575,7 +1574,7 @@ __perf_counter_init_context(struct perf_counter_context *ctx,
        memset(ctx, 0, sizeof(*ctx));
        spin_lock_init(&ctx->lock);
        mutex_init(&ctx->mutex);
-       INIT_LIST_HEAD(&ctx->counter_list);
+       INIT_LIST_HEAD(&ctx->group_list);
        INIT_LIST_HEAD(&ctx->event_list);
        atomic_set(&ctx->refcount, 1);
        ctx->task = task;
@@ -1818,7 +1817,7 @@ static int perf_counter_read_group(struct perf_counter *counter,
 
        size += err;
 
-       list_for_each_entry(sub, &leader->sibling_list, list_entry) {
+       list_for_each_entry(sub, &leader->sibling_list, group_entry) {
                err = perf_counter_read_entry(sub, read_format,
                                buf + size);
                if (err < 0)
@@ -1948,7 +1947,7 @@ static void perf_counter_for_each(struct perf_counter *counter,
 
        perf_counter_for_each_child(counter, func);
        func(counter);
-       list_for_each_entry(sibling, &counter->sibling_list, list_entry)
+       list_for_each_entry(sibling, &counter->sibling_list, group_entry)
                perf_counter_for_each_child(counter, func);
        mutex_unlock(&ctx->mutex);
 }
@@ -2832,7 +2831,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
 
        perf_output_copy(handle, values, n * sizeof(u64));
 
-       list_for_each_entry(sub, &leader->sibling_list, list_entry) {
+       list_for_each_entry(sub, &leader->sibling_list, group_entry) {
                n = 0;
 
                if (sub != counter)
@@ -2955,10 +2954,7 @@ void perf_prepare_sample(struct perf_event_header *header,
        }
 
        if (sample_type & PERF_SAMPLE_TIME) {
-               /*
-                * Maybe do better on x86 and provide cpu_clock_nmi()
-                */
-               data->time = sched_clock();
+               data->time = perf_clock();
 
                header->size += sizeof(data->time);
        }
@@ -3086,6 +3082,7 @@ struct perf_task_event {
                u32                             ppid;
                u32                             tid;
                u32                             ptid;
+               u64                             time;
        } event;
 };
 
@@ -3093,9 +3090,12 @@ static void perf_counter_task_output(struct perf_counter *counter,
                                     struct perf_task_event *task_event)
 {
        struct perf_output_handle handle;
-       int size = task_event->event.header.size;
+       int size;
        struct task_struct *task = task_event->task;
-       int ret = perf_output_begin(&handle, counter, size, 0, 0);
+       int ret;
+
+       size  = task_event->event.header.size;
+       ret = perf_output_begin(&handle, counter, size, 0, 0);
 
        if (ret)
                return;
@@ -3106,7 +3106,10 @@ static void perf_counter_task_output(struct perf_counter *counter,
        task_event->event.tid = perf_counter_tid(counter, task);
        task_event->event.ptid = perf_counter_tid(counter, current);
 
+       task_event->event.time = perf_clock();
+
        perf_output_put(&handle, task_event->event);
+
        perf_output_end(&handle);
 }
 
@@ -3488,7 +3491,7 @@ static void perf_log_throttle(struct perf_counter *counter, int enable)
                        .misc = 0,
                        .size = sizeof(throttle_event),
                },
-               .time           = sched_clock(),
+               .time           = perf_clock(),
                .id             = primary_counter_id(counter),
                .stream_id      = counter->id,
        };
@@ -3540,7 +3543,7 @@ static int __perf_counter_overflow(struct perf_counter *counter, int nmi,
        }
 
        if (counter->attr.freq) {
-               u64 now = sched_clock();
+               u64 now = perf_clock();
                s64 delta = now - hwc->freq_stamp;
 
                hwc->freq_stamp = now;
@@ -3634,7 +3637,7 @@ static void perf_swcounter_overflow(struct perf_counter *counter,
                         */
                        break;
                }
-               throttle = 0;
+               throttle = 1;
        }
 }
 
@@ -4114,7 +4117,7 @@ perf_counter_alloc(struct perf_counter_attr *attr,
        mutex_init(&counter->child_mutex);
        INIT_LIST_HEAD(&counter->child_list);
 
-       INIT_LIST_HEAD(&counter->list_entry);
+       INIT_LIST_HEAD(&counter->group_entry);
        INIT_LIST_HEAD(&counter->event_entry);
        INIT_LIST_HEAD(&counter->sibling_list);
        init_waitqueue_head(&counter->waitq);
@@ -4204,8 +4207,8 @@ done:
 static int perf_copy_attr(struct perf_counter_attr __user *uattr,
                          struct perf_counter_attr *attr)
 {
-       int ret;
        u32 size;
+       int ret;
 
        if (!access_ok(VERIFY_WRITE, uattr, PERF_ATTR_SIZE_VER0))
                return -EFAULT;
@@ -4230,25 +4233,26 @@ static int perf_copy_attr(struct perf_counter_attr __user *uattr,
 
        /*
         * If we're handed a bigger struct than we know of,
-        * ensure all the unknown bits are 0.
+        * ensure all the unknown bits are 0 - i.e. new
+        * user-space does not rely on any kernel feature
+        * extensions we dont know about yet.
         */
        if (size > sizeof(*attr)) {
-               unsigned long val;
-               unsigned long __user *addr;
-               unsigned long __user *end;
+               unsigned char __user *addr;
+               unsigned char __user *end;
+               unsigned char val;
 
-               addr = PTR_ALIGN((void __user *)uattr + sizeof(*attr),
-                               sizeof(unsigned long));
-               end  = PTR_ALIGN((void __user *)uattr + size,
-                               sizeof(unsigned long));
+               addr = (void __user *)uattr + sizeof(*attr);
+               end  = (void __user *)uattr + size;
 
-               for (; addr < end; addr += sizeof(unsigned long)) {
+               for (; addr < end; addr++) {
                        ret = get_user(val, addr);
                        if (ret)
                                return ret;
                        if (val)
                                goto err_size;
                }
+               size = sizeof(*attr);
        }
 
        ret = copy_from_user(attr, uattr, size);
@@ -4539,7 +4543,7 @@ static int inherit_group(struct perf_counter *parent_counter,
                                 child, NULL, child_ctx);
        if (IS_ERR(leader))
                return PTR_ERR(leader);
-       list_for_each_entry(sub, &parent_counter->sibling_list, list_entry) {
+       list_for_each_entry(sub, &parent_counter->sibling_list, group_entry) {
                child_ctr = inherit_counter(sub, parent, parent_ctx,
                                            child, leader, child_ctx);
                if (IS_ERR(child_ctr))
@@ -4665,8 +4669,8 @@ void perf_counter_exit_task(struct task_struct *child)
        mutex_lock_nested(&child_ctx->mutex, SINGLE_DEPTH_NESTING);
 
 again:
-       list_for_each_entry_safe(child_counter, tmp, &child_ctx->counter_list,
-                                list_entry)
+       list_for_each_entry_safe(child_counter, tmp, &child_ctx->group_list,
+                                group_entry)
                __perf_counter_exit_task(child_counter, child_ctx, child);
 
        /*
@@ -4674,7 +4678,7 @@ again:
         * its siblings to the list, but we obtained 'tmp' before that which
         * will still point to the list head terminating the iteration.
         */
-       if (!list_empty(&child_ctx->counter_list))
+       if (!list_empty(&child_ctx->group_list))
                goto again;
 
        mutex_unlock(&child_ctx->mutex);
@@ -4696,7 +4700,7 @@ void perf_counter_free_task(struct task_struct *task)
 
        mutex_lock(&ctx->mutex);
 again:
-       list_for_each_entry_safe(counter, tmp, &ctx->counter_list, list_entry) {
+       list_for_each_entry_safe(counter, tmp, &ctx->group_list, group_entry) {
                struct perf_counter *parent = counter->parent;
 
                if (WARN_ON_ONCE(!parent))
@@ -4712,7 +4716,7 @@ again:
                free_counter(counter);
        }
 
-       if (!list_empty(&ctx->counter_list))
+       if (!list_empty(&ctx->group_list))
                goto again;
 
        mutex_unlock(&ctx->mutex);
@@ -4842,7 +4846,7 @@ static void __perf_counter_exit_cpu(void *info)
        struct perf_counter_context *ctx = &cpuctx->ctx;
        struct perf_counter *counter, *tmp;
 
-       list_for_each_entry_safe(counter, tmp, &ctx->counter_list, list_entry)
+       list_for_each_entry_safe(counter, tmp, &ctx->group_list, group_entry)
                __perf_counter_remove_from_context(counter);
 }
 static void perf_counter_exit_cpu(int cpu)
This page took 0.035165 seconds and 5 git commands to generate.