forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuring.h
76 lines (61 loc) · 2.05 KB
/
uring.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef NDNDPDK_CORE_URING_H
#define NDNDPDK_CORE_URING_H
/** @file */
#include "common.h"
#include <liburing.h>
/** @brief io_uring and related counters. */
typedef struct Uring {
struct io_uring uring;
uint64_t nAllocErrs; ///< SQE allocation errors
uint64_t nSubmitted; ///< submitted SQEs
uint64_t nSubmitNonBlock; ///< non-blocking submission batches
uint64_t nSubmitWait; ///< waiting submission batches
uint32_t nQueued; ///< currently queued but unsubmitted
uint32_t nPending; ///< currently submitted but uncompleted
} Uring;
/** @brief Initialize io_uring. */
__attribute__((nonnull)) bool
Uring_Init(Uring* ur, uint32_t capacity);
/** @brief Delete io_uring. */
__attribute__((nonnull)) bool
Uring_Free(Uring* ur);
/** @brief Obtain and enqueue Submission Queue Entry (SQE). */
__attribute__((nonnull)) static __rte_always_inline struct io_uring_sqe*
Uring_GetSqe(Uring* ur) {
struct io_uring_sqe* sqe = io_uring_get_sqe(&ur->uring);
if (unlikely(sqe == NULL)) {
++ur->nAllocErrs;
} else {
++ur->nQueued;
}
return sqe;
}
__attribute__((nonnull)) void
Uring_Submit_(Uring* ur, uint32_t waitLBound, uint32_t cqeBurst);
/**
* @brief Submit queued SQEs.
* @param waitLBound lower bound of @c ur->nPending to use waiting submission.
* @param cqeBurst number of CQEs to wait for in waiting submission.
*/
__attribute__((nonnull)) static __rte_always_inline void
Uring_Submit(Uring* ur, uint32_t waitLBound, uint32_t cqeBurst) {
if (ur->nQueued > 0) {
Uring_Submit_(ur, waitLBound, cqeBurst);
}
}
/** @brief Retrieve Completion Queue Entries (CQEs). */
__attribute__((nonnull)) static inline uint32_t
Uring_PeekCqes(Uring* ur, struct io_uring_cqe* cqes[], size_t count) {
if (ur->nPending == 0) {
return 0;
}
uint32_t n = io_uring_peek_batch_cqe(&ur->uring, cqes, count);
ur->nPending -= n;
return n;
}
/** @brief Release processed CQEs. */
__attribute__((nonnull)) static __rte_always_inline void
Uring_SeenCqes(Uring* ur, uint32_t n) {
io_uring_cq_advance(&ur->uring, n);
}
#endif // NDNDPDK_CORE_URING_H