summaryrefslogtreecommitdiff
path: root/src/clock.c
diff options
context:
space:
mode:
authorShell <[email protected]>2024-06-04 00:06:41 +0800
committerGitHub <[email protected]>2024-06-04 00:06:41 +0800
commit6ca327d8ce1d9c98204ab7c6d62123cfd5e12dcf (patch)
treeed2cd81b10d249c22c07271d8f94085dbffd1c30 /src/clock.c
parente03342ff6b237d3ac6c38e133cb23b9770281f4a (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/clock.c')
-rw-r--r--src/clock.c34
1 files changed, 34 insertions, 0 deletions
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 */