lsquic_pacer.h revision 229fce07
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov#ifndef LSQUIC_PACER_H 350aadb33SDmitri Tikhonov#define LSQUIC_PACER_H 1 450aadb33SDmitri Tikhonov 550aadb33SDmitri Tikhonovstruct pacer 650aadb33SDmitri Tikhonov{ 750aadb33SDmitri Tikhonov lsquic_cid_t pa_cid; /* Used for logging */ 850aadb33SDmitri Tikhonov lsquic_time_t pa_next_sched; 950aadb33SDmitri Tikhonov lsquic_time_t pa_last_delayed; 1050aadb33SDmitri Tikhonov lsquic_time_t pa_now; 1150aadb33SDmitri Tikhonov 1250aadb33SDmitri Tikhonov /* All tick times are in microseconds */ 1350aadb33SDmitri Tikhonov 1450aadb33SDmitri Tikhonov unsigned pa_max_intertick; /* Maximum intertick time */ 1550aadb33SDmitri Tikhonov 1650aadb33SDmitri Tikhonov /* We keep an average of intertick times, which is our best estimate 1750aadb33SDmitri Tikhonov * for the time when the connection ticks next. This estimate is used 1850aadb33SDmitri Tikhonov * to see whether a packet can be scheduled or not. 1950aadb33SDmitri Tikhonov */ 2050aadb33SDmitri Tikhonov unsigned pa_intertick_avg; /* Smoothed average */ 2150aadb33SDmitri Tikhonov unsigned pa_intertick_var; /* Variance */ 2250aadb33SDmitri Tikhonov 2350aadb33SDmitri Tikhonov unsigned short pa_packet_size; 2450aadb33SDmitri Tikhonov unsigned char pa_burst_tokens; 2550aadb33SDmitri Tikhonov enum { 2650aadb33SDmitri Tikhonov PA_LAST_SCHED_DELAYED = (1 << 0), 2750aadb33SDmitri Tikhonov#ifndef NDEBUG 2850aadb33SDmitri Tikhonov PA_CONSTANT_INTERTICK = (1 << 1), /* Use fake intertick time for testing */ 2950aadb33SDmitri Tikhonov#endif 3050aadb33SDmitri Tikhonov } pa_flags:8; 31bfc7bfd8SDmitri Tikhonov#ifndef NDEBUG 32bfc7bfd8SDmitri Tikhonov struct { 33bfc7bfd8SDmitri Tikhonov unsigned n_scheduled; 34bfc7bfd8SDmitri Tikhonov } pa_stats; 35bfc7bfd8SDmitri Tikhonov#endif 3650aadb33SDmitri Tikhonov}; 3750aadb33SDmitri Tikhonov 3850aadb33SDmitri Tikhonov 3950aadb33SDmitri Tikhonovtypedef lsquic_time_t (*tx_time_f)(void *ctx); 4050aadb33SDmitri Tikhonov 4150aadb33SDmitri Tikhonovvoid 4250aadb33SDmitri Tikhonovpacer_init (struct pacer *, lsquic_cid_t, unsigned max_intertick); 4350aadb33SDmitri Tikhonov 4450aadb33SDmitri Tikhonovvoid 45bfc7bfd8SDmitri Tikhonovpacer_cleanup (struct pacer *); 46bfc7bfd8SDmitri Tikhonov 47bfc7bfd8SDmitri Tikhonovvoid 4850aadb33SDmitri Tikhonovpacer_tick (struct pacer *, lsquic_time_t); 4950aadb33SDmitri Tikhonov 5050aadb33SDmitri Tikhonovint 5150aadb33SDmitri Tikhonovpacer_can_schedule (struct pacer *, unsigned n_in_flight); 5250aadb33SDmitri Tikhonov 5350aadb33SDmitri Tikhonovvoid 5450aadb33SDmitri Tikhonovpacer_packet_scheduled (struct pacer *pacer, unsigned n_in_flight, 5550aadb33SDmitri Tikhonov int in_recovery, tx_time_f tx_time, void *tx_ctx); 5650aadb33SDmitri Tikhonov 5750aadb33SDmitri Tikhonovvoid 5850aadb33SDmitri Tikhonovpacer_loss_event (struct pacer *); 5950aadb33SDmitri Tikhonov 60e8bd737dSDmitri Tikhonov#define pacer_delayed(pacer) ((pacer)->pa_flags & PA_LAST_SCHED_DELAYED) 61e8bd737dSDmitri Tikhonov 6250aadb33SDmitri Tikhonov#define pacer_next_sched(pacer) (+(pacer)->pa_next_sched) 6350aadb33SDmitri Tikhonov 6450aadb33SDmitri Tikhonov#endif 65