From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: linux-kernel@vger.kernel.org, David Ahern <dsahern@gmail.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Jiri Olsa <jolsa@redhat.com>, Mike Galbraith <efault@gmx.de>,
Namhyung Kim <namhyung@gmail.com>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <peterz@infradead.org>,
Stephane Eranian <eranian@google.com>,
Ingo Molnar <mingo@kernel.org>
Subject: [PATCH 8/9] perf tools: add kcore to the object code reading test
Date: Thu, 25 Jul 2013 17:01:29 +0300 [thread overview]
Message-ID: <1374760890-30558-9-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1374760890-30558-1-git-send-email-adrian.hunter@intel.com>
Make the "object code reading" test attempt to read from
kcore.
The test uses objdump which struggles with kcore. i.e.
doesn't always work, sometimes takes a long time.
The test has been made to work around those issues.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/tests/code-reading.c | 77 +++++++++++++++++++++++++++++++++++------
1 file changed, 67 insertions(+), 10 deletions(-)
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 087e6cf..5fffc6f 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -109,6 +109,9 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
pr_debug("Objdump command is: %s\n", cmd);
+ /* Ignore objdump errors */
+ strcat(cmd, " 2>/dev/null");
+
f = popen(cmd, "r");
if (!f) {
pr_debug("popen failed\n");
@@ -148,7 +151,8 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
pr_debug("File is: %s\n", al.map->dso->long_name);
- if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) {
+ if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
+ !dso__is_kcore(al.map->dso)) {
pr_debug("Unexpected kernel address - skipping\n");
return 0;
}
@@ -177,6 +181,26 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
if (map__load(al.map, NULL))
return -1;
+ /* objdump struggles with kcore - try each map only once */
+ if (dso__is_kcore(al.map->dso)) {
+ static u64 done[1024];
+ static size_t done_cnt;
+ size_t d;
+
+ for (d = 0; d < done_cnt; d++) {
+ if (done[d] == al.map->start) {
+ pr_debug("kcore map tested already");
+ pr_debug(" - skipping\n");
+ return 0;
+ }
+ }
+ if (done_cnt >= ARRAY_SIZE(done)) {
+ pr_debug("Too many kcore maps - skipping\n");
+ return 0;
+ }
+ done[done_cnt++] = al.map->start;
+ }
+
/* Read the object code using objdump */
objdump_addr = map__rip_2objdump(al.map, al.addr);
ret = read_via_objdump(al.map->dso->long_name, objdump_addr, buf2, len);
@@ -188,10 +212,19 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
if (cpumode == PERF_RECORD_MISC_KERNEL ||
cpumode == PERF_RECORD_MISC_GUEST_KERNEL) {
len -= ret;
- if (len)
+ if (len) {
pr_debug("Reducing len to %zu\n", len);
- else
+ } else if (dso__is_kcore(al.map->dso)) {
+ /*
+ * objdump cannot handle very large segments
+ * that may be found in kcore.
+ */
+ pr_debug("objdump failed for kcore");
+ pr_debug(" - skipping\n");
+ return 0;
+ } else {
return -1;
+ }
}
}
if (ret < 0) {
@@ -325,10 +358,12 @@ static void do_something(void)
enum {
TEST_CODE_READING_OK,
TEST_CODE_READING_NO_VMLINUX,
+ TEST_CODE_READING_NO_KCORE,
TEST_CODE_READING_NO_ACCESS,
+ TEST_CODE_READING_NO_KERNEL_OBJ,
};
-static int do_test_code_reading(void)
+static int do_test_code_reading(bool try_kcore)
{
struct machines machines;
struct machine *machine;
@@ -349,7 +384,7 @@ static int do_test_code_reading(void)
int err = -1, ret;
pid_t pid;
struct map *map;
- bool have_vmlinux, excl_kernel = false;
+ bool have_vmlinux, have_kcore, excl_kernel = false;
pid = getpid();
@@ -362,6 +397,10 @@ static int do_test_code_reading(void)
goto out_err;
}
+ /* Force the use of kallsyms instead of vmlinux to try kcore */
+ if (try_kcore)
+ symbol_conf.kallsyms_name = "/proc/kallsyms";
+
/* Load kernel map */
map = machine->vmlinux_maps[MAP__FUNCTION];
ret = map__load(map, NULL);
@@ -369,9 +408,15 @@ static int do_test_code_reading(void)
pr_debug("map__load failed\n");
goto out_err;
}
- have_vmlinux = map->dso->symtab_type == DSO_BINARY_TYPE__VMLINUX;
- /* No point getting kernel events if there is no vmlinux */
- if (!have_vmlinux)
+ have_vmlinux = dso__is_vmlinux(map->dso);
+ have_kcore = dso__is_kcore(map->dso);
+
+ /* 2nd time through we just try kcore */
+ if (try_kcore && !have_kcore)
+ return TEST_CODE_READING_NO_KCORE;
+
+ /* No point getting kernel events if there is no kernel object */
+ if (!have_vmlinux && !have_kcore)
excl_kernel = true;
threads = thread_map__new_by_tid(pid);
@@ -457,8 +502,12 @@ static int do_test_code_reading(void)
if (ret < 0)
goto out_err;
- if (!have_vmlinux)
+ if (!have_vmlinux && !have_kcore && !try_kcore)
+ err = TEST_CODE_READING_NO_KERNEL_OBJ;
+ else if (!have_vmlinux && !try_kcore)
err = TEST_CODE_READING_NO_VMLINUX;
+ else if (!have_kcore && try_kcore)
+ err = TEST_CODE_READING_NO_KCORE;
else if (excl_kernel)
err = TEST_CODE_READING_NO_ACCESS;
else
@@ -485,7 +534,9 @@ int test__code_reading(void)
{
int ret;
- ret = do_test_code_reading();
+ ret = do_test_code_reading(false);
+ if (!ret)
+ ret = do_test_code_reading(true);
switch (ret) {
case TEST_CODE_READING_OK:
@@ -493,9 +544,15 @@ int test__code_reading(void)
case TEST_CODE_READING_NO_VMLINUX:
fprintf(stderr, " (no vmlinux)");
return 0;
+ case TEST_CODE_READING_NO_KCORE:
+ fprintf(stderr, " (no kcore)");
+ return 0;
case TEST_CODE_READING_NO_ACCESS:
fprintf(stderr, " (no access)");
return 0;
+ case TEST_CODE_READING_NO_KERNEL_OBJ:
+ fprintf(stderr, " (no kernel obj)");
+ return 0;
default:
return -1;
};
--
1.7.11.7
next prev parent reply other threads:[~2013-07-25 13:55 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-25 14:01 [PATCH 0/9] perf tools: add support for reading object code Adrian Hunter
2013-07-25 14:01 ` [PATCH 1/9] perf tools: add test " Adrian Hunter
2013-07-29 6:28 ` Namhyung Kim
2013-07-30 21:11 ` Adrian Hunter
2013-07-31 17:43 ` Arnaldo Carvalho de Melo
2013-08-03 13:47 ` Adrian Hunter
2013-07-25 14:01 ` [PATCH 2/9] perf tools: load kernel maps before using Adrian Hunter
2013-07-25 20:10 ` Ingo Molnar
2013-07-25 14:01 ` [PATCH 3/9] perf tools: make it possible to read object code from vmlinux Adrian Hunter
2013-07-25 14:01 ` [PATCH 4/9] perf tools: adjust the vmlinux symtab matches kallsyms test Adrian Hunter
2013-07-25 14:01 ` [PATCH 5/9] perf tools: avoid SyS kernel syscall aliases Adrian Hunter
2013-07-25 14:01 ` [PATCH 6/9] perf tools: make it possible to read object code from kernel modules Adrian Hunter
2013-07-25 14:01 ` [PATCH 7/9] perf tools: add support for reading from /proc/kcore Adrian Hunter
2013-07-30 4:37 ` Namhyung Kim
2013-07-30 21:12 ` Adrian Hunter
2013-07-25 14:01 ` Adrian Hunter [this message]
2013-07-30 5:24 ` [PATCH 8/9] perf tools: add kcore to the object code reading test Namhyung Kim
2013-07-30 21:17 ` Adrian Hunter
2013-07-25 14:01 ` [PATCH 9/9] perf tools: allow annotation using /proc/kcore Adrian Hunter
2013-07-25 20:22 ` [PATCH 0/9] perf tools: add support for reading object code Ingo Molnar
2013-07-27 12:27 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374760890-30558-9-git-send-email-adrian.hunter@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@ghostprotocols.net \
--cc=dsahern@gmail.com \
--cc=efault@gmx.de \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@gmail.com \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).