History

perf: Pass last sampling period to perf_sample_data_init()

We always need to pass the last sample period to perf_sample_data_init(), otherwise the event distribution will be wrong. Thus, modifiyng the function interface with the required period as argument. So basically a pattern like this: perf_sample_data_init(&data, ~0ULL); data.period = event->hw.last_period; will now be like that: perf_sample_data_init(&data, ~0ULL, event->hw.last_period); Avoids unininitialized data.period and simplifies code.

Robert Richter committed 14 years ago

Commit fd0d0001 parent c75841a15 files · +25 −43Browse files

Unified · Split

15 files
  1. arch/alpha/kernel/perf_event.c +1 −2
  2. arch/arm/kernel/perf_event_v6.c +1 −3
  3. arch/arm/kernel/perf_event_v7.c +1 −3
  4. arch/arm/kernel/perf_event_xscale.c +2 −6
  5. arch/mips/kernel/perf_event_mipsxx.c +1 −1
  6. arch/powerpc/perf/core-book3s.c +1 −2
  7. arch/powerpc/perf/core-fsl-emb.c +1 −2
  8. arch/sparc/kernel/perf_event.c +1 −3
  9. arch/x86/kernel/cpu/perf_event.c +1 −3
  10. arch/x86/kernel/cpu/perf_event_amd_ibs.c +1 −2
  11. arch/x86/kernel/cpu/perf_event_intel.c +1 −3
  12. arch/x86/kernel/cpu/perf_event_intel_ds.c +2 −4
  13. arch/x86/kernel/cpu/perf_event_p4.c +3 −3
  14. include/linux/perf_event.h +4 −1
  15. kernel/events/core.c +4 −5
