Thread (38 messages) 38 messages, 5 authors, 2024-05-24

Re: [PATCH net-next 14/15] net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.

From: Jesper Dangaard Brouer <hawk@kernel.org>
Date: 2024-05-07 13:27:51
Also in: bpf, lkml


On 07/05/2024 14.36, Sebastian Andrzej Siewior wrote:
On 2024-05-06 16:09:47 [-0700], Alexei Starovoitov wrote:
quoted
quoted
quoted
On PREEMPT_RT the pointer to bpf_net_context is saved task's
task_struct. On non-PREEMPT_RT builds the pointer saved in a per-CPU
variable (which is always NODE-local memory). Using always the
bpf_net_context approach has the advantage that there is almost zero
differences between PREEMPT_RT and non-PREEMPT_RT builds.
Did you ever manage to get any performance data to see if this has an
impact?

[...]
quoted
+static inline struct bpf_net_context *bpf_net_ctx_get(void)
+{
+     struct bpf_net_context *bpf_net_ctx = this_cpu_read(bpf_net_context);
+
+     WARN_ON_ONCE(!bpf_net_ctx);
If we have this WARN...
When asking for change anyhow...

XDP redirect is an extreme fast-path.

Adding an WARN macro cause adding an 'ud2' instruction that cause CPU
instruction-cache to stop pre-fetching.

For this reason we in include/net/xdp.h have #define XDP_WARN and
function xdp_warn() that lives in net/core/xdp.c.
See how it is used in xdp_update_frame_from_buff().

Described in https://git.kernel.org/torvalds/c/34cc0b338a61
  - 34cc0b338a61 ("xdp: Xdp_frame add member frame_sz and handle in 
convert_to_xdp_frame")


quoted
quoted
quoted
+static inline struct bpf_redirect_info *bpf_net_ctx_get_ri(void)
+{
+     struct bpf_net_context *bpf_net_ctx = bpf_net_ctx_get();
+
+     if (!bpf_net_ctx)
+             return NULL;
... do we really need all the NULL checks?
Indeed.
Let's drop all NULL checks, since they definitely add overhead.
I'd also remove ifdef CONFIG_PREEMPT_RT and converge on single implementation:
static inline struct bpf_net_context * bpf_net_ctx_get(void)
{
  return current->bpf_net_context;
}
Okay, let me do that then.
I need/want to echo Toke's request to benchmark these changes.

--Jesper
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help