diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-02-11 13:20:06 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-02-11 13:20:06 -0500 |
commit | d5b76bef01047843cc65bd018046c76182b1fc81 (patch) | |
tree | 13aa1b0019d2afeb53257edde54e36c3fa86ecdf | |
parent | 4e4f74a7eebbc52eaa1dc3c0be6b3c68c0875b09 (diff) | |
parent | 451d24d1e5f40bad000fa9abe36ddb16fc9928cb (diff) |
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf fixes from Ingo Molnar:
"A kernel crash fix plus three tooling fixes"
* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf/core: Fix crash in perf_event_read()
perf callchain: Reference count maps
perf diff: Fix -o/--order option behavior (again)
perf diff: Fix segfault on 'perf diff -o N' option
-rw-r--r-- | kernel/events/core.c | 25 | ||||
-rw-r--r-- | tools/perf/builtin-diff.c | 2 | ||||
-rw-r--r-- | tools/perf/ui/hist.c | 10 | ||||
-rw-r--r-- | tools/perf/util/callchain.c | 11 | ||||
-rw-r--r-- | tools/perf/util/callchain.h | 6 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 7 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 7 |
7 files changed, 55 insertions, 13 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c index e5aaa806702d..e235bb991bdd 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c | |||
@@ -3487,14 +3487,15 @@ struct perf_read_data { | |||
3487 | int ret; | 3487 | int ret; |
3488 | }; | 3488 | }; |
3489 | 3489 | ||
3490 | static int find_cpu_to_read(struct perf_event *event, int local_cpu) | 3490 | static int __perf_event_read_cpu(struct perf_event *event, int event_cpu) |
3491 | { | 3491 | { |
3492 | int event_cpu = event->oncpu; | ||
3493 | u16 local_pkg, event_pkg; | 3492 | u16 local_pkg, event_pkg; |
3494 | 3493 | ||
3495 | if (event->group_caps & PERF_EV_CAP_READ_ACTIVE_PKG) { | 3494 | if (event->group_caps & PERF_EV_CAP_READ_ACTIVE_PKG) { |
3496 | event_pkg = topology_physical_package_id(event_cpu); | 3495 | int local_cpu = smp_processor_id(); |
3497 | local_pkg = topology_physical_package_id(local_cpu); | 3496 | |
3497 | event_pkg = topology_physical_package_id(event_cpu); | ||
3498 | local_pkg = topology_physical_package_id(local_cpu); | ||
3498 | 3499 | ||
3499 | if (event_pkg == local_pkg) | 3500 | if (event_pkg == local_pkg) |
3500 | return local_cpu; | 3501 | return local_cpu; |
@@ -3624,7 +3625,7 @@ u64 perf_event_read_local(struct perf_event *event) | |||
3624 | 3625 | ||
3625 | static int perf_event_read(struct perf_event *event, bool group) | 3626 | static int perf_event_read(struct perf_event *event, bool group) |
3626 | { | 3627 | { |
3627 | int ret = 0, cpu_to_read, local_cpu; | 3628 | int event_cpu, ret = 0; |
3628 | 3629 | ||
3629 | /* | 3630 | /* |
3630 | * If event is enabled and currently active on a CPU, update the | 3631 | * If event is enabled and currently active on a CPU, update the |
@@ -3637,21 +3638,25 @@ static int perf_event_read(struct perf_event *event, bool group) | |||
3637 | .ret = 0, | 3638 | .ret = 0, |
3638 | }; | 3639 | }; |
3639 | 3640 | ||
3640 | local_cpu = get_cpu(); | 3641 | event_cpu = READ_ONCE(event->oncpu); |
3641 | cpu_to_read = find_cpu_to_read(event, local_cpu); | 3642 | if ((unsigned)event_cpu >= nr_cpu_ids) |
3642 | put_cpu(); | 3643 | return 0; |
3644 | |||
3645 | preempt_disable(); | ||
3646 | event_cpu = __perf_event_read_cpu(event, event_cpu); | ||
3643 | 3647 | ||
3644 | /* | 3648 | /* |
3645 | * Purposely ignore the smp_call_function_single() return | 3649 | * Purposely ignore the smp_call_function_single() return |
3646 | * value. | 3650 | * value. |
3647 | * | 3651 | * |
3648 | * If event->oncpu isn't a valid CPU it means the event got | 3652 | * If event_cpu isn't a valid CPU it means the event got |
3649 | * scheduled out and that will have updated the event count. | 3653 | * scheduled out and that will have updated the event count. |
3650 | * | 3654 | * |
3651 | * Therefore, either way, we'll have an up-to-date event count | 3655 | * Therefore, either way, we'll have an up-to-date event count |
3652 | * after this. | 3656 | * after this. |
3653 | */ | 3657 | */ |
3654 | (void)smp_call_function_single(cpu_to_read, __perf_event_read, &data, 1); | 3658 | (void)smp_call_function_single(event_cpu, __perf_event_read, &data, 1); |
3659 | preempt_enable(); | ||
3655 | ret = data.ret; | 3660 | ret = data.ret; |
3656 | } else if (event->state == PERF_EVENT_STATE_INACTIVE) { | 3661 | } else if (event->state == PERF_EVENT_STATE_INACTIVE) { |
3657 | struct perf_event_context *ctx = event->ctx; | 3662 | struct perf_event_context *ctx = event->ctx; |
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 9ff0db4e2d0c..933aeec46f4a 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -1199,7 +1199,7 @@ static int ui_init(void) | |||
1199 | BUG_ON(1); | 1199 | BUG_ON(1); |
1200 | } | 1200 | } |
1201 | 1201 | ||
1202 | perf_hpp__register_sort_field(fmt); | 1202 | perf_hpp__prepend_sort_field(fmt); |
1203 | return 0; | 1203 | return 0; |
1204 | } | 1204 | } |
1205 | 1205 | ||
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 37388397b5bc..18cfcdc90356 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
@@ -521,6 +521,12 @@ void perf_hpp_list__register_sort_field(struct perf_hpp_list *list, | |||
521 | list_add_tail(&format->sort_list, &list->sorts); | 521 | list_add_tail(&format->sort_list, &list->sorts); |
522 | } | 522 | } |
523 | 523 | ||
524 | void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list, | ||
525 | struct perf_hpp_fmt *format) | ||
526 | { | ||
527 | list_add(&format->sort_list, &list->sorts); | ||
528 | } | ||
529 | |||
524 | void perf_hpp__column_unregister(struct perf_hpp_fmt *format) | 530 | void perf_hpp__column_unregister(struct perf_hpp_fmt *format) |
525 | { | 531 | { |
526 | list_del(&format->list); | 532 | list_del(&format->list); |
@@ -560,6 +566,10 @@ void perf_hpp__setup_output_field(struct perf_hpp_list *list) | |||
560 | perf_hpp_list__for_each_sort_list(list, fmt) { | 566 | perf_hpp_list__for_each_sort_list(list, fmt) { |
561 | struct perf_hpp_fmt *pos; | 567 | struct perf_hpp_fmt *pos; |
562 | 568 | ||
569 | /* skip sort-only fields ("sort_compute" in perf diff) */ | ||
570 | if (!fmt->entry && !fmt->color) | ||
571 | continue; | ||
572 | |||
563 | perf_hpp_list__for_each_format(list, pos) { | 573 | perf_hpp_list__for_each_format(list, pos) { |
564 | if (fmt_equal(fmt, pos)) | 574 | if (fmt_equal(fmt, pos)) |
565 | goto next; | 575 | goto next; |
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 42922512c1c6..8b610dd9e2f6 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -437,7 +437,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor) | |||
437 | } | 437 | } |
438 | call->ip = cursor_node->ip; | 438 | call->ip = cursor_node->ip; |
439 | call->ms.sym = cursor_node->sym; | 439 | call->ms.sym = cursor_node->sym; |
440 | call->ms.map = cursor_node->map; | 440 | call->ms.map = map__get(cursor_node->map); |
441 | 441 | ||
442 | if (cursor_node->branch) { | 442 | if (cursor_node->branch) { |
443 | call->branch_count = 1; | 443 | call->branch_count = 1; |
@@ -477,6 +477,7 @@ add_child(struct callchain_node *parent, | |||
477 | 477 | ||
478 | list_for_each_entry_safe(call, tmp, &new->val, list) { | 478 | list_for_each_entry_safe(call, tmp, &new->val, list) { |
479 | list_del(&call->list); | 479 | list_del(&call->list); |
480 | map__zput(call->ms.map); | ||
480 | free(call); | 481 | free(call); |
481 | } | 482 | } |
482 | free(new); | 483 | free(new); |
@@ -761,6 +762,7 @@ merge_chain_branch(struct callchain_cursor *cursor, | |||
761 | list->ms.map, list->ms.sym, | 762 | list->ms.map, list->ms.sym, |
762 | false, NULL, 0, 0); | 763 | false, NULL, 0, 0); |
763 | list_del(&list->list); | 764 | list_del(&list->list); |
765 | map__zput(list->ms.map); | ||
764 | free(list); | 766 | free(list); |
765 | } | 767 | } |
766 | 768 | ||
@@ -811,7 +813,8 @@ int callchain_cursor_append(struct callchain_cursor *cursor, | |||
811 | } | 813 | } |
812 | 814 | ||
813 | node->ip = ip; | 815 | node->ip = ip; |
814 | node->map = map; | 816 | map__zput(node->map); |
817 | node->map = map__get(map); | ||
815 | node->sym = sym; | 818 | node->sym = sym; |
816 | node->branch = branch; | 819 | node->branch = branch; |
817 | node->nr_loop_iter = nr_loop_iter; | 820 | node->nr_loop_iter = nr_loop_iter; |
@@ -1142,11 +1145,13 @@ static void free_callchain_node(struct callchain_node *node) | |||
1142 | 1145 | ||
1143 | list_for_each_entry_safe(list, tmp, &node->parent_val, list) { | 1146 | list_for_each_entry_safe(list, tmp, &node->parent_val, list) { |
1144 | list_del(&list->list); | 1147 | list_del(&list->list); |
1148 | map__zput(list->ms.map); | ||
1145 | free(list); | 1149 | free(list); |
1146 | } | 1150 | } |
1147 | 1151 | ||
1148 | list_for_each_entry_safe(list, tmp, &node->val, list) { | 1152 | list_for_each_entry_safe(list, tmp, &node->val, list) { |
1149 | list_del(&list->list); | 1153 | list_del(&list->list); |
1154 | map__zput(list->ms.map); | ||
1150 | free(list); | 1155 | free(list); |
1151 | } | 1156 | } |
1152 | 1157 | ||
@@ -1210,6 +1215,7 @@ int callchain_node__make_parent_list(struct callchain_node *node) | |||
1210 | goto out; | 1215 | goto out; |
1211 | *new = *chain; | 1216 | *new = *chain; |
1212 | new->has_children = false; | 1217 | new->has_children = false; |
1218 | map__get(new->ms.map); | ||
1213 | list_add_tail(&new->list, &head); | 1219 | list_add_tail(&new->list, &head); |
1214 | } | 1220 | } |
1215 | parent = parent->parent; | 1221 | parent = parent->parent; |
@@ -1230,6 +1236,7 @@ int callchain_node__make_parent_list(struct callchain_node *node) | |||
1230 | out: | 1236 | out: |
1231 | list_for_each_entry_safe(chain, new, &head, list) { | 1237 | list_for_each_entry_safe(chain, new, &head, list) { |
1232 | list_del(&chain->list); | 1238 | list_del(&chain->list); |
1239 | map__zput(chain->ms.map); | ||
1233 | free(chain); | 1240 | free(chain); |
1234 | } | 1241 | } |
1235 | return -ENOMEM; | 1242 | return -ENOMEM; |
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 35c8e379530f..4f4b60f1558a 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/rbtree.h> | 6 | #include <linux/rbtree.h> |
7 | #include "event.h" | 7 | #include "event.h" |
8 | #include "map.h" | ||
8 | #include "symbol.h" | 9 | #include "symbol.h" |
9 | 10 | ||
10 | #define HELP_PAD "\t\t\t\t" | 11 | #define HELP_PAD "\t\t\t\t" |
@@ -184,8 +185,13 @@ int callchain_merge(struct callchain_cursor *cursor, | |||
184 | */ | 185 | */ |
185 | static inline void callchain_cursor_reset(struct callchain_cursor *cursor) | 186 | static inline void callchain_cursor_reset(struct callchain_cursor *cursor) |
186 | { | 187 | { |
188 | struct callchain_cursor_node *node; | ||
189 | |||
187 | cursor->nr = 0; | 190 | cursor->nr = 0; |
188 | cursor->last = &cursor->first; | 191 | cursor->last = &cursor->first; |
192 | |||
193 | for (node = cursor->first; node != NULL; node = node->next) | ||
194 | map__zput(node->map); | ||
189 | } | 195 | } |
190 | 196 | ||
191 | int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip, | 197 | int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip, |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 6770a9645609..7d1b7d33e644 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "util.h" | 1 | #include "util.h" |
2 | #include "build-id.h" | 2 | #include "build-id.h" |
3 | #include "hist.h" | 3 | #include "hist.h" |
4 | #include "map.h" | ||
4 | #include "session.h" | 5 | #include "session.h" |
5 | #include "sort.h" | 6 | #include "sort.h" |
6 | #include "evlist.h" | 7 | #include "evlist.h" |
@@ -1019,6 +1020,10 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, | |||
1019 | int max_stack_depth, void *arg) | 1020 | int max_stack_depth, void *arg) |
1020 | { | 1021 | { |
1021 | int err, err2; | 1022 | int err, err2; |
1023 | struct map *alm = NULL; | ||
1024 | |||
1025 | if (al && al->map) | ||
1026 | alm = map__get(al->map); | ||
1022 | 1027 | ||
1023 | err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent, | 1028 | err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent, |
1024 | iter->evsel, al, max_stack_depth); | 1029 | iter->evsel, al, max_stack_depth); |
@@ -1058,6 +1063,8 @@ out: | |||
1058 | if (!err) | 1063 | if (!err) |
1059 | err = err2; | 1064 | err = err2; |
1060 | 1065 | ||
1066 | map__put(alm); | ||
1067 | |||
1061 | return err; | 1068 | return err; |
1062 | } | 1069 | } |
1063 | 1070 | ||
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index d4b6514eeef5..28c216e3d5b7 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -283,6 +283,8 @@ void perf_hpp_list__column_register(struct perf_hpp_list *list, | |||
283 | struct perf_hpp_fmt *format); | 283 | struct perf_hpp_fmt *format); |
284 | void perf_hpp_list__register_sort_field(struct perf_hpp_list *list, | 284 | void perf_hpp_list__register_sort_field(struct perf_hpp_list *list, |
285 | struct perf_hpp_fmt *format); | 285 | struct perf_hpp_fmt *format); |
286 | void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list, | ||
287 | struct perf_hpp_fmt *format); | ||
286 | 288 | ||
287 | static inline void perf_hpp__column_register(struct perf_hpp_fmt *format) | 289 | static inline void perf_hpp__column_register(struct perf_hpp_fmt *format) |
288 | { | 290 | { |
@@ -294,6 +296,11 @@ static inline void perf_hpp__register_sort_field(struct perf_hpp_fmt *format) | |||
294 | perf_hpp_list__register_sort_field(&perf_hpp_list, format); | 296 | perf_hpp_list__register_sort_field(&perf_hpp_list, format); |
295 | } | 297 | } |
296 | 298 | ||
299 | static inline void perf_hpp__prepend_sort_field(struct perf_hpp_fmt *format) | ||
300 | { | ||
301 | perf_hpp_list__prepend_sort_field(&perf_hpp_list, format); | ||
302 | } | ||
303 | |||
297 | #define perf_hpp_list__for_each_format(_list, format) \ | 304 | #define perf_hpp_list__for_each_format(_list, format) \ |
298 | list_for_each_entry(format, &(_list)->fields, list) | 305 | list_for_each_entry(format, &(_list)->fields, list) |
299 | 306 | ||