All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes
@ 2014-07-31 13:06 Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 1/9] tcg: add ability to dump /tmp/perf-<pid>.map files Alex Bennée
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée, l

Hi,

I've been doing a fair amount of performance analysis recently so I
thought it would be worth polishing up these patches from the last
review. I've merged the perf.map patch which was posted separately as
it makes sense with this series. I've also included some tweaks Peter
made previously which go with this set. I have also done some light
re-factoring of the tcg call to make it easier to pull the size of the
translated code out for a given Translation Block which is useful for
the later patches.

I think this is ready for merging if no one objects.

Changes:
  - dropped the disable chain flag
  - move perf.map stuff up into translate-all.c
  - include prolog/epilog in the perf.map dump
  - include tc_size in TranslationBlock
  - cleaned up documentation of the -dfilter params
  - used GArray instead of GList for debug_regions

Alex Bennée (7):
  tcg: add ability to dump /tmp/perf-<pid>.map files
  tcg: light re-factor and pass down TranslationBlock
  qemu-log: correct help text for -d cpu
  qemu-log: support simple pid substitution in logfile
  qemu-log: new option -dfilter to limit output
  qemu-log: dfilter-ise exec, out_asm, and op_opt
  target-arm: dfilter support for in_asm, op, opt_op

Peter Maydell (2):
  qemu-log: Avoid function call for disabled qemu_log_mask logging
  qemu-log: Improve the "exec" TB execution logging

 cpu-exec.c                 | 21 ++++++-----
 include/exec/exec-all.h    |  9 +++--
 include/qemu-common.h      |  2 ++
 include/qemu/log.h         | 28 +++++++++++++--
 qemu-log.c                 | 87 ++++++++++++++++++++++++++++++++++++++--------
 qemu-options.hx            | 26 ++++++++++++++
 target-arm/translate-a64.c |  6 ++--
 target-arm/translate.c     |  6 ++--
 tcg/tcg.c                  | 33 +++++++++---------
 tcg/tcg.h                  |  5 ++-
 translate-all.c            | 70 ++++++++++++++++++++++++-------------
 vl.c                       |  7 ++++
 12 files changed, 225 insertions(+), 75 deletions(-)

-- 
2.0.3

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH v3 1/9] tcg: add ability to dump /tmp/perf-<pid>.map files
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
@ 2014-07-31 13:06 ` Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 2/9] tcg: light re-factor and pass down TranslationBlock Alex Bennée
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée, l, Anthony Liguori

This allows the perf tool to map samples to each individual translation
block. This could be expanded for user space but currently it gives
enough information to find any hotblocks by other means.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---

v2:
  - hoist up into translate-all.c
  - don't use pointless glib wrappers
  - use proper format types for portability
  - mark prologue/epilog area
  - rebase

v3:
  - fix bracket for perf-map
  - find an include for the tb_enable_perfmap() declaration
  - checkpatch clean-ups

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 6ef8282..ce57884 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -259,6 +259,8 @@ typedef struct PCIHostDeviceAddress {
 void tcg_exec_init(unsigned long tb_size);
 bool tcg_enabled(void);
 
+void tb_enable_perfmap(void);
+
 void cpu_exec_init_all(void);
 
 /* CPU save/load.  */
diff --git a/qemu-options.hx b/qemu-options.hx
index 1549625..3defba8 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3348,6 +3348,16 @@ Dump json-encoded vmstate information for current machine type to file
 in @var{file}
 ETEXI
 
+DEF("perfmap", 0, QEMU_OPTION_PERFMAP, \
+    "-perfmap        generate a /tmp/perf-${pid}.map file for perf\n",
+    QEMU_ARCH_ALL)
+STEXI
+@item -perfmap
+@findex -perfmap
+This will cause QEMU to generate a map file for Linux perf tools that will allow
+basic profiling information to be broken down into basic blocks.
+ETEXI
+
 HXCOMM This is the last statement. Insert new options before this line!
 STEXI
 @end table
diff --git a/translate-all.c b/translate-all.c
index 8f7e11b..2af0774 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
+#include <glib.h>
 
 #include "config.h"
 
@@ -129,6 +130,24 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
                          tb_page_addr_t phys_page2);
 static TranslationBlock *tb_find_pc(uintptr_t tc_ptr);
 
+static FILE *tb_perfmap;
+
+void tb_enable_perfmap(void)
+{
+    gchar *map_file = g_strdup_printf("/tmp/perf-%d.map", getpid());
+    tb_perfmap = fopen(map_file, "w");
+    g_free(map_file);
+}
+
+static void tb_write_perfmap(tcg_insn_unit *start, int size, target_ulong pc)
+{
+    if (tb_perfmap) {
+        fprintf(tb_perfmap,
+                "%"PRIxPTR" %x subject-"TARGET_FMT_lx"\n",
+                (uintptr_t) start, size, pc);
+    }
+}
+
 void cpu_gen_init(void)
 {
     tcg_context_init(&tcg_ctx); 
@@ -184,6 +203,7 @@ int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr
     s->code_out_len += gen_code_size;
 #endif
 
+    tb_write_perfmap(gen_code_buf, gen_code_size, tb->pc);
 #ifdef DEBUG_DISAS
     if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) {
         qemu_log("OUT: [size=%d]\n", gen_code_size);
@@ -670,6 +690,12 @@ static inline void code_gen_alloc(size_t tb_size)
             tcg_ctx.code_gen_buffer_size - 1024;
     tcg_ctx.code_gen_buffer_size -= 1024;
 
+    if (tb_perfmap) {
+        fprintf(tb_perfmap,
+                "%"PRIxPTR" %x tcg-prologue-buffer\n",
+                (uintptr_t) tcg_ctx.code_gen_prologue, 1024);
+    }
+
     tcg_ctx.code_gen_buffer_max_size = tcg_ctx.code_gen_buffer_size -
         (TCG_MAX_OP_SIZE * OPC_BUF_SIZE);
     tcg_ctx.code_gen_max_blocks = tcg_ctx.code_gen_buffer_size /
diff --git a/vl.c b/vl.c
index fe451aa..f07f6e0 100644
--- a/vl.c
+++ b/vl.c
@@ -118,6 +118,7 @@ int main(int argc, char **argv)
 #include "qapi/opts-visitor.h"
 #include "qom/object_interfaces.h"
 #include "qapi-event.h"
+#include "qemu-common.h"
 
 #define DEFAULT_RAM_SIZE 128
 
@@ -3385,6 +3386,9 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_D:
                 log_file = optarg;
                 break;
+            case QEMU_OPTION_PERFMAP:
+                tb_enable_perfmap();
+                break;
             case QEMU_OPTION_s:
                 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
                 break;
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH v3 2/9] tcg: light re-factor and pass down TranslationBlock
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 1/9] tcg: add ability to dump /tmp/perf-<pid>.map files Alex Bennée
@ 2014-07-31 13:06 ` Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 3/9] qemu-log: correct help text for -d cpu Alex Bennée
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée, l, Richard Henderson

My later debugging patches need access to the origin PC. At the same
time we have a slightly clumsy pass-by-reference access to the size of
the translated block again for debugging purposes.

To simplify the code I have expanded the TranslationBlock structure to
include a tc_size variable to compliment the tc_ptr (and the subject pc,
block size). This is set on code generation and then accessed directly
by all the people that need it.

I've also cleaned up some comments and removed un-used return variables.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
v1
 - checkpatch fixes

diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 5e5d86e..ef4d165 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -78,8 +78,7 @@ void restore_state_to_opc(CPUArchState *env, struct TranslationBlock *tb,
                           int pc_pos);
 
 void cpu_gen_init(void);
-int cpu_gen_code(CPUArchState *env, struct TranslationBlock *tb,
-                 int *gen_code_size_ptr);
+void cpu_gen_code(CPUArchState *env, struct TranslationBlock *tb);
 bool cpu_restore_state(CPUState *cpu, uintptr_t searched_pc);
 void page_size_init(void);
 
@@ -147,6 +146,7 @@ struct TranslationBlock {
 #define CF_LAST_IO     0x8000 /* Last insn may be an IO access.  */
 
     void *tc_ptr;    /* pointer to the translated code */
+    uint32_t tc_size;/* size of translated code */
     /* next matching tb for physical address. */
     struct TranslationBlock *phys_hash_next;
     /* first and second physical page containing code. The lower bit
diff --git a/tcg/tcg.c b/tcg/tcg.c
index c068990..1ed085c 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -2414,8 +2414,7 @@ static void dump_op_count(void)
 #endif
 
 
-static inline int tcg_gen_code_common(TCGContext *s,
-                                      tcg_insn_unit *gen_code_buf,
+static inline int tcg_gen_code_common(TCGContext *s, TranslationBlock *tb,
                                       long search_pc)
 {
     TCGOpcode opc;
@@ -2423,6 +2422,10 @@ static inline int tcg_gen_code_common(TCGContext *s,
     const TCGOpDef *def;
     const TCGArg *args;
 
+    /* if we are coming via cpu_restore_state we already have a
+       generated block */
+     g_assert(tb->tc_size == 0 || search_pc > 0);
+
 #ifdef DEBUG_DISAS
     if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
         qemu_log("OP:\n");
@@ -2461,8 +2464,8 @@ static inline int tcg_gen_code_common(TCGContext *s,
 
     tcg_reg_alloc_start(s);
 
-    s->code_buf = gen_code_buf;
-    s->code_ptr = gen_code_buf;
+    s->code_buf = tb->tc_ptr;
+    s->code_ptr = tb->tc_ptr;
 
     tcg_out_tb_init(s);
 
@@ -2544,7 +2547,7 @@ static inline int tcg_gen_code_common(TCGContext *s,
     return -1;
 }
 
-int tcg_gen_code(TCGContext *s, tcg_insn_unit *gen_code_buf)
+void tcg_gen_code(TCGContext *s, TranslationBlock *tb)
 {
 #ifdef CONFIG_PROFILER
     {
@@ -2560,22 +2563,23 @@ int tcg_gen_code(TCGContext *s, tcg_insn_unit *gen_code_buf)
     }
 #endif
 
-    tcg_gen_code_common(s, gen_code_buf, -1);
+    tcg_gen_code_common(s, tb, -1);
 
     /* flush instruction cache */
     flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr);
 
-    return tcg_current_code_size(s);
+    tb->tc_size = tcg_current_code_size(s);
+    return;
 }
 
 /* Return the index of the micro operation such as the pc after is <
    offset bytes from the start of the TB.  The contents of gen_code_buf must
    not be changed, though writing the same values is ok.
    Return -1 if not found. */
-int tcg_gen_code_search_pc(TCGContext *s, tcg_insn_unit *gen_code_buf,
+int tcg_gen_code_search_pc(TCGContext *s, TranslationBlock *tb,
                            long offset)
 {
-    return tcg_gen_code_common(s, gen_code_buf, offset);
+    return tcg_gen_code_common(s, tb, offset);
 }
 
 #ifdef CONFIG_PROFILER
diff --git a/tcg/tcg.h b/tcg/tcg.h
index 997a704..95826f5 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -583,9 +583,8 @@ void tcg_context_init(TCGContext *s);
 void tcg_prologue_init(TCGContext *s);
 void tcg_func_start(TCGContext *s);
 
-int tcg_gen_code(TCGContext *s, tcg_insn_unit *gen_code_buf);
-int tcg_gen_code_search_pc(TCGContext *s, tcg_insn_unit *gen_code_buf,
-                           long offset);
+void tcg_gen_code(TCGContext *s, TranslationBlock *tb);
+int  tcg_gen_code_search_pc(TCGContext *s, TranslationBlock *tb, long offset);
 
 void tcg_set_frame(TCGContext *s, int reg, intptr_t start, intptr_t size);
 
diff --git a/translate-all.c b/translate-all.c
index 2af0774..402112c 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -153,17 +153,12 @@ void cpu_gen_init(void)
     tcg_context_init(&tcg_ctx); 
 }
 
-/* return non zero if the very first instruction is invalid so that
-   the virtual CPU can trigger an exception.
-
-   '*gen_code_size_ptr' contains the size of the generated code (host
-   code).
+/* code generation. On return tb->tc_size will reflect the size of
+ * generated code.
 */
-int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr)
+void cpu_gen_code(CPUArchState *env, TranslationBlock *tb)
 {
     TCGContext *s = &tcg_ctx;
-    tcg_insn_unit *gen_code_buf;
-    int gen_code_size;
 #ifdef CONFIG_PROFILER
     int64_t ti;
 #endif
@@ -178,7 +173,6 @@ int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr
     gen_intermediate_code(env, tb);
 
     /* generate machine code */
-    gen_code_buf = tb->tc_ptr;
     tb->tb_next_offset[0] = 0xffff;
     tb->tb_next_offset[1] = 0xffff;
     s->tb_next_offset = tb->tb_next_offset;
@@ -195,24 +189,23 @@ int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr
     s->interm_time += profile_getclock() - ti;
     s->code_time -= profile_getclock();
 #endif
-    gen_code_size = tcg_gen_code(s, gen_code_buf);
-    *gen_code_size_ptr = gen_code_size;
+   tcg_gen_code(s, tb);
+
 #ifdef CONFIG_PROFILER
     s->code_time += profile_getclock();
     s->code_in_len += tb->size;
-    s->code_out_len += gen_code_size;
+    s->code_out_len += tb->tc_size;
 #endif
 
-    tb_write_perfmap(gen_code_buf, gen_code_size, tb->pc);
+    tb_write_perfmap(tb->tc_ptr, tb->tc_size, tb->pc);
 #ifdef DEBUG_DISAS
     if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) {
-        qemu_log("OUT: [size=%d]\n", gen_code_size);
-        log_disas(tb->tc_ptr, gen_code_size);
+        qemu_log("OUT: [size=%d]\n", tb->tc_size);
+        log_disas(tb->tc_ptr, tb->tc_size);
         qemu_log("\n");
         qemu_log_flush();
     }
 #endif
