|
@@ -11,8 +11,8 @@
|
|
|
* 2025-09-01 Rbb666 Add thread stack overflow hook.
|
|
* 2025-09-01 Rbb666 Add thread stack overflow hook.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-#define DBG_TAG "kernel.sched"
|
|
|
|
|
-#define DBG_LVL DBG_INFO
|
|
|
|
|
|
|
+#define DBG_TAG "kernel.sched"
|
|
|
|
|
+#define DBG_LVL DBG_INFO
|
|
|
#include <rtdbg.h>
|
|
#include <rtdbg.h>
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
#include <rtthread.h>
|
|
@@ -34,7 +34,7 @@
|
|
|
void rt_sched_thread_init_ctx(struct rt_thread *thread, rt_uint32_t tick, rt_uint8_t priority)
|
|
void rt_sched_thread_init_ctx(struct rt_thread *thread, rt_uint32_t tick, rt_uint8_t priority)
|
|
|
{
|
|
{
|
|
|
/* setup thread status */
|
|
/* setup thread status */
|
|
|
- RT_SCHED_CTX(thread).stat = RT_THREAD_INIT;
|
|
|
|
|
|
|
+ RT_SCHED_CTX(thread).stat = RT_THREAD_INIT;
|
|
|
|
|
|
|
|
#ifdef RT_USING_SMP
|
|
#ifdef RT_USING_SMP
|
|
|
/* not bind on any cpu */
|
|
/* not bind on any cpu */
|
|
@@ -258,9 +258,9 @@ rt_err_t rt_sched_thread_ready(struct rt_thread *thread)
|
|
|
/* remove from suspend list */
|
|
/* remove from suspend list */
|
|
|
rt_list_remove(&RT_THREAD_LIST_NODE(thread));
|
|
rt_list_remove(&RT_THREAD_LIST_NODE(thread));
|
|
|
|
|
|
|
|
- #ifdef RT_USING_SMART
|
|
|
|
|
|
|
+#ifdef RT_USING_SMART
|
|
|
thread->wakeup_handle.func = RT_NULL;
|
|
thread->wakeup_handle.func = RT_NULL;
|
|
|
- #endif
|
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
/* insert to schedule ready list and remove from susp list */
|
|
/* insert to schedule ready list and remove from susp list */
|
|
|
rt_sched_insert_thread(thread);
|
|
rt_sched_insert_thread(thread);
|
|
@@ -297,7 +297,7 @@ rt_err_t rt_sched_tick_increase(rt_tick_t tick)
|
|
|
|
|
|
|
|
rt_sched_lock(&slvl);
|
|
rt_sched_lock(&slvl);
|
|
|
|
|
|
|
|
- if(RT_SCHED_PRIV(thread).remaining_tick > tick)
|
|
|
|
|
|
|
+ if (RT_SCHED_PRIV(thread).remaining_tick > tick)
|
|
|
{
|
|
{
|
|
|
RT_SCHED_PRIV(thread).remaining_tick -= tick;
|
|
RT_SCHED_PRIV(thread).remaining_tick -= tick;
|
|
|
}
|
|
}
|
|
@@ -464,7 +464,7 @@ void rt_scheduler_stack_check(struct rt_thread *thread)
|
|
|
|
|
|
|
|
/* if stack pointer locate in user data section skip stack check. */
|
|
/* if stack pointer locate in user data section skip stack check. */
|
|
|
if (lwp && ((rt_uint32_t)thread->sp > (rt_uint32_t)lwp->data_entry &&
|
|
if (lwp && ((rt_uint32_t)thread->sp > (rt_uint32_t)lwp->data_entry &&
|
|
|
- (rt_uint32_t)thread->sp <= (rt_uint32_t)lwp->data_entry + (rt_uint32_t)lwp->data_size))
|
|
|
|
|
|
|
+ (rt_uint32_t)thread->sp <= (rt_uint32_t)lwp->data_entry + (rt_uint32_t)lwp->data_size))
|
|
|
{
|
|
{
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -479,7 +479,7 @@ void rt_scheduler_stack_check(struct rt_thread *thread)
|
|
|
#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
|
|
#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
|
|
|
(rt_uintptr_t)thread->sp <= (rt_uintptr_t)thread->stack_addr ||
|
|
(rt_uintptr_t)thread->sp <= (rt_uintptr_t)thread->stack_addr ||
|
|
|
(rt_uintptr_t)thread->sp >
|
|
(rt_uintptr_t)thread->sp >
|
|
|
- (rt_uintptr_t)thread->stack_addr + (rt_uintptr_t)thread->stack_size)
|
|
|
|
|
|
|
+ (rt_uintptr_t)thread->stack_addr + (rt_uintptr_t)thread->stack_size)
|
|
|
{
|
|
{
|
|
|
rt_base_t dummy = 1;
|
|
rt_base_t dummy = 1;
|
|
|
rt_err_t hook_result = -RT_ERROR;
|
|
rt_err_t hook_result = -RT_ERROR;
|
|
@@ -496,7 +496,8 @@ void rt_scheduler_stack_check(struct rt_thread *thread)
|
|
|
/* If hook handled the overflow successfully, don't enter infinite loop */
|
|
/* If hook handled the overflow successfully, don't enter infinite loop */
|
|
|
if (hook_result != RT_EOK)
|
|
if (hook_result != RT_EOK)
|
|
|
{
|
|
{
|
|
|
- while (dummy);
|
|
|
|
|
|
|
+ while (dummy)
|
|
|
|
|
+ ;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
#endif /* RT_USING_HW_STACK_GUARD */
|
|
#endif /* RT_USING_HW_STACK_GUARD */
|
|
@@ -508,7 +509,7 @@ void rt_scheduler_stack_check(struct rt_thread *thread)
|
|
|
#endif
|
|
#endif
|
|
|
{
|
|
{
|
|
|
LOG_W("warning: %s stack is close to the top of stack address.\n",
|
|
LOG_W("warning: %s stack is close to the top of stack address.\n",
|
|
|
- thread->parent.name);
|
|
|
|
|
|
|
+ thread->parent.name);
|
|
|
}
|
|
}
|
|
|
#else
|
|
#else
|
|
|
#ifndef RT_USING_HW_STACK_GUARD
|
|
#ifndef RT_USING_HW_STACK_GUARD
|
|
@@ -518,7 +519,7 @@ void rt_scheduler_stack_check(struct rt_thread *thread)
|
|
|
#endif
|
|
#endif
|
|
|
{
|
|
{
|
|
|
LOG_W("warning: %s stack is close to end of stack address.\n",
|
|
LOG_W("warning: %s stack is close to end of stack address.\n",
|
|
|
- thread->parent.name);
|
|
|
|
|
|
|
+ thread->parent.name);
|
|
|
}
|
|
}
|
|
|
#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
|
|
#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
|
|
|
}
|
|
}
|