Skip to content

Conversation

@hujun260
Copy link
Contributor

Summary

add a reference count to the TCB to prevent it from being deleted.

To replace the large lock with smaller ones and reduce the large locks related to the TCB, in many scenarios, we only need to ensure that the TCB won't be released instead of locking, thus reducing the possibility of lock recursion.

should merge with apache/nuttx#17468

Impact

tcb release

Testing

esp32s3-devkit:nsh

user_main: scheduler lock test
sched_lock: Starting lowpri_thread at 97
sched_lock: Set lowpri_thread priority to 97
sched_lock: Starting highpri_thread at 98
sched_lock: Set highpri_thread priority to 98
sched_lock: Waiting...
sched_lock: PASSED No pre-emption occurred while scheduler was locked.
sched_lock: Starting lowpri_thread at 97
sched_lock: Set lowpri_thread priority to 97
sched_lock: Starting highpri_thread at 98
sched_lock: Set highpri_thread priority to 98
sched_lock: Waiting...
sched_lock: PASSED No pre-emption occurred while scheduler was locked.
sched_lock: Finished

End of test memory usage:
VARIABLE BEFORE AFTER
======== ======== ========
arena 5d8bc 5d8bc
ordblks 7 6
mxordblk 548a0 548a0
uordblks 5014 5014
fordblks 588a8 588a8

Final memory usage:
VARIABLE BEFORE AFTER
======== ======== ========
arena 5d8bc 5d8bc
ordblks 1 6
mxordblk 59238 548a0
uordblks 4684 5014
fordblks 59238 588a8
user_main: Exiting
ostest_main: Exiting with status 0
nsh> u
nsh: u: command not found
nsh>
nsh>
nsh>
nsh> uname -a
NuttX 12.11.0 ef91333e3ac-dirty Dec 10 2025 16:11:04 xtensa esp32s3-devkit
nsh>

@simbit18
Copy link
Contributor

simbit18 commented Dec 10, 2025

Hi @hujun260 please fix these errors:

../nuttx/tools/checkpatch.sh -c -u -m -g cfff7f5a22aecdfd7799add706c48d6968769cdc..HEAD
Used config files:
    1: .codespellrc
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:29: ccertificate ==> certificate
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:444: CCertificate ==> certificate
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:496: CCertificate ==> certificate
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:632: CCertificate ==> certificate
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:657: CCertificate ==> certificate
Some checks failed. For contributing guidelines, see:

@hujun260 to pass the check
you need to add these lines to this file .codespell-ignore-lines

https://github.com/apache/nuttx-apps/blob/master/.codespell-ignore-lines

add the entire line (including spaces)

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L29

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L444

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L496

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L632

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L657

…deleted.

To replace the large lock with smaller ones and reduce the large locks related to the TCB,
in many scenarios, we only need to ensure that the TCB won't be released
instead of locking, thus reducing the possibility of lock recursion.

Signed-off-by: hujun5 <[email protected]>
@hujun260
Copy link
Contributor Author

Hi @hujun260 please fix these errors:

../nuttx/tools/checkpatch.sh -c -u -m -g cfff7f5a22aecdfd7799add706c48d6968769cdc..HEAD
Used config files:
    1: .codespellrc
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:29: ccertificate ==> certificate
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:444: CCertificate ==> certificate
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:496: CCertificate ==> certificate
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:632: CCertificate ==> certificate
/home/runner/work/nuttx-apps/nuttx-apps/apps/crypto/controlse/controlse_main.cxx:657: CCertificate ==> certificate
Some checks failed. For contributing guidelines, see:

@hujun260 to pass the check you need to add these lines to this file .codespell-ignore-lines

https://github.com/apache/nuttx-apps/blob/master/.codespell-ignore-lines

add the entire line (including spaces)

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L29

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L444

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L496

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L632

https://github.com/hujun260/nuttx-apps/blob/30b40c9a68b8c81623dcd7597d0713b3c0468134/crypto/controlse/controlse_main.cxx#L657

thanks!

tcb = nxsched_get_tcb(getpid());
fprintf(stderr, "\nStack used: %zu / %zu\n", up_check_tcbstack(tcb),
tcb->adj_stack_size);
if (tcb)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (tcb)
if (tcb != NULL)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants