Skip to content

Commit f704375

Browse files
Daniel Camporadpgeorge
authored andcommitted
esp32: Trace the registers when doing a gc collect. Also make it thread ready.
1 parent dc82def commit f704375

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

esp32/gccollect.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* The MIT License (MIT)
77
*
88
* Copyright (c) 2014 Damien P. George
9+
* Copyright (c) 2017 Pycom Limited
910
*
1011
* Permission is hereby granted, free of charge, to any person obtaining a copy
1112
* of this software and associated documentation files (the "Software"), to deal
@@ -28,29 +29,38 @@
2829

2930
#include <stdio.h>
3031

32+
#include "py/mpconfig.h"
33+
#include "py/mpstate.h"
3134
#include "py/gc.h"
35+
#include "py/mpthread.h"
3236
#include "gccollect.h"
37+
#include "soc/cpu.h"
38+
#include "xtensa/hal.h"
3339

34-
// As we do not have control over the application entry point, there is no way
35-
// to figure out the real stack base on runtime, so it needs to be hardcoded
36-
#define STACK_END 0x40000000
3740

38-
mp_uint_t gc_helper_get_regs_and_sp(mp_uint_t *regs) {
39-
// TODO properly
40-
return (mp_uint_t)regs;
41+
static void gc_collect_inner(int level) {
42+
if (level < XCHAL_NUM_AREGS / 8) {
43+
gc_collect_inner(level + 1);
44+
if (level != 0) {
45+
return;
46+
}
47+
}
48+
49+
if (level == XCHAL_NUM_AREGS / 8) {
50+
// get the sp
51+
volatile uint32_t sp = (uint32_t)get_sp();
52+
gc_collect_root((void**)sp, ((mp_uint_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t));
53+
return;
54+
}
55+
56+
// trace root pointers from any threads
57+
#if MICROPY_PY_THREAD
58+
mp_thread_gc_others();
59+
#endif
4160
}
4261

4362
void gc_collect(void) {
44-
// start the GC
4563
gc_collect_start();
46-
47-
// get the registers and the sp
48-
mp_uint_t regs[8];
49-
mp_uint_t sp = gc_helper_get_regs_and_sp(regs);
50-
51-
// trace the stack, including the registers (since they live on the stack in this function)
52-
gc_collect_root((void**)sp, (STACK_END - sp) / sizeof(uint32_t));
53-
54-
// end the GC
64+
gc_collect_inner(0);
5565
gc_collect_end();
5666
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy