Hacker Newsnew | past | comments | ask | show | jobs | submit | dalvrosa's commentslogin

Fair enough yeah. IMO microbenchmarks are useful for trying to gain intuition and propose the next incremental improvement. In real world measuring is mandatory, if you don't want to risk pessimizing the code

The wild thing about locks in particular is that microbenchmarks will cause you to make „optimizations” that are the opposite of what benefits real world workloads.

Very good point, should add this

Yeah that's quite right, you shouldn't be using spinlock without pinned threads

Thanks for sharing! Happy to get feedback :)

Note that I don't recommend spinlock for most cases, only when there is a 1:1 mapping between threads and phsycal CPU cores, and only after measuring


Thanks for sharing! Happy to get feedback :)

Note that I don't recommend spinlock for most cases, only when there is a 1:1 mapping between threads and phsycal CPU cores, and only after measuring


Thanks for sharing! Happy to get feedback :)

Note that I don't recommend spinlock for most cases, only when there is a 1:1 mapping between threads and phsycal CPU cores, and only after measuring


Thanks for sharing! Happy to get feedback :)

Note that I don't recommend spinlock for most cases, only when there is a 1:1 mapping between threads and phsycal CPU cores, and only after measuring


Spinlocks are unsuitable for situations where you can be involuntarily context switched (the vast majority of userspace programs). Probably worth mentioning that.

Unsuitable? Probably depends on your use case. Even a normal end user system shouldn't constantly kick your threads out unless it has enough other things to do to to keep every core busy.

> unless it has enough other things to do to to keep every core busy.

And in this all-cores-busy case, do you want your waiters burning one of those precious cores while lock holders are preempted? If you care enough about your system design to even affirmatively select spinlocks in the first place, you should probably also care enough to not use them in preemptible userspace. Or at least, I am not aware of any reasonable usecase. Hybrid sleeplocks are fine, of course.



Love it


Thanks!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: