+#ifdef KERNEL
+
+/* We consider persist, keep and 2msl as slow timers which can be coalesced
+ * at a higher granularity (500 ms). Rexmt and delayed ack are considered fast
+ * timers which fire in the order of 100ms.
+ *
+ * The following conditional is to check if a timer is one of the slow timers. This
+ * is fast and works well for now. If we add more slow timers for any reason,
+ * we may need to change this.
+ */
+#define IS_TIMER_SLOW(ind) ((ind & 0x3) != 0)
+
+struct tcptimerlist;
+
+struct tcptimerentry {
+ LIST_ENTRY(tcptimerentry) le; /* links for timer list */
+ uint32_t timer_start; /* tcp clock when the timer was started */
+ uint16_t index; /* index of lowest timer that needs to run first */
+ uint32_t runtime; /* deadline at which the first timer has to fire */
+};
+
+LIST_HEAD(timerlisthead, tcptimerentry);
+
+struct tcptimerlist {
+ struct timerlisthead lhead; /* head of the list of timer entries */
+ lck_mtx_t *mtx; /* lock to protect the list */
+ lck_attr_t *mtx_attr; /* mutex attributes */
+ lck_grp_t *mtx_grp; /* mutex group definition */
+ lck_grp_attr_t *mtx_grp_attr; /* mutex group attributes */
+ uint32_t fast_quantum; /* minimum time quantum to coalesce fast timers */
+ uint32_t slow_quantum; /* minimum time quantum to coalesce slow timers */
+ thread_call_t call; /* call entry */
+ uint32_t runtime; /* time at which this list is going to run */
+ uint32_t entries; /* Number of entries on the list */
+ uint32_t maxentries; /* Max number of entries at any time */
+
+ /* Set desired mode when timer list running */
+ boolean_t running; /* Set when timer list is being processed */
+#define TCP_TIMERLIST_FASTMODE 0x1
+#define TCP_TIMERLIST_SLOWMODE 0x2
+ uint32_t mode; /* Current mode, fast or slow */
+ uint32_t pref_mode; /* Preferred mode set by a connection, fast or slow */
+ uint32_t pref_offset; /* Preferred offset set by a connection */
+ uint32_t idlegen; /* Number of times the list has been idle in fast mode */
+ struct tcptimerentry *next_te; /* Store the next timer entry pointer to process */
+
+};
+
+#define TCP_FASTMODE_IDLEGEN_MAX 20 /* Approximately 2 seconds */
+