|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
+ * Copyright (c) 2006-2024 RT-Thread Development Team
|
|
|
*
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
*
|
|
@@ -84,33 +84,33 @@ void rt_tick_set(rt_tick_t tick)
|
|
|
}
|
|
|
|
|
|
#ifdef RT_USING_CPU_USAGE_TRACER
|
|
|
-static void _update_process_times(void)
|
|
|
+static void _update_process_times(rt_tick_t tick)
|
|
|
{
|
|
|
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;
|
|
|
+ thread->user_time += tick;
|
|
|
+ pcpu->cpu_stat.user += tick;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- thread->system_time += 1;
|
|
|
+ thread->system_time += tick;
|
|
|
if (thread == pcpu->idle_thread)
|
|
|
{
|
|
|
- pcpu->cpu_stat.idle += 1;
|
|
|
+ pcpu->cpu_stat.idle += tick;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- pcpu->cpu_stat.system += 1;
|
|
|
+ pcpu->cpu_stat.system += tick;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
|
|
-#define _update_process_times()
|
|
|
+#define _update_process_times(tick)
|
|
|
#endif /* RT_USING_CPU_USAGE_TRACER */
|
|
|
|
|
|
/**
|
|
@@ -124,7 +124,7 @@ void rt_tick_increase(void)
|
|
|
RT_OBJECT_HOOK_CALL(rt_tick_hook, ());
|
|
|
|
|
|
/* tracing cpu usage */
|
|
|
- _update_process_times();
|
|
|
+ _update_process_times(1);
|
|
|
|
|
|
/* increase the global tick */
|
|
|
#ifdef RT_USING_SMP
|
|
@@ -135,7 +135,41 @@ void rt_tick_increase(void)
|
|
|
#endif /* RT_USING_SMP */
|
|
|
|
|
|
/* check time slice */
|
|
|
- rt_sched_tick_increase();
|
|
|
+ rt_sched_tick_increase(1);
|
|
|
+
|
|
|
+ /* check timer */
|
|
|
+#ifdef RT_USING_SMP
|
|
|
+ if (rt_cpu_get_id() != 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ rt_timer_check();
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief This function will notify kernel there is n tick passed.
|
|
|
+ * Normally, this function is invoked by clock ISR.
|
|
|
+ */
|
|
|
+void rt_tick_increase_tick(rt_tick_t tick)
|
|
|
+{
|
|
|
+ RT_ASSERT(rt_interrupt_get_nest() > 0);
|
|
|
+
|
|
|
+ RT_OBJECT_HOOK_CALL(rt_tick_hook, ());
|
|
|
+
|
|
|
+ /* tracing cpu usage */
|
|
|
+ _update_process_times(tick);
|
|
|
+
|
|
|
+ /* increase the global tick */
|
|
|
+#ifdef RT_USING_SMP
|
|
|
+ /* get percpu and increase the tick */
|
|
|
+ rt_atomic_add(&(rt_cpu_self()->tick), tick);
|
|
|
+#else
|
|
|
+ rt_atomic_add(&(rt_tick), tick);
|
|
|
+#endif /* RT_USING_SMP */
|
|
|
+
|
|
|
+ /* check time slice */
|
|
|
+ rt_sched_tick_increase(tick);
|
|
|
|
|
|
/* check timer */
|
|
|
#ifdef RT_USING_SMP
|
|
@@ -191,7 +225,7 @@ RTM_EXPORT(rt_tick_from_millisecond);
|
|
|
*/
|
|
|
rt_weak rt_tick_t rt_tick_get_millisecond(void)
|
|
|
{
|
|
|
-#if RT_TICK_PER_SECOND == 0 // make cppcheck happy
|
|
|
+#if RT_TICK_PER_SECOND == 0 /* make cppcheck happy*/
|
|
|
#error "RT_TICK_PER_SECOND must be greater than zero"
|
|
|
#endif
|
|
|
|