1
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
2
2
/*
3
- * This is a ebpf_exporter variant of the netstacklat tool
3
+ * This is an ebpf_exporter variant of the netstacklat tool
4
4
*
5
5
* Netstacklat - is a tool that "Monitor RX latency within the network stack"
6
6
* - https://github.com/xdp-project/bpf-examples/tree/main/netstacklat
@@ -29,7 +29,7 @@ char LICENSE[] SEC("license") = "GPL";
29
29
const __s64 TAI_OFFSET = (37LL * NS_PER_S );
30
30
const struct netstacklat_bpf_config user_config = {
31
31
.network_ns = 0 ,
32
- .filter_queue_len = 3 , /* zero means filter is inactive */
32
+ .filter_queue_len = 1 , /* zero means filter is inactive */
33
33
.filter_pid = false,
34
34
.filter_ifindex = true,
35
35
.filter_cgroup = true,
@@ -390,12 +390,24 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
390
390
return READ_ONCE (list -> next ) == (const struct sk_buff * )list ;
391
391
}
392
392
393
+ static inline bool sk_backlog_empty (const struct sock * sk )
394
+ {
395
+ return READ_ONCE (sk -> sk_backlog .tail ) == NULL ;
396
+ }
397
+
393
398
static bool filter_nonempty_sockqueue (struct sock * sk )
394
399
{
395
400
if (!user_config .filter_nonempty_sockqueue )
396
401
return true;
397
402
398
- return !skb_queue_empty (& sk -> sk_receive_queue );
403
+ if (!skb_queue_empty (& sk -> sk_receive_queue ))
404
+ return true;
405
+
406
+ /* Packets can also be on the sk_backlog */
407
+ if (!sk_backlog_empty (sk ))
408
+ return true;
409
+
410
+ return false;
399
411
}
400
412
401
413
/* To lower runtime overhead, skip recording timestamps for sockets with very
@@ -416,6 +428,14 @@ static bool filter_queue_len(struct sock *sk)
416
428
417
429
if (sk_queue_len (& sk -> sk_receive_queue ) > above_len )
418
430
return true;
431
+
432
+ /* Packets can also be on the sk_backlog, but we don't know the number
433
+ * of SKBs on the queue, because sk_backlog.len is in bytes (based on
434
+ * skb->truesize). Thus, if any backlog exists we don't filter.
435
+ */
436
+ if (!sk_backlog_empty (sk ))
437
+ return true;
438
+
419
439
return false;
420
440
}
421
441
@@ -526,7 +546,6 @@ int BPF_PROG(netstacklat_udp_enqueue_schedule_skb, struct sock *sk,
526
546
#endif /* CONFIG_HOOKS_ENQUEUE */
527
547
528
548
#ifdef CONFIG_HOOKS_DEQUEUE
529
-
530
549
SEC ("fentry/tcp_recv_timestamp" )
531
550
int BPF_PROG (netstacklat_tcp_recv_timestamp , void * msg , struct sock * sk ,
532
551
struct scm_timestamping_internal * tss )
0 commit comments