[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 <smokewood@qq.com>

* fixup: add ump idle thread

---------

Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
Shell
2024-06-04 00:06:41 +08:00
committed by GitHub
parent e03342ff6b
commit 6ca327d8ce
6 changed files with 77 additions and 53 deletions
+8
View File
@@ -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"
+34
View File
@@ -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 */
+4 -2
View File
@@ -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);
rt_cpu_index(i)->idle_thread = &idle_thread[i];
#endif /* RT_USING_SMP */
/* update */
rt_cpu_index(i)->idle_thread = &idle_thread[i];
/* startup */
rt_thread_startup(&idle_thread[i]);
}