From: Diego Nieto Cid <[email protected]>
Set the default thread and processor set max priority to
that of system threads to allow privileged task to raise
its own priority.
* kern/processor.c: modify pset_init to set the initial
max_priority to BASEPRI_SYSTE.
* kern/thread.c: set the thread template max_priority to
BASEPRI_SYSTEM.
---
kern/processor.c | 6 +++---
kern/thread.c | 12 +++++++++++-
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/kern/processor.c b/kern/processor.c
index ee1f7694..485eb51b 100644
--- a/kern/processor.c
+++ b/kern/processor.c
@@ -91,8 +91,8 @@ void pset_sys_bootstrap(void)
default_pset.active = TRUE;
/*
- * Note: the default_pset has a max_priority of BASEPRI_USER.
- * Internal kernel threads override this in kernel_thread.
+ * Note: the default_pset has a max_priority of BASEPRI_SYSTEM
+ * so that privileged tasks can raise its priority later on.
*/
}
@@ -160,7 +160,7 @@ void pset_init(
simple_lock_init(&pset->lock);
pset->pset_self = IP_NULL;
pset->pset_name_self = IP_NULL;
- pset->max_priority = BASEPRI_USER;
+ pset->max_priority = BASEPRI_SYSTEM;
#if MACH_FIXPRI
pset->policies = POLICY_TIMESHARE;
#endif /* MACH_FIXPRI */
diff --git a/kern/thread.c b/kern/thread.c
index deb9688d..5a0989ae 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -335,7 +335,11 @@ void thread_init(void)
thread_template.swap_func = thread_bootstrap_return;
/* thread_template.priority (later) */
- thread_template.max_priority = BASEPRI_USER;
+ /*
+ * Set an a priori max priority, but avoid going
+ * higher than SYSTEM threads.
+ */
+ thread_template.max_priority = BASEPRI_SYSTEM;
/* thread_template.sched_pri (later - compute_priority) */
#if MACH_FIXPRI
thread_template.sched_data = 0;
@@ -1736,6 +1740,12 @@ thread_t kernel_thread(
* The swapin mechanism might not be operational yet.
*/
thread_doswapin(thread);
+ /*
+ * task_create above, computed the max_priority from
+ * the task and processor set's max_priority.
+ * Since this is a kernel thread, set its max_priority
+ * to BASEPRI_SYSTEM.
+ */
thread->max_priority = BASEPRI_SYSTEM;
thread->priority = BASEPRI_SYSTEM;
thread->sched_pri = BASEPRI_SYSTEM;
--
2.53.0