🎈 perf: perf rt_hw_interrupt_disable/enable (#8042)

Signed-off-by: Shell <smokewood@qq.com>
Co-authored-by: Shell <smokewood@qq.com>
This commit is contained in:
xqyjlj
2023-10-25 20:31:25 +08:00
committed by GitHub
co-authored by Shell
parent 91fc52df36
commit 3283f54c7a
80 changed files with 2478 additions and 1962 deletions
+16 -20
View File
@@ -15,16 +15,18 @@
* 2018-11-22 Jesven add per cpu tick
* 2020-12-29 Meco Man implement rt_tick_get_millisecond()
* 2021-06-01 Meco Man add critical section projection for rt_tick_increase()
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
* 2023-10-16 RiceChen fix: only the main core detection rt_timer_check(), in SMP mode
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtatomic.h>
#ifdef RT_USING_SMP
#define rt_tick rt_cpu_index(0)->tick
#else
static volatile rt_tick_t rt_tick = 0;
static volatile rt_atomic_t rt_tick = 0;
#endif /* RT_USING_SMP */
#ifndef __on_rt_tick_hook
@@ -67,7 +69,7 @@ void rt_tick_sethook(void (*hook)(void))
rt_tick_t rt_tick_get(void)
{
/* return the global tick */
return rt_tick;
return (rt_tick_t)rt_atomic_load(&(rt_tick));
}
RTM_EXPORT(rt_tick_get);
@@ -78,11 +80,7 @@ RTM_EXPORT(rt_tick_get);
*/
void rt_tick_set(rt_tick_t tick)
{
rt_base_t level;
level = rt_hw_interrupt_disable();
rt_tick = tick;
rt_hw_interrupt_enable(level);
rt_atomic_store(&(rt_tick), tick);
}
/**
@@ -93,34 +91,32 @@ void rt_tick_increase(void)
{
struct rt_thread *thread;
rt_base_t level;
rt_atomic_t oldval = 0;
RT_OBJECT_HOOK_CALL(rt_tick_hook, ());
level = rt_hw_interrupt_disable();
/* increase the global tick */
#ifdef RT_USING_SMP
rt_cpu_self()->tick ++;
rt_atomic_add(&(rt_cpu_self()->tick), 1);
#else
++ rt_tick;
rt_atomic_add(&(rt_tick), 1);
#endif /* RT_USING_SMP */
/* check time slice */
thread = rt_thread_self();
-- thread->remaining_tick;
if (thread->remaining_tick == 0)
rt_get_thread_struct(thread);
level = rt_spin_lock_irqsave(&(thread->spinlock));
rt_atomic_sub(&(thread->remaining_tick), 1);
if (rt_atomic_compare_exchange_strong(&(thread->remaining_tick), &oldval, thread->init_tick))
{
/* change to initialized tick */
thread->remaining_tick = thread->init_tick;
thread->stat |= RT_THREAD_STAT_YIELD;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(thread->spinlock), level);
rt_put_thread_struct(thread);
rt_schedule();
}
else
{
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(thread->spinlock), level);
rt_put_thread_struct(thread);
}
/* check timer */