From 36aa7545b0764b6304af7d8dee1b5536eda33f77 Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Fri, 6 Sep 2024 12:43:54 +0200 Subject: [PATCH] qemu/main: Make GC heap size configurable on a per-arch basis. In certain circumstances depending on the code size, the `deflate_decompress` test fails on both ARM and RV32 with a memory allocation failure error. The issue is mitigated by having a larger GC heap, in this case around 20 KBytes more than the original 100 KBytes default. This commit makes the GC heap size configurable on a per-arch basis, with both ARM and RV32 using the enlarged 120 KBytes heap. Signed-off-by: Alessandro Gatti --- ports/qemu/Makefile | 4 ++++ ports/qemu/README.md | 2 ++ ports/qemu/main.c | 8 +++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ports/qemu/Makefile b/ports/qemu/Makefile index ea0bef814..c8c07965f 100644 --- a/ports/qemu/Makefile +++ b/ports/qemu/Makefile @@ -19,9 +19,11 @@ QSTR_DEFS = qstrdefsport.h MICROPY_ROM_TEXT_COMPRESSION ?= 1 ifeq ($(QEMU_ARCH),arm) +MICROPY_HEAP_SIZE ?= 122880 FROZEN_MANIFEST ?= "require('unittest'); freeze('test-frzmpy', ('frozen_asm_thumb.py', 'frozen_const.py', 'frozen_viper.py', 'native_frozen_align.py'))" endif ifeq ($(QEMU_ARCH),riscv32) +MICROPY_HEAP_SIZE ?= 122880 FROZEN_MANIFEST ?= "require('unittest'); freeze('test-frzmpy', ('frozen_asm_rv32.py', 'frozen_const.py', 'frozen_viper.py', 'native_frozen_align.py'))" endif @@ -29,6 +31,8 @@ endif include $(TOP)/py/py.mk include $(TOP)/extmod/extmod.mk +CFLAGS += -DMICROPY_HEAP_SIZE=$(MICROPY_HEAP_SIZE) + ################################################################################ # ARM specific settings diff --git a/ports/qemu/README.md b/ports/qemu/README.md index 9274bcc4e..70edf97f5 100644 --- a/ports/qemu/README.md +++ b/ports/qemu/README.md @@ -122,3 +122,5 @@ The following options can be specified on the `make` command line: - `QEMU_DEBUG_ARGS`: defaults to `-s` (gdb on TCP port 1234), but can be overridden with different qemu gdb arguments. - `QEMU_DEBUG_EXTRA`: extra options to pass to qemu when `QEMU_DEBUG=1` is used. +- `MICROPY_HEAP_SIZE`: pass in an optional value (in bytes) for overriding the GC + heap size used by the port. diff --git a/ports/qemu/main.c b/ports/qemu/main.c index dff55058e..75c6fe4cd 100644 --- a/ports/qemu/main.c +++ b/ports/qemu/main.c @@ -34,14 +34,16 @@ #include "shared/runtime/gchelper.h" #include "shared/runtime/pyexec.h" -#define HEAP_SIZE (100 * 1024) +#if MICROPY_HEAP_SIZE <= 0 +#error MICROPY_HEAP_SIZE must be a positive integer. +#endif -static uint32_t gc_heap[HEAP_SIZE / sizeof(uint32_t)]; +static uint32_t gc_heap[MICROPY_HEAP_SIZE / sizeof(uint32_t)]; int main(int argc, char **argv) { mp_stack_ctrl_init(); mp_stack_set_limit(10240); - gc_init(gc_heap, (char *)gc_heap + HEAP_SIZE); + gc_init(gc_heap, (char *)gc_heap + MICROPY_HEAP_SIZE); for (;;) { mp_init();