summaryrefslogtreecommitdiffstats
path: root/sys/kern/sched_4bsd.c
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2006-08-25 06:12:53 +0000
committerdavidxu <davidxu@FreeBSD.org>2006-08-25 06:12:53 +0000
commit8e3f035b3fe6e8293586d7be12b71498351440c8 (patch)
tree244bf38809201fa8c6b1cc0c207cf963c19902ab /sys/kern/sched_4bsd.c
parent73837f2df49445b9f599115029f3e2986e48e6de (diff)
downloadFreeBSD-src-8e3f035b3fe6e8293586d7be12b71498351440c8.zip
FreeBSD-src-8e3f035b3fe6e8293586d7be12b71498351440c8.tar.gz
Add user priority loaning code to support priority propagation for
1:1 threading's POSIX priority mutexes, the code is no-op unless priority-aware umtx code is committed.
Diffstat (limited to 'sys/kern/sched_4bsd.c')
-rw-r--r--sys/kern/sched_4bsd.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c
index 1e34e80..ce7582f 100644
--- a/sys/kern/sched_4bsd.c
+++ b/sys/kern/sched_4bsd.c
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/turnstile.h>
+#include <sys/umtx.h>
#include <machine/pcb.h>
#include <machine/smp.h>
@@ -586,7 +587,7 @@ resetpriority(struct ksegrp *kg)
NICE_WEIGHT * (kg->kg_proc->p_nice - PRIO_MIN);
newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
PRI_MAX_TIMESHARE);
- kg->kg_user_pri = newpriority;
+ sched_user_prio(kg, newpriority);
}
}
@@ -864,6 +865,60 @@ sched_prio(struct thread *td, u_char prio)
}
void
+sched_user_prio(struct ksegrp *kg, u_char prio)
+{
+ struct thread *td;
+ u_char oldprio;
+
+ kg->kg_base_user_pri = prio;
+
+ /* XXXKSE only for 1:1 */
+
+ td = TAILQ_FIRST(&kg->kg_threads);
+ if (td == NULL) {
+ kg->kg_user_pri = prio;
+ return;
+ }
+
+ if (td->td_flags & TDF_UBORROWING && kg->kg_user_pri <= prio)
+ return;
+
+ oldprio = kg->kg_user_pri;
+ kg->kg_user_pri = prio;
+
+ if (TD_ON_UPILOCK(td) && oldprio != prio)
+ umtx_pi_adjust(td, oldprio);
+}
+
+void
+sched_lend_user_prio(struct thread *td, u_char prio)
+{
+ u_char oldprio;
+
+ td->td_flags |= TDF_UBORROWING;
+
+ oldprio = td->td_ksegrp->kg_user_pri;
+ td->td_ksegrp->kg_user_pri = prio;
+
+ if (TD_ON_UPILOCK(td) && oldprio != prio)
+ umtx_pi_adjust(td, oldprio);
+}
+
+void
+sched_unlend_user_prio(struct thread *td, u_char prio)
+{
+ struct ksegrp *kg = td->td_ksegrp;
+ u_char base_pri;
+
+ base_pri = kg->kg_base_user_pri;
+ if (prio >= base_pri) {
+ td->td_flags &= ~TDF_UBORROWING;
+ sched_user_prio(kg, base_pri);
+ } else
+ sched_lend_user_prio(td, prio);
+}
+
+void
sched_sleep(struct thread *td)
{
OpenPOWER on IntegriCloud