@@ -37,13 +37,87 @@ struct rxrpc_send_params {
3737 bool upgrade ; /* If the connection is upgradeable */
3838};
3939
40+ /*
41+ * Wait for space to appear in the Tx queue or a signal to occur.
42+ */
43+ static int rxrpc_wait_for_tx_window_intr (struct rxrpc_sock * rx ,
44+ struct rxrpc_call * call ,
45+ long * timeo )
46+ {
47+ for (;;) {
48+ set_current_state (TASK_INTERRUPTIBLE );
49+ if (call -> tx_top - call -> tx_hard_ack <
50+ min_t (unsigned int , call -> tx_winsize ,
51+ call -> cong_cwnd + call -> cong_extra ))
52+ return 0 ;
53+
54+ if (call -> state >= RXRPC_CALL_COMPLETE )
55+ return call -> error ;
56+
57+ if (signal_pending (current ))
58+ return sock_intr_errno (* timeo );
59+
60+ trace_rxrpc_transmit (call , rxrpc_transmit_wait );
61+ mutex_unlock (& call -> user_mutex );
62+ * timeo = schedule_timeout (* timeo );
63+ if (mutex_lock_interruptible (& call -> user_mutex ) < 0 )
64+ return sock_intr_errno (* timeo );
65+ }
66+ }
67+
68+ /*
69+ * Wait for space to appear in the Tx queue uninterruptibly, but with
70+ * a timeout of 2*RTT if no progress was made and a signal occurred.
71+ */
72+ static int rxrpc_wait_for_tx_window_nonintr (struct rxrpc_sock * rx ,
73+ struct rxrpc_call * call )
74+ {
75+ rxrpc_seq_t tx_start , tx_win ;
76+ signed long rtt2 , timeout ;
77+ u64 rtt ;
78+
79+ rtt = READ_ONCE (call -> peer -> rtt );
80+ rtt2 = nsecs_to_jiffies64 (rtt ) * 2 ;
81+ if (rtt2 < 1 )
82+ rtt2 = 1 ;
83+
84+ timeout = rtt2 ;
85+ tx_start = READ_ONCE (call -> tx_hard_ack );
86+
87+ for (;;) {
88+ set_current_state (TASK_UNINTERRUPTIBLE );
89+
90+ tx_win = READ_ONCE (call -> tx_hard_ack );
91+ if (call -> tx_top - tx_win <
92+ min_t (unsigned int , call -> tx_winsize ,
93+ call -> cong_cwnd + call -> cong_extra ))
94+ return 0 ;
95+
96+ if (call -> state >= RXRPC_CALL_COMPLETE )
97+ return call -> error ;
98+
99+ if (timeout == 0 &&
100+ tx_win == tx_start && signal_pending (current ))
101+ return - EINTR ;
102+
103+ if (tx_win != tx_start ) {
104+ timeout = rtt2 ;
105+ tx_start = tx_win ;
106+ }
107+
108+ trace_rxrpc_transmit (call , rxrpc_transmit_wait );
109+ timeout = schedule_timeout (timeout );
110+ }
111+ }
112+
40113/*
41114 * wait for space to appear in the transmit/ACK window
42115 * - caller holds the socket locked
43116 */
44117static int rxrpc_wait_for_tx_window (struct rxrpc_sock * rx ,
45118 struct rxrpc_call * call ,
46- long * timeo )
119+ long * timeo ,
120+ bool waitall )
47121{
48122 DECLARE_WAITQUEUE (myself , current );
49123 int ret ;
@@ -53,30 +127,10 @@ static int rxrpc_wait_for_tx_window(struct rxrpc_sock *rx,
53127
54128 add_wait_queue (& call -> waitq , & myself );
55129
56- for (;;) {
57- set_current_state (TASK_INTERRUPTIBLE );
58- ret = 0 ;
59- if (call -> tx_top - call -> tx_hard_ack <
60- min_t (unsigned int , call -> tx_winsize ,
61- call -> cong_cwnd + call -> cong_extra ))
62- break ;
63- if (call -> state >= RXRPC_CALL_COMPLETE ) {
64- ret = call -> error ;
65- break ;
66- }
67- if (signal_pending (current )) {
68- ret = sock_intr_errno (* timeo );
69- break ;
70- }
71-
72- trace_rxrpc_transmit (call , rxrpc_transmit_wait );
73- mutex_unlock (& call -> user_mutex );
74- * timeo = schedule_timeout (* timeo );
75- if (mutex_lock_interruptible (& call -> user_mutex ) < 0 ) {
76- ret = sock_intr_errno (* timeo );
77- break ;
78- }
79- }
130+ if (waitall )
131+ ret = rxrpc_wait_for_tx_window_nonintr (rx , call );
132+ else
133+ ret = rxrpc_wait_for_tx_window_intr (rx , call , timeo );
80134
81135 remove_wait_queue (& call -> waitq , & myself );
82136 set_current_state (TASK_RUNNING );
@@ -254,7 +308,8 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
254308 if (msg -> msg_flags & MSG_DONTWAIT )
255309 goto maybe_error ;
256310 ret = rxrpc_wait_for_tx_window (rx , call ,
257- & timeo );
311+ & timeo ,
312+ msg -> msg_flags & MSG_WAITALL );
258313 if (ret < 0 )
259314 goto maybe_error ;
260315 }
0 commit comments