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

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.

Signed-off-by: Robert Richter <robert.richter@amd.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1333390758-10893-3-git-send-email-robert.richter@amd.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Robert Richter and committed by
Ingo Molnar
fd0d000b c75841a3

+25 -43
+1 -2
arch/alpha/kernel/perf_event.c
··· 824 824 825 825 idx = la_ptr; 826 826 827 - perf_sample_data_init(&data, 0); 828 827 for (j = 0; j < cpuc->n_events; j++) { 829 828 if (cpuc->current_idx[j] == idx) 830 829 break; ··· 847 848 848 849 hwc = &event->hw; 849 850 alpha_perf_event_update(event, hwc, idx, alpha_pmu->pmc_max_period[idx]+1); 850 - data.period = event->hw.last_period; 851 + perf_sample_data_init(&data, 0, hwc->last_period); 851 852 852 853 if (alpha_perf_event_set_period(event, hwc, idx)) { 853 854 if (perf_event_overflow(event, &data, regs)) {
+1 -3
arch/arm/kernel/perf_event_v6.c
··· 489 489 */ 490 490 armv6_pmcr_write(pmcr); 491 491 492 - perf_sample_data_init(&data, 0); 493 - 494 492 cpuc = &__get_cpu_var(cpu_hw_events); 495 493 for (idx = 0; idx < cpu_pmu->num_events; ++idx) { 496 494 struct perf_event *event = cpuc->events[idx]; ··· 507 509 508 510 hwc = &event->hw; 509 511 armpmu_event_update(event, hwc, idx); 510 - data.period = event->hw.last_period; 512 + perf_sample_data_init(&data, 0, hwc->last_period); 511 513 if (!armpmu_event_set_period(event, hwc, idx)) 512 514 continue; 513 515
+1 -3
arch/arm/kernel/perf_event_v7.c
··· 1077 1077 */ 1078 1078 regs = get_irq_regs(); 1079 1079 1080 - perf_sample_data_init(&data, 0); 1081 - 1082 1080 cpuc = &__get_cpu_var(cpu_hw_events); 1083 1081 for (idx = 0; idx < cpu_pmu->num_events; ++idx) { 1084 1082 struct perf_event *event = cpuc->events[idx]; ··· 1095 1097 1096 1098 hwc = &event->hw; 1097 1099 armpmu_event_update(event, hwc, idx); 1098 - data.period = event->hw.last_period; 1100 + perf_sample_data_init(&data, 0, hwc->last_period); 1099 1101 if (!armpmu_event_set_period(event, hwc, idx)) 1100 1102 continue; 1101 1103
+2 -6
arch/arm/kernel/perf_event_xscale.c
··· 248 248 249 249 regs = get_irq_regs(); 250 250 251 - perf_sample_data_init(&data, 0); 252 - 253 251 cpuc = &__get_cpu_var(cpu_hw_events); 254 252 for (idx = 0; idx < cpu_pmu->num_events; ++idx) { 255 253 struct perf_event *event = cpuc->events[idx]; ··· 261 263 262 264 hwc = &event->hw; 263 265 armpmu_event_update(event, hwc, idx); 264 - data.period = event->hw.last_period; 266 + perf_sample_data_init(&data, 0, hwc->last_period); 265 267 if (!armpmu_event_set_period(event, hwc, idx)) 266 268 continue; 267 269 ··· 586 588 587 589 regs = get_irq_regs(); 588 590 589 - perf_sample_data_init(&data, 0); 590 - 591 591 cpuc = &__get_cpu_var(cpu_hw_events); 592 592 for (idx = 0; idx < cpu_pmu->num_events; ++idx) { 593 593 struct perf_event *event = cpuc->events[idx]; ··· 599 603 600 604 hwc = &event->hw; 601 605 armpmu_event_update(event, hwc, idx); 602 - data.period = event->hw.last_period; 606 + perf_sample_data_init(&data, 0, hwc->last_period); 603 607 if (!armpmu_event_set_period(event, hwc, idx)) 604 608 continue; 605 609
+1 -1
arch/mips/kernel/perf_event_mipsxx.c
··· 1325 1325 1326 1326 regs = get_irq_regs(); 1327 1327 1328 - perf_sample_data_init(&data, 0); 1328 + perf_sample_data_init(&data, 0, 0); 1329 1329 1330 1330 switch (counters) { 1331 1331 #define HANDLE_COUNTER(n) \
+1 -2
arch/powerpc/perf/core-book3s.c
··· 1299 1299 if (record) { 1300 1300 struct perf_sample_data data; 1301 1301 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); 1304 1303 1305 1304 if (event->attr.sample_type & PERF_SAMPLE_ADDR) 1306 1305 perf_get_data_addr(regs, &data.addr);
+1 -2
arch/powerpc/perf/core-fsl-emb.c
··· 613 613 if (record) { 614 614 struct perf_sample_data data; 615 615 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); 618 617 619 618 if (perf_event_overflow(event, &data, regs)) 620 619 fsl_emb_pmu_stop(event, 0);
+1 -3
arch/sparc/kernel/perf_event.c
··· 1296 1296 1297 1297 regs = args->regs; 1298 1298 1299 - perf_sample_data_init(&data, 0); 1300 - 1301 1299 cpuc = &__get_cpu_var(cpu_hw_events); 1302 1300 1303 1301 /* If the PMU has the TOE IRQ enable bits, we need to do a ··· 1319 1321 if (val & (1ULL << 31)) 1320 1322 continue; 1321 1323 1322 - data.period = event->hw.last_period; 1324 + perf_sample_data_init(&data, 0, hwc->last_period); 1323 1325 if (!sparc_perf_event_set_period(event, hwc, idx)) 1324 1326 continue; 1325 1327
+1 -3
arch/x86/kernel/cpu/perf_event.c
··· 1183 1183 int idx, handled = 0; 1184 1184 u64 val; 1185 1185 1186 - perf_sample_data_init(&data, 0); 1187 - 1188 1186 cpuc = &__get_cpu_var(cpu_hw_events); 1189 1187 1190 1188 /* ··· 1217 1219 * event overflow 1218 1220 */ 1219 1221 handled++; 1220 - data.period = event->hw.last_period; 1222 + perf_sample_data_init(&data, 0, event->hw.last_period); 1221 1223 1222 1224 if (!x86_perf_event_set_period(event)) 1223 1225 continue;
+1 -2
arch/x86/kernel/cpu/perf_event_amd_ibs.c
··· 398 398 } 399 399 400 400 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); 403 402 404 403 if (event->attr.sample_type & PERF_SAMPLE_RAW) { 405 404 ibs_data.caps = ibs_caps;
+1 -3
arch/x86/kernel/cpu/perf_event_intel.c
··· 1027 1027 u64 status; 1028 1028 int handled; 1029 1029 1030 - perf_sample_data_init(&data, 0); 1031 - 1032 1030 cpuc = &__get_cpu_var(cpu_hw_events); 1033 1031 1034 1032 /* ··· 1080 1082 if (!intel_pmu_save_and_restart(event)) 1081 1083 continue; 1082 1084 1083 - data.period = event->hw.last_period; 1085 + perf_sample_data_init(&data, 0, event->hw.last_period); 1084 1086 1085 1087 if (has_branch_stack(event)) 1086 1088 data.br_stack = &cpuc->lbr_stack;
+2 -4
arch/x86/kernel/cpu/perf_event_intel_ds.c
··· 316 316 317 317 ds->bts_index = ds->bts_buffer_base; 318 318 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); 321 320 regs.ip = 0; 322 321 323 322 /* ··· 563 564 if (!intel_pmu_save_and_restart(event)) 564 565 return; 565 566 566 - perf_sample_data_init(&data, 0); 567 - data.period = event->hw.last_period; 567 + perf_sample_data_init(&data, 0, event->hw.last_period); 568 568 569 569 /* 570 570 * We use the interrupt regs as a base because the PEBS record
+3 -3
arch/x86/kernel/cpu/perf_event_p4.c
··· 1005 1005 int idx, handled = 0; 1006 1006 u64 val; 1007 1007 1008 - perf_sample_data_init(&data, 0); 1009 - 1010 1008 cpuc = &__get_cpu_var(cpu_hw_events); 1011 1009 1012 1010 for (idx = 0; idx < x86_pmu.num_counters; idx++) { ··· 1032 1034 handled += overflow; 1033 1035 1034 1036 /* event overflow for sure */ 1035 - data.period = event->hw.last_period; 1037 + perf_sample_data_init(&data, 0, hwc->last_period); 1036 1038 1037 1039 if (!x86_perf_event_set_period(event)) 1038 1040 continue; 1041 + 1042 + 1039 1043 if (perf_event_overflow(event, &data, regs)) 1040 1044 x86_pmu_stop(event, 0); 1041 1045 }
+4 -1
include/linux/perf_event.h
··· 1132 1132 struct perf_branch_stack *br_stack; 1133 1133 }; 1134 1134 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) 1136 1137 { 1138 + /* remaining struct members initialized in perf_prepare_sample() */ 1137 1139 data->addr = addr; 1138 1140 data->raw = NULL; 1139 1141 data->br_stack = NULL; 1142 + data->period = period; 1140 1143 } 1141 1144 1142 1145 extern void perf_output_sample(struct perf_output_handle *handle,
+4 -5
kernel/events/core.c
··· 4957 4957 if (rctx < 0) 4958 4958 return; 4959 4959 4960 - perf_sample_data_init(&data, addr); 4960 + perf_sample_data_init(&data, addr, 0); 4961 4961 4962 4962 do_perf_sw_event(PERF_TYPE_SOFTWARE, event_id, nr, &data, regs); 4963 4963 ··· 5215 5215 .data = record, 5216 5216 }; 5217 5217 5218 - perf_sample_data_init(&data, addr); 5218 + perf_sample_data_init(&data, addr, 0); 5219 5219 data.raw = &raw; 5220 5220 5221 5221 hlist_for_each_entry_rcu(event, node, head, hlist_entry) { ··· 5318 5318 struct perf_sample_data sample; 5319 5319 struct pt_regs *regs = data; 5320 5320 5321 - perf_sample_data_init(&sample, bp->attr.bp_addr); 5321 + perf_sample_data_init(&sample, bp->attr.bp_addr, 0); 5322 5322 5323 5323 if (!bp->hw.state && !perf_exclude_event(bp, regs)) 5324 5324 perf_swevent_event(bp, 1, &sample, regs); ··· 5344 5344 5345 5345 event->pmu->read(event); 5346 5346 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); 5349 5348 regs = get_irq_regs(); 5350 5349 5351 5350 if (regs && !perf_exclude_event(event, regs)) {