Skip to content

Commit 12b7bcb

Browse files
committed
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar: "The main kernel side changes were: - uprobes enhancements (Masami Hiramatsu) - Uncore group events enhancements (David Carrillo-Cisneros) - x86 Intel: Add support for Skylake server uncore PMUs (Kan Liang) - x86 Intel: LBR cleanups and enhancements, for better branch annotation tracking (Peter Zijlstra) - x86 Intel: Add support for PTWRITE and power event tracing (Alexander Shishkin) - ... various fixes, cleanups and smaller enhancements. Lots of tooling changes - a couple of highlights: - Support event group view with hierarchy mode in 'perf top' and 'perf report' (Namhyung Kim) e.g.: $ perf record -e '{cycles,instructions}' make $ perf report --hierarchy --stdio ... # Overhead Command / Shared Object / Symbol # ...................... .................................. ... 25.74% 27.18%sh 19.96% 24.14%libc-2.24.so 9.55% 14.64%[.] __strcmp_sse2 1.54% 0.00%[.] __tfind 1.07% 1.13%[.] _int_malloc 0.95% 0.00%[.] __strchr_sse2 0.89% 1.39%[.] __tsearch 0.76% 0.00%[.] strlen - Add branch stack / basic block info to 'perf annotate --stdio', where for each branch, we add an asm comment after the instruction with information on how often it was taken and predicted. See example with color output at: http://vger.kernel.org/~acme/perf/annotate_basic_blocks.png (Peter Zijlstra) - Add support for using symbols in address filters with Intel PT and ARM CoreSight (hardware assisted tracing facilities) (Adrian Hunter, Mathieu Poirier) - Add support for interacting with Coresight PMU ETMs/PTMs, that are IP blocks to perform hardware assisted tracing on a ARM CPU core (Mathieu Poirier) - Support generating cross arch probes, i.e. if you specify a vmlinux file for different arch than the one in the host machine, $ perf probe --definition function_name args will generate the probe definition string needed to append to the target machine /sys/kernel/debug/tracing/kprobes_events file, using scripting (Masami Hiramatsu). - Allow configuring the default 'perf report -s' sort order in ~/.perfconfig, for instance, "sym,dso" may be more fitting for kernel developers. (Arnaldo Carvalho de Melo) - ... plus lots of other changes, refactorings, features and fixes" * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (149 commits) perf tests: Add dwarf unwind test for powerpc perf probe: Match linkage name with mangled name perf probe: Fix to cut off incompatible chars from group name perf probe: Skip if the function address is 0 perf probe: Ignore the error of finding inline instance perf intel-pt: Fix decoding when there are address filters perf intel-pt: Enable decoder to handle TIP.PGD with missing IP perf intel-pt: Read address filter from AUXTRACE_INFO event perf intel-pt: Record address filter in AUXTRACE_INFO event perf intel-pt: Add a helper function for processing AUXTRACE_INFO perf intel-pt: Fix missing error codes processing auxtrace_info perf intel-pt: Add support for recording the max non-turbo ratio perf intel-pt: Fix snapshot overlap detection decoder errors perf probe: Increase debug level of SDT debug messages perf record: Add support for using symbols in address filters perf symbols: Add dso__last_symbol() perf record: Fix error paths perf record: Rename label 'out_symbol_exit' perf script: Fix vanished idle symbols perf evsel: Add support for address filters ...
2 parents 00bcf5c + 41aad2a commit 12b7bcb

179 files changed

Lines changed: 6053 additions & 988 deletions

File tree

Some content is hidden

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

