[PATCH 07/13] [PATCH] separate accelerator part of info profiler

Glauber Costa
2008-05-15T14:09:27Z

---
exec-all.h | 8 ++++++++
kqemu.c | 35 +++++++++++++++++++++++++++++++++++
monitor.c | 27 ++++++---------------------
3 files changed, 49 insertions(+), 21 deletions(-)

diff --git a/exec-all.h b/exec-all.h
index f1bd7ae..689973d 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -584,6 +584,7 @@ typedef struct QEMUAccel {
void (*flush_cache)(CPUState *env, int global);
void (*flush_page)(CPUState *env, target_ulong addr);
int (*info)(CPUState *env, char *buf);
+ int (*profile)(CPUState *env, char *buf);
} QEMUAccel;

extern QEMUAccel *current_accel;
@@ -624,6 +625,13 @@ static inline int accel_info(CPUState *env, char *buf)
return 0;
}

+static inline int accel_profile(CPUState *env, char *buf)
+{
+ if (current_accel && current_accel->profile)
+ return current_accel->profile(env, buf);
+ return 0;
+}
+
#ifdef USE_KQEMU
#define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))

diff --git a/kqemu.c b/kqemu.c
index 451d1d4..6d46dfb 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -51,6 +51,10 @@
#include <fcntl.h>
#include "kqemu.h"

+#ifdef CONFIG_PROFILER
+#include "qemu-timer.h" /* for ticks_per_sec */
+#endif
+
/* compatibility stuff */
#ifndef KQEMU_RET_SYSCALL
#define KQEMU_RET_SYSCALL 0x0300 /* syscall insn */
@@ -307,12 +311,43 @@ int kqemu_info(CPUState *env, char *buf)
return len;
}

+int64_t kqemu_time;
+int64_t kqemu_exec_count;
+int64_t kqemu_ret_int_count;
+int64_t kqemu_ret_excp_count;
+int64_t kqemu_ret_intr_count;
+extern int64_t qemu_time;
+
+int kqemu_profile(CPUState *env, char *buf)
+{
+ int len = 0;
+#ifdef CONFIG_PROFILER
+ len = sprintf(buf, "kqemu time %" PRId64 " (%0.3f %0.1f%%) count=%" PRId64
+ " int=%" PRId64 " excp=%" PRId64 " intr=%" PRId64 "\n",
+ kqemu_time, kqemu_time / (double)ticks_per_sec,
+ kqemu_time / qemu_time * 100.0,
+ kqemu_exec_count,
+ kqemu_ret_int_count,
+ kqemu_ret_excp_count,
+ kqemu_ret_intr_count);
+
+ kqemu_time = 0;
+ kqemu_exec_count = 0;
+ kqemu_ret_int_count = 0;
+ kqemu_ret_excp_count = 0;
+ kqemu_ret_intr_count = 0;
+ kqemu_record_dump();
+#endif
+ return len;
+}
+
QEMUAccel kqemu_accel = {
.cpu_interrupt = kqemu_cpu_interrupt,
.init_env = kqemu_init_env,
.flush_cache = kqemu_flush,
.flush_page = kqemu_flush_page,
.info = kqemu_info,
+ .profile = kqemu_profile,
};

diff --git a/monitor.c b/monitor.c
index cb9faef..2ee5b0c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1187,17 +1187,14 @@ static void do_info_accelerator(void)

#ifdef CONFIG_PROFILER

-int64_t kqemu_time;
int64_t qemu_time;
-int64_t kqemu_exec_count;
int64_t dev_time;
-int64_t kqemu_ret_int_count;
-int64_t kqemu_ret_excp_count;
-int64_t kqemu_ret_intr_count;
-
static void do_info_profile(void)
{
int64_t total;
+ char buf[MAX_BUF];
+ CPUState *env = mon_get_cpu();
+
total = qemu_time;
if (total == 0)
total = 1;
@@ -1205,24 +1202,12 @@ static void do_info_profile(void)
dev_time, dev_time / (double)ticks_per_sec);
term_printf("qemu time %" PRId64 " (%0.3f)\n",
qemu_time, qemu_time / (double)ticks_per_sec);
- term_printf("kqemu time %" PRId64 " (%0.3f %0.1f%%) count=%" PRId64 " int=%" PRId64 " excp=%" PRId64 " intr=%" PRId64 "\n",
- kqemu_time, kqemu_time / (double)ticks_per_sec,
- kqemu_time / (double)total * 100.0,
- kqemu_exec_count,
- kqemu_ret_int_count,
- kqemu_ret_excp_count,
- kqemu_ret_intr_count);
+ if (accel_profile(env, buf))
+ term_printf(buf);
qemu_time = 0;
- kqemu_time = 0;
- kqemu_exec_count = 0;
dev_time = 0;
- kqemu_ret_int_count = 0;
- kqemu_ret_excp_count = 0;
- kqemu_ret_intr_count = 0;
-#ifdef USE_KQEMU
- kqemu_record_dump();
-#endif
}
+
#else
static void do_info_profile(void)