Skip to contentSkip to conversation

[4600] variable dynamic translation buffer size

Qemu-devel Fabrice Bellard 3 participants 4 messages May 28, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 4600

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4600
Author:   bellard
Date:     2008-05-28 12:30:31 +0000 (Wed, 28 May 2008)

Log Message:
-----------
variable dynamic translation buffer size

Modified Paths:
--------------

    trunk/cpu-all.h
    trunk/darwin-user/main.c
    trunk/exec-all.h
    trunk/exec.c
    trunk/linux-user/main.c
    trunk/target-i386/cpu.h
    trunk/vl.c

Modified: trunk/cpu-all.h
===================================================================

cpu-all.h +1 -0
@@ -767,6 +767,7 @@
 void page_set_flags(target_ulong start, target_ulong end, int flags);
 int page_check_range(target_ulong start, target_ulong len, int flags);
 
+void cpu_exec_init_all(unsigned long tb_size);
 CPUState *cpu_copy(CPUState *env);
 
 void cpu_dump_state(CPUState *env, FILE *f,

Modified: trunk/darwin-user/main.c
===================================================================

darwin-user/main.c +1 -0
@@ -873,6 +873,7 @@
 #endif
     }
     
+    cpu_exec_init_all(0);
     /* NOTE: we need to init the CPU at this stage to get
        qemu_host_page_size */
     env = cpu_init(cpu_model);

Modified: trunk/exec-all.h
===================================================================

exec-all.h +2 -35
@@ -56,12 +56,6 @@
 typedef void (GenOpFunc2)(long, long);
 typedef void (GenOpFunc3)(long, long, long);
 
-#if defined(TARGET_I386)
-
-void optimize_flags_init(void);
-
-#endif
-
 extern FILE *logfile;
 extern int loglevel;
 
@@ -105,32 +99,8 @@
 #define CODE_GEN_PHYS_HASH_BITS     15
 #define CODE_GEN_PHYS_HASH_SIZE     (1 << CODE_GEN_PHYS_HASH_BITS)
 
-/* maximum total translate dcode allocated */
+#define MIN_CODE_GEN_BUFFER_SIZE     (1024 * 1024)
 
-/* NOTE: the translated code area cannot be too big because on some
-   archs the range of "fast" function calls is limited. Here is a
-   summary of the ranges:
-
-   i386  : signed 32 bits
-   arm   : signed 26 bits
-   ppc   : signed 24 bits
-   sparc : signed 32 bits
-   alpha : signed 23 bits
-*/
-
-#if defined(__alpha__)
-#define CODE_GEN_BUFFER_SIZE     (2 * 1024 * 1024)
-#elif defined(__ia64)
-#define CODE_GEN_BUFFER_SIZE     (4 * 1024 * 1024)	/* range of addl */
-#elif defined(__powerpc__)
-#define CODE_GEN_BUFFER_SIZE     (6 * 1024 * 1024)
-#else
-/* XXX: make it dynamic on x86 */
-#define CODE_GEN_BUFFER_SIZE     (64 * 1024 * 1024)
-#endif
-
-//#define CODE_GEN_BUFFER_SIZE     (128 * 1024)
-
 /* estimated block size for TB allocation */
 /* XXX: use a per code average code fragment size and modulate it
    according to the host CPU */
@@ -140,8 +110,6 @@
 #define CODE_GEN_AVG_BLOCK_SIZE 64
 #endif
 
-#define CODE_GEN_MAX_BLOCKS    (CODE_GEN_BUFFER_SIZE / CODE_GEN_AVG_BLOCK_SIZE)
-
 #if defined(__powerpc__) || defined(__x86_64__) || defined(__arm__)
 #define USE_DIRECT_JUMP
 #endif
@@ -210,9 +178,8 @@
                   target_ulong phys_pc, target_ulong phys_page2);
 
 extern TranslationBlock *tb_phys_hash[CODE_GEN_PHYS_HASH_SIZE];
-
-extern uint8_t code_gen_buffer[CODE_GEN_BUFFER_SIZE];
 extern uint8_t *code_gen_ptr;
+extern int code_gen_max_blocks;
 
 #if defined(USE_DIRECT_JUMP)
 

Modified: trunk/exec.c
===================================================================

exec.c +68 -18

139 lines not on this page · raw message

Modified: trunk/linux-user/main.c
===================================================================

