summaryrefslogtreecommitdiff
path: root/kern/thread.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2018-11-19 02:46:44 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-11-19 02:48:17 +0100
commit23588c267fa08b5d27793e62bb72214164107e97 (patch)
tree800ffb8d3fd0faa7d6f43f3cadb58ce3f00eb149 /kern/thread.c
parent24c0a02a18d35dbd4f7715018bfffb11241bce7b (diff)
Fix interactivity of inactive threads
A new thread will mosty probably start working, assume it will take its share of CPU, to avoid having to find it out slowly. Decaying will however fix that quickly if it actually does not work. This fixes stalling issues when a program keeps creating threads. * kern/thread.c (thread_create): Set new_thread's cpu_usage and sched_usage to a fair share of the current load.
Diffstat (limited to 'kern/thread.c')
-rw-r--r--kern/thread.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/kern/thread.c b/kern/thread.c
index 86b76103..73d9b5a4 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -444,6 +444,17 @@ kern_return_t thread_create(
task_unlock(parent_task);
/*
+ * This thread will mosty probably start working, assume it
+ * will take its share of CPU, to avoid having to find it out
+ * slowly. Decaying will however fix that quickly if it actually
+ * does not work
+ */
+ new_thread->cpu_usage = TIMER_RATE * SCHED_SCALE /
+ (pset->load_average >= SCHED_SCALE ?
+ pset->load_average : SCHED_SCALE);
+ new_thread->sched_usage = TIMER_RATE * SCHED_SCALE;
+
+ /*
* Lock both the processor set and the task,
* so that the thread can be added to both
* simultaneously. Processor set must be