Skip to content

Commit d2f0ef1

Browse files
committed
SUNRPC: Clean up svc_set_num_threads
Document the API contract and remove stale or obvious comments. Reviewed-by: Jeff Layton <jlayton@redhat.com> Reviewed-by: NeilBrown <neilb@suse.de> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent f208e95 commit d2f0ef1

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

net/sunrpc/svc.c

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -723,31 +723,21 @@ bool svc_pool_wake_idle_thread(struct svc_pool *pool)
723723
return false;
724724
}
725725

726-
/*
727-
* Choose a pool in which to create a new thread, for svc_set_num_threads
728-
*/
729-
static inline struct svc_pool *
730-
choose_pool(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
726+
static struct svc_pool *
727+
svc_pool_next(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
731728
{
732-
if (pool != NULL)
733-
return pool;
734-
735-
return &serv->sv_pools[(*state)++ % serv->sv_nrpools];
729+
return pool ? pool : &serv->sv_pools[(*state)++ % serv->sv_nrpools];
736730
}
737731

738-
/*
739-
* Choose a thread to kill, for svc_set_num_threads
740-
*/
741-
static inline struct task_struct *
742-
choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
732+
static struct task_struct *
733+
svc_pool_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
743734
{
744735
unsigned int i;
745736
struct task_struct *task = NULL;
746737

747738
if (pool != NULL) {
748739
spin_lock_bh(&pool->sp_lock);
749740
} else {
750-
/* choose a pool in round-robin fashion */
751741
for (i = 0; i < serv->sv_nrpools; i++) {
752742
pool = &serv->sv_pools[--(*state) % serv->sv_nrpools];
753743
spin_lock_bh(&pool->sp_lock);
@@ -762,21 +752,15 @@ choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
762752
if (!list_empty(&pool->sp_all_threads)) {
763753
struct svc_rqst *rqstp;
764754

765-
/*
766-
* Remove from the pool->sp_all_threads list
767-
* so we don't try to kill it again.
768-
*/
769755
rqstp = list_entry(pool->sp_all_threads.next, struct svc_rqst, rq_all);
770756
set_bit(RQ_VICTIM, &rqstp->rq_flags);
771757
list_del_rcu(&rqstp->rq_all);
772758
task = rqstp->rq_task;
773759
}
774760
spin_unlock_bh(&pool->sp_lock);
775-
776761
return task;
777762
}
778763

779-
/* create new threads */
780764
static int
781765
svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
782766
{
@@ -788,13 +772,12 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
788772

789773
do {
790774
nrservs--;
791-
chosen_pool = choose_pool(serv, pool, &state);
792-
775+
chosen_pool = svc_pool_next(serv, pool, &state);
793776
node = svc_pool_map_get_node(chosen_pool->sp_id);
777+
794778
rqstp = svc_prepare_thread(serv, chosen_pool, node);
795779
if (IS_ERR(rqstp))
796780
return PTR_ERR(rqstp);
797-
798781
task = kthread_create_on_node(serv->sv_threadfn, rqstp,
799782
node, "%s", serv->sv_name);
800783
if (IS_ERR(task)) {
@@ -813,25 +796,15 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
813796
return 0;
814797
}
815798

816-
/*
817-
* Create or destroy enough new threads to make the number
818-
* of threads the given number. If `pool' is non-NULL, applies
819-
* only to threads in that pool, otherwise round-robins between
820-
* all pools. Caller must ensure that mutual exclusion between this and
821-
* server startup or shutdown.
822-
*/
823-
824-
/* destroy old threads */
825799
static int
826800
svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
827801
{
828802
struct svc_rqst *rqstp;
829803
struct task_struct *task;
830804
unsigned int state = serv->sv_nrthreads-1;
831805

832-
/* destroy old threads */
833806
do {
834-
task = choose_victim(serv, pool, &state);
807+
task = svc_pool_victim(serv, pool, &state);
835808
if (task == NULL)
836809
break;
837810
rqstp = kthread_data(task);
@@ -843,6 +816,23 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
843816
return 0;
844817
}
845818

819+
/**
820+
* svc_set_num_threads - adjust number of threads per RPC service
821+
* @serv: RPC service to adjust
822+
* @pool: Specific pool from which to choose threads, or NULL
823+
* @nrservs: New number of threads for @serv (0 or less means kill all threads)
824+
*
825+
* Create or destroy threads to make the number of threads for @serv the
826+
* given number. If @pool is non-NULL, change only threads in that pool;
827+
* otherwise, round-robin between all pools for @serv. @serv's
828+
* sv_nrthreads is adjusted for each thread created or destroyed.
829+
*
830+
* Caller must ensure mutual exclusion between this and server startup or
831+
* shutdown.
832+
*
833+
* Returns zero on success or a negative errno if an error occurred while
834+
* starting a thread.
835+
*/
846836
int
847837
svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
848838
{

0 commit comments

Comments
 (0)