Skip to content

Commit 11ed6f8

Browse files
committed
Optimize out allocation moving code on boards that don't need it.
When no features are enabled that use movable allocations, supervisor_move_memory() is not needed.
1 parent 9ecaa16 commit 11ed6f8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

supervisor/shared/memory.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "supervisor/shared/display.h"
3434

3535
enum {
36-
CIRCUITPY_SUPERVISOR_ALLOC_COUNT =
36+
CIRCUITPY_SUPERVISOR_IMMOVABLE_ALLOC_COUNT =
3737
// stack + heap
3838
2
3939
#ifdef EXTERNAL_FLASH_DEVICES
@@ -42,6 +42,9 @@ enum {
4242
#if CIRCUITPY_USB_MIDI
4343
+ 1
4444
#endif
45+
,
46+
CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT =
47+
0
4548
#if CIRCUITPY_DISPLAYIO
4649
#if CIRCUITPY_TERMINALIO
4750
+ 1
@@ -57,6 +60,8 @@ enum {
5760
#endif
5861
)
5962
#endif
63+
,
64+
CIRCUITPY_SUPERVISOR_ALLOC_COUNT = CIRCUITPY_SUPERVISOR_IMMOVABLE_ALLOC_COUNT + CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT
6065
};
6166

6267
// The lowest two bits of a valid length are always zero, so we can use them to mark an allocation
@@ -147,6 +152,9 @@ static supervisor_allocation_node* find_hole(supervisor_allocation_node* node, s
147152
}
148153

149154
static supervisor_allocation_node* allocate_memory_node(uint32_t length, bool high, bool movable) {
155+
if (CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT == 0) {
156+
assert(!movable);
157+
}
150158
// supervisor_move_memory() currently does not support movable allocations on the high side, it
151159
// must be extended first if this is ever needed.
152160
assert(!(high && movable));
@@ -223,6 +231,11 @@ size_t get_allocation_length(supervisor_allocation* allocation) {
223231
}
224232

225233
void supervisor_move_memory(void) {
234+
// This whole function is not needed when there are no movable allocations, let it be optimized
235+
// out.
236+
if (CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT == 0) {
237+
return;
238+
}
226239
// This must be called exactly after freeing the heap, so that the embedded allocations, if any,
227240
// are now in the free region.
228241
assert(MP_STATE_VM(first_embedded_allocation) == NULL || (low_head < MP_STATE_VM(first_embedded_allocation) && MP_STATE_VM(first_embedded_allocation) < high_head));

0 commit comments

Comments
 (0)