arch/alpha/kernel/perf_event.c+1−2
@@ -824,7 +824,6 @@ static void alpha_perf_event_irq_handler(unsigned long la_ptr, · 823 unmodified lines
824824
825825 idx = la_ptr;
826826
827− perf_sample_data_init(&data, 0);
828827 for (j = 0; j < cpuc->n_events; j++) {
829828 if (cpuc->current_idx[j] == idx)
830829 break;
@@ -848,7 +847,7 @@ static void alpha_perf_event_irq_handler(unsigned long la_ptr, · 17 unmodified lines
848847
849848 hwc = &event->hw;
850849 alpha_perf_event_update(event, hwc, idx, alpha_pmu->pmc_max_period[idx]+1);
851− data.period = event->hw.last_period;
850+ perf_sample_data_init(&data, 0, hwc->last_period);
852851
853852 if (alpha_perf_event_set_period(event, hwc, idx)) {
854853 if (perf_event_overflow(event, &data, regs)) {
arch/arm/kernel/perf_event_v6.c+1−3
@@ -489,8 +489,6 @@ armv6pmu_handle_irq(int irq_num, · 488 unmodified lines
489489 */
490490 armv6_pmcr_write(pmcr);
491491
492− perf_sample_data_init(&data, 0);
493−
494492 cpuc = &__get_cpu_var(cpu_hw_events);
495493 for (idx = 0; idx < cpu_pmu->num_events; ++idx) {
496494 struct perf_event *event = cpuc->events[idx];
@@ -509,7 +507,7 @@ armv6pmu_handle_irq(int irq_num, · 12 unmodified lines
509507
510508 hwc = &event->hw;
511509 armpmu_event_update(event, hwc, idx);
512− data.period = event->hw.last_period;
510+ perf_sample_data_init(&data, 0, hwc->last_period);
513511 if (!armpmu_event_set_period(event, hwc, idx))
514512 continue;
515513
arch/arm/kernel/perf_event_v7.c+1−3
@@ -1077,8 +1077,6 @@ static irqreturn_t armv7pmu_handle_irq(int irq_num, void *dev) · 1076 unmodified lines
10771077 */
10781078 regs = get_irq_regs();
10791079
1080− perf_sample_data_init(&data, 0);
1081−
10821080 cpuc = &__get_cpu_var(cpu_hw_events);
10831081 for (idx = 0; idx < cpu_pmu->num_events; ++idx) {
10841082 struct perf_event *event = cpuc->events[idx];
@@ -1097,7 +1095,7 @@ static irqreturn_t armv7pmu_handle_irq(int irq_num, void *dev) · 12 unmodified lines
10971095
10981096 hwc = &event->hw;
10991097 armpmu_event_update(event, hwc, idx);
1100− data.period = event->hw.last_period;
1098+ perf_sample_data_init(&data, 0, hwc->last_period);
11011099 if (!armpmu_event_set_period(event, hwc, idx))
11021100 continue;
11031101
arch/arm/kernel/perf_event_xscale.c+2−6
@@ -248,8 +248,6 @@ xscale1pmu_handle_irq(int irq_num, void *dev) · 247 unmodified lines
248248
249249 regs = get_irq_regs();
250250
251− perf_sample_data_init(&data, 0);
252−
253251 cpuc = &__get_cpu_var(cpu_hw_events);
254252 for (idx = 0; idx < cpu_pmu->num_events; ++idx) {
255253 struct perf_event *event = cpuc->events[idx];
@@ -263,7 +261,7 @@ xscale1pmu_handle_irq(int irq_num, void *dev) · 7 unmodified lines
263261
264262 hwc = &event->hw;
265263 armpmu_event_update(event, hwc, idx);
266− data.period = event->hw.last_period;
264+ perf_sample_data_init(&data, 0, hwc->last_period);
267265 if (!armpmu_event_set_period(event, hwc, idx))
268266 continue;
269267
@@ -588,8 +586,6 @@ xscale2pmu_handle_irq(int irq_num, void *dev) · 318 unmodified lines
588586
589587 regs = get_irq_regs();
590588
591− perf_sample_data_init(&data, 0);
592−
593589 cpuc = &__get_cpu_var(cpu_hw_events);
594590 for (idx = 0; idx < cpu_pmu->num_events; ++idx) {
595591 struct perf_event *event = cpuc->events[idx];
@@ -603,7 +599,7 @@ xscale2pmu_handle_irq(int irq_num, void *dev) · 7 unmodified lines
603599
604600 hwc = &event->hw;
605601 armpmu_event_update(event, hwc, idx);
606− data.period = event->hw.last_period;
602+ perf_sample_data_init(&data, 0, hwc->last_period);
607603 if (!armpmu_event_set_period(event, hwc, idx))
608604 continue;
609605
arch/mips/kernel/perf_event_mipsxx.c+1−1
@@ -1325,7 +1325,7 @@ static int mipsxx_pmu_handle_shared_irq(void) · 1324 unmodified lines
13251325
13261326 regs = get_irq_regs();
13271327
1328− perf_sample_data_init(&data, 0);
1328+ perf_sample_data_init(&data, 0, 0);
13291329
13301330 switch (counters) {
13311331 #define HANDLE_COUNTER(n) \
arch/powerpc/perf/core-book3s.c+1−2
@@ -1299,8 +1299,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, · 1298 unmodified lines
12991299 if (record) {
13001300 struct perf_sample_data data;
13011301
1302− perf_sample_data_init(&data, ~0ULL);
1303− data.period = event->hw.last_period;
1302+ perf_sample_data_init(&data, ~0ULL, event->hw.last_period);
13041303
13051304 if (event->attr.sample_type & PERF_SAMPLE_ADDR)
13061305 perf_get_data_addr(regs, &data.addr);
arch/powerpc/perf/core-fsl-emb.c+1−2
@@ -613,8 +613,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, · 612 unmodified lines
613613 if (record) {
614614 struct perf_sample_data data;
615615
616− perf_sample_data_init(&data, 0);
617− data.period = event->hw.last_period;
616+ perf_sample_data_init(&data, 0, event->hw.last_period);
618617
619618 if (perf_event_overflow(event, &data, regs))
620619 fsl_emb_pmu_stop(event, 0);
arch/sparc/kernel/perf_event.c+1−3
@@ -1296,8 +1296,6 @@ static int __kprobes perf_event_nmi_handler(struct notifier_block *self, · 1295 unmodified lines
12961296
12971297 regs = args->regs;
12981298
1299− perf_sample_data_init(&data, 0);
1300−
13011299 cpuc = &__get_cpu_var(cpu_hw_events);
13021300
13031301 /* If the PMU has the TOE IRQ enable bits, we need to do a
@@ -1321,7 +1319,7 @@ static int __kprobes perf_event_nmi_handler(struct notifier_block *self, · 17 unmodified lines
13211319 if (val & (1ULL << 31))
13221320 continue;
13231321
1324− data.period = event->hw.last_period;
1322+ perf_sample_data_init(&data, 0, hwc->last_period);
13251323 if (!sparc_perf_event_set_period(event, hwc, idx))
13261324 continue;
13271325
arch/x86/kernel/cpu/perf_event.c+1−3
@@ -1183,8 +1183,6 @@ int x86_pmu_handle_irq(struct pt_regs *regs) · 1182 unmodified lines
11831183 int idx, handled = 0;
11841184 u64 val;
11851185
1186− perf_sample_data_init(&data, 0);
1187−
11881186 cpuc = &__get_cpu_var(cpu_hw_events);
11891187
11901188 /*
@@ -1219,7 +1217,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs) · 28 unmodified lines
12191217 * event overflow
12201218 */
12211219 handled++;
1222− data.period = event->hw.last_period;
1220+ perf_sample_data_init(&data, 0, event->hw.last_period);
12231221
12241222 if (!x86_perf_event_set_period(event))
12251223 continue;
arch/x86/kernel/cpu/perf_event_amd_ibs.c+1−2
@@ -398,8 +398,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs) · 397 unmodified lines
398398 }
399399
400400 perf_ibs_event_update(perf_ibs, event, config);
401− perf_sample_data_init(&data, 0);
402− data.period = event->hw.last_period;
401+ perf_sample_data_init(&data, 0, hwc->last_period);
403402
404403 if (event->attr.sample_type & PERF_SAMPLE_RAW) {
405404 ibs_data.caps = ibs_caps;
arch/x86/kernel/cpu/perf_event_intel.c+1−3
@@ -1027,8 +1027,6 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) · 1026 unmodified lines
10271027 u64 status;
10281028 int handled;
10291029
1030− perf_sample_data_init(&data, 0);
1031−
10321030 cpuc = &__get_cpu_var(cpu_hw_events);
10331031
10341032 /*
@@ -1082,7 +1080,7 @@ again: · 47 unmodified lines
10821080 if (!intel_pmu_save_and_restart(event))
10831081 continue;
10841082
1085− data.period = event->hw.last_period;
1083+ perf_sample_data_init(&data, 0, event->hw.last_period);
10861084
10871085 if (has_branch_stack(event))
10881086 data.br_stack = &cpuc->lbr_stack;
arch/x86/kernel/cpu/perf_event_intel_ds.c+2−4
@@ -316,8 +316,7 @@ int intel_pmu_drain_bts_buffer(void) · 315 unmodified lines
316316
317317 ds->bts_index = ds->bts_buffer_base;
318318
319− perf_sample_data_init(&data, 0);
320− data.period = event->hw.last_period;
319+ perf_sample_data_init(&data, 0, event->hw.last_period);
321320 regs.ip = 0;
322321
323322 /*
@@ -564,8 +563,7 @@ static void __intel_pmu_pebs_event(struct perf_event *event, · 240 unmodified lines
564563 if (!intel_pmu_save_and_restart(event))
565564 return;
566565
567− perf_sample_data_init(&data, 0);
568− data.period = event->hw.last_period;
566+ perf_sample_data_init(&data, 0, event->hw.last_period);
569567
570568 /*
571569 * We use the interrupt regs as a base because the PEBS record
arch/x86/kernel/cpu/perf_event_p4.c+3−3
@@ -1005,8 +1005,6 @@ static int p4_pmu_handle_irq(struct pt_regs *regs) · 1004 unmodified lines
10051005 int idx, handled = 0;
10061006 u64 val;
10071007
1008− perf_sample_data_init(&data, 0);
1009−
10101008 cpuc = &__get_cpu_var(cpu_hw_events);
10111009
10121010 for (idx = 0; idx < x86_pmu.num_counters; idx++) {
@@ -1034,10 +1032,12 @@ static int p4_pmu_handle_irq(struct pt_regs *regs) · 21 unmodified lines
10341032 handled += overflow;
10351033
10361034 /* event overflow for sure */
1037− data.period = event->hw.last_period;
1035+ perf_sample_data_init(&data, 0, hwc->last_period);
10381036
10391037 if (!x86_perf_event_set_period(event))
10401038 continue;
1039+
1040+
10411041 if (perf_event_overflow(event, &data, regs))
10421042 x86_pmu_stop(event, 0);
10431043 }
include/linux/perf_event.h+4−1
@@ -1132,11 +1132,14 @@ struct perf_sample_data { · 1131 unmodified lines
11321132 struct perf_branch_stack *br_stack;
11331133 };
11341134
1135−static inline void perf_sample_data_init(struct perf_sample_data *data, u64 addr)
1135+static inline void perf_sample_data_init(struct perf_sample_data *data,
1136+ u64 addr, u64 period)
11361137 {
1138+ /* remaining struct members initialized in perf_prepare_sample() */
11371139 data->addr = addr;
11381140 data->raw = NULL;
11391141 data->br_stack = NULL;
1142+ data->period = period;
11401143 }
11411144
11421145 extern void perf_output_sample(struct perf_output_handle *handle,
kernel/events/core.c+4−5
@@ -4957,7 +4957,7 @@ void __perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) · 4956 unmodified lines
49574957 if (rctx < 0)
49584958 return;
49594959
4960− perf_sample_data_init(&data, addr);
4960+ perf_sample_data_init(&data, addr, 0);
49614961
49624962 do_perf_sw_event(PERF_TYPE_SOFTWARE, event_id, nr, &data, regs);
49634963
@@ -5215,7 +5215,7 @@ void perf_tp_event(u64 addr, u64 count, void *record, int entry_size, · 251 unmodified lines
52155215 .data = record,
52165216 };
52175217
5218− perf_sample_data_init(&data, addr);
5218+ perf_sample_data_init(&data, addr, 0);
52195219 data.raw = &raw;
52205220
52215221 hlist_for_each_entry_rcu(event, node, head, hlist_entry) {
@@ -5318,7 +5318,7 @@ void perf_bp_event(struct perf_event *bp, void *data) · 96 unmodified lines
53185318 struct perf_sample_data sample;
53195319 struct pt_regs *regs = data;
53205320
5321− perf_sample_data_init(&sample, bp->attr.bp_addr);
5321+ perf_sample_data_init(&sample, bp->attr.bp_addr, 0);
53225322
53235323 if (!bp->hw.state && !perf_exclude_event(bp, regs))
53245324 perf_swevent_event(bp, 1, &sample, regs);
@@ -5344,8 +5344,7 @@ static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer) · 19 unmodified lines
53445344
53455345 event->pmu->read(event);
53465346
5347− perf_sample_data_init(&data, 0);
5348− data.period = event->hw.last_period;
5347+ perf_sample_data_init(&data, 0, event->hw.last_period);
53495348 regs = get_irq_regs();
53505349
53515350 if (regs && !perf_exclude_event(event, regs)) {