From: He Kuang <hekuang@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
<alexander.shishkin@linux.intel.com>, <jolsa@redhat.com>,
<wangnan0@huawei.com>, <hekuang@huawei.com>,
<jpoimboe@redhat.com>, <ak@linux.intel.com>, <eranian@google.com>,
<namhyung@kernel.org>, <adrian.hunter@intel.com>,
<sukadev@linux.vnet.ibm.com>, <masami.hiramatsu.pt@hitachi.com>,
<tumanova@linux.vnet.ibm.com>, <kan.liang@intel.com>,
<penberg@kernel.org>, <dsahern@gmail.com>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH v4 4/6] perf callchain: Add support for cross-platform unwind
Date: Thu, 19 May 2016 11:47:40 +0000 [thread overview]
Message-ID: <1463658462-85131-5-git-send-email-hekuang@huawei.com> (raw)
In-Reply-To: <1463658462-85131-1-git-send-email-hekuang@huawei.com>
Use thread specific unwind ops to unwind cross-platform callchains.
Before this patch, unwind methods is suitable for local unwind, this
patch changes the fixed methods to thread/map related. Each time a map
is inserted, we find the target arch and see if this platform can be
remote unwind. In this patch, we test for x86 platform and only show
proper messages. The real unwind methods are not implemented, will be
introduced in next patch.
Signed-off-by: He Kuang <hekuang@huawei.com>
---
tools/perf/util/thread.c | 5 +--
tools/perf/util/thread.h | 14 +++++-
tools/perf/util/unwind-libunwind.c | 48 ++++++++++++++++++---
tools/perf/util/unwind-libunwind_common.c | 71 +++++++++++++++++++++++++++++--
tools/perf/util/unwind.h | 32 +++++++++-----
5 files changed, 145 insertions(+), 25 deletions(-)
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 3043113..4e1aaf5 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -43,9 +43,6 @@ struct thread *thread__new(pid_t pid, pid_t tid)
thread->cpu = -1;
INIT_LIST_HEAD(&thread->comm_list);
- if (unwind__prepare_access(thread) < 0)
- goto err_thread;
-
comm_str = malloc(32);
if (!comm_str)
goto err_thread;
@@ -59,6 +56,8 @@ struct thread *thread__new(pid_t pid, pid_t tid)
list_add(&comm->list, &thread->comm_list);
atomic_set(&thread->refcnt, 1);
RB_CLEAR_NODE(&thread->rb_node);
+
+ register_null_unwind_libunwind_ops(thread);
}
return thread;
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 45fba13..de8e42e 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -15,6 +15,17 @@
struct thread_stack;
+struct unwind_entry;
+typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
+struct unwind_libunwind_ops {
+ int (*prepare_access)(struct thread *thread);
+ void (*flush_access)(struct thread *thread);
+ void (*finish_access)(struct thread *thread);
+ int (*get_entries)(unwind_entry_cb_t cb, void *arg,
+ struct thread *thread,
+ struct perf_sample *data, int max_stack);
+};
+
struct thread {
union {
struct rb_node rb_node;
@@ -36,7 +47,8 @@ struct thread {
void *priv;
struct thread_stack *ts;
#ifdef HAVE_LIBUNWIND_SUPPORT
- unw_addr_space_t addr_space;
+ unw_addr_space_t addr_space;
+ struct unwind_libunwind_ops *unwind_libunwind_ops;
#endif
};
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 63687d3..d3a2ec44 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -22,6 +22,9 @@
#include <unistd.h>
#include <sys/mman.h>
#include <linux/list.h>
+#ifdef REMOTE_UNWIND_LIBUNWIND
+#include "libunwind-arch.h"
+#endif
#include <libunwind.h>
#include <libunwind-ptrace.h>
#include "callchain.h"
@@ -34,6 +37,21 @@
#include "debug.h"
#include "asm/bug.h"
+#ifndef REMOTE_UNWIND_LIBUNWIND
+ #define LIBUNWIND__ARCH_REG_ID libunwind__arch_reg_id
+ #define LOCAL_UNWIND_LIBUNWIND
+ #undef UNWT_OBJ
+ #define UNWT_OBJ(x) _##x
+#else
+ #undef NO_LIBUNWIND_DEBUG_FRAME
+ #if defined(LIBUNWIND_ARM) && !defined(NO_LIBUNWIND_DEBUG_FRAME_ARM)
+ #elif defined(LIBUNWIND_AARCH64) && \
+ defined(NO_LIBUNWIND_DEBUG_FRAME_ARM_AARCH64)
+ #else
+ #define NO_LIBUNWIND_DEBUG_FRAME
+ #endif
+#endif
+
extern int
UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as,
unw_word_t ip,
@@ -508,7 +526,7 @@ static int access_reg(unw_addr_space_t __maybe_unused as,
return 0;
}
- id = libunwind__arch_reg_id(regnum);
+ id = LIBUNWIND__ARCH_REG_ID(regnum);
if (id < 0)
return -EINVAL;
@@ -579,7 +597,7 @@ static unw_accessors_t accessors = {
.get_proc_name = get_proc_name,
};
-int unwind__prepare_access(struct thread *thread)
+static int UNWT_OBJ(_unwind__prepare_access)(struct thread *thread)
{
if (callchain_param.record_mode != CALLCHAIN_DWARF)
return 0;
@@ -594,7 +612,7 @@ int unwind__prepare_access(struct thread *thread)
return 0;
}
-void unwind__flush_access(struct thread *thread)
+static void UNWT_OBJ(_unwind__flush_access)(struct thread *thread)
{
if (callchain_param.record_mode != CALLCHAIN_DWARF)
return;
@@ -602,7 +620,7 @@ void unwind__flush_access(struct thread *thread)
unw_flush_cache(thread->addr_space, 0, 0);
}
-void unwind__finish_access(struct thread *thread)
+static void UNWT_OBJ(_unwind__finish_access)(struct thread *thread)
{
if (callchain_param.record_mode != CALLCHAIN_DWARF)
return;
@@ -662,9 +680,10 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
return ret;
}
-int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
- struct thread *thread,
- struct perf_sample *data, int max_stack)
+static int UNWT_OBJ(_unwind__get_entries)(unwind_entry_cb_t cb, void *arg,
+ struct thread *thread,
+ struct perf_sample *data,
+ int max_stack)
{
struct unwind_info ui = {
.sample = data,
@@ -680,3 +699,18 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
return get_entries(&ui, cb, arg, max_stack);
}
+
+struct unwind_libunwind_ops
+UNWT_OBJ(unwind_libunwind_ops) = {
+ .prepare_access = UNWT_OBJ(_unwind__prepare_access),
+ .flush_access = UNWT_OBJ(_unwind__flush_access),
+ .finish_access = UNWT_OBJ(_unwind__finish_access),
+ .get_entries = UNWT_OBJ(_unwind__get_entries),
+};
+
+#ifdef LOCAL_UNWIND_LIBUNWIND
+void register_local_unwind_libunwind_ops(struct thread *thread)
+{
+ thread->unwind_libunwind_ops = &UNWT_OBJ(unwind_libunwind_ops);
+}
+#endif
diff --git a/tools/perf/util/unwind-libunwind_common.c b/tools/perf/util/unwind-libunwind_common.c
index 3946c99..f44833b 100644
--- a/tools/perf/util/unwind-libunwind_common.c
+++ b/tools/perf/util/unwind-libunwind_common.c
@@ -5,10 +5,64 @@
#include "debug.h"
#include "arch/common.h"
+static int __null__prepare_access(struct thread *thread __maybe_unused)
+{
+ return 0;
+}
+
+static void __null__flush_access(struct thread *thread __maybe_unused)
+{
+}
+
+static void __null__finish_access(struct thread *thread __maybe_unused)
+{
+}
+
+static int __null__get_entries(unwind_entry_cb_t cb __maybe_unused,
+ void *arg __maybe_unused,
+ struct thread *thread __maybe_unused,
+ struct perf_sample *data __maybe_unused,
+ int max_stack __maybe_unused)
+{
+ return 0;
+}
+
+static struct unwind_libunwind_ops null_unwind_libunwind_ops = {
+ .prepare_access = __null__prepare_access,
+ .flush_access = __null__flush_access,
+ .finish_access = __null__finish_access,
+ .get_entries = __null__get_entries,
+};
+
+void register_null_unwind_libunwind_ops(struct thread *thread)
+{
+ thread->unwind_libunwind_ops = &null_unwind_libunwind_ops;
+ if (thread->mg)
+ pr_err("unwind: target platform=%s unwind unsupported\n",
+ thread->mg->machine->env->arch);
+}
+
+void register_unwind_libunwind_ops(struct unwind_libunwind_ops *ops,
+ struct thread *thread)
+{
+ thread->unwind_libunwind_ops = ops;
+}
+
+void unwind__flush_access(struct thread *thread)
+{
+ thread->unwind_libunwind_ops->flush_access(thread);
+}
+
+void unwind__finish_access(struct thread *thread)
+{
+ thread->unwind_libunwind_ops->finish_access(thread);
+}
+
void unwind__get_arch(struct thread *thread, struct map *map)
{
const char *arch;
enum dso_type dso_type;
+ int use_local_unwind = 1;
if (!thread->mg->machine->env)
return;
@@ -17,18 +71,27 @@ void unwind__get_arch(struct thread *thread, struct map *map)
if (dso_type == DSO__TYPE_UNKNOWN)
return;
- if (thread->addr_space)
+ if (thread->addr_space) {
pr_debug("unwind: thread map already set, 64bit is %d, dso=%s\n",
dso_type == DSO__TYPE_64BIT, map->dso->name);
+ return;
+ }
arch = normalize_arch(thread->mg->machine->env->arch);
if (!strcmp(arch, "x86")) {
- if (dso_type != DSO__TYPE_64BIT)
+ if (dso_type != DSO__TYPE_64BIT) {
#ifdef HAVE_LIBUNWIND_X86_SUPPORT
pr_err("unwind: target platform=%s is not implemented\n", arch);
-#else
- pr_err("unwind: target platform=%s is not supported\n", arch);
#endif
+ register_null_unwind_libunwind_ops(thread);
+ use_local_unwind = 0;
+ }
}
+
+ if (use_local_unwind)
+ register_local_unwind_libunwind_ops(thread);
+
+ if (thread->unwind_libunwind_ops->prepare_access(thread) < 0)
+ return;
}
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 889d630..1187950 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -21,20 +21,35 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
/* libunwind specific */
#ifdef HAVE_LIBUNWIND_SUPPORT
int libunwind__arch_reg_id(int regnum);
-int unwind__prepare_access(struct thread *thread);
void unwind__flush_access(struct thread *thread);
void unwind__finish_access(struct thread *thread);
void unwind__get_arch(struct thread *thread, struct map *map);
-#else
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
-{
- return 0;
+void register_unwind_libunwind_ops(struct unwind_libunwind_ops *ops,
+ struct thread *thread);
+void register_null_unwind_libunwind_ops(struct thread *thread);
+
+#ifndef HAVE_LIBUNWIND_LOCAL_SUPPORT
+static inline void
+register_local_unwind_libunwind_ops(struct thread *thread) {
+ register_null_unwind_libunwind_ops(thread);
}
+#else
+void register_local_unwind_libunwind_ops(struct thread *thread);
+#endif
+#define unwind__get_entries(cb, arg, \
+ thread, \
+ data, max_stack) \
+ thread->unwind_libunwind_ops->get_entries(cb, arg, thread, \
+ data, max_stack)
+
+#else
static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
static inline void unwind__get_arch(struct thread *thread __maybe_unused,
struct map *map __maybe_unused) {}
+static inline void
+register_null_unwind_libunwind_ops(struct thread *thread __maybe_unused) {}
#endif
#else
static inline int
@@ -47,14 +62,11 @@ unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
return 0;
}
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
-{
- return 0;
-}
-
static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
static inline void unwind__get_arch(struct thread *thread __maybe_unused,
struct map *map __maybe_unused) {}
+static inline void
+register_null_unwind_libunwind_ops(struct thread *thread __maybe_unused) {}
#endif /* HAVE_DWARF_UNWIND_SUPPORT */
#endif /* __UNWIND_H */
--
1.8.5.2
next prev parent reply other threads:[~2016-05-19 11:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-19 11:47 [PATCH v4 0/6] Add support for remote unwind He Kuang
2016-05-19 11:47 ` [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided He Kuang
2016-05-19 14:23 ` David Ahern
2016-05-19 16:07 ` Jiri Olsa
2016-05-20 17:46 ` [tip:perf/urgent] " tip-bot for He Kuang
2016-05-19 11:47 ` [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind He Kuang
2016-05-19 14:50 ` Arnaldo Carvalho de Melo
2016-05-19 16:19 ` Jiri Olsa
2016-05-20 3:00 ` Hekuang
2016-05-19 16:46 ` Jiri Olsa
2016-05-19 17:15 ` Jiri Olsa
2016-05-20 2:59 ` Hekuang
2016-05-20 9:53 ` Jiri Olsa
2016-05-19 11:47 ` [PATCH v4 3/6] perf tools: Separate local and remote unwind support detection He Kuang
2016-05-19 11:47 ` He Kuang [this message]
2016-05-19 11:47 ` [PATCH v4 5/6] perf callchain: Support x86 target platform He Kuang
2016-05-19 11:47 ` [PATCH v4 6/6] perf callchain: Support aarch64 cross-platform He Kuang
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=1463658462-85131-5-git-send-email-hekuang@huawei.com \
--to=hekuang@huawei.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=jpoimboe@redhat.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=penberg@kernel.org \
--cc=peterz@infradead.org \
--cc=sukadev@linux.vnet.ibm.com \
--cc=tumanova@linux.vnet.ibm.com \
--cc=wangnan0@huawei.com \
/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
all inboxes | Powered by JetHome®