emulator: modify RAM preallocation logic 95/22995/2
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 16 Jun 2014 03:18:43 +0000 (12:18 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 16 Jun 2014 05:02:16 +0000 (14:02 +0900)
Change-Id: Idfe6eb74f35fa13c9518dedb18adec3b9ed1de20
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
hw/i386/pc_piix.c
util/oslib-posix.c
util/oslib-win32.c
vl.c

index 8050a67be76e07e7d825ff2d6a67828f52570b24..ff92135fc0447e1b7b54adb41911c2c1f0a41725 100644 (file)
@@ -58,7 +58,7 @@
 void pc_init_pci(QEMUMachineInitArgs *args);
 
 extern MemoryRegion *global_ram_memory; 
-extern void *preallocated_ptr;
+extern void *preallocated_ram_ptr;
 #endif
 
 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
@@ -162,13 +162,6 @@ static void pc_init1(QEMUMachineInitArgs *args,
 
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
-#ifdef CONFIG_MARU
-        // W/A for allocate larger continuous heap.
-        // see vl.c
-        if(preallocated_ptr != NULL) {
-            g_free(preallocated_ptr);
-        }
-#endif
         fw_cfg = pc_memory_init(system_memory,
                 args->kernel_filename, args->kernel_cmdline,
                 args->initrd_filename,
index d891d65f2315e204cf84442875869341c9222f47..11ff7e2fba82066d73b9209469210f7af50432b0 100644 (file)
@@ -139,9 +139,17 @@ void *qemu_memalign(size_t alignment, size_t size)
     return ptr;
 }
 
+#ifdef CONFIG_MARU
+void *preallocated_ram_ptr = NULL;
+#endif
 /* alloc shared memory pages */
 void *qemu_anon_ram_alloc(size_t size)
 {
+#ifdef CONFIG_MARU
+    if (preallocated_ram_ptr) {
+        return preallocated_ram_ptr;
+    }
+#endif
     size_t align = QEMU_VMALLOC_ALIGN;
     size_t total = size + align - getpagesize();
     void *ptr = mmap(0, total, PROT_READ | PROT_WRITE,
index 67746cc5e4ce7941445bcdf2d01ca619fb401456..e03c9fe6ca715e21053bab49b45f69b6d43bf3e0 100644 (file)
@@ -170,6 +170,9 @@ void *qemu_memalign(size_t alignment, size_t size)
     return ptr;
 }
 
+#ifdef CONFIG_MARU
+void *preallocated_ram_ptr = NULL;
+#endif
 void *qemu_anon_ram_alloc(size_t size)
 {
     void *ptr;
@@ -177,6 +180,11 @@ void *qemu_anon_ram_alloc(size_t size)
     /* FIXME: this is not exactly optimal solution since VirtualAlloc
        has 64Kb granularity, but at least it guarantees us that the
        memory is page aligned. */
+#ifdef CONFIG_MARU
+    if (preallocated_ram_ptr) {
+        return preallocated_ram_ptr;
+    }
+#endif
     ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
     trace_qemu_anon_ram_alloc(size, ptr);
     return ptr;
diff --git a/vl.c b/vl.c
index 73495eed33a2f26cca1d847c61d4c95f7cec4dce..e424fe82a676711c1fba17557b15a009f24bd4fa 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -2987,8 +2987,9 @@ out:
 
 #ifdef CONFIG_MARU
 int use_qemu_display = 0; //0:use tizen qemu sdl, 1:use original qemu sdl
+
 // W/A for preserve larger continuous heap for RAM.
-void *preallocated_ptr = 0;
+extern void *preallocated_ram_ptr;
 #endif
 
 int main(int argc, char **argv, char **envp)
@@ -4080,8 +4081,7 @@ int main(int argc, char **argv, char **envp)
     }
 
 #if defined(CONFIG_MARU)
-    // W/A for preserve larger continuous heap for RAM.
-    preallocated_ptr = g_malloc(ram_size);
+    preallocated_ram_ptr = qemu_anon_ram_alloc(ram_size);
 
     kernel_cmdline = qemu_opt_get(qemu_get_machine_opts(), "append");
     // Returned variable points different address from input variable.