NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mintmr.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_CORE_MINTMR_H
2 #define NDNDPDK_CORE_MINTMR_H
3 
6 #include "../dpdk/tsc.h"
7 
9 typedef struct MinTmr {
10  struct cds_list_head h;
12 
14 __attribute__((nonnull)) static __rte_always_inline void
15 MinTmr_Init(MinTmr* tmr) {
16  CDS_INIT_LIST_HEAD(&tmr->h);
17 }
18 
19 typedef void (*MinTmrCb)(MinTmr* tmr, uintptr_t ctx);
20 
22 typedef 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*
40 MinSched_New(int nSlotBits, TscDuration interval, MinTmrCb cb, uintptr_t ctx);
41 
43 __attribute__((nonnull)) void
44 MinSched_Clear(MinSched* sched);
45 
47 __attribute__((nonnull)) void
48 MinSched_Close(MinSched* sched);
49 
50 __attribute__((nonnull)) void
52 
54 __attribute__((nonnull)) static __rte_always_inline void
55 MinSched_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
64 MinSched_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
73 MinTmr_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
86 MinTmr_After(MinTmr* tmr, TscDuration after, MinSched* sched);
87 
89 __attribute__((nonnull)) static inline bool
90 MinTmr_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
struct MinTmr MinTmr
Timer on minute scheduler.
void MinSched_Close(MinSched *sched)
Destroy a minute scheduler.
Definition: mintmr.c:36
void MinSched_Trigger_(MinSched *sched, TscTime now)
Definition: mintmr.c:41
struct MinSched MinSched
Minute scheduler.
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