[src][tick]rt_tick setting arbitrary value function is added to support low-power wake-up tick compensation
This commit is contained in:
parent
7c1d205a4e
commit
8d3ad68caf
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2024, RT-Thread Development Team
|
||||
* Copyright (c) 2023-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
@ -157,7 +157,7 @@ void rt_sched_thread_startup(struct rt_thread *thread);
|
|||
|
||||
/* scheduler related routine */
|
||||
void rt_sched_post_ctx_switch(struct rt_thread *thread);
|
||||
rt_err_t rt_sched_tick_increase(void);
|
||||
rt_err_t rt_sched_tick_increase(rt_tick_t tick);
|
||||
|
||||
/* thread status operation */
|
||||
rt_uint8_t rt_sched_thread_get_stat(struct rt_thread *thread);
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
@ -100,6 +100,7 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object));
|
|||
rt_tick_t rt_tick_get(void);
|
||||
void rt_tick_set(rt_tick_t tick);
|
||||
void rt_tick_increase(void);
|
||||
void rt_tick_increase_tick(rt_tick_t tick);
|
||||
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms);
|
||||
rt_tick_t rt_tick_get_millisecond(void);
|
||||
#ifdef RT_USING_HOOK
|
||||
|
|
56
src/clock.c
56
src/clock.c
|
@ -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
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
@ -144,7 +144,7 @@ rt_err_t rt_sched_thread_ready(struct rt_thread *thread)
|
|||
return error;
|
||||
}
|
||||
|
||||
rt_err_t rt_sched_tick_increase(void)
|
||||
rt_err_t rt_sched_tick_increase(rt_tick_t tick)
|
||||
{
|
||||
struct rt_thread *thread;
|
||||
rt_sched_lock_level_t slvl;
|
||||
|
@ -153,7 +153,15 @@ rt_err_t rt_sched_tick_increase(void)
|
|||
|
||||
rt_sched_lock(&slvl);
|
||||
|
||||
RT_SCHED_PRIV(thread).remaining_tick--;
|
||||
if(RT_SCHED_PRIV(thread).remaining_tick > tick)
|
||||
{
|
||||
RT_SCHED_PRIV(thread).remaining_tick -= tick;
|
||||
}
|
||||
else
|
||||
{
|
||||
RT_SCHED_PRIV(thread).remaining_tick = 0;
|
||||
}
|
||||
|
||||
if (RT_SCHED_PRIV(thread).remaining_tick)
|
||||
{
|
||||
rt_sched_unlock(slvl);
|
||||
|
|
Loading…
Reference in New Issue