NDN-DPDK
High-Speed Named Data Networking Forwarder
Loading...
Searching...
No Matches
mintmr.h
Go to the documentation of this file.
1#ifndef NDNDPDK_CORE_MINTMR_H
2#define NDNDPDK_CORE_MINTMR_H
3
5
6#include "../dpdk/tsc.h"
7
9typedef struct MinTmr {
10 struct cds_list_head h;
12
14__attribute__((nonnull)) static __rte_always_inline void
15MinTmr_Init(MinTmr* tmr) {
16 CDS_INIT_LIST_HEAD(&tmr->h);
17}
18
19typedef void (*MinTmrCb)(MinTmr* tmr, uintptr_t ctx);
20
22typedef struct MinSched {
26 uintptr_t ctx;
27 uint32_t lastSlot;
28 uint32_t slotMask;
29 uint32_t nSlots;
30 struct cds_list_head slot[];
32
39__attribute__((returns_nonnull)) MinSched*
40MinSched_New(int nSlotBits, TscDuration interval, MinTmrCb cb, uintptr_t ctx);
41
43__attribute__((nonnull)) void
45
47__attribute__((nonnull)) void
49
50__attribute__((nonnull)) void
52
54__attribute__((nonnull)) static __rte_always_inline void
55MinSched_Trigger(MinSched* sched) {
56 TscTime now = rte_get_tsc_cycles();
57 if (now >= sched->nextTime) {
58 MinSched_Trigger_(sched, now);
59 }
60}
61
63__attribute__((nonnull)) static inline TscDuration
64MinSched_GetMaxDelay(MinSched* sched) {
65 return sched->interval * (sched->nSlots - 2);
66}
67
68__attribute__((nonnull)) void
70
72__attribute__((nonnull)) static __rte_always_inline void
73MinTmr_Cancel(MinTmr* tmr) {
74 if (likely(tmr->h.next != NULL && !cds_list_empty(&tmr->h))) {
75 MinTmr_Cancel_(tmr);
76 }
77}
78
85__attribute__((nonnull)) bool
86MinTmr_After(MinTmr* tmr, TscDuration after, MinSched* sched);
87
89__attribute__((nonnull)) static inline bool
90MinTmr_At(MinTmr* tmr, TscTime at, MinSched* sched) {
91 TscTime now = rte_get_tsc_cycles();
92 return MinTmr_After(tmr, at - now, sched);
93}
94
95#endif // NDNDPDK_CORE_MINTMR_H
void MinTmr_Cancel_(MinTmr *tmr)
Definition mintmr.c:59
void MinSched_Close(MinSched *sched)
Destroy a minute scheduler.
Definition mintmr.c:36
void MinSched_Trigger_(MinSched *sched, TscTime now)
Definition mintmr.c:41
bool MinTmr_After(MinTmr *tmr, TscDuration after, MinSched *sched)
Schedule a timer to expire after since current time.
Definition mintmr.c:65
void(* MinTmrCb)(MinTmr *tmr, uintptr_t ctx)
Definition mintmr.h:19
void MinSched_Clear(MinSched *sched)
Cancel all events.
Definition mintmr.c:29
MinSched * MinSched_New(int nSlotBits, TscDuration interval, MinTmrCb cb, uintptr_t ctx)
Create a minute scheduler.
Definition mintmr.c:8
Minute scheduler.
Definition mintmr.h:22
struct cds_list_head slot[]
Definition mintmr.h:30
TscDuration interval
Definition mintmr.h:23
uintptr_t ctx
Definition mintmr.h:26
uint32_t lastSlot
Definition mintmr.h:27
MinTmrCb cb
Definition mintmr.h:25
uint32_t slotMask
Definition mintmr.h:28
TscTime nextTime
Definition mintmr.h:24
uint32_t nSlots
Definition mintmr.h:29
Timer on minute scheduler.
Definition mintmr.h:9
struct cds_list_head h
Definition mintmr.h:10
int64_t TscDuration
Duration in TscTime unit.
Definition tsc.h:12
uint64_t TscTime
TSC clock time point.
Definition tsc.h:9