5 #ifndef _RTE_RCU_QSBR_H_
6 #define _RTE_RCU_QSBR_H_
39 extern int rte_rcu_log_type;
41 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
42 #define __RTE_RCU_DP_LOG(level, fmt, args...) \
43 rte_log(RTE_LOG_ ## level, rte_rcu_log_type, \
44 "%s(): " fmt "\n", __func__, ## args)
46 #define __RTE_RCU_DP_LOG(level, fmt, args...)
49 #if defined(RTE_LIBRTE_RCU_DEBUG)
50 #define __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, level, fmt, args...) do {\
51 if (v->qsbr_cnt[thread_id].lock_cnt) \
52 rte_log(RTE_LOG_ ## level, rte_rcu_log_type, \
53 "%s(): " fmt "\n", __func__, ## args); \
56 #define __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, level, fmt, args...)
63 #define __RTE_QSBR_THRID_ARRAY_ELM_SIZE (sizeof(uint64_t) * 8)
64 #define __RTE_QSBR_THRID_ARRAY_SIZE(max_threads) \
65 RTE_ALIGN(RTE_ALIGN_MUL_CEIL(max_threads, \
66 __RTE_QSBR_THRID_ARRAY_ELM_SIZE) >> 3, RTE_CACHE_LINE_SIZE)
67 #define __RTE_QSBR_THRID_ARRAY_ELM(v, i) ((uint64_t *) \
68 ((struct rte_rcu_qsbr_cnt *)(v + 1) + v->max_threads) + i)
69 #define __RTE_QSBR_THRID_INDEX_SHIFT 6
70 #define __RTE_QSBR_THRID_MASK 0x3f
71 #define RTE_QSBR_THRID_INVALID 0xffffffff
74 struct rte_rcu_qsbr_cnt {
85 #define __RTE_QSBR_CNT_THR_OFFLINE 0
86 #define __RTE_QSBR_CNT_INIT 1
87 #define __RTE_QSBR_CNT_MAX ((uint64_t)~0)
88 #define __RTE_QSBR_TOKEN_SIZE sizeof(uint64_t)
106 uint32_t num_threads;
108 uint32_t max_threads;
111 struct rte_rcu_qsbr_cnt qsbr_cnt[0] __rte_cache_aligned;
134 #define RTE_RCU_QSBR_DQ_NAMESIZE RTE_RING_NAMESIZE
144 #define RTE_RCU_QSBR_DQ_MT_UNSAFE 1
188 struct rte_rcu_qsbr *
v;
197 struct rte_rcu_qsbr_dq;
322 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
324 __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, ERR,
"Lock counter %u\n",
325 v->qsbr_cnt[thread_id].lock_cnt);
332 t = __atomic_load_n(&v->token, __ATOMIC_RELAXED);
337 __atomic_store_n(&v->qsbr_cnt[thread_id].cnt,
338 t, __ATOMIC_RELAXED);
347 #ifdef RTE_ARCH_X86_64
351 __atomic_thread_fence(__ATOMIC_SEQ_CST);
382 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
384 __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, ERR,
"Lock counter %u\n",
385 v->qsbr_cnt[thread_id].lock_cnt);
392 __atomic_store_n(&v->qsbr_cnt[thread_id].cnt,
393 __RTE_QSBR_CNT_THR_OFFLINE, __ATOMIC_RELEASE);
424 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
426 #if defined(RTE_LIBRTE_RCU_DEBUG)
428 __atomic_fetch_add(&v->qsbr_cnt[thread_id].lock_cnt,
429 1, __ATOMIC_ACQUIRE);
461 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
463 #if defined(RTE_LIBRTE_RCU_DEBUG)
465 __atomic_fetch_sub(&v->qsbr_cnt[thread_id].lock_cnt,
466 1, __ATOMIC_RELEASE);
468 __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, WARNING,
469 "Lock counter %u. Nested locks?\n",
470 v->qsbr_cnt[thread_id].lock_cnt);
496 RTE_ASSERT(v != NULL);
503 t = __atomic_add_fetch(&v->token, 1, __ATOMIC_RELEASE);
529 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
531 __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, ERR,
"Lock counter %u\n",
532 v->qsbr_cnt[thread_id].lock_cnt);
539 t = __atomic_load_n(&v->token, __ATOMIC_ACQUIRE);
546 if (t != __atomic_load_n(&v->qsbr_cnt[thread_id].cnt, __ATOMIC_RELAXED))
547 __atomic_store_n(&v->qsbr_cnt[thread_id].cnt,
548 t, __ATOMIC_RELEASE);
550 __RTE_RCU_DP_LOG(DEBUG,
"%s: update: token = %"PRIu64
", Thread ID = %d",
551 __func__, t, thread_id);
558 __rte_rcu_qsbr_check_selective(
struct rte_rcu_qsbr *v, uint64_t t,
bool wait)
563 uint64_t *reg_thread_id;
564 uint64_t acked_token = __RTE_QSBR_CNT_MAX;
566 for (i = 0, reg_thread_id = __RTE_QSBR_THRID_ARRAY_ELM(v, 0);
568 i++, reg_thread_id++) {
572 bmap = __atomic_load_n(reg_thread_id, __ATOMIC_ACQUIRE);
573 id = i << __RTE_QSBR_THRID_INDEX_SHIFT;
576 j = __builtin_ctzl(bmap);
577 __RTE_RCU_DP_LOG(DEBUG,
578 "%s: check: token = %"PRIu64
", wait = %d, Bit Map = 0x%"PRIx64
", Thread ID = %d",
579 __func__, t, wait, bmap,
id + j);
581 &v->qsbr_cnt[
id + j].cnt,
583 __RTE_RCU_DP_LOG(DEBUG,
584 "%s: status: token = %"PRIu64
", wait = %d, Thread QS cnt = %"PRIu64
", Thread ID = %d",
585 __func__, t, wait, c,
id+j);
591 __RTE_QSBR_CNT_THR_OFFLINE && c < t)) {
600 bmap = __atomic_load_n(reg_thread_id,
610 if (c != __RTE_QSBR_CNT_THR_OFFLINE && acked_token > c)
621 if (acked_token != __RTE_QSBR_CNT_MAX)
622 __atomic_store_n(&v->acked_token, acked_token,
632 __rte_rcu_qsbr_check_all(
struct rte_rcu_qsbr *v, uint64_t t,
bool wait)
635 struct rte_rcu_qsbr_cnt *cnt;
637 uint64_t acked_token = __RTE_QSBR_CNT_MAX;
639 for (i = 0, cnt = v->qsbr_cnt; i < v->max_threads; i++, cnt++) {
640 __RTE_RCU_DP_LOG(DEBUG,
641 "%s: check: token = %"PRIu64
", wait = %d, Thread ID = %d",
642 __func__, t, wait, i);
644 c = __atomic_load_n(&cnt->cnt, __ATOMIC_ACQUIRE);
645 __RTE_RCU_DP_LOG(DEBUG,
646 "%s: status: token = %"PRIu64
", wait = %d, Thread QS cnt = %"PRIu64
", Thread ID = %d",
647 __func__, t, wait, c, i);
652 if (
likely(c == __RTE_QSBR_CNT_THR_OFFLINE || c >= t))
665 if (
likely(c != __RTE_QSBR_CNT_THR_OFFLINE && acked_token > c))
673 if (acked_token != __RTE_QSBR_CNT_MAX)
674 __atomic_store_n(&v->acked_token, acked_token,
718 RTE_ASSERT(v != NULL);
721 if (
likely(t <= v->acked_token)) {
722 __RTE_RCU_DP_LOG(DEBUG,
723 "%s: check: token = %"PRIu64
", wait = %d",
725 __RTE_RCU_DP_LOG(DEBUG,
726 "%s: status: least acked token = %"PRIu64
"",
727 __func__, v->acked_token);
731 if (
likely(v->num_threads == v->max_threads))
732 return __rte_rcu_qsbr_check_all(v, t, wait);
734 return __rte_rcu_qsbr_check_selective(v, t, wait);
801 struct rte_rcu_qsbr_dq *
867 unsigned int *freed,
unsigned int *pending,
unsigned int *available);
static __rte_experimental __rte_always_inline int rte_rcu_qsbr_check(struct rte_rcu_qsbr *v, uint64_t t, bool wait)
__rte_experimental int rte_rcu_qsbr_thread_register(struct rte_rcu_qsbr *v, unsigned int thread_id)
#define __rte_always_inline
__rte_experimental int rte_rcu_qsbr_dq_reclaim(struct rte_rcu_qsbr_dq *dq, unsigned int n, unsigned int *freed, unsigned int *pending, unsigned int *available)
__rte_experimental int rte_rcu_qsbr_dq_delete(struct rte_rcu_qsbr_dq *dq)
static __rte_experimental __rte_always_inline void rte_rcu_qsbr_thread_online(struct rte_rcu_qsbr *v, unsigned int thread_id)
__rte_experimental int rte_rcu_qsbr_dump(FILE *f, struct rte_rcu_qsbr *v)
static __rte_experimental __rte_always_inline void rte_rcu_qsbr_quiescent(struct rte_rcu_qsbr *v, unsigned int thread_id)
static __rte_experimental __rte_always_inline void rte_rcu_qsbr_thread_offline(struct rte_rcu_qsbr *v, unsigned int thread_id)
void(* rte_rcu_qsbr_free_resource_t)(void *p, void *e, unsigned int n)
rte_rcu_qsbr_free_resource_t free_fn
static void rte_pause(void)
uint32_t trigger_reclaim_limit
uint32_t max_reclaim_size
static __rte_experimental __rte_always_inline void rte_rcu_qsbr_unlock(__rte_unused struct rte_rcu_qsbr *v, __rte_unused unsigned int thread_id)
__rte_experimental int rte_rcu_qsbr_thread_unregister(struct rte_rcu_qsbr *v, unsigned int thread_id)
static __rte_experimental __rte_always_inline uint64_t rte_rcu_qsbr_start(struct rte_rcu_qsbr *v)
__rte_experimental void rte_rcu_qsbr_synchronize(struct rte_rcu_qsbr *v, unsigned int thread_id)
static __rte_experimental __rte_always_inline void rte_rcu_qsbr_lock(__rte_unused struct rte_rcu_qsbr *v, __rte_unused unsigned int thread_id)
#define __rte_cache_aligned
static void rte_smp_mb(void)
__rte_experimental struct rte_rcu_qsbr_dq * rte_rcu_qsbr_dq_create(const struct rte_rcu_qsbr_dq_parameters *params)
__rte_experimental size_t rte_rcu_qsbr_get_memsize(uint32_t max_threads)
__rte_experimental int rte_rcu_qsbr_dq_enqueue(struct rte_rcu_qsbr_dq *dq, void *e)
__rte_experimental int rte_rcu_qsbr_init(struct rte_rcu_qsbr *v, uint32_t max_threads)