lsquic_pacer.h revision 50aadb33
1/* Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE. */
2#ifndef LSQUIC_PACER_H
3#define LSQUIC_PACER_H 1
4
5struct pacer
6{
7    lsquic_cid_t    pa_cid;             /* Used for logging */
8    lsquic_time_t   pa_next_sched;
9    lsquic_time_t   pa_last_delayed;
10    lsquic_time_t   pa_now;
11
12    /* All tick times are in microseconds */
13
14    unsigned        pa_max_intertick;   /* Maximum intertick time */
15
16    /* We keep an average of intertick times, which is our best estimate
17     * for the time when the connection ticks next.  This estimate is used
18     * to see whether a packet can be scheduled or not.
19     */
20    unsigned        pa_intertick_avg;   /* Smoothed average */
21    unsigned        pa_intertick_var;   /* Variance */
22
23    unsigned short  pa_packet_size;
24    unsigned char   pa_burst_tokens;
25    enum {
26        PA_LAST_SCHED_DELAYED   = (1 << 0),
27#ifndef NDEBUG
28        PA_CONSTANT_INTERTICK   = (1 << 1), /* Use fake intertick time for testing */
29#endif
30    }               pa_flags:8;
31};
32
33
34typedef lsquic_time_t (*tx_time_f)(void *ctx);
35
36void
37pacer_init (struct pacer *, lsquic_cid_t, unsigned max_intertick);
38
39void
40pacer_tick (struct pacer *, lsquic_time_t);
41
42int
43pacer_can_schedule (struct pacer *, unsigned n_in_flight);
44
45void
46pacer_packet_scheduled (struct pacer *pacer, unsigned n_in_flight,
47                        int in_recovery, tx_time_f tx_time, void *tx_ctx);
48
49void
50pacer_loss_event (struct pacer *);
51
52#define pacer_next_sched(pacer) (+(pacer)->pa_next_sched)
53
54#endif
55