Skip to content

Commit 3fa2fe2

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf fixes from Ingo Molnar: "This tree contains various perf fixes on the kernel side, plus three hw/event-enablement late additions: - Intel Memory Bandwidth Monitoring events and handling - the AMD Accumulated Power Mechanism reporting facility - more IOMMU events ... and a final round of perf tooling updates/fixes" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (44 commits) perf llvm: Use strerror_r instead of the thread unsafe strerror one perf llvm: Use realpath to canonicalize paths perf tools: Unexport some methods unused outside strbuf.c perf probe: No need to use formatting strbuf method perf help: Use asprintf instead of adhoc equivalents perf tools: Remove unused perf_pathdup, xstrdup functions perf tools: Do not include stringify.h from the kernel sources tools include: Copy linux/stringify.h from the kernel tools lib traceevent: Remove redundant CPU output perf tools: Remove needless 'extern' from function prototypes perf tools: Simplify die() mechanism perf tools: Remove unused DIE_IF macro perf script: Remove lots of unused arguments perf thread: Rename perf_event__preprocess_sample_addr to thread__resolve perf machine: Rename perf_event__preprocess_sample to machine__resolve perf tools: Add cpumode to struct perf_sample perf tests: Forward the perf_sample in the dwarf unwind test perf tools: Remove misplaced __maybe_unused perf list: Fix documentation of :ppp perf bench numa: Fix assertion for nodes bitfield ...
2 parents d88f48e + 05f5ece commit 3fa2fe2

95 files changed

Lines changed: 1336 additions & 634 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/x86/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,15 @@ config MICROCODE_OLD_INTERFACE
12101210
def_bool y
12111211
depends on MICROCODE
12121212

1213+
config PERF_EVENTS_AMD_POWER
1214+
depends on PERF_EVENTS && CPU_SUP_AMD
1215+
tristate "AMD Processor Power Reporting Mechanism"
1216+
---help---
1217+
Provide power reporting mechanism support for AMD processors.
1218+
Currently, it leverages X86_FEATURE_ACC_POWER
1219+
(CPUID Fn8000_0007_EDX[12]) interface to calculate the
1220+
average power consumption on Family 15h processors.
1221+
12131222
config X86_MSR
12141223
tristate "/dev/cpu/*/msr - Model-specific register support"
12151224
---help---

‎arch/x86/events/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
obj-y += core.o
22

33
obj-$(CONFIG_CPU_SUP_AMD) += amd/core.o amd/uncore.o
4+
obj-$(CONFIG_PERF_EVENTS_AMD_POWER) += amd/power.o
45
obj-$(CONFIG_X86_LOCAL_APIC) += amd/ibs.o msr.o
56
ifdef CONFIG_AMD_IOMMU
67
obj-$(CONFIG_CPU_SUP_AMD) += amd/iommu.o

‎arch/x86/events/amd/ibs.c‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,13 @@ static void perf_ibs_start(struct perf_event *event, int flags)
376376
hwc->state = 0;
377377

378378
perf_ibs_set_period(perf_ibs, hwc, &period);
379+
/*
380+
* Set STARTED before enabling the hardware, such that
381+
* a subsequent NMI must observe it. Then clear STOPPING
382+
* such that we don't consume NMIs by accident.
383+
*/
379384
set_bit(IBS_STARTED, pcpu->state);
385+
clear_bit(IBS_STOPPING, pcpu->state);
380386
perf_ibs_enable_event(perf_ibs, hwc, period >> 4);
381387

382388
perf_event_update_userpage(event);
@@ -390,16 +396,32 @@ static void perf_ibs_stop(struct perf_event *event, int flags)
390396
u64 config;
391397
int stopping;
392398

393-
stopping = test_and_clear_bit(IBS_STARTED, pcpu->state);
399+
stopping = test_bit(IBS_STARTED, pcpu->state);
394400

395401
if (!stopping && (hwc->state & PERF_HES_UPTODATE))
396402
return;
397403

398404
rdmsrl(hwc->config_base, config);
399405

400406
if (stopping) {
407+
/*
408+
* Set STOPPING before disabling the hardware, such that it
409+
* must be visible to NMIs the moment we clear the EN bit,
410+
* at which point we can generate an !VALID sample which
411+
* we need to consume.
412+
*/
401413
set_bit(IBS_STOPPING, pcpu->state);
402414
perf_ibs_disable_event(perf_ibs, hwc, config);
415+
/*
416+
* Clear STARTED after disabling the hardware; if it were
417+
* cleared before an NMI hitting after the clear but before
418+
* clearing the EN bit might think it a spurious NMI and not
419+
* handle it.
420+
*
421+
* Clearing it after, however, creates the problem of the NMI
422+
* handler seeing STARTED but not having a valid sample.
423+
*/
424+
clear_bit(IBS_STARTED, pcpu->state);
403425
WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED);
404426
hwc->state |= PERF_HES_STOPPED;
405427
}
@@ -527,20 +549,24 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
527549
u64 *buf, *config, period;
528550

529551
if (!test_bit(IBS_STARTED, pcpu->state)) {
552+
fail:
530553
/*
531554
* Catch spurious interrupts after stopping IBS: After
532555
* disabling IBS there could be still incoming NMIs
533556
* with samples that even have the valid bit cleared.
534557
* Mark all this NMIs as handled.
535558
*/
536-
return test_and_clear_bit(IBS_STOPPING, pcpu->state) ? 1 : 0;
559+
if (test_and_clear_bit(IBS_STOPPING, pcpu->state))
560+
return 1;
561+
562+
return 0;
537563
}
538564

539565
msr = hwc->config_base;
540566
buf = ibs_data.regs;
541567
rdmsrl(msr, *buf);
542568
if (!(*buf++ & perf_ibs->valid_mask))
543-
return 0;
569+
goto fail;
544570

545571
config = &ibs_data.regs[0];
546572
perf_ibs_event_update(perf_ibs, event, config);
@@ -599,7 +625,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
599625
throttle = perf_event_overflow(event, &data, &regs);
600626
out:
601627
if (throttle)
602-
perf_ibs_disable_event(perf_ibs, hwc, *config);
628+
perf_ibs_stop(event, 0);
603629
else
604630
perf_ibs_enable_event(perf_ibs, hwc, period >> 4);
605631

@@ -611,6 +637,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
611637
static int
612638
perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs)
613639
{
640+
u64 stamp = sched_clock();
614641
int handled = 0;
615642

616643
handled += perf_ibs_handle_irq(&perf_ibs_fetch, regs);
@@ -619,6 +646,8 @@ perf_ibs_nmi_handler(unsigned int cmd, struct pt_regs *regs)
619646
if (handled)
620647
inc_irq_stat(apic_perf_irqs);
621648

649+
perf_sample_event_took(sched_clock() - stamp);
650+
622651
return handled;
623652
}
624653
NOKPROBE_SYMBOL(perf_ibs_nmi_handler);

‎arch/x86/events/amd/iommu.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ static struct amd_iommu_event_desc amd_iommu_v2_event_descs[] = {
118118
AMD_IOMMU_EVENT_DESC(cmd_processed, "csource=0x11"),
119119
AMD_IOMMU_EVENT_DESC(cmd_processed_inv, "csource=0x12"),
120120
AMD_IOMMU_EVENT_DESC(tlb_inv, "csource=0x13"),
121+
AMD_IOMMU_EVENT_DESC(ign_rd_wr_mmio_1ff8h, "csource=0x14"),
122+
AMD_IOMMU_EVENT_DESC(vapic_int_non_guest, "csource=0x15"),
123+
AMD_IOMMU_EVENT_DESC(vapic_int_guest, "csource=0x16"),
124+
AMD_IOMMU_EVENT_DESC(smi_recv, "csource=0x17"),
125+
AMD_IOMMU_EVENT_DESC(smi_blk, "csource=0x18"),
121126
{ /* end: all zeroes */ },
122127
};
123128

0 commit comments

Comments
 (0)