[components][ktime]support period ktime timeout and multiple ktimer_hrtimer (#8972)

* support period time

* enable multiple ktimer

* mv set delay_cnt to hrtimer_start

* add ktime debug info

* change current_irq_begin to local var

* fix bug: setting current timer and setting timeout in driver aren't atomicly

* create->init

* refactoring ktime
This commit is contained in:
zms123456 2024-06-23 22:08:54 +08:00 committed by GitHub
parent 5c1e5d2fca
commit 22b5e5fd7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 132 additions and 139 deletions

View File

@ -104,7 +104,6 @@ struct rt_pic_isr
#ifdef RT_USING_PIC_STATISTICS #ifdef RT_USING_PIC_STATISTICS
struct rt_pic_irq_statistics struct rt_pic_irq_statistics
{ {
rt_ubase_t current_irq_begin[RT_CPUS_NR];
rt_ubase_t max_irq_time_ns; rt_ubase_t max_irq_time_ns;
rt_ubase_t min_irq_time_ns; rt_ubase_t min_irq_time_ns;
rt_ubase_t sum_irq_time_ns; rt_ubase_t sum_irq_time_ns;

View File

@ -22,10 +22,11 @@
struct rt_ktime_hrtimer struct rt_ktime_hrtimer
{ {
struct rt_object parent; /**< inherit from rt_object */ rt_uint8_t flag; /**< compatible to tick timer's flag */
rt_list_t row; char name[RT_NAME_MAX];
rt_list_t node;
void *parameter; void *parameter;
unsigned long init_cnt; unsigned long delay_cnt;
unsigned long timeout_cnt; unsigned long timeout_cnt;
rt_err_t error; rt_err_t error;
struct rt_completion completion; struct rt_completion completion;
@ -113,22 +114,24 @@ unsigned long rt_ktime_hrtimer_getfrq(void);
unsigned long rt_ktime_hrtimer_getcnt(void); unsigned long rt_ktime_hrtimer_getcnt(void);
/** /**
* @brief set hrtimer timeout, when timeout, the timer callback will call timeout * @brief set hrtimer interrupt timeout count (cnt), you should re-implemented it in hrtimer device driver
* *
* @param cnt: hrtimer requires a timing cnt value * @param cnt: hrtimer requires a timing cnt value
* @param timeout: timeout callback
* @param param: parameter
* @return rt_err_t * @return rt_err_t
*/ */
rt_err_t rt_ktime_hrtimer_settimeout(unsigned long cnt, void (*timeout)(void *param), void *param); rt_err_t rt_ktime_hrtimer_settimeout(unsigned long cnt);
/**
* @brief called in hrtimer device driver isr routinue, it will process the timeouts
*/
void rt_ktime_hrtimer_process(void);
void rt_ktime_hrtimer_init(rt_ktime_hrtimer_t timer, void rt_ktime_hrtimer_init(rt_ktime_hrtimer_t timer,
const char *name, const char *name,
unsigned long cnt,
rt_uint8_t flag, rt_uint8_t flag,
void (*timeout)(void *parameter), void (*timeout)(void *parameter),
void *parameter); void *parameter);
rt_err_t rt_ktime_hrtimer_start(rt_ktime_hrtimer_t timer); rt_err_t rt_ktime_hrtimer_start(rt_ktime_hrtimer_t timer, unsigned long cnt);
rt_err_t rt_ktime_hrtimer_stop(rt_ktime_hrtimer_t timer); rt_err_t rt_ktime_hrtimer_stop(rt_ktime_hrtimer_t timer);
rt_err_t rt_ktime_hrtimer_control(rt_ktime_hrtimer_t timer, int cmd, void *arg); rt_err_t rt_ktime_hrtimer_control(rt_ktime_hrtimer_t timer, int cmd, void *arg);
rt_err_t rt_ktime_hrtimer_detach(rt_ktime_hrtimer_t timer); rt_err_t rt_ktime_hrtimer_detach(rt_ktime_hrtimer_t timer);
@ -143,6 +146,7 @@ rt_inline void rt_ktime_hrtimer_keep_errno(rt_ktime_hrtimer_t timer, rt_err_t er
void rt_ktime_hrtimer_delay_init(struct rt_ktime_hrtimer *timer); void rt_ktime_hrtimer_delay_init(struct rt_ktime_hrtimer *timer);
void rt_ktime_hrtimer_delay_detach(struct rt_ktime_hrtimer *timer); void rt_ktime_hrtimer_delay_detach(struct rt_ktime_hrtimer *timer);
void rt_ktime_hrtimer_process(void);
/** /**
* @brief sleep by the cputimer cnt value * @brief sleep by the cputimer cnt value

View File

@ -13,6 +13,10 @@
#include <rthw.h> #include <rthw.h>
#include <rtthread.h> #include <rtthread.h>
#define DBG_SECTION_NAME "drv.ktime"
#define DBG_LEVEL DBG_INFO
#include <rtdbg.h>
#include "ktime.h" #include "ktime.h"
#ifdef ARCH_CPU_64BIT #ifdef ARCH_CPU_64BIT
@ -21,10 +25,14 @@
#define _HRTIMER_MAX_CNT UINT32_MAX #define _HRTIMER_MAX_CNT UINT32_MAX
#endif #endif
static rt_list_t _timer_list = RT_LIST_OBJECT_INIT(_timer_list); static rt_list_t _timer_list = RT_LIST_OBJECT_INIT(_timer_list);
static rt_ktime_hrtimer_t _nowtimer = RT_NULL;
static RT_DEFINE_SPINLOCK(_spinlock); static RT_DEFINE_SPINLOCK(_spinlock);
rt_inline rt_ktime_hrtimer_t _first_hrtimer(void)
{
return rt_list_isempty(&_timer_list) ? RT_NULL : rt_list_first_entry(&_timer_list, struct rt_ktime_hrtimer, node);
}
rt_weak rt_uint64_t rt_ktime_hrtimer_getres(void) rt_weak rt_uint64_t rt_ktime_hrtimer_getres(void)
{ {
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / RT_TICK_PER_SECOND; return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / RT_TICK_PER_SECOND;
@ -40,50 +48,30 @@ rt_weak unsigned long rt_ktime_hrtimer_getcnt(void)
return rt_tick_get(); return rt_tick_get();
} }
static void (*_outcb)(void *param) = RT_NULL; rt_weak rt_err_t rt_ktime_hrtimer_settimeout(unsigned long cnt)
static void _hrtimer_timeout(void *parameter)
{
if (_outcb)
_outcb(parameter);
}
rt_weak rt_err_t rt_ktime_hrtimer_settimeout(unsigned long cnt, void (*timeout)(void *param), void *param)
{ {
static rt_timer_t timer = RT_NULL; static rt_timer_t timer = RT_NULL;
static struct rt_timer _sh_rtimer;
_outcb = timeout; RT_ASSERT(cnt > 0);
if (cnt == 0)
{
if (timer != RT_NULL)
{
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
{
rt_timer_stop(timer);
}
}
if (_outcb)
_outcb(param);
return RT_EOK;
}
if (timer == RT_NULL) if (timer == RT_NULL)
{ {
timer = rt_timer_create("shrtimer", _hrtimer_timeout, param, cnt, RT_TIMER_FLAG_ONE_SHOT); timer = &_sh_rtimer;
rt_timer_init(timer, "shrtimer", (void (*)(void *))rt_ktime_hrtimer_process, RT_NULL, cnt, RT_TIMER_FLAG_ONE_SHOT);
} }
else else
{ {
rt_tick_t tick = cnt; rt_tick_t tick = cnt;
rt_timer_control(timer, RT_TIMER_CTRL_SET_TIME, &tick); rt_timer_control(timer, RT_TIMER_CTRL_SET_TIME, &tick);
rt_timer_control(timer, RT_TIMER_CTRL_SET_PARM, param); rt_timer_control(timer, RT_TIMER_CTRL_SET_PARM, RT_NULL);
} }
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
{ {
rt_timer_stop(timer); rt_timer_stop(timer);
} }
rt_timer_start(timer); rt_timer_start(timer);
return RT_EOK; return RT_EOK;
} }
@ -111,63 +99,81 @@ static void _sleep_timeout(void *parameter)
rt_completion_done(&timer->completion); rt_completion_done(&timer->completion);
} }
static void _set_next_timeout_n_unlock(rt_base_t level); static void _insert_timer_to_list_locked(rt_ktime_hrtimer_t timer)
static void _timeout_callback(void *parameter)
{ {
rt_ktime_hrtimer_t timer; rt_ktime_hrtimer_t iter;
timer = (rt_ktime_hrtimer_t)parameter;
rt_base_t level;
level = rt_spin_lock_irqsave(&_spinlock); rt_list_for_each_entry(iter, &_timer_list, node)
_nowtimer = RT_NULL;
rt_list_remove(&(timer->row));
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
{ {
timer->timeout_func(timer->parameter); if (iter->timeout_cnt > timer->timeout_cnt)
{
break;
}
} }
rt_list_insert_before(&iter->node, &(timer->node));
_set_next_timeout_n_unlock(level); timer->flag |= RT_TIMER_FLAG_ACTIVATED;
} }
static void _set_next_timeout_n_unlock(rt_base_t level) static void _hrtimer_process_locked(void)
{ {
rt_ktime_hrtimer_t t; rt_ktime_hrtimer_t timer;
if (&_timer_list != _timer_list.prev) for (timer = _first_hrtimer();
(timer != RT_NULL) && (timer->timeout_cnt <= rt_ktime_cputimer_getcnt());
timer = _first_hrtimer())
{ {
t = rt_list_entry((&_timer_list)->next, struct rt_ktime_hrtimer, row); rt_list_remove(&(timer->node));
if (_nowtimer != RT_NULL)
if (timer->flag & RT_TIMER_FLAG_PERIODIC)
{ {
if (t != _nowtimer && t->timeout_cnt < _nowtimer->timeout_cnt) timer->timeout_cnt = timer->delay_cnt + rt_ktime_cputimer_getcnt();
{ _insert_timer_to_list_locked(timer);
_nowtimer = t;
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_ktime_hrtimer_settimeout(_cnt_convert(t->timeout_cnt), _timeout_callback, t);
}
else
{
rt_spin_unlock_irqrestore(&_spinlock, level);
}
} }
else else
{ {
_nowtimer = t; timer->flag &= ~RT_TIMER_FLAG_ACTIVATED;
rt_spin_unlock_irqrestore(&_spinlock, level); }
rt_ktime_hrtimer_settimeout(_cnt_convert(t->timeout_cnt), _timeout_callback, t);
if (timer->timeout_func)
{
timer->timeout_func(timer->parameter);
} }
} }
else }
static void _set_next_timeout_locked(void)
{
rt_ktime_hrtimer_t timer;
rt_ubase_t next_timeout_hrtimer_cnt;
if ((timer = _first_hrtimer()) != RT_NULL)
{ {
_nowtimer = RT_NULL; next_timeout_hrtimer_cnt = _cnt_convert(timer->timeout_cnt);
rt_spin_unlock_irqrestore(&_spinlock, level); if (next_timeout_hrtimer_cnt > 0)
rt_ktime_hrtimer_settimeout(0, RT_NULL, RT_NULL); {
rt_ktime_hrtimer_settimeout(next_timeout_hrtimer_cnt);
}
else
{
_hrtimer_process_locked();
_set_next_timeout_locked();
}
} }
} }
void rt_ktime_hrtimer_process(void)
{
rt_base_t level = rt_spin_lock_irqsave(&_spinlock);
_hrtimer_process_locked();
_set_next_timeout_locked();
rt_spin_unlock_irqrestore(&_spinlock, level);
}
void rt_ktime_hrtimer_init(rt_ktime_hrtimer_t timer, void rt_ktime_hrtimer_init(rt_ktime_hrtimer_t timer,
const char *name, const char *name,
unsigned long cnt,
rt_uint8_t flag, rt_uint8_t flag,
void (*timeout)(void *parameter), void (*timeout)(void *parameter),
void *parameter) void *parameter)
@ -175,55 +181,40 @@ void rt_ktime_hrtimer_init(rt_ktime_hrtimer_t timer,
/* parameter check */ /* parameter check */
RT_ASSERT(timer != RT_NULL); RT_ASSERT(timer != RT_NULL);
RT_ASSERT(timeout != RT_NULL); RT_ASSERT(timeout != RT_NULL);
RT_ASSERT(cnt < (_HRTIMER_MAX_CNT / 2));
/* set flag */ rt_memset(timer, 0, sizeof(struct rt_ktime_hrtimer));
timer->parent.flag = flag;
/* set deactivated */ timer->flag = flag & ~RT_TIMER_FLAG_ACTIVATED;
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; timer->timeout_func = timeout;
timer->timeout_func = timeout; timer->parameter = parameter;
timer->parameter = parameter; rt_strncpy(timer->name, name, RT_NAME_MAX - 1);
timer->timeout_cnt = cnt + rt_ktime_cputimer_getcnt(); rt_list_init(&(timer->node));
timer->init_cnt = cnt;
rt_list_init(&(timer->row));
rt_completion_init(&timer->completion); rt_completion_init(&timer->completion);
} }
rt_err_t rt_ktime_hrtimer_start(rt_ktime_hrtimer_t timer) rt_err_t rt_ktime_hrtimer_start(rt_ktime_hrtimer_t timer, unsigned long delay_cnt)
{ {
rt_list_t *timer_list;
rt_base_t level; rt_base_t level;
/* parameter check */ /* parameter check */
RT_ASSERT(timer != RT_NULL); RT_ASSERT(timer != RT_NULL);
RT_ASSERT(delay_cnt < (_HRTIMER_MAX_CNT / 2));
timer->delay_cnt = delay_cnt;
timer->timeout_cnt = timer->delay_cnt + rt_ktime_cputimer_getcnt();
level = rt_spin_lock_irqsave(&_spinlock); level = rt_spin_lock_irqsave(&_spinlock);
rt_list_remove(&timer->row); /* remove timer from list */
/* change status of timer */ if (timer->flag & RT_TIMER_FLAG_ACTIVATED)
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
timer_list = &_timer_list;
for (; timer_list != _timer_list.prev; timer_list = timer_list->next)
{ {
rt_ktime_hrtimer_t t; rt_spin_unlock_irqrestore(&_spinlock, level);
rt_list_t *p = timer_list->next; return -RT_ERROR;
t = rt_list_entry(p, struct rt_ktime_hrtimer, row);
if ((t->timeout_cnt - timer->timeout_cnt) == 0)
{
continue;
}
else if ((t->timeout_cnt - timer->timeout_cnt) < (_HRTIMER_MAX_CNT / 2))
{
break;
}
} }
rt_list_insert_after(timer_list, &(timer->row));
timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED;
_set_next_timeout_n_unlock(level); _insert_timer_to_list_locked(timer);
_set_next_timeout_locked();
rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_EOK; return RT_EOK;
} }
@ -235,16 +226,18 @@ rt_err_t rt_ktime_hrtimer_stop(rt_ktime_hrtimer_t timer)
RT_ASSERT(timer != RT_NULL); /* timer check */ RT_ASSERT(timer != RT_NULL); /* timer check */
level = rt_spin_lock_irqsave(&_spinlock); level = rt_spin_lock_irqsave(&_spinlock);
if (!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED))
if (!(timer->flag & RT_TIMER_FLAG_ACTIVATED))
{ {
rt_spin_unlock_irqrestore(&_spinlock, level); rt_spin_unlock_irqrestore(&_spinlock, level);
return -RT_ERROR; return -RT_ERROR;
} }
_nowtimer = RT_NULL;
rt_list_remove(&timer->row);
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; /* change status */
_set_next_timeout_n_unlock(level); rt_list_remove(&timer->node);
timer->flag &= ~RT_TIMER_FLAG_ACTIVATED;
_set_next_timeout_locked();
rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_EOK; return RT_EOK;
} }
@ -259,26 +252,27 @@ rt_err_t rt_ktime_hrtimer_control(rt_ktime_hrtimer_t timer, int cmd, void *arg)
level = rt_spin_lock_irqsave(&_spinlock); level = rt_spin_lock_irqsave(&_spinlock);
switch (cmd) switch (cmd)
{ {
case RT_TIMER_CTRL_GET_TIME: case RT_TIMER_CTRL_GET_TIME:
*(unsigned long *)arg = timer->init_cnt; *(unsigned long *)arg = timer->delay_cnt;
break; break;
case RT_TIMER_CTRL_SET_TIME: case RT_TIMER_CTRL_SET_TIME:
RT_ASSERT((*(unsigned long *)arg) < (_HRTIMER_MAX_CNT / 2)); RT_ASSERT((*(unsigned long *)arg) < (_HRTIMER_MAX_CNT / 2));
timer->init_cnt = *(unsigned long *)arg; timer->delay_cnt = *(unsigned long *)arg;
timer->timeout_cnt = *(unsigned long *)arg + rt_ktime_cputimer_getcnt(); timer->timeout_cnt = *(unsigned long *)arg + rt_ktime_cputimer_getcnt();
break; break;
case RT_TIMER_CTRL_SET_ONESHOT: case RT_TIMER_CTRL_SET_ONESHOT:
timer->parent.flag &= ~RT_TIMER_FLAG_PERIODIC; timer->flag &= ~RT_TIMER_FLAG_PERIODIC;
break; break;
case RT_TIMER_CTRL_SET_PERIODIC: case RT_TIMER_CTRL_SET_PERIODIC:
timer->parent.flag |= RT_TIMER_FLAG_PERIODIC; timer->flag |= RT_TIMER_FLAG_PERIODIC;
break; break;
case RT_TIMER_CTRL_GET_STATE: case RT_TIMER_CTRL_GET_STATE:
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) if (timer->flag & RT_TIMER_FLAG_ACTIVATED)
{ {
/*timer is start and run*/ /*timer is start and run*/
*(rt_uint32_t *)arg = RT_TIMER_FLAG_ACTIVATED; *(rt_uint32_t *)arg = RT_TIMER_FLAG_ACTIVATED;
@ -330,19 +324,16 @@ rt_err_t rt_ktime_hrtimer_detach(rt_ktime_hrtimer_t timer)
level = rt_spin_lock_irqsave(&_spinlock); level = rt_spin_lock_irqsave(&_spinlock);
/* stop timer */ /* stop timer */
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; timer->flag &= ~RT_TIMER_FLAG_ACTIVATED;
/* when interrupted */ /* when interrupted */
if (timer->error == -RT_EINTR || timer->error == RT_EINTR) if (timer->error == -RT_EINTR || timer->error == RT_EINTR)
{ {
_nowtimer = RT_NULL; rt_list_remove(&timer->node);
rt_list_remove(&timer->row); _set_next_timeout_locked();
_set_next_timeout_n_unlock(level);
}
else
{
rt_spin_unlock_irqrestore(&_spinlock, level);
} }
rt_spin_unlock_irqrestore(&_spinlock, level);
return RT_EOK; return RT_EOK;
} }
@ -350,7 +341,7 @@ rt_err_t rt_ktime_hrtimer_detach(rt_ktime_hrtimer_t timer)
void rt_ktime_hrtimer_delay_init(struct rt_ktime_hrtimer *timer) void rt_ktime_hrtimer_delay_init(struct rt_ktime_hrtimer *timer)
{ {
rt_ktime_hrtimer_init(timer, "hrtimer_sleep", 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_HARD_TIMER, rt_ktime_hrtimer_init(timer, "hrtimer_sleep", RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_HARD_TIMER,
_sleep_timeout, timer); _sleep_timeout, timer);
} }
@ -366,15 +357,15 @@ rt_err_t rt_ktime_hrtimer_sleep(struct rt_ktime_hrtimer *timer, unsigned long cn
if (cnt == 0) if (cnt == 0)
return -RT_EINVAL; return -RT_EINVAL;
timer->timeout_cnt = cnt + rt_ktime_cputimer_getcnt(); err = rt_ktime_hrtimer_start(timer, cnt);
timer->init_cnt = cnt; if (err)
return err;
rt_ktime_hrtimer_start(timer); /* reset the timeout of thread timer and start it */
err = rt_completion_wait_flags(&(timer->completion), RT_WAITING_FOREVER, err = rt_completion_wait_flags(&(timer->completion), RT_WAITING_FOREVER,
RT_INTERRUPTIBLE); RT_INTERRUPTIBLE);
rt_ktime_hrtimer_keep_errno(timer, err); rt_ktime_hrtimer_keep_errno(timer, err);
return RT_EOK; return err;
} }
rt_err_t rt_ktime_hrtimer_ndelay(struct rt_ktime_hrtimer *timer, unsigned long ns) rt_err_t rt_ktime_hrtimer_ndelay(struct rt_ktime_hrtimer *timer, unsigned long ns)

View File

@ -515,6 +515,7 @@ rt_err_t rt_pic_handle_isr(struct rt_pic_irq *pirq)
#ifdef RT_USING_PIC_STATISTICS #ifdef RT_USING_PIC_STATISTICS
struct timespec ts; struct timespec ts;
rt_ubase_t irq_time_ns; rt_ubase_t irq_time_ns;
rt_ubase_t current_irq_begin;
#endif #endif
RT_ASSERT(pirq != RT_NULL); RT_ASSERT(pirq != RT_NULL);
@ -522,7 +523,7 @@ rt_err_t rt_pic_handle_isr(struct rt_pic_irq *pirq)
#ifdef RT_USING_PIC_STATISTICS #ifdef RT_USING_PIC_STATISTICS
rt_ktime_boottime_get_ns(&ts); rt_ktime_boottime_get_ns(&ts);
pirq->stat.current_irq_begin[rt_hw_cpu_id()] = ts.tv_sec * (1000UL * 1000 * 1000) + ts.tv_nsec; current_irq_begin = ts.tv_sec * (1000UL * 1000 * 1000) + ts.tv_nsec;
#endif #endif
handler_nodes = &pirq->isr.list; handler_nodes = &pirq->isr.list;
@ -577,7 +578,7 @@ rt_err_t rt_pic_handle_isr(struct rt_pic_irq *pirq)
#ifdef RT_USING_PIC_STATISTICS #ifdef RT_USING_PIC_STATISTICS
rt_ktime_boottime_get_ns(&ts); rt_ktime_boottime_get_ns(&ts);
irq_time_ns = ts.tv_sec * (1000UL * 1000 * 1000) + ts.tv_nsec - pirq->stat.current_irq_begin[rt_hw_cpu_id()]; irq_time_ns = ts.tv_sec * (1000UL * 1000 * 1000) + ts.tv_nsec - current_irq_begin;
pirq->stat.sum_irq_time_ns += irq_time_ns; pirq->stat.sum_irq_time_ns += irq_time_ns;
if (irq_time_ns < pirq->stat.min_irq_time_ns || pirq->stat.min_irq_time_ns == 0) if (irq_time_ns < pirq->stat.min_irq_time_ns || pirq->stat.min_irq_time_ns == 0)
{ {

View File

@ -881,8 +881,7 @@ static void rtthread_timer_wrapper(void *timerobj)
rt_ktime_cputimer_getres(); rt_ktime_cputimer_getres();
if (timer->reload) if (timer->reload)
{ {
rt_ktime_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_SET_TIME, &(timer->reload)); rt_ktime_hrtimer_start(&timer->hrtimer, timer->reload);
rt_ktime_hrtimer_start(&timer->hrtimer);
} }
#ifdef RT_USING_SMART #ifdef RT_USING_SMART
/* this field is named as tid in musl */ /* this field is named as tid in musl */
@ -1003,7 +1002,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
timer->status = NOT_ACTIVE; timer->status = NOT_ACTIVE;
timer->clockid = clockid; timer->clockid = clockid;
rt_ktime_hrtimer_init(&timer->hrtimer, timername, 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_HARD_TIMER, rt_ktime_hrtimer_init(&timer->hrtimer, timername, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_HARD_TIMER,
rtthread_timer_wrapper, timer); rtthread_timer_wrapper, timer);
_timerid = resource_id_get(&id_timer); _timerid = resource_id_get(&id_timer);
@ -1226,8 +1225,7 @@ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
else else
rt_ktime_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_SET_PERIODIC, RT_NULL); rt_ktime_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_SET_PERIODIC, RT_NULL);
rt_ktime_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_SET_TIME, &(timer->reload)); rt_ktime_hrtimer_start(&timer->hrtimer, timer->reload);
rt_ktime_hrtimer_start(&timer->hrtimer);
return 0; return 0;
} }