Skip to content

Commit cf1a647

Browse files
committed
rxrpc: Add per-peer RTT tracker
Add a function to track the average RTT for a peer. Sources of RTT data will be added in subsequent patches. The RTT data will be useful in the future for determining resend timeouts and for handling the slow-start part of the Rx protocol. Also add a pair of tracepoints, one to log transmissions to elicit a response for RTT purposes and one to log responses that contribute RTT data. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent f07373e commit cf1a647

4 files changed

Lines changed: 131 additions & 4 deletions

File tree

‎include/trace/events/rxrpc.h‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,67 @@ TRACE_EVENT(rxrpc_recvmsg,
353353
__entry->ret)
354354
);
355355

356+
TRACE_EVENT(rxrpc_rtt_tx,
357+
TP_PROTO(struct rxrpc_call *call, enum rxrpc_rtt_tx_trace why,
358+
rxrpc_serial_t send_serial),
359+
360+
TP_ARGS(call, why, send_serial),
361+
362+
TP_STRUCT__entry(
363+
__field(struct rxrpc_call *, call )
364+
__field(enum rxrpc_rtt_tx_trace, why )
365+
__field(rxrpc_serial_t, send_serial )
366+
),
367+
368+
TP_fast_assign(
369+
__entry->call = call;
370+
__entry->why = why;
371+
__entry->send_serial = send_serial;
372+
),
373+
374+
TP_printk("c=%p %s sr=%08x",
375+
__entry->call,
376+
rxrpc_rtt_tx_traces[__entry->why],
377+
__entry->send_serial)
378+
);
379+
380+
TRACE_EVENT(rxrpc_rtt_rx,
381+
TP_PROTO(struct rxrpc_call *call, enum rxrpc_rtt_rx_trace why,
382+
rxrpc_serial_t send_serial, rxrpc_serial_t resp_serial,
383+
s64 rtt, u8 nr, s64 avg),
384+
385+
TP_ARGS(call, why, send_serial, resp_serial, rtt, nr, avg),
386+
387+
TP_STRUCT__entry(
388+
__field(struct rxrpc_call *, call )
389+
__field(enum rxrpc_rtt_rx_trace, why )
390+
__field(u8, nr )
391+
__field(rxrpc_serial_t, send_serial )
392+
__field(rxrpc_serial_t, resp_serial )
393+
__field(s64, rtt )
394+
__field(u64, avg )
395+
),
396+
397+
TP_fast_assign(
398+
__entry->call = call;
399+
__entry->why = why;
400+
__entry->send_serial = send_serial;
401+
__entry->resp_serial = resp_serial;
402+
__entry->rtt = rtt;
403+
__entry->nr = nr;
404+
__entry->avg = avg;
405+
),
406+
407+
TP_printk("c=%p %s sr=%08x rr=%08x rtt=%lld nr=%u avg=%lld",
408+
__entry->call,
409+
rxrpc_rtt_rx_traces[__entry->why],
410+
__entry->send_serial,
411+
__entry->resp_serial,
412+
__entry->rtt,
413+
__entry->nr,
414+
__entry->avg)
415+
);
416+
356417
#endif /* _TRACE_RXRPC_H */
357418

358419
/* This part must be outside protection */

‎net/rxrpc/ar-internal.h‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,11 @@ struct rxrpc_peer {
258258

259259
/* calculated RTT cache */
260260
#define RXRPC_RTT_CACHE_SIZE 32
261-
suseconds_t rtt; /* current RTT estimate (in uS) */
262-
unsigned int rtt_point; /* next entry at which to insert */
263-
unsigned int rtt_usage; /* amount of cache actually used */
264-
suseconds_t rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
261+
u64 rtt; /* Current RTT estimate (in nS) */
262+
u64 rtt_sum; /* Sum of cache contents */
263+
u64 rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */
264+
u8 rtt_cursor; /* next entry at which to insert */
265+
u8 rtt_usage; /* amount of cache actually used */
265266
};
266267

267268
/*
@@ -657,6 +658,20 @@ enum rxrpc_recvmsg_trace {
657658

658659
extern const char rxrpc_recvmsg_traces[rxrpc_recvmsg__nr_trace][5];
659660

661+
enum rxrpc_rtt_tx_trace {
662+
rxrpc_rtt_tx_ping,
663+
rxrpc_rtt_tx__nr_trace
664+
};
665+
666+
extern const char rxrpc_rtt_tx_traces[rxrpc_rtt_tx__nr_trace][5];
667+
668+
enum rxrpc_rtt_rx_trace {
669+
rxrpc_rtt_rx_ping_response,
670+
rxrpc_rtt_rx__nr_trace
671+
};
672+
673+
extern const char rxrpc_rtt_rx_traces[rxrpc_rtt_rx__nr_trace][5];
674+
660675
extern const char *const rxrpc_pkts[];
661676
extern const char *rxrpc_acks(u8 reason);
662677

@@ -955,6 +970,8 @@ void rxrpc_reject_packets(struct rxrpc_local *);
955970
*/
956971
void rxrpc_error_report(struct sock *);
957972
void rxrpc_peer_error_distributor(struct work_struct *);
973+
void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace,
974+
rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
958975

959976
/*
960977
* peer_object.c

‎net/rxrpc/misc.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,11 @@ const char rxrpc_recvmsg_traces[rxrpc_recvmsg__nr_trace][5] = {
182182
[rxrpc_recvmsg_to_be_accepted] = "TBAC",
183183
[rxrpc_recvmsg_return] = "RETN",
184184
};
185+
186+
const char rxrpc_rtt_tx_traces[rxrpc_rtt_tx__nr_trace][5] = {
187+
[rxrpc_rtt_tx_ping] = "PING",
188+
};
189+
190+
const char rxrpc_rtt_rx_traces[rxrpc_rtt_rx__nr_trace][5] = {
191+
[rxrpc_rtt_rx_ping_response] = "PONG",
192+
};

‎net/rxrpc/peer_event.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,44 @@ void rxrpc_peer_error_distributor(struct work_struct *work)
305305
rxrpc_put_peer(peer);
306306
_leave("");
307307
}
308+
309+
/*
310+
* Add RTT information to cache. This is called in softirq mode and has
311+
* exclusive access to the peer RTT data.
312+
*/
313+
void rxrpc_peer_add_rtt(struct rxrpc_call *call, enum rxrpc_rtt_rx_trace why,
314+
rxrpc_serial_t send_serial, rxrpc_serial_t resp_serial,
315+
ktime_t send_time, ktime_t resp_time)
316+
{
317+
struct rxrpc_peer *peer = call->peer;
318+
s64 rtt;
319+
u64 sum = peer->rtt_sum, avg;
320+
u8 cursor = peer->rtt_cursor, usage = peer->rtt_usage;
321+
322+
rtt = ktime_to_ns(ktime_sub(resp_time, send_time));
323+
if (rtt < 0)
324+
return;
325+
326+
/* Replace the oldest datum in the RTT buffer */
327+
sum -= peer->rtt_cache[cursor];
328+
sum += rtt;
329+
peer->rtt_cache[cursor] = rtt;
330+
peer->rtt_cursor = (cursor + 1) & (RXRPC_RTT_CACHE_SIZE - 1);
331+
peer->rtt_sum = sum;
332+
if (usage < RXRPC_RTT_CACHE_SIZE) {
333+
usage++;
334+
peer->rtt_usage = usage;
335+
}
336+
337+
/* Now recalculate the average */
338+
if (usage == RXRPC_RTT_CACHE_SIZE) {
339+
avg = sum / RXRPC_RTT_CACHE_SIZE;
340+
} else {
341+
avg = sum;
342+
do_div(avg, usage);
343+
}
344+
345+
peer->rtt = avg;
346+
trace_rxrpc_rtt_rx(call, why, send_serial, resp_serial, rtt,
347+
usage, avg);
348+
}

0 commit comments

Comments
 (0)