1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * lustre/ptlrpc/ptlrpcd.c
42 /** \defgroup ptlrpcd PortalRPC daemon
44 * ptlrpcd is a special thread with its own set where other user might add
45 * requests when they don't want to wait for their completion.
46 * PtlRPCD will take care of sending such requests and then processing their
47 * replies and calling completion callbacks as necessary.
48 * The callbacks are called directly from ptlrpcd context.
49 * It is important to never significantly block (esp. on RPCs!) within such
50 * completion handler or a deadlock might occur where ptlrpcd enters some
51 * callback that attempts to send another RPC and wait for it to return,
52 * during which time ptlrpcd is completely blocked, so e.g. if import
53 * fails, recovery cannot progress because connection requests are also
59 #define DEBUG_SUBSYSTEM S_RPC
62 # include <libcfs/libcfs.h>
63 #else /* __KERNEL__ */
64 # include <liblustre.h>
68 #include <lustre_net.h>
69 # include <lustre_lib.h>
71 #include <lustre_ha.h>
72 #include <obd_class.h> /* for obd_zombie */
73 #include <obd_support.h> /* for OBD_FAIL_CHECK */
74 #include <cl_object.h> /* cl_env_{get,put}() */
75 #include <lprocfs_status.h>
77 #include "ptlrpc_internal.h"
83 struct ptlrpcd_ctl pd_thread_rcv;
84 struct ptlrpcd_ctl pd_threads[0];
88 static int max_ptlrpcds;
89 CFS_MODULE_PARM(max_ptlrpcds, "i", int, 0644,
90 "Max ptlrpcd thread count to be started.");
92 static int ptlrpcd_bind_policy = PDB_POLICY_PAIR;
93 CFS_MODULE_PARM(ptlrpcd_bind_policy, "i", int, 0644,
94 "Ptlrpcd threads binding mode.");
96 static struct ptlrpcd *ptlrpcds;
98 cfs_semaphore_t ptlrpcd_sem;
99 static int ptlrpcd_users = 0;
101 void ptlrpcd_wake(struct ptlrpc_request *req)
103 struct ptlrpc_request_set *rq_set = req->rq_set;
105 LASSERT(rq_set != NULL);
107 cfs_waitq_signal(&rq_set->set_waitq);
110 static struct ptlrpcd_ctl *
111 ptlrpcd_select_pc(struct ptlrpc_request *req, pdl_policy_t policy, int index)
115 if (req != NULL && req->rq_send_state != LUSTRE_IMP_FULL)
116 return &ptlrpcds->pd_thread_rcv;
120 case PDL_POLICY_SAME:
121 idx = cfs_smp_processor_id() % ptlrpcds->pd_nthreads;
123 case PDL_POLICY_LOCAL:
124 /* Before CPU partition patches available, process it the same
125 * as "PDL_POLICY_ROUND". */
126 # ifdef CFS_CPU_MODE_NUMA
127 # warning "fix this code to use new CPU partition APIs"
129 /* Fall through to PDL_POLICY_ROUND until the CPU
130 * CPU partition patches are available. */
132 case PDL_POLICY_PREFERRED:
133 if (index >= 0 && index < cfs_num_online_cpus()) {
134 idx = index % ptlrpcds->pd_nthreads;
137 /* Fall through to PDL_POLICY_ROUND for bad index. */
139 /* Fall through to PDL_POLICY_ROUND for unknown policy. */
140 case PDL_POLICY_ROUND:
141 /* We do not care whether it is strict load balance. */
142 idx = ptlrpcds->pd_index + 1;
143 if (idx == cfs_smp_processor_id())
145 idx %= ptlrpcds->pd_nthreads;
146 ptlrpcds->pd_index = idx;
149 #endif /* __KERNEL__ */
151 return &ptlrpcds->pd_threads[idx];
155 * Move all request from an existing request set to the ptlrpcd queue.
156 * All requests from the set must be in phase RQ_PHASE_NEW.
158 void ptlrpcd_add_rqset(struct ptlrpc_request_set *set)
160 cfs_list_t *tmp, *pos;
162 struct ptlrpcd_ctl *pc;
163 struct ptlrpc_request_set *new;
166 pc = ptlrpcd_select_pc(NULL, PDL_POLICY_LOCAL, -1);
170 cfs_list_for_each_safe(pos, tmp, &set->set_requests) {
171 struct ptlrpc_request *req =
172 cfs_list_entry(pos, struct ptlrpc_request,
175 LASSERT(req->rq_phase == RQ_PHASE_NEW);
178 req->rq_queued_time = cfs_time_current();
180 cfs_list_del_init(&req->rq_set_chain);
182 ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
183 cfs_atomic_dec(&set->set_remaining);
188 cfs_spin_lock(&new->set_new_req_lock);
189 cfs_list_splice_init(&set->set_requests, &new->set_new_requests);
190 i = cfs_atomic_read(&set->set_remaining);
191 count = cfs_atomic_add_return(i, &new->set_new_count);
192 cfs_atomic_set(&set->set_remaining, 0);
193 cfs_spin_unlock(&new->set_new_req_lock);
195 cfs_waitq_signal(&new->set_waitq);
197 /* XXX: It maybe unnecessary to wakeup all the partners. But to
198 * guarantee the async RPC can be processed ASAP, we have
199 * no other better choice. It maybe fixed in future. */
200 for (i = 0; i < pc->pc_npartners; i++)
201 cfs_waitq_signal(&pc->pc_partners[i]->pc_set->set_waitq);
205 EXPORT_SYMBOL(ptlrpcd_add_rqset);
209 * Return transferred RPCs count.
211 static int ptlrpcd_steal_rqset(struct ptlrpc_request_set *des,
212 struct ptlrpc_request_set *src)
214 cfs_list_t *tmp, *pos;
215 struct ptlrpc_request *req;
218 cfs_spin_lock(&src->set_new_req_lock);
219 if (likely(!cfs_list_empty(&src->set_new_requests))) {
220 cfs_list_for_each_safe(pos, tmp, &src->set_new_requests) {
221 req = cfs_list_entry(pos, struct ptlrpc_request,
225 cfs_list_splice_init(&src->set_new_requests,
227 rc = cfs_atomic_read(&src->set_new_count);
228 cfs_atomic_add(rc, &des->set_remaining);
229 cfs_atomic_set(&src->set_new_count, 0);
231 cfs_spin_unlock(&src->set_new_req_lock);
237 * Requests that are added to the ptlrpcd queue are sent via
238 * ptlrpcd_check->ptlrpc_check_set().
240 void ptlrpcd_add_req(struct ptlrpc_request *req, pdl_policy_t policy, int idx)
242 struct ptlrpcd_ctl *pc;
244 cfs_spin_lock(&req->rq_lock);
245 if (req->rq_invalid_rqset) {
246 struct l_wait_info lwi = LWI_TIMEOUT(cfs_time_seconds(5),
247 back_to_sleep, NULL);
249 req->rq_invalid_rqset = 0;
250 cfs_spin_unlock(&req->rq_lock);
251 l_wait_event(req->rq_set_waitq, (req->rq_set == NULL), &lwi);
252 } else if (req->rq_set) {
253 /* If we have a vaid "rq_set", just reuse it to avoid double
255 LASSERT(req->rq_phase == RQ_PHASE_NEW);
256 LASSERT(req->rq_send_state == LUSTRE_IMP_REPLAY);
258 /* ptlrpc_check_set will decrease the count */
259 cfs_atomic_inc(&req->rq_set->set_remaining);
260 cfs_spin_unlock(&req->rq_lock);
261 cfs_waitq_signal(&req->rq_set->set_waitq);
264 cfs_spin_unlock(&req->rq_lock);
267 pc = ptlrpcd_select_pc(req, policy, idx);
269 DEBUG_REQ(D_INFO, req, "add req [%p] to pc [%s:%d]",
270 req, pc->pc_name, pc->pc_index);
272 ptlrpc_set_add_new_req(pc, req);
275 static inline void ptlrpc_reqset_get(struct ptlrpc_request_set *set)
277 cfs_atomic_inc(&set->set_refcount);
281 * Check if there is more work to do on ptlrpcd set.
284 static int ptlrpcd_check(const struct lu_env *env, struct ptlrpcd_ctl *pc)
286 cfs_list_t *tmp, *pos;
287 struct ptlrpc_request *req;
288 struct ptlrpc_request_set *set = pc->pc_set;
292 if (cfs_atomic_read(&set->set_new_count)) {
293 cfs_spin_lock(&set->set_new_req_lock);
294 if (likely(!cfs_list_empty(&set->set_new_requests))) {
295 cfs_list_splice_init(&set->set_new_requests,
297 cfs_atomic_add(cfs_atomic_read(&set->set_new_count),
298 &set->set_remaining);
299 cfs_atomic_set(&set->set_new_count, 0);
301 * Need to calculate its timeout.
305 cfs_spin_unlock(&set->set_new_req_lock);
308 if (cfs_atomic_read(&set->set_remaining))
309 rc |= ptlrpc_check_set(env, set);
311 if (!cfs_list_empty(&set->set_requests)) {
313 * XXX: our set never completes, so we prune the completed
314 * reqs after each iteration. boy could this be smarter.
316 cfs_list_for_each_safe(pos, tmp, &set->set_requests) {
317 req = cfs_list_entry(pos, struct ptlrpc_request,
319 if (req->rq_phase != RQ_PHASE_COMPLETE)
322 cfs_list_del_init(&req->rq_set_chain);
324 ptlrpc_req_finished(req);
330 * If new requests have been added, make sure to wake up.
332 rc = cfs_atomic_read(&set->set_new_count);
335 /* If we have nothing to do, check whether we can take some
336 * work from our partner threads. */
337 if (rc == 0 && pc->pc_npartners > 0) {
338 struct ptlrpcd_ctl *partner;
339 struct ptlrpc_request_set *ps;
340 int first = pc->pc_cursor;
343 partner = pc->pc_partners[pc->pc_cursor++];
344 if (pc->pc_cursor >= pc->pc_npartners)
349 cfs_spin_lock(&partner->pc_lock);
350 ps = partner->pc_set;
352 cfs_spin_unlock(&partner->pc_lock);
356 ptlrpc_reqset_get(ps);
357 cfs_spin_unlock(&partner->pc_lock);
359 if (cfs_atomic_read(&ps->set_new_count)) {
360 rc = ptlrpcd_steal_rqset(set, ps);
362 CDEBUG(D_RPCTRACE, "transfer %d"
363 " async RPCs [%d->%d]\n",
367 ptlrpc_reqset_put(ps);
368 } while (rc == 0 && pc->pc_cursor != first);
378 * Main ptlrpcd thread.
379 * ptlrpc's code paths like to execute in process context, so we have this
380 * thread which spins on a set which contains the rpcs and sends them.
383 static int ptlrpcd(void *arg)
385 struct ptlrpcd_ctl *pc = arg;
386 struct ptlrpc_request_set *set = pc->pc_set;
387 struct lu_env env = { .le_ses = NULL };
391 cfs_daemonize_ctxt(pc->pc_name);
392 #if defined(CONFIG_SMP) && defined(HAVE_NODE_TO_CPUMASK)
393 if (cfs_test_bit(LIOD_BIND, &pc->pc_flags)) {
394 int index = pc->pc_index;
396 if (index >= 0 && index < cfs_num_possible_cpus()) {
397 while (!cfs_cpu_online(index)) {
398 if (++index >= cfs_num_possible_cpus())
401 cfs_set_cpus_allowed(cfs_current(),
402 node_to_cpumask(cpu_to_node(index)));
407 * XXX So far only "client" ptlrpcd uses an environment. In
408 * the future, ptlrpcd thread (or a thread-set) has to given
409 * an argument, describing its "scope".
411 rc = lu_context_init(&env.le_ctx,
412 LCT_CL_THREAD|LCT_REMEMBER|LCT_NOREF);
413 cfs_complete(&pc->pc_starting);
419 * This mainloop strongly resembles ptlrpc_set_wait() except that our
420 * set never completes. ptlrpcd_check() calls ptlrpc_check_set() when
421 * there are requests in the set. New requests come in on the set's
422 * new_req_list and ptlrpcd_check() moves them into the set.
425 struct l_wait_info lwi;
428 rc = lu_env_refill(&env);
431 * XXX This is very awkward situation, because
432 * execution can neither continue (request
433 * interpreters assume that env is set up), nor repeat
434 * the loop (as this potentially results in a tight
435 * loop of -ENOMEM's).
437 * Fortunately, refill only ever does something when
438 * new modules are loaded, i.e., early during boot up.
440 CERROR("Failure to refill session: %d\n", rc);
444 timeout = ptlrpc_set_next_timeout(set);
445 lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1),
446 ptlrpc_expired_set, set);
448 lu_context_enter(&env.le_ctx);
449 l_wait_event(set->set_waitq,
450 ptlrpcd_check(&env, pc), &lwi);
451 lu_context_exit(&env.le_ctx);
454 * Abort inflight rpcs for forced stop case.
456 if (cfs_test_bit(LIOD_STOP, &pc->pc_flags)) {
457 if (cfs_test_bit(LIOD_FORCE, &pc->pc_flags))
458 ptlrpc_abort_set(set);
463 * Let's make one more loop to make sure that ptlrpcd_check()
464 * copied all raced new rpcs into the set so we can kill them.
469 * Wait for inflight requests to drain.
471 if (!cfs_list_empty(&set->set_requests))
472 ptlrpc_set_wait(set);
473 lu_context_fini(&env.le_ctx);
474 cfs_complete(&pc->pc_finishing);
476 cfs_clear_bit(LIOD_START, &pc->pc_flags);
477 cfs_clear_bit(LIOD_STOP, &pc->pc_flags);
478 cfs_clear_bit(LIOD_FORCE, &pc->pc_flags);
479 cfs_clear_bit(LIOD_BIND, &pc->pc_flags);
483 /* XXX: We want multiple CPU cores to share the async RPC load. So we start many
484 * ptlrpcd threads. We also want to reduce the ptlrpcd overhead caused by
485 * data transfer cross-CPU cores. So we bind ptlrpcd thread to specified
486 * CPU core. But binding all ptlrpcd threads maybe cause response delay
487 * because of some CPU core(s) busy with other loads.
489 * For example: "ls -l", some async RPCs for statahead are assigned to
490 * ptlrpcd_0, and ptlrpcd_0 is bound to CPU_0, but CPU_0 may be quite busy
491 * with other non-ptlrpcd, like "ls -l" itself (we want to the "ls -l"
492 * thread, statahead thread, and ptlrpcd thread can run in parallel), under
493 * such case, the statahead async RPCs can not be processed in time, it is
494 * unexpected. If ptlrpcd_0 can be re-scheduled on other CPU core, it may
495 * be better. But it breaks former data transfer policy.
497 * So we shouldn't be blind for avoiding the data transfer. We make some
498 * compromise: divide the ptlrpcd threds pool into two parts. One part is
499 * for bound mode, each ptlrpcd thread in this part is bound to some CPU
500 * core. The other part is for free mode, all the ptlrpcd threads in the
501 * part can be scheduled on any CPU core. We specify some partnership
502 * between bound mode ptlrpcd thread(s) and free mode ptlrpcd thread(s),
503 * and the async RPC load within the partners are shared.
505 * It can partly avoid data transfer cross-CPU (if the bound mode ptlrpcd
506 * thread can be scheduled in time), and try to guarantee the async RPC
507 * processed ASAP (as long as the free mode ptlrpcd thread can be scheduled
510 * As for how to specify the partnership between bound mode ptlrpcd
511 * thread(s) and free mode ptlrpcd thread(s), the simplest way is to use
512 * <free bound> pair. In future, we can specify some more complex
513 * partnership based on the patches for CPU partition. But before such
514 * patches are available, we prefer to use the simplest one.
516 # ifdef CFS_CPU_MODE_NUMA
517 # warning "fix ptlrpcd_bind() to use new CPU partition APIs"
519 static int ptlrpcd_bind(int index, int max)
521 struct ptlrpcd_ctl *pc;
525 LASSERT(index <= max - 1);
526 pc = &ptlrpcds->pd_threads[index];
527 switch (ptlrpcd_bind_policy) {
528 case PDB_POLICY_NONE:
529 pc->pc_npartners = -1;
531 case PDB_POLICY_FULL:
532 pc->pc_npartners = 0;
533 cfs_set_bit(LIOD_BIND, &pc->pc_flags);
535 case PDB_POLICY_PAIR:
536 LASSERT(max % 2 == 0);
537 pc->pc_npartners = 1;
539 case PDB_POLICY_NEIGHBOR:
541 pc->pc_npartners = 2;
544 CERROR("unknown ptlrpcd bind policy %d\n", ptlrpcd_bind_policy);
548 if (rc == 0 && pc->pc_npartners > 0) {
549 OBD_ALLOC(pc->pc_partners,
550 sizeof(struct ptlrpcd_ctl *) * pc->pc_npartners);
551 if (pc->pc_partners == NULL) {
552 pc->pc_npartners = 0;
556 cfs_set_bit(LIOD_BIND, &pc->pc_flags);
558 switch (ptlrpcd_bind_policy) {
559 case PDB_POLICY_PAIR:
561 pc->pc_partners[0] = &ptlrpcds->
562 pd_threads[index - 1];
563 ptlrpcds->pd_threads[index - 1].
567 case PDB_POLICY_NEIGHBOR:
569 pc->pc_partners[0] = &ptlrpcds->
570 pd_threads[index - 1];
571 ptlrpcds->pd_threads[index - 1].
573 if (index == max - 1) {
575 &ptlrpcds->pd_threads[0];
576 ptlrpcds->pd_threads[0].
588 #else /* !__KERNEL__ */
591 * In liblustre we do not have separate threads, so this function
592 * is called from time to time all across common code to see
593 * if something needs to be processed on ptlrpcd set.
595 int ptlrpcd_check_async_rpcs(void *arg)
597 struct ptlrpcd_ctl *pc = arg;
605 if (pc->pc_recurred == 1) {
606 rc = lu_env_refill(&pc->pc_env);
608 lu_context_enter(&pc->pc_env.le_ctx);
609 rc = ptlrpcd_check(&pc->pc_env, pc);
611 ptlrpc_expired_set(pc->pc_set);
613 * XXX: send replay requests.
615 if (cfs_test_bit(LIOD_RECOVERY, &pc->pc_flags))
616 rc = ptlrpcd_check(&pc->pc_env, pc);
617 lu_context_exit(&pc->pc_env.le_ctx);
625 int ptlrpcd_idle(void *arg)
627 struct ptlrpcd_ctl *pc = arg;
629 return (cfs_atomic_read(&pc->pc_set->set_new_count) == 0 &&
630 cfs_atomic_read(&pc->pc_set->set_remaining) == 0);
635 int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc)
642 * Do not allow start second thread for one pc.
644 if (cfs_test_and_set_bit(LIOD_START, &pc->pc_flags)) {
645 CWARN("Starting second thread (%s) for same pc %p\n",
650 pc->pc_index = index;
651 cfs_init_completion(&pc->pc_starting);
652 cfs_init_completion(&pc->pc_finishing);
653 cfs_spin_lock_init(&pc->pc_lock);
654 strncpy(pc->pc_name, name, sizeof(pc->pc_name) - 1);
655 pc->pc_set = ptlrpc_prep_set();
656 if (pc->pc_set == NULL)
657 GOTO(out, rc = -ENOMEM);
659 * So far only "client" ptlrpcd uses an environment. In the future,
660 * ptlrpcd thread (or a thread-set) has to be given an argument,
661 * describing its "scope".
663 rc = lu_context_init(&pc->pc_env.le_ctx, LCT_CL_THREAD|LCT_REMEMBER);
670 rc = ptlrpcd_bind(index, max);
675 rc = cfs_create_thread(ptlrpcd, pc, 0);
680 cfs_wait_for_completion(&pc->pc_starting);
682 pc->pc_wait_callback =
683 liblustre_register_wait_callback("ptlrpcd_check_async_rpcs",
684 &ptlrpcd_check_async_rpcs, pc);
685 pc->pc_idle_callback =
686 liblustre_register_idle_callback("ptlrpcd_check_idle_rpcs",
692 if (pc->pc_set != NULL) {
693 struct ptlrpc_request_set *set = pc->pc_set;
695 cfs_spin_lock(&pc->pc_lock);
697 cfs_spin_unlock(&pc->pc_lock);
698 ptlrpc_set_destroy(set);
701 lu_context_fini(&pc->pc_env.le_ctx);
702 cfs_clear_bit(LIOD_BIND, &pc->pc_flags);
704 cfs_clear_bit(LIOD_START, &pc->pc_flags);
709 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force)
711 struct ptlrpc_request_set *set = pc->pc_set;
714 if (!cfs_test_bit(LIOD_START, &pc->pc_flags)) {
715 CWARN("Thread for pc %p was not started\n", pc);
719 cfs_set_bit(LIOD_STOP, &pc->pc_flags);
721 cfs_set_bit(LIOD_FORCE, &pc->pc_flags);
722 cfs_waitq_signal(&pc->pc_set->set_waitq);
724 cfs_wait_for_completion(&pc->pc_finishing);
726 liblustre_deregister_wait_callback(pc->pc_wait_callback);
727 liblustre_deregister_idle_callback(pc->pc_idle_callback);
729 lu_context_fini(&pc->pc_env.le_ctx);
731 cfs_spin_lock(&pc->pc_lock);
733 cfs_spin_unlock(&pc->pc_lock);
734 ptlrpc_set_destroy(set);
738 if (pc->pc_npartners > 0) {
739 LASSERT(pc->pc_partners != NULL);
741 OBD_FREE(pc->pc_partners,
742 sizeof(struct ptlrpcd_ctl *) * pc->pc_npartners);
743 pc->pc_partners = NULL;
745 pc->pc_npartners = 0;
750 static void ptlrpcd_fini(void)
755 if (ptlrpcds != NULL) {
756 for (i = 0; i < ptlrpcds->pd_nthreads; i++)
757 ptlrpcd_stop(&ptlrpcds->pd_threads[i], 0);
758 ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
759 OBD_FREE(ptlrpcds, ptlrpcds->pd_size);
766 static int ptlrpcd_init(void)
768 int nthreads = cfs_num_online_cpus();
770 int size, i = -1, j, rc = 0;
774 if (max_ptlrpcds > 0 && max_ptlrpcds < nthreads)
775 nthreads = max_ptlrpcds;
778 if (nthreads < 3 && ptlrpcd_bind_policy == PDB_POLICY_NEIGHBOR)
779 ptlrpcd_bind_policy = PDB_POLICY_PAIR;
780 else if (nthreads % 2 != 0 && ptlrpcd_bind_policy == PDB_POLICY_PAIR)
781 nthreads &= ~1; /* make sure it is even */
786 size = offsetof(struct ptlrpcd, pd_threads[nthreads]);
787 OBD_ALLOC(ptlrpcds, size);
788 if (ptlrpcds == NULL)
789 GOTO(out, rc = -ENOMEM);
791 snprintf(name, 15, "ptlrpcd_rcv");
792 cfs_set_bit(LIOD_RECOVERY, &ptlrpcds->pd_thread_rcv.pc_flags);
793 rc = ptlrpcd_start(-1, nthreads, name, &ptlrpcds->pd_thread_rcv);
797 /* XXX: We start nthreads ptlrpc daemons. Each of them can process any
798 * non-recovery async RPC to improve overall async RPC efficiency.
800 * But there are some issues with async I/O RPCs and async non-I/O
801 * RPCs processed in the same set under some cases. The ptlrpcd may
802 * be blocked by some async I/O RPC(s), then will cause other async
803 * non-I/O RPC(s) can not be processed in time.
805 * Maybe we should distinguish blocked async RPCs from non-blocked
806 * async RPCs, and process them in different ptlrpcd sets to avoid
807 * unnecessary dependency. But how to distribute async RPCs load
808 * among all the ptlrpc daemons becomes another trouble. */
809 for (i = 0; i < nthreads; i++) {
810 snprintf(name, 15, "ptlrpcd_%d", i);
811 rc = ptlrpcd_start(i, nthreads, name, &ptlrpcds->pd_threads[i]);
816 ptlrpcds->pd_size = size;
817 ptlrpcds->pd_index = 0;
818 ptlrpcds->pd_nthreads = nthreads;
821 if (rc != 0 && ptlrpcds != NULL) {
822 for (j = 0; j <= i; j++)
823 ptlrpcd_stop(&ptlrpcds->pd_threads[j], 0);
824 ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
825 OBD_FREE(ptlrpcds, size);
832 int ptlrpcd_addref(void)
837 cfs_mutex_down(&ptlrpcd_sem);
838 if (++ptlrpcd_users == 1)
840 cfs_mutex_up(&ptlrpcd_sem);
844 void ptlrpcd_decref(void)
846 cfs_mutex_down(&ptlrpcd_sem);
847 if (--ptlrpcd_users == 0)
849 cfs_mutex_up(&ptlrpcd_sem);