perf fixes
Subsystems (6)
Linus,
Please pull the latest perf-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf-urgent-for-linus
Thanks,
Ingo
------------------>
Arnaldo Carvalho de Melo (1):
perf python: Fix undefined symbol problem
David Ahern (1):
perf session: Fix crash with invalid CPU list
Gleb Natapov (1):
perf: Do not set task_ctx pointer in cpuctx if there are no events in the context
Peter Zijlstra (5):
perf/x86: Fix PEBS instruction unwind
perf: Don't use -ENOSPC for out of PMU resources perf/x86: Enable raw event access to Intel offcore events perf, x86: Disable PEBS on SandyBridge chips
perf: Fix loss of notification with multi-event
Robert Richter (3):
oprofile: Fix crash when unloading module (hr timer mode) oprofile, x86: Fix crash when unloading module (nmi timer mode) perf, x86: Force IBS LVT offset assignment for family 10h
Tejun Heo (1):
trace_events_filter: Use rcu_assign_pointer() when setting ftrace_event_call->filter
arch/arm/kernel/perf_event.c | 6 +- arch/mips/kernel/perf_event_mipsxx.c | 8 +- arch/x86/kernel/cpu/perf_event.c | 16 ++--- arch/x86/kernel/cpu/perf_event_amd_ibs.c | 29 ++++++---- arch/x86/kernel/cpu/perf_event_intel.c | 8 +++ arch/x86/kernel/cpu/perf_event_intel_ds.c | 6 ++- arch/x86/kernel/cpu/perf_event_p4.c | 2 +- arch/x86/oprofile/init.c | 7 ++- drivers/oprofile/oprof.c | 29 ++++++++-- drivers/oprofile/timer_int.c | 1 + include/linux/perf_event.h | 1 + kernel/events/core.c | 89 ++++++++++++++++++++++++++++- kernel/events/internal.h | 3 + kernel/events/ring_buffer.c | 3 + kernel/trace/trace_events_filter.c | 6 +- tools/perf/util/evsel.c | 10 +++ tools/perf/util/hist.c | 10 --- tools/perf/util/hist.h | 2 - tools/perf/util/session.c | 4 + 19 files changed, 185 insertions(+), 55 deletions(-)
arch/arm/kernel/perf_event.c +3 -3
@@ -347,15 +347,15 @@ validate_group(struct perf_event *event)memset (&fake_pmu,0 ,sizeof (fake_pmu));if (!validate_event (&fake_pmu, leader)) -return -ENOSPC ; +return -EINVAL ;list_for_each_entry (sibling, &leader->sibling_list, group_entry) {if (!validate_event (&fake_pmu, sibling)) -return -ENOSPC ; +return -EINVAL ; }if (!validate_event (&fake_pmu, event)) -return -ENOSPC ; +return -EINVAL ;return 0 ; }
arch/mips/kernel/perf_event_mipsxx.c +4 -4
@@ -623,7 +623,7 @@ static int mipspmu_event_init(struct perf_event *event)if (!atomic_inc_not_zero (&active_events)) {if (atomic_read (&active_events) >MIPS_MAX_HWEVENTS ) {atomic_dec (&active_events); -return -ENOSPC ; +return -EINVAL ; }mutex_lock (&pmu_reserve_mutex);
@@ -732,15 +732,15 @@ static int validate_group(struct perf_event *event)memset (&fake_cpuc,0 ,sizeof (fake_cpuc));if (!validate_event (&fake_cpuc, leader)) -return -ENOSPC ; +return -EINVAL ;list_for_each_entry (sibling, &leader->sibling_list, group_entry) {if (!validate_event (&fake_cpuc, sibling)) -return -ENOSPC ; +return -EINVAL ; }if (!validate_event (&fake_cpuc, event)) -return -ENOSPC ; +return -EINVAL ;return 0 ; }
arch/x86/kernel/cpu/perf_event.c +6 -10
@@ -312,12 +312,8 @@ int x86_setup_perfctr(struct perf_event *event)return -EOPNOTSUPP ; } -/* -* Do not allow config1 (extended registers) to propagate, -* there's no sane user-space generalization yet: -*/ if (attr->type ==PERF_TYPE_RAW ) -return 0 ; +return x86_pmu_extra_regs (event->attr.config, event);if (attr->type ==PERF_TYPE_HW_CACHE )return set_ext_hw_attr (hwc, event);
@@ -588,7 +584,7 @@ done: x86_pmu.put_event_constraints (cpuc, cpuc->event_list[i]); } } -return num ? -ENOSPC :0 ; +return num ? -EINVAL :0 ; }/*
@@ -607,7 +603,7 @@ static int collect_events(struct cpu_hw_events *cpuc, struct perf_event *leader,if (is_x86_event (leader)) {if (n >= max_count) -return -ENOSPC ; +return -EINVAL ; cpuc->event_list[n] = leader; n++; }
@@ -620,7 +616,7 @@ static int collect_events(struct cpu_hw_events *cpuc, struct perf_event *leader,continue ;if (n >= max_count) -return -ENOSPC ; +return -EINVAL ; cpuc->event_list[n] = event; n++;
@@ -1316,7 +1312,7 @@ static int validate_event(struct perf_event *event) c = x86_pmu.get_event_constraints (fake_cpuc, event);if (!c || !c->weight) - ret = -ENOSPC ; + ret = -EINVAL ;if (x86_pmu.put_event_constraints) x86_pmu.put_event_constraints (fake_cpuc, event);
@@ -1341,7 +1337,7 @@ static int validate_group(struct perf_event *event) {struct perf_event *leader = event->group_leader;struct cpu_hw_events *fake_cpuc; -int ret = -ENOSPC , n; +int ret = -EINVAL , n; fake_cpuc =allocate_fake_cpuc ();if (IS_ERR (fake_cpuc))
arch/x86/kernel/cpu/perf_event_amd_ibs.c +18 -11
@@ -199,8 +199,7 @@ static int force_ibs_eilvt_setup(void) goto out; } -pr_err (FW_BUG "using offset %d for IBS interrupts\n" , offset); -pr_err (FW_BUG "workaround enabled for IBS LVT offset\n" ); +pr_info ("IBS: LVT offset %d assigned\n" , offset);return 0 ; out:
@@ -265,19 +264,23 @@ perf_ibs_cpu_notifier(struct notifier_block *self, unsigned long action, void *hstatic __init int amd_ibs_init (void ) {u32 caps; -int ret; +int ret = -EINVAL ; caps =__get_ibs_caps ();if (!caps)return -ENODEV ;/* ibs not supported by the cpu */ -if (!ibs_eilvt_valid ()) { - ret =force_ibs_eilvt_setup (); -if (ret) { -pr_err ("Failed to setup IBS, %d\n" , ret); -return ret; - } - } +/* +* Force LVT offset assignment for family 10h: The offsets are +* not assigned by the BIOS for this family, so the OS is +* responsible for doing it. If the OS assignment fails, fall +* back to BIOS settings and try to setup this. +*/ +if (boot_cpu_data.x86 ==0x10 ) +force_ibs_eilvt_setup (); + +if (!ibs_eilvt_valid ()) + goto out;get_online_cpus (); ibs_caps = caps;
@@ -287,7 +290,11 @@ static __init int amd_ibs_init(void)smp_call_function (setup_APIC_ibs,NULL ,1 );put_online_cpus (); -return perf_event_ibs_init (); + ret =perf_event_ibs_init (); +out: +if (ret) +pr_err ("Failed to setup IBS, %d\n" , ret); +return ret; }/* Since we need the pci subsystem to init ibs we can't do this earlier: */
arch/x86/kernel/cpu/perf_event_intel.c +8 -0
@@ -1545,6 +1545,13 @@ static void intel_clovertown_quirks(void) x86_pmu.pebs_constraints =NULL ; } +static void intel_sandybridge_quirks (void ) +{ +printk (KERN_WARNING "PEBS disabled due to CPU errata.\n" ); + x86_pmu.pebs =0 ; + x86_pmu.pebs_constraints =NULL ; +} +__init int intel_pmu_init (void ) {union cpuid10_edx edx;
@@ -1694,6 +1701,7 @@ __init int intel_pmu_init(void)break ;case 42 :/* SandyBridge */ + x86_pmu.quirks = intel_sandybridge_quirks;case 45 :/* SandyBridge, "Romely-EP" */ memcpy (hw_cache_event_ids, snb_hw_cache_event_ids,sizeof (hw_cache_event_ids));
arch/x86/kernel/cpu/perf_event_intel_ds.c +5 -1
@@ -493,6 +493,7 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)unsigned long from = cpuc->lbr_entries[0 ].from;unsigned long old_to, to = cpuc->lbr_entries[0 ].to;unsigned long ip = regs->ip; +int is_64bit =0 ;/* * We don't need to fixup if the PEBS assist is fault like
@@ -544,7 +545,10 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs) }else kaddr = (void *)to; -kernel_insn_init (&insn, kaddr); +#ifdef CONFIG_X86_64 + is_64bit =kernel_ip (to) || !test_thread_flag (TIF_IA32 ); +#endif +insn_init (&insn, kaddr, is_64bit);insn_get_length (&insn); to += insn.length; }while (to < ip);
arch/x86/kernel/cpu/perf_event_p4.c +1 -1
@@ -1268,7 +1268,7 @@ reserve: } done: -return num ? -ENOSPC :0 ; +return num ? -EINVAL :0 ; }static __initconst const struct x86_pmu p4_pmu = {
arch/x86/oprofile/init.c +5 -2
@@ -21,6 +21,7 @@ extern int op_nmi_timer_init(struct oprofile_operations *ops);extern void op_nmi_exit (void );extern void x86_backtrace (struct pt_regs *const regs,unsigned int depth); +static int nmi_timer;int __init oprofile_arch_init (struct oprofile_operations *ops) {
@@ -31,8 +32,9 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)#ifdef CONFIG_X86_LOCAL_APIC ret =op_nmi_init (ops);#endif + nmi_timer = (ret !=0 );#ifdef CONFIG_X86_IO_APIC -if (ret <0 ) +if (nmi_timer) ret =op_nmi_timer_init (ops);#endif ops->backtrace = x86_backtrace;
@@ -44,6 +46,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)void oprofile_arch_exit (void ) {#ifdef CONFIG_X86_LOCAL_APIC -op_nmi_exit (); +if (!nmi_timer) +op_nmi_exit ();#endif }
drivers/oprofile/oprof.c +24 -5
@@ -239,26 +239,45 @@ int oprofile_set_ulong(unsigned long *addr, unsigned long val)return err; } +static int timer_mode; +static int __init oprofile_init (void ) {int err; +/* always init architecture to setup backtrace support */ err =oprofile_arch_init (&oprofile_ops); -if (err <0 || timer) { -printk (KERN_INFO "oprofile: using timer interrupt.\n" ); + + timer_mode = err || timer;/* fall back to timer mode on errors */ +if (timer_mode) { +if (!err) +oprofile_arch_exit (); err =oprofile_timer_init (&oprofile_ops);if (err)return err; } -return oprofilefs_register (); + + err =oprofilefs_register (); +if (!err) +return 0 ; + +/* failed */ +if (timer_mode) +oprofile_timer_exit (); +else +oprofile_arch_exit (); + +return err; } static void __exit oprofile_exit(void) { -oprofile_timer_exit ();oprofilefs_unregister (); -oprofile_arch_exit (); +if (timer_mode) +oprofile_timer_exit (); +else +oprofile_arch_exit (); }
drivers/oprofile/timer_int.c +1 -0
@@ -110,6 +110,7 @@ int oprofile_timer_init(struct oprofile_operations *ops) ops->start = oprofile_hrtimer_start; ops->stop = oprofile_hrtimer_stop; ops->cpu_type ="timer" ; +printk (KERN_INFO "oprofile: using timer interrupt.\n" );return 0 ; }
include/linux/perf_event.h +1 -0
@@ -822,6 +822,7 @@ struct perf_event {int mmap_locked;struct user_struct *mmap_user;struct ring_buffer *rb; +struct list_head rb_entry;/* poll related */ wait_queue_head_t waitq;
kernel/events/core.c +86 -3
151 lines not on this page · raw message
kernel/events/internal.h +3 -0
@@ -22,6 +22,9 @@ struct ring_buffer {local_t lost;/* nr records lost */ long watermark;/* wakeup watermark */ +/* poll crap */ +spinlock_t event_lock; +struct list_head event_list;struct perf_event_mmap_page *user_page;void *data_pages[0 ];
kernel/events/ring_buffer.c +3 -0
@@ -209,6 +209,9 @@ ring_buffer_init(struct ring_buffer *rb, long watermark, int flags) rb->writable =1 ;atomic_set (&rb->refcount,1 ); + +INIT_LIST_HEAD (&rb->event_list); +spin_lock_init (&rb->event_lock); }#ifndef CONFIG_PERF_USE_VMALLOC
kernel/trace/trace_events_filter.c +3 -3
@@ -1686,7 +1686,7 @@ static int replace_system_preds(struct event_subsystem *system,* replace the filter for the call. */ filter = call->filter; - call->filter = filter_item->filter; +rcu_assign_pointer (call->filter, filter_item->filter); filter_item->filter = filter; fail = false;
@@ -1741,7 +1741,7 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string) filter = call->filter;if (!filter) goto out_unlock; - call->filter =NULL ; +RCU_INIT_POINTER (call->filter,NULL );/* Make sure the filter is not being used */ synchronize_sched ();__free_filter (filter);
@@ -1782,7 +1782,7 @@ out:* string */ tmp = call->filter; - call->filter = filter; +rcu_assign_pointer (call->filter, filter);if (tmp) {/* Make sure the call is done with the filter */ synchronize_sched ();
tools/perf/util/evsel.c +10 -0
@@ -34,6 +34,16 @@ int __perf_evsel__sample_size(u64 sample_type)return size; } +static void hists__init (struct hists *hists) +{ +memset (hists,0 ,sizeof (*hists)); + hists->entries_in_array[0 ] = hists->entries_in_array[1 ] =RB_ROOT ; + hists->entries_in = &hists->entries_in_array[0 ]; + hists->entries_collapsed =RB_ROOT ; + hists->entries =RB_ROOT ; +pthread_mutex_init (&hists->lock,NULL ); +} +void perf_evsel__init (struct perf_evsel *evsel,struct perf_event_attr *attr,int idx) {
tools/perf/util/hist.c +0 -10
@@ -1211,13 +1211,3 @@ size_t hists__fprintf_nr_events(struct hists *hists, FILE *fp)return ret; } - -void hists__init (struct hists *hists) -{ -memset (hists,0 ,sizeof (*hists)); - hists->entries_in_array[0 ] = hists->entries_in_array[1 ] =RB_ROOT ; - hists->entries_in = &hists->entries_in_array[0 ]; - hists->entries_collapsed =RB_ROOT ; - hists->entries =RB_ROOT ; -pthread_mutex_init (&hists->lock,NULL ); -}
tools/perf/util/hist.h +0 -2
@@ -63,8 +63,6 @@ struct hists {struct callchain_cursor callchain_cursor; }; -void hists__init (struct hists *hists); -struct hist_entry *__hists__add_entry (struct hists *self,struct addr_location *al,struct symbol *parent,u64 period);
tools/perf/util/session.c +4 -0
@@ -1333,6 +1333,10 @@ int perf_session__cpu_bitmap(struct perf_session *session, } map =cpu_map__new (cpu_list); +if (map ==NULL ) { +pr_err ("Invalid cpu_list\n" ); +return -1 ; + }for (i =0 ; i < map->nr; i++) {int cpu = map->map[i];