From 62eb0ec36c9c6c53cd1b6c17920be62a9851b789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E8=B6=85?= Date: Mon, 30 Aug 2021 15:23:29 +0800 Subject: [PATCH] add schedule hook for cpu usage statistics --- src/scheduler.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/scheduler.c b/src/scheduler.c index 28a8a78fcc..56fba09d03 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -49,6 +49,7 @@ rt_uint8_t rt_current_priority; #ifdef RT_USING_HOOK static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to); +static void (*rt_scheduler_switch_hook)(struct rt_thread *tid); /** * @addtogroup Hook @@ -68,6 +69,11 @@ rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to)) rt_scheduler_hook = hook; } +void +rt_scheduler_switch_sethook(void (*hook)(struct rt_thread *tid)) +{ + rt_scheduler_switch_hook = hook; +} /**@}*/ #endif @@ -372,7 +378,7 @@ void rt_schedule(void) #ifdef RT_USING_OVERFLOW_CHECK _rt_scheduler_stack_check(to_thread); #endif - + RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (current_thread)); rt_hw_context_switch((rt_ubase_t)¤t_thread->sp, (rt_ubase_t)&to_thread->sp, to_thread); } @@ -478,6 +484,7 @@ void rt_schedule(void) _rt_scheduler_stack_check(to_thread); #endif + RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (from_thread)); if (rt_interrupt_nest == 0) { extern void rt_thread_handle_sig(rt_bool_t clean_state); -- Gitee