From: SeokYeon Hwang Date: Mon, 16 Jun 2014 03:18:43 +0000 (+0900) Subject: emulator: modify RAM preallocation logic X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~228^2^2~145^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=182b9a44a4df628515135db9869319a34ccb296f;p=sdk%2Femulator%2Fqemu.git emulator: modify RAM preallocation logic Change-Id: Idfe6eb74f35fa13c9518dedb18adec3b9ed1de20 Signed-off-by: SeokYeon Hwang --- diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 8050a67be7..ff92135fc0 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -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, diff --git a/util/oslib-posix.c b/util/oslib-posix.c index d891d65f23..11ff7e2fba 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -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, diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 67746cc5e4..e03c9fe6ca 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -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 73495eed33..e424fe82a6 100644 --- 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.