huojianchaoyy opened a new pull request, #22093:
URL: https://github.com/apache/nuttx/pull/22093

   *Note: Please adhere to [Contributing 
Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## Summary
   
   Assert and coredump fixes from Xiaomi Vela:
   
   - **assert: move the coredump after panic notify**: the board crash dump and 
the coredump, which can take long, now run after the `PANIC_KERNEL_FINAL` 
notifiers (rptun, rpmsg dump, serial gdbstub) instead of before them.
   - **assert.c:fix bug for dump_core_info**: pass it the arguments the crash 
dump and the per-task coredump use.
   - **assert: flush dcache before panic other CPU**: flush before 
`PANIC_KERNEL_FINAL`, where other processors may be told about the panic and 
read the shared memory; the flush moves there from `reset_board()`.
   - **libs/libc/assert: add LIBC_ASSERT_CUSTOM**: leave `__assert()` out of 
libc so that a custom one can be provided, e.g. for code of another core linked 
into the same image.
   - **sched: add PERCPU_METHOD to help improve the percpu locate & 
performace**: new `include/nuttx/percpu.h` with macros to define and access 
per-CPU data (`DEFINE_PER_CPU()`, `per_cpu_var()`, `this_cpu_var()`, and `_SMP` 
variants that collapse to one entry without SMP). `PERCPU_METHOD` chooses the 
layout; `PERCPU_ARRAY`, the only one, keeps arrays of `CONFIG_NCPUS` entries.
   - **assert.c: limit stack print length**: `CONFIG_ARCH_STACKDUMP_MAX_LENGTH` 
now also limits the dump from a known sp, and its default changes from 0 (no 
limit) to 4096; **assert.c:use 'top' ...** then drops the extra variable.
   - **sched/percpu: remove irq.h in percpu.h to avoide loop depend.**: 
`nuttx/sched.h` includes `percpu.h`.
   - **sched/misc: replace DEADLOCK_MAX with CONFIG_ARCH_DEADLOCKDUMP_MAX**: 
the number of deadlocked threads (mutex or spinlock) that `dump_deadlock()` 
collects, 8 by default as before.
   - **sched/misc/assert: change panic info dump to percpu**: `g_last_regs` and 
`g_cpu_paused` are defined and accessed with the per-CPU macros; `last_regs_t` 
is the register context of one CPU.
   - **sched/assert: Fix stack_dump boundary check**: a read that starts below 
`stack_top` could end past it.
   - **sched/assert: cover exception context in stack dump**: back off a whole 
register context below sp instead of 8 words, so an offline unwinder can cross 
the exception frame.
   - **sched/assert: silence ASAN for stack_dump()**: on sim with ASAN the walk 
over the whole stack hit the redzones between frames.
   - **sched/assert: spin after board_reset()**: `board_reset()` may return 
(asynchronous reset); `reset_board()` must not.
   - **assert: gate all-thread backtrace dump behind 
CONFIG_SCHED_DUMP_BACKTRACE** (default y).
   - **sched/coredump: mark multi-call helpers as noinline to save Flash**.
   
   One follow-up fix: **libs/libc/assert: add the license header to Kconfig**, 
the new `libs/libc/assert/Kconfig` had none.
   
   ## Impact
   
   - With a coredump method configured, the `PANIC_KERNEL_FINAL` notifiers run 
before the coredump.
   - `reset_board()` no longer flushes the dcache; the flush is done before 
`PANIC_KERNEL_FINAL`.
   - `ARCH_STACKDUMP_MAX_LENGTH` defaults to 4096 instead of 0, so a stack dump 
stops after 4 KiB.
   - New header `include/nuttx/percpu.h`, included by `nuttx/sched.h`, and the 
choice `PERCPU_METHOD` (`PERCPU_ARRAY`, the same arrays as before).
   - New Kconfig options, all keeping the current behavior by default: 
`LIBC_ASSERT_CUSTOM` (n), `ARCH_DEADLOCKDUMP_MAX` (8), `SCHED_DUMP_BACKTRACE` 
(y).
   - The stack dump from a known sp starts a register context lower, so it is a 
few lines longer.
   
   ## Testing
   
   Host: Ubuntu 22.04 x86_64, GCC 13.4.0, Arm GNU Toolchain 13.2.rel1, CMake 
3.23 + Ninja. Base: master 11c71e16384.
   `./tools/checkpatch.sh -c -u -m -g HEAD~17..HEAD` passes.
   
   `mps2-an500:nsh` with `CONFIG_COREDUMP=y CONFIG_BOARD_COREDUMP_SYSLOG=y 
CONFIG_ARCH_STACKDUMP=y`, bus fault with `mw 0xf0000000=1` on QEMU:
   
   - User stack dump: master starts at sp - 32 (`0x60008840`), this PR at sp - 
216 (`0x60008788`), which includes the saved context (PC `0x00033c14` in 
`cmd_mw`, xPSR `0x81000000`).
   - With `CONFIG_ARCH_STACKDUMP_MAX_LENGTH=256` the last line of the dump 
starts 256 bytes after the first one.
   - The coredump still comes out after the notifiers: `tools/coredump.py` 
converts it, and GDB lists the threads and the faulting frame in `cmd_mw()`, as 
on master.
   
   `qemu-armv8a:nsh_smp` (2 CPUs), data abort with `mw 0xf0000000=1`: as on 
master, the other CPU is paused and dumped (`Dump CPU1: PAUSED` and its 
registers), now through the per-CPU `g_cpu_paused` and `g_last_regs`.
   
   Builds: `sim:nsh` (`ARCH_STACKDUMP`, `SCHED_DUMP_FDLIST`, 
`ARCH_DEADLOCKDUMP`), `sim:nsh` with `LIBC_ASSERT_CUSTOM=y`, 
`qemu-armv8a:nsh_smp` with the coredump to syslog and 
`ARCH_STACKDUMP_MAX_LENGTH=1024`, `qemu-armv8a:nsh_smp` with `SPINLOCK_DEBUG` 
and `ARCH_DEADLOCKDUMP_MAX=4`, `mps2-an500:nsh` with `ARCH_DEADLOCKDUMP_MAX=4`.
   
   Not tested: an asynchronous `board_reset()`, ASAN on sim, 
`BOARD_CRASHDUMP_CUSTOM`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to