Skip to content

Commit 19b097f

Browse files
author
jocke
committed
Change naming of load_average fields/functions internally, as semantics changed from 'load average' to 'run queue length' and is properly implemented on both Linux and Solaris now.
1 parent dacc4ff commit 19b097f

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

LICENSE

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*-
2-
* Copyright (c) 2010, Mark Heily <[email protected]>
2+
* Copyright (c) 2011-2012, Joakim Johansson <[email protected]>
3+
* Copyright (c) 2010-2012, Mark Heily <[email protected]>
34
* Copyright (c) 2009, Stacey Son <[email protected]>
45
* Copyright (c) 2000-2008, Apple Inc.
56
* All rights reserved.

src/posix/manager.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ unsigned volatile int current_threads_spinning = 0; // The number of threads cur
4747
#define WORKER_IDLE_SECONDS_THRESHOLD 15
4848

4949
/* Function prototypes */
50-
static unsigned int get_load_average(void);
50+
static unsigned int get_runqueue_length(void);
5151
static void * worker_main(void *arg);
5252
static void * overcommit_worker_main(void *arg);
5353
static unsigned int get_process_limit(void);
@@ -75,7 +75,7 @@ static int wqlist_has_manager;
7575
static pthread_attr_t detached_attr;
7676

7777
static struct {
78-
volatile unsigned int load,
78+
volatile unsigned int runqueue_length,
7979
count,
8080
idle;
8181
sem_t sb_sem;
@@ -482,7 +482,7 @@ worker_stop(void)
482482
static void *
483483
manager_main(void *unused __attribute__ ((unused)))
484484
{
485-
unsigned int load_max = (cpu_count + 1); // We allow +1 to take manager thread into account
485+
unsigned int runqueue_length_max = cpu_count;
486486
unsigned int worker_max, current_thread_count = 0;
487487
unsigned int worker_idle_seconds_accumulated = 0;
488488
unsigned int max_threads_to_stop = 0;
@@ -493,7 +493,7 @@ manager_main(void *unused __attribute__ ((unused)))
493493
struct timeval tp;
494494

495495
worker_max = get_process_limit();
496-
scoreboard.load = get_load_average();
496+
scoreboard.runqueue_length = get_runqueue_length();
497497

498498
/* Block all signals */
499499
sigfillset(&sigmask);
@@ -532,27 +532,27 @@ manager_main(void *unused __attribute__ ((unused)))
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
534534
{
535-
// allow cheap rampup up to worker_idle_threshold without going to /proc / checking load average
535+
// allow cheap rampup up to worker_idle_threshold without going to /proc / checking run queue length
536536
if (scoreboard.count < worker_idle_threshold)
537537
{
538538
worker_start();
539539
}
540540
else
541541
{
542-
// otherwise check if load / stalled threads allows for new creation unless we hit worker_max ceiling
542+
// otherwise check if run queue length / stalled threads allows for new creation unless we hit worker_max ceiling
543543

544544
if (scoreboard.count < worker_max)
545545
{
546546
if (threads_runnable(&current_thread_count) != 0)
547547
current_thread_count = 0;
548548

549-
// only start thread if we have less runnable threads than cpus and load allows it
549+
// only start thread if we have less runnable threads than cpus and run queue length allows it
550550

551551
if (current_thread_count <= cpu_count) // <= discounts the manager thread
552552
{
553-
scoreboard.load = get_load_average();
553+
scoreboard.runqueue_length = get_runqueue_length();
554554

555-
if (scoreboard.load <= load_max) // <= discounts the manager thread
555+
if (scoreboard.runqueue_length <= runqueue_length_max) // <= discounts the manager thread
556556
{
557557
if (scoreboard.idle == 0) // someone might have become idle during getting thread count etc.
558558
worker_start();
@@ -562,8 +562,8 @@ manager_main(void *unused __attribute__ ((unused)))
562562
}
563563
else
564564
{
565-
dbg_printf("Not spawning worker thread, scoreboard.load = %d > load_max = %d",
566-
scoreboard.load, load_max);
565+
dbg_printf("Not spawning worker thread, scoreboard.runqueue_length = %d > runqueue_length_max = %d",
566+
scoreboard.runqueue_length, runqueue_length_max);
567567
}
568568
}
569569
else
@@ -731,7 +731,7 @@ get_process_limit(void)
731731
}
732732

733733
static unsigned int
734-
get_load_average(void)
734+
get_runqueue_length(void)
735735
{
736736
double loadavg;
737737

@@ -744,7 +744,7 @@ get_load_average(void)
744744
return solaris_get_runqueue_length();
745745
#endif
746746

747-
/* Fallback to using the 1-minute load average. */
747+
/* Fallback to using the 1-minute load average if proper run queue length can't be determined. */
748748

749749
/* TODO: proper error handling */
750750
if (getloadavg(&loadavg, 1) != 1) {

0 commit comments

Comments
 (0)