4 ms·
Isn't it nonsense to do this in user-space? Your thread can get preempted at any moment.
by inshadows 5y ago
Isn't it nonsense to do this in user-space? Your thread can get preempted at any moment.
- dataflow 5y agoCan happen at any moment != will happen most of the time
- inshadows 5y agoPreemption sure is non-deterministic from POV of the thread. But what's the point of it anyway? It's not like you handle HW interrupts in user-space and need to wait for some value in memory mapped register.
- Kranar 5y agoIt absolutely is, which is why the benchmarks posted should not be taken seriously. Some environments don't have a scheduler or a "user-space", and so this implementation can suffice, but the problem with this post is that all of the testing and benchmarking are done in user-space, and hence the metrics are not very meaningful.
- tialaramex 5y agoIt's a micro-benchmark. "Everybody" can write a faster lock that wins on a micro-benchmark they built, and I guess if your goal is to feel smug then you're all done. If you actually have a performance problem, you need to benchmark the entire system that isn't performing as well as you'd like, then try to distil a small element you can optimise, micro-benchmark that, improve it using your micro-benchmark to measure progress, then apply the improvement to the large system, and then finally benchmark the larger system again to discover if the changes paid off. This will be much more time-consuming, but if you don't do this work then you're probably just masturbating. The larger system might be Twitter, or Hacker News, or Binding of Isaac, or a SatNav, but the performance of those larger things is what matters, if you micro-optimise your spinlock to be 5% better but now Hacker News falls over with half as many simultaneous users, you made it worse not better.
- DSingularity 5y agoNo. You can configure the kernel run with a different scheduling policy and pretty much prevent preemption. You can even move IO interrupt handlers to other cores to really ensure you have the core.
- inshadows 5y agoOK. And who does that, when and why? Can you point to some practical REAL (= existing) examples?
- spacechild1 5y agoIn general, multi-threaded realtime audio software. Example: https://github.com/supercollider/supercollider/tree/develop/server/supernova https://github.com/supercollider/supercollider/tree/develop/...
- DSingularity 5y agoAnother example are OS-bypassing workloads which are tail-latency sensitive. They will prefer to avoid any OS involvement and take charge of everything in user space.
- detaro 5y agoI've seen things like that in industrial control systems. I think some high-performance networking setups also do things like that, doing almost everything in user-space, actively polling for packets from the hardware.
- anarazel 5y agoIt depends. In a general purpose OS without scheduler trickery one would need at least some backoff & yielding syscall. And it's hugely workload dependent. But more importantly, even with kernel backed waiting (e.g. using futexes) some userspace spinning can be important for performance. And then pretty much all the concerns from the spinlock apply there as well.
- rigtorp 5y agoIt's nonsense to do this when you can be preempted. But you can run one thread per core and avoid preemption. You can tune the linux kernel to avoid almost all preemption, due to TLB shootdowns etc: https://rigtorp.se/low-latency-guide/ https://rigtorp.se/low-latency-guide/