Lines Matching +full:max +full:- +full:cur
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
5 * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz>
18 return LIH_SIZE - 1 - (ctr % LIH_SIZE); in LIH_INDEX()
24 return lh->counter ? lh->ring[LIH_INDEX(lh->counter - 1)] : NULL; in tfrc_lh_peek()
30 BUG_ON(i >= lh->counter); in tfrc_lh_get_interval()
31 return lh->ring[LIH_INDEX(lh->counter - i - 1)]->li_length; in tfrc_lh_get_interval()
35 * On-demand allocation and de-allocation of entries
39 if (lh->ring[LIH_INDEX(lh->counter)] == NULL) in tfrc_lh_demand_next()
40 lh->ring[LIH_INDEX(lh->counter)] = kmem_cache_alloc(tfrc_lh_slab, in tfrc_lh_demand_next()
42 return lh->ring[LIH_INDEX(lh->counter)]; in tfrc_lh_demand_next()
50 for (lh->counter = 0; lh->counter < LIH_SIZE; lh->counter++) in tfrc_lh_cleanup()
51 if (lh->ring[LIH_INDEX(lh->counter)] != NULL) { in tfrc_lh_cleanup()
53 lh->ring[LIH_INDEX(lh->counter)]); in tfrc_lh_cleanup()
54 lh->ring[LIH_INDEX(lh->counter)] = NULL; in tfrc_lh_cleanup()
61 int i, k = tfrc_lh_length(lh) - 1; /* k is as in rfc3448bis, 5.4 */ in tfrc_lh_calc_i_mean()
74 i_tot1 += i_i * tfrc_lh_weights[i-1]; in tfrc_lh_calc_i_mean()
77 lh->i_mean = max(i_tot0, i_tot1) / w_tot; in tfrc_lh_calc_i_mean()
81 * tfrc_lh_update_i_mean - Update the `open' loss interval I_0
89 struct tfrc_loss_interval *cur = tfrc_lh_peek(lh); in tfrc_lh_update_i_mean() local
90 u32 old_i_mean = lh->i_mean; in tfrc_lh_update_i_mean()
93 if (cur == NULL) /* not initialised */ in tfrc_lh_update_i_mean()
96 len = dccp_delta_seqno(cur->li_seqno, DCCP_SKB_CB(skb)->dccpd_seq) + 1; in tfrc_lh_update_i_mean()
98 if (len - (s64)cur->li_length <= 0) /* duplicate or reordered */ in tfrc_lh_update_i_mean()
101 if (SUB16(dccp_hdr(skb)->dccph_ccval, cur->li_ccval) > 4) in tfrc_lh_update_i_mean()
105 * starting the current loss interval (cur) and if the modulo-16 in tfrc_lh_update_i_mean()
106 * distance from C(cur) to C(S) is greater than 4, consider all in tfrc_lh_update_i_mean()
110 cur->li_is_closed = 1; in tfrc_lh_update_i_mean()
115 cur->li_length = len; in tfrc_lh_update_i_mean()
118 return lh->i_mean < old_i_mean; in tfrc_lh_update_i_mean()
122 static inline u8 tfrc_lh_is_new_loss(struct tfrc_loss_interval *cur, in tfrc_lh_is_new_loss() argument
125 return dccp_delta_seqno(cur->li_seqno, new_loss->tfrchrx_seqno) > 0 && in tfrc_lh_is_new_loss()
126 (cur->li_is_closed || SUB16(new_loss->tfrchrx_ccval, cur->li_ccval) > 4); in tfrc_lh_is_new_loss()
130 * tfrc_lh_interval_add - Insert new record into the Loss Interval database
133 * @calc_first_li: Caller-dependent routine to compute length of first interval
134 * @sk: Used by @calc_first_li in caller-specific way (subtyping)
141 struct tfrc_loss_interval *cur = tfrc_lh_peek(lh), *new; in tfrc_lh_interval_add() local
143 if (cur != NULL && !tfrc_lh_is_new_loss(cur, tfrc_rx_hist_loss_prev(rh))) in tfrc_lh_interval_add()
152 new->li_seqno = tfrc_rx_hist_loss_prev(rh)->tfrchrx_seqno; in tfrc_lh_interval_add()
153 new->li_ccval = tfrc_rx_hist_loss_prev(rh)->tfrchrx_ccval; in tfrc_lh_interval_add()
154 new->li_is_closed = 0; in tfrc_lh_interval_add()
156 if (++lh->counter == 1) in tfrc_lh_interval_add()
157 lh->i_mean = new->li_length = (*calc_first_li)(sk); in tfrc_lh_interval_add()
159 cur->li_length = dccp_delta_seqno(cur->li_seqno, new->li_seqno); in tfrc_lh_interval_add()
160 new->li_length = dccp_delta_seqno(new->li_seqno, in tfrc_lh_interval_add()
161 tfrc_rx_hist_last_rcv(rh)->tfrchrx_seqno) + 1; in tfrc_lh_interval_add()
162 if (lh->counter > (2*LIH_SIZE)) in tfrc_lh_interval_add()
163 lh->counter -= LIH_SIZE; in tfrc_lh_interval_add()
175 return tfrc_lh_slab == NULL ? -ENOBUFS : 0; in tfrc_li_init()