summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Gatti <a.gatti@frob.it>2024-09-06 12:43:54 +0200
committerDamien George <damien@micropython.org>2025-01-02 11:51:50 +1100
commit36aa7545b0764b6304af7d8dee1b5536eda33f77 (patch)
treec856b20087acbabf24eb7295a59a6a2d034a45fa
parent268acb714dd79fa5eeeb82c1fca022bc4ea126b7 (diff)
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 <a.gatti@frob.it>
-rw-r--r--ports/qemu/Makefile4
-rw-r--r--ports/qemu/README.md2
-rw-r--r--ports/qemu/main.c8
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();