Skip to content

Commit dacc4ff

Browse files
author
jocke
committed
Now that we have fine-granularity run queue checking, return check of it to path where we create the thread to avoid lagging effect - this now very nicely modulates the number of created threads, significantly better than old approach... Also removed the '-1' for manager thread in the platform-specific load.c, instead check in common code as the same pattern is required everywhere.
1 parent 9d6aff8 commit dacc4ff

File tree

3 files changed

+10
-27
lines changed

3 files changed

+10
-27
lines changed

Diff for: src/linux/load.c

-10
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ linux_get_kse_count(void)
6969
}
7070
nkse = atoi(p + 1);
7171

72-
/* The manager thread is currently running, but will not perform any "real" work.
73-
* Subtract one from the total number of running KSEs.
74-
*/
75-
nkse--;
76-
7772
(void) close(fd);
7873

7974
return ((unsigned int) nkse);
@@ -105,10 +100,5 @@ linux_get_runqueue_length(void)
105100

106101
(void) fclose(f);
107102

108-
/* The manager thread is currently running, but will not perform
109-
* any "real" work. Subtract it from the runqueue size.
110-
*/
111-
runqsz--;
112-
113103
return ((unsigned int) runqsz);
114104
}

Diff for: src/posix/manager.c

+8-11
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ manager_main(void *unused __attribute__ ((unused)))
526526

527527
dbg_puts("manager is awake");
528528

529-
dbg_printf("load=%u idle=%u workers=%u max_workers=%u worker_min = %u",
530-
scoreboard.load, scoreboard.idle, scoreboard.count, worker_max, worker_min);
529+
dbg_printf("idle=%u workers=%u max_workers=%u worker_min = %u",
530+
scoreboard.idle, scoreboard.count, worker_max, worker_min);
531531

532532
// If no workers available, check if we should create a new one
533533
if ((scoreboard.idle == 0) && (scoreboard.count > 0) && (pending_thread_create == 0)) // last part required for an extremely unlikely race at startup
@@ -545,15 +545,14 @@ manager_main(void *unused __attribute__ ((unused)))
545545
{
546546
if (threads_runnable(&current_thread_count) != 0)
547547
current_thread_count = 0;
548-
else
549-
current_thread_count--; // decrease by one as we don't want to count the manager thread who
550-
// usually will be runnable when testing this...
551-
// TODO: We should instead pass our thread id to thread_runnable()
552548

553549
// only start thread if we have less runnable threads than cpus and load allows it
554-
if (current_thread_count < cpu_count)
550+
551+
if (current_thread_count <= cpu_count) // <= discounts the manager thread
555552
{
556-
if (scoreboard.load <= load_max)
553+
scoreboard.load = get_load_average();
554+
555+
if (scoreboard.load <= load_max) // <= discounts the manager thread
557556
{
558557
if (scoreboard.idle == 0) // someone might have become idle during getting thread count etc.
559558
worker_start();
@@ -569,7 +568,7 @@ manager_main(void *unused __attribute__ ((unused)))
569568
}
570569
else
571570
{
572-
dbg_printf("Not spawning worker thread, thread_runnable = %d >= cpu_count = %d",
571+
dbg_printf("Not spawning worker thread, thread_runnable = %d > cpu_count = %d",
573572
current_thread_count, cpu_count);
574573
}
575574
}
@@ -584,8 +583,6 @@ manager_main(void *unused __attribute__ ((unused)))
584583
{
585584
if (sem_timedwait_rv == ETIMEDOUT) // Only check for ramp down on the 'timer tick'
586585
{
587-
scoreboard.load = get_load_average(); // update internal stat, avoid doing it in critical path for creating new threads...
588-
589586
if (scoreboard.idle > worker_idle_threshold) // only accumulate if there are 'too many' idle threads
590587
{
591588
worker_idle_seconds_accumulated += scoreboard.idle; // keep track of many idle 'thread seconds' we have

Diff for: src/solaris/load.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ solaris_get_runqueue_length(void)
6565
if (previous_updates != 0)
6666
{
6767
run_queue = (previous_runque/previous_updates);
68-
// dbg_printf("runqueue = %u, updates = %u, ratio = %u \n", previous_runque, previous_updates, run_queue);
68+
dbg_printf("runqueue = %u, updates = %u, ratio = %u \n", previous_runque, previous_updates, run_queue);
6969
}
7070

7171
previous_runque = sysinfo.runque;
@@ -76,9 +76,5 @@ solaris_get_runqueue_length(void)
7676
return 0;
7777
}
7878

79-
/* The manager thread is currently running, but will not perform
80-
* any "real" work. Subtract it from the runqueue size returned.
81-
*/
82-
83-
return (run_queue > 0 ? (run_queue - 1) : 0);
79+
return run_queue;
8480
}

0 commit comments

Comments
 (0)