Skip to content

Commit 5749434

Browse files
committed
rxrpc: Implement slow-start
Implement RxRPC slow-start, which is similar to RFC 5681 for TCP. A tracepoint is added to log the state of the congestion management algorithm and the decisions it makes. Notes: (1) Since we send fixed-size DATA packets (apart from the final packet in each phase), counters and calculations are in terms of packets rather than bytes. (2) The ACK packet carries the equivalent of TCP SACK. (3) The FLIGHT_SIZE calculation in RFC 5681 doesn't seem particularly suited to SACK of a small number of packets. It seems that, almost inevitably, by the time three 'duplicate' ACKs have been seen, we have narrowed the loss down to one or two missing packets, and the FLIGHT_SIZE calculation ends up as 2. (4) In rxrpc_resend(), if there was no data that apparently needed retransmission, we transmit a PING ACK to ask the peer to tell us what its Rx window state is. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 0d96796 commit 5749434

9 files changed

Lines changed: 339 additions & 13 deletions

File tree

‎include/trace/events/rxrpc.h‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,51 @@ TRACE_EVENT(rxrpc_retransmit,
570570
__entry->expiry)
571571
);
572572

573+
TRACE_EVENT(rxrpc_congest,
574+
TP_PROTO(struct rxrpc_call *call, struct rxrpc_ack_summary *summary,
575+
rxrpc_serial_t ack_serial, enum rxrpc_congest_change change),
576+
577+
TP_ARGS(call, summary, ack_serial, change),
578+
579+
TP_STRUCT__entry(
580+
__field(struct rxrpc_call *, call )
581+
__field(enum rxrpc_congest_change, change )
582+
__field(rxrpc_seq_t, hard_ack )
583+
__field(rxrpc_seq_t, top )
584+
__field(rxrpc_seq_t, lowest_nak )
585+
__field(rxrpc_serial_t, ack_serial )
586+
__field_struct(struct rxrpc_ack_summary, sum )
587+
),
588+
589+
TP_fast_assign(
590+
__entry->call = call;
591+
__entry->change = change;
592+
__entry->hard_ack = call->tx_hard_ack;
593+
__entry->top = call->tx_top;
594+
__entry->lowest_nak = call->acks_lowest_nak;
595+
__entry->ack_serial = ack_serial;
596+
memcpy(&__entry->sum, summary, sizeof(__entry->sum));
597+
),
598+
599+
TP_printk("c=%p %08x %s %08x %s cw=%u ss=%u nr=%u,%u nw=%u,%u r=%u b=%u u=%u d=%u l=%x%s%s%s",
600+
__entry->call,
601+
__entry->ack_serial,
602+
rxrpc_ack_names[__entry->sum.ack_reason],
603+
__entry->hard_ack,
604+
rxrpc_congest_modes[__entry->sum.mode],
605+
__entry->sum.cwnd,
606+
__entry->sum.ssthresh,
607+
__entry->sum.nr_acks, __entry->sum.nr_nacks,
608+
__entry->sum.nr_new_acks, __entry->sum.nr_new_nacks,
609+
__entry->sum.nr_rot_new_acks,
610+
__entry->top - __entry->hard_ack,
611+
__entry->sum.cumulative_acks,
612+
__entry->sum.dup_acks,
613+
__entry->lowest_nak, __entry->sum.new_low_nack ? "!" : "",
614+
rxrpc_congest_changes[__entry->change],
615+
__entry->sum.retrans_timeo ? " rTxTo" : "")
616+
);
617+
573618
#endif /* _TRACE_RXRPC_H */
574619

575620
/* This part must be outside protection */

‎net/rxrpc/ar-internal.h‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ enum rxrpc_call_flag {
402402
RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */
403403
RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */
404404
RXRPC_CALL_PINGING, /* Ping in process */
405+
RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */
405406
};
406407

407408
/*
@@ -446,6 +447,17 @@ enum rxrpc_call_completion {
446447
NR__RXRPC_CALL_COMPLETIONS
447448
};
448449

450+
/*
451+
* Call Tx congestion management modes.
452+
*/
453+
enum rxrpc_congest_mode {
454+
RXRPC_CALL_SLOW_START,
455+
RXRPC_CALL_CONGEST_AVOIDANCE,
456+
RXRPC_CALL_PACKET_LOSS,
457+
RXRPC_CALL_FAST_RETRANSMIT,
458+
NR__RXRPC_CONGEST_MODES
459+
};
460+
449461
/*
450462
* RxRPC call definition
451463
* - matched by { connection, call_id }
@@ -518,6 +530,20 @@ struct rxrpc_call {
518530
* not hard-ACK'd packet follows this.
519531
*/
520532
rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */
533+
534+
/* TCP-style slow-start congestion control [RFC5681]. Since the SMSS
535+
* is fixed, we keep these numbers in terms of segments (ie. DATA
536+
* packets) rather than bytes.
537+
*/
538+
#define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN
539+
u8 cong_cwnd; /* Congestion window size */
540+
u8 cong_extra; /* Extra to send for congestion management */
541+
u8 cong_ssthresh; /* Slow-start threshold */
542+
enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */
543+
u8 cong_dup_acks; /* Count of ACKs showing missing packets */
544+
u8 cong_cumul_acks; /* Cumulative ACK count */
545+
ktime_t cong_tstamp; /* Last time cwnd was changed */
546+
521547
rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not
522548
* consumed packet follows this.
523549
*/
@@ -539,12 +565,13 @@ struct rxrpc_call {
539565
ktime_t ackr_ping_time; /* Time last ping sent */
540566

541567
/* transmission-phase ACK management */
568+
ktime_t acks_latest_ts; /* Timestamp of latest ACK received */
542569
rxrpc_serial_t acks_latest; /* serial number of latest ACK received */
543570
rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
544571
};
545572

546573
/*
547-
* Summary of a new ACK and the changes it made.
574+
* Summary of a new ACK and the changes it made to the Tx buffer packet states.
548575
*/
549576
struct rxrpc_ack_summary {
550577
u8 ack_reason;
@@ -554,6 +581,14 @@ struct rxrpc_ack_summary {
554581
u8 nr_new_nacks; /* Number of new NACKs in packet */
555582
u8 nr_rot_new_acks; /* Number of rotated new ACKs */
556583
bool new_low_nack; /* T if new low NACK found */
584+
bool retrans_timeo; /* T if reTx due to timeout happened */
585+
u8 flight_size; /* Number of unreceived transmissions */
586+
/* Place to stash values for tracing */
587+
enum rxrpc_congest_mode mode:8;
588+
u8 cwnd;
589+
u8 ssthresh;
590+
u8 dup_acks;
591+
u8 cumulative_acks;
557592
};
558593

559594
enum rxrpc_skb_trace {
@@ -709,6 +744,7 @@ extern const char rxrpc_timer_traces[rxrpc_timer__nr_trace][8];
709744
enum rxrpc_propose_ack_trace {
710745
rxrpc_propose_ack_client_tx_end,
711746
rxrpc_propose_ack_input_data,
747+
rxrpc_propose_ack_ping_for_lost_ack,
712748
rxrpc_propose_ack_ping_for_lost_reply,
713749
rxrpc_propose_ack_ping_for_params,
714750
rxrpc_propose_ack_respond_to_ack,
@@ -729,6 +765,21 @@ enum rxrpc_propose_ack_outcome {
729765
extern const char rxrpc_propose_ack_traces[rxrpc_propose_ack__nr_trace][8];
730766
extern const char *const rxrpc_propose_ack_outcomes[rxrpc_propose_ack__nr_outcomes];
731767

768+
enum rxrpc_congest_change {
769+
rxrpc_cong_begin_retransmission,
770+
rxrpc_cong_cleared_nacks,
771+
rxrpc_cong_new_low_nack,
772+
rxrpc_cong_no_change,
773+
rxrpc_cong_progress,
774+
rxrpc_cong_retransmit_again,
775+
rxrpc_cong_rtt_window_end,
776+
rxrpc_cong_saw_nack,
777+
rxrpc_congest__nr_change
778+
};
779+
780+
extern const char rxrpc_congest_modes[NR__RXRPC_CONGEST_MODES][10];
781+
extern const char rxrpc_congest_changes[rxrpc_congest__nr_change][9];
782+
732783
extern const char *const rxrpc_pkts[];
733784
extern const char const rxrpc_ack_names[RXRPC_ACK__INVALID + 1][4];
734785

‎net/rxrpc/call_event.c‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ void rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
146146
spin_unlock_bh(&call->lock);
147147
}
148148

149+
/*
150+
* Handle congestion being detected by the retransmit timeout.
151+
*/
152+
static void rxrpc_congestion_timeout(struct rxrpc_call *call)
153+
{
154+
set_bit(RXRPC_CALL_RETRANS_TIMEOUT, &call->flags);
155+
}
156+
149157
/*
150158
* Perform retransmission of NAK'd and unack'd packets.
151159
*/
@@ -154,9 +162,9 @@ static void rxrpc_resend(struct rxrpc_call *call)
154162
struct rxrpc_skb_priv *sp;
155163
struct sk_buff *skb;
156164
rxrpc_seq_t cursor, seq, top;
157-
ktime_t now = ktime_get_real(), max_age, oldest, resend_at;
165+
ktime_t now = ktime_get_real(), max_age, oldest, resend_at, ack_ts;
158166
int ix;
159-
u8 annotation, anno_type;
167+
u8 annotation, anno_type, retrans = 0, unacked = 0;
160168

161169
_enter("{%d,%d}", call->tx_hard_ack, call->tx_top);
162170

@@ -193,10 +201,13 @@ static void rxrpc_resend(struct rxrpc_call *call)
193201
oldest = skb->tstamp;
194202
continue;
195203
}
204+
if (!(annotation & RXRPC_TX_ANNO_RESENT))
205+
unacked++;
196206
}
197207

198208
/* Okay, we need to retransmit a packet. */
199209
call->rxtx_annotations[ix] = RXRPC_TX_ANNO_RETRANS | annotation;
210+
retrans++;
200211
trace_rxrpc_retransmit(call, seq, annotation | anno_type,
201212
ktime_to_ns(ktime_sub(skb->tstamp, max_age)));
202213
}
@@ -210,6 +221,25 @@ static void rxrpc_resend(struct rxrpc_call *call)
210221
* reached the nsec timeout yet.
211222
*/
212223

224+
if (unacked)
225+
rxrpc_congestion_timeout(call);
226+
227+
/* If there was nothing that needed retransmission then it's likely
228+
* that an ACK got lost somewhere. Send a ping to find out instead of
229+
* retransmitting data.
230+
*/
231+
if (!retrans) {
232+
rxrpc_set_timer(call, rxrpc_timer_set_for_resend);
233+
spin_unlock_bh(&call->lock);
234+
ack_ts = ktime_sub(now, call->acks_latest_ts);
235+
if (ktime_to_ns(ack_ts) < call->peer->rtt)
236+
goto out;
237+
rxrpc_propose_ACK(call, RXRPC_ACK_PING, 0, 0, true, false,
238+
rxrpc_propose_ack_ping_for_lost_ack);
239+
rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ACK);
240+
goto out;
241+
}
242+
213243
/* Now go through the Tx window and perform the retransmissions. We
214244
* have to drop the lock for each send. If an ACK comes in whilst the
215245
* lock is dropped, it may clear some of the retransmission markers for
@@ -260,6 +290,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
260290

261291
out_unlock:
262292
spin_unlock_bh(&call->lock);
293+
out:
263294
_leave("");
264295
}
265296

@@ -293,6 +324,7 @@ void rxrpc_process_call(struct work_struct *work)
293324
if (time_after_eq(now, call->expire_at)) {
294325
rxrpc_abort_call("EXP", call, 0, RX_CALL_TIMEOUT, ETIME);
295326
set_bit(RXRPC_CALL_EV_ABORT, &call->events);
327+
goto recheck_state;
296328
}
297329

298330
if (test_and_clear_bit(RXRPC_CALL_EV_ACK, &call->events) ||

‎net/rxrpc/call_object.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
160160
call->rx_winsize = rxrpc_rx_window_size;
161161
call->tx_winsize = 16;
162162
call->rx_expect_next = 1;
163+
164+
if (RXRPC_TX_SMSS > 2190)
165+
call->cong_cwnd = 2;
166+
else if (RXRPC_TX_SMSS > 1095)
167+
call->cong_cwnd = 3;
168+
else
169+
call->cong_cwnd = 4;
170+
call->cong_ssthresh = RXRPC_RXTX_BUFF_SIZE - 1;
163171
return call;
164172

165173
nomem_2:
@@ -176,6 +184,7 @@ static struct rxrpc_call *rxrpc_alloc_client_call(struct sockaddr_rxrpc *srx,
176184
gfp_t gfp)
177185
{
178186
struct rxrpc_call *call;
187+
ktime_t now;
179188

180189
_enter("");
181190

@@ -185,6 +194,9 @@ static struct rxrpc_call *rxrpc_alloc_client_call(struct sockaddr_rxrpc *srx,
185194
call->state = RXRPC_CALL_CLIENT_AWAIT_CONN;
186195
call->service_id = srx->srx_service;
187196
call->tx_phase = true;
197+
now = ktime_get_real();
198+
call->acks_latest_ts = now;
199+
call->cong_tstamp = now;
188200

189201
_leave(" = %p", call);
190202
return call;
@@ -325,6 +337,7 @@ void rxrpc_incoming_call(struct rxrpc_sock *rx,
325337
call->state = RXRPC_CALL_SERVER_ACCEPTING;
326338
if (sp->hdr.securityIndex > 0)
327339
call->state = RXRPC_CALL_SERVER_SECURING;
340+
call->cong_tstamp = skb->tstamp;
328341

329342
/* Set the channel for this call. We don't get channel_lock as we're
330343
* only defending against the data_ready handler (which we're called

‎net/rxrpc/conn_event.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn,
9797
pkt.info.maxMTU = htonl(mtu);
9898
pkt.info.rwind = htonl(rxrpc_rx_window_size);
9999
pkt.info.jumbo_max = htonl(rxrpc_rx_jumbo_max);
100+
pkt.whdr.flags |= RXRPC_SLOW_START_OK;
100101
len += sizeof(pkt.ack) + sizeof(pkt.info);
101102
break;
102103
}

0 commit comments

Comments
 (0)