Subject: nesting simple_lock and spl*?
To: None <tech-kern@netbsd.org>
From: Konrad Schroder <perseant@hhhh.org>
List: tech-kern
Date: 05/23/2002 12:11:03
What is the rule of thumb with regard to spl*() (in my case splbio()) in
conjunction with simple_lock()? Must they be nested, and if so in what
order?
For example, I have a pending change to vrele which (I think) should look
like this:
s = splbio();
simple_lock(&vp->v_interlock);
vp->v_usecount--;
if (vp->v_usecount > 0) {
simple_unlock(&vp->v_interlock);
splx(s);
return;
}
simple_lock(&vnode_free_list_slock);
if (vp->v_holdcnt > 0)
TAILQ_INSERT_TAIL(&vnode_hold_list, vp, v_freelist);
else
TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
simple_unlock(&vnode_free_list_slock);
splx(s);
The purpose of the change is that "v_usecount--" and the tailq insertion
need to be atomic vis-a-vis disk interrupts. Given that the section under
splbio() has to interact with the simple_lock()s, is this the best way to
do this, or might
simple_lock(&vp->v_interlock);
s = splbio();
vp->v_usecount--;
if (vp->v_usecount > 0) {
simple_unlock(&vp->v_interlock);
splx(s);
return;
}
simple_lock(&vnode_free_list_slock);
if (vp->v_holdcnt > 0)
TAILQ_INSERT_TAIL(&vnode_hold_list, vp, v_freelist);
else
TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
splx(s);
simple_unlock(&vnode_free_list_slock);
be as good?
Thanks,
Konrad Schroder
perseant@hhhh.org