‎Documentation/trace/kprobetrace.txt‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Synopsis of kprobe_events
4444
+|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**)
4545
NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
4646
FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
47-
(u8/u16/u32/u64/s8/s16/s32/s64), "string" and bitfield
48-
are supported.
47+
(u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types
48+
(x8/x16/x32/x64), "string" and bitfield are supported.
4949

5050
(*) only for return probe.
5151
(**) this is useful for fetching a field of data structures.
@@ -54,7 +54,10 @@ Types
5454
-----
5555
Several types are supported for fetch-args. Kprobe tracer will access memory
5656
by given type. Prefix 's' and 'u' means those types are signed and unsigned
57-
respectively. Traced arguments are shown in decimal (signed) or hex (unsigned).
57+
respectively. 'x' prefix implies it is unsigned. Traced arguments are shown
58+
in decimal ('s' and 'u') or hexadecimal ('x'). Without type casting, 'x32'
59+
or 'x64' is used depends on the architecture (e.g. x86-32 uses x32, and
60+
x86-64 uses x64).
5861
String type is a special type, which fetches a "null-terminated" string from
5962
kernel space. This means it will fail and store NULL if the string container
6063
has been paged out.

‎Documentation/trace/uprobetracer.txt‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Synopsis of uprobe_tracer
4040
+|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**)
4141
NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
4242
FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
43-
(u8/u16/u32/u64/s8/s16/s32/s64), "string" and bitfield
44-
are supported.
43+
(u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types
44+
(x8/x16/x32/x64), "string" and bitfield are supported.
4545

4646
(*) only for return probe.
4747
(**) this is useful for fetching a field of data structures.
@@ -50,7 +50,10 @@ Types
5050
-----
5151
Several types are supported for fetch-args. Uprobe tracer will access memory
5252
by given type. Prefix 's' and 'u' means those types are signed and unsigned
53-
respectively. Traced arguments are shown in decimal (signed) or hex (unsigned).
53+
respectively. 'x' prefix implies it is unsigned. Traced arguments are shown
54+
in decimal ('s' and 'u') or hexadecimal ('x'). Without type casting, 'x32'
55+
or 'x64' is used depends on the architecture (e.g. x86-32 uses x32, and
56+
x86-64 uses x64).
5457
String type is a special type, which fetches a "null-terminated" string from
5558
user space.
5659
Bitfield is another special type, which takes 3 parameters, bit-width, bit-

‎MAINTAINERS‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,11 @@ F: drivers/hwtracing/coresight/*
11251125
F: Documentation/trace/coresight.txt
11261126
F: Documentation/devicetree/bindings/arm/coresight.txt
11271127
F: Documentation/ABI/testing/sysfs-bus-coresight-devices-*
1128+
F: tools/perf/arch/arm/util/pmu.c
1129+
F: tools/perf/arch/arm/util/auxtrace.c
1130+
F: tools/perf/arch/arm/util/cs-etm.c
1131+
F: tools/perf/arch/arm/util/cs-etm.h
1132+
F: tools/perf/util/cs-etm.h
11281133

11291134
ARM/CORGI MACHINE SUPPORT
11301135
M: Richard Purdie <rpurdie@rpsys.net>

‎arch/x86/events/core.c‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,9 @@ static int x86_pmu_add(struct perf_event *event, int flags)
12011201
* If group events scheduling transaction was started,
12021202
* skip the schedulability test here, it will be performed
12031203
* at commit time (->commit_txn) as a whole.
1204+
*
1205+
* If commit fails, we'll call ->del() on all events
1206+
* for which ->add() was called.
12041207
*/
12051208
if (cpuc->txn_flags & PERF_PMU_TXN_ADD)
12061209
goto done_collect;
@@ -1223,6 +1226,14 @@ static int x86_pmu_add(struct perf_event *event, int flags)
12231226
cpuc->n_added += n - n0;
12241227
cpuc->n_txn += n - n0;
12251228

1229+
if (x86_pmu.add) {
1230+
/*
1231+
* This is before x86_pmu_enable() will call x86_pmu_start(),
1232+
* so we enable LBRs before an event needs them etc..
1233+
*/
1234+
x86_pmu.add(event);
1235+
}
1236+
12261237
ret = 0;
12271238
out:
12281239
return ret;
@@ -1346,15 +1357,15 @@ static void x86_pmu_del(struct perf_event *event, int flags)
13461357
event->hw.flags &= ~PERF_X86_EVENT_COMMITTED;
13471358

13481359
/*
1349-
* If we're called during a txn, we don't need to do anything.
1360+
* If we're called during a txn, we only need to undo x86_pmu.add.
13501361
* The events never got scheduled and ->cancel_txn will truncate
13511362
* the event_list.
13521363
*
13531364
* XXX assumes any ->del() called during a TXN will only be on
13541365
* an event added during that same TXN.
13551366
*/
13561367
if (cpuc->txn_flags & PERF_PMU_TXN_ADD)
1357-
return;
1368+
goto do_del;
13581369

13591370
/*
13601371
* Not a TXN, therefore cleanup properly.
@@ -1384,6 +1395,15 @@ static void x86_pmu_del(struct perf_event *event, int flags)
13841395
--cpuc->n_events;
13851396

13861397
perf_event_update_userpage(event);
1398+
1399+
do_del:
1400+
if (x86_pmu.del) {
1401+
/*
1402+
* This is after x86_pmu_stop(); so we disable LBRs after any
1403+
* event can need them etc..
1404+
*/
1405+
x86_pmu.del(event);
1406+
}
13871407
}
13881408

13891409
int x86_pmu_handle_irq(struct pt_regs *regs)

‎arch/x86/events/intel/core.c‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,13 +1906,6 @@ static void intel_pmu_disable_event(struct perf_event *event)
19061906
cpuc->intel_ctrl_host_mask &= ~(1ull << hwc->idx);
19071907
cpuc->intel_cp_status &= ~(1ull << hwc->idx);
19081908

1909-
/*
1910-
* must disable before any actual event
1911-
* because any event may be combined with LBR
1912-
*/
1913-
if (needs_branch_stack(event))
1914-
intel_pmu_lbr_disable(event);
1915-
19161909
if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
19171910
intel_pmu_disable_fixed(hwc);
19181911
return;
@@ -1924,6 +1917,14 @@ static void intel_pmu_disable_event(struct perf_event *event)
19241917
intel_pmu_pebs_disable(event);
19251918
}
19261919

1920+
static void intel_pmu_del_event(struct perf_event *event)
1921+
{
1922+
if (needs_branch_stack(event))
1923+
intel_pmu_lbr_del(event);
1924+
if (event->attr.precise_ip)
1925+
intel_pmu_pebs_del(event);
1926+
}
1927+
19271928
static void intel_pmu_enable_fixed(struct hw_perf_event *hwc)
19281929
{
19291930
int idx = hwc->idx - INTEL_PMC_IDX_FIXED;
@@ -1967,12 +1968,6 @@ static void intel_pmu_enable_event(struct perf_event *event)
19671968
intel_pmu_enable_bts(hwc->config);
19681969
return;
19691970
}
1970-
/*
1971-
* must enabled before any actual event
1972-
* because any event may be combined with LBR
1973-
*/
1974-
if (needs_branch_stack(event))
1975-
intel_pmu_lbr_enable(event);
19761971

19771972
if (event->attr.exclude_host)
19781973
cpuc->intel_ctrl_guest_mask |= (1ull << hwc->idx);
@@ -1993,6 +1988,14 @@ static void intel_pmu_enable_event(struct perf_event *event)
19931988
__x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
19941989
}
19951990

1991+
static void intel_pmu_add_event(struct perf_event *event)
1992+
{
1993+
if (event->attr.precise_ip)
1994+
intel_pmu_pebs_add(event);
1995+
if (needs_branch_stack(event))
1996+
intel_pmu_lbr_add(event);
1997+
}
1998+
19961999
/*
19972000
* Save and restart an expired event. Called by NMI contexts,
19982001
* so it has to be careful about preempting normal event ops:
@@ -3291,6 +3294,8 @@ static __initconst const struct x86_pmu intel_pmu = {
32913294
.enable_all = intel_pmu_enable_all,
32923295
.enable = intel_pmu_enable_event,
32933296
.disable = intel_pmu_disable_event,
3297+
.add = intel_pmu_add_event,
3298+
.del = intel_pmu_del_event,
32943299
.hw_config = intel_pmu_hw_config,
32953300
.schedule_events = x86_schedule_events,
32963301
.eventsel = MSR_ARCH_PERFMON_EVENTSEL0,

‎arch/x86/events/intel/ds.c‎

Lines changed: 73 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -806,22 +806,75 @@ struct event_constraint *intel_pebs_constraints(struct perf_event *event)
806806
return &emptyconstraint;
807807
}
808808

809-
static inline bool pebs_is_enabled(struct cpu_hw_events *cpuc)
809+
/*
810+
* We need the sched_task callback even for per-cpu events when we use
811+
* the large interrupt threshold, such that we can provide PID and TID
812+
* to PEBS samples.
813+
*/
814+
static inline bool pebs_needs_sched_cb(struct cpu_hw_events *cpuc)
815+
{
816+
return cpuc->n_pebs && (cpuc->n_pebs == cpuc->n_large_pebs);
817+
}
818+
819+
static inline void pebs_update_threshold(struct cpu_hw_events *cpuc)
820+
{
821+
struct debug_store *ds = cpuc->ds;
822+
u64 threshold;
823+
824+
if (cpuc->n_pebs == cpuc->n_large_pebs) {
825+
threshold = ds->pebs_absolute_maximum -
826+
x86_pmu.max_pebs_events * x86_pmu.pebs_record_size;
827+
} else {
828+
threshold = ds->pebs_buffer_base + x86_pmu.pebs_record_size;
829+
}
830+
831+
ds->pebs_interrupt_threshold = threshold;
832+
}
833+
834+
static void
835+
pebs_update_state(bool needed_cb, struct cpu_hw_events *cpuc, struct pmu *pmu)
836+
{
837+
/*
838+
* Make sure we get updated with the first PEBS
839+
* event. It will trigger also during removal, but
840+
* that does not hurt:
841+
*/
842+
bool update = cpuc->n_pebs == 1;
843+
844+
if (needed_cb != pebs_needs_sched_cb(cpuc)) {
845+
if (!needed_cb)
846+
perf_sched_cb_inc(pmu);
847+
else
848+
perf_sched_cb_dec(pmu);
849+
850+
update = true;
851+
}
852+
853+
if (update)
854+
pebs_update_threshold(cpuc);
855+
}
856+
857+
void intel_pmu_pebs_add(struct perf_event *event)
810858
{
811-
return (cpuc->pebs_enabled & ((1ULL << MAX_PEBS_EVENTS) - 1));
859+
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
860+
struct hw_perf_event *hwc = &event->hw;
861+
bool needed_cb = pebs_needs_sched_cb(cpuc);
862+
863+
cpuc->n_pebs++;
864+
if (hwc->flags & PERF_X86_EVENT_FREERUNNING)
865+
cpuc->n_large_pebs++;
866+
867+
pebs_update_state(needed_cb, cpuc, event->ctx->pmu);
812868
}
813869

