lsquic_pacer.h revision 10c492f0
1/* Copyright (c) 2017 - 2018 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#ifndef NDEBUG
32    struct {
33        unsigned        n_scheduled;
34    }               pa_stats;
35#endif
36};
37
38
39typedef lsquic_time_t (*tx_time_f)(void *ctx);
40
41void
42pacer_init (struct pacer *, lsquic_cid_t, unsigned max_intertick);
43
44void
45pacer_cleanup (struct pacer *);
46
47void
48pacer_tick (struct pacer *, lsquic_time_t);
49
50int
51pacer_can_schedule (struct pacer *, unsigned n_in_flight);
52
53void
54pacer_packet_scheduled (struct pacer *pacer, unsigned n_in_flight,
55                        int in_recovery, tx_time_f tx_time, void *tx_ctx);
56
57void
58pacer_loss_event (struct pacer *);
59
60#define pacer_next_sched(pacer) (+(pacer)->pa_next_sched)
61
62#endif
63