lsquic_hpi.h revision fbc6cc04
1fbc6cc04SDmitri Tikhonov/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2fbc6cc04SDmitri Tikhonov/* 3fbc6cc04SDmitri Tikhonov * lsquic_hpi.h - HPI: (Extensible) HTTP Priority Iterator 4fbc6cc04SDmitri Tikhonov * 5fbc6cc04SDmitri Tikhonov * https://tools.ietf.org/html/draft-ietf-httpbis-priority-01 6fbc6cc04SDmitri Tikhonov * 7fbc6cc04SDmitri Tikhonov * Changing a stream's priority when the stream is in the iterator 8fbc6cc04SDmitri Tikhonov * does not change the stream's position in the iterator. 9fbc6cc04SDmitri Tikhonov */ 10fbc6cc04SDmitri Tikhonov 11fbc6cc04SDmitri Tikhonov#ifndef LSQUIC_HPI 12fbc6cc04SDmitri Tikhonov#define LSQUIC_HPI 1 13fbc6cc04SDmitri Tikhonov 14fbc6cc04SDmitri Tikhonovstruct lsquic_conn_public; 15fbc6cc04SDmitri Tikhonov 16fbc6cc04SDmitri Tikhonov/* We add 1 to the urgency when we place them on hpi_streams. Critical 17fbc6cc04SDmitri Tikhonov * streams get the highest-priority slot zero. 18fbc6cc04SDmitri Tikhonov */ 19fbc6cc04SDmitri Tikhonov#define N_HPI_PRIORITIES (2 + LSQUIC_MAX_HTTP_URGENCY) 20fbc6cc04SDmitri Tikhonov 21fbc6cc04SDmitri Tikhonov 22fbc6cc04SDmitri Tikhonovstruct http_prio_iter 23fbc6cc04SDmitri Tikhonov{ 24fbc6cc04SDmitri Tikhonov const char *hpi_name; /* Used for logging */ 25fbc6cc04SDmitri Tikhonov struct lsquic_conn_public *hpi_conn_pub; 26fbc6cc04SDmitri Tikhonov enum { 27fbc6cc04SDmitri Tikhonov HPI_MH_4K = 1 << 0, 28fbc6cc04SDmitri Tikhonov HPI_MH_MALLOC = 1 << 1, 29fbc6cc04SDmitri Tikhonov } hpi_flags; 30fbc6cc04SDmitri Tikhonov unsigned hpi_set[2]; /* Bitmask */ 31fbc6cc04SDmitri Tikhonov unsigned hpi_counts[N_HPI_PRIORITIES]; /* For non-incr only */ 32fbc6cc04SDmitri Tikhonov unsigned hpi_heaped; /* Bitmask */ 33fbc6cc04SDmitri Tikhonov struct lsquic_streams_tailq hpi_streams[2][N_HPI_PRIORITIES]; 34fbc6cc04SDmitri Tikhonov struct min_heap hpi_min_heap; 35fbc6cc04SDmitri Tikhonov /* We do this because http_prio_iter is used in a union with 36fbc6cc04SDmitri Tikhonov * stream_prio_iter, which is over 4KB on the stack. Since we 37fbc6cc04SDmitri Tikhonov * are already allocating this memory on the stack, we might as well 38fbc6cc04SDmitri Tikhonov * use it. 39fbc6cc04SDmitri Tikhonov */ 40fbc6cc04SDmitri Tikhonov struct min_heap_elem hpi_min_heap_els[236]; 41fbc6cc04SDmitri Tikhonov}; 42fbc6cc04SDmitri Tikhonov 43fbc6cc04SDmitri Tikhonov 44fbc6cc04SDmitri Tikhonovvoid 45fbc6cc04SDmitri Tikhonovlsquic_hpi_init (void *, struct lsquic_stream *first, 46fbc6cc04SDmitri Tikhonov struct lsquic_stream *last, uintptr_t next_ptr_offset, 47fbc6cc04SDmitri Tikhonov struct lsquic_conn_public *, const char *name, 48fbc6cc04SDmitri Tikhonov int (*filter)(void *filter_ctx, struct lsquic_stream *), 49fbc6cc04SDmitri Tikhonov void *filter_ctx); 50fbc6cc04SDmitri Tikhonov 51fbc6cc04SDmitri Tikhonovstruct lsquic_stream * 52fbc6cc04SDmitri Tikhonovlsquic_hpi_first (void *); 53fbc6cc04SDmitri Tikhonov 54fbc6cc04SDmitri Tikhonovstruct lsquic_stream * 55fbc6cc04SDmitri Tikhonovlsquic_hpi_next (void *); 56fbc6cc04SDmitri Tikhonov 57fbc6cc04SDmitri Tikhonovvoid 58fbc6cc04SDmitri Tikhonovlsquic_hpi_drop_non_high (void *); 59fbc6cc04SDmitri Tikhonov 60fbc6cc04SDmitri Tikhonovvoid 61fbc6cc04SDmitri Tikhonovlsquic_hpi_drop_high (void *); 62fbc6cc04SDmitri Tikhonov 63fbc6cc04SDmitri Tikhonovvoid 64fbc6cc04SDmitri Tikhonovlsquic_hpi_cleanup (void *); 65fbc6cc04SDmitri Tikhonov 66fbc6cc04SDmitri Tikhonov#ifndef NDEBUG 67fbc6cc04SDmitri Tikhonov#define LSQUIC_HPI_HEAP_TEST_STACK_OK (1 << 0) 68fbc6cc04SDmitri Tikhonov#define LSQUIC_HPI_HEAP_TEST_4K_OK (1 << 1) 69fbc6cc04SDmitri Tikhonov#if LSQUIC_TEST 70fbc6cc04SDmitri Tikhonovvoid 71fbc6cc04SDmitri Tikhonovlsquic_hpi_set_heap_test (int val); 72fbc6cc04SDmitri Tikhonov#endif 73fbc6cc04SDmitri Tikhonov#endif 74fbc6cc04SDmitri Tikhonov 75fbc6cc04SDmitri Tikhonov#endif 76