Skip to content

sched/sched_lock: remove null pointer check of rtcb#17310

Open
anchao wants to merge 1 commit intomasterfrom
revert-17300-apache_6
Open

sched/sched_lock: remove null pointer check of rtcb#17310
anchao wants to merge 1 commit intomasterfrom
revert-17300-apache_6

Conversation

@anchao
Copy link
Contributor

@anchao anchao commented Nov 11, 2025

Summary

Reverts #17300

sched/sched_lock: remove null pointer check of rtcb

In previous commits to xiaomi, runtime null pointer checks for RTCB were removed.
This could cause sched_lock/unlock exceptions when DEBUG_ASSERTIONS was disabled.
In this commit, we removed all RTCB checks to improve performance by 1 comparison cycle,
References to null pointers in the RTCB will rely on hardware exception or MPU/MMU protection.

| commit d94cb53d6cde6a999d862ae45e1fcd3692675cb4 (HEAD, origin/master, origin/HEAD)
| Author: hujun5 <hujun5@xiaomi.com>
| Date:   Thu Feb 6 15:06:00 2025 +0800
|
|     sched_lock: remove the check for whether tcb is NULL
|
|     Remove Redundant Checks
|
|     Signed-off-by: hujun5 <hujun5@xiaomi.com>

Signed-off-by: chao an anchao.archer@bytedance.com

Testing

sim/nsh ostest ; sabre-6quad/smp

@github-actions github-actions bot added Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small labels Nov 11, 2025
@anchao
Copy link
Contributor Author

anchao commented Nov 11, 2025

I submitted a change request in PR #17300 , but @xiaoxiang781216 was ignored and the commit was forcibly merged. Please revert this change.

REF: #17300 (comment)

@anchao anchao force-pushed the revert-17300-apache_6 branch from f2730b0 to ed1367b Compare November 11, 2025 10:36
@anchao anchao closed this Nov 11, 2025
@anchao anchao deleted the revert-17300-apache_6 branch November 11, 2025 10:37
@anchao anchao changed the title Revert "sched_lock: remove the check for whether tcb is NULL" sched/sched_lock: remove null pointer check of rtcb Nov 11, 2025
@anchao anchao restored the revert-17300-apache_6 branch November 11, 2025 10:39
@anchao anchao reopened this Nov 11, 2025
In previous commits to xiaomi, runtime null pointer checks for RTCB were removed.
This could cause `sched_lock/unlock` exceptions when `DEBUG_ASSERTIONS` was disabled.
In this commit, we removed all RTCB checks to improve performance by 1 comparison cycle
References to null pointers in the RTCB will rely on hardware exception or MPU/MMU protection.

| commit d94cb53 (HEAD, origin/master, origin/HEAD)
| Author: hujun5 <hujun5@xiaomi.com>
| Date:   Thu Feb 6 15:06:00 2025 +0800
|
|     sched_lock: remove the check for whether tcb is NULL
|
|     Remove Redundant Checks
|
|     Signed-off-by: hujun5 <hujun5@xiaomi.com>

Signed-off-by: chao an <anchao.archer@bytedance.com>
@anchao anchao force-pushed the revert-17300-apache_6 branch from ed1367b to b96f993 Compare November 11, 2025 10:42
@linguini1
Copy link
Contributor

Hi @anchao , I support reverting the commit until the review comments are satisfied. But, this revert PR looks like it has modifications and isn't a direct revert. I think we should revert the exact commit changes and then reopen for discussion.

Copy link
Contributor

@xiaoxiang781216 xiaoxiang781216 left a comment

Choose a reason for hiding this comment

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

I submitted a change request in PR #17300 , but @xiaoxiang781216 was ignored and the commit was forcibly merged. Please revert this change.

REF: #17300 (comment)

so, do you plan to remove all DEBUGASSERT(xxx != NULL) check in the whoe codebase? if that, it's fine to merge this pr.

@raiden00pl
Copy link
Member

What's the point of fighting for performance in debug code? It's normal for debug code to have no performance.
Null pointer debug assertions are useful because they sometimes allow you to find bugs that are hard to find, like stack/buffers overflows. I remember that this type of assertions helped me to find bugs in completely unrelated parts of the kernel.

Also I very much doubt that all architectures support null pointer detection, the first thing that comes to my mind is STM32F0 (cortex-m0). For all STM32 0x0000:0000 is the correct address, which means that by default there will be no exception even for chips with MPU. This can lead to bugs that are difficult to detect and debug.

@linguini1
Copy link
Contributor

What's the point of fighting for performance in debug code? It's normal for debug code to have no performance.
Null pointer debug assertions are useful because they sometimes allow you to find bugs that are hard to find, like stack/buffers overflows. I remember that this type of assertions helped me to find bugs in completely unrelated parts of the kernel.

Also I very much doubt that all architectures support null pointer detection, the first thing that comes to my mind is STM32F0 (cortex-m0). For all STM32 0x0000:0000 is the correct address, which means that by default there will be no exception even for chips with MPU. This can lead to bugs that are difficult to detect and debug.

I agree. I wonder if someone could explain though why we don't need the runtime check out of debug mode? Why is the rtcb never null?

@anchao
Copy link
Contributor Author

anchao commented Nov 24, 2025

What's the point of fighting for performance in debug code? It's normal for debug code to have no performance. Null pointer debug assertions are useful because they sometimes allow you to find bugs that are hard to find, like stack/buffers overflows. I remember that this type of assertions helped me to find bugs in completely unrelated parts of the kernel.

I disagree with your point. In fact, most Nuttx devices have DEBUG_ASSERTIONS enabled by default, including those already on the market, because this is very helpful for locating and resolving certain issues.

Therefore, performance is also very important in the enable assertion mode.

Also I very much doubt that all architectures support null pointer detection, the first thing that comes to my mind is STM32F0 (cortex-m0). For all STM32 0x0000:0000 is the correct address, which means that by default there will be no exception even for chips with MPU. This can lead to bugs that are difficult to detect and debug.

@raiden00pl Have you actually seen the changes in #17300 reviewed? This commit removed the check for rtcb validity. If, as you claim, some hardware lacks 0-address protection, then #17300 needs to be reverted.

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

Labels

Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants