lsquic_pacer.h revision b8fa6195
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
36a5fa05f9SDmitri Tikhonovlsquic_pacer_init (struct pacer *, const struct lsquic_conn *,
375392f7a3SLiteSpeed Tech                                            unsigned clock_granularity);
3850aadb33SDmitri Tikhonov
3950aadb33SDmitri Tikhonovvoid
40a5fa05f9SDmitri Tikhonovlsquic_pacer_cleanup (struct pacer *);
41bfc7bfd8SDmitri Tikhonov
42bfc7bfd8SDmitri Tikhonovvoid
43a5fa05f9SDmitri Tikhonovlsquic_pacer_tick_in (struct pacer *, lsquic_time_t);
445392f7a3SLiteSpeed Tech
455392f7a3SLiteSpeed Techvoid
46a5fa05f9SDmitri Tikhonovlsquic_pacer_tick_out (struct pacer *);
4750aadb33SDmitri Tikhonov
4850aadb33SDmitri Tikhonovint
49a5fa05f9SDmitri Tikhonovlsquic_pacer_can_schedule (struct pacer *, unsigned n_in_flight);
5050aadb33SDmitri Tikhonov
5150aadb33SDmitri Tikhonovvoid
52a5fa05f9SDmitri Tikhonovlsquic_pacer_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
56a5fa05f9SDmitri Tikhonovlsquic_pacer_loss_event (struct pacer *);
5750aadb33SDmitri Tikhonov
58a5fa05f9SDmitri Tikhonov#define lsquic_pacer_delayed(pacer) ((pacer)->pa_flags & PA_LAST_SCHED_DELAYED)
59e8bd737dSDmitri Tikhonov
60a5fa05f9SDmitri Tikhonov#define lsquic_pacer_next_sched(pacer) (+(pacer)->pa_next_sched)
6150aadb33SDmitri Tikhonov
62b8fa6195SDmitri Tikhonovint
63b8fa6195SDmitri Tikhonovlsquic_pacer_can_schedule_probe (const struct pacer *,
64b8fa6195SDmitri Tikhonov                                unsigned n_in_flight, lsquic_time_t tx_time);
65b8fa6195SDmitri Tikhonov
6650aadb33SDmitri Tikhonov#endif
67