sched/task: remove the check for whether tcb is NULL
Summary
sched/task: remove the check for whether tcb is NULL
We should not call these functions before nx_start; therefore, this_task will not be empty. If these functions are called (before nx_start), the correct value cannot be obtained either.
Impact
sched
This is a very minor optimization, primarily focused on performance.For example, in the ARM64 compilation of nxsched_gettid, there were 27 instructions before the modification and 20 instructions after the modification.
Testing
test with ./tools/configure.sh -l qemu-armv8a:nsh_smp
ostest End of test memory usage: VARIABLE BEFORE AFTER ======== ======== ======== arena 7b94000 7b94000 ordblks 10 9 mxordblk 7b61118 7b65150 uordblks 1a588 1a590 fordblks 7b79a78 7b79a70
user_main: vfork() test vfork_test: Child 95 ran successfully
user_main: smp call test smp_call_test: Test start smp_call_test: Call cpu 0, nowait smp_call_test: Call cpu 0, wait smp_call_test: Call cpu 1, nowait smp_call_test: Call cpu 1, wait smp_call_test: Call multi cpu, nowait smp_call_test: Call in interrupt, wait smp_call_test: Call multi cpu, wait smp_call_test: Test success
Final memory usage: VARIABLE BEFORE AFTER ======== ======== ======== arena 7b94000 7b94000 ordblks 2 9 mxordblk 7b81e58 7b65150 uordblks 12180 1a410 fordblks 7b81e80 7b79bf0 user_main: Exiting ostest_main: Exiting with status 0 nsh>
I also test in realhardware target: esp32s3-devkit:smp
nsh> nsh> uname -a NuttX 12.11.0 c85db15d7b1 Nov 21 2025 20:16:56 xtensa esp32s3-devkit nsh> ostest stdio_test: write fd=1 stdio_test: Standard I/O Check: printf stdio_test: write fd=2 stdio_test: Standard I/O Check: fprintf to stderr ostest_main: putenv(Variable1=BadValue3) ostest_main: setenv(Variable1, GoodValue1, TRUE) ostest_main: setenv(Variable2, BadValue1, FALSE) ostest_main: setenv(Variable2, GoodValue2, TRUE) ostest_main: setenv(Variable3, GoodValue3, FALSE) ostest_main: setenv(Variable3, BadValue2, FALSE) show_variable: Variable=Variable1 has value=GoodValue1 show_variable: Variable=Variable2 has value=GoodValue2 show_variable: Variable=Variable3 has value=GoodValue3 ostest_main: Started user_main at PID=4
user_main: Begin argument test
As with the last PR which got merged, can you please provide an explanation of why it is not possible for rtcb to be NULL in these contexts? Please include this justification in the PR summary.
And if it is possible through user error or memory corruption, I suggest adding
DEBUGASSERTstatements to make sure the rtcb is not NULL when debugging.Also, what is the reason for this change?
This is a very minor optimization, primarily focused on performance.For example, in the ARM64 compilation of nxsched_gettid, there were 27 instructions before the modification and 20 instructions after the modification. We should not call these functions before nx_start; therefore, this_task will not be empty. If these functions are called (before nx_start), the correct value cannot be obtained either. We should modify the logic of the calling program, as there is no need for us to be compatible with unreasonable calling scenarios.A DEBUGASSERT can be added to help expose such issues.
@hujun260 please test in real hardware. In the past we saw patches that passed in qemu but failed in real hardware
also tested in real hardware
also tested in real hardware
Can you please list what real hardware in the testing section?
I also, I have just modified your PR description to put the justifications from your comment there. Makes it easier for reviewers.
also tested in real hardware
Can you please list what real hardware in the testing section?
I also, I have just modified your PR description to put the justifications from your comment there. Makes it easier for reviewers.
ok