src/dpdk/lib/librte_timer/rte_timer.c
static int
__rte_timer_reset(struct rte_timer *tim, uint64_t expire,
		  uint64_t period, unsigned tim_lcore,
		  rte_timer_cb_t fct, void *arg,
		  int local_is_locked,
		  struct rte_timer_data *timer_data)
{
	union rte_timer_status prev_status, status;
	int ret;
	unsigned lcore_id = rte_lcore_id();
	struct priv_timer *priv_timer = timer_data->priv_timer;

	/* round robin for tim_lcore */
	if (tim_lcore == (unsigned)LCORE_ID_ANY) {
		if (lcore_id < RTE_MAX_LCORE) {
			/* EAL thread with valid lcore_id */
			tim_lcore = rte_get_next_lcore(
				priv_timer[lcore_id].prev_lcore,
				0, 1);
			priv_timer[lcore_id].prev_lcore = tim_lcore;
		} else
			/* non-EAL thread do not run rte_timer_manage(),
			 * so schedule the timer on the first enabled lcore. */
			tim_lcore = rte_get_next_lcore(LCORE_ID_ANY, 0, 1);
	}

	/* wait that the timer is in correct status before update,
	 * and mark it as being configured */
	ret = timer_set_config_state(tim, &prev_status, priv_timer);
	if (ret < 0)
		return -1;

	__TIMER_STAT_ADD(priv_timer, reset, 1);
	if (prev_status.state == RTE_TIMER_RUNNING &&
	    lcore_id < RTE_MAX_LCORE) {
		priv_timer[lcore_id].updated = 1;
	}

	/* remove it from list */
	if (prev_status.state == RTE_TIMER_PENDING) {
		timer_del(tim, prev_status, local_is_locked, priv_timer);
		__TIMER_STAT_ADD(priv_timer, pending, -1);
	}

	tim->period = period;
	tim->expire = expire;
	tim->f = fct;
	tim->arg = arg;

	/* if timer needs to be scheduled on another core, we need to
	 * lock the destination list; if it is on local core, we need to lock if
	 * we are not called from rte_timer_manage()
	 */
	if (tim_lcore != lcore_id || !local_is_locked)
		rte_spinlock_lock(&priv_timer[tim_lcore].list_lock);

	__TIMER_STAT_ADD(priv_timer, pending, 1);
	timer_add(tim, tim_lcore, priv_timer);

	/* update state: as we are in CONFIG state, only us can modify
	 * the state so we don't need to use cmpset() here */
	status.state = RTE_TIMER_PENDING;
	status.owner = (int16_t)tim_lcore;
	/* The "RELEASE" ordering guarantees the memory operations above
	 * the status update are observed before the update by all threads
	 */
	__atomic_store_n(&tim->status.u32, status.u32, __ATOMIC_RELEASE);

	if (tim_lcore != lcore_id || !local_is_locked)
		rte_spinlock_unlock(&priv_timer[tim_lcore].list_lock);

