Mon Mar 7 21:57:15 2011 UTC ()
use nwork-adjusted amount of idle workers to decide is they are truly idle.


(pooka)
diff -r1.42 -r1.43 src/lib/librumpuser/rumpuser_sp.c

cvs diff -r1.42 -r1.43 src/lib/librumpuser/rumpuser_sp.c (expand / switch to unified diff)

--- src/lib/librumpuser/rumpuser_sp.c 2011/02/15 16:10:41 1.42
+++ src/lib/librumpuser/rumpuser_sp.c 2011/03/07 21:57:15 1.43
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rumpuser_sp.c,v 1.42 2011/02/15 16:10:41 pooka Exp $ */ 1/* $NetBSD: rumpuser_sp.c,v 1.43 2011/03/07 21:57:15 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * SUCH DAMAGE. 25 * SUCH DAMAGE.
26 */ 26 */
27 27
28/* 28/*
29 * Sysproxy routines. This provides system RPC support over host sockets. 29 * Sysproxy routines. This provides system RPC support over host sockets.
30 * The most notable limitation is that the client and server must share 30 * The most notable limitation is that the client and server must share
31 * the same ABI. This does not mean that they have to be the same 31 * the same ABI. This does not mean that they have to be the same
32 * machine or that they need to run the same version of the host OS, 32 * machine or that they need to run the same version of the host OS,
33 * just that they must agree on the data structures. This even *might* 33 * just that they must agree on the data structures. This even *might*
34 * work correctly from one hardware architecture to another. 34 * work correctly from one hardware architecture to another.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__RCSID("$NetBSD: rumpuser_sp.c,v 1.42 2011/02/15 16:10:41 pooka Exp $"); 38__RCSID("$NetBSD: rumpuser_sp.c,v 1.43 2011/03/07 21:57:15 pooka Exp $");
39 39
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/atomic.h> 41#include <sys/atomic.h>
42#include <sys/mman.h> 42#include <sys/mman.h>
43#include <sys/socket.h> 43#include <sys/socket.h>
44 44
45#include <arpa/inet.h> 45#include <arpa/inet.h>
46#include <netinet/in.h> 46#include <netinet/in.h>
47#include <netinet/tcp.h> 47#include <netinet/tcp.h>
48 48
49#include <assert.h> 49#include <assert.h>
50#include <errno.h> 50#include <errno.h>
51#include <fcntl.h> 51#include <fcntl.h>
@@ -613,27 +613,27 @@ struct sysbouncearg { @@ -613,27 +613,27 @@ struct sysbouncearg {
613static pthread_mutex_t sbamtx; 613static pthread_mutex_t sbamtx;
614static pthread_cond_t sbacv; 614static pthread_cond_t sbacv;
615static int nworker, idleworker, nwork; 615static int nworker, idleworker, nwork;
616static TAILQ_HEAD(, sysbouncearg) syslist = TAILQ_HEAD_INITIALIZER(syslist); 616static TAILQ_HEAD(, sysbouncearg) syslist = TAILQ_HEAD_INITIALIZER(syslist);
617 617
618/*ARGSUSED*/ 618/*ARGSUSED*/
619static void * 619static void *
620serv_syscallbouncer(void *arg) 620serv_syscallbouncer(void *arg)
621{ 621{
622 struct sysbouncearg *sba; 622 struct sysbouncearg *sba;
623 623
624 for (;;) { 624 for (;;) {
625 pthread_mutex_lock(&sbamtx); 625 pthread_mutex_lock(&sbamtx);
626 if (__predict_false(idleworker >= rumpsp_idleworker)) { 626 if (__predict_false(idleworker - nwork >= rumpsp_idleworker)) {
627 nworker--; 627 nworker--;
628 pthread_mutex_unlock(&sbamtx); 628 pthread_mutex_unlock(&sbamtx);
629 break; 629 break;
630 } 630 }
631 idleworker++; 631 idleworker++;
632 while (TAILQ_EMPTY(&syslist)) { 632 while (TAILQ_EMPTY(&syslist)) {
633 _DIAGASSERT(nwork == 0); 633 _DIAGASSERT(nwork == 0);
634 pthread_cond_wait(&sbacv, &sbamtx); 634 pthread_cond_wait(&sbacv, &sbamtx);
635 } 635 }
636 idleworker--; 636 idleworker--;
637 637
638 sba = TAILQ_FIRST(&syslist); 638 sba = TAILQ_FIRST(&syslist);
639 TAILQ_REMOVE(&syslist, sba, sba_entries); 639 TAILQ_REMOVE(&syslist, sba, sba_entries);