[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87352lx9xm.fsf@metaspace.dk>
Date: Wed, 21 Jun 2023 14:30:01 +0200
From: "Andreas Hindborg (Samsung)" <nmi@...aspace.dk>
To: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
Cc: Andrew Lunn <andrew@...n.ch>, FUJITA Tomonori
<fujita.tomonori@...il.com>, kuba@...nel.org, netdev@...r.kernel.org,
rust-for-linux@...r.kernel.org, aliceryhl@...gle.com
Subject: Re: [PATCH 0/5] Rust abstractions for network device drivers
Miguel Ojeda <miguel.ojeda.sandonis@...il.com> writes:
> On Fri, Jun 16, 2023 at 3:14 PM Andrew Lunn <andrew@...n.ch> wrote:
>>
>> I think this is something you need to get addressed at a language
>> level very soon. Lots of netdev API calls will be to macros. The API
>> to manipulate skbs is pretty much always used on the hot path, so i
>> expect that it will have a large number of macros. It is unclear to me
>> how well it will scale if you need to warp them all?
>>
>> ~/linux/include/linux$ grep inline skbuff.h | wc
>> 349 2487 23010
>>
>> Do you really want to write 300+ wrappers?
>
> It would be very nice if at least `bindgen` (or even the Rust
> compiler... :) could cover many of these one-liners. We have discussed
> and asked for this in the past, and messages like this reinforce the
> need/request for this clearly, so thanks for this.
>
> Since `bindgen` 0.64.0 earlier this year [1] there is an experimental
> feature for this (`--wrap-static-fns`), so that is nice -- though we
> need to see how well it works. We are upgrading `bindgen` to the
> latest version after the merge window, so we can play with this soon.
>
> In particular, given:
>
> static inline int foo(int a, int b) {
> return a + b;
> }
>
> It generates a C file with e.g.:
>
> #include "a.h"
>
> // Static wrappers
>
> int foo__extern(int a, int b) { return foo(a, b); }
>
> And then in the usual Rust bindings:
>
> extern "C" {
> #[link_name = "foo__extern"]
> pub fn foo(a: ::std::os::raw::c_int, b: ::std::os::raw::c_int)
> -> ::std::os::raw::c_int;
> }
This is nice! It would be awesome if we could have something similar for
macros. I am not sure if it is possible though. For the null_block
demonstrator I had to move some C macros to Rust, for instance to
implement iterators of bvec [1]. In the particular case of
`bvec_iter_bvec()` it is not possible to wrap the macro in a function
because the macro operates on a value, not a reference. We would have to
pass an argument by value to the wrapping function in order to invoke
the macro on this stack local variable, and then return the value again.
Not really efficient.
[1] https://lore.kernel.org/rust-for-linux/20230503090708.2524310-5-nmi@metaspace.dk/
Powered by blists - more mailing lists