On 7/14/25 06:54, Dave Hansen wrote: > On 7/14/25 00:35, Reshetova, Elena wrote: >> I think you put it: this would require a spinlock in the fast path and >> *in theory* if we are running many many concurrent enclaves can create >> contention > FWIW, my mental model is that spinlocks that are held for short periods > of time are pretty much the same cost as an atomic under contention. > > If there are lots of users, the cost of moving the cacheline for the > atomic or the spinlock dominates everything else. It doesn't matter > whether that cacheline is an atomic_t or spinlock_t. > > The only difference is that there is _visible_ spinning for a spinlock.
Oh, and I had a brain fart on this one. You've got a mutex, not a spinlock. But the concept still applies: for small critical sections, the cost of moving the cacheline dominates the cost of everything else, no matter if it's a mutex, spinlock or atomic. Never add complexity unless you're getting actual, real-world performance out of it. In this case, the only thing you'd _maybe_ improve with added complexity is an open()/close() loop on /dev/sgx, which is completely unrealistic.