	return 0;
}
/* Reset and start the timer associated with the timer handle (private func) */
Reset and start the timer associated with the timer handle (private func)
Reset and start the timer associated with the timer handle ( private func )
static int
__rte_timer_reset(struct rte_timer *tim, uint64_t expire,
		  uint64_t period, unsigned tim_lcore,
		  rte_timer_cb_t fct, void *arg,
		  int local_is_locked,
		  struct rte_timer_data *timer_data)
{
	union rte_timer_status prev_status, status;
	int ret;
	unsigned lcore_id = rte_lcore_id();
	struct priv_timer *priv_timer = timer_data->priv_timer;
	if (tim_lcore == (unsigned)LCORE_ID_ANY) {
		if (lcore_id < RTE_MAX_LCORE) {
			tim_lcore = rte_get_next_lcore(
				priv_timer[lcore_id].prev_lcore,
				0, 1);
			priv_timer[lcore_id].prev_lcore = tim_lcore;
		} else
			tim_lcore = rte_get_next_lcore(LCORE_ID_ANY, 0, 1);
	}
	ret = timer_set_config_state(tim, &prev_status, priv_timer);
	if (ret < 0)
		return -1;
	__TIMER_STAT_ADD(priv_timer, reset, 1);
	if (prev_status.state == RTE_TIMER_RUNNING &&
	    lcore_id < RTE_MAX_LCORE) {
		priv_timer[lcore_id].updated = 1;
	}
	if (prev_status.state == RTE_TIMER_PENDING) {
		timer_del(tim, prev_status, local_is_locked, priv_timer);
		__TIMER_STAT_ADD(priv_timer, pending, -1);
	}
	tim->period = period;
	tim->expire = expire;
	tim->f = fct;
	tim->arg = arg;
	if (tim_lcore != lcore_id || !local_is_locked)
		rte_spinlock_lock(&priv_timer[tim_lcore].list_lock);
	__TIMER_STAT_ADD(priv_timer, pending, 1);
	timer_add(tim, tim_lcore, priv_timer);
	status.state = RTE_TIMER_PENDING;
	status.owner = (int16_t)tim_lcore;
	__atomic_store_n(&tim->status.u32, status.u32, __ATOMIC_RELEASE);
	if (tim_lcore != lcore_id || !local_is_locked)
		rte_spinlock_unlock(&priv_timer[tim_lcore].list_lock);
	return 0;
}
static int __rte_timer_reset ( struct rte_timer * tim , uint64_t expire , uint64_t period , unsigned tim_lcore , rte_timer_cb_t fct , void * arg , int local_is_locked , struct rte_timer_data * timer_data ) { union rte_timer_status prev_status , status ; int ret ; unsigned lcore_id = rte_lcore_id ( ) ; struct priv_timer * priv_timer = timer_data -> priv_timer ; if ( tim_lcore == ( unsigned ) LCORE_ID_ANY ) { if ( lcore_id < RTE_MAX_LCORE ) { tim_lcore = rte_get_next_lcore ( priv_timer [ lcore_id ] . prev_lcore , 0 , 1 ) ; priv_timer [ lcore_id ] . prev_lcore = tim_lcore ; } else tim_lcore = rte_get_next_lcore ( LCORE_ID_ANY , 0 , 1 ) ; } ret = timer_set_config_state ( tim , & prev_status , priv_timer ) ; if ( ret < 0 ) return -1 ; __TIMER_STAT_ADD ( priv_timer , reset , 1 ) ; if ( prev_status . state == RTE_TIMER_RUNNING && lcore_id < RTE_MAX_LCORE ) { priv_timer [ lcore_id ] . updated = 1 ; } if ( prev_status . state == RTE_TIMER_PENDING ) { timer_del ( tim , prev_status , local_is_locked , priv_timer ) ; __TIMER_STAT_ADD ( priv_timer , pending , -1 ) ; } tim -> period = period ; tim -> expire = expire ; tim -> f = fct ; tim -> arg = arg ; if ( tim_lcore != lcore_id || ! local_is_locked ) rte_spinlock_lock ( & priv_timer [ tim_lcore ] . list_lock ) ; __TIMER_STAT_ADD ( priv_timer , pending , 1 ) ; timer_add ( tim , tim_lcore , priv_timer ) ; status . state = RTE_TIMER_PENDING ; status . owner = ( int16_t ) tim_lcore ; __atomic_store_n ( & tim -> status . u32 , status . u32 , __ATOMIC_RELEASE ) ; if ( tim_lcore != lcore_id || ! local_is_locked ) rte_spinlock_unlock ( & priv_timer [ tim_lcore ] . list_lock ) ; return 0 ; }
Reset and start the timer associated with the timer handle (private func)
Reset and start the timer associated with the timer handle ( private func )
/* round robin for tim_lcore */ /* EAL thread with valid lcore_id */ /* non-EAL thread do not run rte_timer_manage(),
			 * so schedule the timer on the first enabled lcore. */ /* wait that the timer is in correct status before update,
	 * and mark it as being configured */ /* remove it from list */ /* if timer needs to be scheduled on another core, we need to
	 * lock the destination list; if it is on local core, we need to lock if
	 * we are not called from rte_timer_manage()
	 */ /* update state: as we are in CONFIG state, only us can modify
	 * the state so we don't need to use cmpset() here */ /* The "RELEASE" ordering guarantees the memory operations above
	 * the status update are observed before the update by all threads
	 */