From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: Wedson Almeida Filho <wedsonaf@google.com>,
Linus Walleij <linus.walleij@linaro.org>,
Greg KH <greg@kroah.com>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Kees Cook <keescook@chromium.org>, Jan Kara <jack@suse.cz>,
James Bottomley <James.Bottomley@hansenpartnership.com>,
Julia Lawall <julia.lawall@inria.fr>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Roland Dreier <roland@kernel.org>,
ksummit@lists.linux.dev, Viresh Kumar <viresh.kumar@linaro.org>
Subject: Re: [TECH TOPIC] Rust for Linux
Date: Tue, 20 Jul 2021 11:39:47 +0200 [thread overview]
Message-ID: <YPaZ4zTZHOQfBhOk@piout.net> (raw)
In-Reply-To: <CANiq72mpCysR3B=sLBWOi4PGSZf9B5e1bXQJaGQ5MkknKfixhg@mail.gmail.com>
Hi,
On 20/07/2021 09:15:44+0200, Miguel Ojeda wrote:
> Hi Alexandre,
>
> On Tue, Jul 20, 2021 at 12:57 AM Alexandre Belloni
> <alexandre.belloni@bootlin.com> wrote:
> >
> > I'd love to have a side by side disassembly of the generated object
> > files (ideally intermixed with the source).
>
> It is hard to do such a match because of different reasons, such as:
>
> - The extra work that the Rust version does (the revocable resources feature).
>
Well, the point is exactly to have a look at that extra work.
> - The Rust version not being able to inline the opaque helpers that
> we use to avoid rewriting C macros (without cross-language LTO
> support).
>
> - The Rust version inlining generics from the `kernel` crate (which
> happens even without LTO, because they are generics).
>
> - The C version not being able to inline from other translation
> units (without LTO).
>
> In any case, to give you an example, I took `get_direction()` which is
> fairly simple and under `-O2` with overflow checks disabled in Rust I
> got:
>
I was under the impression that you would compile the kernel with
overflow checks enabled, why would you disable them here?
> 00000000000001b8 <pl061_get_direction>:
> 1b8: a9be7bfd stp x29, x30, [sp, #-32]!
> 1bc: f9000bf3 str x19, [sp, #16]
> 1c0: 910003fd mov x29, sp
> 1c4: 2a0103f3 mov w19, w1
> 1c8: 94000000 bl 0 <gpiochip_get_data>
> 1cc: f9400408 ldr x8, [x0, #8]
> 1d0: 91100108 add x8, x8, #0x400
> 1d4: 39400108 ldrb w8, [x8]
> 1d8: d50331bf dmb oshld
> 1dc: 92401d08 and x8, x8, #0xff
> 1e0: ca080109 eor x9, x8, x8
> 1e4: b5000009 cbnz x9, 1e4 <pl061_get_direction+0x2c>
> 1e8: 9ad32508 lsr x8, x8, x19
> 1ec: f9400bf3 ldr x19, [sp, #16]
> 1f0: f240011f tst x8, #0x1
> 1f4: 1a9f17e0 cset w0, eq // eq = none
> 1f8: a8c27bfd ldp x29, x30, [sp], #32
> 1fc: d65f03c0 ret
>
> 00000000000009d8 <...::get_direction>:
> 9d8: a9bd7bfd stp x29, x30, [sp, #-48]!
> 9dc: f9000bf5 str x21, [sp, #16]
> 9e0: a9024ff4 stp x20, x19, [sp, #32]
> 9e4: 910003fd mov x29, sp
> 9e8: f9400014 ldr x20, [x0]
> 9ec: 2a0103f3 mov w19, w1
> 9f0: 94000000 bl 0 <rust_helper_rcu_read_lock>
> 9f4: 39402288 ldrb w8, [x20, #8]
> 9f8: 72001d1f tst w8, #0xff
> 9fc: 54000180 b.eq a2c <...::get_direction+0x54> // b.none
> a00: f9419288 ldr x8, [x20, #800]
> a04: 91100100 add x0, x8, #0x400
> a08: 94000000 bl 0 <rust_helper_readb>
> a0c: 92400a68 and x8, x19, #0x7
> a10: 1ac82408 lsr w8, w0, w8
> a14: 7200011f tst w8, #0x1
> a18: 1a9f17e8 cset w8, eq // eq = none
> a1c: aa1f03f4 mov x20, xzr
> a20: aa1f03f5 mov x21, xzr
> a24: d378dd13 lsl x19, x8, #8
> a28: 14000005 b a3c <...::get_direction+0x64>
> a2c: d2dfff54 mov x20, #0xfffa00000000 // #281449206906880
> a30: aa1f03f3 mov x19, xzr
> a34: f2fffff4 movk x20, #0xffff, lsl #48
> a38: 52800035 mov w21, #0x1 // #1
> a3c: 94000000 bl 0 <rust_helper_rcu_read_unlock>
> a40: aa140268 orr x8, x19, x20
> a44: aa150100 orr x0, x8, x21
> a48: a9424ff4 ldp x20, x19, [sp, #32]
> a4c: f9400bf5 ldr x21, [sp, #16]
> a50: a8c37bfd ldp x29, x30, [sp], #48
> a54: d65f03c0 ret
>
> To be a bit more fair to the Rust version by not having the revocable
> part, I wrote a `test` function in both C and Rust with only the read
> that `get_direction()` does:
But do we care about very simple test cases? The pl061 driver is already
simple and this would be an example of what to expect for most of the
simple drivers that would get converted.
>
> u8 test(struct pl061 *pl061, unsigned offset) {
> return readb(pl061->base + GPIODIR) & BIT(offset);
> }
>
> fn test(pl061: &PL061Resources, offset: u32) -> u8 {
> pl061.base.readb(GPIODIR) & bit(offset)
> }
>
> This, of course, yields a much closer result:
>
> 0000000000000000 <test>:
> 0: f9400408 ldr x8, [x0, #8]
> 4: 91100108 add x8, x8, #0x400
> 8: 39400108 ldrb w8, [x8]
> c: d50331bf dmb oshld
> 10: 92401d09 and x9, x8, #0xff
> 14: ca090129 eor x9, x9, x9
> 18: b5000009 cbnz x9, 18 <test+0x18>
> 1c: 52800029 mov w9, #0x1 // #1
> 20: 9ac12129 lsl x9, x9, x1
> 24: 0a090100 and w0, w8, w9
> 28: d65f03c0 ret
>
> 00000000000009d0 <gpio_pl061_rust::test>:
> 9d0: a9be7bfd stp x29, x30, [sp, #-32]!
> 9d4: f9000bf3 str x19, [sp, #16]
> 9d8: 910003fd mov x29, sp
> 9dc: f9400008 ldr x8, [x0]
> 9e0: 2a0103f3 mov w19, w1
> 9e4: 91100100 add x0, x8, #0x400
> 9e8: 94000000 bl 0 <rust_helper_readb>
This is a function call, I would not call that closer to the C
version. Can we see rust_helper_readb?
> 9ec: 92400a68 and x8, x19, #0x7
> 9f0: f9400bf3 ldr x19, [sp, #16]
> 9f4: 52800029 mov w9, #0x1 // #1
> 9f8: 1ac82128 lsl w8, w9, w8
> 9fc: 0a080000 and w0, w0, w8
> a00: a8c27bfd ldp x29, x30, [sp], #32
> a04: d65f03c0 ret
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2021-07-20 9:49 UTC|newest]
Thread overview: 204+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-25 22:09 [TECH TOPIC] Rust for Linux Miguel Ojeda
2021-07-05 23:51 ` Linus Walleij
2021-07-06 4:30 ` Leon Romanovsky
2021-07-06 9:55 ` Linus Walleij
2021-07-06 10:16 ` Geert Uytterhoeven
2021-07-06 17:59 ` Linus Walleij
2021-07-06 18:36 ` Miguel Ojeda
2021-07-06 19:12 ` Linus Walleij
2021-07-06 21:32 ` Miguel Ojeda
2021-07-07 14:10 ` Arnd Bergmann
2021-07-07 15:28 ` Miguel Ojeda
2021-07-07 15:50 ` Andrew Lunn
2021-07-07 16:34 ` Miguel Ojeda
2021-07-07 16:55 ` Arnd Bergmann
2021-07-07 17:54 ` Miguel Ojeda
2021-07-06 10:22 ` Leon Romanovsky
2021-07-06 14:30 ` Miguel Ojeda
2021-07-06 14:32 ` Miguel Ojeda
2021-07-06 15:03 ` Sasha Levin
2021-07-06 15:33 ` Miguel Ojeda
2021-07-06 15:42 ` Laurent Pinchart
2021-07-06 16:09 ` Mike Rapoport
2021-07-06 18:29 ` Miguel Ojeda
2021-07-06 18:38 ` Laurent Pinchart
2021-07-06 19:45 ` Steven Rostedt
2021-07-06 19:59 ` Miguel Ojeda
2021-07-06 18:53 ` Sasha Levin
2021-07-06 21:50 ` Miguel Ojeda
2021-07-07 4:57 ` Leon Romanovsky
2021-07-07 13:39 ` Alexandre Belloni
2021-07-07 13:50 ` Miguel Ojeda
2021-07-06 18:26 ` Linus Walleij
2021-07-06 19:11 ` Miguel Ojeda
2021-07-06 19:13 ` Johannes Berg
2021-07-06 19:43 ` Miguel Ojeda
2021-07-06 10:20 ` James Bottomley
2021-07-06 14:55 ` Miguel Ojeda
2021-07-06 15:01 ` Sasha Levin
2021-07-06 15:36 ` Miguel Ojeda
2021-07-09 10:02 ` Marco Elver
2021-07-09 16:02 ` Miguel Ojeda
2021-07-06 18:09 ` Linus Walleij
2021-07-06 14:24 ` Miguel Ojeda
2021-07-06 14:33 ` Laurent Pinchart
2021-07-06 14:56 ` Leon Romanovsky
2021-07-06 15:29 ` Miguel Ojeda
2021-07-07 4:38 ` Leon Romanovsky
2021-07-06 20:00 ` Roland Dreier
2021-07-06 20:36 ` Linus Walleij
2021-07-06 22:00 ` Laurent Pinchart
2021-07-07 7:27 ` Julia Lawall
2021-07-07 7:45 ` Greg KH
2021-07-07 7:52 ` James Bottomley
2021-07-07 13:49 ` Miguel Ojeda
2021-07-07 14:08 ` James Bottomley
2021-07-07 15:15 ` Miguel Ojeda
2021-07-07 15:44 ` Greg KH
2021-07-07 17:01 ` Wedson Almeida Filho
2021-07-07 17:20 ` Greg KH
2021-07-07 19:19 ` Wedson Almeida Filho
2021-07-07 20:38 ` Jan Kara
2021-07-07 23:09 ` Wedson Almeida Filho
2021-07-08 6:11 ` Greg KH
2021-07-08 13:36 ` Wedson Almeida Filho
2021-07-08 18:51 ` Greg KH
2021-07-08 19:31 ` Andy Lutomirski
2021-07-08 19:35 ` Geert Uytterhoeven
2021-07-08 21:56 ` Andy Lutomirski
2021-07-08 19:49 ` Linus Walleij
2021-07-08 20:34 ` Miguel Ojeda
2021-07-08 22:13 ` Linus Walleij
2021-07-09 7:24 ` Geert Uytterhoeven
2021-07-19 12:24 ` Wedson Almeida Filho
2021-07-19 13:15 ` Wedson Almeida Filho
2021-07-19 14:02 ` Arnd Bergmann
2021-07-19 14:13 ` Linus Walleij
2021-07-19 21:32 ` Arnd Bergmann
2021-07-19 21:33 ` Arnd Bergmann
2021-07-20 1:46 ` Miguel Ojeda
2021-07-20 6:43 ` Johannes Berg
2021-07-19 14:43 ` Geert Uytterhoeven
2021-07-19 18:24 ` Miguel Ojeda
2021-07-19 18:47 ` Steven Rostedt
2021-07-19 14:54 ` Miguel Ojeda
2021-07-19 17:32 ` Wedson Almeida Filho
2021-07-19 21:31 ` Arnd Bergmann
2021-07-19 17:37 ` Miguel Ojeda
2021-07-19 16:02 ` Vegard Nossum
2021-07-19 17:45 ` Miguel Ojeda
2021-07-19 17:54 ` Miguel Ojeda
2021-07-19 18:06 ` Wedson Almeida Filho
2021-07-19 19:37 ` Laurent Pinchart
2021-07-19 21:09 ` Wedson Almeida Filho
2021-07-20 23:54 ` Laurent Pinchart
2021-07-21 1:33 ` Andy Lutomirski
2021-07-21 1:42 ` Laurent Pinchart
2021-07-21 13:54 ` Linus Walleij
2021-07-21 14:13 ` Wedson Almeida Filho
2021-07-21 14:19 ` Linus Walleij
2021-07-22 11:33 ` Wedson Almeida Filho
2021-07-23 0:45 ` Linus Walleij
2021-07-21 4:39 ` Wedson Almeida Filho
2021-07-23 1:04 ` Laurent Pinchart
2021-07-21 4:23 ` Wedson Almeida Filho
2021-07-23 1:13 ` Laurent Pinchart
2021-07-19 22:57 ` Alexandre Belloni
2021-07-20 7:15 ` Miguel Ojeda
2021-07-20 9:39 ` Alexandre Belloni [this message]
2021-07-20 12:10 ` Miguel Ojeda
2021-07-19 13:53 ` Linus Walleij
2021-07-19 14:42 ` Wedson Almeida Filho
2021-07-19 22:16 ` Linus Walleij
2021-07-20 1:20 ` Wedson Almeida Filho
2021-07-20 13:21 ` Andrew Lunn
2021-07-20 13:38 ` Miguel Ojeda
2021-07-20 14:04 ` Andrew Lunn
2021-07-20 13:55 ` Greg KH
2021-07-20 1:21 ` Miguel Ojeda
2021-07-20 16:00 ` Mark Brown
2021-07-20 22:42 ` Linus Walleij
2021-07-19 14:43 ` Miguel Ojeda
2021-07-19 15:15 ` Andrew Lunn
2021-07-19 15:43 ` Miguel Ojeda
2021-07-09 7:03 ` Viresh Kumar
2021-07-09 17:06 ` Mark Brown
2021-07-09 17:43 ` Miguel Ojeda
2021-07-10 9:53 ` Jonathan Cameron
2021-07-10 20:09 ` Kees Cook
2021-07-08 13:55 ` Miguel Ojeda
2021-07-08 14:58 ` Greg KH
2021-07-08 15:02 ` Mark Brown
2021-07-08 16:38 ` Andy Lutomirski
2021-07-08 18:01 ` Greg KH
2021-07-08 18:00 ` Miguel Ojeda
2021-07-08 18:44 ` Greg KH
2021-07-08 23:09 ` Miguel Ojeda
2021-07-08 7:20 ` Geert Uytterhoeven
2021-07-08 13:41 ` Wedson Almeida Filho
2021-07-08 13:43 ` Geert Uytterhoeven
2021-07-08 13:54 ` Wedson Almeida Filho
2021-07-08 14:16 ` Geert Uytterhoeven
2021-07-08 14:24 ` Wedson Almeida Filho
2021-07-09 7:04 ` Jerome Glisse
2021-07-08 14:04 ` Miguel Ojeda
2021-07-08 14:18 ` Geert Uytterhoeven
2021-07-08 14:28 ` Miguel Ojeda
2021-07-08 14:33 ` Geert Uytterhoeven
2021-07-08 14:35 ` Miguel Ojeda
2021-07-09 11:55 ` Geert Uytterhoeven
2021-07-08 16:07 ` Andy Lutomirski
2021-07-07 20:58 ` Miguel Ojeda
2021-07-07 21:47 ` Laurent Pinchart
2021-07-07 22:44 ` Miguel Ojeda
2021-07-07 17:01 ` Miguel Ojeda
2021-07-07 10:50 ` Mark Brown
2021-07-07 10:56 ` Julia Lawall
2021-07-07 11:27 ` James Bottomley
2021-07-07 11:34 ` James Bottomley
2021-07-07 12:20 ` Greg KH
2021-07-07 12:38 ` James Bottomley
2021-07-07 12:45 ` Greg KH
2021-07-07 17:17 ` Laurent Pinchart
2021-07-08 6:49 ` cdev/devm_* issues (was Re: [TECH TOPIC] Rust for Linux) Greg KH
2021-07-08 8:23 ` Laurent Pinchart
2021-07-08 23:06 ` Linus Walleij
2021-07-09 0:02 ` Dan Williams
2021-07-09 16:53 ` Wedson Almeida Filho
2021-07-13 8:59 ` Linus Walleij
2021-07-13 8:59 ` Linus Walleij
[not found] ` <CAHp75VfW7PxAyU=eYPNWFU_oUY=aStz-4W5gX87KSo402YhMXQ@mail.gmail.com>
2021-07-21 13:46 ` Linus Walleij
2021-07-21 13:46 ` Linus Walleij
2021-07-21 15:49 ` Andy Shevchenko
2021-07-21 15:49 ` Andy Shevchenko
2021-07-10 7:09 ` Dan Carpenter
2021-07-12 13:42 ` Jason Gunthorpe
2021-07-15 9:54 ` Daniel Vetter
2021-07-21 9:08 ` Dan Carpenter
2021-07-22 9:56 ` Daniel Vetter
2021-07-22 10:09 ` Dan Carpenter
2021-07-08 9:08 ` [TECH TOPIC] Rust for Linux Mauro Carvalho Chehab
2021-07-10 16:42 ` Laurent Pinchart
2021-07-10 17:18 ` Andy Lutomirski
2021-07-07 15:17 ` Mark Brown
2021-07-06 21:45 ` Bart Van Assche
2021-07-06 23:08 ` Stephen Hemminger
2021-07-07 2:41 ` Bart Van Assche
2021-07-07 18:57 ` Linus Torvalds
2021-07-07 20:32 ` Bart Van Assche
2021-07-07 20:39 ` Linus Torvalds
2021-07-07 21:40 ` Laurent Pinchart
2021-07-08 7:22 ` Geert Uytterhoeven
2021-07-07 21:02 ` Laurent Pinchart
2021-07-07 22:11 ` Miguel Ojeda
2021-07-07 22:43 ` Laurent Pinchart
2021-07-07 23:21 ` Miguel Ojeda
2021-07-07 23:40 ` Laurent Pinchart
2021-07-08 0:27 ` Miguel Ojeda
2021-07-08 0:56 ` Laurent Pinchart
2021-07-08 6:26 ` Alexey Dobriyan
2021-07-06 19:05 ` Bart Van Assche
2021-07-06 19:27 ` Miguel Ojeda
2021-07-07 15:48 ` Steven Rostedt
2021-07-07 16:44 ` Miguel Ojeda
2023-08-07 10:03 Miguel Ojeda
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=YPaZ4zTZHOQfBhOk@piout.net \
--to=alexandre.belloni@bootlin.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=bgolaszewski@baylibre.com \
--cc=greg@kroah.com \
--cc=jack@suse.cz \
--cc=julia.lawall@inria.fr \
--cc=keescook@chromium.org \
--cc=ksummit@lists.linux.dev \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linus.walleij@linaro.org \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=roland@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=wedsonaf@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.