From 23588c267fa08b5d27793e62bb72214164107e97 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 19 Nov 2018 02:46:44 +0100 Subject: 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. --- kern/thread.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'kern/thread.c') diff --git a/kern/thread.c b/kern/thread.c index 86b76103..73d9b5a4 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -443,6 +443,17 @@ kern_return_t thread_create( pset_reference(pset); 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 -- cgit v1.2.3