-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rust/kernel: remove config #ifdef
in Error.rs file
#346
Conversation
This comment has been minimized.
This comment has been minimized.
8cd2ce8
to
8fa8ce4
Compare
This comment has been minimized.
This comment has been minimized.
Good idea to defer to the C function! However, note that conditional compilation is not deprecated -- Greg is saying it should be avoided in Also note that [*] Which is actually badly worded in |
Absolutely, conditional compilation is unavoidable in, say. So should I reword the commit message from "deprecated" to "should be avoided"? PS There's another conditional compilation in linux/rust/kernel/sync/mutex.rs Lines 83 to 93 in 0b9bcdf
What's your opinion on that one? People are going to say "performance", but do we have any data to back that up? Premature optimization etc :) |
Yeah, please! Or just remove that line -- simplifying conditional compilation is always a good idea even without further arguments.
In general, unless we have proof of bad performance, please prefer simplicity. In particular, for this case, I would simplify that one too. Performance should be the same, because both calls are black boxes without cross-language LTO (and with it, it should not matter). But I let @wedsonaf comment in case I am missing something -- he can easily test & compare (he has some benchmarks for Rust Binder). |
It's a shame that bindgen can't handle static inline functions and c2rust can't handle macros :( It would save us a lot hassle if we can just call into static inline functions. |
The use of `#ifdef CONFIG_` statements in .c/.rs files should be avoided: it makes the code much more unmaintainable over time. See: https://lore.kernel.org/lkml/YLjWKwhp7akqyR1S@kroah.com/ Use a Rust-C helper instead to leverage automatic `CONFIG` selection in C kernel headers. Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
8fa8ce4
to
40676ff
Compare
Review of
|
v1 -> v2ojeda:
|
Idea: can we do some text processing, e.g. look into E.g. add these only if helper_generated.c const char *rust_helper_errname(int err)
{
return errname(err);
} binding_helper_generated.rs extern "C" {
#[link_name = "rust_helper_errname"]
fn errname(err: c_types::c_int) -> *const c_types::c_char;
} |
Won't this issue go away on its own, once we can build the kernel with ThinLTO? This is already possible in I tried to merge |
There are two issues with current approach, one is usability and one is performance:
|
Sure, I will work on updating the repo to the latest |
Good point. Should we move that discussion to a separate Issue or PR ? |
Sounds good to me. |
Done: #352 |
Yes, I like this as a general guideline: let's choose simplicity unless there's a regression in a metric we care about; performance improvements that complicate the design/implementation should be justified with an improved metric we care about.
Oddly enough, #357 seems to have improved performance. The following is a ping test: it sends transaction to a server and waits for a response; the server just responds as soon as it can to any transactions it gets. The tests repeats this 1M times and measures how long it takes. Before #357:
After #357:
I'm converting my binder tests to kernel selftests, I'll convert this one as well so others can also run it. |
Definitely odd, and quite consistent and significant (~5%).
🎉 |
💯
🥇 |
By the way, now that #361 is in, we could write In any case, I want to have a way to perform benchmarks that looks as simple as |
👍 It's crucially important to be able to run benchmarks or self-tests on platforms such as Raspberry Pi etc. It would be awesome if there was a way to accomplish this via a |
Well, if you run But yeah, I want to have something like |
On nightly you can use |
@wedsonaf Does your benchmark kernel have |
No, the following is the "lock debugging" section of my
The test is actually quite simple. Let me upload it as is so you can try it out if you'd like. |
The test is here: wedsonaf@76001a4 You can build as follows (from the kernel git root):
To run the test, first you need to run the server as follows:
And leave it running. Then you can ran the client as many times as need:
In both cases, |
I'm having some issues with the benchmark, created a separate issue #365 |
Sounds like an issue where a mutex is highly concurrently accessed, and slowing down I tried to run the benchmark myself but ran into |
Ah, then it can be easier than expected! Thanks! I will take a look. |
So I've tried the benchmark with cycle-level simulation in RISC-V, with and without #357, here's the result (3 runs, averaged, all in seconds):
So for my configuration, #357 does regress performance (but very tiny). A more interesting result is that performance improves when I reduce core count to just 1 as I expected. I wonder if any of you can reproduce the result? |
To know if differences as tiny as that are meaningful (as opposed to mere noise), we probably need multiple samples, combined with a statistical test for equal means. |
The runs are all in cycle-level simulation and there are no external noises. The standard deviation are quite small, and two-sample unpaired t test gives P value of 0.03 (for 1 core case), so the result is statistically significant. |
Thanks! It's awesome to determine that properly ! @wedsonaf on what platform did you observe the 5% speedup, x86? |
Yes, x86-64 running on KVM with a single core, so external factors may have influenced the result. I can try again tomorrow. (I had never seen the benchmark run below 10s before today, though I hadn't run it in a while...) |
On my arm32 system (cortex-a9) #357 seems to make no difference. Everything is a factor 20 slower (!) than what you guys are observing on your systems. So I'll rebuild the ping client/server with (ETA: |
I tweaked the number of iterations, and it happens (by pure luck) to be roughly 10 seconds :) |
I ran again, still see an improvement: At commit 5bb76a6:
At 5bb76a6 + revert of a8553d8:
I'm attaching my |
Can you try with |
I don't think we should be surprised by changes that affect platforms unequally. Or even in the opposite direction :) Not sure why adding a |
Without KMEMLEAK, I do see a regression: At commit 5bb76a6 (average 4.6901051054):
At 5bb76a6 + revert of a8553d8 (average 4.4586401322):
KMEMLEAK has quite an impact on this benchmark... |
Edited: nevermind |
Regression from 5.055406773 to 5.1458177946. Slower than with CONFIG_PREEMPT_VOLUNTARY. |
So what's the conclusion here? Is the regression not acceptable? If not, how do we fix? Would ThinLTO be preferable to reverting the PR? |
I don't think we should revert that. #359 can resolve the issue without using I think the only conclusion we can make currently is that binder benchmark isn't a reliable indicator for other changes, and we probably need a more deterministic (sequential) benchmark. |
It would be good to do a test with ThinLTO too. Let me update the kernel today. |
Mainline supports ThinLTO on x86 and arm64 only. So no arm 32-bit or RISC-V support for myself or Gary for now... |
Add a test case to assert that the skb->pkt_type which was set from the BPF program is retained from the netkit xmit side to the peer's device at tcx ingress location. # ./vmtest.sh -- ./test_progs -t netkit [...] ./test_progs -t netkit [ 1.140780] bpf_testmod: loading out-of-tree module taints kernel. [ 1.141127] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel [ 1.284601] tsc: Refined TSC clocksource calibration: 3408.006 MHz [ 1.286672] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x311fd9b189d, max_idle_ns: 440795225691 ns [ 1.290384] clocksource: Switched to clocksource tsc #345 tc_netkit_basic:OK #346 tc_netkit_device:OK #347 tc_netkit_multi_links:OK #348 tc_netkit_multi_opts:OK #349 tc_netkit_neigh_links:OK #350 tc_netkit_pkt_type:OK Summary: 6/0 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20240524163619.26001-4-daniel@iogearbox.net Signed-off-by: Alexei Starovoitov <ast@kernel.org>
The use of
#ifdef CONFIG_
statements in .c/.rs files is deprecated:it makes the code much more unmaintainable over time. See:
https://lkml.org/lkml/2021/6/3/564
Use a Rust-C helper instead to leverage automatic
CONFIG
selectionin C kernel headers.
Signed-off-by: Sven Van Asbroeck thesven73@gmail.com