DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Van Haaren, Harry" <harry.van.haaren@intel.com>
To: "Etelson, Gregory" <getelson@nvidia.com>
Cc: "Richardson, Bruce" <bruce.richardson@intel.com>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [RFC PATCH] add rust binding support to DPDK
Date: Fri, 11 Apr 2025 16:22:18 +0000	[thread overview]
Message-ID: <PH8PR11MB6803A8EFAF0A3E8DA8211254D7B62@PH8PR11MB6803.namprd11.prod.outlook.com> (raw)
In-Reply-To: <95367723-36f5-13a4-b513-27a7b4f7ee7c@nvidia.com>

> From: Etelson, Gregory
> Sent: Friday, April 11, 2025 4:39 PM
> To: Van Haaren, Harry
> Cc: Richardson, Bruce; dev@dpdk.org
> Subject: Re: [RFC PATCH] add rust binding support to DPDK
> 
> Hello Bruce & Harry,
> 
> <snip>
> 
> >
> >> My concern is how to properly maintain Rust crate once DPDK starts to implement
> >> it's own API.
> >
> > I'm not really sure what is meant here. I don't understand what "own" word refers to?
> >
> > I see it like this:
> > - DPDK has the public C API exported (and that stays the same as today, with ABI rules, version.map files, etc)
> > - The Rust crate consumes the public C API (via bindgen, as done in this patch. More detail about bindgen below.)
> >
> 
> Bindgen cannot provide access to all DPDK public API.

Ah - you're referring to C static inline functions, declared in header files, which bindgen doesn't wrap.
Correct - thanks - I understand your point now.

> A good example here is rte_eth_rx_burst().
> That function is defined as inline and bindgen does not translate it.
> Also, the function definition references rte_eth_fp_ops array that is not part of the
> public DPDK API. That means Rust cannot duplicate rte_eth_rx_burst() "as-is" and
> the solution can require extensions to existing DPDK API.
> 
> I added a new public API that exports rte_eth_fp_ops for a given port Id.
> 
> Rust implementation of rte_eth_rx_burst() does not have to follow the original
> approach.
> Usage of rte_eth_fp_ops is good for C, but Rust has different methods.

Agreed there is a certain "mismatch" sometimes, if functions aren't in the
actually "C ABI" then they can't be called via bindgen.

Agree that elegant solutions (clean, maintainable, and high performance) will have
to be found here. Many existing solutions just wrap the "static inline" function into
a "non-static" function, and export it as a public symbol. That allows calling into it
from Rust (via bindgen-generated header) however causes an actual function call..
(LTO _might_ fix/inline it, but not everybody compiles with LTO.. link times!)

As DPDK uses static-inline functions primarily for "packet-at-a-time" performance reasons,
it is unfortunate to give-up (some small amounts of..?) performance by having a C->Rust FFI call.
We have work to do to find/propose the best solution.

> For conclusion, Rust DPDK infrastructure cannot relay on bindgen only and needs
> to provide native implementation for some public DPDK API.
> It can be easier to maintain Rust files separately.

OK, now I understand your "kind-of-C-DPDK, kind of Rust-DPDK" code, or the "own" code reference above.
I'm not sure right now where that would be best implemented/maintained, I'll have to think about it and do a POC.


> You can check out my Rust DPDK version here: https://github.com/getelson-at-mellanox/rdpdk

Thanks for the link - I see you've been pushing code actively! Good to see opportunities,
and compare approaches and concepts. Have you investigated wrapping the various pointers
into structs, and providing safer APIs? For example, the [*mut rte_mbuf; 64] array for RX causes
raw pointers to be handled for all packet-processing - resulting in "unsafe{ /* work here */ }" blocks.

The code in the above repo feels like "DPDK C code written in Rust". It is a great step towards better
understanding, and having something that works is very valuable; thanks for sharing it.

A "top down" application view might help to brainstorm idiomatic/Safe Rust APIs, and then we can
discuss/understand how to map these high level APIs onto the "DPDK C in Rust" or even "DPDK C API/ABI" layers.

Does that seem like a good method to you, to achieve an ergonomic Safe Rust API as the end result?


