BPF List
 help / color / mirror / Atom feed
From: David Vernet <void@manifault.com>
To: lsf-pc@lists.linux-foundation.org
Cc: bpf@vger.kernel.org
Subject: [LSF/MM/BPF TOPIC] Polymorphic Kfuncs
Date: Wed, 3 Jan 2024 13:21:20 -0600	[thread overview]
Message-ID: <20240103192120.GA303539@maniforge> (raw)

[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]

Hello,

Kfuncs [0] allow BPF programs to call out to the main kernel. They are
the modern version of BPF helpers, and don't require any UAPI changes.
With sched_ext, we define a variety of kfuncs for many different
purposes.  For example, the scx_bpf_dispatch() [1] kfunc is used to
"dispatch" a task to a dispatch queue. Other kfuncs are used to e.g. get
a cpumask that tracks idle cores.

[0]: https://docs.kernel.org/bpf/kfuncs.html
[1]: https://github.com/sched-ext/sched_ext/blob/6b747e0ee5fca284330d065a0c777d1991290bc4/kernel/sched/ext.c#L3921

One thing that's interesting about scx_bpf_dispatch() is that while the
interface and advertised semantics of the kfunc are the same regardless
of where it's called, the implementation of the kfunc varies depending
on its calling context. If it's called from a certain set of struct_ops
progs, we do something differently than if it's called from another, due
to implementation details of the subsystem.

We can (and already do) enable this behavior by setting a per-cpu
variable that we check in the kfunc implementation to determine where we
were called from, but it would be more ergonomic if we could instead
specify that a different kfunc implementation should be invoked
depending on which prog it was invoked from as part of the core kfunc
interface. Or, in other words, if we supported "polymorphic" kfuncs.

I'd like to go into more details on how this feature would be used, and
of course to also discuss possible designs.

Thanks,
David

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

                 reply	other threads:[~2024-01-03 19:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240103192120.GA303539@maniforge \
    --to=void@manifault.com \
    --cc=bpf@vger.kernel.org \
    --cc=lsf-pc@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox