-
Notifications
You must be signed in to change notification settings - Fork 48
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
Locking strategy for scheduler #242
Comments
I feel that p. 133 of FreeBSD book has a comment that somehow is related to this issue:
|
https://lists.freebsd.org/pipermail/freebsd-arch/2013-September/014794.html
|
Another useful source: "Solaris™ Internals: Solaris 10 and OpenSolaris Kernel Architecture", Second Edition, chapter 3.4:
|
After spending a few hours reading FreeBSD sources I wasn't able to figure out what is happening to
td_lock
and what are the interactions between 4BSD scheduler and threads.Same parts of NetBSD kernel seems to be implemented in cleaner way. Additionally I was able to find some extensive in-code documentation about locking strategy. I post my findings here...
Having a first look at
l_mutex
andtd_lock
field it is not apparent why it's a pointer. Rather shocking fact tells that over the life of a thread the pointer changes frequently! Long comment in kern_lwp.c tries to shed some light on it.Seems like
l_mutex
may point tospc_mutex
andspc_lwplock
, which are both constituent of schedstate_percpu. When a thread is created by lwp_create itsl_mutex
field gets initialized tospc_lwplock
. Note, that scheduler and thread related code is littered withKASSERT(mutex_owned(l->l_mutex))
check. There are special routines to obtain and releasel_mutex
lock – namely lwp_lock, lwp_unlock, lwp_setlock and lwp_unlock_to.According to in-code documentation the locking order is
spc::spc_lwplock > sleeptab::st_mutex > tschain_t::tc_mutex > spc::spc_mutex
.... more to come, stay tuned.
The text was updated successfully, but these errors were encountered: