mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-17 07:12:06 +08:00
interpreters/python: add patch to set _PyRuntime
section
By setting a specific region for the `_PyRuntime` structure, it is possible to move it to the external memory, for instance, freeing the internal memory (this structure occupies around 140KiB).
This commit is contained in:
@@ -80,6 +80,7 @@ $(CPYTHON_UNPACKNAME): $(CPYTHON_ZIP)
|
|||||||
$(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0009-include-nuttx-sys-select-header-to-define-FD_SETSIZE.patch
|
$(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0009-include-nuttx-sys-select-header-to-define-FD_SETSIZE.patch
|
||||||
$(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0010-check-for-the-d_ino-member-of-the-structure-dirent.patch
|
$(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0010-check-for-the-d_ino-member-of-the-structure-dirent.patch
|
||||||
$(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0011-avoid-redefinition-warning-if-UNUSED-is-already-defi.patch
|
$(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0011-avoid-redefinition-warning-if-UNUSED-is-already-defi.patch
|
||||||
|
$(Q) patch -p1 -d $(CPYTHON_UNPACKNAME) < patch$(DELIM)0012-hack-place-_PyRuntime-structure-into-PSRAM-bss-regio.patch
|
||||||
|
|
||||||
$(HOSTPYTHON):
|
$(HOSTPYTHON):
|
||||||
mkdir -p $(HOSTBUILD)
|
mkdir -p $(HOSTBUILD)
|
||||||
|
@@ -0,0 +1,54 @@
|
|||||||
|
From d1e903f516849c535455904b3c3f8a33665c1a88 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Ivan Grokhotkov <ivan@espressif.com>
|
||||||
|
Date: Wed, 23 Oct 2024 16:52:52 +0200
|
||||||
|
Subject: [PATCH 12/12] hack: place _PyRuntime structure into PSRAM bss region,
|
||||||
|
initialize later
|
||||||
|
|
||||||
|
_PyRuntime occupies around 100kB of RAM in .data region, making it
|
||||||
|
hard to fit the interpreter into the available static RAM.
|
||||||
|
This patch moves it into PSRAM using section attribute. Normally
|
||||||
|
we shouldn't need this as we can specify placements in ldfragments,
|
||||||
|
however in this specific case I couldn't get it to work.
|
||||||
|
Since the structure is now in .bss, add a function which will assign
|
||||||
|
it the initial value.
|
||||||
|
|
||||||
|
The proper fix might be to support .data segment on PSRAM in IDF,
|
||||||
|
as well as to fix whatever ldgen issue prevents this variable from
|
||||||
|
being moved to PSRAM.
|
||||||
|
|
||||||
|
Co-authored-by: Tiago Medicci Serrano <tiago.medicci@espressif.com>
|
||||||
|
---
|
||||||
|
Python/pylifecycle.c | 11 +++++++++++
|
||||||
|
1 file changed, 11 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
|
||||||
|
index 1701a1cd217..2a8e544f0ac 100644
|
||||||
|
--- a/Python/pylifecycle.c
|
||||||
|
+++ b/Python/pylifecycle.c
|
||||||
|
@@ -102,12 +102,23 @@ __attribute__((
|
||||||
|
_PyRuntimeState _PyRuntime
|
||||||
|
#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
|
||||||
|
__attribute__ ((section (".PyRuntime")))
|
||||||
|
+#elif defined(ESP_PLATFORM)
|
||||||
|
+__attribute__ ((section (".PyRuntime")))
|
||||||
|
#endif
|
||||||
|
= _PyRuntimeState_INIT(_PyRuntime, _Py_Debug_Cookie);
|
||||||
|
_Py_COMP_DIAG_POP
|
||||||
|
|
||||||
|
static int runtime_initialized = 0;
|
||||||
|
|
||||||
|
+void _PyRuntime_Early_Init(void) {
|
||||||
|
+#if defined(ESP_PLATFORM)
|
||||||
|
+ // Normally, _PyRuntime is in .data and is initialized by the C runtime.
|
||||||
|
+ // This function allows us to place it into external RAM .bss section
|
||||||
|
+ // and initialize it manually, saving some internal RAM.
|
||||||
|
+ _PyRuntime = (struct pyruntimestate) _PyRuntimeState_INIT(_PyRuntime, _Py_Debug_Cookie);
|
||||||
|
+#endif
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
PyStatus
|
||||||
|
_PyRuntime_Initialize(void)
|
||||||
|
{
|
||||||
|
--
|
||||||
|
2.47.1
|
||||||
|
|
Reference in New Issue
Block a user