Prio ceiling mutex issues
Hi Philippe,
we ran into at least one bug of the current prio ceiling support for synch objects: on xnsynch_release, we only reschedule if we woken up a new owner. But we also have to reschedule after dropping the ceiling prio as some higher prio thread may be waiting.
For that, I would propose to alter the return type and semantic of xnsynch_release from "pointer to new owner" into "bool, true if reschedule is needed". It seems, no caller of xnsynch_release makes a non-boolean use of the return value anyway. And then we can simply return true on "synch->status & XNSYNCH_PP".
That leads to the question what would happen in the fast case. Consider
pthread_mutex_lock(ceiling_mutex); wake_up_thread(some_thread); // caller_prio < target_prio < ceiling_prio pthread_mutex_unlock(ceiling_mutex);
To my current understanding, there is nothing enforcing a syscall for the unlock caller if some thread woke up after the lock, thus may have a high prio after the unlock. Or am I missing something?
Thanks,
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 15 lines · Jan Kiszka
Hi Philippe,
we ran into at least one bug of the current prio ceiling support for synch objects: on
xnsynch_release, we only reschedule if we woken up a new owner. But we also have to reschedule after dropping the ceiling prio as some higher prio thread may be waiting.For that, I would propose to alter the return type and semantic of
xnsynch_releasefrom "pointer to new owner" into "bool, true if reschedule is needed". It seems, no caller ofxnsynch_releasemakes a non-boolean use of the return value anyway. And then we can simply return true on "synch->status&XNSYNCH_PP".That leads to the question what would happen in the fast case. Consider
Quoted 7 lines
pthread_mutex_lock(ceiling_mutex);wake_up_thread(some_thread); //caller_prio<target_prio<ceiling_priopthread_mutex_unlock(ceiling_mutex);To my current understanding, there is nothing enforcing a syscall for the unlock caller if some thread woke up after the lock, thus may have a high prio after the unlock. Or am I missing something?
OK, I think I got it: When we found a reason to reschedule after taking such a ceiling lock lazily, we commit the prio-boost and enforce the kernel exit on release via xnsynch_fast_ceiling in commit_ceiling, right? Then we only need to fix the above scheduling issue and are fine. I'll quickly hack up some patches for discussion.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 20 lines · Jan Kiszka
Quoted 19 lines · Jan Kiszka
Hi Philippe,
we ran into at least one bug of the current prio ceiling support for synch objects: on
xnsynch_release, we only reschedule if we woken up a new owner. But we also have to reschedule after dropping the ceiling prio as some higher prio thread may be waiting.For that, I would propose to alter the return type and semantic of
xnsynch_releasefrom "pointer to new owner" into "bool, true if reschedule is needed". It seems, no caller ofxnsynch_releasemakes a non-boolean use of the return value anyway. And then we can simply return true on "synch->status&XNSYNCH_PP".That leads to the question what would happen in the fast case. Consider
pthread_mutex_lock(ceiling_mutex);wake_up_thread(some_thread); //caller_prio<target_prio<ceiling_priopthread_mutex_unlock(ceiling_mutex);
Quoted 8 lines
Quoted 3 lines
To my current understanding, there is nothing enforcing a syscall for the unlock caller if some thread woke up after the lock, thus may have a high prio after the unlock. Or am I missing something?
OK, I think I got it: When we found a reason to reschedule after taking such a ceiling lock lazily, we commit the prio-boost and enforce the kernel exit on release via
xnsynch_fast_ceilingincommit_ceiling, right?
Correct (at the very least this is the intent of the implementation).
Signature · 1 line
Philippe.
Quoted 25 lines · Philippe Gerum
Quoted 24 lines · Jan Kiszka
Quoted 22 lines · Jan Kiszka
Hi Philippe,
we ran into at least one bug of the current prio ceiling support for synch objects: on
xnsynch_release, we only reschedule if we woken up a new owner. But we also have to reschedule after dropping the ceiling prio as some higher prio thread may be waiting.For that, I would propose to alter the return type and semantic of
xnsynch_releasefrom "pointer to new owner" into "bool, true if reschedule is needed". It seems, no caller ofxnsynch_releasemakes a non-boolean use of the return value anyway. And then we can simply return true on "synch->status&XNSYNCH_PP".That leads to the question what would happen in the fast case. Consider
pthread_mutex_lock(ceiling_mutex);wake_up_thread(some_thread); //caller_prio<target_prio<ceiling_priopthread_mutex_unlock(ceiling_mutex);To my current understanding, there is nothing enforcing a syscall for the unlock caller if some thread woke up after the lock, thus may have a high prio after the unlock. Or am I missing something?
Quoted 7 lines
Quoted 4 lines
OK, I think I got it: When we found a reason to reschedule after taking such a ceiling lock lazily, we commit the prio-boost and enforce the kernel exit on release via
xnsynch_fast_ceilingincommit_ceiling, right?Correct (at the very least this is the intent of the implementation).
Good... I pushed the two patches I have in mind, but both lack testing beyond "builds for me". I will let them run to our scenario tomorrow unless you see a problem.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 7 lines · Jan Kiszka
Hi Philippe,
we ran into at least one bug of the current prio ceiling support for synch objects: on
xnsynch_release, we only reschedule if we woken up a new owner. But we also have to reschedule after dropping the ceiling prio as some higher prio thread may be waiting.
Quoted 5 lines
For that, I would propose to alter the return type and semantic of
xnsynch_releasefrom "pointer to new owner" into "bool, true if reschedule is needed". It seems, no caller ofxnsynch_releasemakes a non-boolean use of the return value anyway. And then we can simply return true on "synch->status&XNSYNCH_PP".
I agree, but we need to keep the next owner check in the boolean status. Something like this would do I believe:
kernel/cobalt/synch.c +8 -6
@@ -913,10 +913,10 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch,* * @coretags{primary-only, might-switch} */ -struct xnthread *xnsynch_release (struct xnsynch *synch, -struct xnthread *curr) +static bool xnsynch_release (struct xnsynch *synch, +struct xnthread *curr) { -struct xnthread *nextowner =NULL ; +bool resched = false;xnhandle_t currh, h;atomic_t *lockp;spl_t s;
@@ -946,16 +946,18 @@ struct xnthread *xnsynch_release(struct xnsynch *synch, h =atomic_cmpxchg (lockp, currh,XN_NO_HANDLE );if ((h & ~XNSYNCH_FLCEIL ) != currh)/* FLCLAIM set, synch is contended. */ - nextowner =transfer_ownership (synch, curr); + resched =transfer_ownership (synch, curr) !=NULL ;else if (h != currh)/* FLCEIL set, FLCLAIM clear. */ atomic_set (lockp,XN_NO_HANDLE ); -if (synch->status &XNSYNCH_PP ) +if (synch->status &XNSYNCH_PP ) {clear_pp_boost (synch, curr); + resched = true; + }xnlock_put_irqrestore (&nklock, s); -return nextowner; +return resched; }EXPORT_SYMBOL_GPL (xnsynch_release);
Signature · 1 line
Philippe.
Quoted 47 lines · Philippe Gerum
Quoted 7 lines · Jan Kiszka
Hi Philippe,
we ran into at least one bug of the current prio ceiling support for synch objects: on
xnsynch_release, we only reschedule if we woken up a new owner. But we also have to reschedule after dropping the ceiling prio as some higher prio thread may be waiting.Quoted 5 lines
For that, I would propose to alter the return type and semantic of
xnsynch_releasefrom "pointer to new owner" into "bool, true if reschedule is needed". It seems, no caller ofxnsynch_releasemakes a non-boolean use of the return value anyway. And then we can simply return true on "synch->status&XNSYNCH_PP".I agree, but we need to keep the next owner check in the boolean status. Something like this would do I believe:
kernel/cobalt/synch.c +5
-5@@ -913,10 +913,10 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch,* * @coretags{primary-only, might-switch} */ -struct xnthread *xnsynch_release (struct xnsynch *synch, -struct xnthread *curr) +static bool xnsynch_release (struct xnsynch *synch, +struct xnthread *curr) { -struct xnthread *nextowner =NULL ; +bool resched = false;xnhandle_t currh, h;atomic_t *lockp;spl_t s;@@ -946,16 +946,18 @@ struct xnthread *xnsynch_release(struct xnsynch *synch, h =atomic_cmpxchg (lockp, currh,XN_NO_HANDLE );if ((h & ~XNSYNCH_FLCEIL ) != currh)/* FLCLAIM set, synch is contended. */ - nextowner =transfer_ownership (synch, curr); + resched =transfer_ownership (synch, curr) !=NULL ;else if (h != currh)/* FLCEIL set, FLCLAIM clear. */ atomic_set (lockp,XN_NO_HANDLE ); -if (synch->status &XNSYNCH_PP ) +if (synch->status &XNSYNCH_PP ) {clear_pp_boost (synch, curr);
kernel/cobalt/synch.c struct xnthread *xnsynch_release(struct xnsynch *synch, · line 963
Quoted 10 lines
kernel/cobalt/synch.c +3
-1+ resched = true; + }xnlock_put_irqrestore (&nklock, s); -return nextowner; +return resched; }EXPORT_SYMBOL_GPL (xnsynch_release);
OK, I didn't use bool (will change that), but otherwise did the same with that two patches in for-forge. Or what do you mean?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 52 lines · Jan Kiszka
Quoted 51 lines · Philippe Gerum
Quoted 7 lines · Jan Kiszka
Hi Philippe,
we ran into at least one bug of the current prio ceiling support for synch objects: on
xnsynch_release, we only reschedule if we woken up a new owner. But we also have to reschedule after dropping the ceiling prio as some higher prio thread may be waiting.Quoted 5 lines
For that, I would propose to alter the return type and semantic of
xnsynch_releasefrom "pointer to new owner" into "bool, true if reschedule is needed". It seems, no caller ofxnsynch_releasemakes a non-boolean use of the return value anyway. And then we can simply return true on "synch->status&XNSYNCH_PP".I agree, but we need to keep the next owner check in the boolean status. Something like this would do I believe:
kernel/cobalt/synch.c +7
-5@@ -913,10 +913,10 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch,* * @coretags{primary-only, might-switch} */ -struct xnthread *xnsynch_release (struct xnsynch *synch, -struct xnthread *curr) +static bool xnsynch_release (struct xnsynch *synch, +struct xnthread *curr) { -struct xnthread *nextowner =NULL ; +bool resched = false;xnhandle_t currh, h;atomic_t *lockp;spl_t s;@@ -946,16 +946,18 @@ struct xnthread *xnsynch_release(struct xnsynch *synch, h =atomic_cmpxchg (lockp, currh,XN_NO_HANDLE );if ((h & ~XNSYNCH_FLCEIL ) != currh)/* FLCLAIM set, synch is contended. */ - nextowner =transfer_ownership (synch, curr); + resched =transfer_ownership (synch, curr) !=NULL ;else if (h != currh)/* FLCEIL set, FLCLAIM clear. */ atomic_set (lockp,XN_NO_HANDLE ); -if (synch->status &XNSYNCH_PP ) +if (synch->status &XNSYNCH_PP ) {clear_pp_boost (synch, curr); + resched = true; + }xnlock_put_irqrestore (&nklock, s);
Quoted 9 lines
kernel/cobalt/synch.c struct xnthread *xnsynch_release(struct xnsynch *synch, · line 963
Quoted 6 lines
kernel/cobalt/synch.c +1
-1-return nextowner; +return resched; }EXPORT_SYMBOL_GPL (xnsynch_release);OK, I didn't use bool (will change that), but otherwise did the same with that two patches in for-forge. Or what do you mean?
Problem solved these ways, both for slow and fast path. Just received the confirmation.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 52 lines · Jan Kiszka
Quoted 51 lines · Philippe Gerum
Quoted 7 lines · Jan Kiszka
Hi Philippe,
we ran into at least one bug of the current prio ceiling support for synch objects: on
xnsynch_release, we only reschedule if we woken up a new owner. But we also have to reschedule after dropping the ceiling prio as some higher prio thread may be waiting.Quoted 5 lines
For that, I would propose to alter the return type and semantic of
xnsynch_releasefrom "pointer to new owner" into "bool, true if reschedule is needed". It seems, no caller ofxnsynch_releasemakes a non-boolean use of the return value anyway. And then we can simply return true on "synch->status&XNSYNCH_PP".I agree, but we need to keep the next owner check in the boolean status. Something like this would do I believe:
kernel/cobalt/synch.c +7
-5@@ -913,10 +913,10 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch,* * @coretags{primary-only, might-switch} */ -struct xnthread *xnsynch_release (struct xnsynch *synch, -struct xnthread *curr) +static bool xnsynch_release (struct xnsynch *synch, +struct xnthread *curr) { -struct xnthread *nextowner =NULL ; +bool resched = false;xnhandle_t currh, h;atomic_t *lockp;spl_t s;@@ -946,16 +946,18 @@ struct xnthread *xnsynch_release(struct xnsynch *synch, h =atomic_cmpxchg (lockp, currh,XN_NO_HANDLE );if ((h & ~XNSYNCH_FLCEIL ) != currh)/* FLCLAIM set, synch is contended. */ - nextowner =transfer_ownership (synch, curr); + resched =transfer_ownership (synch, curr) !=NULL ;else if (h != currh)/* FLCEIL set, FLCLAIM clear. */ atomic_set (lockp,XN_NO_HANDLE ); -if (synch->status &XNSYNCH_PP ) +if (synch->status &XNSYNCH_PP ) {clear_pp_boost (synch, curr); + resched = true; + }xnlock_put_irqrestore (&nklock, s);
Quoted 10 lines
kernel/cobalt/synch.c struct xnthread *xnsynch_release(struct xnsynch *synch, · line 963
Quoted 6 lines
kernel/cobalt/synch.c +1
-1-return nextowner; +return resched; }EXPORT_SYMBOL_GPL (xnsynch_release);OK, I didn't use bool (will change that), but otherwise did the same with that two patches in for-forge. Or what do you mean?
No issue, e-mail crossing.
Signature · 1 line
Philippe.