lsquic_pacer.h revision 6aba801d
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
146aba801dSDmitri Tikhonov    unsigned        pa_clock_granularity;
1550aadb33SDmitri Tikhonov
166aba801dSDmitri Tikhonov    unsigned        pa_burst_tokens;
1750aadb33SDmitri Tikhonov    enum {
1850aadb33SDmitri Tikhonov        PA_LAST_SCHED_DELAYED   = (1 << 0),
196aba801dSDmitri Tikhonov    }               pa_flags;
20bfc7bfd8SDmitri Tikhonov#ifndef NDEBUG
21bfc7bfd8SDmitri Tikhonov    struct {
22bfc7bfd8SDmitri Tikhonov        unsigned        n_scheduled;
23bfc7bfd8SDmitri Tikhonov    }               pa_stats;
24bfc7bfd8SDmitri Tikhonov#endif
2550aadb33SDmitri Tikhonov};
2650aadb33SDmitri Tikhonov
2750aadb33SDmitri Tikhonov
2850aadb33SDmitri Tikhonovtypedef lsquic_time_t (*tx_time_f)(void *ctx);
2950aadb33SDmitri Tikhonov
3050aadb33SDmitri Tikhonovvoid
316aba801dSDmitri Tikhonovpacer_init (struct pacer *, lsquic_cid_t, unsigned clock_granularity);
3250aadb33SDmitri Tikhonov
3350aadb33SDmitri Tikhonovvoid
34bfc7bfd8SDmitri Tikhonovpacer_cleanup (struct pacer *);
35bfc7bfd8SDmitri Tikhonov
36bfc7bfd8SDmitri Tikhonovvoid
3750aadb33SDmitri Tikhonovpacer_tick (struct pacer *, lsquic_time_t);
3850aadb33SDmitri Tikhonov
3950aadb33SDmitri Tikhonovint
4050aadb33SDmitri Tikhonovpacer_can_schedule (struct pacer *, unsigned n_in_flight);
4150aadb33SDmitri Tikhonov
4250aadb33SDmitri Tikhonovvoid
4350aadb33SDmitri Tikhonovpacer_packet_scheduled (struct pacer *pacer, unsigned n_in_flight,
4450aadb33SDmitri Tikhonov                        int in_recovery, tx_time_f tx_time, void *tx_ctx);
4550aadb33SDmitri Tikhonov
4650aadb33SDmitri Tikhonovvoid
4750aadb33SDmitri Tikhonovpacer_loss_event (struct pacer *);
4850aadb33SDmitri Tikhonov
49e8bd737dSDmitri Tikhonov#define pacer_delayed(pacer) ((pacer)->pa_flags & PA_LAST_SCHED_DELAYED)
50e8bd737dSDmitri Tikhonov
5150aadb33SDmitri Tikhonov#define pacer_next_sched(pacer) (+(pacer)->pa_next_sched)
5250aadb33SDmitri Tikhonov
5350aadb33SDmitri Tikhonov#endif
54