xdp-newbies.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Pass a map to a global BPF function
@ 2021-09-13 17:43 Zvi Effron
  2021-09-21 20:04 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Zvi Effron @ 2021-09-13 17:43 UTC (permalink / raw)
  To: Xdp

Hi all,

We have some map-of-arrays that we use for tracking labeled metrics in
our XDP code. The inner map tracks the metrics for a given label,
which is the key in the outer map.

Our XDP code calls several global BPF functions (freplaced, so can't
be inlined). Currently, each global function has to make a lookup to
get the inner map to record its metrics. Now that non-context pointers
can be passed to global BPF functions, is it possible to pass maps to
these global functions?

That would allow the primary function to do the lookup once, and the
helpers would be able to skip their lookup saving considerable time.
Using this map-of-maps approach for labeled metrics has produced a
noticeable performance degradation that profiling indicates is because
of the extra lookups, which is why we're interested in reducing the
number of lookups.

Thanks!
--Zvi

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Pass a map to a global BPF function
  2021-09-13 17:43 Pass a map to a global BPF function Zvi Effron
@ 2021-09-21 20:04 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2021-09-21 20:04 UTC (permalink / raw)
  To: Zvi Effron, bpf; +Cc: Xdp

On Mon, Sep 13, 2021 at 10:44 AM Zvi Effron <zeffron@riotgames.com> wrote:
>
> Hi all,
>
> We have some map-of-arrays that we use for tracking labeled metrics in
> our XDP code. The inner map tracks the metrics for a given label,
> which is the key in the outer map.
>
> Our XDP code calls several global BPF functions (freplaced, so can't
> be inlined). Currently, each global function has to make a lookup to
> get the inner map to record its metrics. Now that non-context pointers
> can be passed to global BPF functions, is it possible to pass maps to
> these global functions?

The program can pass a pointer to struct bpf_map and the verifier
will recognize it as PTR_TO_BTF_ID.
It won't be a CONST_PTR_TO_MAP, so secondary lookup won't be
allowed, but if that's the desired use case then the verifier can be extended
to recognize it.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-21 20:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13 17:43 Pass a map to a global BPF function Zvi Effron
2021-09-21 20:04 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).