814870
void intel_pmu_pebs_enable(struct perf_event *event)
815871
{
816872
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
817873
struct hw_perf_event *hwc = &event->hw;
818874
struct debug_store *ds = cpuc->ds;
819-
bool first_pebs;
820-
u64 threshold;
821875

822876
hwc->config &= ~ARCH_PERFMON_EVENTSEL_INT;
823877

824-
first_pebs = !pebs_is_enabled(cpuc);
825878
cpuc->pebs_enabled |= 1ULL << hwc->idx;
826879

827880
if (event->hw.flags & PERF_X86_EVENT_PEBS_LDLAT)
@@ -830,46 +883,34 @@ void intel_pmu_pebs_enable(struct perf_event *event)
830883
cpuc->pebs_enabled |= 1ULL << 63;
831884

832885
/*
833-
* When the event is constrained enough we can use a larger
834-
* threshold and run the event with less frequent PMI.
886+
* Use auto-reload if possible to save a MSR write in the PMI.
887+
* This must be done in pmu::start(), because PERF_EVENT_IOC_PERIOD.
835888
*/
836-
if (hwc->flags & PERF_X86_EVENT_FREERUNNING) {
837-
threshold = ds->pebs_absolute_maximum -
838-
x86_pmu.max_pebs_events * x86_pmu.pebs_record_size;
839-
840-
if (first_pebs)
841-
perf_sched_cb_inc(event->ctx->pmu);
842-
} else {
843-
threshold = ds->pebs_buffer_base + x86_pmu.pebs_record_size;
844-
845-
/*
846-
* If not all events can use larger buffer,
847-
* roll back to threshold = 1
848-
*/
849-
if (!first_pebs &&
850-
(ds->pebs_interrupt_threshold > threshold))
851-
perf_sched_cb_dec(event->ctx->pmu);
852-
}
853-
854-
/* Use auto-reload if possible to save a MSR write in the PMI */
855889
if (hwc->flags & PERF_X86_EVENT_AUTO_RELOAD) {
856890
ds->pebs_event_reset[hwc->idx] =
857891
(u64)(-hwc->sample_period) & x86_pmu.cntval_mask;
858892
}
893+
}
894+
895+
void intel_pmu_pebs_del(struct perf_event *event)
896+
{
897+
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
898+
struct hw_perf_event *hwc = &event->hw;
899+
bool needed_cb = pebs_needs_sched_cb(cpuc);
859900

860-
if (first_pebs || ds->pebs_interrupt_threshold > threshold)
861-
ds->pebs_interrupt_threshold = threshold;
901+
cpuc->n_pebs--;
902+
if (hwc->flags & PERF_X86_EVENT_FREERUNNING)
903+
cpuc->n_large_pebs--;
904+
905+
pebs_update_state(needed_cb, cpuc, event->ctx->pmu);
862906
}
863907

864908
void intel_pmu_pebs_disable(struct perf_event *event)
865909
{
866910
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
867911
struct hw_perf_event *hwc = &event->hw;
868-
struct debug_store *ds = cpuc->ds;
869-
bool large_pebs = ds->pebs_interrupt_threshold >
870-
ds->pebs_buffer_base + x86_pmu.pebs_record_size;
871912

872-
if (large_pebs)
913+
if (cpuc->n_pebs == cpuc->n_large_pebs)
873914
intel_pmu_drain_pebs_buffer();
874915

875916
cpuc->pebs_enabled &= ~(1ULL << hwc->idx);
@@ -879,9 +920,6 @@ void intel_pmu_pebs_disable(struct perf_event *event)
879920
else if (event->hw.flags & PERF_X86_EVENT_PEBS_ST)
880921
cpuc->pebs_enabled &= ~(1ULL << 63);
881922

882-
if (large_pebs && !pebs_is_enabled(cpuc))
883-
perf_sched_cb_dec(event->ctx->pmu);
884-
885923
if (cpuc->enabled)
886924
wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled);
887925

0 commit comments

Comments
 (0)