简体   繁体   中英

mutex owner in SMP linux

In the kernel implementation of mutex, thread owner field exists only if it is a SMP build. I can understand that under good and clean code a thread will call release only if acquire was successful so we can save some cache and cpu cycles by not keeping track of the thread. But then why does SMP require it ? Is it because in SMP the mutex is hybrid and spins while the thread owner is on another cpu and requires this field for the reference or are there more reasons behind it ?

Honestly, I don't remember linux kernel mutex implementation now, but I see at least three reasons to store mutex owner directly in the data structure:

  1. For debugging. It's easy to detect an owner from the kernel crash dump
  2. For runtime assertions. It becomes dead easy to detect an attempt to acquire the mutex you've already acquired.
  3. For implementation of priority inheritance protocol or any other mechanism that resolves priority inversion problem: http://en.wikipedia.org/wiki/Priority_inversion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM