Skip to content

Commit 10a331e

Browse files
committed
netstacklat: minor sync with upstream bpf-examples version
The upstream version of netstacklat that we are based on got merged see PR#129. xdp-project/bpf-examples#129 Some adjustments were made, so lets sync with these to avoid diverting too much from upstream. Signed-off-by: Jesper Dangaard Brouer <hawk@kernel.org>
1 parent febd9b7 commit 10a331e

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

examples/netstacklat.bpf.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "netstacklat.h"
2020
#include "bits.bpf.h"
2121

22+
#define READ_ONCE(x) (*(volatile typeof(x) *)&(x))
23+
2224
char LICENSE[] SEC("license") = "GPL";
2325

2426
/* The ebpf_exporter variant of netstacklat is not runtime configurable at
@@ -28,7 +30,7 @@ char LICENSE[] SEC("license") = "GPL";
2830
const __s64 TAI_OFFSET = (37LL * NS_PER_S);
2931
const struct netstacklat_bpf_config user_config = {
3032
.network_ns = 0,
31-
.filter_min_queue_len = 0, /* zero means filter is inactive */
33+
.filter_min_sockqueue_len = 0, /* zero means filter is inactive */
3234
.filter_nth_packet = 0, /* reduce recorded event to every nth packet, use power-of-2 */
3335
.filter_pid = false,
3436
.filter_ifindex = true,
@@ -122,7 +124,7 @@ struct {
122124
#else
123125
struct {
124126
__uint(type, BPF_MAP_TYPE_HASH); /* type: hash */
125-
__uint(max_entries, MAX_TRACKED_CGROUPS);
127+
__uint(max_entries, MAX_PARSED_CGROUPS);
126128
__type(key, u64);
127129
__type(value, u64);
128130
} netstack_cgroupfilter SEC(".maps");
@@ -305,9 +307,7 @@ static bool filter_network_ns(struct sk_buff *skb, struct sock *sk)
305307
if (user_config.network_ns == 0)
306308
return true;
307309

308-
u32 ns = get_network_ns(skb, sk);
309-
310-
return ns == user_config.network_ns;
310+
return get_network_ns(skb, sk) == user_config.network_ns;
311311
}
312312

313313
#if (CONFIG_HOOKS_EARLY_RCV || CONFIG_HOOKS_ENQUEUE)
@@ -372,7 +372,6 @@ static bool filter_pid(u32 pid)
372372
return false;
373373

374374
return *pid_ok > 0;
375-
376375
}
377376
#endif /* CONFIG_PID_FILTER_MAP */
378377

@@ -425,8 +424,6 @@ static bool filter_current_task()
425424
return ok;
426425
}
427426

428-
#define READ_ONCE(x) (*(volatile typeof(x) *)&(x))
429-
430427
/**
431428
* skb_queue_empty - check if a queue is empty
432429
* @list: queue head
@@ -469,9 +466,9 @@ static inline __u32 sk_queue_len(const struct sk_buff_head *list_)
469466
return READ_ONCE(list_->qlen);
470467
}
471468

472-
static bool filter_min_queue_len(struct sock *sk)
469+
static bool filter_min_sockqueue_len(struct sock *sk)
473470
{
474-
const u32 min_qlen = user_config.filter_min_queue_len;
471+
const u32 min_qlen = user_config.filter_min_sockqueue_len;
475472

476473
if (min_qlen == 0)
477474
return true;
@@ -496,7 +493,7 @@ static __always_inline bool filter_socket(struct sock *sk, struct sk_buff *skb,
496493
if (!filter_nonempty_sockqueue(sk))
497494
return false;
498495

499-
if (!filter_min_queue_len(sk))
496+
if (!filter_min_sockqueue_len(sk))
500497
return false;
501498

502499
if (!filter_cgroup(cgroup_id))

examples/netstacklat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// The highest ifindex we expect to encounter
2424
#define IFINDEX_MAX 16384
2525
// The maximum number of different cgroups we can filter for
26-
#define MAX_TRACKED_CGROUPS 4096
26+
#define MAX_PARSED_CGROUPS 4096
2727

2828
#ifndef ARRAY_SIZE
2929
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
@@ -80,7 +80,7 @@ struct hist_key {
8080

8181
struct netstacklat_bpf_config {
8282
__u32 network_ns;
83-
__u32 filter_min_queue_len;
83+
__u32 filter_min_sockqueue_len;
8484
__u64 filter_nth_packet;
8585
bool filter_pid;
8686
bool filter_ifindex;

0 commit comments

Comments
 (0)