From: "Alex Bennée" <alex.bennee@linaro.org>
To: stefanha@redhat.com
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
qemu-devel@nongnu.org, mohamad.gebai@gmail.com
Subject: [Qemu-devel] [PATCH v2 2/3] trace: add some tcg tracing support
Date: Tue, 15 Jul 2014 12:42:20 +0100 [thread overview]
Message-ID: <1405424541-21803-3-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1405424541-21803-1-git-send-email-alex.bennee@linaro.org>
This adds a couple of tcg specific trace-events which are useful for
tracing execution though tcg generated blocks. It's been tested with
lttng user space tracing but is generic enough for all systems. The tcg
events are:
* translate_block - when a subject block is translated
* exec_tb - when a translated block is entered
* exec_tb_exit - when we exit the translated code
* exec_tb_nocache - special case translations
Of course we can only trace the entrance to the first block of a chain
as each block will jump directly to the next when it can. See the -d
nochain patch to allow more complete tracing at the expense of
performance.
---
v2
- rebase
diff --git a/cpu-exec.c b/cpu-exec.c
index 38e5f02..45ef77b 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -18,6 +18,7 @@
*/
#include "config.h"
#include "cpu.h"
+#include "trace.h"
#include "disas/disas.h"
#include "tcg.h"
#include "qemu/atomic.h"
@@ -65,6 +66,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr)
#endif /* DEBUG_DISAS */
next_tb = tcg_qemu_tb_exec(env, tb_ptr);
+ trace_exec_tb_exit( (void *) (next_tb & ~TB_EXIT_MASK),
+ next_tb & TB_EXIT_MASK);
+
if ((next_tb & TB_EXIT_MASK) > TB_EXIT_IDX1) {
/* We didn't start executing this TB (eg because the instruction
* counter hit zero); we must restore the guest PC to the address
@@ -105,6 +109,7 @@ static void cpu_exec_nocache(CPUArchState *env, int max_cycles,
max_cycles);
cpu->current_tb = tb;
/* execute the generated code */
+ trace_exec_tb_nocache(tb, tb->pc);
cpu_tb_exec(cpu, tb->tc_ptr);
cpu->current_tb = NULL;
tb_phys_invalidate(tb, -1);
@@ -637,6 +642,7 @@ int cpu_exec(CPUArchState *env)
cpu->current_tb = tb;
barrier();
if (likely(!cpu->exit_request)) {
+ trace_exec_tb(tb, tb->pc);
tc_ptr = tb->tc_ptr;
/* execute the generated code */
next_tb = cpu_tb_exec(cpu, tc_ptr);
diff --git a/trace-events b/trace-events
index 709de68..f8cc35f 100644
--- a/trace-events
+++ b/trace-events
@@ -1237,6 +1237,14 @@ kvm_failed_spr_get(int str, const char *msg) "Warning: Unable to retrieve SPR %d
kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s"
kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s"
+# cpu-exec.c
+exec_tb(void *tb, uintptr_t pc) "tb:%p pc=0x%x"
+exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=0x%x"
+exec_tb_exit(void *next_tb, unsigned int flags) "tb:%p flags=%x"
+
+# translate-all.c
+translate_block(void *tb, uintptr_t pc, uint8_t *tb_code) "tb:%p, pc:0x%x, tb_code:%p"
+
# memory.c
memory_region_ops_read(void *mr, uint64_t addr, uint64_t value, unsigned size) "mr %p addr %#"PRIx64" value %#"PRIx64" size %u"
memory_region_ops_write(void *mr, uint64_t addr, uint64_t value, unsigned size) "mr %p addr %#"PRIx64" value %#"PRIx64" size %u"
diff --git a/translate-all.c b/translate-all.c
index 11d3f28..a11c083 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -34,6 +34,7 @@
#include "qemu-common.h"
#define NO_CPU_IO_DEFS
#include "cpu.h"
+#include "trace.h"
#include "disas/disas.h"
#include "tcg.h"
#if defined(CONFIG_USER_ONLY)
@@ -177,6 +178,8 @@ int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr
gen_intermediate_code(env, tb);
+ trace_translate_block(tb, tb->pc, tb->tc_ptr);
+
/* generate machine code */
gen_code_buf = tb->tc_ptr;
tb->tb_next_offset[0] = 0xffff;
--
2.0.1
next prev parent reply other threads:[~2014-07-15 11:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-15 11:42 [Qemu-devel] [PATCH v2 0/3] some TCG related trace patches Alex Bennée
2014-07-15 11:42 ` [Qemu-devel] [PATCH v2 1/3] trace: teach lttng backend to use format strings Alex Bennée
2014-08-01 9:05 ` Alex Bennée
2014-08-01 12:54 ` Stefan Hajnoczi
2014-07-15 11:42 ` Alex Bennée [this message]
2014-07-15 11:42 ` [Qemu-devel] [PATCH v2 3/3] trace: instrument and trace tcg tb flush activity Alex Bennée
2014-07-15 12:15 ` Andreas Färber
2014-07-15 13:12 ` Alex Bennée
2014-07-15 12:23 ` Peter Maydell
2014-07-15 13:07 ` Peter Maydell
2014-07-15 13:10 ` Alex Bennée
2014-07-15 13:19 ` Paolo Bonzini
2014-07-15 14:16 ` Alex Bennée
2014-07-15 20:11 ` Paolo Bonzini
2014-07-15 20:29 ` Peter Maydell
2014-07-15 20:38 ` Paolo Bonzini
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=1405424541-21803-3-git-send-email-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=mohamad.gebai@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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;
as well as URLs for NNTP newsgroup(s).