diff options
| author | zms123456 <[email protected]> | 2024-06-20 04:20:38 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-06-20 04:20:38 +0800 |
| commit | 59193dfeeb25a781288ef242d2dcc9e67925b064 (patch) | |
| tree | be4017572a3b03412a644a6263bf39ff03bb2bb5 /src | |
| parent | 6bd6317f77b336d43df3b6f225a6eca17d821721 (diff) | |
[timer]add all soft timer config (#9048)
* add all soft timer
* update wq
* add timer test
* shield LOG_D
Diffstat (limited to 'src')
| -rw-r--r-- | src/Kconfig | 4 | ||||
| -rw-r--r-- | src/timer.c | 92 |
2 files changed, 48 insertions, 48 deletions
diff --git a/src/Kconfig b/src/Kconfig index bf14182939..30105c3956 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -176,6 +176,10 @@ if RT_USING_TIMER_SOFT int "The stack size of timer thread" default 2048 if ARCH_CPU_64BIT default 512 + + config RT_USING_TIMER_ALL_SOFT + bool "Set all timer as soft timer" + default n endif config RT_USING_CPU_USAGE_TRACER diff --git a/src/timer.c b/src/timer.c index fd362a5b05..eee8a41959 100644 --- a/src/timer.c +++ b/src/timer.c @@ -31,9 +31,11 @@ #define DBG_LVL DBG_INFO #include <rtdbg.h> +#ifndef RT_USING_TIMER_ALL_SOFT /* hard timer list */ static rt_list_t _timer_list[RT_TIMER_SKIP_LIST_LEVEL]; static struct rt_spinlock _htimer_lock; +#endif #ifdef RT_USING_TIMER_SOFT @@ -93,6 +95,9 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) rt_inline struct rt_spinlock* _timerlock_idx(struct rt_timer *timer) { +#ifdef RT_USING_TIMER_ALL_SOFT + return &_stimer_lock; +#else #ifdef RT_USING_TIMER_SOFT if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { @@ -103,6 +108,7 @@ rt_inline struct rt_spinlock* _timerlock_idx(struct rt_timer *timer) { return &_htimer_lock; } +#endif } /** @@ -130,6 +136,10 @@ static void _timer_init(rt_timer_t timer, { int i; +#ifdef RT_USING_TIMER_ALL_SOFT + flag |= RT_TIMER_FLAG_SOFT_TIMER; +#endif + /* set flag */ timer->parent.flag = flag; @@ -403,11 +413,6 @@ static rt_err_t _timer_start(rt_list_t *timer_list, rt_timer_t timer) unsigned int tst_nr; static unsigned int random_nr; - if (timer->parent.flag & RT_TIMER_FLAG_PROCESSING) - { - return -RT_ERROR; - } - /* remove timer from list */ _timer_remove(timer); /* change status of timer */ @@ -516,7 +521,6 @@ static void _timer_check(rt_list_t *timer_list, struct rt_spinlock *lock) t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; } - t->parent.flag |= RT_TIMER_FLAG_PROCESSING; /* add timer to temporary list */ rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); @@ -529,8 +533,6 @@ static void _timer_check(rt_list_t *timer_list, struct rt_spinlock *lock) level = rt_spin_lock_irqsave(lock); - t->parent.flag &= ~RT_TIMER_FLAG_PROCESSING; - /* Check whether the timer object is detached or started again */ if (rt_list_isempty(&list)) { @@ -570,6 +572,10 @@ rt_err_t rt_timer_start(rt_timer_t timer) RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); +#ifdef RT_USING_TIMER_ALL_SOFT + timer_list = _soft_timer_list; + spinlock = &_stimer_lock; +#else #ifdef RT_USING_TIMER_SOFT if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { @@ -582,6 +588,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) timer_list = _timer_list; spinlock = &_htimer_lock; } +#endif if (timer->parent.flag & RT_TIMER_FLAG_THREAD_TIMER) { @@ -598,13 +605,6 @@ rt_err_t rt_timer_start(rt_timer_t timer) err = _timer_start(timer_list, timer); -#ifdef RT_USING_TIMER_SOFT - if (err == RT_EOK && (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)) - { - rt_sem_release(&_soft_timer_sem); - } -#endif /* RT_USING_TIMER_SOFT */ - rt_spin_unlock_irqrestore(spinlock, level); if (is_thread_timer) @@ -756,7 +756,20 @@ void rt_timer_check(void) return; } #endif + +#ifdef RT_USING_TIMER_SOFT + rt_err_t ret = RT_ERROR; + rt_tick_t next_timeout; + + ret = _timer_list_next_timeout(_soft_timer_list, &next_timeout); + if ((ret == RT_EOK) && (next_timeout <= rt_tick_get())) + { + rt_sem_release(&_soft_timer_sem); + } +#endif +#ifndef RT_USING_TIMER_ALL_SOFT _timer_check(_timer_list, &_htimer_lock); +#endif } /** @@ -767,13 +780,21 @@ void rt_timer_check(void) rt_tick_t rt_timer_next_timeout_tick(void) { rt_base_t level; - rt_tick_t next_timeout = RT_TICK_MAX; + rt_tick_t htimer_next_timeout = RT_TICK_MAX, stimer_next_timeout = RT_TICK_MAX; +#ifndef RT_USING_TIMER_ALL_SOFT level = rt_spin_lock_irqsave(&_htimer_lock); - _timer_list_next_timeout(_timer_list, &next_timeout); + _timer_list_next_timeout(_timer_list, &htimer_next_timeout); rt_spin_unlock_irqrestore(&_htimer_lock, level); +#endif - return next_timeout; +#ifdef RT_USING_TIMER_SOFT + level = rt_spin_lock_irqsave(&_stimer_lock); + _timer_list_next_timeout(_soft_timer_list, &stimer_next_timeout); + rt_spin_unlock_irqrestore(&_stimer_lock, level); +#endif + + return htimer_next_timeout < stimer_next_timeout ? htimer_next_timeout : stimer_next_timeout; } #ifdef RT_USING_TIMER_SOFT @@ -784,41 +805,12 @@ rt_tick_t rt_timer_next_timeout_tick(void) */ static void _timer_thread_entry(void *parameter) { - rt_err_t ret = RT_ERROR; - rt_tick_t next_timeout; - rt_base_t level; - RT_UNUSED(parameter); - rt_sem_control(&_soft_timer_sem, RT_IPC_CMD_SET_VLIMIT, (void*)1); - while (1) { - /* get the next timeout tick */ - level = rt_spin_lock_irqsave(&_stimer_lock); - ret = _timer_list_next_timeout(_soft_timer_list, &next_timeout); - rt_spin_unlock_irqrestore(&_stimer_lock, level); - - if (ret != RT_EOK) - { - rt_sem_take(&_soft_timer_sem, RT_WAITING_FOREVER); - } - else - { - rt_tick_t current_tick; - - /* get current tick */ - current_tick = rt_tick_get(); - - if ((next_timeout - current_tick) < RT_TICK_MAX / 2) - { - /* get the delta timeout tick */ - next_timeout = next_timeout - current_tick; - rt_sem_take(&_soft_timer_sem, next_timeout); - } - } - _timer_check(_soft_timer_list, &_stimer_lock); /* check software timer */ + rt_sem_take(&_soft_timer_sem, RT_WAITING_FOREVER); } } #endif /* RT_USING_TIMER_SOFT */ @@ -830,13 +822,16 @@ static void _timer_thread_entry(void *parameter) */ void rt_system_timer_init(void) { +#ifndef RT_USING_TIMER_ALL_SOFT rt_size_t i; for (i = 0; i < sizeof(_timer_list) / sizeof(_timer_list[0]); i++) { rt_list_init(_timer_list + i); } + rt_spin_lock_init(&_htimer_lock); +#endif } /** @@ -857,6 +852,7 @@ void rt_system_timer_thread_init(void) } rt_spin_lock_init(&_stimer_lock); rt_sem_init(&_soft_timer_sem, "stimer", 0, RT_IPC_FLAG_PRIO); + rt_sem_control(&_soft_timer_sem, RT_IPC_CMD_SET_VLIMIT, (void*)1); /* start software timer thread */ rt_thread_init(&_timer_thread, "timer", |
