xref: /linux/net/ipv4/tcp_lp.c (revision 726e5e49c91cabc091fad3150342803d5d3d2d2e)
109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
27c106d7eSWong Hoi Sing Edison /*
37c106d7eSWong Hoi Sing Edison  * TCP Low Priority (TCP-LP)
47c106d7eSWong Hoi Sing Edison  *
57c106d7eSWong Hoi Sing Edison  * TCP Low Priority is a distributed algorithm whose goal is to utilize only
67c106d7eSWong Hoi Sing Edison  *   the excess network bandwidth as compared to the ``fair share`` of
73795da47SWong Hoi Sing Edison  *   bandwidth as targeted by TCP.
87c106d7eSWong Hoi Sing Edison  *
97c106d7eSWong Hoi Sing Edison  * As of 2.6.13, Linux supports pluggable congestion control algorithms.
107c106d7eSWong Hoi Sing Edison  * Due to the limitation of the API, we take the following changes from
117c106d7eSWong Hoi Sing Edison  * the original TCP-LP implementation:
127c106d7eSWong Hoi Sing Edison  *   o We use newReno in most core CA handling. Only add some checking
137c106d7eSWong Hoi Sing Edison  *     within cong_avoid.
147c106d7eSWong Hoi Sing Edison  *   o Error correcting in remote HZ, therefore remote HZ will be keeped
157c106d7eSWong Hoi Sing Edison  *     on checking and updating.
1625985edcSLucas De Marchi  *   o Handling calculation of One-Way-Delay (OWD) within rtt_sample, since
177c106d7eSWong Hoi Sing Edison  *     OWD have a similar meaning as RTT. Also correct the buggy formular.
187c106d7eSWong Hoi Sing Edison  *   o Handle reaction for Early Congestion Indication (ECI) within
197c106d7eSWong Hoi Sing Edison  *     pkts_acked, as mentioned within pseudo code.
207c106d7eSWong Hoi Sing Edison  *   o OWD is handled in relative format, where local time stamp will in
217c106d7eSWong Hoi Sing Edison  *     tcp_time_stamp format.
227c106d7eSWong Hoi Sing Edison  *
233795da47SWong Hoi Sing Edison  * Original Author:
243795da47SWong Hoi Sing Edison  *   Aleksandar Kuzmanovic <akuzma@northwestern.edu>
253795da47SWong Hoi Sing Edison  * Available from:
263795da47SWong Hoi Sing Edison  *   http://www.ece.rice.edu/~akuzma/Doc/akuzma/TCP-LP.pdf
273795da47SWong Hoi Sing Edison  * Original implementation for 2.4.19:
283795da47SWong Hoi Sing Edison  *   http://www-ece.rice.edu/networks/TCP-LP/
297c106d7eSWong Hoi Sing Edison  *
303795da47SWong Hoi Sing Edison  * 2.6.x module Authors:
313795da47SWong Hoi Sing Edison  *   Wong Hoi Sing, Edison <hswong3i@gmail.com>
323795da47SWong Hoi Sing Edison  *   Hung Hing Lun, Mike <hlhung3i@gmail.com>
333795da47SWong Hoi Sing Edison  * SourceForge project page:
343795da47SWong Hoi Sing Edison  *   http://tcp-lp-mod.sourceforge.net/
357c106d7eSWong Hoi Sing Edison  */
367c106d7eSWong Hoi Sing Edison 
377c106d7eSWong Hoi Sing Edison #include <linux/module.h>
387c106d7eSWong Hoi Sing Edison #include <net/tcp.h>
397c106d7eSWong Hoi Sing Edison 
407c106d7eSWong Hoi Sing Edison /* resolution of owd */
419a568de4SEric Dumazet #define LP_RESOL       TCP_TS_HZ
427c106d7eSWong Hoi Sing Edison 
437c106d7eSWong Hoi Sing Edison /**
447c106d7eSWong Hoi Sing Edison  * enum tcp_lp_state
457c106d7eSWong Hoi Sing Edison  * @LP_VALID_RHZ: is remote HZ valid?
467c106d7eSWong Hoi Sing Edison  * @LP_VALID_OWD: is OWD valid?
477c106d7eSWong Hoi Sing Edison  * @LP_WITHIN_THR: are we within threshold?
487c106d7eSWong Hoi Sing Edison  * @LP_WITHIN_INF: are we within inference?
497c106d7eSWong Hoi Sing Edison  *
507c106d7eSWong Hoi Sing Edison  * TCP-LP's state flags.
517c106d7eSWong Hoi Sing Edison  * We create this set of state flag mainly for debugging.
527c106d7eSWong Hoi Sing Edison  */
537c106d7eSWong Hoi Sing Edison enum tcp_lp_state {
547c106d7eSWong Hoi Sing Edison 	LP_VALID_RHZ = (1 << 0),
557c106d7eSWong Hoi Sing Edison 	LP_VALID_OWD = (1 << 1),
567c106d7eSWong Hoi Sing Edison 	LP_WITHIN_THR = (1 << 3),
577c106d7eSWong Hoi Sing Edison 	LP_WITHIN_INF = (1 << 4),
587c106d7eSWong Hoi Sing Edison };
597c106d7eSWong Hoi Sing Edison 
607c106d7eSWong Hoi Sing Edison /**
617c106d7eSWong Hoi Sing Edison  * struct lp
627c106d7eSWong Hoi Sing Edison  * @flag: TCP-LP state flag
637c106d7eSWong Hoi Sing Edison  * @sowd: smoothed OWD << 3
647c106d7eSWong Hoi Sing Edison  * @owd_min: min OWD
657c106d7eSWong Hoi Sing Edison  * @owd_max: max OWD
667c106d7eSWong Hoi Sing Edison  * @owd_max_rsv: resrved max owd
677c106d7eSWong Hoi Sing Edison  * @remote_hz: estimated remote HZ
687c106d7eSWong Hoi Sing Edison  * @remote_ref_time: remote reference time
697c106d7eSWong Hoi Sing Edison  * @local_ref_time: local reference time
707c106d7eSWong Hoi Sing Edison  * @last_drop: time for last active drop
717c106d7eSWong Hoi Sing Edison  * @inference: current inference
727c106d7eSWong Hoi Sing Edison  *
737c106d7eSWong Hoi Sing Edison  * TCP-LP's private struct.
747c106d7eSWong Hoi Sing Edison  * We get the idea from original TCP-LP implementation where only left those we
757c106d7eSWong Hoi Sing Edison  * found are really useful.
767c106d7eSWong Hoi Sing Edison  */
777c106d7eSWong Hoi Sing Edison struct lp {
787c106d7eSWong Hoi Sing Edison 	u32 flag;
797c106d7eSWong Hoi Sing Edison 	u32 sowd;
807c106d7eSWong Hoi Sing Edison 	u32 owd_min;
817c106d7eSWong Hoi Sing Edison 	u32 owd_max;
827c106d7eSWong Hoi Sing Edison 	u32 owd_max_rsv;
837c106d7eSWong Hoi Sing Edison 	u32 remote_hz;
847c106d7eSWong Hoi Sing Edison 	u32 remote_ref_time;
857c106d7eSWong Hoi Sing Edison 	u32 local_ref_time;
867c106d7eSWong Hoi Sing Edison 	u32 last_drop;
877c106d7eSWong Hoi Sing Edison 	u32 inference;
887c106d7eSWong Hoi Sing Edison };
897c106d7eSWong Hoi Sing Edison 
907c106d7eSWong Hoi Sing Edison /**
917c106d7eSWong Hoi Sing Edison  * tcp_lp_init
92*726e5e49SAndrew Lunn  * @sk: socket to initialize congestion control algorithm for
937c106d7eSWong Hoi Sing Edison  *
947c106d7eSWong Hoi Sing Edison  * Init all required variables.
957c106d7eSWong Hoi Sing Edison  * Clone the handling from Vegas module implementation.
967c106d7eSWong Hoi Sing Edison  */
977c106d7eSWong Hoi Sing Edison static void tcp_lp_init(struct sock *sk)
987c106d7eSWong Hoi Sing Edison {
997c106d7eSWong Hoi Sing Edison 	struct lp *lp = inet_csk_ca(sk);
1007c106d7eSWong Hoi Sing Edison 
1017c106d7eSWong Hoi Sing Edison 	lp->flag = 0;
1027c106d7eSWong Hoi Sing Edison 	lp->sowd = 0;
1037c106d7eSWong Hoi Sing Edison 	lp->owd_min = 0xffffffff;
1047c106d7eSWong Hoi Sing Edison 	lp->owd_max = 0;
1057c106d7eSWong Hoi Sing Edison 	lp->owd_max_rsv = 0;
1067c106d7eSWong Hoi Sing Edison 	lp->remote_hz = 0;
1077c106d7eSWong Hoi Sing Edison 	lp->remote_ref_time = 0;
1087c106d7eSWong Hoi Sing Edison 	lp->local_ref_time = 0;
1097c106d7eSWong Hoi Sing Edison 	lp->last_drop = 0;
1107c106d7eSWong Hoi Sing Edison 	lp->inference = 0;
1117c106d7eSWong Hoi Sing Edison }
1127c106d7eSWong Hoi Sing Edison 
1137c106d7eSWong Hoi Sing Edison /**
1147c106d7eSWong Hoi Sing Edison  * tcp_lp_cong_avoid
115*726e5e49SAndrew Lunn  * @sk: socket to avoid congesting
1167c106d7eSWong Hoi Sing Edison  *
1177c106d7eSWong Hoi Sing Edison  * Implementation of cong_avoid.
1187c106d7eSWong Hoi Sing Edison  * Will only call newReno CA when away from inference.
1197c106d7eSWong Hoi Sing Edison  * From TCP-LP's paper, this will be handled in additive increasement.
1207c106d7eSWong Hoi Sing Edison  */
12124901551SEric Dumazet static void tcp_lp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
1227c106d7eSWong Hoi Sing Edison {
1237c106d7eSWong Hoi Sing Edison 	struct lp *lp = inet_csk_ca(sk);
1247c106d7eSWong Hoi Sing Edison 
1257c106d7eSWong Hoi Sing Edison 	if (!(lp->flag & LP_WITHIN_INF))
12624901551SEric Dumazet 		tcp_reno_cong_avoid(sk, ack, acked);
1277c106d7eSWong Hoi Sing Edison }
1287c106d7eSWong Hoi Sing Edison 
1297c106d7eSWong Hoi Sing Edison /**
1307c106d7eSWong Hoi Sing Edison  * tcp_lp_remote_hz_estimator
131*726e5e49SAndrew Lunn  * @sk: socket which needs an estimate for the remote HZs
1327c106d7eSWong Hoi Sing Edison  *
1337c106d7eSWong Hoi Sing Edison  * Estimate remote HZ.
1347c106d7eSWong Hoi Sing Edison  * We keep on updating the estimated value, where original TCP-LP
1357c106d7eSWong Hoi Sing Edison  * implementation only guest it for once and use forever.
1367c106d7eSWong Hoi Sing Edison  */
1377c106d7eSWong Hoi Sing Edison static u32 tcp_lp_remote_hz_estimator(struct sock *sk)
1387c106d7eSWong Hoi Sing Edison {
1397c106d7eSWong Hoi Sing Edison 	struct tcp_sock *tp = tcp_sk(sk);
1407c106d7eSWong Hoi Sing Edison 	struct lp *lp = inet_csk_ca(sk);
1417c106d7eSWong Hoi Sing Edison 	s64 rhz = lp->remote_hz << 6;	/* remote HZ << 6 */
1427c106d7eSWong Hoi Sing Edison 	s64 m = 0;
1437c106d7eSWong Hoi Sing Edison 
1447c106d7eSWong Hoi Sing Edison 	/* not yet record reference time
1457c106d7eSWong Hoi Sing Edison 	 * go away!! record it before come back!! */
1467c106d7eSWong Hoi Sing Edison 	if (lp->remote_ref_time == 0 || lp->local_ref_time == 0)
1477c106d7eSWong Hoi Sing Edison 		goto out;
1487c106d7eSWong Hoi Sing Edison 
1497c106d7eSWong Hoi Sing Edison 	/* we can't calc remote HZ with no different!! */
1509d4fb27dSJoe Perches 	if (tp->rx_opt.rcv_tsval == lp->remote_ref_time ||
1519d4fb27dSJoe Perches 	    tp->rx_opt.rcv_tsecr == lp->local_ref_time)
1527c106d7eSWong Hoi Sing Edison 		goto out;
1537c106d7eSWong Hoi Sing Edison 
1549a568de4SEric Dumazet 	m = TCP_TS_HZ *
1559a568de4SEric Dumazet 	    (tp->rx_opt.rcv_tsval - lp->remote_ref_time) /
1569a568de4SEric Dumazet 	    (tp->rx_opt.rcv_tsecr - lp->local_ref_time);
1577c106d7eSWong Hoi Sing Edison 	if (m < 0)
1587c106d7eSWong Hoi Sing Edison 		m = -m;
1597c106d7eSWong Hoi Sing Edison 
1603795da47SWong Hoi Sing Edison 	if (rhz > 0) {
1617c106d7eSWong Hoi Sing Edison 		m -= rhz >> 6;	/* m is now error in remote HZ est */
1627c106d7eSWong Hoi Sing Edison 		rhz += m;	/* 63/64 old + 1/64 new */
1637c106d7eSWong Hoi Sing Edison 	} else
1647c106d7eSWong Hoi Sing Edison 		rhz = m << 6;
1657c106d7eSWong Hoi Sing Edison 
1667c106d7eSWong Hoi Sing Edison  out:
1673795da47SWong Hoi Sing Edison 	/* record time for successful remote HZ calc */
168bfbea8a8SWong Hoi Sing Edison 	if ((rhz >> 6) > 0)
1693795da47SWong Hoi Sing Edison 		lp->flag |= LP_VALID_RHZ;
1703795da47SWong Hoi Sing Edison 	else
1713795da47SWong Hoi Sing Edison 		lp->flag &= ~LP_VALID_RHZ;
1723795da47SWong Hoi Sing Edison 
1737c106d7eSWong Hoi Sing Edison 	/* record reference time stamp */
1747c106d7eSWong Hoi Sing Edison 	lp->remote_ref_time = tp->rx_opt.rcv_tsval;
1757c106d7eSWong Hoi Sing Edison 	lp->local_ref_time = tp->rx_opt.rcv_tsecr;
1767c106d7eSWong Hoi Sing Edison 
1777c106d7eSWong Hoi Sing Edison 	return rhz >> 6;
1787c106d7eSWong Hoi Sing Edison }
1797c106d7eSWong Hoi Sing Edison 
1807c106d7eSWong Hoi Sing Edison /**
1817c106d7eSWong Hoi Sing Edison  * tcp_lp_owd_calculator
182*726e5e49SAndrew Lunn  * @sk: socket to calculate one way delay for
1837c106d7eSWong Hoi Sing Edison  *
1847c106d7eSWong Hoi Sing Edison  * Calculate one way delay (in relative format).
1857c106d7eSWong Hoi Sing Edison  * Original implement OWD as minus of remote time difference to local time
1867c106d7eSWong Hoi Sing Edison  * difference directly. As this time difference just simply equal to RTT, when
1877c106d7eSWong Hoi Sing Edison  * the network status is stable, remote RTT will equal to local RTT, and result
1887c106d7eSWong Hoi Sing Edison  * OWD into zero.
1897c106d7eSWong Hoi Sing Edison  * It seems to be a bug and so we fixed it.
1907c106d7eSWong Hoi Sing Edison  */
1917c106d7eSWong Hoi Sing Edison static u32 tcp_lp_owd_calculator(struct sock *sk)
1927c106d7eSWong Hoi Sing Edison {
1937c106d7eSWong Hoi Sing Edison 	struct tcp_sock *tp = tcp_sk(sk);
1947c106d7eSWong Hoi Sing Edison 	struct lp *lp = inet_csk_ca(sk);
1957c106d7eSWong Hoi Sing Edison 	s64 owd = 0;
1967c106d7eSWong Hoi Sing Edison 
1977c106d7eSWong Hoi Sing Edison 	lp->remote_hz = tcp_lp_remote_hz_estimator(sk);
1987c106d7eSWong Hoi Sing Edison 
1997c106d7eSWong Hoi Sing Edison 	if (lp->flag & LP_VALID_RHZ) {
2007c106d7eSWong Hoi Sing Edison 		owd =
2017c106d7eSWong Hoi Sing Edison 		    tp->rx_opt.rcv_tsval * (LP_RESOL / lp->remote_hz) -
2029a568de4SEric Dumazet 		    tp->rx_opt.rcv_tsecr * (LP_RESOL / TCP_TS_HZ);
2037c106d7eSWong Hoi Sing Edison 		if (owd < 0)
2047c106d7eSWong Hoi Sing Edison 			owd = -owd;
2057c106d7eSWong Hoi Sing Edison 	}
2067c106d7eSWong Hoi Sing Edison 
2077c106d7eSWong Hoi Sing Edison 	if (owd > 0)
2087c106d7eSWong Hoi Sing Edison 		lp->flag |= LP_VALID_OWD;
2097c106d7eSWong Hoi Sing Edison 	else
2107c106d7eSWong Hoi Sing Edison 		lp->flag &= ~LP_VALID_OWD;
2117c106d7eSWong Hoi Sing Edison 
2127c106d7eSWong Hoi Sing Edison 	return owd;
2137c106d7eSWong Hoi Sing Edison }
2147c106d7eSWong Hoi Sing Edison 
2157c106d7eSWong Hoi Sing Edison /**
2167c106d7eSWong Hoi Sing Edison  * tcp_lp_rtt_sample
217*726e5e49SAndrew Lunn  * @sk: socket to add a rtt sample to
218*726e5e49SAndrew Lunn  * @rtt: round trip time, which is ignored!
2197c106d7eSWong Hoi Sing Edison  *
2207c106d7eSWong Hoi Sing Edison  * Implementation or rtt_sample.
2217c106d7eSWong Hoi Sing Edison  * Will take the following action,
2227c106d7eSWong Hoi Sing Edison  *   1. calc OWD,
2237c106d7eSWong Hoi Sing Edison  *   2. record the min/max OWD,
2247c106d7eSWong Hoi Sing Edison  *   3. calc smoothed OWD (SOWD).
2257c106d7eSWong Hoi Sing Edison  * Most ideas come from the original TCP-LP implementation.
2267c106d7eSWong Hoi Sing Edison  */
227164891aaSStephen Hemminger static void tcp_lp_rtt_sample(struct sock *sk, u32 rtt)
2287c106d7eSWong Hoi Sing Edison {
2297c106d7eSWong Hoi Sing Edison 	struct lp *lp = inet_csk_ca(sk);
2307c106d7eSWong Hoi Sing Edison 	s64 mowd = tcp_lp_owd_calculator(sk);
2317c106d7eSWong Hoi Sing Edison 
2327c106d7eSWong Hoi Sing Edison 	/* sorry that we don't have valid data */
2337c106d7eSWong Hoi Sing Edison 	if (!(lp->flag & LP_VALID_RHZ) || !(lp->flag & LP_VALID_OWD))
2347c106d7eSWong Hoi Sing Edison 		return;
2357c106d7eSWong Hoi Sing Edison 
2367c106d7eSWong Hoi Sing Edison 	/* record the next min owd */
2377c106d7eSWong Hoi Sing Edison 	if (mowd < lp->owd_min)
2387c106d7eSWong Hoi Sing Edison 		lp->owd_min = mowd;
2397c106d7eSWong Hoi Sing Edison 
2407c106d7eSWong Hoi Sing Edison 	/* always forget the max of the max
2417c106d7eSWong Hoi Sing Edison 	 * we just set owd_max as one below it */
2427c106d7eSWong Hoi Sing Edison 	if (mowd > lp->owd_max) {
2437c106d7eSWong Hoi Sing Edison 		if (mowd > lp->owd_max_rsv) {
2447c106d7eSWong Hoi Sing Edison 			if (lp->owd_max_rsv == 0)
2457c106d7eSWong Hoi Sing Edison 				lp->owd_max = mowd;
2467c106d7eSWong Hoi Sing Edison 			else
2477c106d7eSWong Hoi Sing Edison 				lp->owd_max = lp->owd_max_rsv;
2487c106d7eSWong Hoi Sing Edison 			lp->owd_max_rsv = mowd;
2497c106d7eSWong Hoi Sing Edison 		} else
2507c106d7eSWong Hoi Sing Edison 			lp->owd_max = mowd;
2517c106d7eSWong Hoi Sing Edison 	}
2527c106d7eSWong Hoi Sing Edison 
2537c106d7eSWong Hoi Sing Edison 	/* calc for smoothed owd */
2547c106d7eSWong Hoi Sing Edison 	if (lp->sowd != 0) {
2557c106d7eSWong Hoi Sing Edison 		mowd -= lp->sowd >> 3;	/* m is now error in owd est */
2567c106d7eSWong Hoi Sing Edison 		lp->sowd += mowd;	/* owd = 7/8 owd + 1/8 new */
2577c106d7eSWong Hoi Sing Edison 	} else
2587c106d7eSWong Hoi Sing Edison 		lp->sowd = mowd << 3;	/* take the measured time be owd */
2597c106d7eSWong Hoi Sing Edison }
2607c106d7eSWong Hoi Sing Edison 
2617c106d7eSWong Hoi Sing Edison /**
2627c106d7eSWong Hoi Sing Edison  * tcp_lp_pkts_acked
263*726e5e49SAndrew Lunn  * @sk: socket requiring congestion avoidance calculations
2647c106d7eSWong Hoi Sing Edison  *
2657c106d7eSWong Hoi Sing Edison  * Implementation of pkts_acked.
2667c106d7eSWong Hoi Sing Edison  * Deal with active drop under Early Congestion Indication.
2677c106d7eSWong Hoi Sing Edison  * Only drop to half and 1 will be handle, because we hope to use back
2687c106d7eSWong Hoi Sing Edison  * newReno in increase case.
2697c106d7eSWong Hoi Sing Edison  * We work it out by following the idea from TCP-LP's paper directly
2707c106d7eSWong Hoi Sing Edison  */
271756ee172SLawrence Brakmo static void tcp_lp_pkts_acked(struct sock *sk, const struct ack_sample *sample)
2727c106d7eSWong Hoi Sing Edison {
2737c106d7eSWong Hoi Sing Edison 	struct tcp_sock *tp = tcp_sk(sk);
2747c106d7eSWong Hoi Sing Edison 	struct lp *lp = inet_csk_ca(sk);
2759a568de4SEric Dumazet 	u32 now = tcp_time_stamp(tp);
276a9f11f96SEric Dumazet 	u32 delta;
2777c106d7eSWong Hoi Sing Edison 
278756ee172SLawrence Brakmo 	if (sample->rtt_us > 0)
279756ee172SLawrence Brakmo 		tcp_lp_rtt_sample(sk, sample->rtt_us);
280164891aaSStephen Hemminger 
2817c106d7eSWong Hoi Sing Edison 	/* calc inference */
28246bf466fSEric Dumazet 	delta = now - tp->rx_opt.rcv_tsecr;
283a9f11f96SEric Dumazet 	if ((s32)delta > 0)
284a9f11f96SEric Dumazet 		lp->inference = 3 * delta;
2857c106d7eSWong Hoi Sing Edison 
2867c106d7eSWong Hoi Sing Edison 	/* test if within inference */
28746bf466fSEric Dumazet 	if (lp->last_drop && (now - lp->last_drop < lp->inference))
2887c106d7eSWong Hoi Sing Edison 		lp->flag |= LP_WITHIN_INF;
2897c106d7eSWong Hoi Sing Edison 	else
2907c106d7eSWong Hoi Sing Edison 		lp->flag &= ~LP_WITHIN_INF;
2917c106d7eSWong Hoi Sing Edison 
2927c106d7eSWong Hoi Sing Edison 	/* test if within threshold */
2937c106d7eSWong Hoi Sing Edison 	if (lp->sowd >> 3 <
2947c106d7eSWong Hoi Sing Edison 	    lp->owd_min + 15 * (lp->owd_max - lp->owd_min) / 100)
2957c106d7eSWong Hoi Sing Edison 		lp->flag |= LP_WITHIN_THR;
2967c106d7eSWong Hoi Sing Edison 	else
2977c106d7eSWong Hoi Sing Edison 		lp->flag &= ~LP_WITHIN_THR;
2987c106d7eSWong Hoi Sing Edison 
2997c106d7eSWong Hoi Sing Edison 	pr_debug("TCP-LP: %05o|%5u|%5u|%15u|%15u|%15u\n", lp->flag,
3007c106d7eSWong Hoi Sing Edison 		 tp->snd_cwnd, lp->remote_hz, lp->owd_min, lp->owd_max,
3017c106d7eSWong Hoi Sing Edison 		 lp->sowd >> 3);
3027c106d7eSWong Hoi Sing Edison 
3037c106d7eSWong Hoi Sing Edison 	if (lp->flag & LP_WITHIN_THR)
3047c106d7eSWong Hoi Sing Edison 		return;
3057c106d7eSWong Hoi Sing Edison 
3067c106d7eSWong Hoi Sing Edison 	/* FIXME: try to reset owd_min and owd_max here
3077c106d7eSWong Hoi Sing Edison 	 * so decrease the chance the min/max is no longer suitable
3087c106d7eSWong Hoi Sing Edison 	 * and will usually within threshold when whithin inference */
3097c106d7eSWong Hoi Sing Edison 	lp->owd_min = lp->sowd >> 3;
3107c106d7eSWong Hoi Sing Edison 	lp->owd_max = lp->sowd >> 2;
3117c106d7eSWong Hoi Sing Edison 	lp->owd_max_rsv = lp->sowd >> 2;
3127c106d7eSWong Hoi Sing Edison 
3137c106d7eSWong Hoi Sing Edison 	/* happened within inference
3147c106d7eSWong Hoi Sing Edison 	 * drop snd_cwnd into 1 */
3157c106d7eSWong Hoi Sing Edison 	if (lp->flag & LP_WITHIN_INF)
3167c106d7eSWong Hoi Sing Edison 		tp->snd_cwnd = 1U;
3177c106d7eSWong Hoi Sing Edison 
3187c106d7eSWong Hoi Sing Edison 	/* happened after inference
3197c106d7eSWong Hoi Sing Edison 	 * cut snd_cwnd into half */
3207c106d7eSWong Hoi Sing Edison 	else
3217c106d7eSWong Hoi Sing Edison 		tp->snd_cwnd = max(tp->snd_cwnd >> 1U, 1U);
3227c106d7eSWong Hoi Sing Edison 
3237c106d7eSWong Hoi Sing Edison 	/* record this drop time */
32446bf466fSEric Dumazet 	lp->last_drop = now;
3257c106d7eSWong Hoi Sing Edison }
3267c106d7eSWong Hoi Sing Edison 
327a252bebeSStephen Hemminger static struct tcp_congestion_ops tcp_lp __read_mostly = {
3287c106d7eSWong Hoi Sing Edison 	.init = tcp_lp_init,
3297c106d7eSWong Hoi Sing Edison 	.ssthresh = tcp_reno_ssthresh,
330e9799183SFlorian Westphal 	.undo_cwnd = tcp_reno_undo_cwnd,
3317c106d7eSWong Hoi Sing Edison 	.cong_avoid = tcp_lp_cong_avoid,
3327c106d7eSWong Hoi Sing Edison 	.pkts_acked = tcp_lp_pkts_acked,
3337c106d7eSWong Hoi Sing Edison 
3347c106d7eSWong Hoi Sing Edison 	.owner = THIS_MODULE,
3357c106d7eSWong Hoi Sing Edison 	.name = "lp"
3367c106d7eSWong Hoi Sing Edison };
3377c106d7eSWong Hoi Sing Edison 
3387c106d7eSWong Hoi Sing Edison static int __init tcp_lp_register(void)
3397c106d7eSWong Hoi Sing Edison {
34029896972SAlexey Dobriyan 	BUILD_BUG_ON(sizeof(struct lp) > ICSK_CA_PRIV_SIZE);
3417c106d7eSWong Hoi Sing Edison 	return tcp_register_congestion_control(&tcp_lp);
3427c106d7eSWong Hoi Sing Edison }
3437c106d7eSWong Hoi Sing Edison 
3447c106d7eSWong Hoi Sing Edison static void __exit tcp_lp_unregister(void)
3457c106d7eSWong Hoi Sing Edison {
3467c106d7eSWong Hoi Sing Edison 	tcp_unregister_congestion_control(&tcp_lp);
3477c106d7eSWong Hoi Sing Edison }
3487c106d7eSWong Hoi Sing Edison 
3497c106d7eSWong Hoi Sing Edison module_init(tcp_lp_register);
3507c106d7eSWong Hoi Sing Edison module_exit(tcp_lp_unregister);
3517c106d7eSWong Hoi Sing Edison 
3523795da47SWong Hoi Sing Edison MODULE_AUTHOR("Wong Hoi Sing Edison, Hung Hing Lun Mike");
3537c106d7eSWong Hoi Sing Edison MODULE_LICENSE("GPL");
3547c106d7eSWong Hoi Sing Edison MODULE_DESCRIPTION("TCP Low Priority");
355