-
-
Notifications
You must be signed in to change notification settings - Fork 370
Make multi-threading a feature #3237
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
Conversation
@wfdewith Any thoughts? |
libafl_qemu/librasan/asan/Cargo.toml
Outdated
@@ -42,6 +43,10 @@ libc = ["dep:libc"] | |||
linux = ["dep:rustix"] | |||
## Enable the `baby_mimalloc` allocator | |||
mimalloc = ["dep:baby-mimalloc"] | |||
## Support multi-threaded targets by using real synchronization primitives | |||
multi-threaded = ["dep:spin"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be default
## Support multi-threaded targets by using real synchronization primitives | ||
multi-threaded = ["dep:spin"] | ||
## Support single-threaded targets by using dummy synchronization primitives | ||
single-threaded = ["dep:nospin"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe-single-threaded
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe actually just make this a feature and have the other not be a feature? Or just make threadsafe
a feature, and leave the other one default. In rust features should be additive if possible
You could also take a look at the Probably quite a bit more work though |
I agree with @domenukk on creating one feature for However, I'm going to be annoying again and ask if this really improves performance measurably. The reason I'm asking is that mutexes typically try opportunistically lock before falling back to a more expensive syscall, or in the case of |
There are still some atomics so the cores cannot run free - if you know that your target is single threaded there's not really any reason to pay for the potential overhead (think 128 cores at 100% etc) .. however measurements for this on real world software are always nice to have, if it's only a few nano seconds extra, why bother |
I do agree that the atomics have overhead, but consider that this code will only run in QEMU. Since QEMU JITs instructions during execution (except in system mode with KVM acceleration enabled), it can optimize memory barriers out during runtime if it is running in single-threaded context. Looking at the source and documentation here and here, that is exactly what QEMU does. |
Cool. I didn't know it did that. Obviously the oppotunistic locking would otherwise still have a cache coherency overhead. I'm running |
Also interestingly, if a process creates a second thread, then the TCG is flushed. That could cause performance overhead for fork-server implementations? |
CC @rmalmain |
Seems we don't benefit from QEMU dropping the memory barriers right now as the process is multi threaded (that needs investigating). But the PR may still be useful if librasan is to be reused in FRIDA, or otherwise outside of QEMU. |
Seems if the process makes any shared mappings, then the optimizations have to be disabled too (which make sense). https://github.com/qemu/qemu/blob/757a34115e7491744a63dfc3d291fd1de5297ee2/linux-user/mmap.c#L1011. So this optimization still stands as presumable this is how the fuzzing process communicates with the fuzzer itself? |
Well spotted! Only remaining question for me then is what the overhead of the single atomic operation in |
I'd expect that it must be noticeable, otherwise, QEMU wouldn't have gone to the effort of removing them either. I'd expect it would be worse as you run more parallel instances? |
I'm not sure this adds much performance, so I'll close it for now. |
Description
Add
single-threaded
andmulti-threaded
configuration options tolibrasan
to switch out the use of thespin
crate for synchronization for the newly creatednospin
crate (which doesn't provide any thread safety).Checklist
./scripts/precommit.sh
and addressed all comments