5#ifndef _RTE_RCU_QSBR_H_
6#define _RTE_RCU_QSBR_H_
44extern int rte_rcu_log_type;
46#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
47#define __RTE_RCU_DP_LOG(level, fmt, args...) \
48 rte_log(RTE_LOG_ ## level, rte_rcu_log_type, \
49 "%s(): " fmt "\n", __func__, ## args)
51#define __RTE_RCU_DP_LOG(level, fmt, args...)
54#if defined(RTE_LIBRTE_RCU_DEBUG)
55#define __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, level, fmt, args...) do {\
56 if (v->qsbr_cnt[thread_id].lock_cnt) \
57 rte_log(RTE_LOG_ ## level, rte_rcu_log_type, \
58 "%s(): " fmt "\n", __func__, ## args); \
61#define __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, level, fmt, args...)
68#define __RTE_QSBR_THRID_ARRAY_ELM_SIZE (sizeof(uint64_t) * 8)
69#define __RTE_QSBR_THRID_ARRAY_SIZE(max_threads) \
70 RTE_ALIGN(RTE_ALIGN_MUL_CEIL(max_threads, \
71 __RTE_QSBR_THRID_ARRAY_ELM_SIZE) >> 3, RTE_CACHE_LINE_SIZE)
72#define __RTE_QSBR_THRID_ARRAY_ELM(v, i) ((uint64_t *) \
73 ((struct rte_rcu_qsbr_cnt *)(v + 1) + v->max_threads) + i)
74#define __RTE_QSBR_THRID_INDEX_SHIFT 6
75#define __RTE_QSBR_THRID_MASK 0x3f
76#define RTE_QSBR_THRID_INVALID 0xffffffff
79struct rte_rcu_qsbr_cnt {
90#define __RTE_QSBR_CNT_THR_OFFLINE 0
91#define __RTE_QSBR_CNT_INIT 1
92#define __RTE_QSBR_CNT_MAX ((uint64_t)~0)
93#define __RTE_QSBR_TOKEN_SIZE sizeof(uint64_t)
104 uint64_t acked_token;
111 uint32_t num_threads;
113 uint32_t max_threads;
139#define RTE_RCU_QSBR_DQ_NAMESIZE RTE_RING_NAMESIZE
149#define RTE_RCU_QSBR_DQ_MT_UNSAFE 1
193 struct rte_rcu_qsbr *
v;
202struct rte_rcu_qsbr_dq;
307 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
309 __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, ERR,
"Lock counter %u\n",
310 v->qsbr_cnt[thread_id].lock_cnt);
317 t = __atomic_load_n(&v->token, __ATOMIC_RELAXED);
322 __atomic_store_n(&v->qsbr_cnt[thread_id].cnt,
323 t, __ATOMIC_RELAXED);
358 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
360 __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, ERR,
"Lock counter %u\n",
361 v->qsbr_cnt[thread_id].lock_cnt);
368 __atomic_store_n(&v->qsbr_cnt[thread_id].cnt,
369 __RTE_QSBR_CNT_THR_OFFLINE, __ATOMIC_RELEASE);
396 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
398#if defined(RTE_LIBRTE_RCU_DEBUG)
400 __atomic_fetch_add(&v->qsbr_cnt[thread_id].lock_cnt,
401 1, __ATOMIC_ACQUIRE);
429 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
431#if defined(RTE_LIBRTE_RCU_DEBUG)
433 __atomic_fetch_sub(&v->qsbr_cnt[thread_id].lock_cnt,
434 1, __ATOMIC_RELEASE);
436 __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, WARNING,
437 "Lock counter %u. Nested locks?\n",
438 v->qsbr_cnt[thread_id].lock_cnt);
460 RTE_ASSERT(v != NULL);
467 t = __atomic_add_fetch(&v->token, 1, __ATOMIC_RELEASE);
489 RTE_ASSERT(v != NULL && thread_id < v->max_threads);
491 __RTE_RCU_IS_LOCK_CNT_ZERO(v, thread_id, ERR,
"Lock counter %u\n",
492 v->qsbr_cnt[thread_id].lock_cnt);
499 t = __atomic_load_n(&v->token, __ATOMIC_ACQUIRE);
506 if (t != __atomic_load_n(&v->qsbr_cnt[thread_id].cnt, __ATOMIC_RELAXED))
507 __atomic_store_n(&v->qsbr_cnt[thread_id].cnt,
508 t, __ATOMIC_RELEASE);
510 __RTE_RCU_DP_LOG(DEBUG,
"%s: update: token = %" PRIu64
", Thread ID = %d",
511 __func__, t, thread_id);
518__rte_rcu_qsbr_check_selective(
struct rte_rcu_qsbr *v, uint64_t t,
bool wait)
523 uint64_t *reg_thread_id;
524 uint64_t acked_token = __RTE_QSBR_CNT_MAX;
526 for (i = 0, reg_thread_id = __RTE_QSBR_THRID_ARRAY_ELM(v, 0);
528 i++, reg_thread_id++) {
532 bmap = __atomic_load_n(reg_thread_id, __ATOMIC_ACQUIRE);
533 id = i << __RTE_QSBR_THRID_INDEX_SHIFT;
536 j = __builtin_ctzl(bmap);
537 __RTE_RCU_DP_LOG(DEBUG,
538 "%s: check: token = %" PRIu64
", wait = %d, Bit Map = 0x%" PRIx64
", Thread ID = %d",
539 __func__, t, wait, bmap,
id + j);
541 &v->qsbr_cnt[
id + j].cnt,
543 __RTE_RCU_DP_LOG(DEBUG,
544 "%s: status: token = %" PRIu64
", wait = %d, Thread QS cnt = %" PRIu64
", Thread ID = %d",
545 __func__, t, wait, c,
id+j);
551 __RTE_QSBR_CNT_THR_OFFLINE && c < t)) {
560 bmap = __atomic_load_n(reg_thread_id,
570 if (c != __RTE_QSBR_CNT_THR_OFFLINE && acked_token > c)
581 if (acked_token != __RTE_QSBR_CNT_MAX)
582 __atomic_store_n(&v->acked_token, acked_token,
592__rte_rcu_qsbr_check_all(
struct rte_rcu_qsbr *v, uint64_t t,
bool wait)
595 struct rte_rcu_qsbr_cnt *cnt;
597 uint64_t acked_token = __RTE_QSBR_CNT_MAX;
599 for (i = 0, cnt = v->qsbr_cnt; i < v->max_threads; i++, cnt++) {
600 __RTE_RCU_DP_LOG(DEBUG,
601 "%s: check: token = %" PRIu64
", wait = %d, Thread ID = %d",
602 __func__, t, wait, i);
604 c = __atomic_load_n(&cnt->cnt, __ATOMIC_ACQUIRE);
605 __RTE_RCU_DP_LOG(DEBUG,
606 "%s: status: token = %" PRIu64
", wait = %d, Thread QS cnt = %" PRIu64
", Thread ID = %d",
607 __func__, t, wait, c, i);
612 if (
likely(c == __RTE_QSBR_CNT_THR_OFFLINE || c >= t))
625 if (
likely(c != __RTE_QSBR_CNT_THR_OFFLINE && acked_token > c))
633 if (acked_token != __RTE_QSBR_CNT_MAX)
634 __atomic_store_n(&v->acked_token, acked_token,
674 RTE_ASSERT(v != NULL);
677 if (
likely(t <= v->acked_token)) {
678 __RTE_RCU_DP_LOG(DEBUG,
679 "%s: check: token = %" PRIu64
", wait = %d",
681 __RTE_RCU_DP_LOG(DEBUG,
682 "%s: status: least acked token = %" PRIu64,
683 __func__, v->acked_token);
687 if (
likely(v->num_threads == v->max_threads))
688 return __rte_rcu_qsbr_check_all(v, t, wait);
690 return __rte_rcu_qsbr_check_selective(v, t, wait);
749struct rte_rcu_qsbr_dq *
815 unsigned int *freed,
unsigned int *pending,
unsigned int *available);
static void rte_atomic_thread_fence(int memorder)
#define __rte_cache_aligned
#define __rte_always_inline
static void rte_pause(void)
static __rte_always_inline uint64_t rte_rcu_qsbr_start(struct rte_rcu_qsbr *v)
__rte_experimental struct rte_rcu_qsbr_dq * rte_rcu_qsbr_dq_create(const struct rte_rcu_qsbr_dq_parameters *params)
static __rte_always_inline void rte_rcu_qsbr_unlock(__rte_unused struct rte_rcu_qsbr *v, __rte_unused unsigned int thread_id)
int rte_rcu_qsbr_thread_register(struct rte_rcu_qsbr *v, unsigned int thread_id)
static __rte_always_inline void rte_rcu_qsbr_thread_online(struct rte_rcu_qsbr *v, unsigned int thread_id)
int rte_rcu_qsbr_thread_unregister(struct rte_rcu_qsbr *v, unsigned int thread_id)
static __rte_always_inline void rte_rcu_qsbr_lock(__rte_unused struct rte_rcu_qsbr *v, __rte_unused unsigned int thread_id)
__rte_experimental int rte_rcu_qsbr_dq_enqueue(struct rte_rcu_qsbr_dq *dq, void *e)
int rte_rcu_qsbr_init(struct rte_rcu_qsbr *v, uint32_t max_threads)
static __rte_always_inline void rte_rcu_qsbr_thread_offline(struct rte_rcu_qsbr *v, unsigned int thread_id)
__rte_experimental int rte_rcu_qsbr_dq_delete(struct rte_rcu_qsbr_dq *dq)
__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)
void(* rte_rcu_qsbr_free_resource_t)(void *p, void *e, unsigned int n)
void rte_rcu_qsbr_synchronize(struct rte_rcu_qsbr *v, unsigned int thread_id)
int rte_rcu_qsbr_dump(FILE *f, struct rte_rcu_qsbr *v)
static __rte_always_inline int rte_rcu_qsbr_check(struct rte_rcu_qsbr *v, uint64_t t, bool wait)
size_t rte_rcu_qsbr_get_memsize(uint32_t max_threads)
static __rte_always_inline void rte_rcu_qsbr_quiescent(struct rte_rcu_qsbr *v, unsigned int thread_id)
rte_rcu_qsbr_free_resource_t free_fn
uint32_t trigger_reclaim_limit
uint32_t max_reclaim_size