Skip to content

Commit 31954cd

Browse files
tracywwnjdavem330
authored andcommitted
tcp: Refactor pingpong code
Instead of using pingpong as a single bit information, we refactor the code to treat it as a counter. When interactive session is detected, we set pingpong count to TCP_PINGPONG_THRESH. And when pingpong count is >= TCP_PINGPONG_THRESH, we consider the session in pingpong mode. This patch is a pure refactor and sets foundation for the next patch. This patch itself does not change any pingpong logic. Signed-off-by: Wei Wang <weiwan@google.com> Signed-off-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fb1b699 commit 31954cd

File tree

9 files changed

+35
-18
lines changed

9 files changed

+35
-18
lines changed

include/net/inet_connection_sock.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,21 @@ int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
314314
char __user *optval, unsigned int optlen);
315315

316316
struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu);
317+
318+
#define TCP_PINGPONG_THRESH 1
319+
320+
static inline void inet_csk_enter_pingpong_mode(struct sock *sk)
321+
{
322+
inet_csk(sk)->icsk_ack.pingpong = TCP_PINGPONG_THRESH;
323+
}
324+
325+
static inline void inet_csk_exit_pingpong_mode(struct sock *sk)
326+
{
327+
inet_csk(sk)->icsk_ack.pingpong = 0;
328+
}
329+
330+
static inline bool inet_csk_in_pingpong_mode(struct sock *sk)
331+
{
332+
return inet_csk(sk)->icsk_ack.pingpong >= TCP_PINGPONG_THRESH;
333+
}
317334
#endif /* _INET_CONNECTION_SOCK_H */

net/dccp/input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
480480
sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT);
481481
}
482482

483-
if (sk->sk_write_pending || icsk->icsk_ack.pingpong ||
483+
if (sk->sk_write_pending || inet_csk_in_pingpong_mode(sk) ||
484484
icsk->icsk_accept_queue.rskq_defer_accept) {
485485
/* Save one ACK. Data will be ready after
486486
* several ticks, if write_pending is set.

net/dccp/timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ static void dccp_delack_timer(struct timer_list *t)
199199
icsk->icsk_ack.pending &= ~ICSK_ACK_TIMER;
200200

201201
if (inet_csk_ack_scheduled(sk)) {
202-
if (!icsk->icsk_ack.pingpong) {
202+
if (!inet_csk_in_pingpong_mode(sk)) {
203203
/* Delayed ACK missed: inflate ATO. */
204204
icsk->icsk_ack.ato = min(icsk->icsk_ack.ato << 1,
205205
icsk->icsk_rto);
206206
} else {
207207
/* Delayed ACK missed: leave pingpong mode and
208208
* deflate ATO.
209209
*/
210-
icsk->icsk_ack.pingpong = 0;
210+
inet_csk_exit_pingpong_mode(sk);
211211
icsk->icsk_ack.ato = TCP_ATO_MIN;
212212
}
213213
dccp_send_ack(sk);

net/ipv4/tcp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ static void tcp_cleanup_rbuf(struct sock *sk, int copied)
15511551
(copied > 0 &&
15521552
((icsk->icsk_ack.pending & ICSK_ACK_PUSHED2) ||
15531553
((icsk->icsk_ack.pending & ICSK_ACK_PUSHED) &&
1554-
!icsk->icsk_ack.pingpong)) &&
1554+
!inet_csk_in_pingpong_mode(sk))) &&
15551555
!atomic_read(&sk->sk_rmem_alloc)))
15561556
time_to_ack = true;
15571557
}
@@ -2984,16 +2984,16 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
29842984

29852985
case TCP_QUICKACK:
29862986
if (!val) {
2987-
icsk->icsk_ack.pingpong = 1;
2987+
inet_csk_enter_pingpong_mode(sk);
29882988
} else {
2989-
icsk->icsk_ack.pingpong = 0;
2989+
inet_csk_exit_pingpong_mode(sk);
29902990
if ((1 << sk->sk_state) &
29912991
(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT) &&
29922992
inet_csk_ack_scheduled(sk)) {
29932993
icsk->icsk_ack.pending |= ICSK_ACK_PUSHED;
29942994
tcp_cleanup_rbuf(sk, 1);
29952995
if (!(val & 1))
2996-
icsk->icsk_ack.pingpong = 1;
2996+
inet_csk_enter_pingpong_mode(sk);
29972997
}
29982998
}
29992999
break;
@@ -3407,7 +3407,7 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
34073407
return 0;
34083408
}
34093409
case TCP_QUICKACK:
3410-
val = !icsk->icsk_ack.pingpong;
3410+
val = !inet_csk_in_pingpong_mode(sk);
34113411
break;
34123412

34133413
case TCP_CONGESTION:

net/ipv4/tcp_input.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void tcp_enter_quickack_mode(struct sock *sk, unsigned int max_quickacks)
221221
struct inet_connection_sock *icsk = inet_csk(sk);
222222

223223
tcp_incr_quickack(sk, max_quickacks);
224-
icsk->icsk_ack.pingpong = 0;
224+
inet_csk_exit_pingpong_mode(sk);
225225
icsk->icsk_ack.ato = TCP_ATO_MIN;
226226
}
227227
EXPORT_SYMBOL(tcp_enter_quickack_mode);
@@ -236,7 +236,7 @@ static bool tcp_in_quickack_mode(struct sock *sk)
236236
const struct dst_entry *dst = __sk_dst_get(sk);
237237

238238
return (dst && dst_metric(dst, RTAX_QUICKACK)) ||
239-
(icsk->icsk_ack.quick && !icsk->icsk_ack.pingpong);
239+
(icsk->icsk_ack.quick && !inet_csk_in_pingpong_mode(sk));
240240
}
241241

242242
static void tcp_ecn_queue_cwr(struct tcp_sock *tp)
@@ -4094,7 +4094,7 @@ void tcp_fin(struct sock *sk)
40944094
case TCP_ESTABLISHED:
40954095
/* Move to CLOSE_WAIT */
40964096
tcp_set_state(sk, TCP_CLOSE_WAIT);
4097-
inet_csk(sk)->icsk_ack.pingpong = 1;
4097+
inet_csk_enter_pingpong_mode(sk);
40984098
break;
40994099

41004100
case TCP_CLOSE_WAIT:
@@ -5889,7 +5889,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
58895889
return -1;
58905890
if (sk->sk_write_pending ||
58915891
icsk->icsk_accept_queue.rskq_defer_accept ||
5892-
icsk->icsk_ack.pingpong) {
5892+
inet_csk_in_pingpong_mode(sk)) {
58935893
/* Save one ACK. Data will be ready after
58945894
* several ticks, if write_pending is set.
58955895
*

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
24372437
refcount_read(&sk->sk_refcnt), sk,
24382438
jiffies_to_clock_t(icsk->icsk_rto),
24392439
jiffies_to_clock_t(icsk->icsk_ack.ato),
2440-
(icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
2440+
(icsk->icsk_ack.quick << 1) | inet_csk_in_pingpong_mode(sk),
24412441
tp->snd_cwnd,
24422442
state == TCP_LISTEN ?
24432443
fastopenq->max_qlen :

net/ipv4/tcp_output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void tcp_event_data_sent(struct tcp_sock *tp,
171171
* packet, enter pingpong mode.
172172
*/
173173
if ((u32)(now - icsk->icsk_ack.lrcvtime) < icsk->icsk_ack.ato)
174-
icsk->icsk_ack.pingpong = 1;
174+
inet_csk_enter_pingpong_mode(sk);
175175
}
176176

177177
/* Account for an ACK we sent. */
@@ -3569,7 +3569,7 @@ void tcp_send_delayed_ack(struct sock *sk)
35693569
const struct tcp_sock *tp = tcp_sk(sk);
35703570
int max_ato = HZ / 2;
35713571

3572-
if (icsk->icsk_ack.pingpong ||
3572+
if (inet_csk_in_pingpong_mode(sk) ||
35733573
(icsk->icsk_ack.pending & ICSK_ACK_PUSHED))
35743574
max_ato = TCP_DELACK_MAX;
35753575

net/ipv4/tcp_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,14 @@ void tcp_delack_timer_handler(struct sock *sk)
277277
icsk->icsk_ack.pending &= ~ICSK_ACK_TIMER;
278278

279279
if (inet_csk_ack_scheduled(sk)) {
280-
if (!icsk->icsk_ack.pingpong) {
280+
if (!inet_csk_in_pingpong_mode(sk)) {
281281
/* Delayed ACK missed: inflate ATO. */
282282
icsk->icsk_ack.ato = min(icsk->icsk_ack.ato << 1, icsk->icsk_rto);
283283
} else {
284284
/* Delayed ACK missed: leave pingpong mode and
285285
* deflate ATO.
286286
*/
287-
icsk->icsk_ack.pingpong = 0;
287+
inet_csk_exit_pingpong_mode(sk);
288288
icsk->icsk_ack.ato = TCP_ATO_MIN;
289289
}
290290
tcp_mstamp_refresh(tcp_sk(sk));

net/ipv6/tcp_ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
18641864
refcount_read(&sp->sk_refcnt), sp,
18651865
jiffies_to_clock_t(icsk->icsk_rto),
18661866
jiffies_to_clock_t(icsk->icsk_ack.ato),
1867-
(icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
1867+
(icsk->icsk_ack.quick << 1) | inet_csk_in_pingpong_mode(sp),
18681868
tp->snd_cwnd,
18691869
state == TCP_LISTEN ?
18701870
fastopenq->max_qlen :

0 commit comments

Comments
 (0)