perf fixes
Subsystems (3)
Linus,
Please pull the latest perf-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf-urgent-for-linus
# HEAD: 95f3be798472f63b495ca4712af005ea5ac7aa47 perf/x86/intel/uncore: Add enable_box for client MSR uncore
Mostly tooling fixes, plus two uncore-PMU fixes, an uprobes fix, a perf-cgroups fix and an AUX events fix.
Thanks,
Ingo
------------------>
Arnaldo Carvalho de Melo (4):
perf hists: Trim libtraceevent trace_seq buffers
tools: Sync cpufeatures.h and vmx.h with the kernel
toops: Sync tools/include/uapi/linux/bpf.h with the kernel
tools: Sync cpufeatures headers with the kernel
Brendan Gregg (1):
perf script: Add 'bpf-output' field to usage message
David Carrillo-Cisneros (1):
perf/core: Set cgroup in CPU contexts for new cgroup events
Denys Vlasenko (1):
uprobes/x86: Fix RIP-relative handling of EVEX-encoded instructions
Kan Liang (2):
perf/x86/intel/uncore: Fix uncore num_counters perf/x86/intel/uncore: Add enable_box for client MSR uncore
Konstantin Khlebnikov (1):
perf probe: Fix module name matching
Mark Rutland (1):
perf stat: Avoid skew when reading events
Masami Hiramatsu (1):
perf probe: Adjust map->reloc offset when finding kernel symbol from map
Naohiro Aota (1):
perf probe: Support signedness casting
Peter Zijlstra (1):
perf/core: Fix sideband list-iteration vs. event ordering NULL pointer deference crash
Ravi Bangoria (2):
perf probe: Add function to post process kernel trace events perf probe ppc64le: Fix probe location when using DWARF
arch/x86/events/intel/uncore_snb.c | 14 +++++ arch/x86/events/intel/uncore_snbep.c | 10 +-- arch/x86/kernel/uprobes.c | 22 +++---- include/linux/perf_event.h | 4 ++ kernel/events/core.c | 77 ++++++++++++++++------- tools/arch/x86/include/asm/cpufeatures.h | 9 +-- tools/arch/x86/include/asm/disabled-features.h | 2 + tools/arch/x86/include/asm/required-features.h | 2 + tools/arch/x86/include/uapi/asm/vmx.h | 4 +- tools/include/uapi/linux/bpf.h | 86 +++++++++++++++++++++++++- tools/perf/Documentation/perf-probe.txt | 10 ++- tools/perf/Documentation/perf-script.txt | 4 +- tools/perf/arch/powerpc/util/sym-handling.c | 27 ++++++-- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-stat.c | 31 +++++++--- tools/perf/util/probe-event.c | 60 +++++++++++------- tools/perf/util/probe-event.h | 6 +- tools/perf/util/probe-finder.c | 15 ++++- tools/perf/util/sort.c | 6 +- 19 files changed, 298 insertions(+), 93 deletions(-)
arch/x86/events/intel/uncore_snb.c +14 -0
@@ -100,6 +100,12 @@ static void snb_uncore_msr_init_box(struct intel_uncore_box *box) } } +static void snb_uncore_msr_enable_box (struct intel_uncore_box *box) +{ +wrmsrl (SNB_UNC_PERF_GLOBAL_CTL , +SNB_UNC_GLOBAL_CTL_EN |SNB_UNC_GLOBAL_CTL_CORE_ALL ); +} +static void snb_uncore_msr_exit_box (struct intel_uncore_box *box) {if (box->pmu->pmu_idx ==0 )
@@ -127,6 +133,7 @@ static struct attribute_group snb_uncore_format_group = {static struct intel_uncore_ops snb_uncore_msr_ops = { .init_box = snb_uncore_msr_init_box, + .enable_box = snb_uncore_msr_enable_box, .exit_box = snb_uncore_msr_exit_box, .disable_event = snb_uncore_msr_disable_event, .enable_event = snb_uncore_msr_enable_event,
@@ -192,6 +199,12 @@ static void skl_uncore_msr_init_box(struct intel_uncore_box *box) } } +static void skl_uncore_msr_enable_box (struct intel_uncore_box *box) +{ +wrmsrl (SKL_UNC_PERF_GLOBAL_CTL , +SNB_UNC_GLOBAL_CTL_EN |SKL_UNC_GLOBAL_CTL_CORE_ALL ); +} +static void skl_uncore_msr_exit_box (struct intel_uncore_box *box) {if (box->pmu->pmu_idx ==0 )
@@ -200,6 +213,7 @@ static void skl_uncore_msr_exit_box(struct intel_uncore_box *box)static struct intel_uncore_ops skl_uncore_msr_ops = { .init_box = skl_uncore_msr_init_box, + .enable_box = skl_uncore_msr_enable_box, .exit_box = skl_uncore_msr_exit_box, .disable_event = snb_uncore_msr_disable_event, .enable_event = snb_uncore_msr_enable_event,
arch/x86/events/intel/uncore_snbep.c +5 -5
@@ -2626,7 +2626,7 @@ void hswep_uncore_cpu_init(void)static struct intel_uncore_type hswep_uncore_ha = { .name ="ha" , - .num_counters =5 , + .num_counters =4 , .num_boxes =2 , .perf_ctr_bits =48 ,SNBEP_UNCORE_PCI_COMMON_INIT (),
@@ -2645,7 +2645,7 @@ static struct uncore_event_desc hswep_uncore_imc_events[] = {static struct intel_uncore_type hswep_uncore_imc = { .name ="imc" , - .num_counters =5 , + .num_counters =4 , .num_boxes =8 , .perf_ctr_bits =48 , .fixed_ctr_bits =48 ,
@@ -2691,7 +2691,7 @@ static struct intel_uncore_type hswep_uncore_irp = {static struct intel_uncore_type hswep_uncore_qpi = { .name ="qpi" , - .num_counters =5 , + .num_counters =4 , .num_boxes =3 , .perf_ctr_bits =48 , .perf_ctr =SNBEP_PCI_PMON_CTR0 ,
@@ -2773,7 +2773,7 @@ static struct event_constraint hswep_uncore_r3qpi_constraints[] = {static struct intel_uncore_type hswep_uncore_r3qpi = { .name ="r3qpi" , - .num_counters =4 , + .num_counters =3 , .num_boxes =3 , .perf_ctr_bits =44 , .constraints = hswep_uncore_r3qpi_constraints,
@@ -2972,7 +2972,7 @@ static struct intel_uncore_type bdx_uncore_ha = {static struct intel_uncore_type bdx_uncore_imc = { .name ="imc" , - .num_counters =5 , + .num_counters =4 , .num_boxes =8 , .perf_ctr_bits =48 , .fixed_ctr_bits =48 ,
arch/x86/kernel/uprobes.c +11 -11
@@ -357,20 +357,22 @@ static void riprel_analyze(struct arch_uprobe *auprobe, struct insn *insn) *cursor &=0xfe ; }/* -* Similar treatment for VEX3 prefix. -* TODO: add XOP/EVEX treatment when insn decoder supports them +* Similar treatment for VEX3/EVEX prefix. +* TODO: add XOP treatment when insn decoder supports them */ -if (insn->vex_prefix.nbytes ==3 ) { +if (insn->vex_prefix.nbytes >=3 ) {/* * vex2: c5 rvvvvLpp (has no b bit) * vex3/xop: c4/8f rxbmmmmm wvvvvLpp * evex: 62 rxbR00mm wvvvv1pp zllBVaaa -* (evex will need setting of both b and x since -* in non-sib encoding evex.x is 4th bit of MODRM.rm) -* Setting VEX3.b (setting because it has inverted meaning): +* Setting VEX3.b (setting because it has inverted meaning). +* Setting EVEX.x since (in non-SIB encoding) EVEX.x +* is the 4th bit of MODRM.rm, and needs the same treatment. +* For VEX3-encoded insns, VEX3.x value has no effect in +* non-SIB encoding, the change is superfluous but harmless. */ cursor = auprobe->insn +insn_offset_vex_prefix (insn) +1 ; - *cursor |=0x20 ; + *cursor |=0x60 ; }/*
@@ -415,12 +417,10 @@ static void riprel_analyze(struct arch_uprobe *auprobe, struct insn *insn) reg =MODRM_REG (insn);/* Fetch modrm.reg */ reg2 =0xff ;/* Fetch vex.vvvv */ -if (insn->vex_prefix.nbytes ==2 ) - reg2 = insn->vex_prefix.bytes[1 ]; -else if (insn->vex_prefix.nbytes ==3 ) +if (insn->vex_prefix.nbytes) reg2 = insn->vex_prefix.bytes[2 ];/* -* TODO: add XOP, EXEV vvvv reading. +* TODO: add XOP vvvv reading. * * vex.vvvv field is in bits 6-3, bits are inverted. * But in 32-bit mode, high-order bit may be ignored.
include/linux/perf_event.h +4 -0
@@ -743,7 +743,9 @@ struct perf_event_context {u64 parent_gen;u64 generation;int pin_count; +#ifdef CONFIG_CGROUP_PERF int nr_cgroups;/* cgroup evts */ +#endif void *task_ctx_data;/* pmu specific data */ struct rcu_head rcu_head; };
@@ -769,7 +771,9 @@ struct perf_cpu_context {unsigned int hrtimer_active;struct pmu *unique_pmu; +#ifdef CONFIG_CGROUP_PERF struct perf_cgroup *cgrp; +#endif };struct perf_output_handle {
kernel/events/core.c +54 -23
140 lines not on this page · raw message
tools/arch/x86/include/asm/cpufeatures.h +3 -6
@@ -225,7 +225,6 @@#define X86_FEATURE_RDSEED ( 9*32+18)/* The RDSEED instruction */ #define X86_FEATURE_ADX ( 9*32+19)/* The ADCX and ADOX instructions */ #define X86_FEATURE_SMAP ( 9*32+20)/* Supervisor Mode Access Prevention */ -#define X86_FEATURE_PCOMMIT ( 9*32+22)/* PCOMMIT instruction */ #define X86_FEATURE_CLFLUSHOPT ( 9*32+23)/* CLFLUSHOPT instruction */ #define X86_FEATURE_CLWB ( 9*32+24)/* CLWB instruction */ #define X86_FEATURE_AVX512PF ( 9*32+26)/* AVX-512 Prefetch */
@@ -301,10 +300,6 @@#define X86_BUG_FXSAVE_LEAK X86_BUG(6)/* FXSAVE leaks FOP/FIP/FOP */ #define X86_BUG_CLFLUSH_MONITOR X86_BUG(7)/* AAI65, CLFLUSH required before MONITOR */ #define X86_BUG_SYSRET_SS_ATTRS X86_BUG(8)/* SYSRET doesn't fix up SS attrs */ -#define X86_BUG_NULL_SEG X86_BUG(9)/* Nulling a selector preserves the base */ -#define X86_BUG_SWAPGS_FENCE X86_BUG(10)/* SWAPGS without input dep on GS */ - -#ifdef CONFIG_X86_32 /* * 64-bit kernels don't use X86_BUG_ESPFIX. Make the define conditional
@@ -312,5 +307,7 @@*/ #define X86_BUG_ESPFIX X86_BUG(9)/* "" IRET to 16-bit SS corrupts ESP/RSP high bits */ #endif - +#define X86_BUG_NULL_SEG X86_BUG(10)/* Nulling a selector preserves the base */ +#define X86_BUG_SWAPGS_FENCE X86_BUG(11)/* SWAPGS without input dep on GS */ +#define X86_BUG_MONITOR X86_BUG(12)/* IPI required to wake up remote CPU */ #endif /* _ASM_X86_CPUFEATURES_H */
tools/arch/x86/include/asm/disabled-features.h +2 -0
@@ -56,5 +56,7 @@#define DISABLED_MASK14 0#define DISABLED_MASK15 0#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE) +#define DISABLED_MASK17 0 +#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)#endif /* _ASM_X86_DISABLED_FEATURES_H */
tools/arch/x86/include/asm/required-features.h +2 -0
@@ -99,5 +99,7 @@#define REQUIRED_MASK14 0#define REQUIRED_MASK15 0#define REQUIRED_MASK16 0 +#define REQUIRED_MASK17 0 +#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)#endif /* _ASM_X86_REQUIRED_FEATURES_H */
tools/arch/x86/include/uapi/asm/vmx.h +1 -3
@@ -78,7 +78,6 @@#define EXIT_REASON_PML_FULL 62#define EXIT_REASON_XSAVES 63#define EXIT_REASON_XRSTORS 64 -#define EXIT_REASON_PCOMMIT 65#define VMX_EXIT_REASONS \ { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
@@ -127,8 +126,7 @@ { EXIT_REASON_INVVPID, "INVVPID" }, \ { EXIT_REASON_INVPCID, "INVPCID" }, \ { EXIT_REASON_XSAVES, "XSAVES" }, \ - { EXIT_REASON_XRSTORS, "XRSTORS" }, \ - { EXIT_REASON_PCOMMIT, "PCOMMIT" } + { EXIT_REASON_XRSTORS, "XRSTORS" }#define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1#define VMX_ABORT_LOAD_HOST_MSR_FAIL 4
tools/include/uapi/linux/bpf.h +85 -1
116 lines not on this page · raw message
tools/perf/Documentation/perf-probe.txt +9 -1
@@ -176,10 +176,18 @@ Each probe argument follows below syntax. 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.) '$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters. -'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type. +'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail) On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid. +TYPES +----- +Basic types (u8/u16/u32/u64/s8/s16/s32/s64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe. +String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type. +Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is; + + b<bit-width>@<bit-offset>/<container-size> + LINE SYNTAX ----------- Line range is described by following syntax.
tools/perf/Documentation/perf-script.txt +2 -2
@@ -116,8 +116,8 @@ OPTIONS --fields:: Comma separated list of fields to print. Options are: comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, - srcline, period, iregs, brstack, brstacksym, flags. - Field list can be prepended with the type, trace, sw or hw, + srcline, period, iregs, brstack, brstacksym, flags, bpf-output, + callindent. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
tools/perf/arch/powerpc/util/sym-handling.c +23 -4
@@ -54,10 +54,6 @@ int arch__compare_symbol_names(const char *namea, const char *nameb)#endif #if defined(_CALL_ELF) && _CALL_ELF ==2 -bool arch__prefers_symtab (void ) -{ -return true; -}#ifdef HAVE_LIBELF_SUPPORT void arch__sym_update (struct symbol *s,GElf_Sym *sym)
@@ -100,4 +96,27 @@ void arch__fix_tev_from_maps(struct perf_probe_event *pev, tev->point.offset += lep_offset; } } + +void arch__post_process_probe_trace_events (struct perf_probe_event *pev, +int ntevs) +{ +struct probe_trace_event *tev; +struct map *map; +struct symbol *sym =NULL ; +struct rb_node *tmp; +int i =0 ; + + map =get_target_map (pev->target, pev->uprobes); +if (!map ||map__load (map,NULL ) <0 ) +return ; + +for (i =0 ; i < ntevs; i++) { + tev = &pev->tevs[i]; +map__for_each_symbol (map, sym, tmp) { +if (map->unmap_ip (map, sym->start) == tev->point.address) +arch__fix_tev_from_maps (pev, tev, map, sym); + } + } +} +#endif
tools/perf/builtin-script.c +1 -1
@@ -2116,7 +2116,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) "Valid types: hw,sw,trace,raw. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," "addr,symoff,period,iregs,brstack,brstacksym,flags," - "callindent", parse_output_fields), + "bpf-output,callindent", parse_output_fields),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide,"system-wide collection from all CPUs" ), OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
tools/perf/builtin-stat.c +23 -8
@@ -331,7 +331,7 @@ static int read_counter(struct perf_evsel *counter)return 0 ; } -static void read_counters (bool close_counters) +static void read_counters (void ) {struct perf_evsel *counter;
@@ -341,11 +341,6 @@ static void read_counters(bool close_counters)if (perf_stat_process_counter (&stat_config, counter))pr_warning ("failed to process counter %s\n" , counter->name); - -if (close_counters) { -perf_evsel__close_fd (counter,perf_evsel__nr_cpus (counter), -thread_map__nr (evsel_list->threads)); - } } }
@@ -353,7 +348,7 @@ static void process_interval(void) {struct timespec ts, rs; -read_counters (false); +read_counters ();clock_gettime (CLOCK_MONOTONIC , &ts);diff_timespec (&rs, &ts, &ref_time);
@@ -380,6 +375,17 @@ static void enable_counters(void)perf_evlist__enable (evsel_list); } +static void disable_counters (void ) +{ +/* +* If we don't have tracee (attaching to task or cpu), counters may +* still be running. To get accurate group ratios, we must stop groups +* from counting before reading their constituent counters. +*/ +if (!target__none (&target)) +perf_evlist__disable (evsel_list); +} +static volatile int workload_exec_errno;/*
@@ -657,11 +663,20 @@ static int __run_perf_stat(int argc, const char **argv) } } +disable_counters (); + t1 =rdclock ();update_stats (&walltime_nsecs_stats, t1 - t0); -read_counters (true); +/* +* Closing a group leader splits the group, and as we only disable +* group leaders, results in remaining events becoming enabled. To +* avoid arbitrary skew, we must read all counters before closing any +* group leaders. +*/ +read_counters (); +perf_evlist__close (evsel_list);return WEXITSTATUS (status); }
tools/perf/util/probe-event.c +37 -23
114 lines not on this page · raw message
tools/perf/util/probe-event.h +5 -1
@@ -158,7 +158,6 @@ int show_line_range(struct line_range *lr, const char *module, bool user);int show_available_vars (struct perf_probe_event *pevs,int npevs,struct strfilter *filter);int show_available_funcs (const char *module,struct strfilter *filter,bool user); -bool arch__prefers_symtab (void );void arch__fix_tev_from_maps (struct perf_probe_event *pev,struct probe_trace_event *tev,struct map *map,struct symbol *sym);
@@ -173,4 +172,9 @@ int e_snprintf(char *str, size_t size, const char *format, ...)int copy_to_probe_trace_arg (struct probe_trace_arg *tvar,struct perf_probe_arg *pvar); +struct map *get_target_map (const char *target,bool user); + +void arch__post_process_probe_trace_events (struct perf_probe_event *pev, +int ntevs); +#endif /*_PROBE_EVENT_H */
tools/perf/util/probe-finder.c +12 -3
@@ -297,10 +297,13 @@ static int convert_variable_type(Dwarf_Die *vr_die,char sbuf[STRERR_BUFSIZE ];int bsize, boffs, total;int ret; +char sign;/* TODO: check all types */ -if (cast &&strcmp (cast,"string" ) !=0 ) { +if (cast &&strcmp (cast,"string" ) !=0 && +strcmp (cast,"s" ) !=0 &&strcmp (cast,"u" ) !=0 ) {/* Non string type is OK */ +/* and respect signedness cast */ tvar->type =strdup (cast);return (tvar->type ==NULL ) ? -ENOMEM :0 ; }
@@ -361,6 +364,13 @@ static int convert_variable_type(Dwarf_Die *vr_die,return (tvar->type ==NULL ) ? -ENOMEM :0 ; } +if (cast && (strcmp (cast,"u" ) ==0 )) + sign ='u' ; +else if (cast && (strcmp (cast,"s" ) ==0 )) + sign ='s' ; +else + sign =die_is_signed_type (&type) ?'s' :'u' ; + ret =dwarf_bytesize (&type);if (ret <=0 )/* No size ... try to use default type */
@@ -373,8 +383,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, dwarf_diename(&type), MAX_BASIC_TYPE_BITS); ret =MAX_BASIC_TYPE_BITS ; } - ret =snprintf (buf,16 ,"%c%d" , -die_is_signed_type (&type) ?'s' :'u' , ret); + ret =snprintf (buf,16 ,"%c%d" , sign, ret); formatted:if (ret <0 || ret >=16 ) {
tools/perf/util/sort.c +5 -1
@@ -588,7 +588,11 @@ static char *get_trace_output(struct hist_entry *he) }else {pevent_event_info (&seq, evsel->tp_format, &rec); } -return seq.buffer; +/* +* Trim the buffer, it starts at 4KB and we're not going to +* add anything more to this buffer. +*/ +return realloc (seq.buffer, seq.len +1 ); } static int64_t