diff options
| author | Avi Kivity <avi@redhat.com> | 2011-12-25 08:44:43 -0500 |
|---|---|---|
| committer | Avi Kivity <avi@redhat.com> | 2011-12-27 04:22:24 -0500 |
| commit | 9e31905f293ae84e4f120ed9e414031eaefa0bdf (patch) | |
| tree | 153204ff0dca820e760007bc24075ec7fb46a276 /drivers/oprofile | |
| parent | ff5c2c0316ff0e3e2dba3ca14167d994453df093 (diff) | |
| parent | b3d9468a8bd218a695e3a0ff112cd4efd27b670a (diff) | |
Merge remote-tracking branch 'tip/perf/core' into kvm-updates/3.3
* tip/perf/core: (66 commits)
perf, x86: Expose perf capability to other modules
perf, x86: Implement arch event mask as quirk
x86, perf: Disable non available architectural events
jump_label: Provide jump_label_key initializers
jump_label, x86: Fix section mismatch
perf, core: Rate limit perf_sched_events jump_label patching
perf: Fix enable_on_exec for sibling events
perf: Remove superfluous arguments
perf, x86: Prefer fixed-purpose counters when scheduling
perf, x86: Fix event scheduler for constraints with overlapping counters
perf, x86: Implement event scheduler helper functions
perf: Avoid a useless pmu_disable() in the perf-tick
x86/tools: Add decoded instruction dump mode
x86: Update instruction decoder to support new AVX formats
x86/tools: Fix insn_sanity message outputs
x86/tools: Fix instruction decoder message output
x86: Fix instruction decoder to handle grouped AVX instructions
x86/tools: Fix Makefile to build all test tools
perf test: Soft errors shouldn't stop the "Validate PERF_RECORD_" test
perf test: Validate PERF_RECORD_ events and perf_sample fields
...
Signed-off-by: Avi Kivity <avi@redhat.com>
* commit 'b3d9468a8bd218a695e3a0ff112cd4efd27b670a': (66 commits)
perf, x86: Expose perf capability to other modules
perf, x86: Implement arch event mask as quirk
x86, perf: Disable non available architectural events
jump_label: Provide jump_label_key initializers
jump_label, x86: Fix section mismatch
perf, core: Rate limit perf_sched_events jump_label patching
perf: Fix enable_on_exec for sibling events
perf: Remove superfluous arguments
perf, x86: Prefer fixed-purpose counters when scheduling
perf, x86: Fix event scheduler for constraints with overlapping counters
perf, x86: Implement event scheduler helper functions
perf: Avoid a useless pmu_disable() in the perf-tick
x86/tools: Add decoded instruction dump mode
x86: Update instruction decoder to support new AVX formats
x86/tools: Fix insn_sanity message outputs
x86/tools: Fix instruction decoder message output
x86: Fix instruction decoder to handle grouped AVX instructions
x86/tools: Fix Makefile to build all test tools
perf test: Soft errors shouldn't stop the "Validate PERF_RECORD_" test
perf test: Validate PERF_RECORD_ events and perf_sample fields
...
Diffstat (limited to 'drivers/oprofile')
| -rw-r--r-- | drivers/oprofile/nmi_timer_int.c | 173 | ||||
| -rw-r--r-- | drivers/oprofile/oprof.c | 30 | ||||
| -rw-r--r-- | drivers/oprofile/oprof.h | 9 | ||||
| -rw-r--r-- | drivers/oprofile/timer_int.c | 30 |
4 files changed, 209 insertions, 33 deletions
diff --git a/drivers/oprofile/nmi_timer_int.c b/drivers/oprofile/nmi_timer_int.c new file mode 100644 index 000000000000..76f1c9357f39 --- /dev/null +++ b/drivers/oprofile/nmi_timer_int.c | |||
| @@ -0,0 +1,173 @@ | |||
| 1 | /** | ||
| 2 | * @file nmi_timer_int.c | ||
| 3 | * | ||
| 4 | * @remark Copyright 2011 Advanced Micro Devices, Inc. | ||
| 5 | * | ||
| 6 | * @author Robert Richter <robert.richter@amd.com> | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <linux/init.h> | ||
| 10 | #include <linux/smp.h> | ||
| 11 | #include <linux/errno.h> | ||
| 12 | #include <linux/oprofile.h> | ||
| 13 | #include <linux/perf_event.h> | ||
| 14 | |||
| 15 | #ifdef CONFIG_OPROFILE_NMI_TIMER | ||
| 16 | |||
| 17 | static DEFINE_PER_CPU(struct perf_event *, nmi_timer_events); | ||
| 18 | static int ctr_running; | ||
| 19 | |||
| 20 | static struct perf_event_attr nmi_timer_attr = { | ||
| 21 | .type = PERF_TYPE_HARDWARE, | ||
| 22 | .config = PERF_COUNT_HW_CPU_CYCLES, | ||
| 23 | .size = sizeof(struct perf_event_attr), | ||
| 24 | .pinned = 1, | ||
| 25 | .disabled = 1, | ||
| 26 | }; | ||
| 27 | |||
| 28 | static void nmi_timer_callback(struct perf_event *event, | ||
| 29 | struct perf_sample_data *data, | ||
| 30 | struct pt_regs *regs) | ||
| 31 | { | ||
| 32 | event->hw.interrupts = 0; /* don't throttle interrupts */ | ||
| 33 | oprofile_add_sample(regs, 0); | ||
| 34 | } | ||
| 35 | |||
| 36 | static int nmi_timer_start_cpu(int cpu) | ||
| 37 | { | ||
| 38 | struct perf_event *event = per_cpu(nmi_timer_events, cpu); | ||
| 39 | |||
| 40 | if (!event) { | ||
| 41 | event = perf_event_create_kernel_counter(&nmi_timer_attr, cpu, NULL, | ||
| 42 | nmi_timer_callback, NULL); | ||
| 43 | if (IS_ERR(event)) | ||
| 44 | return PTR_ERR(event); | ||
| 45 | per_cpu(nmi_timer_events, cpu) = event; | ||
| 46 | } | ||
| 47 | |||
| 48 | if (event && ctr_running) | ||
| 49 | perf_event_enable(event); | ||
| 50 | |||
| 51 | return 0; | ||
| 52 | } | ||
| 53 | |||
| 54 | static void nmi_timer_stop_cpu(int cpu) | ||
| 55 | { | ||
| 56 | struct perf_event *event = per_cpu(nmi_timer_events, cpu); | ||
| 57 | |||
| 58 | if (event && ctr_running) | ||
| 59 | perf_event_disable(event); | ||
| 60 | } | ||
| 61 | |||
| 62 | static int nmi_timer_cpu_notifier(struct notifier_block *b, unsigned long action, | ||
| 63 | void *data) | ||
| 64 | { | ||
| 65 | int cpu = (unsigned long)data; | ||
| 66 | switch (action) { | ||
| 67 | case CPU_DOWN_FAILED: | ||
| 68 | case CPU_ONLINE: | ||
| 69 | nmi_timer_start_cpu(cpu); | ||
| 70 | break; | ||
| 71 | case CPU_DOWN_PREPARE: | ||
| 72 | nmi_timer_stop_cpu(cpu); | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | return NOTIFY_DONE; | ||
| 76 | } | ||
| 77 | |||
| 78 | static struct notifier_block nmi_timer_cpu_nb = { | ||
| 79 | .notifier_call = nmi_timer_cpu_notifier | ||
| 80 | }; | ||
| 81 | |||
| 82 | static int nmi_timer_start(void) | ||
| 83 | { | ||
| 84 | int cpu; | ||
| 85 | |||
| 86 | get_online_cpus(); | ||
| 87 | ctr_running = 1; | ||
| 88 | for_each_online_cpu(cpu) | ||
| 89 | nmi_timer_start_cpu(cpu); | ||
| 90 | put_online_cpus(); | ||
| 91 | |||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | static void nmi_timer_stop(void) | ||
| 96 | { | ||
| 97 | int cpu; | ||
| 98 | |||
| 99 | get_online_cpus(); | ||
| 100 | for_each_online_cpu(cpu) | ||
| 101 | nmi_timer_stop_cpu(cpu); | ||
| 102 | ctr_running = 0; | ||
| 103 | put_online_cpus(); | ||
| 104 | } | ||
| 105 | |||
| 106 | static void nmi_timer_shutdown(void) | ||
| 107 | { | ||
| 108 | struct perf_event *event; | ||
| 109 | int cpu; | ||
| 110 | |||
| 111 | get_online_cpus(); | ||
| 112 | unregister_cpu_notifier(&nmi_timer_cpu_nb); | ||
| 113 | for_each_possible_cpu(cpu) { | ||
| 114 | event = per_cpu(nmi_timer_events, cpu); | ||
| 115 | if (!event) | ||
| 116 | continue; | ||
| 117 | perf_event_disable(event); | ||
| 118 | per_cpu(nmi_timer_events, cpu) = NULL; | ||
| 119 | perf_event_release_kernel(event); | ||
| 120 | } | ||
| 121 | |||
| 122 | put_online_cpus(); | ||
| 123 | } | ||
| 124 | |||
| 125 | static int nmi_timer_setup(void) | ||
| 126 | { | ||
| 127 | int cpu, err; | ||
| 128 | u64 period; | ||
| 129 | |||
| 130 | /* clock cycles per tick: */ | ||
| 131 | period = (u64)cpu_khz * 1000; | ||
| 132 | do_div(period, HZ); | ||
| 133 | nmi_timer_attr.sample_period = period; | ||
| 134 | |||
| 135 | get_online_cpus(); | ||
| 136 | err = register_cpu_notifier(&nmi_timer_cpu_nb); | ||
| 137 | if (err) | ||
| 138 | goto out; | ||
| 139 | /* can't attach events to offline cpus: */ | ||
| 140 | for_each_online_cpu(cpu) { | ||
| 141 | err = nmi_timer_start_cpu(cpu); | ||
| 142 | if (err) | ||
| 143 | break; | ||
| 144 | } | ||
| 145 | if (err) | ||
| 146 | nmi_timer_shutdown(); | ||
| 147 | out: | ||
| 148 | put_online_cpus(); | ||
| 149 | return err; | ||
| 150 | } | ||
| 151 | |||
| 152 | int __init op_nmi_timer_init(struct oprofile_operations *ops) | ||
| 153 | { | ||
| 154 | int err = 0; | ||
| 155 | |||
| 156 | err = nmi_timer_setup(); | ||
| 157 | if (err) | ||
| 158 | return err; | ||
| 159 | nmi_timer_shutdown(); /* only check, don't alloc */ | ||
| 160 | |||
| 161 | ops->create_files = NULL; | ||
| 162 | ops->setup = nmi_timer_setup; | ||
| 163 | ops->shutdown = nmi_timer_shutdown; | ||
| 164 | ops->start = nmi_timer_start; | ||
| 165 | ops->stop = nmi_timer_stop; | ||
| 166 | ops->cpu_type = "timer"; | ||
| 167 | |||
| 168 | printk(KERN_INFO "oprofile: using NMI timer interrupt.\n"); | ||
| 169 | |||
| 170 | return 0; | ||
| 171 | } | ||
| 172 | |||
| 173 | #endif | ||
diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c index f8c752e408a6..ed2c3ec07024 100644 --- a/drivers/oprofile/oprof.c +++ b/drivers/oprofile/oprof.c | |||
| @@ -246,37 +246,31 @@ static int __init oprofile_init(void) | |||
| 246 | int err; | 246 | int err; |
| 247 | 247 | ||
| 248 | /* always init architecture to setup backtrace support */ | 248 | /* always init architecture to setup backtrace support */ |
| 249 | timer_mode = 0; | ||
| 249 | err = oprofile_arch_init(&oprofile_ops); | 250 | err = oprofile_arch_init(&oprofile_ops); |
| 251 | if (!err) { | ||
| 252 | if (!timer && !oprofilefs_register()) | ||
| 253 | return 0; | ||
| 254 | oprofile_arch_exit(); | ||
| 255 | } | ||
| 250 | 256 | ||
| 251 | timer_mode = err || timer; /* fall back to timer mode on errors */ | 257 | /* setup timer mode: */ |
| 252 | if (timer_mode) { | 258 | timer_mode = 1; |
| 253 | if (!err) | 259 | /* no nmi timer mode if oprofile.timer is set */ |
| 254 | oprofile_arch_exit(); | 260 | if (timer || op_nmi_timer_init(&oprofile_ops)) { |
| 255 | err = oprofile_timer_init(&oprofile_ops); | 261 | err = oprofile_timer_init(&oprofile_ops); |
| 256 | if (err) | 262 | if (err) |
| 257 | return err; | 263 | return err; |
| 258 | } | 264 | } |
| 259 | 265 | ||
| 260 | err = oprofilefs_register(); | 266 | return oprofilefs_register(); |
| 261 | if (!err) | ||
| 262 | return 0; | ||
| 263 | |||
| 264 | /* failed */ | ||
| 265 | if (timer_mode) | ||
| 266 | oprofile_timer_exit(); | ||
| 267 | else | ||
| 268 | oprofile_arch_exit(); | ||
| 269 | |||
| 270 | return err; | ||
| 271 | } | 267 | } |
| 272 | 268 | ||
| 273 | 269 | ||
| 274 | static void __exit oprofile_exit(void) | 270 | static void __exit oprofile_exit(void) |
| 275 | { | 271 | { |
| 276 | oprofilefs_unregister(); | 272 | oprofilefs_unregister(); |
| 277 | if (timer_mode) | 273 | if (!timer_mode) |
| 278 | oprofile_timer_exit(); | ||
| 279 | else | ||
| 280 | oprofile_arch_exit(); | 274 | oprofile_arch_exit(); |
| 281 | } | 275 | } |
| 282 | 276 | ||
diff --git a/drivers/oprofile/oprof.h b/drivers/oprofile/oprof.h index 177b73de5e5f..769fb0fcac44 100644 --- a/drivers/oprofile/oprof.h +++ b/drivers/oprofile/oprof.h | |||
| @@ -36,6 +36,15 @@ struct dentry; | |||
| 36 | void oprofile_create_files(struct super_block *sb, struct dentry *root); | 36 | void oprofile_create_files(struct super_block *sb, struct dentry *root); |
| 37 | int oprofile_timer_init(struct oprofile_operations *ops); | 37 | int oprofile_timer_init(struct oprofile_operations *ops); |
| 38 | void oprofile_timer_exit(void); | 38 | void oprofile_timer_exit(void); |
| 39 | #ifdef CONFIG_OPROFILE_NMI_TIMER | ||
| 40 | int op_nmi_timer_init(struct oprofile_operations *ops); | ||
| 41 | #else | ||
| 42 | static inline int op_nmi_timer_init(struct oprofile_operations *ops) | ||
| 43 | { | ||
| 44 | return -ENODEV; | ||
| 45 | } | ||
| 46 | #endif | ||
| 47 | |||
| 39 | 48 | ||
| 40 | int oprofile_set_ulong(unsigned long *addr, unsigned long val); | 49 | int oprofile_set_ulong(unsigned long *addr, unsigned long val); |
| 41 | int oprofile_set_timeout(unsigned long time); | 50 | int oprofile_set_timeout(unsigned long time); |
diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c index 878fba126582..93404f72dfa8 100644 --- a/drivers/oprofile/timer_int.c +++ b/drivers/oprofile/timer_int.c | |||
| @@ -97,24 +97,24 @@ static struct notifier_block __refdata oprofile_cpu_notifier = { | |||
| 97 | .notifier_call = oprofile_cpu_notify, | 97 | .notifier_call = oprofile_cpu_notify, |
| 98 | }; | 98 | }; |
| 99 | 99 | ||
| 100 | int oprofile_timer_init(struct oprofile_operations *ops) | 100 | static int oprofile_hrtimer_setup(void) |
| 101 | { | 101 | { |
| 102 | int rc; | 102 | return register_hotcpu_notifier(&oprofile_cpu_notifier); |
| 103 | |||
| 104 | rc = register_hotcpu_notifier(&oprofile_cpu_notifier); | ||
| 105 | if (rc) | ||
| 106 | return rc; | ||
| 107 | ops->create_files = NULL; | ||
| 108 | ops->setup = NULL; | ||
| 109 | ops->shutdown = NULL; | ||
| 110 | ops->start = oprofile_hrtimer_start; | ||
| 111 | ops->stop = oprofile_hrtimer_stop; | ||
| 112 | ops->cpu_type = "timer"; | ||
| 113 | printk(KERN_INFO "oprofile: using timer interrupt.\n"); | ||
| 114 | return 0; | ||
| 115 | } | 103 | } |
| 116 | 104 | ||
| 117 | void oprofile_timer_exit(void) | 105 | static void oprofile_hrtimer_shutdown(void) |
| 118 | { | 106 | { |
| 119 | unregister_hotcpu_notifier(&oprofile_cpu_notifier); | 107 | unregister_hotcpu_notifier(&oprofile_cpu_notifier); |
| 120 | } | 108 | } |
| 109 | |||
| 110 | int oprofile_timer_init(struct oprofile_operations *ops) | ||
| 111 | { | ||
| 112 | ops->create_files = NULL; | ||
| 113 | ops->setup = oprofile_hrtimer_setup; | ||
| 114 | ops->shutdown = oprofile_hrtimer_shutdown; | ||
| 115 | ops->start = oprofile_hrtimer_start; | ||
| 116 | ops->stop = oprofile_hrtimer_stop; | ||
| 117 | ops->cpu_type = "timer"; | ||
| 118 | printk(KERN_INFO "oprofile: using timer interrupt.\n"); | ||
| 119 | return 0; | ||
| 120 | } | ||
