|
| 1 | +From d1e903f516849c535455904b3c3f8a33665c1a88 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ivan Grokhotkov < [email protected]> |
| 3 | +Date: Wed, 23 Oct 2024 16:52:52 +0200 |
| 4 | +Subject: [PATCH 12/12] hack: place _PyRuntime structure into PSRAM bss region, |
| 5 | + initialize later |
| 6 | + |
| 7 | +_PyRuntime occupies around 100kB of RAM in .data region, making it |
| 8 | +hard to fit the interpreter into the available static RAM. |
| 9 | +This patch moves it into PSRAM using section attribute. Normally |
| 10 | +we shouldn't need this as we can specify placements in ldfragments, |
| 11 | +however in this specific case I couldn't get it to work. |
| 12 | +Since the structure is now in .bss, add a function which will assign |
| 13 | +it the initial value. |
| 14 | + |
| 15 | +The proper fix might be to support .data segment on PSRAM in IDF, |
| 16 | +as well as to fix whatever ldgen issue prevents this variable from |
| 17 | +being moved to PSRAM. |
| 18 | + |
| 19 | +Co-authored-by: Tiago Medicci Serrano < [email protected]> |
| 20 | +--- |
| 21 | + Python/pylifecycle.c | 11 +++++++++++ |
| 22 | + 1 file changed, 11 insertions(+) |
| 23 | + |
| 24 | +diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c |
| 25 | +index 1701a1cd217..2a8e544f0ac 100644 |
| 26 | +--- a/Python/pylifecycle.c |
| 27 | ++++ b/Python/pylifecycle.c |
| 28 | +@@ -102,12 +102,23 @@ __attribute__(( |
| 29 | + _PyRuntimeState _PyRuntime |
| 30 | + #if defined(__linux__) && (defined(__GNUC__) || defined(__clang__)) |
| 31 | + __attribute__ ((section (".PyRuntime"))) |
| 32 | ++#elif defined(ESP_PLATFORM) |
| 33 | ++__attribute__ ((section (".PyRuntime"))) |
| 34 | + #endif |
| 35 | + = _PyRuntimeState_INIT(_PyRuntime, _Py_Debug_Cookie); |
| 36 | + _Py_COMP_DIAG_POP |
| 37 | + |
| 38 | + static int runtime_initialized = 0; |
| 39 | + |
| 40 | ++void _PyRuntime_Early_Init(void) { |
| 41 | ++#if defined(ESP_PLATFORM) |
| 42 | ++ // Normally, _PyRuntime is in .data and is initialized by the C runtime. |
| 43 | ++ // This function allows us to place it into external RAM .bss section |
| 44 | ++ // and initialize it manually, saving some internal RAM. |
| 45 | ++ _PyRuntime = (struct pyruntimestate) _PyRuntimeState_INIT(_PyRuntime, _Py_Debug_Cookie); |
| 46 | ++#endif |
| 47 | ++} |
| 48 | ++ |
| 49 | + PyStatus |
| 50 | + _PyRuntime_Initialize(void) |
| 51 | + { |
| 52 | +-- |
| 53 | +2.47.1 |
| 54 | + |
0 commit comments