> > Next steps are to "allowlist" more DPDK public API functions, and start building "Safe Rust" APIs over
> > them, in order to expose an ergonomic and misuse-resistant API. As you note, this is where a network ports,
> > lcores, mempools, and ethdev configuration are all required. First goal something like "Safe L2 macswap"?
> 
> I suggest to set the first goal to initiate a port and run simple Rx/Tx functions.

Agreed, we need some API to "work towards" (Top down) as well as "work from" (DPDK C APIs, and your repo above).

> > I will make some Safe-Rust API suggestions for EAL, and send a patch sometime next week to discuss.

Hopefully this Safe-Rust API proposal will be a candidate for "Top Down" API design approach.

> > Thanks for the inputs! Regards, -Harry
> 
> Regards,
> Gregory

Thanks! -Harry

  reply	other threads:[~2025-04-11 16:22 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-06 13:37 [PATCH] rust: support DPDK API Gregory Etelson
2025-03-06 19:26 ` Van Haaren, Harry
2025-03-07 16:56   ` Etelson, Gregory
2025-03-07 15:54 ` Van Haaren, Harry
2025-03-07 16:20   ` Bruce Richardson
2025-03-07 18:15     ` Etelson, Gregory
2025-03-07 18:00   ` Etelson, Gregory
2025-03-08 14:28 ` Igor Gutorov
2025-03-08 19:14   ` Etelson, Gregory
2025-03-10 15:31     ` Stephen Hemminger
2025-03-12  5:21       ` Etelson, Gregory
2025-03-08 18:50 ` [PATCH v2] rust: support raw " Gregory Etelson
2025-03-10 16:13   ` Van Haaren, Harry
2025-03-10 16:25     ` Bruce Richardson
2025-03-12 17:19       ` Thomas Monjalon
2025-03-14 19:12     ` Etelson, Gregory
2025-03-10 15:00 ` [PATCH] rust: support " Stephen Hemminger
2025-03-12  5:12   ` Etelson, Gregory
2025-03-10 16:18 ` Stephen Hemminger
2025-03-10 16:30   ` Bruce Richardson
2025-03-12 14:30   ` Etelson, Gregory
2025-03-13  7:56     ` Igor Gutorov
2025-03-12 15:29   ` Igor Gutorov
2025-03-12 17:24     ` Thomas Monjalon
2025-03-14 18:38 ` [PATCH v3] rust: support raw " Gregory Etelson
2025-03-18  8:51   ` Dariusz Sosnowski
2025-03-18  9:12     ` Dariusz Sosnowski
2025-03-22 10:59 ` [PATCH v4] " Gregory Etelson
2025-03-22 17:39   ` Bruce Richardson
2025-03-27  5:51     ` Etelson, Gregory
2025-03-27 16:22   ` Bruce Richardson
2025-03-28 18:30     ` Etelson, Gregory
2025-03-27  8:23 ` DPDK for rust Morten Brørup
2025-03-27  9:00   ` Etelson, Gregory
2025-03-27 16:17     ` Bruce Richardson
2025-03-28 18:09       ` Etelson, Gregory
2025-03-28 19:25         ` Stephen Hemminger
2025-03-31  9:11           ` Bruce Richardson
2025-03-31 10:26             ` Luca Boccassi
2025-04-01 13:08               ` Etelson, Gregory
2025-03-31  9:03       ` Thomas Monjalon
2025-03-31  9:10         ` Bruce Richardson
2025-04-08 14:58 ` [RFC PATCH] add rust binding support to DPDK Bruce Richardson
2025-04-08 15:05   ` Bruce Richardson
2025-04-10  5:28   ` Etelson, Gregory
2025-04-11 13:13     ` Van Haaren, Harry
2025-04-11 15:39       ` Etelson, Gregory
2025-04-11 16:22         ` Van Haaren, Harry [this message]
2025-04-13  8:07           ` Etelson, Gregory
2025-04-13 17:09             ` Owen Hilyard

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=PH8PR11MB6803A8EFAF0A3E8DA8211254D7B62@PH8PR11MB6803.namprd11.prod.outlook.com \
    --to=harry.van.haaren@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=getelson@nvidia.com \
    /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;
as well as URLs for NNTP newsgroup(s).