Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 fair chunk of the linecount comes from a fix for a tracing bug that
corrupts latency tracing buffers when the overwrite mode is changed on
the fly - the rest is mostly assorted fewliner fixlets."

* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf/x86: Add SNB/SNB-EP scheduling constraints for cycle_activity event
kprobes/x86: Check Interrupt Flag modifier when registering probe
kprobes: Make hash_64() as always inlined
perf: Generate EXIT event only once per task context
perf: Reset hwc->last_period on sw clock events
tracing: Prevent buffer overwrite disabled for latency tracers
tracing: Keep overwrite in sync between regular and snapshot buffers
tracing: Protect tracer flags with trace_types_lock
perf tools: Fix LIBNUMA build with glibc 2.12 and older.
tracing: Fix free of probe entry by calling call_rcu_sched()
perf/POWER7: Create a sysfs format entry for Power7 events
perf probe: Fix segfault
libtraceevent: Remove hard coded include to /usr/local/include in Makefile
perf record: Fix -C option
perf tools: check if -DFORTIFY_SOURCE=2 is allowed
perf report: Fix build with NO_NEWT=1
perf annotate: Fix build with NO_NEWT=1
tracing: Fix race in snapshot swapping

+152 -35
+13
arch/powerpc/perf/power7-pmu.c
··· 420 420 .attrs = power7_events_attr, 421 421 }; 422 422 423 + PMU_FORMAT_ATTR(event, "config:0-19"); 424 + 425 + static struct attribute *power7_pmu_format_attr[] = { 426 + &format_attr_event.attr, 427 + NULL, 428 + }; 429 + 430 + struct attribute_group power7_pmu_format_group = { 431 + .name = "format", 432 + .attrs = power7_pmu_format_attr, 433 + }; 434 + 423 435 static const struct attribute_group *power7_pmu_attr_groups[] = { 436 + &power7_pmu_format_group, 424 437 &power7_pmu_events_group, 425 438 NULL, 426 439 };
+1
arch/x86/include/asm/kprobes.h
··· 77 77 * a post_handler or break_handler). 78 78 */ 79 79 int boostable; 80 + bool if_modifier; 80 81 }; 81 82 82 83 struct arch_optimized_insn {
+4
arch/x86/kernel/cpu/perf_event_intel.c
··· 101 101 FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ 102 102 FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ 103 103 FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ 104 + INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_NO_DISPATCH */ 105 + INTEL_UEVENT_CONSTRAINT(0x05a3, 0xf), /* CYCLE_ACTIVITY.STALLS_L2_PENDING */ 106 + INTEL_UEVENT_CONSTRAINT(0x02a3, 0x4), /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */ 107 + INTEL_UEVENT_CONSTRAINT(0x06a3, 0x4), /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */ 104 108 INTEL_EVENT_CONSTRAINT(0x48, 0x4), /* L1D_PEND_MISS.PENDING */ 105 109 INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */ 106 110 INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.LOAD_LATENCY */
+4 -1
arch/x86/kernel/kprobes/core.c
··· 375 375 else 376 376 p->ainsn.boostable = -1; 377 377 378 + /* Check whether the instruction modifies Interrupt Flag or not */ 379 + p->ainsn.if_modifier = is_IF_modifier(p->ainsn.insn); 380 + 378 381 /* Also, displacement change doesn't affect the first byte */ 379 382 p->opcode = p->ainsn.insn[0]; 380 383 } ··· 437 434 __this_cpu_write(current_kprobe, p); 438 435 kcb->kprobe_saved_flags = kcb->kprobe_old_flags 439 436 = (regs->flags & (X86_EFLAGS_TF | X86_EFLAGS_IF)); 440 - if (is_IF_modifier(p->ainsn.insn)) 437 + if (p->ainsn.if_modifier) 441 438 kcb->kprobe_saved_flags &= ~X86_EFLAGS_IF; 442 439 } 443 440
+2 -1
include/linux/hash.h
··· 15 15 */ 16 16 17 17 #include <asm/types.h> 18 + #include <linux/compiler.h> 18 19 19 20 /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ 20 21 #define GOLDEN_RATIO_PRIME_32 0x9e370001UL ··· 32 31 #error Wordsize not 32 or 64 33 32 #endif 34 33 35 - static inline u64 hash_64(u64 val, unsigned int bits) 34 + static __always_inline u64 hash_64(u64 val, unsigned int bits) 36 35 { 37 36 u64 hash = val; 38 37
+6 -2
kernel/events/core.c
··· 4434 4434 if (ctxn < 0) 4435 4435 goto next; 4436 4436 ctx = rcu_dereference(current->perf_event_ctxp[ctxn]); 4437 + if (ctx) 4438 + perf_event_task_ctx(ctx, task_event); 4437 4439 } 4438 - if (ctx) 4439 - perf_event_task_ctx(ctx, task_event); 4440 4440 next: 4441 4441 put_cpu_ptr(pmu->pmu_cpu_context); 4442 4442 } 4443 + if (task_event->task_ctx) 4444 + perf_event_task_ctx(task_event->task_ctx, task_event); 4445 + 4443 4446 rcu_read_unlock(); 4444 4447 } 4445 4448 ··· 5650 5647 event->attr.sample_period = NSEC_PER_SEC / freq; 5651 5648 hwc->sample_period = event->attr.sample_period; 5652 5649 local64_set(&hwc->period_left, hwc->sample_period); 5650 + hwc->last_period = hwc->sample_period; 5653 5651 event->attr.freq = 0; 5654 5652 } 5655 5653 }
+2 -2
kernel/trace/ftrace.c
··· 3104 3104 continue; 3105 3105 } 3106 3106 3107 - hlist_del(&entry->node); 3108 - call_rcu(&entry->rcu, ftrace_free_entry_rcu); 3107 + hlist_del_rcu(&entry->node); 3108 + call_rcu_sched(&entry->rcu, ftrace_free_entry_rcu); 3109 3109 } 3110 3110 } 3111 3111 __disable_ftrace_function_probe();
+47 -12
kernel/trace/trace.c
··· 704 704 void 705 705 update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) 706 706 { 707 - struct ring_buffer *buf = tr->buffer; 707 + struct ring_buffer *buf; 708 708 709 709 if (trace_stop_count) 710 710 return; ··· 719 719 720 720 arch_spin_lock(&ftrace_max_lock); 721 721 722 + buf = tr->buffer; 722 723 tr->buffer = max_tr.buffer; 723 724 max_tr.buffer = buf; 724 725 ··· 2881 2880 return -EINVAL; 2882 2881 } 2883 2882 2884 - static void set_tracer_flags(unsigned int mask, int enabled) 2883 + /* Some tracers require overwrite to stay enabled */ 2884 + int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) 2885 + { 2886 + if (tracer->enabled && (mask & TRACE_ITER_OVERWRITE) && !set) 2887 + return -1; 2888 + 2889 + return 0; 2890 + } 2891 + 2892 + int set_tracer_flag(unsigned int mask, int enabled) 2885 2893 { 2886 2894 /* do nothing if flag is already set */ 2887 2895 if (!!(trace_flags & mask) == !!enabled) 2888 - return; 2896 + return 0; 2897 + 2898 + /* Give the tracer a chance to approve the change */ 2899 + if (current_trace->flag_changed) 2900 + if (current_trace->flag_changed(current_trace, mask, !!enabled)) 2901 + return -EINVAL; 2889 2902 2890 2903 if (enabled) 2891 2904 trace_flags |= mask; ··· 2909 2894 if (mask == TRACE_ITER_RECORD_CMD) 2910 2895 trace_event_enable_cmd_record(enabled); 2911 2896 2912 - if (mask == TRACE_ITER_OVERWRITE) 2897 + if (mask == TRACE_ITER_OVERWRITE) { 2913 2898 ring_buffer_change_overwrite(global_trace.buffer, enabled); 2899 + #ifdef CONFIG_TRACER_MAX_TRACE 2900 + ring_buffer_change_overwrite(max_tr.buffer, enabled); 2901 + #endif 2902 + } 2914 2903 2915 2904 if (mask == TRACE_ITER_PRINTK) 2916 2905 trace_printk_start_stop_comm(enabled); 2906 + 2907 + return 0; 2917 2908 } 2918 2909 2919 2910 static int trace_set_options(char *option) 2920 2911 { 2921 2912 char *cmp; 2922 2913 int neg = 0; 2923 - int ret = 0; 2914 + int ret = -ENODEV; 2924 2915 int i; 2925 2916 2926 2917 cmp = strstrip(option); ··· 2936 2915 cmp += 2; 2937 2916 } 2938 2917 2918 + mutex_lock(&trace_types_lock); 2919 + 2939 2920 for (i = 0; trace_options[i]; i++) { 2940 2921 if (strcmp(cmp, trace_options[i]) == 0) { 2941 - set_tracer_flags(1 << i, !neg); 2922 + ret = set_tracer_flag(1 << i, !neg); 2942 2923 break; 2943 2924 } 2944 2925 } 2945 2926 2946 2927 /* If no option could be set, test the specific tracer options */ 2947 - if (!trace_options[i]) { 2948 - mutex_lock(&trace_types_lock); 2928 + if (!trace_options[i]) 2949 2929 ret = set_tracer_option(current_trace, cmp, neg); 2950 - mutex_unlock(&trace_types_lock); 2951 - } 2930 + 2931 + mutex_unlock(&trace_types_lock); 2952 2932 2953 2933 return ret; 2954 2934 } ··· 2959 2937 size_t cnt, loff_t *ppos) 2960 2938 { 2961 2939 char buf[64]; 2940 + int ret; 2962 2941 2963 2942 if (cnt >= sizeof(buf)) 2964 2943 return -EINVAL; ··· 2969 2946 2970 2947 buf[cnt] = 0; 2971 2948 2972 - trace_set_options(buf); 2949 + ret = trace_set_options(buf); 2950 + if (ret < 0) 2951 + return ret; 2973 2952 2974 2953 *ppos += cnt; 2975 2954 ··· 3275 3250 goto out; 3276 3251 3277 3252 trace_branch_disable(); 3253 + 3254 + current_trace->enabled = false; 3255 + 3278 3256 if (current_trace->reset) 3279 3257 current_trace->reset(tr); 3280 3258 ··· 3322 3294 } 3323 3295 3324 3296 current_trace = t; 3297 + current_trace->enabled = true; 3325 3298 trace_branch_enable(tr); 3326 3299 out: 3327 3300 mutex_unlock(&trace_types_lock); ··· 4809 4780 4810 4781 if (val != 0 && val != 1) 4811 4782 return -EINVAL; 4812 - set_tracer_flags(1 << index, val); 4783 + 4784 + mutex_lock(&trace_types_lock); 4785 + ret = set_tracer_flag(1 << index, val); 4786 + mutex_unlock(&trace_types_lock); 4787 + 4788 + if (ret < 0) 4789 + return ret; 4813 4790 4814 4791 *ppos += cnt; 4815 4792
+6
kernel/trace/trace.h
··· 283 283 enum print_line_t (*print_line)(struct trace_iterator *iter); 284 284 /* If you handled the flag setting, return 0 */ 285 285 int (*set_flag)(u32 old_flags, u32 bit, int set); 286 + /* Return 0 if OK with change, else return non-zero */ 287 + int (*flag_changed)(struct tracer *tracer, 288 + u32 mask, int set); 286 289 struct tracer *next; 287 290 struct tracer_flags *flags; 288 291 bool print_max; 289 292 bool use_max_tr; 290 293 bool allocated_snapshot; 294 + bool enabled; 291 295 }; 292 296 293 297 ··· 947 943 948 944 void trace_printk_init_buffers(void); 949 945 void trace_printk_start_comm(void); 946 + int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set); 947 + int set_tracer_flag(unsigned int mask, int enabled); 950 948 951 949 #undef FTRACE_ENTRY 952 950 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
+14 -5
kernel/trace/trace_irqsoff.c
··· 32 32 33 33 static int trace_type __read_mostly; 34 34 35 - static int save_lat_flag; 35 + static int save_flags; 36 36 37 37 static void stop_irqsoff_tracer(struct trace_array *tr, int graph); 38 38 static int start_irqsoff_tracer(struct trace_array *tr, int graph); ··· 558 558 559 559 static void __irqsoff_tracer_init(struct trace_array *tr) 560 560 { 561 - save_lat_flag = trace_flags & TRACE_ITER_LATENCY_FMT; 562 - trace_flags |= TRACE_ITER_LATENCY_FMT; 561 + save_flags = trace_flags; 562 + 563 + /* non overwrite screws up the latency tracers */ 564 + set_tracer_flag(TRACE_ITER_OVERWRITE, 1); 565 + set_tracer_flag(TRACE_ITER_LATENCY_FMT, 1); 563 566 564 567 tracing_max_latency = 0; 565 568 irqsoff_trace = tr; ··· 576 573 577 574 static void irqsoff_tracer_reset(struct trace_array *tr) 578 575 { 576 + int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT; 577 + int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE; 578 + 579 579 stop_irqsoff_tracer(tr, is_graph()); 580 580 581 - if (!save_lat_flag) 582 - trace_flags &= ~TRACE_ITER_LATENCY_FMT; 581 + set_tracer_flag(TRACE_ITER_LATENCY_FMT, lat_flag); 582 + set_tracer_flag(TRACE_ITER_OVERWRITE, overwrite_flag); 583 583 } 584 584 585 585 static void irqsoff_tracer_start(struct trace_array *tr) ··· 615 609 .print_line = irqsoff_print_line, 616 610 .flags = &tracer_flags, 617 611 .set_flag = irqsoff_set_flag, 612 + .flag_changed = trace_keep_overwrite, 618 613 #ifdef CONFIG_FTRACE_SELFTEST 619 614 .selftest = trace_selftest_startup_irqsoff, 620 615 #endif ··· 649 642 .print_line = irqsoff_print_line, 650 643 .flags = &tracer_flags, 651 644 .set_flag = irqsoff_set_flag, 645 + .flag_changed = trace_keep_overwrite, 652 646 #ifdef CONFIG_FTRACE_SELFTEST 653 647 .selftest = trace_selftest_startup_preemptoff, 654 648 #endif ··· 685 677 .print_line = irqsoff_print_line, 686 678 .flags = &tracer_flags, 687 679 .set_flag = irqsoff_set_flag, 680 + .flag_changed = trace_keep_overwrite, 688 681 #ifdef CONFIG_FTRACE_SELFTEST 689 682 .selftest = trace_selftest_startup_preemptirqsoff, 690 683 #endif
+13 -5
kernel/trace/trace_sched_wakeup.c
··· 36 36 static int wakeup_graph_entry(struct ftrace_graph_ent *trace); 37 37 static void wakeup_graph_return(struct ftrace_graph_ret *trace); 38 38 39 - static int save_lat_flag; 39 + static int save_flags; 40 40 41 41 #define TRACE_DISPLAY_GRAPH 1 42 42 ··· 540 540 541 541 static int __wakeup_tracer_init(struct trace_array *tr) 542 542 { 543 - save_lat_flag = trace_flags & TRACE_ITER_LATENCY_FMT; 544 - trace_flags |= TRACE_ITER_LATENCY_FMT; 543 + save_flags = trace_flags; 544 + 545 + /* non overwrite screws up the latency tracers */ 546 + set_tracer_flag(TRACE_ITER_OVERWRITE, 1); 547 + set_tracer_flag(TRACE_ITER_LATENCY_FMT, 1); 545 548 546 549 tracing_max_latency = 0; 547 550 wakeup_trace = tr; ··· 566 563 567 564 static void wakeup_tracer_reset(struct trace_array *tr) 568 565 { 566 + int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT; 567 + int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE; 568 + 569 569 stop_wakeup_tracer(tr); 570 570 /* make sure we put back any tasks we are tracing */ 571 571 wakeup_reset(tr); 572 572 573 - if (!save_lat_flag) 574 - trace_flags &= ~TRACE_ITER_LATENCY_FMT; 573 + set_tracer_flag(TRACE_ITER_LATENCY_FMT, lat_flag); 574 + set_tracer_flag(TRACE_ITER_OVERWRITE, overwrite_flag); 575 575 } 576 576 577 577 static void wakeup_tracer_start(struct trace_array *tr) ··· 600 594 .print_line = wakeup_print_line, 601 595 .flags = &tracer_flags, 602 596 .set_flag = wakeup_set_flag, 597 + .flag_changed = trace_keep_overwrite, 603 598 #ifdef CONFIG_FTRACE_SELFTEST 604 599 .selftest = trace_selftest_startup_wakeup, 605 600 #endif ··· 622 615 .print_line = wakeup_print_line, 623 616 .flags = &tracer_flags, 624 617 .set_flag = wakeup_set_flag, 618 + .flag_changed = trace_keep_overwrite, 625 619 #ifdef CONFIG_FTRACE_SELFTEST 626 620 .selftest = trace_selftest_startup_wakeup, 627 621 #endif
+1 -1
tools/lib/traceevent/Makefile
··· 122 122 123 123 EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) 124 124 125 - INCLUDES = -I. -I/usr/local/include $(CONFIG_INCLUDES) 125 + INCLUDES = -I. $(CONFIG_INCLUDES) 126 126 127 127 # Set compile option CFLAGS if not set elsewhere 128 128 CFLAGS ?= -g -Wall
+7 -1
tools/perf/Makefile
··· 95 95 PERF_DEBUG = $(DEBUG) 96 96 endif 97 97 ifndef PERF_DEBUG 98 - CFLAGS_OPTIMIZE = -O6 -D_FORTIFY_SOURCE=2 98 + CFLAGS_OPTIMIZE = -O6 99 99 endif 100 100 101 101 ifdef PARSER_DEBUG ··· 178 178 179 179 ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wvolatile-register-var,-Wvolatile-register-var),y) 180 180 CFLAGS := $(CFLAGS) -Wvolatile-register-var 181 + endif 182 + 183 + ifndef PERF_DEBUG 184 + ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -D_FORTIFY_SOURCE=2,-D_FORTIFY_SOURCE=2),y) 185 + CFLAGS := $(CFLAGS) -D_FORTIFY_SOURCE=2 186 + endif 181 187 endif 182 188 183 189 ### --- END CONFIGURATION SECTION ---
+24
tools/perf/bench/bench.h
··· 1 1 #ifndef BENCH_H 2 2 #define BENCH_H 3 3 4 + /* 5 + * The madvise transparent hugepage constants were added in glibc 6 + * 2.13. For compatibility with older versions of glibc, define these 7 + * tokens if they are not already defined. 8 + * 9 + * PA-RISC uses different madvise values from other architectures and 10 + * needs to be special-cased. 11 + */ 12 + #ifdef __hppa__ 13 + # ifndef MADV_HUGEPAGE 14 + # define MADV_HUGEPAGE 67 15 + # endif 16 + # ifndef MADV_NOHUGEPAGE 17 + # define MADV_NOHUGEPAGE 68 18 + # endif 19 + #else 20 + # ifndef MADV_HUGEPAGE 21 + # define MADV_HUGEPAGE 14 22 + # endif 23 + # ifndef MADV_NOHUGEPAGE 24 + # define MADV_NOHUGEPAGE 15 25 + # endif 26 + #endif 27 + 4 28 extern int bench_numa(int argc, const char **argv, const char *prefix); 5 29 extern int bench_sched_messaging(int argc, const char **argv, const char *prefix); 6 30 extern int bench_sched_pipe(int argc, const char **argv, const char *prefix);
+4 -2
tools/perf/builtin-record.c
··· 573 573 perf_event__synthesize_guest_os, tool); 574 574 } 575 575 576 - if (!opts->target.system_wide) 576 + if (perf_target__has_task(&opts->target)) 577 577 err = perf_event__synthesize_thread_map(tool, evsel_list->threads, 578 578 process_synthesized_event, 579 579 machine); 580 - else 580 + else if (perf_target__has_cpu(&opts->target)) 581 581 err = perf_event__synthesize_threads(tool, process_synthesized_event, 582 582 machine); 583 + else /* command specified */ 584 + err = 0; 583 585 584 586 if (err != 0) 585 587 goto out_delete_session;
+3 -2
tools/perf/util/hist.h
··· 208 208 return 0; 209 209 } 210 210 211 - #define K_LEFT -1 212 - #define K_RIGHT -2 211 + #define K_LEFT -1000 212 + #define K_RIGHT -2000 213 + #define K_SWITCH_INPUT_DATA -3000 213 214 #endif 214 215 215 216 #ifdef GTK2_SUPPORT
+1 -1
tools/perf/util/strlist.c
··· 143 143 slist->rblist.node_delete = strlist__node_delete; 144 144 145 145 slist->dupstr = dupstr; 146 - if (slist && strlist__parse_list(slist, list) != 0) 146 + if (list && strlist__parse_list(slist, list) != 0) 147 147 goto out_error; 148 148 } 149 149