diff options
| author | Shell <[email protected]> | 2024-06-04 00:06:41 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-06-04 00:06:41 +0800 |
| commit | 6ca327d8ce1d9c98204ab7c6d62123cfd5e12dcf (patch) | |
| tree | ed2cd81b10d249c22c07271d8f94085dbffd1c30 /src | |
| parent | e03342ff6b237d3ac6c38e133cb23b9770281f4a (diff) | |
[smart] add CPU/thread usage tracing config (#8947)
* [smart] add CPU usage tracing config
This patch introduces following features:
- Added CPU usage tracing functionality, enabled by default, for
applications like 'top'
- update time as smart independent
Signed-off-by: Shell <[email protected]>
* fixup: add ump idle thread
---------
Signed-off-by: Shell <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/Kconfig | 8 | ||||
| -rw-r--r-- | src/clock.c | 34 | ||||
| -rw-r--r-- | src/idle.c | 4 |
3 files changed, 45 insertions, 1 deletions
diff --git a/src/Kconfig b/src/Kconfig index 1d4c0489d7..0443366051 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -183,6 +183,14 @@ if RT_USING_TIMER_SOFT default 512 endif +config RT_USING_CPU_USAGE_TRACER + select RT_USING_HOOK + bool "Enable cpu usage tracing" + help + Enable cpu usage tracer for application like top. + default y if RT_USING_SMART + default n + menu "kservice optimization" config RT_USING_TINY_FFS bool "Enable kservice to use tiny finding first bit set method" diff --git a/src/clock.c b/src/clock.c index c2fe321c33..6a2366a0ac 100644 --- a/src/clock.c +++ b/src/clock.c @@ -79,6 +79,36 @@ void rt_tick_set(rt_tick_t tick) rt_atomic_store(&(rt_tick), tick); } +#ifdef RT_USING_CPU_USAGE_TRACER +static void _update_process_times(void) +{ + struct rt_thread *thread = rt_thread_self(); + struct rt_cpu *pcpu = rt_cpu_self(); + + if (!LWP_IS_USER_MODE(thread)) + { + thread->user_time += 1; + pcpu->cpu_stat.user += 1; + } + else + { + thread->system_time += 1; + if (thread == pcpu->idle_thread) + { + pcpu->cpu_stat.idle += 1; + } + else + { + pcpu->cpu_stat.system += 1; + } + } +} + +#else + +#define _update_process_times() +#endif /* RT_USING_CPU_USAGE_TRACER */ + /** * @brief This function will notify kernel there is one tick passed. * Normally, this function is invoked by clock ISR. @@ -88,6 +118,10 @@ void rt_tick_increase(void) RT_ASSERT(rt_interrupt_get_nest() > 0); RT_OBJECT_HOOK_CALL(rt_tick_hook, ()); + + /* tracing cpu usage */ + _update_process_times(); + /* increase the global tick */ #ifdef RT_USING_SMP /* get percpu and increase the tick */ diff --git a/src/idle.c b/src/idle.c index 26b559b70e..0447de79b3 100644 --- a/src/idle.c +++ b/src/idle.c @@ -346,9 +346,11 @@ void rt_thread_idle_init(void) 32); #ifdef RT_USING_SMP rt_thread_control(&idle_thread[i], RT_THREAD_CTRL_BIND_CPU, (void*)i); +#endif /* RT_USING_SMP */ + /* update */ rt_cpu_index(i)->idle_thread = &idle_thread[i]; -#endif /* RT_USING_SMP */ + /* startup */ rt_thread_startup(&idle_thread[i]); } |
