aboutsummaryrefslogtreecommitdiff
path: root/sys/rpc
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2013-11-14 13:51:53 +0000
committerAlexander Motin <mav@FreeBSD.org>2013-11-14 13:51:53 +0000
commitdb7cdfee302b41198029860bd21b5b4d9bf788f2 (patch)
tree2872a1646be42572b1913ce3c6df58c3afaf3877 /sys/rpc
parent77badb18cd70c9482aef0f84d1ec9aa7049117d6 (diff)
downloadsrc-db7cdfee302b41198029860bd21b5b4d9bf788f2.tar.gz
src-db7cdfee302b41198029860bd21b5b4d9bf788f2.zip
Some minor tuning to rpc/svc.c:
- close cosmetic race in svc_exit(); - do not set wait timeout for idle threads if we have no use for wakeups; - create new requested thread sooner, not only after some another thread wakeup, that may happen later under constant load.
Notes
Notes: svn path=/head/; revision=258132
Diffstat (limited to 'sys/rpc')
-rw-r--r--sys/rpc/svc.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/sys/rpc/svc.c b/sys/rpc/svc.c
index bbc6f6d54505..fbea16b9490c 100644
--- a/sys/rpc/svc.c
+++ b/sys/rpc/svc.c
@@ -1011,6 +1011,18 @@ svc_run_internal(SVCPOOL *pool, bool_t ismaster)
while (pool->sp_state != SVCPOOL_CLOSING) {
/*
+ * Create new thread if requested.
+ */
+ if (pool->sp_state == SVCPOOL_THREADWANTED) {
+ pool->sp_state = SVCPOOL_THREADSTARTING;
+ pool->sp_lastcreatetime = time_uptime;
+ mtx_unlock(&pool->sp_lock);
+ svc_new_thread(pool);
+ mtx_lock(&pool->sp_lock);
+ continue;
+ }
+
+ /*
* Check for idle transports once per second.
*/
if (time_uptime > pool->sp_lastidlecheck) {
@@ -1046,8 +1058,13 @@ svc_run_internal(SVCPOOL *pool, bool_t ismaster)
continue;
LIST_INSERT_HEAD(&pool->sp_idlethreads, st, st_ilink);
- error = cv_timedwait_sig(&st->st_cond, &pool->sp_lock,
- 5 * hz);
+ if (ismaster || (!ismaster &&
+ pool->sp_threadcount > pool->sp_minthreads))
+ error = cv_timedwait_sig(&st->st_cond,
+ &pool->sp_lock, 5 * hz);
+ else
+ error = cv_wait_sig(&st->st_cond,
+ &pool->sp_lock);
LIST_REMOVE(st, st_ilink);
/*
@@ -1060,24 +1077,11 @@ svc_run_internal(SVCPOOL *pool, bool_t ismaster)
&& !st->st_xprt
&& STAILQ_EMPTY(&st->st_reqs))
break;
- }
- if (error == EWOULDBLOCK)
- continue;
- if (error) {
- if (pool->sp_state != SVCPOOL_CLOSING) {
- mtx_unlock(&pool->sp_lock);
- svc_exit(pool);
- mtx_lock(&pool->sp_lock);
- }
- break;
- }
-
- if (pool->sp_state == SVCPOOL_THREADWANTED) {
- pool->sp_state = SVCPOOL_THREADSTARTING;
- pool->sp_lastcreatetime = time_uptime;
+ } else if (error) {
mtx_unlock(&pool->sp_lock);
- svc_new_thread(pool);
+ svc_exit(pool);
mtx_lock(&pool->sp_lock);
+ break;
}
continue;
}
@@ -1245,9 +1249,11 @@ svc_exit(SVCPOOL *pool)
mtx_lock(&pool->sp_lock);
- pool->sp_state = SVCPOOL_CLOSING;
- LIST_FOREACH(st, &pool->sp_idlethreads, st_ilink)
- cv_signal(&st->st_cond);
+ if (pool->sp_state != SVCPOOL_CLOSING) {
+ pool->sp_state = SVCPOOL_CLOSING;
+ LIST_FOREACH(st, &pool->sp_idlethreads, st_ilink)
+ cv_signal(&st->st_cond);
+ }
mtx_unlock(&pool->sp_lock);
}