* [Qemu-devel] [PATCH] Add option to disable TB cache
@ 2008-01-08 16:13 Hervé Poussineau
0 siblings, 0 replies; only message in thread
From: Hervé Poussineau @ 2008-01-08 16:13 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 353 bytes --]
Hi,
This patch adds the "-translation no-cache" option to disable the use
of Translation Blocks Cache.
The emulated system runs much slower, but it is easier to debug it. The
-translation value can be extended to handle more settings.
It also adds help for "-startdate" flag and displays right log file
name.
Hervé
[-- Attachment #2: no-tb-cache.patch --]
[-- Type: application/octet-stream, Size: 6282 bytes --]
Index: cpu-all.h
===================================================================
RCS file: /sources/qemu/qemu/cpu-all.h,v
retrieving revision 1.81
diff -u -r1.81 cpu-all.h
--- cpu-all.h 1 Jan 2008 16:57:19 -0000 1.81
+++ cpu-all.h 8 Jan 2008 16:41:09 -0000
@@ -787,6 +787,20 @@
void cpu_set_log_filename(const char *filename);
int cpu_str_to_log_mask(const char *str);
+#define CPU_SETTING_NO_CACHE (1 << 0)
+
+/* define translation settings */
+typedef struct CPUTranslationSetting {
+ int mask;
+ const char *name;
+ const char *help;
+} CPUTranslationSetting;
+
+extern CPUTranslationSetting cpu_translation_settings[];
+
+void cpu_set_translation_settings(int translation_flags);
+int cpu_str_to_translation_mask(const char *str);
+
/* IO ports API */
/* NOTE: as these functions may be even used when there is an isa
Index: cpu-exec.c
===================================================================
RCS file: /sources/qemu/qemu/cpu-exec.c,v
retrieving revision 1.130
diff -u -r1.130 cpu-exec.c
--- cpu-exec.c 11 Dec 2007 19:39:25 -0000 1.130
+++ cpu-exec.c 8 Jan 2008 16:52:33 -0000
@@ -20,6 +20,7 @@
#include "config.h"
#include "exec.h"
#include "disas.h"
+#include <string.h>
#if !defined(CONFIG_SOFTMMU)
#undef EAX
@@ -40,6 +41,9 @@
//#define DEBUG_EXEC
//#define DEBUG_SIGNAL
+/* translation settings */
+int translation_settings = 0;
+
#define SAVE_GLOBALS()
#define RESTORE_GLOBALS()
@@ -120,6 +124,56 @@
longjmp(env->jmp_env, 1);
}
+CPUTranslationSetting cpu_translation_settings[] = {
+ { CPU_SETTING_NO_CACHE, "no-cache",
+ "Do not use translation blocks cache (very slow!)" },
+ { 0, NULL, NULL },
+};
+
+void cpu_set_translation_settings(int translation_flags)
+{
+ translation_settings = translation_flags;
+}
+
+static int cmp1(const char *s1, int n, const char *s2)
+{
+ if (strlen(s2) != n)
+ return 0;
+ return memcmp(s1, s2, n) == 0;
+}
+
+/* takes a comma separated list of translation settings. Return 0 if error. */
+int cpu_str_to_translation_mask(const char *str)
+{
+ CPUTranslationSetting *setting;
+ int mask;
+ const char *p, *p1;
+
+ p = str;
+ mask = 0;
+ for(;;) {
+ p1 = strchr(p, ',');
+ if (!p1)
+ p1 = p + strlen(p);
+ if(cmp1(p,p1-p,"all")) {
+ for(setting = cpu_translation_settings; setting->mask != 0; setting++) {
+ mask |= setting->mask;
+ }
+ } else {
+ for(setting = cpu_translation_settings; setting->mask != 0; setting++) {
+ if (cmp1(p, p1 - p, setting->name))
+ goto found;
+ }
+ return 0;
+ }
+ found:
+ mask |= setting->mask;
+ if (*p1 != ',')
+ break;
+ p = p1 + 1;
+ }
+ return mask;
+}
static TranslationBlock *tb_find_slow(target_ulong pc,
target_ulong cs_base,
@@ -141,6 +195,9 @@
phys_pc = get_phys_addr_code(env, pc);
phys_page1 = phys_pc & TARGET_PAGE_MASK;
phys_page2 = -1;
+ if (translation_settings & CPU_SETTING_NO_CACHE)
+ goto not_found;
+
h = tb_phys_hash_func(phys_pc);
ptb1 = &tb_phys_hash[h];
for(;;) {
@@ -264,7 +321,10 @@
#else
#error unsupported CPU
#endif
- tb = env->tb_jmp_cache[tb_jmp_cache_hash_func(pc)];
+ if (translation_settings & CPU_SETTING_NO_CACHE)
+ tb = NULL;
+ else
+ tb = env->tb_jmp_cache[tb_jmp_cache_hash_func(pc)];
if (__builtin_expect(!tb || tb->pc != pc || tb->cs_base != cs_base ||
tb->flags != flags, 0)) {
tb = tb_find_slow(pc, cs_base, flags);
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.394
diff -u -r1.394 vl.c
--- vl.c 6 Jan 2008 17:21:48 -0000 1.394
+++ vl.c 8 Jan 2008 16:48:45 -0000
@@ -237,6 +237,8 @@
static CPUState *next_cpu;
static int event_pending = 1;
+extern char *logfilename;
+
#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
/***********************************************************/
@@ -7617,6 +7617,9 @@
#endif
"-clock force the use of the given methods for timer alarm.\n"
" To see what timers are available use -clock help\n"
+ "-startdate select initial date of the Qemu clock\n"
+ "-translation setting1,... configures code translation\n"
+ " (use -translation ? for a list of settings)\n"
"\n"
"During emulation, the following keys are useful:\n"
"ctrl-alt-f toggle full screen\n"
@@ -7632,7 +7635,7 @@
DEFAULT_NETWORK_DOWN_SCRIPT,
#endif
DEFAULT_GDBSTUB_PORT,
- "/tmp/qemu.log");
+ logfilename);
exit(exitcode);
}
@@ -7719,6 +7722,7 @@
QEMU_OPTION_old_param,
QEMU_OPTION_clock,
QEMU_OPTION_startdate,
+ QEMU_OPTION_translation,
};
typedef struct QEMUOption {
@@ -7827,6 +7831,7 @@
#endif
{ "clock", HAS_ARG, QEMU_OPTION_clock },
{ "startdate", HAS_ARG, QEMU_OPTION_startdate },
+ { "translation", HAS_ARG, QEMU_OPTION_translation },
{ NULL },
};
@@ -8661,6 +8666,22 @@
}
}
break;
+ case QEMU_OPTION_translation:
+ {
+ int mask;
+ CPUTranslationSetting *setting;
+
+ mask = cpu_str_to_translation_mask(optarg);
+ if (!mask) {
+ printf("Translation settings (comma separated):\n");
+ for(setting = cpu_translation_settings; setting->mask != 0; setting++) {
+ printf("%-10s %s\n", setting->name, setting->help);
+ }
+ exit(1);
+ }
+ cpu_set_translation_settings(mask);
+ }
+ break;
}
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-01-08 17:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-08 16:13 [Qemu-devel] [PATCH] Add option to disable TB cache Hervé Poussineau
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).