Skip to content

Commit 69766c4

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-urgent-for-mingo-20160809' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
Pull perf/urgent fixes from Arnaldo Carvalho de Melo: User visible fixes: - Fix the lookup for a kernel module in 'perf probe', fixing for instance, the erroneous return of "[raid10]" when looking for "[raid1]" (Konstantin Khlebnikov) - Disable counters in a group before reading them in 'perf stat', to avoid skew (Mark Rutland) - Fix adding probes to function aliases in systems using kaslr (Masami Hiramatsu) - Trip libtraceevent trace_seq buffers, removing unnecessary memory usage that could bring a system using tracepoint events with 'perf top' to a crawl, as the trace_seq buffers start at a whooping 4 KB, which is very rarely used in perf's usecases, so realloc it to the really used space as a last measure after using libtraceevent functions to format the fields of tracepoint events (Arnaldo Carvalho de Melo) - Fix 'perf probe' location when using DWARF on ppc64le (Ravi Bangoria) - Allow specifying signedness casts to a 'perf probe' variable, to shorten the number of steps to see signed values that otherwise would always appear as hex values (Naohiro Aota) Documentation fixes: - Add 'bpf-output' field to 'perf script' usage message (Brendan Gregg) Infrastructure fixes: - Sync kernel header files: cpufeatures.h, {disabled,required}-features.h, bpf.h and vmx.h, so that we get a clean build, without warnings about files being different from the kernel counterparts. A verification of the need or desirability of changes in tools/ based on what was done in the kernel changesets was made and documented in the respective file sync changesets (Arnaldo Carvalho de Melo) Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
2 parents 81abf25 + 99e608b commit 69766c4

File tree

14 files changed

+210
-54
lines changed

14 files changed

+210
-54
lines changed

tools/arch/x86/include/asm/cpufeatures.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@
225225
#define X86_FEATURE_RDSEED ( 9*32+18) /* The RDSEED instruction */
226226
#define X86_FEATURE_ADX ( 9*32+19) /* The ADCX and ADOX instructions */
227227
#define X86_FEATURE_SMAP ( 9*32+20) /* Supervisor Mode Access Prevention */
228-
#define X86_FEATURE_PCOMMIT ( 9*32+22) /* PCOMMIT instruction */
229228
#define X86_FEATURE_CLFLUSHOPT ( 9*32+23) /* CLFLUSHOPT instruction */
230229
#define X86_FEATURE_CLWB ( 9*32+24) /* CLWB instruction */
231230
#define X86_FEATURE_AVX512PF ( 9*32+26) /* AVX-512 Prefetch */
@@ -301,16 +300,14 @@
301300
#define X86_BUG_FXSAVE_LEAK X86_BUG(6) /* FXSAVE leaks FOP/FIP/FOP */
302301
#define X86_BUG_CLFLUSH_MONITOR X86_BUG(7) /* AAI65, CLFLUSH required before MONITOR */
303302
#define X86_BUG_SYSRET_SS_ATTRS X86_BUG(8) /* SYSRET doesn't fix up SS attrs */
304-
#define X86_BUG_NULL_SEG X86_BUG(9) /* Nulling a selector preserves the base */
305-
#define X86_BUG_SWAPGS_FENCE X86_BUG(10) /* SWAPGS without input dep on GS */
306-
307-
308303
#ifdef CONFIG_X86_32
309304
/*
310305
* 64-bit kernels don't use X86_BUG_ESPFIX. Make the define conditional
311306
* to avoid confusion.
312307
*/
313308
#define X86_BUG_ESPFIX X86_BUG(9) /* "" IRET to 16-bit SS corrupts ESP/RSP high bits */
314309
#endif
315-
310+
#define X86_BUG_NULL_SEG X86_BUG(10) /* Nulling a selector preserves the base */
311+
#define X86_BUG_SWAPGS_FENCE X86_BUG(11) /* SWAPGS without input dep on GS */
312+
#define X86_BUG_MONITOR X86_BUG(12) /* IPI required to wake up remote CPU */
316313
#endif /* _ASM_X86_CPUFEATURES_H */

tools/arch/x86/include/asm/disabled-features.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@
5656
#define DISABLED_MASK14 0
5757
#define DISABLED_MASK15 0
5858
#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE)
59+
#define DISABLED_MASK17 0
60+
#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
5961

6062
#endif /* _ASM_X86_DISABLED_FEATURES_H */

tools/arch/x86/include/asm/required-features.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,7 @@
9999
#define REQUIRED_MASK14 0
100100
#define REQUIRED_MASK15 0
101101
#define REQUIRED_MASK16 0
102+
#define REQUIRED_MASK17 0
103+
#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
102104

103105
#endif /* _ASM_X86_REQUIRED_FEATURES_H */

tools/arch/x86/include/uapi/asm/vmx.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
#define EXIT_REASON_PML_FULL 62
7979
#define EXIT_REASON_XSAVES 63
8080
#define EXIT_REASON_XRSTORS 64
81-
#define EXIT_REASON_PCOMMIT 65
8281

8382
#define VMX_EXIT_REASONS \
8483
{ EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
@@ -127,8 +126,7 @@
127126
{ EXIT_REASON_INVVPID, "INVVPID" }, \
128127
{ EXIT_REASON_INVPCID, "INVPCID" }, \
129128
{ EXIT_REASON_XSAVES, "XSAVES" }, \
130-
{ EXIT_REASON_XRSTORS, "XRSTORS" }, \
131-
{ EXIT_REASON_PCOMMIT, "PCOMMIT" }
129+
{ EXIT_REASON_XRSTORS, "XRSTORS" }
132130

133131
#define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1
134132
#define VMX_ABORT_LOAD_HOST_MSR_FAIL 4

tools/include/uapi/linux/bpf.h

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ enum bpf_map_type {
8484
BPF_MAP_TYPE_PERCPU_HASH,
8585
BPF_MAP_TYPE_PERCPU_ARRAY,
8686
BPF_MAP_TYPE_STACK_TRACE,
87+
BPF_MAP_TYPE_CGROUP_ARRAY,
8788
};
8889

8990
enum bpf_prog_type {
@@ -93,6 +94,7 @@ enum bpf_prog_type {
9394
BPF_PROG_TYPE_SCHED_CLS,
9495
BPF_PROG_TYPE_SCHED_ACT,
9596
BPF_PROG_TYPE_TRACEPOINT,
97+
BPF_PROG_TYPE_XDP,
9698
};
9799

98100
#define BPF_PSEUDO_MAP_FD 1
@@ -313,6 +315,66 @@ enum bpf_func_id {
313315
*/
314316
BPF_FUNC_skb_get_tunnel_opt,
315317
BPF_FUNC_skb_set_tunnel_opt,
318+
319+
/**
320+
* bpf_skb_change_proto(skb, proto, flags)
321+
* Change protocol of the skb. Currently supported is
322+
* v4 -> v6, v6 -> v4 transitions. The helper will also
323+
* resize the skb. eBPF program is expected to fill the
324+
* new headers via skb_store_bytes and lX_csum_replace.
325+
* @skb: pointer to skb
326+
* @proto: new skb->protocol type
327+
* @flags: reserved
328+
* Return: 0 on success or negative error
329+
*/
330+
BPF_FUNC_skb_change_proto,
331+
332+
/**
333+
* bpf_skb_change_type(skb, type)
334+
* Change packet type of skb.
335+
* @skb: pointer to skb
336+
* @type: new skb->pkt_type type
337+
* Return: 0 on success or negative error
338+
*/
339+
BPF_FUNC_skb_change_type,
340+
341+
/**
342+
* bpf_skb_in_cgroup(skb, map, index) - Check cgroup2 membership of skb
343+
* @skb: pointer to skb
344+
* @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
345+
* @index: index of the cgroup in the bpf_map
346+
* Return:
347+
* == 0 skb failed the cgroup2 descendant test
348+
* == 1 skb succeeded the cgroup2 descendant test
349+
* < 0 error
350+
*/
351+
BPF_FUNC_skb_in_cgroup,
352+
353+
/**
354+
* bpf_get_hash_recalc(skb)
355+
* Retrieve and possibly recalculate skb->hash.
356+
* @skb: pointer to skb
357+
* Return: hash
358+
*/
359+
BPF_FUNC_get_hash_recalc,
360+
361+
/**
362+
* u64 bpf_get_current_task(void)
363+
* Returns current task_struct
364+
* Return: current
365+
*/
366+
BPF_FUNC_get_current_task,
367+
368+
/**
369+
* bpf_probe_write_user(void *dst, void *src, int len)
370+
* safely attempt to write to a location
371+
* @dst: destination address in userspace
372+
* @src: source address on stack
373+
* @len: number of bytes to copy
374+
* Return: 0 on success or negative error
375+
*/
376+
BPF_FUNC_probe_write_user,
377+
316378
__BPF_FUNC_MAX_ID,
317379
};
318380

@@ -347,9 +409,11 @@ enum bpf_func_id {
347409
#define BPF_F_ZERO_CSUM_TX (1ULL << 1)
348410
#define BPF_F_DONT_FRAGMENT (1ULL << 2)
349411

350-
/* BPF_FUNC_perf_event_output flags. */
412+
/* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */
351413
#define BPF_F_INDEX_MASK 0xffffffffULL
352414
#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
415+
/* BPF_FUNC_perf_event_output for sk_buff input context. */
416+
#define BPF_F_CTXLEN_MASK (0xfffffULL << 32)
353417

354418
/* user accessible mirror of in-kernel sk_buff.
355419
* new fields can only be added to the end of this structure
@@ -386,4 +450,24 @@ struct bpf_tunnel_key {
386450
__u32 tunnel_label;
387451
};
388452

453+
/* User return codes for XDP prog type.
454+
* A valid XDP program must return one of these defined values. All other
455+
* return codes are reserved for future use. Unknown return codes will result
456+
* in packet drop.
457+
*/
458+
enum xdp_action {
459+
XDP_ABORTED = 0,
460+
XDP_DROP,
461+
XDP_PASS,
462+
XDP_TX,
463+
};
464+
465+
/* user accessible metadata for XDP packet hook
466+
* new fields must be added to the end of this structure
467+
*/
468+
struct xdp_md {
469+
__u32 data;
470+
__u32 data_end;
471+
};
472+
389473
#endif /* _UAPI__LINUX_BPF_H__ */

tools/perf/Documentation/perf-probe.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,18 @@ Each probe argument follows below syntax.
176176

177177
'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'.)
178178
'$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.
179-
'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.
179+
'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)
180180

181181
On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
182182

183+
TYPES
184+
-----
185+
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.
186+
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.
187+
Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
188+
189+
b<bit-width>@<bit-offset>/<container-size>
190+
183191
LINE SYNTAX
184192
-----------
185193
Line range is described by following syntax.

tools/perf/Documentation/perf-script.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ OPTIONS
116116
--fields::
117117
Comma separated list of fields to print. Options are:
118118
comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
119-
srcline, period, iregs, brstack, brstacksym, flags.
120-
Field list can be prepended with the type, trace, sw or hw,
119+
srcline, period, iregs, brstack, brstacksym, flags, bpf-output,
120+
callindent. Field list can be prepended with the type, trace, sw or hw,
121121
to indicate to which event type the field list applies.
122122
e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
123123

tools/perf/arch/powerpc/util/sym-handling.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ int arch__compare_symbol_names(const char *namea, const char *nameb)
5454
#endif
5555

5656
#if defined(_CALL_ELF) && _CALL_ELF == 2
57-
bool arch__prefers_symtab(void)
58-
{
59-
return true;
60-
}
6157

6258
#ifdef HAVE_LIBELF_SUPPORT
6359
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,
10096
tev->point.offset += lep_offset;
10197
}
10298
}
99+
100+
void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
101+
int ntevs)
102+
{
103+
struct probe_trace_event *tev;
104+
struct map *map;
105+
struct symbol *sym = NULL;
106+
struct rb_node *tmp;
107+
int i = 0;
108+
109+
map = get_target_map(pev->target, pev->uprobes);
110+
if (!map || map__load(map, NULL) < 0)
111+
return;
112+
113+
for (i = 0; i < ntevs; i++) {
114+
tev = &pev->tevs[i];
115+
map__for_each_symbol(map, sym, tmp) {
116+
if (map->unmap_ip(map, sym->start) == tev->point.address)
117+
arch__fix_tev_from_maps(pev, tev, map, sym);
118+
}
119+
}
120+
}
121+
103122
#endif

tools/perf/builtin-script.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
21162116
"Valid types: hw,sw,trace,raw. "
21172117
"Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
21182118
"addr,symoff,period,iregs,brstack,brstacksym,flags,"
2119-
"callindent", parse_output_fields),
2119+
"bpf-output,callindent", parse_output_fields),
21202120
OPT_BOOLEAN('a', "all-cpus", &system_wide,
21212121
"system-wide collection from all CPUs"),
21222122
OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",

tools/perf/builtin-stat.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static int read_counter(struct perf_evsel *counter)
331331
return 0;
332332
}
333333

334-
static void read_counters(bool close_counters)
334+
static void read_counters(void)
335335
{
336336
struct perf_evsel *counter;
337337

@@ -341,19 +341,14 @@ static void read_counters(bool close_counters)
341341

342342
if (perf_stat_process_counter(&stat_config, counter))
343343
pr_warning("failed to process counter %s\n", counter->name);
344-
345-
if (close_counters) {
346-
perf_evsel__close_fd(counter, perf_evsel__nr_cpus(counter),
347-
thread_map__nr(evsel_list->threads));
348-
}
349344
}
350345
}
351346

352347
static void process_interval(void)
353348
{
354349
struct timespec ts, rs;
355350

356-
read_counters(false);
351+
read_counters();
357352

358353
clock_gettime(CLOCK_MONOTONIC, &ts);
359354
diff_timespec(&rs, &ts, &ref_time);
@@ -380,6 +375,17 @@ static void enable_counters(void)
380375
perf_evlist__enable(evsel_list);
381376
}
382377

378+
static void disable_counters(void)
379+
{
380+
/*
381+
* If we don't have tracee (attaching to task or cpu), counters may
382+
* still be running. To get accurate group ratios, we must stop groups
383+
* from counting before reading their constituent counters.
384+
*/
385+
if (!target__none(&target))
386+
perf_evlist__disable(evsel_list);
387+
}
388+
383389
static volatile int workload_exec_errno;
384390

385391
/*
@@ -657,11 +663,20 @@ static int __run_perf_stat(int argc, const char **argv)
657663
}
658664
}
659665

666+
disable_counters();
667+
660668
t1 = rdclock();
661669

662670
update_stats(&walltime_nsecs_stats, t1 - t0);
663671

664-
read_counters(true);
672+
/*
673+
* Closing a group leader splits the group, and as we only disable
674+
* group leaders, results in remaining events becoming enabled. To
675+
* avoid arbitrary skew, we must read all counters before closing any
676+
* group leaders.
677+
*/
678+
read_counters();
679+
perf_evlist__close(evsel_list);
665680

666681
return WEXITSTATUS(status);
667682
}

0 commit comments

Comments
 (0)