summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2012-11-24 18:31:15 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2012-11-24 18:31:15 +0100
commitb2d57eb33ddd8f24929f372bfb08bac3a29ac6ea (patch)
tree314f93072e55c1016fa3fd70c9c1cc6badeb9e3c
parentdefb5c49977bcbf92f22a5eecd35b0a27ed8745d (diff)
Move starvation-reduction computation into adjust_priority
* libports/manage-multithread.c (ports_manage_port_operations_multithread): Move starvation-reduction computation and thread_switch() call into... (adjust_priority): ... here, passing TOTALTHREADS as a parameter.
-rw-r--r--libports/manage-multithread.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c
index 309b3038..035cd38d 100644
--- a/libports/manage-multithread.c
+++ b/libports/manage-multithread.c
@@ -26,15 +26,27 @@
#include <mach/thread_info.h>
#include <mach/thread_switch.h>
-/* A very high priority is assigned to reduce thread storms in core servers. */
#define THREAD_PRI 2
+/* XXX To reduce starvation, the priority of new threads is initially
+ depressed. This helps already existing threads complete their job and be
+ recycled to handle new messages. The duration of this depression is made
+ a function of the total number of threads because more threads imply
+ more contention, and the priority of threads blocking on a contended spin
+ lock is also implicitely depressed.
+
+ Then, if permitted, a greater priority is requested to further decrease
+ the need for additional threads. */
static void
-adjust_priority (void)
+adjust_priority (unsigned int totalthreads)
{
mach_port_t host_priv, self, pset, pset_priv;
+ unsigned int t;
error_t err;
+ t = 10 + (((totalthreads - 1) / 100) + 1) * 10;
+ thread_switch (MACH_PORT_NULL, SWITCH_OPTION_DEPRESS, t);
+
self = MACH_PORT_NULL;
err = get_privileged_ports (&host_priv, NULL);
@@ -162,18 +174,8 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket,
int timeout;
error_t err;
- /* XXX To reduce starvation, the priority of new threads is initially
- depressed. This helps already existing threads complete their job
- and be recycled to handle new messages. The duration of this
- depression is made a function of the total number of threads because
- more threads implies more contention, and the priority of threads
- blocking on a contented spin lock is also implicitely depressed.
- The lock isn't needed, since an approximation is sufficient. */
- timeout = (((totalthreads - 1) / 100) + 1) * 10;
- thread_switch (MACH_PORT_NULL, SWITCH_OPTION_DEPRESS, timeout);
-
- /* XXX Give servers a greater priority when possible. */
- adjust_priority ();
+ /* No need to lock as an approximation is sufficient. */
+ adjust_priority (totalthreads);
if (hook)
(*hook) ();