-    return 0;
 }
 
 /* The cpu state corresponding to 'searched_pc' is restored.
@@ -223,7 +216,6 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
     CPUArchState *env = cpu->env_ptr;
     TCGContext *s = &tcg_ctx;
     int j;
-    uintptr_t tc_ptr;
 #ifdef CONFIG_PROFILER
     int64_t ti;
 #endif
@@ -243,9 +235,9 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
     }
 
     /* find opc index corresponding to search_pc */
-    tc_ptr = (uintptr_t)tb->tc_ptr;
-    if (searched_pc < tc_ptr)
+    if (searched_pc < (uintptr_t) tb->tc_ptr) {
         return -1;
+    }
 
     s->tb_next_offset = tb->tb_next_offset;
 #ifdef USE_DIRECT_JUMP
@@ -255,8 +247,8 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
     s->tb_jmp_offset = NULL;
     s->tb_next = tb->tb_next;
 #endif
-    j = tcg_gen_code_search_pc(s, (tcg_insn_unit *)tc_ptr,
-                               searched_pc - tc_ptr);
+    j = tcg_gen_code_search_pc(s, tb,
+                               searched_pc - (uintptr_t) tb->tc_ptr);
     if (j < 0)
         return -1;
     /* now find start of instruction before */
@@ -1059,7 +1051,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
     TranslationBlock *tb;
     tb_page_addr_t phys_pc, phys_page2;
     target_ulong virt_page2;
-    int code_gen_size;
 
     phys_pc = get_page_addr_code(env, pc);
     tb = tb_alloc(pc);
@@ -1072,12 +1063,14 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
         tcg_ctx.tb_ctx.tb_invalidated_flag = 1;
     }
     tb->tc_ptr = tcg_ctx.code_gen_ptr;
+    tb->tc_size = 0;
     tb->cs_base = cs_base;
     tb->flags = flags;
     tb->cflags = cflags;
-    cpu_gen_code(env, tb, &code_gen_size);
-    tcg_ctx.code_gen_ptr = (void *)(((uintptr_t)tcg_ctx.code_gen_ptr +
-            code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1));
+    cpu_gen_code(env, tb);
+    tcg_ctx.code_gen_ptr = (void *) (
+        ((uintptr_t) tcg_ctx.code_gen_ptr + tb->tc_size + CODE_GEN_ALIGN - 1)
+        & ~(CODE_GEN_ALIGN - 1));
 
     /* check next page if needed */
     virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK;
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH v3 3/9] qemu-log: correct help text for -d cpu
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 1/9] tcg: add ability to dump /tmp/perf-<pid>.map files Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 2/9] tcg: light re-factor and pass down TranslationBlock Alex Bennée
@ 2014-07-31 13:06 ` Alex Bennée
  2014-08-11 11:12   ` Andreas Färber
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 4/9] qemu-log: Avoid function call for disabled qemu_log_mask logging Alex Bennée
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée, l

This doesn't just dump CPU state on translation but on every block
entrance.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