linux-user/main.c +1 -0
@@ -2115,6 +2115,7 @@
         cpu_model = "any";
 #endif
     }
+    cpu_exec_init_all(0);
     /* NOTE: we need to init the CPU at this stage to get
        qemu_host_page_size */
     env = cpu_init(cpu_model);

Modified: trunk/target-i386/cpu.h
===================================================================

target-i386/cpu.h +2 -0
@@ -723,6 +723,8 @@
     return (env->hflags & HF_CPL_MASK) == 3 ? 1 : 0;
 }
 
+void optimize_flags_init(void);
+
 typedef struct CCTable {
     int (*compute_all)(void); /* return all the flags */
     int (*compute_c)(void);  /* return the C flag */

Modified: trunk/vl.c
===================================================================

vl.c +13 -1
@@ -7378,6 +7378,7 @@
     QEMU_OPTION_old_param,
     QEMU_OPTION_clock,
     QEMU_OPTION_startdate,
+    QEMU_OPTION_tb_size,
 };
 
 typedef struct QEMUOption {
@@ -7489,6 +7490,7 @@
 #endif
     { "clock", HAS_ARG, QEMU_OPTION_clock },
     { "startdate", HAS_ARG, QEMU_OPTION_startdate },
+    { "tb-size", HAS_ARG, QEMU_OPTION_tb_size },
     { NULL },
 };
 
@@ -7697,6 +7699,7 @@
     const char *usb_devices[MAX_USB_CMDLINE];
     int usb_devices_index;
     int fds[2];
+    int tb_size;
     const char *pid_file = NULL;
     VLANState *vlan;
 
@@ -7768,8 +7771,9 @@
     hda_index = -1;
 
     nb_nics = 0;
-    /* default mac address of the first network interface */
 
+    tb_size = 0;
+    
     optind = 1;
     for(;;) {
         if (optind >= argc)
@@ -8296,6 +8300,11 @@
                     }
                 }
                 break;
+            case QEMU_OPTION_tb_size:
+                tb_size = strtol(optarg, NULL, 0);
+                if (tb_size < 0)
+                    tb_size = 0;
+                break;
             }
         }
     }
@@ -8467,6 +8476,9 @@
         exit(1);
     }
 
+    /* init the dynamic translator */
+    cpu_exec_init_all(tb_size * 1024 * 1024);
+
     bdrv_init();
 
     /* we always create the cdrom drive, even if no disk is there */
#1 lore raw
Quoted 3 lines · Fabrice Bellard

+        code_gen_buffer = mmap(NULL, code_gen_buffer_size,
+                               PROT_WRITE | PROT_READ | PROT_EXEC,
+                               flags, -1, 0);

I'd expect this to cause a significant performance regression on hosts that have limited branch range (i.e. everything except x86). The mmap region is almost never close to the application text segment, so all helper calls have to be indirect.

Paul

#2 lore raw
Quoted 6 lines · Paul Brook

exec.c line 352

Quoted 3 lines · Fabrice Bellard
exec.c +3 -0
+        code_gen_buffer = mmap(NULL, code_gen_buffer_size,
+                               PROT_WRITE | PROT_READ | PROT_EXEC,
+                               flags, -1, 0);

I'd expect this to cause a significant performance regression on hosts that have limited branch range (i.e. everything except x86). The mmap region is almost never close to the application text segment, so all helper calls have to be indirect.

I knew that when I did the patch, but having a dynamic size on x86 hosts prevails.

The other hosts can still implement hacks if they really need to, either by reserving a huge data in BSS as it was done before or by using the proc/x/maps entries to compute a possible mmap() address. IMHO I think this is unnecessary as helpers should be the exception.

Fabrice.

#3 lore raw
In reply to Fabrice Bellard
Quoted 8 lines · Fabrice Bellard

Revision: 4600

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4600

Author: bellard
Date: 2008-05-28 12:30:31 +0000 (Wed, 28 May 2008)

Log Message:
-----------
variable dynamic translation buffer size

This commit broke sparc-linux-user, tested on amd64 host:
./obj-amd64/sparc-linux-user/qemu-sparc -L ../qemu-tests/usr/local/gnemul/qemu-sparc ../qemu-tests/sparc/ash -help
qemu: uncaught target signal 11 (Segmentation fault) - exiting

While expected result is:
Illegal option -h