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 LASSERT(req->rq_phase == RQ_PHASE_NEW);
254 LASSERT(req->rq_send_state == LUSTRE_IMP_REPLAY);
256 /* ptlrpc_check_set will decrease the count */
257 cfs_atomic_inc(&req->rq_set->set_remaining);
258 cfs_spin_unlock(&req->rq_lock);
259 cfs_waitq_signal(&req->rq_set->set_waitq);
262 cfs_spin_unlock(&req->rq_lock);
265 pc = ptlrpcd_select_pc(req, policy, idx);
267 DEBUG_REQ(D_INFO, req, "add req [%p] to pc [%s:%d]",
268 req, pc->pc_name, pc->pc_index);
270 ptlrpc_set_add_new_req(pc, req);
273 static inline void ptlrpc_reqset_get(struct ptlrpc_request_set *set)
275 cfs_atomic_inc(&set->set_refcount);
279 * Check if there is more work to do on ptlrpcd set.
282 static int ptlrpcd_check(const struct lu_env *env, struct ptlrpcd_ctl *pc)
284 cfs_list_t *tmp, *pos;
285 struct ptlrpc_request *req;
286 struct ptlrpc_request_set *set = pc->pc_set;
290 if (cfs_atomic_read(&set->set_new_count)) {
291 cfs_spin_lock(&set->set_new_req_lock);
292 if (likely(!cfs_list_empty(&set->set_new_requests))) {
293 cfs_list_splice_init(&set->set_new_requests,
295 cfs_atomic_add(cfs_atomic_read(&set->set_new_count),
296 &set->set_remaining);
297 cfs_atomic_set(&set->set_new_count, 0);
299 * Need to calculate its timeout.
303 cfs_spin_unlock(&set->set_new_req_lock);
306 if (cfs_atomic_read(&set->set_remaining))
307 rc |= ptlrpc_check_set(env, set);
309 if (!cfs_list_empty(&set->set_requests)) {
311 * XXX: our set never completes, so we prune the completed
312 * reqs after each iteration. boy could this be smarter.
314 cfs_list_for_each_safe(pos, tmp, &set->set_requests) {
315 req = cfs_list_entry(pos, struct ptlrpc_request,
317 if (req->rq_phase != RQ_PHASE_COMPLETE)
320 cfs_list_del_init(&req->rq_set_chain);
322 ptlrpc_req_finished(req);
328 * If new requests have been added, make sure to wake up.
330 rc = cfs_atomic_read(&set->set_new_count);
333 if (rc == 0 && pc->pc_npartners > 0) {
334 struct ptlrpcd_ctl *partner;
335 struct ptlrpc_request_set *ps;
336 int first = pc->pc_cursor;
339 partner = pc->pc_partners[pc->pc_cursor++];
340 if (pc->pc_cursor >= pc->pc_npartners)
345 cfs_spin_lock(&partner->pc_lock);
346 ps = partner->pc_set;
348 cfs_spin_unlock(&partner->pc_lock);
352 ptlrpc_reqset_get(ps);
353 cfs_spin_unlock(&partner->pc_lock);
355 if (cfs_atomic_read(&ps->set_new_count)) {
356 rc = ptlrpcd_steal_rqset(set, ps);
358 CDEBUG(D_RPCTRACE, "transfer %d"
359 " async RPCs [%d->%d]\n",
363 ptlrpc_reqset_put(ps);
364 } while (rc == 0 && pc->pc_cursor != first);
374 * Main ptlrpcd thread.
375 * ptlrpc's code paths like to execute in process context, so we have this
376 * thread which spins on a set which contains the rpcs and sends them.
379 static int ptlrpcd(void *arg)
381 struct ptlrpcd_ctl *pc = arg;
382 struct ptlrpc_request_set *set = pc->pc_set;
383 struct lu_env env = { .le_ses = NULL };
387 cfs_daemonize_ctxt(pc->pc_name);
388 #if defined(CONFIG_SMP) && defined(HAVE_NODE_TO_CPUMASK)
389 if (cfs_test_bit(LIOD_BIND, &pc->pc_flags)) {
390 int index = pc->pc_index;
392 if (index >= 0 && index < cfs_num_possible_cpus()) {
393 while (!cfs_cpu_online(index)) {
394 if (++index >= cfs_num_possible_cpus())
397 cfs_set_cpus_allowed(cfs_current(),
398 node_to_cpumask(cpu_to_node(index)));
403 * XXX So far only "client" ptlrpcd uses an environment. In
404 * the future, ptlrpcd thread (or a thread-set) has to given
405 * an argument, describing its "scope".
407 rc = lu_context_init(&env.le_ctx,
408 LCT_CL_THREAD|LCT_REMEMBER|LCT_NOREF);
409 cfs_complete(&pc->pc_starting);
415 * This mainloop strongly resembles ptlrpc_set_wait() except that our
416 * set never completes. ptlrpcd_check() calls ptlrpc_check_set() when
417 * there are requests in the set. New requests come in on the set's
418 * new_req_list and ptlrpcd_check() moves them into the set.
421 struct l_wait_info lwi;
424 rc = lu_env_refill(&env);
427 * XXX This is very awkward situation, because
428 * execution can neither continue (request
429 * interpreters assume that env is set up), nor repeat
430 * the loop (as this potentially results in a tight
431 * loop of -ENOMEM's).
433 * Fortunately, refill only ever does something when
434 * new modules are loaded, i.e., early during boot up.
436 CERROR("Failure to refill session: %d\n", rc);
440 timeout = ptlrpc_set_next_timeout(set);
441 lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1),
442 ptlrpc_expired_set, set);
444 lu_context_enter(&env.le_ctx);
445 l_wait_event(set->set_waitq,
446 ptlrpcd_check(&env, pc), &lwi);
447 lu_context_exit(&env.le_ctx);
450 * Abort inflight rpcs for forced stop case.
452 if (cfs_test_bit(LIOD_STOP, &pc->pc_flags)) {
453 if (cfs_test_bit(LIOD_FORCE, &pc->pc_flags))
454 ptlrpc_abort_set(set);
459 * Let's make one more loop to make sure that ptlrpcd_check()
460 * copied all raced new rpcs into the set so we can kill them.
465 * Wait for inflight requests to drain.
467 if (!cfs_list_empty(&set->set_requests))
468 ptlrpc_set_wait(set);
469 lu_context_fini(&env.le_ctx);
470 cfs_complete(&pc->pc_finishing);
472 cfs_clear_bit(LIOD_START, &pc->pc_flags);
473 cfs_clear_bit(LIOD_STOP, &pc->pc_flags);
474 cfs_clear_bit(LIOD_FORCE, &pc->pc_flags);
475 cfs_clear_bit(LIOD_BIND, &pc->pc_flags);
479 /* XXX: We want multiple CPU cores to share the async RPC load. So we start many
480 * ptlrpcd threads. We also want to reduce the ptlrpcd overhead caused by
481 * data transfer cross-CPU cores. So we bind ptlrpcd thread to specified
482 * CPU core. But binding all ptlrpcd threads maybe cause response delay
483 * because of some CPU core(s) busy with other loads.
485 * For example: "ls -l", some async RPCs for statahead are assigned to
486 * ptlrpcd_0, and ptlrpcd_0 is bound to CPU_0, but CPU_0 may be quite busy
487 * with other non-ptlrpcd, like "ls -l" itself (we want to the "ls -l"
488 * thread, statahead thread, and ptlrpcd thread can run in parallel), under
489 * such case, the statahead async RPCs can not be processed in time, it is
490 * unexpected. If ptlrpcd_0 can be re-scheduled on other CPU core, it may
491 * be better. But it breaks former data transfer policy.
493 * So we shouldn't be blind for avoiding the data transfer. We make some
494 * compromise: divide the ptlrpcd threds pool into two parts. One part is
495 * for bound mode, each ptlrpcd thread in this part is bound to some CPU
496 * core. The other part is for free mode, all the ptlrpcd threads in the
497 * part can be scheduled on any CPU core. We specify some partnership
498 * between bound mode ptlrpcd thread(s) and free mode ptlrpcd thread(s),
499 * and the async RPC load within the partners are shared.
501 * It can partly avoid data transfer cross-CPU (if the bound mode ptlrpcd
502 * thread can be scheduled in time), and try to guarantee the async RPC
503 * processed ASAP (as long as the free mode ptlrpcd thread can be scheduled
506 * As for how to specify the partnership between bound mode ptlrpcd
507 * thread(s) and free mode ptlrpcd thread(s), the simplest way is to use
508 * <free bound> pair. In future, we can specify some more complex
509 * partnership based on the patches for CPU partition. But before such
510 * patches are available, we prefer to use the simplest one.
512 # ifdef CFS_CPU_MODE_NUMA
513 # warning "fix ptlrpcd_bind() to use new CPU partition APIs"
515 static int ptlrpcd_bind(int index, int max)
517 struct ptlrpcd_ctl *pc;
521 LASSERT(index <= max - 1);
522 pc = &ptlrpcds->pd_threads[index];
523 switch (ptlrpcd_bind_policy) {
524 case PDB_POLICY_NONE:
525 pc->pc_npartners = -1;
527 case PDB_POLICY_FULL:
528 pc->pc_npartners = 0;
529 cfs_set_bit(LIOD_BIND, &pc->pc_flags);
531 case PDB_POLICY_PAIR:
532 LASSERT(max % 2 == 0);
533 pc->pc_npartners = 1;
535 case PDB_POLICY_NEIGHBOR:
537 pc->pc_npartners = 2;
540 CERROR("unknown ptlrpcd bind policy %d\n", ptlrpcd_bind_policy);
544 if (rc == 0 && pc->pc_npartners > 0) {
545 OBD_ALLOC(pc->pc_partners,
546 sizeof(struct ptlrpcd_ctl *) * pc->pc_npartners);
547 if (pc->pc_partners == NULL) {
548 pc->pc_npartners = 0;
552 cfs_set_bit(LIOD_BIND, &pc->pc_flags);
554 switch (ptlrpcd_bind_policy) {
555 case PDB_POLICY_PAIR:
557 pc->pc_partners[0] = &ptlrpcds->
558 pd_threads[index - 1];
559 ptlrpcds->pd_threads[index - 1].
563 case PDB_POLICY_NEIGHBOR:
565 pc->pc_partners[0] = &ptlrpcds->
566 pd_threads[index - 1];
567 ptlrpcds->pd_threads[index - 1].
569 if (index == max - 1) {
571 &ptlrpcds->pd_threads[0];
572 ptlrpcds->pd_threads[0].
584 #else /* !__KERNEL__ */
587 * In liblustre we do not have separate threads, so this function
588 * is called from time to time all across common code to see
589 * if something needs to be processed on ptlrpcd set.
591 int ptlrpcd_check_async_rpcs(void *arg)
593 struct ptlrpcd_ctl *pc = arg;
601 if (pc->pc_recurred == 1) {
602 rc = lu_env_refill(&pc->pc_env);
604 lu_context_enter(&pc->pc_env.le_ctx);
605 rc = ptlrpcd_check(&pc->pc_env, pc);
607 ptlrpc_expired_set(pc->pc_set);
609 * XXX: send replay requests.
611 if (cfs_test_bit(LIOD_RECOVERY, &pc->pc_flags))
612 rc = ptlrpcd_check(&pc->pc_env, pc);
613 lu_context_exit(&pc->pc_env.le_ctx);
621 int ptlrpcd_idle(void *arg)
623 struct ptlrpcd_ctl *pc = arg;
625 return (cfs_atomic_read(&pc->pc_set->set_new_count) == 0 &&
626 cfs_atomic_read(&pc->pc_set->set_remaining) == 0);
631 int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc)
638 * Do not allow start second thread for one pc.
640 if (cfs_test_and_set_bit(LIOD_START, &pc->pc_flags)) {
641 CWARN("Starting second thread (%s) for same pc %p\n",
646 pc->pc_index = index;
647 cfs_init_completion(&pc->pc_starting);
648 cfs_init_completion(&pc->pc_finishing);
649 cfs_spin_lock_init(&pc->pc_lock);
650 strncpy(pc->pc_name, name, sizeof(pc->pc_name) - 1);
651 pc->pc_set = ptlrpc_prep_set();
652 if (pc->pc_set == NULL)
653 GOTO(out, rc = -ENOMEM);
655 * So far only "client" ptlrpcd uses an environment. In the future,
656 * ptlrpcd thread (or a thread-set) has to be given an argument,
657 * describing its "scope".
659 rc = lu_context_init(&pc->pc_env.le_ctx, LCT_CL_THREAD|LCT_REMEMBER);
666 rc = ptlrpcd_bind(index, max);
671 rc = cfs_create_thread(ptlrpcd, pc, 0);
676 cfs_wait_for_completion(&pc->pc_starting);
678 pc->pc_wait_callback =
679 liblustre_register_wait_callback("ptlrpcd_check_async_rpcs",
680 &ptlrpcd_check_async_rpcs, pc);
681 pc->pc_idle_callback =
682 liblustre_register_idle_callback("ptlrpcd_check_idle_rpcs",
688 if (pc->pc_set != NULL) {
689 struct ptlrpc_request_set *set = pc->pc_set;
691 cfs_spin_lock(&pc->pc_lock);
693 cfs_spin_unlock(&pc->pc_lock);
694 ptlrpc_set_destroy(set);
697 lu_context_fini(&pc->pc_env.le_ctx);
698 cfs_clear_bit(LIOD_BIND, &pc->pc_flags);
700 cfs_clear_bit(LIOD_START, &pc->pc_flags);
705 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force)
707 struct ptlrpc_request_set *set = pc->pc_set;
710 if (!cfs_test_bit(LIOD_START, &pc->pc_flags)) {
711 CWARN("Thread for pc %p was not started\n", pc);
715 cfs_set_bit(LIOD_STOP, &pc->pc_flags);
717 cfs_set_bit(LIOD_FORCE, &pc->pc_flags);
718 cfs_waitq_signal(&pc->pc_set->set_waitq);
720 cfs_wait_for_completion(&pc->pc_finishing);
722 liblustre_deregister_wait_callback(pc->pc_wait_callback);
723 liblustre_deregister_idle_callback(pc->pc_idle_callback);
725 lu_context_fini(&pc->pc_env.le_ctx);
727 cfs_spin_lock(&pc->pc_lock);
729 cfs_spin_unlock(&pc->pc_lock);
730 ptlrpc_set_destroy(set);
734 if (pc->pc_npartners > 0) {
735 LASSERT(pc->pc_partners != NULL);
737 OBD_FREE(pc->pc_partners,
738 sizeof(struct ptlrpcd_ctl *) * pc->pc_npartners);
739 pc->pc_partners = NULL;
741 pc->pc_npartners = 0;
746 static void ptlrpcd_fini(void)
751 if (ptlrpcds != NULL) {
752 for (i = 0; i < ptlrpcds->pd_nthreads; i++)
753 ptlrpcd_stop(&ptlrpcds->pd_threads[i], 0);
754 ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
755 OBD_FREE(ptlrpcds, ptlrpcds->pd_size);
762 static int ptlrpcd_init(void)
764 int nthreads = cfs_num_online_cpus();
766 int size, i = -1, j, rc = 0;
770 if (max_ptlrpcds > 0 && max_ptlrpcds < nthreads)
771 nthreads = max_ptlrpcds;
774 if (nthreads < 3 && ptlrpcd_bind_policy == PDB_POLICY_NEIGHBOR)
775 ptlrpcd_bind_policy = PDB_POLICY_PAIR;
776 else if (nthreads % 2 != 0 && ptlrpcd_bind_policy == PDB_POLICY_PAIR)
777 nthreads &= ~1; /* make sure it is even */
782 size = offsetof(struct ptlrpcd, pd_threads[nthreads]);
783 OBD_ALLOC(ptlrpcds, size);
784 if (ptlrpcds == NULL)
785 GOTO(out, rc = -ENOMEM);
787 snprintf(name, 15, "ptlrpcd_rcv");
788 cfs_set_bit(LIOD_RECOVERY, &ptlrpcds->pd_thread_rcv.pc_flags);
789 rc = ptlrpcd_start(-1, nthreads, name, &ptlrpcds->pd_thread_rcv);
793 /* XXX: We start nthreads ptlrpc daemons. Each of them can process any
794 * non-recovery async RPC to improve overall async RPC efficiency.
796 * But there are some issues with async I/O RPCs and async non-I/O
797 * RPCs processed in the same set under some cases. The ptlrpcd may
798 * be blocked by some async I/O RPC(s), then will cause other async
799 * non-I/O RPC(s) can not be processed in time.
801 * Maybe we should distinguish blocked async RPCs from non-blocked
802 * async RPCs, and process them in different ptlrpcd sets to avoid
803 * unnecessary dependency. But how to distribute async RPCs load
804 * among all the ptlrpc daemons becomes another trouble. */
805 for (i = 0; i < nthreads; i++) {
806 snprintf(name, 15, "ptlrpcd_%d", i);
807 rc = ptlrpcd_start(i, nthreads, name, &ptlrpcds->pd_threads[i]);
812 ptlrpcds->pd_size = size;
813 ptlrpcds->pd_index = 0;
814 ptlrpcds->pd_nthreads = nthreads;
817 if (rc != 0 && ptlrpcds != NULL) {
818 for (j = 0; j <= i; j++)
819 ptlrpcd_stop(&ptlrpcds->pd_threads[j], 0);
820 ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
821 OBD_FREE(ptlrpcds, size);
828 int ptlrpcd_addref(void)
833 cfs_mutex_down(&ptlrpcd_sem);
834 if (++ptlrpcd_users == 1)
836 cfs_mutex_up(&ptlrpcd_sem);
840 void ptlrpcd_decref(void)
842 cfs_mutex_down(&ptlrpcd_sem);
843 if (--ptlrpcd_users == 0)
845 cfs_mutex_up(&ptlrpcd_sem);