@@ -723,31 +723,21 @@ bool svc_pool_wake_idle_thread(struct svc_pool *pool)
723
723
return false;
724
724
}
725
725
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 )
731
728
{
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 ];
736
730
}
737
731
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 )
743
734
{
744
735
unsigned int i ;
745
736
struct task_struct * task = NULL ;
746
737
747
738
if (pool != NULL ) {
748
739
spin_lock_bh (& pool -> sp_lock );
749
740
} else {
750
- /* choose a pool in round-robin fashion */
751
741
for (i = 0 ; i < serv -> sv_nrpools ; i ++ ) {
752
742
pool = & serv -> sv_pools [-- (* state ) % serv -> sv_nrpools ];
753
743
spin_lock_bh (& pool -> sp_lock );
@@ -762,21 +752,15 @@ choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
762
752
if (!list_empty (& pool -> sp_all_threads )) {
763
753
struct svc_rqst * rqstp ;
764
754
765
- /*
766
- * Remove from the pool->sp_all_threads list
767
- * so we don't try to kill it again.
768
- */
769
755
rqstp = list_entry (pool -> sp_all_threads .next , struct svc_rqst , rq_all );
770
756
set_bit (RQ_VICTIM , & rqstp -> rq_flags );
771
757
list_del_rcu (& rqstp -> rq_all );
772
758
task = rqstp -> rq_task ;
773
759
}
774
760
spin_unlock_bh (& pool -> sp_lock );
775
-
776
761
return task ;
777
762
}
778
763
779
- /* create new threads */
780
764
static int
781
765
svc_start_kthreads (struct svc_serv * serv , struct svc_pool * pool , int nrservs )
782
766
{
@@ -788,13 +772,12 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
788
772
789
773
do {
790
774
nrservs -- ;
791
- chosen_pool = choose_pool (serv , pool , & state );
792
-
775
+ chosen_pool = svc_pool_next (serv , pool , & state );
793
776
node = svc_pool_map_get_node (chosen_pool -> sp_id );
777
+
794
778
rqstp = svc_prepare_thread (serv , chosen_pool , node );
795
779
if (IS_ERR (rqstp ))
796
780
return PTR_ERR (rqstp );
797
-
798
781
task = kthread_create_on_node (serv -> sv_threadfn , rqstp ,
799
782
node , "%s" , serv -> sv_name );
800
783
if (IS_ERR (task )) {
@@ -813,25 +796,15 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
813
796
return 0 ;
814
797
}
815
798
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 */
825
799
static int
826
800
svc_stop_kthreads (struct svc_serv * serv , struct svc_pool * pool , int nrservs )
827
801
{
828
802
struct svc_rqst * rqstp ;
829
803
struct task_struct * task ;
830
804
unsigned int state = serv -> sv_nrthreads - 1 ;
831
805
832
- /* destroy old threads */
833
806
do {
834
- task = choose_victim (serv , pool , & state );
807
+ task = svc_pool_victim (serv , pool , & state );
835
808
if (task == NULL )
836
809
break ;
837
810
rqstp = kthread_data (task );
@@ -843,6 +816,23 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
843
816
return 0 ;
844
817
}
845
818
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
+ */
846
836
int
847
837
svc_set_num_threads (struct svc_serv * serv , struct svc_pool * pool , int nrservs )
848
838
{
0 commit comments