Skip to content

Commit a10626b

Browse files
committed
extmod/zephyr_kernel: Use same priority for spawned threads as creating thread.
Root cause investigation revealed that spawned threads had higher priority (0) than main thread (1), causing z_reschedule() to immediately preempt during GIL bounce windows (MP_THREAD_GIL_EXIT → MP_THREAD_GIL_ENTER). When main thread executes multi-step operations like bytearray.append() and bounces the GIL, higher priority waiting threads would immediately preempt, acquire the GIL, and corrupt shared data structures. Fix matches ports/zephyr proven approach: use k_thread_priority_get() to inherit priority from creating thread, ensuring equal priority prevents immediate preemption during GIL bounce. Signed-off-by: Andrew Leech <andrew@alelec.net>
1 parent d018d84 commit a10626b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+9310
-4
lines changed

extmod/zephyr_kernel/kernel/mpthread_zephyr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void z_ready_thread(struct k_thread *thread);
4444

4545
#define MP_THREAD_MIN_STACK_SIZE (4 * 1024)
4646
#define MP_THREAD_DEFAULT_STACK_SIZE (MP_THREAD_MIN_STACK_SIZE + 1024)
47-
#define MP_THREAD_PRIORITY K_PRIO_PREEMPT(0) // Higher priority than main (1)
47+
#define MP_THREAD_PRIORITY (k_thread_priority_get(k_current_get())) // Same priority as creating thread (matches ports/zephyr)
4848
#define MP_THREAD_MAXIMUM_USER_THREADS (5) // Reduced from 8 to save RAM (allows mutate_bytearray.py with 4 threads)
4949

5050
// FPU context size validation

gdb_hardfault_capture.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Breakpoint 1 at 0x80706f8: file stm32_it.c, line 150.
2+
Note: automatically using hardware breakpoints for read-only addresses.
3+
4+
Program received signal SIGSEGV, Segmentation fault.
5+
0x080718c4 in usbd_msc_IsReady (warning: Could not fetch required FPCCR content. Further unwinding is impossible.
6+
lun=148 '\224') at usbd_msc_interface.c:250
7+
250 return -1;
8+
(gdb) A debugging session is active.
9+
10+
Inferior 1 [Remote target] will be detached.
11+
12+
Quit anyway? (y or n) [answered Y; input not from terminal]
13+
Detaching from program: /home/corona/micropython/ports/stm32/build-NUCLEO_F429ZI/firmware.elf, Remote target
14+
[Inferior 1 (Remote target) detached]

gdb_stack_interactive.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Breakpoint 1 at 0x8070844: file stm32_it.c, line 227.
2+
Note: automatically using hardware breakpoints for read-only addresses.
3+
4+
Program received signal SIGSEGV, Segmentation fault.
5+
0x08071908 in usbd_msc_Write (lun=<optimized out>, buf=0x2000c594 <usb_device+4108> "", blk_addr=0, blk_len=<optimized out>) at usbd_msc_interface.c:310
6+
310 return -1;
7+
(gdb) A debugging session is active.
8+
9+
Inferior 1 [Remote target] will be detached.
10+
11+
Quit anyway? (y or n) [answered Y; input not from terminal]
12+
Detaching from program: /home/corona/micropython/ports/stm32/build-NUCLEO_F429ZI/firmware.elf, Remote target
13+
[Inferior 1 (Remote target) detached]

gdb_stack_interactive_output.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
GNU gdb (Arm GNU Toolchain 14.3.Rel1 (Build arm-14.174)) 15.2.90.20241229-git
2+
Copyright (C) 2024 Free Software Foundation, Inc.
3+
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
4+
This is free software: you are free to change and redistribute it.
5+
There is NO WARRANTY, to the extent permitted by law.
6+
Type "show copying" and "show warranty" for details.
7+
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-none-eabi".
8+
Type "show configuration" for configuration details.
9+
For bug reporting instructions, please see:
10+
<https://bugs.linaro.org/>.
11+
Find the GDB manual and other documentation resources online at:
12+
<http://www.gnu.org/software/gdb/documentation/>.
13+
14+
For help, type "help".
15+
Type "apropos word" to search for commands related to "word"...
16+
Reading symbols from ports/stm32/build-NUCLEO_F429ZI/firmware.elf...
17+
0x08071908 in usbd_msc_Write (lun=<optimized out>,
18+
buf=0x2000c594 <usb_device+4108> "", blk_addr=0, blk_len=<optimized out>)
19+
at usbd_msc_interface.c:310
20+
310 return -1;
21+
Warning: 'set logging on', an alias for the command 'set logging enabled', is deprecated.
22+
Use 'set logging enabled on'.
23+
24+
Breakpoint 1 at 0x8070844: file stm32_it.c, line 227.
25+
Note: automatically using hardware breakpoints for read-only addresses.
26+
27+
Program received signal SIGSEGV, Segmentation fault.
28+
0x08071908 in usbd_msc_Write (lun=<optimized out>, buf=0x2000c594 <usb_device+4108> "", blk_addr=0, blk_len=<optimized out>) at usbd_msc_interface.c:310
29+
310 return -1;
30+
(gdb) A debugging session is active.
31+
32+
Inferior 1 [Remote target] will be detached.
33+
34+
Quit anyway? (y or n) [answered Y; input not from terminal]
35+
Detaching from program: /home/corona/micropython/ports/stm32/build-NUCLEO_F429ZI/firmware.elf, Remote target
36+
[Inferior 1 (Remote target) detached]

gdb_stack_sentinel_check.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Breakpoint 1 at 0x8070844: file stm32_it.c, line 227.
2+
Note: automatically using hardware breakpoints for read-only addresses.
3+
4+
Program received signal SIGSEGV, Segmentation fault.
5+
0x08071908 in usbd_msc_Write (lun=<optimized out>, buf=0x2000c594 <usb_device+4108> "", blk_addr=0, blk_len=<optimized out>) at usbd_msc_interface.c:310
6+
310 return -1;
7+
(gdb) A debugging session is active.
8+
9+
Inferior 1 [Remote target] will be detached.
10+
11+
Quit anyway? (y or n) [answered Y; input not from terminal]
12+
Detaching from program: /home/corona/micropython/ports/stm32/build-NUCLEO_F429ZI/firmware.elf, Remote target
13+
[Inferior 1 (Remote target) detached]

gdb_thread_fault.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Function "mp_thread_create_ex" not defined.
2+
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
3+
/home/corona/mpy/thread/capture_thread_fault.gdb:19: Error in sourced command file:
4+
Argument required (one or more breakpoint numbers).
5+
(gdb) A debugging session is active.
6+
7+
Inferior 1 [Remote target] will be detached.
8+
9+
Quit anyway? (y or n) [answered Y; input not from terminal]
10+
Detaching from program: /home/corona/micropython/ports/stm32/build-NUCLEO_F429ZI/firmware.elf, Remote target
11+
[Inferior 1 (Remote target) detached]

lib/tinyusb

Submodule tinyusb updated 616 files

lib/zephyr

micropython-memory.zip

13.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)