lsquic_pacer.h revision 06b2a236
1/* Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc. See LICENSE. */ 2#ifndef LSQUIC_PACER_H 3#define LSQUIC_PACER_H 1 4 5struct lsquic_conn; 6 7struct pacer 8{ 9 const struct lsquic_conn 10 *pa_conn; /* Used for logging */ 11 lsquic_time_t pa_next_sched; 12 lsquic_time_t pa_last_delayed; 13 lsquic_time_t pa_now; 14 15 /* All tick times are in microseconds */ 16 17 unsigned pa_clock_granularity; 18 19 unsigned pa_burst_tokens; 20 unsigned pa_n_scheduled; /* Within single tick */ 21 enum { 22 PA_LAST_SCHED_DELAYED = (1 << 0), 23 PA_DELAYED_ON_TICK_IN = (1 << 1), 24 } pa_flags; 25#ifndef NDEBUG 26 struct { 27 unsigned n_scheduled; 28 } pa_stats; 29#endif 30}; 31 32 33typedef lsquic_time_t (*tx_time_f)(void *ctx); 34 35void 36lsquic_pacer_init (struct pacer *, const struct lsquic_conn *, 37 unsigned clock_granularity); 38 39void 40lsquic_pacer_cleanup (struct pacer *); 41 42void 43lsquic_pacer_tick_in (struct pacer *, lsquic_time_t); 44 45void 46lsquic_pacer_tick_out (struct pacer *); 47 48int 49lsquic_pacer_can_schedule (struct pacer *, unsigned n_in_flight); 50 51void 52lsquic_pacer_packet_scheduled (struct pacer *pacer, unsigned n_in_flight, 53 int in_recovery, tx_time_f tx_time, void *tx_ctx); 54 55void 56lsquic_pacer_loss_event (struct pacer *); 57 58#define lsquic_pacer_delayed(pacer) ((pacer)->pa_flags & PA_LAST_SCHED_DELAYED) 59 60#define lsquic_pacer_next_sched(pacer) (+(pacer)->pa_next_sched) 61 62int 63lsquic_pacer_can_schedule_probe (const struct pacer *, 64 unsigned n_in_flight, lsquic_time_t tx_time); 65 66#endif 67