Originally posted by cl333r
View Post
Announcement
Collapse
No announcement yet.
LPC 2022: Rust Linux Drivers Capable Of Achieving Performance Comparable To C Code
Collapse
X
-
- Likes 5
-
Originally posted by jacob View Post
Many people seem to believe that safe code is somehow detrimental to performance or that a lower level language allows for some performance-improving "hacks". That's not necessarily true at all. A strong type system, together with borrow checking, lifetime analysis etc. can enable the compiler to perform some optimisations that are not readily feasible in C, like implicit destructuring, memory access reordering etc. Back when C was created, the primary goal was not performance but the ease to write and/or port a compiler. There was basically a 1-to-1 match between a C source code and the generated assembly, which in turn had a 1-to-1 match to the operations actually performed by the CPU. But this is a very different world, with complex out-of-order execution, register renaming, non-intuitive memory consistency models, hardware multithreading, SIMD and/or variable length vector instructions that we would like the compiler to take advantage of automatically as appropriate, etc. In this context, a more abstract language is a performance benefit, not a hindrance.
Also, as the Rust compiler has taught me, safe code isn't even always about checks, it can be about writing the damn thing correctly.
Edit: About C being about 1:1 match with assembly, that also had to do with what could be proven at the time to be correct code. I mean, with all the modern features you mentioned, can you confidently run gcc -O3? You can't, because nobody was ever able to proven the output of that is mathematically correct.Last edited by bug77; 13 September 2022, 06:49 PM.
- Likes 1
Leave a comment:
-
Originally posted by bug77 View Post
It's hard to tell. On one hand, you can concentrate on performance more if you spend less time checking memory management. But on the other hand, C's "unsafety" may allow for some interesting hack wrt performance.
I think I'm with you when I say I expect performance in the same ballpark for a few more years. After that, yes, maybe Rust can pull some rabbits out of its hat.
- Likes 3
Leave a comment:
-
Originally posted by MowKow View Post
Well said, but atm I still prefer the added flexibility C++ offers me, especially templates and other compile time abstractions
concerning memory safety:
virtually all issues I'm running into are due to having to interface into C APIs using raw pointers, so Rust really won't help me there
But once again, there are experienced C or C++ programmers out there that can produce good code without too much effort. Nobody expects them ti give that up and move to the Rust side. But now there are three choices when you want to learn systems programming: C, C++ and Rust. Most newcomers will flock to Rust, simply because it's more modern.
- Likes 2
Leave a comment:
-
Jesus Christ, I noticed you know (almost?) everything and be up-to-date with everything, are you a robot or what?
Leave a comment:
-
Originally posted by bug77 View Post
Exactly. The discussion should not be centered around performance, it should be about time-to-market. How long does it take to write (and fix) C vs Rust code. That is where C leaves you hanging while Rust's compiler bends over backwards for you.
Rust has more time spent making it compile (though it takes less and less time as the developer becomes more seasoned) but much more time saved in the testing phase and in deployment issues.
- Likes 3
Leave a comment:
-
Originally posted by Developer12 View Post
Don't get me wrong: there will also be performance *benefits* to using rust over C.
But it's going to take a fair bit longer for that particular advantage to materialize. Lots of compiler bugs to fix and infrastructure to build.
I think I'm with you when I say I expect performance in the same ballpark for a few more years. After that, yes, maybe Rust can pull some rabbits out of its hat.
Leave a comment:
-
Originally posted by bug77 View Post
Exactly. The discussion should not be centered around performance, it should be about time-to-market. How long does it take to write (and fix) C vs Rust code. That is where C leaves you hanging while Rust's compiler bends over backwards for you.
But it's going to take a fair bit longer for that particular advantage to materialize. Lots of compiler bugs to fix and infrastructure to build.Last edited by Developer12; 13 September 2022, 09:29 AM.
- Likes 1
Leave a comment:
-
Originally posted by EvilHowl View PostLinus tried C++ once 30 years ago and he decided C++ is a very bad language for kernels. He might have been right then, but things have changed a lot over the last three decades. No, nobody is going to use any runtime features in a kernel, such as exceptions, virtual functions or dynamic casts.
But still, there are many features of modern C++ that would come in handy on kernel development that will make the mantainers' lifes way easier. There are many open source operating systems (like SerenityOS) that make use of C++ features on their kernels, like the improved type safety over C, namespaces, constructors, templates (those shady and type unsafe macros should have been long gone in any kernel nowadays), RAII (the best C++ feature in my honest opinion) and they are more than happy with C++.
I don't think they are doing things wrong by using C++, like Linus once said. Should they be using pure and inmaculate C89, like Linux until a few months ago? If Rust code is accepted, modern C++ code should be as well.
Linux kernel has been C89 + Sparse extras for quite some time. Migrating to C11 means not having to implement more checking features in Sparse. Do note Linus Torvalds wrote sparse in 2003.
Migrating to C++ does not cover the issues that sparse detects. So C++ you would have to implement C++ version of sparse. Welcome to hell.
Interesting enough rust developers slide page 61
Is worth a note.
Note that direct going from rust code to Linux kernel code is totally forbid. So in the rust crate there can be sparse rules to make sure you code is not doing anything known to be stupid.
Please note sparse is also just the tip of iceberg here. You have Linux kernel added gcc plugins that check for Linux kernel known issue as well.
The Linux kernel uses a highly extended version of C. Lot of the features you say are good in C++ makes processing all the extra language limitation rules that the Linux kernel developers have added massively harder to get the same result.
- Likes 3
Leave a comment:
-
Originally posted by EvilHowl View Post...
But still, there are many features of modern C++ that would come in handy on kernel development that will make the mantainers' lifes way easier. There are many open source operating systems (like SerenityOS) that make use of C++ features on their kernels, like the improved type safety over C, namespaces, constructors, templates (those shady and type unsafe macros should have been long gone in any kernel nowadays), RAII (the best C++ feature in my honest opinion) and they are more than happy with C++.
I don't think they are doing things wrong by using C++, like Linus once said. Should they be using pure and inmaculate C89, like Linux until a few months ago? If Rust code is accepted, modern C++ code should be as well.
C++ is an incremental change, Rust is a fundamental rearrangement of priorities.Last edited by zcansi; 13 September 2022, 07:40 AM.
- Likes 10
Leave a comment:
Leave a comment: