Commit d2f0ef1c authored by Chuck Lever's avatar Chuck Lever

SUNRPC: Clean up svc_set_num_threads

Document the API contract and remove stale or obvious comments.
Reviewed-by: default avatarJeff Layton <jlayton@redhat.com>
Reviewed-by: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent f208e950
...@@ -723,23 +723,14 @@ bool svc_pool_wake_idle_thread(struct svc_pool *pool) ...@@ -723,23 +723,14 @@ bool svc_pool_wake_idle_thread(struct svc_pool *pool)
return false; return false;
} }
/* static struct svc_pool *
* Choose a pool in which to create a new thread, for svc_set_num_threads svc_pool_next(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
*/
static inline struct svc_pool *
choose_pool(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
{ {
if (pool != NULL) return pool ? pool : &serv->sv_pools[(*state)++ % serv->sv_nrpools];
return pool;
return &serv->sv_pools[(*state)++ % serv->sv_nrpools];
} }
/* static struct task_struct *
* Choose a thread to kill, for svc_set_num_threads svc_pool_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
*/
static inline struct task_struct *
choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
{ {
unsigned int i; unsigned int i;
struct task_struct *task = NULL; struct task_struct *task = NULL;
...@@ -747,7 +738,6 @@ choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state) ...@@ -747,7 +738,6 @@ choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
if (pool != NULL) { if (pool != NULL) {
spin_lock_bh(&pool->sp_lock); spin_lock_bh(&pool->sp_lock);
} else { } else {
/* choose a pool in round-robin fashion */
for (i = 0; i < serv->sv_nrpools; i++) { for (i = 0; i < serv->sv_nrpools; i++) {
pool = &serv->sv_pools[--(*state) % serv->sv_nrpools]; pool = &serv->sv_pools[--(*state) % serv->sv_nrpools];
spin_lock_bh(&pool->sp_lock); spin_lock_bh(&pool->sp_lock);
...@@ -762,21 +752,15 @@ choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state) ...@@ -762,21 +752,15 @@ choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
if (!list_empty(&pool->sp_all_threads)) { if (!list_empty(&pool->sp_all_threads)) {
struct svc_rqst *rqstp; struct svc_rqst *rqstp;
/*
* Remove from the pool->sp_all_threads list
* so we don't try to kill it again.
*/
rqstp = list_entry(pool->sp_all_threads.next, struct svc_rqst, rq_all); rqstp = list_entry(pool->sp_all_threads.next, struct svc_rqst, rq_all);
set_bit(RQ_VICTIM, &rqstp->rq_flags); set_bit(RQ_VICTIM, &rqstp->rq_flags);
list_del_rcu(&rqstp->rq_all); list_del_rcu(&rqstp->rq_all);
task = rqstp->rq_task; task = rqstp->rq_task;
} }
spin_unlock_bh(&pool->sp_lock); spin_unlock_bh(&pool->sp_lock);
return task; return task;
} }
/* create new threads */
static int static int
svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
{ {
...@@ -788,13 +772,12 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) ...@@ -788,13 +772,12 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
do { do {
nrservs--; nrservs--;
chosen_pool = choose_pool(serv, pool, &state); chosen_pool = svc_pool_next(serv, pool, &state);
node = svc_pool_map_get_node(chosen_pool->sp_id); node = svc_pool_map_get_node(chosen_pool->sp_id);
rqstp = svc_prepare_thread(serv, chosen_pool, node); rqstp = svc_prepare_thread(serv, chosen_pool, node);
if (IS_ERR(rqstp)) if (IS_ERR(rqstp))
return PTR_ERR(rqstp); return PTR_ERR(rqstp);
task = kthread_create_on_node(serv->sv_threadfn, rqstp, task = kthread_create_on_node(serv->sv_threadfn, rqstp,
node, "%s", serv->sv_name); node, "%s", serv->sv_name);
if (IS_ERR(task)) { if (IS_ERR(task)) {
...@@ -813,15 +796,6 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) ...@@ -813,15 +796,6 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
return 0; return 0;
} }
/*
* Create or destroy enough new threads to make the number
* of threads the given number. If `pool' is non-NULL, applies
* only to threads in that pool, otherwise round-robins between
* all pools. Caller must ensure that mutual exclusion between this and
* server startup or shutdown.
*/
/* destroy old threads */
static int static int
svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
{ {
...@@ -829,9 +803,8 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) ...@@ -829,9 +803,8 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
struct task_struct *task; struct task_struct *task;
unsigned int state = serv->sv_nrthreads-1; unsigned int state = serv->sv_nrthreads-1;
/* destroy old threads */
do { do {
task = choose_victim(serv, pool, &state); task = svc_pool_victim(serv, pool, &state);
if (task == NULL) if (task == NULL)
break; break;
rqstp = kthread_data(task); rqstp = kthread_data(task);
...@@ -843,6 +816,23 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) ...@@ -843,6 +816,23 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
return 0; return 0;
} }
/**
* svc_set_num_threads - adjust number of threads per RPC service
* @serv: RPC service to adjust
* @pool: Specific pool from which to choose threads, or NULL
* @nrservs: New number of threads for @serv (0 or less means kill all threads)
*
* Create or destroy threads to make the number of threads for @serv the
* given number. If @pool is non-NULL, change only threads in that pool;
* otherwise, round-robin between all pools for @serv. @serv's
* sv_nrthreads is adjusted for each thread created or destroyed.
*
* Caller must ensure mutual exclusion between this and server startup or
* shutdown.
*
* Returns zero on success or a negative errno if an error occurred while
* starting a thread.
*/
int int
svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment