lsquic_pacer.h revision 50aadb33
150aadb33SDmitri Tikhonov/* Copyright (c) 2017 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; 3150aadb33SDmitri Tikhonov}; 3250aadb33SDmitri Tikhonov 3350aadb33SDmitri Tikhonov 3450aadb33SDmitri Tikhonovtypedef lsquic_time_t (*tx_time_f)(void *ctx); 3550aadb33SDmitri Tikhonov 3650aadb33SDmitri Tikhonovvoid 3750aadb33SDmitri Tikhonovpacer_init (struct pacer *, lsquic_cid_t, unsigned max_intertick); 3850aadb33SDmitri Tikhonov 3950aadb33SDmitri Tikhonovvoid 4050aadb33SDmitri Tikhonovpacer_tick (struct pacer *, lsquic_time_t); 4150aadb33SDmitri Tikhonov 4250aadb33SDmitri Tikhonovint 4350aadb33SDmitri Tikhonovpacer_can_schedule (struct pacer *, unsigned n_in_flight); 4450aadb33SDmitri Tikhonov 4550aadb33SDmitri Tikhonovvoid 4650aadb33SDmitri Tikhonovpacer_packet_scheduled (struct pacer *pacer, unsigned n_in_flight, 4750aadb33SDmitri Tikhonov int in_recovery, tx_time_f tx_time, void *tx_ctx); 4850aadb33SDmitri Tikhonov 4950aadb33SDmitri Tikhonovvoid 5050aadb33SDmitri Tikhonovpacer_loss_event (struct pacer *); 5150aadb33SDmitri Tikhonov 5250aadb33SDmitri Tikhonov#define pacer_next_sched(pacer) (+(pacer)->pa_next_sched) 5350aadb33SDmitri Tikhonov 5450aadb33SDmitri Tikhonov#endif 55