diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/fork.c | 9 | ||||
-rw-r--r-- | kernel/perf_counter.c | 185 |
2 files changed, 94 insertions, 100 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index bd2959228871..9b42695f0d14 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -1407,14 +1407,11 @@ long do_fork(unsigned long clone_flags, | |||
1407 | if (clone_flags & CLONE_VFORK) { | 1407 | if (clone_flags & CLONE_VFORK) { |
1408 | p->vfork_done = &vfork; | 1408 | p->vfork_done = &vfork; |
1409 | init_completion(&vfork); | 1409 | init_completion(&vfork); |
1410 | } else if (!(clone_flags & CLONE_VM)) { | ||
1411 | /* | ||
1412 | * vfork will do an exec which will call | ||
1413 | * set_task_comm() | ||
1414 | */ | ||
1415 | perf_counter_fork(p); | ||
1416 | } | 1410 | } |
1417 | 1411 | ||
1412 | if (!(clone_flags & CLONE_THREAD)) | ||
1413 | perf_counter_fork(p); | ||
1414 | |||
1418 | audit_finish_fork(p); | 1415 | audit_finish_fork(p); |
1419 | tracehook_report_clone(regs, clone_flags, nr, p); | 1416 | tracehook_report_clone(regs, clone_flags, nr, p); |
1420 | 1417 | ||
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c index 7bc888dfd06a..950931041954 100644 --- a/kernel/perf_counter.c +++ b/kernel/perf_counter.c | |||
@@ -146,6 +146,28 @@ static void put_ctx(struct perf_counter_context *ctx) | |||
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | static void unclone_ctx(struct perf_counter_context *ctx) | ||
150 | { | ||
151 | if (ctx->parent_ctx) { | ||
152 | put_ctx(ctx->parent_ctx); | ||
153 | ctx->parent_ctx = NULL; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | /* | ||
158 | * If we inherit counters we want to return the parent counter id | ||
159 | * to userspace. | ||
160 | */ | ||
161 | static u64 primary_counter_id(struct perf_counter *counter) | ||
162 | { | ||
163 | u64 id = counter->id; | ||
164 | |||
165 | if (counter->parent) | ||
166 | id = counter->parent->id; | ||
167 | |||
168 | return id; | ||
169 | } | ||
170 | |||
149 | /* | 171 | /* |
150 | * Get the perf_counter_context for a task and lock it. | 172 | * Get the perf_counter_context for a task and lock it. |
151 | * This has to cope with with the fact that until it is locked, | 173 | * This has to cope with with the fact that until it is locked, |
@@ -1288,7 +1310,6 @@ static void perf_counter_cpu_sched_in(struct perf_cpu_context *cpuctx, int cpu) | |||
1288 | #define MAX_INTERRUPTS (~0ULL) | 1310 | #define MAX_INTERRUPTS (~0ULL) |
1289 | 1311 | ||
1290 | static void perf_log_throttle(struct perf_counter *counter, int enable); | 1312 | static void perf_log_throttle(struct perf_counter *counter, int enable); |
1291 | static void perf_log_period(struct perf_counter *counter, u64 period); | ||
1292 | 1313 | ||
1293 | static void perf_adjust_period(struct perf_counter *counter, u64 events) | 1314 | static void perf_adjust_period(struct perf_counter *counter, u64 events) |
1294 | { | 1315 | { |
@@ -1307,8 +1328,6 @@ static void perf_adjust_period(struct perf_counter *counter, u64 events) | |||
1307 | if (!sample_period) | 1328 | if (!sample_period) |
1308 | sample_period = 1; | 1329 | sample_period = 1; |
1309 | 1330 | ||
1310 | perf_log_period(counter, sample_period); | ||
1311 | |||
1312 | hwc->sample_period = sample_period; | 1331 | hwc->sample_period = sample_period; |
1313 | } | 1332 | } |
1314 | 1333 | ||
@@ -1463,10 +1482,8 @@ static void perf_counter_enable_on_exec(struct task_struct *task) | |||
1463 | /* | 1482 | /* |
1464 | * Unclone this context if we enabled any counter. | 1483 | * Unclone this context if we enabled any counter. |
1465 | */ | 1484 | */ |
1466 | if (enabled && ctx->parent_ctx) { | 1485 | if (enabled) |
1467 | put_ctx(ctx->parent_ctx); | 1486 | unclone_ctx(ctx); |
1468 | ctx->parent_ctx = NULL; | ||
1469 | } | ||
1470 | 1487 | ||
1471 | spin_unlock(&ctx->lock); | 1488 | spin_unlock(&ctx->lock); |
1472 | 1489 | ||
@@ -1526,7 +1543,6 @@ __perf_counter_init_context(struct perf_counter_context *ctx, | |||
1526 | 1543 | ||
1527 | static struct perf_counter_context *find_get_context(pid_t pid, int cpu) | 1544 | static struct perf_counter_context *find_get_context(pid_t pid, int cpu) |
1528 | { | 1545 | { |
1529 | struct perf_counter_context *parent_ctx; | ||
1530 | struct perf_counter_context *ctx; | 1546 | struct perf_counter_context *ctx; |
1531 | struct perf_cpu_context *cpuctx; | 1547 | struct perf_cpu_context *cpuctx; |
1532 | struct task_struct *task; | 1548 | struct task_struct *task; |
@@ -1586,11 +1602,7 @@ static struct perf_counter_context *find_get_context(pid_t pid, int cpu) | |||
1586 | retry: | 1602 | retry: |
1587 | ctx = perf_lock_task_context(task, &flags); | 1603 | ctx = perf_lock_task_context(task, &flags); |
1588 | if (ctx) { | 1604 | if (ctx) { |
1589 | parent_ctx = ctx->parent_ctx; | 1605 | unclone_ctx(ctx); |
1590 | if (parent_ctx) { | ||
1591 | put_ctx(parent_ctx); | ||
1592 | ctx->parent_ctx = NULL; /* no longer a clone */ | ||
1593 | } | ||
1594 | spin_unlock_irqrestore(&ctx->lock, flags); | 1606 | spin_unlock_irqrestore(&ctx->lock, flags); |
1595 | } | 1607 | } |
1596 | 1608 | ||
@@ -1704,7 +1716,7 @@ perf_read_hw(struct perf_counter *counter, char __user *buf, size_t count) | |||
1704 | values[n++] = counter->total_time_running + | 1716 | values[n++] = counter->total_time_running + |
1705 | atomic64_read(&counter->child_total_time_running); | 1717 | atomic64_read(&counter->child_total_time_running); |
1706 | if (counter->attr.read_format & PERF_FORMAT_ID) | 1718 | if (counter->attr.read_format & PERF_FORMAT_ID) |
1707 | values[n++] = counter->id; | 1719 | values[n++] = primary_counter_id(counter); |
1708 | mutex_unlock(&counter->child_mutex); | 1720 | mutex_unlock(&counter->child_mutex); |
1709 | 1721 | ||
1710 | if (count < n * sizeof(u64)) | 1722 | if (count < n * sizeof(u64)) |
@@ -1811,8 +1823,6 @@ static int perf_counter_period(struct perf_counter *counter, u64 __user *arg) | |||
1811 | 1823 | ||
1812 | counter->attr.sample_freq = value; | 1824 | counter->attr.sample_freq = value; |
1813 | } else { | 1825 | } else { |
1814 | perf_log_period(counter, value); | ||
1815 | |||
1816 | counter->attr.sample_period = value; | 1826 | counter->attr.sample_period = value; |
1817 | counter->hw.sample_period = value; | 1827 | counter->hw.sample_period = value; |
1818 | } | 1828 | } |
@@ -2661,6 +2671,9 @@ static void perf_counter_output(struct perf_counter *counter, int nmi, | |||
2661 | if (sample_type & PERF_SAMPLE_ID) | 2671 | if (sample_type & PERF_SAMPLE_ID) |
2662 | header.size += sizeof(u64); | 2672 | header.size += sizeof(u64); |
2663 | 2673 | ||
2674 | if (sample_type & PERF_SAMPLE_STREAM_ID) | ||
2675 | header.size += sizeof(u64); | ||
2676 | |||
2664 | if (sample_type & PERF_SAMPLE_CPU) { | 2677 | if (sample_type & PERF_SAMPLE_CPU) { |
2665 | header.size += sizeof(cpu_entry); | 2678 | header.size += sizeof(cpu_entry); |
2666 | 2679 | ||
@@ -2704,7 +2717,13 @@ static void perf_counter_output(struct perf_counter *counter, int nmi, | |||
2704 | if (sample_type & PERF_SAMPLE_ADDR) | 2717 | if (sample_type & PERF_SAMPLE_ADDR) |
2705 | perf_output_put(&handle, data->addr); | 2718 | perf_output_put(&handle, data->addr); |
2706 | 2719 | ||
2707 | if (sample_type & PERF_SAMPLE_ID) | 2720 | if (sample_type & PERF_SAMPLE_ID) { |
2721 | u64 id = primary_counter_id(counter); | ||
2722 | |||
2723 | perf_output_put(&handle, id); | ||
2724 | } | ||
2725 | |||
2726 | if (sample_type & PERF_SAMPLE_STREAM_ID) | ||
2708 | perf_output_put(&handle, counter->id); | 2727 | perf_output_put(&handle, counter->id); |
2709 | 2728 | ||
2710 | if (sample_type & PERF_SAMPLE_CPU) | 2729 | if (sample_type & PERF_SAMPLE_CPU) |
@@ -2727,7 +2746,7 @@ static void perf_counter_output(struct perf_counter *counter, int nmi, | |||
2727 | if (sub != counter) | 2746 | if (sub != counter) |
2728 | sub->pmu->read(sub); | 2747 | sub->pmu->read(sub); |
2729 | 2748 | ||
2730 | group_entry.id = sub->id; | 2749 | group_entry.id = primary_counter_id(sub); |
2731 | group_entry.counter = atomic64_read(&sub->count); | 2750 | group_entry.counter = atomic64_read(&sub->count); |
2732 | 2751 | ||
2733 | perf_output_put(&handle, group_entry); | 2752 | perf_output_put(&handle, group_entry); |
@@ -2787,15 +2806,8 @@ perf_counter_read_event(struct perf_counter *counter, | |||
2787 | } | 2806 | } |
2788 | 2807 | ||
2789 | if (counter->attr.read_format & PERF_FORMAT_ID) { | 2808 | if (counter->attr.read_format & PERF_FORMAT_ID) { |
2790 | u64 id; | ||
2791 | |||
2792 | event.header.size += sizeof(u64); | 2809 | event.header.size += sizeof(u64); |
2793 | if (counter->parent) | 2810 | event.format[i++] = primary_counter_id(counter); |
2794 | id = counter->parent->id; | ||
2795 | else | ||
2796 | id = counter->id; | ||
2797 | |||
2798 | event.format[i++] = id; | ||
2799 | } | 2811 | } |
2800 | 2812 | ||
2801 | ret = perf_output_begin(&handle, counter, event.header.size, 0, 0); | 2813 | ret = perf_output_begin(&handle, counter, event.header.size, 0, 0); |
@@ -2896,8 +2908,11 @@ void perf_counter_fork(struct task_struct *task) | |||
2896 | .event = { | 2908 | .event = { |
2897 | .header = { | 2909 | .header = { |
2898 | .type = PERF_EVENT_FORK, | 2910 | .type = PERF_EVENT_FORK, |
2911 | .misc = 0, | ||
2899 | .size = sizeof(fork_event.event), | 2912 | .size = sizeof(fork_event.event), |
2900 | }, | 2913 | }, |
2914 | /* .pid */ | ||
2915 | /* .ppid */ | ||
2901 | }, | 2916 | }, |
2902 | }; | 2917 | }; |
2903 | 2918 | ||
@@ -2969,8 +2984,10 @@ static void perf_counter_comm_event(struct perf_comm_event *comm_event) | |||
2969 | struct perf_cpu_context *cpuctx; | 2984 | struct perf_cpu_context *cpuctx; |
2970 | struct perf_counter_context *ctx; | 2985 | struct perf_counter_context *ctx; |
2971 | unsigned int size; | 2986 | unsigned int size; |
2972 | char *comm = comm_event->task->comm; | 2987 | char comm[TASK_COMM_LEN]; |
2973 | 2988 | ||
2989 | memset(comm, 0, sizeof(comm)); | ||
2990 | strncpy(comm, comm_event->task->comm, sizeof(comm)); | ||
2974 | size = ALIGN(strlen(comm)+1, sizeof(u64)); | 2991 | size = ALIGN(strlen(comm)+1, sizeof(u64)); |
2975 | 2992 | ||
2976 | comm_event->comm = comm; | 2993 | comm_event->comm = comm; |
@@ -3005,8 +3022,16 @@ void perf_counter_comm(struct task_struct *task) | |||
3005 | 3022 | ||
3006 | comm_event = (struct perf_comm_event){ | 3023 | comm_event = (struct perf_comm_event){ |
3007 | .task = task, | 3024 | .task = task, |
3025 | /* .comm */ | ||
3026 | /* .comm_size */ | ||
3008 | .event = { | 3027 | .event = { |
3009 | .header = { .type = PERF_EVENT_COMM, }, | 3028 | .header = { |
3029 | .type = PERF_EVENT_COMM, | ||
3030 | .misc = 0, | ||
3031 | /* .size */ | ||
3032 | }, | ||
3033 | /* .pid */ | ||
3034 | /* .tid */ | ||
3010 | }, | 3035 | }, |
3011 | }; | 3036 | }; |
3012 | 3037 | ||
@@ -3089,8 +3114,15 @@ static void perf_counter_mmap_event(struct perf_mmap_event *mmap_event) | |||
3089 | char *buf = NULL; | 3114 | char *buf = NULL; |
3090 | const char *name; | 3115 | const char *name; |
3091 | 3116 | ||
3117 | memset(tmp, 0, sizeof(tmp)); | ||
3118 | |||
3092 | if (file) { | 3119 | if (file) { |
3093 | buf = kzalloc(PATH_MAX, GFP_KERNEL); | 3120 | /* |
3121 | * d_path works from the end of the buffer backwards, so we | ||
3122 | * need to add enough zero bytes after the string to handle | ||
3123 | * the 64bit alignment we do later. | ||
3124 | */ | ||
3125 | buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL); | ||
3094 | if (!buf) { | 3126 | if (!buf) { |
3095 | name = strncpy(tmp, "//enomem", sizeof(tmp)); | 3127 | name = strncpy(tmp, "//enomem", sizeof(tmp)); |
3096 | goto got_name; | 3128 | goto got_name; |
@@ -3101,9 +3133,11 @@ static void perf_counter_mmap_event(struct perf_mmap_event *mmap_event) | |||
3101 | goto got_name; | 3133 | goto got_name; |
3102 | } | 3134 | } |
3103 | } else { | 3135 | } else { |
3104 | name = arch_vma_name(mmap_event->vma); | 3136 | if (arch_vma_name(mmap_event->vma)) { |
3105 | if (name) | 3137 | name = strncpy(tmp, arch_vma_name(mmap_event->vma), |
3138 | sizeof(tmp)); | ||
3106 | goto got_name; | 3139 | goto got_name; |
3140 | } | ||
3107 | 3141 | ||
3108 | if (!vma->vm_mm) { | 3142 | if (!vma->vm_mm) { |
3109 | name = strncpy(tmp, "[vdso]", sizeof(tmp)); | 3143 | name = strncpy(tmp, "[vdso]", sizeof(tmp)); |
@@ -3148,8 +3182,16 @@ void __perf_counter_mmap(struct vm_area_struct *vma) | |||
3148 | 3182 | ||
3149 | mmap_event = (struct perf_mmap_event){ | 3183 | mmap_event = (struct perf_mmap_event){ |
3150 | .vma = vma, | 3184 | .vma = vma, |
3185 | /* .file_name */ | ||
3186 | /* .file_size */ | ||
3151 | .event = { | 3187 | .event = { |
3152 | .header = { .type = PERF_EVENT_MMAP, }, | 3188 | .header = { |
3189 | .type = PERF_EVENT_MMAP, | ||
3190 | .misc = 0, | ||
3191 | /* .size */ | ||
3192 | }, | ||
3193 | /* .pid */ | ||
3194 | /* .tid */ | ||
3153 | .start = vma->vm_start, | 3195 | .start = vma->vm_start, |
3154 | .len = vma->vm_end - vma->vm_start, | 3196 | .len = vma->vm_end - vma->vm_start, |
3155 | .pgoff = vma->vm_pgoff, | 3197 | .pgoff = vma->vm_pgoff, |
@@ -3160,49 +3202,6 @@ void __perf_counter_mmap(struct vm_area_struct *vma) | |||
3160 | } | 3202 | } |
3161 | 3203 | ||
3162 | /* | 3204 | /* |
3163 | * Log sample_period changes so that analyzing tools can re-normalize the | ||
3164 | * event flow. | ||
3165 | */ | ||
3166 | |||
3167 | struct freq_event { | ||
3168 | struct perf_event_header header; | ||
3169 | u64 time; | ||
3170 | u64 id; | ||
3171 | u64 period; | ||
3172 | }; | ||
3173 | |||
3174 | static void perf_log_period(struct perf_counter *counter, u64 period) | ||
3175 | { | ||
3176 | struct perf_output_handle handle; | ||
3177 | struct freq_event event; | ||
3178 | int ret; | ||
3179 | |||
3180 | if (counter->hw.sample_period == period) | ||
3181 | return; | ||
3182 | |||
3183 | if (counter->attr.sample_type & PERF_SAMPLE_PERIOD) | ||
3184 | return; | ||
3185 | |||
3186 | event = (struct freq_event) { | ||
3187 | .header = { | ||
3188 | .type = PERF_EVENT_PERIOD, | ||
3189 | .misc = 0, | ||
3190 | .size = sizeof(event), | ||
3191 | }, | ||
3192 | .time = sched_clock(), | ||
3193 | .id = counter->id, | ||
3194 | .period = period, | ||
3195 | }; | ||
3196 | |||
3197 | ret = perf_output_begin(&handle, counter, sizeof(event), 1, 0); | ||
3198 | if (ret) | ||
3199 | return; | ||
3200 | |||
3201 | perf_output_put(&handle, event); | ||
3202 | perf_output_end(&handle); | ||
3203 | } | ||
3204 | |||
3205 | /* | ||
3206 | * IRQ throttle logging | 3205 | * IRQ throttle logging |
3207 | */ | 3206 | */ |
3208 | 3207 | ||
@@ -3215,16 +3214,21 @@ static void perf_log_throttle(struct perf_counter *counter, int enable) | |||
3215 | struct perf_event_header header; | 3214 | struct perf_event_header header; |
3216 | u64 time; | 3215 | u64 time; |
3217 | u64 id; | 3216 | u64 id; |
3217 | u64 stream_id; | ||
3218 | } throttle_event = { | 3218 | } throttle_event = { |
3219 | .header = { | 3219 | .header = { |
3220 | .type = PERF_EVENT_THROTTLE + 1, | 3220 | .type = PERF_EVENT_THROTTLE, |
3221 | .misc = 0, | 3221 | .misc = 0, |
3222 | .size = sizeof(throttle_event), | 3222 | .size = sizeof(throttle_event), |
3223 | }, | 3223 | }, |
3224 | .time = sched_clock(), | 3224 | .time = sched_clock(), |
3225 | .id = counter->id, | 3225 | .id = primary_counter_id(counter), |
3226 | .stream_id = counter->id, | ||
3226 | }; | 3227 | }; |
3227 | 3228 | ||
3229 | if (enable) | ||
3230 | throttle_event.header.type = PERF_EVENT_UNTHROTTLE; | ||
3231 | |||
3228 | ret = perf_output_begin(&handle, counter, sizeof(throttle_event), 1, 0); | 3232 | ret = perf_output_begin(&handle, counter, sizeof(throttle_event), 1, 0); |
3229 | if (ret) | 3233 | if (ret) |
3230 | return; | 3234 | return; |
@@ -3672,7 +3676,7 @@ static const struct pmu perf_ops_task_clock = { | |||
3672 | void perf_tpcounter_event(int event_id) | 3676 | void perf_tpcounter_event(int event_id) |
3673 | { | 3677 | { |
3674 | struct perf_sample_data data = { | 3678 | struct perf_sample_data data = { |
3675 | .regs = get_irq_regs(); | 3679 | .regs = get_irq_regs(), |
3676 | .addr = 0, | 3680 | .addr = 0, |
3677 | }; | 3681 | }; |
3678 | 3682 | ||
@@ -3688,16 +3692,12 @@ extern void ftrace_profile_disable(int); | |||
3688 | 3692 | ||
3689 | static void tp_perf_counter_destroy(struct perf_counter *counter) | 3693 | static void tp_perf_counter_destroy(struct perf_counter *counter) |
3690 | { | 3694 | { |
3691 | ftrace_profile_disable(perf_event_id(&counter->attr)); | 3695 | ftrace_profile_disable(counter->attr.config); |
3692 | } | 3696 | } |
3693 | 3697 | ||
3694 | static const struct pmu *tp_perf_counter_init(struct perf_counter *counter) | 3698 | static const struct pmu *tp_perf_counter_init(struct perf_counter *counter) |
3695 | { | 3699 | { |
3696 | int event_id = perf_event_id(&counter->attr); | 3700 | if (ftrace_profile_enable(counter->attr.config)) |
3697 | int ret; | ||
3698 | |||
3699 | ret = ftrace_profile_enable(event_id); | ||
3700 | if (ret) | ||
3701 | return NULL; | 3701 | return NULL; |
3702 | 3702 | ||
3703 | counter->destroy = tp_perf_counter_destroy; | 3703 | counter->destroy = tp_perf_counter_destroy; |
@@ -4256,15 +4256,12 @@ void perf_counter_exit_task(struct task_struct *child) | |||
4256 | */ | 4256 | */ |
4257 | spin_lock(&child_ctx->lock); | 4257 | spin_lock(&child_ctx->lock); |
4258 | child->perf_counter_ctxp = NULL; | 4258 | child->perf_counter_ctxp = NULL; |
4259 | if (child_ctx->parent_ctx) { | 4259 | /* |
4260 | /* | 4260 | * If this context is a clone; unclone it so it can't get |
4261 | * This context is a clone; unclone it so it can't get | 4261 | * swapped to another process while we're removing all |
4262 | * swapped to another process while we're removing all | 4262 | * the counters from it. |
4263 | * the counters from it. | 4263 | */ |
4264 | */ | 4264 | unclone_ctx(child_ctx); |
4265 | put_ctx(child_ctx->parent_ctx); | ||
4266 | child_ctx->parent_ctx = NULL; | ||
4267 | } | ||
4268 | spin_unlock(&child_ctx->lock); | 4265 | spin_unlock(&child_ctx->lock); |
4269 | local_irq_restore(flags); | 4266 | local_irq_restore(flags); |
4270 | 4267 | ||