lsquic_pacer.h revision 7d09751d
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov#ifndef LSQUIC_PACER_H 350aadb33SDmitri Tikhonov#define LSQUIC_PACER_H 1 450aadb33SDmitri Tikhonov 55392f7a3SLiteSpeed Techstruct lsquic_conn; 65392f7a3SLiteSpeed Tech 750aadb33SDmitri Tikhonovstruct pacer 850aadb33SDmitri Tikhonov{ 95392f7a3SLiteSpeed Tech const struct lsquic_conn 105392f7a3SLiteSpeed Tech *pa_conn; /* Used for logging */ 1150aadb33SDmitri Tikhonov lsquic_time_t pa_next_sched; 1250aadb33SDmitri Tikhonov lsquic_time_t pa_last_delayed; 1350aadb33SDmitri Tikhonov lsquic_time_t pa_now; 1450aadb33SDmitri Tikhonov 1550aadb33SDmitri Tikhonov /* All tick times are in microseconds */ 1650aadb33SDmitri Tikhonov 176aba801dSDmitri Tikhonov unsigned pa_clock_granularity; 1850aadb33SDmitri Tikhonov 196aba801dSDmitri Tikhonov unsigned pa_burst_tokens; 205392f7a3SLiteSpeed Tech unsigned pa_n_scheduled; /* Within single tick */ 2150aadb33SDmitri Tikhonov enum { 2250aadb33SDmitri Tikhonov PA_LAST_SCHED_DELAYED = (1 << 0), 235392f7a3SLiteSpeed Tech PA_DELAYED_ON_TICK_IN = (1 << 1), 246aba801dSDmitri Tikhonov } pa_flags; 25bfc7bfd8SDmitri Tikhonov#ifndef NDEBUG 26bfc7bfd8SDmitri Tikhonov struct { 27bfc7bfd8SDmitri Tikhonov unsigned n_scheduled; 28bfc7bfd8SDmitri Tikhonov } pa_stats; 29bfc7bfd8SDmitri Tikhonov#endif 3050aadb33SDmitri Tikhonov}; 3150aadb33SDmitri Tikhonov 3250aadb33SDmitri Tikhonov 3350aadb33SDmitri Tikhonovtypedef lsquic_time_t (*tx_time_f)(void *ctx); 3450aadb33SDmitri Tikhonov 3550aadb33SDmitri Tikhonovvoid 365392f7a3SLiteSpeed Techpacer_init (struct pacer *, const struct lsquic_conn *, 375392f7a3SLiteSpeed Tech unsigned clock_granularity); 3850aadb33SDmitri Tikhonov 3950aadb33SDmitri Tikhonovvoid 40bfc7bfd8SDmitri Tikhonovpacer_cleanup (struct pacer *); 41bfc7bfd8SDmitri Tikhonov 42bfc7bfd8SDmitri Tikhonovvoid 435392f7a3SLiteSpeed Techpacer_tick_in (struct pacer *, lsquic_time_t); 445392f7a3SLiteSpeed Tech 455392f7a3SLiteSpeed Techvoid 465392f7a3SLiteSpeed Techpacer_tick_out (struct pacer *); 4750aadb33SDmitri Tikhonov 4850aadb33SDmitri Tikhonovint 4950aadb33SDmitri Tikhonovpacer_can_schedule (struct pacer *, unsigned n_in_flight); 5050aadb33SDmitri Tikhonov 5150aadb33SDmitri Tikhonovvoid 5250aadb33SDmitri Tikhonovpacer_packet_scheduled (struct pacer *pacer, unsigned n_in_flight, 5350aadb33SDmitri Tikhonov int in_recovery, tx_time_f tx_time, void *tx_ctx); 5450aadb33SDmitri Tikhonov 5550aadb33SDmitri Tikhonovvoid 5650aadb33SDmitri Tikhonovpacer_loss_event (struct pacer *); 5750aadb33SDmitri Tikhonov 58e8bd737dSDmitri Tikhonov#define pacer_delayed(pacer) ((pacer)->pa_flags & PA_LAST_SCHED_DELAYED) 59e8bd737dSDmitri Tikhonov 6050aadb33SDmitri Tikhonov#define pacer_next_sched(pacer) (+(pacer)->pa_next_sched) 6150aadb33SDmitri Tikhonov 6250aadb33SDmitri Tikhonov#endif 63