hujun260 opened a new pull request, #18208:
URL: https://github.com/apache/nuttx/pull/18208
## Summary
Refactor the `nxsched_set_param()` function by extracting complex scheduling
parameter validation and configuration logic into dedicated helper
functions,
and consolidating multiple return statements into single exit points to
improve
code quality and achieve MISRA HIS compliance.
## Motivation and Problem
The original `nxsched_set_param()` function had excessive cyclomatic
complexity
due to deeply nested conditionals handling multiple scheduling policies
(SCHED_SPORADIC, SCHED_RR, SCHED_FIFO). Multiple return points throughout
the
function violated MISRA HIS metric rules and made code verification
difficult.
This refactoring improves code readability, testability, and compliance with
automotive safety standards.
## Changes
- Extract `set_sporadic_param()` helper function for SCHED_SPORADIC policy
handling
- Extract helper functions for other scheduling policies (RR, FIFO)
- Convert early returns to result variable assignments
- Consolidate to single exit point per function
- Maintain identical runtime behavior with improved code structure
## Impact
- **Code Quality**: Significantly reduced cyclomatic complexity through
function extraction
- **Compliance**: Achieves MISRA HIS compliance for return statement and
function size metrics
- **Verifiability**: Single exit points improve static analysis and code
verification
- **Maintainability**: Clearer separation of concerns with policy-specific
helper functions
- **Backward Compatibility**: No functional changes; identical runtime
behavior
- **Performance**: No performance impact; compiler optimizations identical
## Verification
- [x] Code compiles without warnings on ARM GCC 10.x
- [x] Verified on QEMU ARMv7-A simulator with multimedia profile
- [x] All scheduling policies tested (SCHED_RR, SCHED_FIFO, SCHED_SPORADIC)
- [x] Parameter validation logic verified
- [x] Error paths verified for invalid parameters
- [x] Task state transitions verified
- [x] Static analysis shows improved complexity metrics
## Testing
Tested with:
- ARM GCC 10.x compiler
- QEMU ARMv7-A simulation
- Scheduling parameter operations:
- SCHED_RR parameter configuration
- SCHED_FIFO parameter configuration
- SCHED_SPORADIC parameter configuration
- Invalid parameter validation
- Priority range checks
- Sporadic scheduling replenishment and budget handling
## Files Changed
- `sched/sched/sched_setparam.c` (233 lines: 128 insertions, 105 deletions)
--
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]