diff --git a/qemu-log.c b/qemu-log.c
index 797f2af..35bbb56 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -105,7 +105,7 @@ const QEMULogItem qemu_log_items[] = {
     { CPU_LOG_EXEC, "exec",
       "show trace before each executed TB (lots of logs)" },
     { CPU_LOG_TB_CPU, "cpu",
-      "show CPU state before block translation" },
+      "show CPU registers before each executed TB (lots of logs)" },
     { CPU_LOG_PCALL, "pcall",
       "x86 only: show protected mode far calls/returns/exceptions" },
     { CPU_LOG_RESET, "cpu_reset",
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH v3 4/9] qemu-log: Avoid function call for disabled qemu_log_mask logging
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
                   ` (2 preceding siblings ...)
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 3/9] qemu-log: correct help text for -d cpu Alex Bennée
@ 2014-07-31 13:06 ` Alex Bennée
  2014-08-11 11:14   ` Andreas Färber
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 5/9] qemu-log: Improve the "exec" TB execution logging Alex Bennée
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, l

From: Peter Maydell <peter.maydell@linaro.org>

Make qemu_log_mask() a macro which only calls the function to
do the actual work if the logging is enabled. This avoids making
a function call in possible fast paths where logging is disabled.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

diff --git a/include/qemu/log.h b/include/qemu/log.h
index d515424..da22e13 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -64,10 +64,17 @@ qemu_log_vprintf(const char *fmt, va_list va)
     }
 }
 
-/* log only if a bit is set on the current loglevel mask
+/* log only if a bit is set on the current loglevel mask:
+ * @mask: bit to check in the mask
+ * @fmt: printf-style format string
+ * @args: optional arguments for format string
  */
-void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
-
+#define qemu_log_mask(MASK, FMT, ...)                   \
+    do {                                                \
+        if (unlikely(qemu_loglevel_mask(MASK))) {       \
+            qemu_log(FMT, ## __VA_ARGS__);              \
+        }                                               \
+    } while (0)
 
 /* Special cases: */
 
diff --git a/qemu-log.c b/qemu-log.c
index 35bbb56..83e0cb4 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -36,17 +36,6 @@ void qemu_log(const char *fmt, ...)
     va_end(ap);
 }
 
-void qemu_log_mask(int mask, const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start(ap, fmt);
-    if ((qemu_loglevel & mask) && qemu_logfile) {
-        vfprintf(qemu_logfile, fmt, ap);
-    }
-    va_end(ap);
-}
-
 /* enable or disable low levels log */
 void do_qemu_set_log(int log_flags, bool use_own_buffers)
 {
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH v3 5/9] qemu-log: Improve the "exec" TB execution logging
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
                   ` (3 preceding siblings ...)
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 4/9] qemu-log: Avoid function call for disabled qemu_log_mask logging Alex Bennée
@ 2014-07-31 13:06 ` Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 6/9] qemu-log: support simple pid substitution in logfile Alex Bennée
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Alex Bennée, l

From: Peter Maydell <peter.maydell@linaro.org>

Improve the TB execution logging so that it is easier to identify
what is happening from trace logs:
 * move the "Trace" logging of executed TBs into cpu_tb_exec()
   so that it is emitted if and only if we actually execute a TB,
   and for consistency for the CPU state logging
 * log when we link two TBs together via tb_add_jump()
 * log when cpu_tb_exec() returns early from a chain of TBs

The new style logging looks like this:

Trace 0x7fb7cc822ca0 [ffffffc0000dce00]
Linking TBs 0x7fb7cc822ca0 [ffffffc0000dce00] index 0 -> 0x7fb7cc823110 [ffffffc0000dce10]
Trace 0x7fb7cc823110 [ffffffc0000dce10]
Trace 0x7fb7cc823420 [ffffffc000302688]
Trace 0x7fb7cc8234a0 [ffffffc000302698]
Trace 0x7fb7cc823520 [ffffffc0003026a4]
Trace 0x7fb7cc823560 [ffffffc0000dce44]
Linking TBs 0x7fb7cc823560 [ffffffc0000dce44] index 1 -> 0x7fb7cc8235d0 [ffffffc0000dce70]
Trace 0x7fb7cc8235d0 [ffffffc0000dce70]
Abandoned execution of TB chain before 0x7fb7cc8235d0 [ffffffc0000dce70]
Trace 0x7fb7cc8235d0 [ffffffc0000dce70]
Trace 0x7fb7cc822fd0 [ffffffc0000dd52c]

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
[AJB: reword patch title]

diff --git a/cpu-exec.c b/cpu-exec.c
index 38e5f02..b7786fe 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -43,10 +43,14 @@ void cpu_resume_from_signal(CPUState *cpu, void *puc)
 #endif
 
 /* Execute a TB, and fix up the CPU state afterwards if necessary */
-static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr)
+static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
 {
     CPUArchState *env = cpu->env_ptr;
     uintptr_t next_tb;
+    uint8_t *tb_ptr = itb->tc_ptr;
+
+    qemu_log_mask(CPU_LOG_EXEC, "Trace %p [" TARGET_FMT_lx "] %s\n",
+                  itb->tc_ptr, itb->pc, lookup_symbol(itb->pc));
 
 #if defined(DEBUG_DISAS)
     if (qemu_loglevel_mask(CPU_LOG_TB_CPU)) {
@@ -72,6 +76,10 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr)
          */
         CPUClass *cc = CPU_GET_CLASS(cpu);
         TranslationBlock *tb = (TranslationBlock *)(next_tb & ~TB_EXIT_MASK);
+        qemu_log_mask(CPU_LOG_EXEC,
+                      "Abandoned execution of TB chain before %p ["
+                      TARGET_FMT_lx "] %s\n",
+                      itb->tc_ptr, itb->pc, lookup_symbol(itb->pc));
         if (cc->synchronize_from_tb) {
             cc->synchronize_from_tb(cpu, tb);
         } else {
@@ -105,7 +113,7 @@ static void cpu_exec_nocache(CPUArchState *env, int max_cycles,
                      max_cycles);
     cpu->current_tb = tb;
     /* execute the generated code */
-    cpu_tb_exec(cpu, tb->tc_ptr);
+    cpu_tb_exec(cpu, tb);
     cpu->current_tb = NULL;
     tb_phys_invalidate(tb, -1);
     tb_free(tb);
@@ -225,7 +233,6 @@ int cpu_exec(CPUArchState *env)
 #endif
     int ret, interrupt_request;
     TranslationBlock *tb;
-    uint8_t *tc_ptr;
     uintptr_t next_tb;
     /* This must be volatile so it is not trashed by longjmp() */
     volatile bool have_tb_lock = false;
@@ -616,10 +623,6 @@ int cpu_exec(CPUArchState *env)
                     next_tb = 0;
                     tcg_ctx.tb_ctx.tb_invalidated_flag = 0;
                 }
-                if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
-                    qemu_log("Trace %p [" TARGET_FMT_lx "] %s\n",
-                             tb->tc_ptr, tb->pc, lookup_symbol(tb->pc));
-                }
                 /* see if we can patch the calling TB. When the TB
                    spans two pages, we cannot safely do a direct
                    jump. */
@@ -637,9 +640,8 @@ int cpu_exec(CPUArchState *env)
                 cpu->current_tb = tb;
                 barrier();
                 if (likely(!cpu->exit_request)) {
-                    tc_ptr = tb->tc_ptr;
                     /* execute the generated code */
-                    next_tb = cpu_tb_exec(cpu, tc_ptr);
+                    next_tb = cpu_tb_exec(cpu, tb);
                     switch (next_tb & TB_EXIT_MASK) {
                     case TB_EXIT_REQUESTED:
                         /* Something asked us to stop executing
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index ef4d165..2ff6a6b 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -297,6 +297,9 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,
 {
     /* NOTE: this test is only needed for thread safety */
     if (!tb->jmp_next[n]) {
+        qemu_log_mask(CPU_LOG_EXEC, "Linking TBs %p [" TARGET_FMT_lx
+                      "] index %d -> %p [" TARGET_FMT_lx "]\n",
+                      tb->tc_ptr, tb->pc, n, tb_next->tc_ptr, tb_next->pc);
         /* patch the native jump address */
         tb_set_jmp_target(tb, n, (uintptr_t)tb_next->tc_ptr);
 
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH v3 6/9] qemu-log: support simple pid substitution in logfile
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
                   ` (4 preceding siblings ...)
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 5/9] qemu-log: Improve the "exec" TB execution logging Alex Bennée
@ 2014-07-31 13:06 ` Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 7/9] qemu-log: new option -dfilter to limit output Alex Bennée
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée, l

When debugging stuff that occurs over several forks it would be useful
not to keep overwriting the one logfile you've set-up. This allows a
simple %d to be included once in the logfile parameter which is
substituted with getpid().

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Leandro Dorileo <l@dorileo.org>

diff --git a/qemu-log.c b/qemu-log.c
index 83e0cb4..4dd530c 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -70,11 +70,24 @@ void do_qemu_set_log(int log_flags, bool use_own_buffers)
         qemu_log_close();
     }
 }
-
+/*
+ * Allow the user to include %d in their logfile which will be
+ * substituted with the current PID. This is useful for debugging many
+ * nested linux-user tasks but will result in lots of logs.
+ */
 void qemu_set_log_filename(const char *filename)
 {
     g_free(logfilename);
-    logfilename = g_strdup(filename);
+    if (g_strrstr(filename, "%d")) {
+        /* if we are going to format this we'd better validate first */
+        if (g_regex_match_simple("^[^%]+%d[^%]+$", filename, 0, 0)) {
+            logfilename = g_strdup_printf(filename, getpid());
+        } else {
+            g_error("Bad logfile format: %s", filename);
+        }
+    } else {
+        logfilename = g_strdup(filename);
+    }
     qemu_log_close();
     qemu_set_log(qemu_loglevel);
 }
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH v3 7/9] qemu-log: new option -dfilter to limit output
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
                   ` (5 preceding siblings ...)
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 6/9] qemu-log: support simple pid substitution in logfile Alex Bennée
@ 2014-07-31 13:06 ` Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 8/9] qemu-log: dfilter-ise exec, out_asm, and op_opt Alex Bennée
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée, l, Anthony Liguori

When debugging big programs or system emulation sometimes you want both
the verbosity of cpu,exec et all but don't want to generate lots of logs
for unneeded stuff. This patch adds a new option -dfilter which allows
you to specify interesting address ranges in the form:

  -dfilter 0x8000-0x9000,0xffffffc000080000+0x200,...

Then logging code can use the new qemu_log_in_addr_range() function to
decide if it will output logging information for the given range.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

----

v2
  - More clean-ups to the documentation

v3
  - re-base
  - use GArray instead of GList to avoid cache bouncing
  - checkpatch fixes

diff --git a/include/qemu/log.h b/include/qemu/log.h
index da22e13..8cfe57f 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -181,6 +181,8 @@ static inline void qemu_set_log(int log_flags)
 }
 
 void qemu_set_log_filename(const char *filename);
+void qemu_set_dfilter_ranges(const char *ranges);
+bool qemu_log_in_addr_range(uint64_t addr);
 int qemu_str_to_log_mask(const char *str);
 
 /* Print a usage message listing all the valid logging categories
diff --git a/qemu-log.c b/qemu-log.c
index 4dd530c..70956b8 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -19,11 +19,13 @@
 
 #include "qemu-common.h"
 #include "qemu/log.h"
+#include "qemu/range.h"
 
 static char *logfilename;
 FILE *qemu_logfile;
 int qemu_loglevel;
 static int log_append = 0;
+static GArray *debug_regions;
 
 void qemu_log(const char *fmt, ...)
 {
@@ -92,6 +94,61 @@ void qemu_set_log_filename(const char *filename)
     qemu_set_log(qemu_loglevel);
 }
 
+/* Returns true if addr is in our debug filter or no filter defined
+ */
+bool qemu_log_in_addr_range(uint64_t addr)
+{
+    if (debug_regions) {
+        int i = 0;
+        for (i = 0; i < debug_regions->len; i++) {
+            struct Range *range = &g_array_index(debug_regions, Range, i);
+            if (addr >= range->begin && addr <= range->end) {
+                return true;
+            }
+        }
+        return false;
+    } else {
+        return true;
+    }
+}
+
+
+void qemu_set_dfilter_ranges(const char *filter_spec)
+{
+    gchar **ranges = g_strsplit(filter_spec, ",", 0);
+    if (ranges) {
+        gchar **next = ranges;
+        gchar *r = *next++;
+        debug_regions = g_array_sized_new(FALSE, FALSE,
+                                          sizeof(Range), g_strv_length(ranges));
+        while (r) {
+            gchar *delim = g_strrstr(r, "-");
+            if (!delim) {
+                delim = g_strrstr(r, "+");
+            }
+            if (delim) {
+                struct Range range;
+                range.begin = strtoul(r, NULL, 0);
+                switch (*delim) {
+                case '+':
+                    range.end = range.begin + strtoul(delim+1, NULL, 0);
+                    break;
+                case '-':
+                    range.end = strtoul(delim+1, NULL, 0);
+                    break;
+                default:
+                    g_assert_not_reached();
+                }
+                g_array_append_val(debug_regions, range);
+            } else {
+                g_error("Bad range specifier in: %s", r);
+            }
+            r = *next++;
+        }
+        g_strfreev(ranges);
+    }
+}
+
 const QEMULogItem qemu_log_items[] = {
     { CPU_LOG_TB_OUT_ASM, "out_asm",
       "show generated host assembly code for each compiled TB" },
diff --git a/qemu-options.hx b/qemu-options.hx
index 3defba8..7ac9ed3 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2867,6 +2867,22 @@ STEXI
 Output log in @var{logfile} instead of to stderr
 ETEXI
 
+DEF("dfilter", HAS_ARG, QEMU_OPTION_DFILTER, \
+    "-dfilter range,..  filter debug output to range of addresses (useful for -d cpu,exec,etc..)\n",
+    QEMU_ARCH_ALL)
+STEXI
+@item -dfilter @var{range1}[,...]
+@findex -dfilter
+Filter debug output to that relevant to a range of target addresses. The filter
+spec can be either @var{start}-@var{end} or @var{start}+@var{size} where @var{start}
+@var{end} and @var{size} are the addresses and sizes required. For example:
+@example
+    -dfilter 0x8000-0x9000,0xffffffc000080000+0x200
+@end example
+Will dump output for any code in the 0x1000 sized block starting at 0x8000 and
+the 0x200 sized block starting at 0xffffffc000080000.
+ETEXI
+
 DEF("L", HAS_ARG, QEMU_OPTION_L, \
     "-L path         set the directory for the BIOS, VGA BIOS and keymaps\n",
     QEMU_ARCH_ALL)
diff --git a/vl.c b/vl.c
index f07f6e0..3d72752 100644
--- a/vl.c
+++ b/vl.c
@@ -3386,6 +3386,9 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_D:
                 log_file = optarg;
                 break;
+            case QEMU_OPTION_DFILTER:
+                qemu_set_dfilter_ranges(optarg);
+                break;
             case QEMU_OPTION_PERFMAP:
                 tb_enable_perfmap();
                 break;
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH v3 8/9] qemu-log: dfilter-ise exec, out_asm, and op_opt
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
                   ` (6 preceding siblings ...)
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 7/9] qemu-log: new option -dfilter to limit output Alex Bennée
@ 2014-07-31 13:06 ` Alex Bennée
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 9/9] target-arm: dfilter support for in_asm, op, opt_op Alex Bennée
  2014-08-11  9:37 ` [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
  9 siblings, 0 replies; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée, l, Richard Henderson

This ensures the code generation debug code will honour -dfilter if set.
For the "exec" tracing I've added a new inline macro for efficiency's
sake. I've not touched CPU_LOG_TB_OP as this is buried in each
individual target.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

----

v2
   - checkpatch updates
   - add qemu_log_mask_and_addr macro for inline dump for traces
   - re-base on re-factored tcg layout
   - include new Trace & Link lines

diff --git a/cpu-exec.c b/cpu-exec.c
index b7786fe..2d51c1e 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -49,8 +49,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
     uintptr_t next_tb;
     uint8_t *tb_ptr = itb->tc_ptr;
 
-    qemu_log_mask(CPU_LOG_EXEC, "Trace %p [" TARGET_FMT_lx "] %s\n",
-                  itb->tc_ptr, itb->pc, lookup_symbol(itb->pc));
+    qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc,
+                           "Trace %p [" TARGET_FMT_lx "] %s\n",
+                           itb->tc_ptr, itb->pc, lookup_symbol(itb->pc));
 
 #if defined(DEBUG_DISAS)
     if (qemu_loglevel_mask(CPU_LOG_TB_CPU)) {
@@ -76,10 +77,10 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
          */
         CPUClass *cc = CPU_GET_CLASS(cpu);
         TranslationBlock *tb = (TranslationBlock *)(next_tb & ~TB_EXIT_MASK);
-        qemu_log_mask(CPU_LOG_EXEC,
-                      "Abandoned execution of TB chain before %p ["
-                      TARGET_FMT_lx "] %s\n",
-                      itb->tc_ptr, itb->pc, lookup_symbol(itb->pc));
+        qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc,
+                               "Abandoned execution of TB chain before %p ["
+                               TARGET_FMT_lx "] %s\n",
+                               itb->tc_ptr, itb->pc, lookup_symbol(itb->pc));
         if (cc->synchronize_from_tb) {
             cc->synchronize_from_tb(cpu, tb);
         } else {
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 2ff6a6b..52b4143 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -297,9 +297,11 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,
 {
     /* NOTE: this test is only needed for thread safety */
     if (!tb->jmp_next[n]) {
-        qemu_log_mask(CPU_LOG_EXEC, "Linking TBs %p [" TARGET_FMT_lx
-                      "] index %d -> %p [" TARGET_FMT_lx "]\n",
-                      tb->tc_ptr, tb->pc, n, tb_next->tc_ptr, tb_next->pc);
+        qemu_log_mask_and_addr(CPU_LOG_EXEC, tb->pc,
+                               "Linking TBs %p [" TARGET_FMT_lx
+                               "] index %d -> %p [" TARGET_FMT_lx "]\n",
+                               tb->tc_ptr, tb->pc, n,
+                               tb_next->tc_ptr, tb_next->pc);
         /* patch the native jump address */
         tb_set_jmp_target(tb, n, (uintptr_t)tb_next->tc_ptr);
 
diff --git a/include/qemu/log.h b/include/qemu/log.h
index 8cfe57f..f6cef9e 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -76,6 +76,21 @@ qemu_log_vprintf(const char *fmt, va_list va)
         }                                               \
     } while (0)
 
+/* log only if a bit is set on the current loglevel mask
+ * and we are in the address range we care about:
+ * @mask: bit to check in the mask
+ * @addr: address to check in dfilter
+ * @fmt: printf-style format string
+ * @args: optional arguments for format string
+ */
+#define qemu_log_mask_and_addr(MASK, ADDR, FMT, ...)    \
+    do {                                                \
+        if (unlikely(qemu_loglevel_mask(MASK)) &&       \
+                     qemu_log_in_addr_range(ADDR)) {    \
+            qemu_log(FMT, ## __VA_ARGS__);              \
+        }                                               \
+    } while (0)
+
 /* Special cases: */
 
 /* cpu_dump_state() logging functions: */
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 1ed085c..732cec4 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -2427,7 +2427,8 @@ static inline int tcg_gen_code_common(TCGContext *s, TranslationBlock *tb,
      g_assert(tb->tc_size == 0 || search_pc > 0);
 
 #ifdef DEBUG_DISAS
-    if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
+    if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)
+                 && qemu_log_in_addr_range(tb->pc))) {
         qemu_log("OP:\n");
         tcg_dump_ops(s);
         qemu_log("\n");
@@ -2455,7 +2456,8 @@ static inline int tcg_gen_code_common(TCGContext *s, TranslationBlock *tb,
 #endif
 
 #ifdef DEBUG_DISAS
-    if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT))) {
+    if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT)
+                 && qemu_log_in_addr_range(tb->pc))) {
         qemu_log("OP after optimization and liveness analysis:\n");
         tcg_dump_ops(s);
         qemu_log("\n");
@@ -2478,11 +2480,6 @@ static inline int tcg_gen_code_common(TCGContext *s, TranslationBlock *tb,
         tcg_table_op_count[opc]++;
 #endif
         def = &tcg_op_defs[opc];
-#if 0
-        printf("%s: %d %d %d\n", def->name,
-               def->nb_oargs, def->nb_iargs, def->nb_cargs);
-        //        dump_regs(s);
-#endif
         switch(opc) {
         case INDEX_op_mov_i32:
         case INDEX_op_mov_i64:
diff --git a/translate-all.c b/translate-all.c
index 402112c..4809840 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -199,7 +199,8 @@ void cpu_gen_code(CPUArchState *env, TranslationBlock *tb)
 
     tb_write_perfmap(tb->tc_ptr, tb->tc_size, tb->pc);
 #ifdef DEBUG_DISAS
-    if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) {
+    if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) &&
+        qemu_log_in_addr_range(tb->pc)) {
         qemu_log("OUT: [size=%d]\n", tb->tc_size);
         log_disas(tb->tc_ptr, tb->tc_size);
         qemu_log("\n");
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH v3 9/9] target-arm: dfilter support for in_asm, op, opt_op
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
                   ` (7 preceding siblings ...)
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 8/9] qemu-log: dfilter-ise exec, out_asm, and op_opt Alex Bennée
@ 2014-07-31 13:06 ` Alex Bennée
  2014-08-11  9:37 ` [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
  9 siblings, 0 replies; 13+ messages in thread
From: Alex Bennée @ 2014-07-31 13:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Alex Bennée, l

Each individual architecture needs to use the qemu_log_in_addr_range()
feature for enabling in_asm and marking blocks for op/opt_op output.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
index 33b5025..56b8534 100644
--- a/target-arm/translate-a64.c
+++ b/target-arm/translate-a64.c
@@ -10910,7 +10910,8 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,
             gen_io_start();
         }
 
-        if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
+        if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT) &&
+                     qemu_log_in_addr_range(dc->pc))) {
             tcg_gen_debug_insn_start(dc->pc);
         }
 
@@ -10984,7 +10985,8 @@ done_generating:
     *tcg_ctx.gen_opc_ptr = INDEX_op_end;
 
 #ifdef DEBUG_DISAS
-    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
+    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) &&
+        qemu_log_in_addr_range(pc_start)) {
         qemu_log("----------------\n");
         qemu_log("IN: %s\n", lookup_symbol(pc_start));
         log_target_disas(env, pc_start, dc->pc - pc_start,
diff --git a/target-arm/translate.c b/target-arm/translate.c
index cf4e767..d74a8a9 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -11018,7 +11018,8 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
         if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
             gen_io_start();
 
-        if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
+        if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT)) &&
+            qemu_log_in_addr_range(dc->pc)) {
             tcg_gen_debug_insn_start(dc->pc);
         }
 
@@ -11138,7 +11139,8 @@ done_generating:
     *tcg_ctx.gen_opc_ptr = INDEX_op_end;
 
 #ifdef DEBUG_DISAS
-    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
+    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) &&
+        qemu_log_in_addr_range(pc_start)) {
         qemu_log("----------------\n");
         qemu_log("IN: %s\n", lookup_symbol(pc_start));
         log_target_disas(env, pc_start, dc->pc - pc_start,
-- 
2.0.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes
  2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
                   ` (8 preceding siblings ...)
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 9/9] target-arm: dfilter support for in_asm, op, opt_op Alex Bennée
@ 2014-08-11  9:37 ` Alex Bennée
  9 siblings, 0 replies; 13+ messages in thread
From: Alex Bennée @ 2014-08-11  9:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, l, Michael S. Tsirkin, Stefan Hajnoczi,
	Paolo Bonzini, Andreas Färber, Richard Henderson


Alex Bennée writes:

> Hi,
>
> I've been doing a fair amount of performance analysis recently so I
> thought it would be worth polishing up these patches from the last
> review. I've merged the perf.map patch which was posted separately as
> it makes sense with this series. I've also included some tweaks Peter
> made previously which go with this set. I have also done some light
> re-factoring of the tcg call to make it easier to pull the size of the
> translated code out for a given Translation Block which is useful for
> the later patches.
>
> I think this is ready for merging if no one objects.

Ping!

I would be grateful if some review eyes could be cast over this? It
seems I'm pretty good at picking files that aren't actively covered by
maintainers though so I've widened the CC list to people who have also
hacked in the various areas.

Regards,

> Changes:
>   - dropped the disable chain flag
>   - move perf.map stuff up into translate-all.c
>   - include prolog/epilog in the perf.map dump
>   - include tc_size in TranslationBlock
>   - cleaned up documentation of the -dfilter params
>   - used GArray instead of GList for debug_regions
>
> Alex Bennée (7):
>   tcg: add ability to dump /tmp/perf-<pid>.map files
>   tcg: light re-factor and pass down TranslationBlock
>   qemu-log: correct help text for -d cpu
>   qemu-log: support simple pid substitution in logfile
>   qemu-log: new option -dfilter to limit output
>   qemu-log: dfilter-ise exec, out_asm, and op_opt
>   target-arm: dfilter support for in_asm, op, opt_op
>
> Peter Maydell (2):
>   qemu-log: Avoid function call for disabled qemu_log_mask logging
>   qemu-log: Improve the "exec" TB execution logging
>
>  cpu-exec.c                 | 21 ++++++-----
>  include/exec/exec-all.h    |  9 +++--
>  include/qemu-common.h      |  2 ++
>  include/qemu/log.h         | 28 +++++++++++++--
>  qemu-log.c                 | 87 ++++++++++++++++++++++++++++++++++++++--------
>  qemu-options.hx            | 26 ++++++++++++++
>  target-arm/translate-a64.c |  6 ++--
>  target-arm/translate.c     |  6 ++--
>  tcg/tcg.c                  | 33 +++++++++---------
>  tcg/tcg.h                  |  5 ++-
>  translate-all.c            | 70 ++++++++++++++++++++++++-------------
>  vl.c                       |  7 ++++
>  12 files changed, 225 insertions(+), 75 deletions(-)

-- 
Alex Bennée

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH v3 3/9] qemu-log: correct help text for -d cpu
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 3/9] qemu-log: correct help text for -d cpu Alex Bennée
@ 2014-08-11 11:12   ` Andreas Färber
  0 siblings, 0 replies; 13+ messages in thread
From: Andreas Färber @ 2014-08-11 11:12 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel; +Cc: l

Am 31.07.2014 14:06, schrieb Alex Bennée:
> This doesn't just dump CPU state on translation but on every block
> entrance.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> 
> diff --git a/qemu-log.c b/qemu-log.c
> index 797f2af..35bbb56 100644
> --- a/qemu-log.c
> +++ b/qemu-log.c
> @@ -105,7 +105,7 @@ const QEMULogItem qemu_log_items[] = {
>      { CPU_LOG_EXEC, "exec",
>        "show trace before each executed TB (lots of logs)" },
>      { CPU_LOG_TB_CPU, "cpu",
> -      "show CPU state before block translation" },
> +      "show CPU registers before each executed TB (lots of logs)" },
>      { CPU_LOG_PCALL, "pcall",
>        "x86 only: show protected mode far calls/returns/exceptions" },
>      { CPU_LOG_RESET, "cpu_reset",

Seeing that the "lots of logs" is already in use above,

Reviewed-by: Andreas Färber <afaerber@suse.de>

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH v3 4/9] qemu-log: Avoid function call for disabled qemu_log_mask logging
  2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 4/9] qemu-log: Avoid function call for disabled qemu_log_mask logging Alex Bennée
@ 2014-08-11 11:14   ` Andreas Färber
  0 siblings, 0 replies; 13+ messages in thread
From: Andreas Färber @ 2014-08-11 11:14 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel; +Cc: Peter Maydell, l

Am 31.07.2014 14:06, schrieb Alex Bennée:
> From: Peter Maydell <peter.maydell@linaro.org>
> 
> Make qemu_log_mask() a macro which only calls the function to
> do the actual work if the logging is enabled. This avoids making
> a function call in possible fast paths where logging is disabled.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Lacking your Sob as submitter. If you fix that,
Reviewed-by: Andreas Färber <afaerber@suse.de>

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-08-11 11:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-31 13:06 [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée
2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 1/9] tcg: add ability to dump /tmp/perf-<pid>.map files Alex Bennée
2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 2/9] tcg: light re-factor and pass down TranslationBlock Alex Bennée
2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 3/9] qemu-log: correct help text for -d cpu Alex Bennée
2014-08-11 11:12   ` Andreas Färber
2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 4/9] qemu-log: Avoid function call for disabled qemu_log_mask logging Alex Bennée
2014-08-11 11:14   ` Andreas Färber
2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 5/9] qemu-log: Improve the "exec" TB execution logging Alex Bennée
2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 6/9] qemu-log: support simple pid substitution in logfile Alex Bennée
2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 7/9] qemu-log: new option -dfilter to limit output Alex Bennée
2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 8/9] qemu-log: dfilter-ise exec, out_asm, and op_opt Alex Bennée
2014-07-31 13:06 ` [Qemu-devel] [PATCH v3 9/9] target-arm: dfilter support for in_asm, op, opt_op Alex Bennée
2014-08-11  9:37 ` [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes Alex Bennée

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.