History

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 is mostly tooling fixes, plus an instruction pointer filtering fix. It's more fixes than usual - Arnaldo got back from a longer vacation and there was a backlog" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (27 commits) perf symbols: Kill dso__build_id_is_kmod() perf symbols: Keep DSO->symtab_type after decompress perf tests: Decompress kernel module before objdump perf tools: Consolidate error path in __open_dso() perf tools: Decompress kernel module when reading DSO data perf annotate: Use dso__decompress_kmodule_path() perf tools: Introduce dso__decompress_kmodule_{fd,path} perf tools: Fix a memory leak in __open_dso() perf annotate: Fix symbolic link of build-id cache perf/core: Drop kernel samples even though :u is specified perf script python: Remove dups in documentation examples perf script python: Updated trace_unhandled() signature perf script python: Fix wrong code snippets in documentation perf script: Fix documentation errors perf script: Fix outdated comment for perf-trace-python perf probe: Fix examples section of documentation perf report: Ensure the perf DSO mapping matches what libdw sees perf report: Include partial stacks unwound with libdw perf annotate: Add missing powerpc triplet perf test: Disable breakpoint signal tests for powerpc ...

Linus Torvalds committed 9 years ago

Commit f701d862 parents 9376906 47c1ded22 files · +259 −156Browse files

Unified · Split

22 files
  1. kernel/events/core.c +21 −0
  2. tools/perf/Documentation/perf-probe.txt +6 −2
  3. tools/perf/Documentation/perf-script-perl.txt +1 −1
  4. tools/perf/Documentation/perf-script-python.txt +9 −14
  5. tools/perf/arch/common.c +1 −0
  6. tools/perf/builtin-stat.c +4 −1
  7. tools/perf/builtin-trace.c +4 −0
  8. tools/perf/tests/bp_signal.c +14 −0
  9. tools/perf/tests/builtin-test.c +7 −0
  10. tools/perf/tests/code-reading.c +19 −1
  11. tools/perf/tests/tests.h +3 −0
  12. tools/perf/util/annotate.c +43 −29
  13. tools/perf/util/build-id.c +0 −45
  14. tools/perf/util/build-id.h +0 −1
  15. tools/perf/util/dso.c +94 −6
  16. tools/perf/util/dso.h +9 −0
  17. tools/perf/util/header.c +10 −2
  18. tools/perf/util/machine.c +1 −10
  19. tools/perf/util/scripting-engines/trace-event-python.c +1 −1
  20. tools/perf/util/symbol-elf.c +3 −38
  21. tools/perf/util/symbol.c +0 −4
  22. tools/perf/util/unwind-libdw.c +9 −1
kernel/events/core.c+21−0
@@ -7316,6 +7316,21 @@ int perf_event_account_interrupt(struct perf_event *event) · 7315 unmodified lines
73167316 return __perf_event_account_interrupt(event, 1);
73177317 }
73187318
7319+static bool sample_is_allowed(struct perf_event *event, struct pt_regs *regs)
7320+{
7321+ /*
7322+ * Due to interrupt latency (AKA "skid"), we may enter the
7323+ * kernel before taking an overflow, even if the PMU is only
7324+ * counting user events.
7325+ * To avoid leaking information to userspace, we must always
7326+ * reject kernel samples when exclude_kernel is set.
7327+ */
7328+ if (event->attr.exclude_kernel && !user_mode(regs))
7329+ return false;
7330+
7331+ return true;
7332+}
7333+
73197334 /*
73207335 * Generic event overflow handling, sampling.
73217336 */
@@ -7336,6 +7351,12 @@ static int __perf_event_overflow(struct perf_event *event, · 14 unmodified lines
73367351
73377352 ret = __perf_event_account_interrupt(event, throttle);
73387353
7354+ /*
7355+ * For security, drop the skid kernel samples if necessary.
7356+ */
7357+ if (!sample_is_allowed(event, regs))
7358+ return ret;
7359+
73397360 /*
73407361 * XXX event_limit might not quite work as expected on inherited
73417362 * events
tools/perf/Documentation/perf-probe.txt+6−2
@@ -240,9 +240,13 @@ Add a probe on schedule() function 12th line with recording cpu local variable: · 239 unmodified lines
240240 or
241241 ./perf probe --add='schedule:12 cpu'
242242
243− this will add one or more probes which has the name start with "schedule".
243+Add one or more probes which has the name start with "schedule".
244244
245− Add probes on lines in schedule() function which calls update_rq_clock().
245+ ./perf probe schedule*
246+ or
247+ ./perf probe --add='schedule*'
248+
249+Add probes on lines in schedule() function which calls update_rq_clock().
246250
247251 ./perf probe 'schedule;update_rq_clock*'
248252 or
tools/perf/Documentation/perf-script-perl.txt+1−1
@@ -39,7 +39,7 @@ EVENT HANDLERS · 38 unmodified lines
3939 When perf script is invoked using a trace script, a user-defined
4040 'handler function' is called for each event in the trace. If there's
4141 no handler function defined for a given event type, the event is
42−ignored (or passed to a 'trace_handled' function, see below) and the
42+ignored (or passed to a 'trace_unhandled' function, see below) and the
4343 next event is processed.
4444
4545 Most of the event's field values are passed as arguments to the
tools/perf/Documentation/perf-script-python.txt+9−14
@@ -149,10 +149,8 @@ def raw_syscalls__sys_enter(event_name, context, common_cpu, · 148 unmodified lines
149149 print "id=%d, args=%s\n" % \
150150 (id, args),
151151
152−def trace_unhandled(event_name, context, common_cpu, common_secs, common_nsecs,
153− common_pid, common_comm):
154− print_header(event_name, common_cpu, common_secs, common_nsecs,
155− common_pid, common_comm)
152+def trace_unhandled(event_name, context, event_fields_dict):
153+ print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
156154
157155 def print_header(event_name, cpu, secs, nsecs, pid, comm):
158156 print "%-20s %5u %05u.%09u %8u %-20s " % \
@@ -321,7 +319,7 @@ So those are the essential steps in writing and running a script. The · 162 unmodified lines
321319 process can be generalized to any tracepoint or set of tracepoints
322320 you're interested in - basically find the tracepoint(s) you're
323321 interested in by looking at the list of available events shown by
324−'perf list' and/or look in /sys/kernel/debug/tracing events for
322+'perf list' and/or look in /sys/kernel/debug/tracing/events/ for
325323 detailed event and field info, record the corresponding trace data
326324 using 'perf record', passing it the list of interesting events,
327325 generate a skeleton script using 'perf script -g python' and modify the
@@ -334,7 +332,7 @@ right place, you can have your script listed alongside the other · 6 unmodified lines
334332 scripts listed by the 'perf script -l' command e.g.:
335333
336334 ----
337−root@tropicana:~# perf script -l
335+# perf script -l
338336 List of available trace scripts:
339337 wakeup-latency system-wide min/max/avg wakeup latency
340338 rw-by-file <comm> r/w activity for a program, by file
@@ -383,8 +381,6 @@ source tree: · 42 unmodified lines
383381
384382 ----
385383 # ls -al kernel-source/tools/perf/scripts/python
386−
387−root@tropicana:/home/trz/src/tip# ls -al tools/perf/scripts/python
388384 total 32
389385 drwxr-xr-x 4 trz trz 4096 2010-01-26 22:30 .
390386 drwxr-xr-x 4 trz trz 4096 2010-01-26 22:29 ..
@@ -399,7 +395,7 @@ otherwise your script won't show up at run-time), 'perf script -l' · 8 unmodified lines
399395 should show a new entry for your script:
400396
401397 ----
402−root@tropicana:~# perf script -l
398+# perf script -l
403399 List of available trace scripts:
404400 wakeup-latency system-wide min/max/avg wakeup latency
405401 rw-by-file <comm> r/w activity for a program, by file
@@ -437,7 +433,7 @@ EVENT HANDLERS · 31 unmodified lines
437433 When perf script is invoked using a trace script, a user-defined
438434 'handler function' is called for each event in the trace. If there's
439435 no handler function defined for a given event type, the event is
440−ignored (or passed to a 'trace_handled' function, see below) and the
436+ignored (or passed to a 'trace_unhandled' function, see below) and the
441437 next event is processed.
442438
443439 Most of the event's field values are passed as arguments to the
@@ -532,7 +528,7 @@ can implement a set of optional functions: · 88 unmodified lines
532528 gives scripts a chance to do setup tasks:
533529
534530 ----
535−def trace_begin:
531+def trace_begin():
536532 pass
537533 ----
538534
@@ -541,7 +537,7 @@ def trace_begin: · 2 unmodified lines
541537 as display results:
542538
543539 ----
544−def trace_end:
540+def trace_end():
545541 pass
546542 ----
547543
@@ -550,8 +546,7 @@ def trace_end: · 2 unmodified lines
550546 of common arguments are passed into it:
551547
552548 ----
553−def trace_unhandled(event_name, context, common_cpu, common_secs,
554− common_nsecs, common_pid, common_comm):
549+def trace_unhandled(event_name, context, event_fields_dict):
555550 pass
556551 ----
557552
tools/perf/arch/common.c+1−0
@@ -26,6 +26,7 @@ const char *const arm64_triplets[] = { · 25 unmodified lines
2626
2727 const char *const powerpc_triplets[] = {
2828 "powerpc-unknown-linux-gnu-",
29+ "powerpc-linux-gnu-",
2930 "powerpc64-unknown-linux-gnu-",
3031 "powerpc64-linux-gnu-",
3132 "powerpc64le-linux-gnu-",
tools/perf/builtin-stat.c+4−1
@@ -1578,6 +1578,7 @@ static void print_header(int argc, const char **argv) · 1577 unmodified lines
15781578 static void print_footer(void)
15791579 {
15801580 FILE *output = stat_config.output;
1581+ int n;
15811582
15821583 if (!null_run)
15831584 fprintf(output, "\n");
@@ -1590,7 +1591,9 @@ static void print_footer(void) · 6 unmodified lines
15901591 }
15911592 fprintf(output, "\n\n");
15921593
1593− if (print_free_counters_hint)
1594+ if (print_free_counters_hint &&
1595+ sysctl__read_int("kernel/nmi_watchdog", &n) >= 0 &&
1596+ n > 0)
15941597 fprintf(output,
15951598 "Some events weren't counted. Try disabling the NMI watchdog:\n"
15961599 " echo 0 > /proc/sys/kernel/nmi_watchdog\n"
tools/perf/builtin-trace.c+4−0
@@ -681,6 +681,10 @@ static struct syscall_fmt { · 680 unmodified lines
681681 { .name = "mlockall", .errmsg = true,
682682 .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, },
683683 { .name = "mmap", .hexret = true,
684+/* The standard mmap maps to old_mmap on s390x */
685+#if defined(__s390x__)
686+ .alias = "old_mmap",
687+#endif
684688 .arg_scnprintf = { [0] = SCA_HEX, /* addr */
685689 [2] = SCA_MMAP_PROT, /* prot */
686690 [3] = SCA_MMAP_FLAGS, /* flags */ }, },
tools/perf/tests/bp_signal.c+14−0
@@ -288,3 +288,17 @@ int test__bp_signal(int subtest __maybe_unused) · 287 unmodified lines
288288 return count1 == 1 && overflows == 3 && count2 == 3 && overflows_2 == 3 && count3 == 2 ?
289289 TEST_OK : TEST_FAIL;
290290 }
291+
292+bool test__bp_signal_is_supported(void)
293+{
294+/*
295+ * The powerpc so far does not have support to even create
296+ * instruction breakpoint using the perf event interface.
297+ * Once it's there we can release this.
298+ */
299+#ifdef __powerpc__
300+ return false;
301+#else
302+ return true;
303+#endif
304+}
tools/perf/tests/builtin-test.c+7−0
@@ -97,10 +97,12 @@ static struct test generic_tests[] = { · 96 unmodified lines
9797 {
9898 .desc = "Breakpoint overflow signal handler",
9999 .func = test__bp_signal,
100+ .is_supported = test__bp_signal_is_supported,
100101 },
101102 {
102103 .desc = "Breakpoint overflow sampling",
103104 .func = test__bp_signal_overflow,
105+ .is_supported = test__bp_signal_is_supported,
104106 },
105107 {
106108 .desc = "Number of exit events of a simple workload",
@@ -401,6 +403,11 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) · 294 unmodified lines
401403 if (!perf_test__matches(t, curr, argc, argv))
402404 continue;
403405
406+ if (t->is_supported && !t->is_supported()) {
407+ pr_debug("%2d: %-*s: Disabled\n", i, width, t->desc);
408+ continue;
409+ }
410+
404411 pr_info("%2d: %-*s:", i, width, t->desc);
405412
406413 if (intlist__find(skiplist, i)) {
tools/perf/tests/code-reading.c+19−1
@@ -229,6 +229,8 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, · 228 unmodified lines
229229 unsigned char buf2[BUFSZ];
230230 size_t ret_len;
231231 u64 objdump_addr;
232+ const char *objdump_name;
233+ char decomp_name[KMOD_DECOMP_LEN];
232234 int ret;
233235
234236 pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
@@ -289,9 +291,25 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, · 54 unmodified lines
289291 state->done[state->done_cnt++] = al.map->start;
290292 }
291293
294+ objdump_name = al.map->dso->long_name;
295+ if (dso__needs_decompress(al.map->dso)) {
296+ if (dso__decompress_kmodule_path(al.map->dso, objdump_name,
297+ decomp_name,
298+ sizeof(decomp_name)) < 0) {
299+ pr_debug("decompression failed\n");
300+ return -1;
301+ }
302+
303+ objdump_name = decomp_name;
304+ }
305+
292306 /* Read the object code using objdump */
293307 objdump_addr = map__rip_2objdump(al.map, al.addr);
294− ret = read_via_objdump(al.map->dso->long_name, objdump_addr, buf2, len);
308+ ret = read_via_objdump(objdump_name, objdump_addr, buf2, len);
309+
310+ if (dso__needs_decompress(al.map->dso))
311+ unlink(objdump_name);
312+
295313 if (ret > 0) {
296314 /*
297315 * The kernel maps are inaccurate - assume objdump is right in
tools/perf/tests/tests.h+3−0
@@ -34,6 +34,7 @@ struct test { · 33 unmodified lines
3434 int (*get_nr)(void);
3535 const char *(*get_desc)(int subtest);
3636 } subtest;
37+ bool (*is_supported)(void);
3738 };
3839
3940 /* Tests */
@@ -99,6 +100,8 @@ const char *test__clang_subtest_get_desc(int subtest); · 59 unmodified lines
99100 int test__clang_subtest_get_nr(void);
100101 int test__unit_number__scnprint(int subtest);
101102
103+bool test__bp_signal_is_supported(void);
104+
102105 #if defined(__arm__) || defined(__aarch64__)
103106 #ifdef HAVE_DWARF_UNWIND_SUPPORT
104107 struct thread;
tools/perf/util/annotate.c+43−29
@@ -239,10 +239,20 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op · 238 unmodified lines
239239 const char *s = strchr(ops->raw, '+');
240240 const char *c = strchr(ops->raw, ',');
241241
242− if (c++ != NULL)
242+ /*
243+ * skip over possible up to 2 operands to get to address, e.g.:
244+ * tbnz w0, #26, ffff0000083cd190 <security_file_permission+0xd0>
245+ */
246+ if (c++ != NULL) {
243247 ops->target.addr = strtoull(c, NULL, 16);
244− else
248+ if (!ops->target.addr) {
249+ c = strchr(c, ',');
250+ if (c++ != NULL)
251+ ops->target.addr = strtoull(c, NULL, 16);
252+ }
253+ } else {
245254 ops->target.addr = strtoull(ops->raw, NULL, 16);
255+ }
246256
247257 if (s++ != NULL) {
248258 ops->target.offset = strtoull(s, NULL, 16);
@@ -257,10 +267,27 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op · 8 unmodified lines
257267 static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
258268 struct ins_operands *ops)
259269 {
270+ const char *c = strchr(ops->raw, ',');
271+
260272 if (!ops->target.addr || ops->target.offset < 0)
261273 return ins__raw_scnprintf(ins, bf, size, ops);
262274
263− return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, ops->target.offset);
275+ if (c != NULL) {
276+ const char *c2 = strchr(c + 1, ',');
277+
278+ /* check for 3-op insn */
279+ if (c2 != NULL)
280+ c = c2;
281+ c++;
282+
283+ /* mirror arch objdump's space-after-comma style */
284+ if (*c == ' ')
285+ c++;
286+ }
287+
288+ return scnprintf(bf, size, "%-6.6s %.*s%" PRIx64,
289+ ins->name, c ? c - ops->raw : 0, ops->raw,
290+ ops->target.offset);
264291 }
265292
266293 static struct ins_ops jump_ops = {
@@ -1294,6 +1321,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil · 1027 unmodified lines
12941321 char linkname[PATH_MAX];
12951322 char *build_id_filename;
12961323 char *build_id_path = NULL;
1324+ char *pos;
12971325
12981326 if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
12991327 !dso__is_kcore(dso))
@@ -1313,7 +1341,14 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil · 13 unmodified lines
13131341 if (!build_id_path)
13141342 return -1;
13151343
1316− dirname(build_id_path);
1344+ /*
1345+ * old style build-id cache has name of XX/XXXXXXX.. while
1346+ * new style has XX/XXXXXXX../{elf,kallsyms,vdso}.
1347+ * extract the build-id part of dirname in the new style only.
1348+ */
1349+ pos = strrchr(build_id_path, '/');
1350+ if (pos && strlen(pos) < SBUILD_ID_SIZE - 2)
1351+ dirname(build_id_path);
13171352
13181353 if (dso__is_kcore(dso) ||
13191354 readlink(build_id_path, linkname, sizeof(linkname)) < 0 ||
@@ -1396,31 +1431,10 @@ int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_na · 76 unmodified lines
13961431 sizeof(symfs_filename));
13971432 }
13981433 } else if (dso__needs_decompress(dso)) {
1399− char tmp[PATH_MAX];
1400− struct kmod_path m;
1401− int fd;
1402− bool ret;
1403−
1404− if (kmod_path__parse_ext(&m, symfs_filename))
1405− goto out;
1406−
1407− snprintf(tmp, PATH_MAX, "/tmp/perf-kmod-XXXXXX");
1408−
1409− fd = mkstemp(tmp);
1410− if (fd < 0) {
1411− free(m.ext);
1412− goto out;
1413− }
1414−
1415− ret = decompress_to_file(m.ext, symfs_filename, fd);
1416−
1417− if (ret)
1418− pr_err("Cannot decompress %s %s\n", m.ext, symfs_filename);
1419−
1420− free(m.ext);
1421− close(fd);
1434+ char tmp[KMOD_DECOMP_LEN];
14221435
1423− if (!ret)
1436+ if (dso__decompress_kmodule_path(dso, symfs_filename,
1437+ tmp, sizeof(tmp)) < 0)
14241438 goto out;
14251439
14261440 strcpy(symfs_filename, tmp);
@@ -1429,7 +1443,7 @@ int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_na · 2 unmodified lines
14291443 snprintf(command, sizeof(command),
14301444 "%s %s%s --start-address=0x%016" PRIx64
14311445 " --stop-address=0x%016" PRIx64
1432− " -l -d %s %s -C %s 2>/dev/null|grep -v %s:|expand",
1446+ " -l -d %s %s -C \"%s\" 2>/dev/null|grep -v \"%s:\"|expand",
14331447 objdump_path ? objdump_path : "objdump",
14341448 disassembler_style ? "-M " : "",
14351449 disassembler_style ? disassembler_style : "",
tools/perf/util/build-id.c+0−45
@@ -278,51 +278,6 @@ char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size) · 277 unmodified lines
278278 return bf;
279279 }
280280
281−bool dso__build_id_is_kmod(const struct dso *dso, char *bf, size_t size)
282−{
283− char *id_name = NULL, *ch;
284− struct stat sb;
285− char sbuild_id[SBUILD_ID_SIZE];
286−
287− if (!dso->has_build_id)
288− goto err;
289−
290− build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
291− id_name = build_id_cache__linkname(sbuild_id, NULL, 0);
292− if (!id_name)
293− goto err;
294− if (access(id_name, F_OK))
295− goto err;
296− if (lstat(id_name, &sb) == -1)
297− goto err;
298− if ((size_t)sb.st_size > size - 1)
299− goto err;
300− if (readlink(id_name, bf, size - 1) < 0)
301− goto err;
302−
303− bf[sb.st_size] = '\0';
304−
305− /*
306− * link should be:
307− * ../../lib/modules/4.4.0-rc4/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko/a09fe3eb3147dafa4e3b31dbd6257e4d696bdc92
308− */
309− ch = strrchr(bf, '/');
310− if (!ch)
311− goto err;
312− if (ch - 3 < bf)
313− goto err;
314−
315− free(id_name);
316− return strncmp(".ko", ch - 3, 3) == 0;
317−err:
318− pr_err("Invalid build id: %s\n", id_name ? :
319− dso->long_name ? :
320− dso->short_name ? :
321− "[unknown]");
322− free(id_name);
323− return false;
324−}
325−
326281 #define dsos__for_each_with_build_id(pos, head) \
327282 list_for_each_entry(pos, head, node) \
328283 if (!pos->has_build_id) \
tools/perf/util/build-id.h+0−1
@@ -17,7 +17,6 @@ char *build_id_cache__kallsyms_path(const char *sbuild_id, char *bf, · 16 unmodified lines
1717 size_t size);
1818
1919 char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size);
20−bool dso__build_id_is_kmod(const struct dso *dso, char *bf, size_t size);
2120
2221 int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event,
2322 struct perf_sample *sample, struct perf_evsel *evsel,
tools/perf/util/dso.c+94−6
@@ -248,6 +248,64 @@ bool dso__needs_decompress(struct dso *dso) · 247 unmodified lines
248248 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
249249 }
250250
251+static int decompress_kmodule(struct dso *dso, const char *name, char *tmpbuf)
252+{
253+ int fd = -1;
254+ struct kmod_path m;
255+
256+ if (!dso__needs_decompress(dso))
257+ return -1;
258+
259+ if (kmod_path__parse_ext(&m, dso->long_name))
260+ return -1;
261+
262+ if (!m.comp)
263+ goto out;
264+
265+ fd = mkstemp(tmpbuf);
266+ if (fd < 0) {
267+ dso->load_errno = errno;
268+ goto out;
269+ }
270+
271+ if (!decompress_to_file(m.ext, name, fd)) {
272+ dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE;
273+ close(fd);
274+ fd = -1;
275+ }
276+
277+out:
278+ free(m.ext);
279+ return fd;
280+}
281+
282+int dso__decompress_kmodule_fd(struct dso *dso, const char *name)
283+{
284+ char tmpbuf[] = KMOD_DECOMP_NAME;
285+ int fd;
286+
287+ fd = decompress_kmodule(dso, name, tmpbuf);
288+ unlink(tmpbuf);
289+ return fd;
290+}
291+
292+int dso__decompress_kmodule_path(struct dso *dso, const char *name,
293+ char *pathname, size_t len)
294+{
295+ char tmpbuf[] = KMOD_DECOMP_NAME;
296+ int fd;
297+
298+ fd = decompress_kmodule(dso, name, tmpbuf);
299+ if (fd < 0) {
300+ unlink(tmpbuf);
301+ return -1;
302+ }
303+
304+ strncpy(pathname, tmpbuf, len);
305+ close(fd);
306+ return 0;
307+}
308+
251309 /*
252310 * Parses kernel module specified in @path and updates
253311 * @m argument like:
@@ -335,6 +393,21 @@ int __kmod_path__parse(struct kmod_path *m, const char *path, · 81 unmodified lines
335393 return 0;
336394 }
337395
396+void dso__set_module_info(struct dso *dso, struct kmod_path *m,
397+ struct machine *machine)
398+{
399+ if (machine__is_host(machine))
400+ dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
401+ else
402+ dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
403+
404+ /* _KMODULE_COMP should be next to _KMODULE */
405+ if (m->kmod && m->comp)
406+ dso->symtab_type++;
407+
408+ dso__set_short_name(dso, strdup(m->name), true);
409+}
410+
338411 /*
339412 * Global list of open DSOs and the counter.
340413 */
@@ -381,7 +454,7 @@ static int do_open(char *name) · 40 unmodified lines
381454
382455 static int __open_dso(struct dso *dso, struct machine *machine)
383456 {
384− int fd;
457+ int fd = -EINVAL;
385458 char *root_dir = (char *)"";
386459 char *name = malloc(PATH_MAX);
387460
@@ -392,15 +465,30 @@ static int __open_dso(struct dso *dso, struct machine *machine) · 4 unmodified lines
392465 root_dir = machine->root_dir;
393466
394467 if (dso__read_binary_type_filename(dso, dso->binary_type,
395− root_dir, name, PATH_MAX)) {
396− free(name);
397− return -EINVAL;
398− }
468+ root_dir, name, PATH_MAX))
469+ goto out;
399470
400471 if (!is_regular_file(name))
401− return -EINVAL;
472+ goto out;
473+
474+ if (dso__needs_decompress(dso)) {
475+ char newpath[KMOD_DECOMP_LEN];
476+ size_t len = sizeof(newpath);
477+
478+ if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
479+ fd = -dso->load_errno;
480+ goto out;
481+ }
482+
483+ strcpy(name, newpath);
484+ }
402485
403486 fd = do_open(name);
487+
488+ if (dso__needs_decompress(dso))
489+ unlink(name);
490+
491+out:
404492 free(name);
405493 return fd;
406494 }
tools/perf/util/dso.h+9−0
@@ -244,6 +244,12 @@ bool is_supported_compression(const char *ext); · 243 unmodified lines
244244 bool is_kernel_module(const char *pathname, int cpumode);
245245 bool decompress_to_file(const char *ext, const char *filename, int output_fd);
246246 bool dso__needs_decompress(struct dso *dso);
247+int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
248+int dso__decompress_kmodule_path(struct dso *dso, const char *name,
249+ char *pathname, size_t len);
250+
251+#define KMOD_DECOMP_NAME "/tmp/perf-kmod-XXXXXX"
252+#define KMOD_DECOMP_LEN sizeof(KMOD_DECOMP_NAME)
247253
248254 struct kmod_path {
249255 char *name;
@@ -259,6 +265,9 @@ int __kmod_path__parse(struct kmod_path *m, const char *path, · 9 unmodified lines
259265 #define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true , false)
260266 #define kmod_path__parse_ext(__m, __p) __kmod_path__parse(__m, __p, false, true)
261267
268+void dso__set_module_info(struct dso *dso, struct kmod_path *m,
269+ struct machine *machine);
270+
262271 /*
263272 * The dso__data_* external interface provides following functions:
264273 * dso__data_get_fd
tools/perf/util/header.c+10−2
@@ -1469,8 +1469,16 @@ static int __event_process_build_id(struct build_id_event *bev, · 1468 unmodified lines
14691469
14701470 dso__set_build_id(dso, &bev->build_id);
14711471
1472− if (!is_kernel_module(filename, cpumode))
1473− dso->kernel = dso_type;
1472+ if (dso_type != DSO_TYPE_USER) {
1473+ struct kmod_path m = { .name = NULL, };
1474+
1475+ if (!kmod_path__parse_name(&m, filename) && m.kmod)
1476+ dso__set_module_info(dso, &m, machine);
1477+ else
1478+ dso->kernel = dso_type;
1479+
1480+ free(m.name);
1481+ }
14741482
14751483 build_id__sprintf(dso->build_id, sizeof(dso->build_id),
14761484 sbuild_id);
tools/perf/util/machine.c+1−10
@@ -572,16 +572,7 @@ static struct dso *machine__findnew_module_dso(struct machine *machine, · 571 unmodified lines
572572 if (dso == NULL)
573573 goto out_unlock;
574574
575− if (machine__is_host(machine))
576− dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
577− else
578− dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
579−
580− /* _KMODULE_COMP should be next to _KMODULE */
581− if (m->kmod && m->comp)
582− dso->symtab_type++;
583−
584− dso__set_short_name(dso, strdup(m->name), true);
575+ dso__set_module_info(dso, m, machine);
585576 dso__set_long_name(dso, strdup(filename), true);
586577 }
587578
tools/perf/util/scripting-engines/trace-event-python.c+1−1
@@ -1219,7 +1219,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) · 1218 unmodified lines
12191219 fprintf(ofp, "# be retrieved using Python functions of the form "
12201220 "common_*(context).\n");
12211221
1222− fprintf(ofp, "# See the perf-trace-python Documentation for the list "
1222+ fprintf(ofp, "# See the perf-script-python Documentation for the list "
12231223 "of available functions.\n\n");
12241224
12251225 fprintf(ofp, "import os\n");
tools/perf/util/symbol-elf.c+3−38
@@ -637,43 +637,6 @@ static int dso__swap_init(struct dso *dso, unsigned char eidata) · 636 unmodified lines
637637 return 0;
638638 }
639639
640−static int decompress_kmodule(struct dso *dso, const char *name,
641− enum dso_binary_type type)
642−{
643− int fd = -1;
644− char tmpbuf[] = "/tmp/perf-kmod-XXXXXX";
645− struct kmod_path m;
646−
647− if (type != DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP &&
648− type != DSO_BINARY_TYPE__GUEST_KMODULE_COMP &&
649− type != DSO_BINARY_TYPE__BUILD_ID_CACHE)
650− return -1;
651−
652− if (type == DSO_BINARY_TYPE__BUILD_ID_CACHE)
653− name = dso->long_name;
654−
655− if (kmod_path__parse_ext(&m, name) || !m.comp)
656− return -1;
657−
658− fd = mkstemp(tmpbuf);
659− if (fd < 0) {
660− dso->load_errno = errno;
661− goto out;
662− }
663−
664− if (!decompress_to_file(m.ext, name, fd)) {
665− dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE;
666− close(fd);
667− fd = -1;
668− }
669−
670− unlink(tmpbuf);
671−
672−out:
673− free(m.ext);
674− return fd;
675−}
676−
677640 bool symsrc__possibly_runtime(struct symsrc *ss)
678641 {
679642 return ss->dynsym || ss->opdsec;
@@ -705,9 +668,11 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, · 25 unmodified lines
705668 int fd;
706669
707670 if (dso__needs_decompress(dso)) {
708− fd = decompress_kmodule(dso, name, type);
671+ fd = dso__decompress_kmodule_fd(dso, name);
709672 if (fd < 0)
710673 return -1;
674+
675+ type = dso->symtab_type;
711676 } else {
712677 fd = open(name, O_RDONLY);
713678 if (fd < 0) {
tools/perf/util/symbol.c+0−4
@@ -1562,10 +1562,6 @@ int dso__load(struct dso *dso, struct map *map) · 1561 unmodified lines
15621562 if (!runtime_ss && syms_ss)
15631563 runtime_ss = syms_ss;
15641564
1565− if (syms_ss && syms_ss->type == DSO_BINARY_TYPE__BUILD_ID_CACHE)
1566− if (dso__build_id_is_kmod(dso, name, PATH_MAX))
1567− kmod = true;
1568−
15691565 if (syms_ss)
15701566 ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod);
15711567 else
tools/perf/util/unwind-libdw.c+9−1
@@ -39,6 +39,14 @@ static int __report_module(struct addr_location *al, u64 ip, · 38 unmodified lines
3939 return 0;
4040
4141 mod = dwfl_addrmodule(ui->dwfl, ip);
42+ if (mod) {
43+ Dwarf_Addr s;
44+
45+ dwfl_module_info(mod, NULL, &s, NULL, NULL, NULL, NULL, NULL);
46+ if (s != al->map->start)
47+ mod = 0;
48+ }
49+
4250 if (!mod)
4351 mod = dwfl_report_elf(ui->dwfl, dso->short_name,
4452 dso->long_name, -1, al->map->start,
@@ -224,7 +232,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, · 179 unmodified lines
224232
225233 err = dwfl_getthread_frames(ui->dwfl, thread->tid, frame_callback, ui);
226234
227− if (err && !ui->max_stack)
235+ if (err && ui->max_stack != max_stack)
228236 err = 0;
229237
230238 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t