MCPcopy Create free account
hub / github.com/F-Stack/f-stack / timer_set_config_state

Function timer_set_config_state

dpdk/lib/timer/rte_timer.c:221–266  ·  view source on GitHub ↗

* if timer is pending or stopped (or running on the same core than * us), mark timer as configuring, and on success return the previous * status of the timer */

Source from the content-addressed store, hash-verified

219 * status of the timer
220 */
221static int
222timer_set_config_state(struct rte_timer *tim,
223 union rte_timer_status *ret_prev_status,
224 struct priv_timer *priv_timer)
225{
226 union rte_timer_status prev_status, status;
227 int success = 0;
228 unsigned lcore_id;
229
230 lcore_id = rte_lcore_id();
231
232 /* wait that the timer is in correct status before update,
233 * and mark it as being configured */
234 prev_status.u32 = rte_atomic_load_explicit(&tim->status.u32, rte_memory_order_relaxed);
235
236 while (success == 0) {
237 /* timer is running on another core
238 * or ready to run on local core, exit
239 */
240 if (prev_status.state == RTE_TIMER_RUNNING &&
241 (prev_status.owner != (uint16_t)lcore_id ||
242 tim != priv_timer[lcore_id].running_tim))
243 return -1;
244
245 /* timer is being configured on another core */
246 if (prev_status.state == RTE_TIMER_CONFIG)
247 return -1;
248
249 /* here, we know that timer is stopped or pending,
250 * mark it atomically as being configured */
251 status.state = RTE_TIMER_CONFIG;
252 status.owner = (int16_t)lcore_id;
253 /* CONFIG states are acting as locked states. If the
254 * timer is in CONFIG state, the state cannot be changed
255 * by other threads. So, we should use ACQUIRE here.
256 */
257 success = rte_atomic_compare_exchange_strong_explicit(&tim->status.u32,
258 (uint32_t *)(uintptr_t)&prev_status.u32,
259 status.u32,
260 rte_memory_order_acquire,
261 rte_memory_order_relaxed);
262 }
263
264 ret_prev_status->u32 = prev_status.u32;
265 return 0;
266}
267
268/*
269 * if timer is pending, mark timer as running

Callers 2

__rte_timer_resetFunction · 0.85
__rte_timer_stopFunction · 0.85

Calls 1

rte_lcore_idFunction · 0.85

Tested by

no test coverage detected