Whamcloud - gitweb
LU-1425 build: make Lustre build ready for gcov
[fs/lustre-release.git] / lnet / lnet / lib-ptl.c
index 1cfc87c..527a28a 100644 (file)
@@ -39,7 +39,7 @@
 #include <lnet/lib-lnet.h>
 
 /* NB: add /proc interfaces in upcoming patches */
 #include <lnet/lib-lnet.h>
 
 /* NB: add /proc interfaces in upcoming patches */
-int    portal_rotor;
+int    portal_rotor    = LNET_PTL_ROTOR_HASH_RT;
 CFS_MODULE_PARM(portal_rotor, "i", int, 0644,
                "redirect PUTs to different cpu-partitions");
 
 CFS_MODULE_PARM(portal_rotor, "i", int, 0644,
                "redirect PUTs to different cpu-partitions");
 
@@ -259,34 +259,42 @@ lnet_mt_of_attach(unsigned int index, lnet_process_id_t id,
        }
 }
 
        }
 }
 
-struct lnet_match_table *
-lnet_mt_of_match(unsigned int index, lnet_process_id_t id, __u64 mbits)
+static struct lnet_match_table *
+lnet_mt_of_match(struct lnet_match_info *info, struct lnet_msg *msg)
 {
        struct lnet_match_table *mtable;
        struct lnet_portal      *ptl;
        int                     nmaps;
        int                     rotor;
 {
        struct lnet_match_table *mtable;
        struct lnet_portal      *ptl;
        int                     nmaps;
        int                     rotor;
+       int                     routed;
        int                     cpt;
 
        /* NB: called w/o lock */
        int                     cpt;
 
        /* NB: called w/o lock */
-       LASSERT(index < the_lnet.ln_nportals);
-       ptl = the_lnet.ln_portals[index];
+       LASSERT(info->mi_portal < the_lnet.ln_nportals);
+       ptl = the_lnet.ln_portals[info->mi_portal];
 
        LASSERT(lnet_ptl_is_wildcard(ptl) || lnet_ptl_is_unique(ptl));
 
 
        LASSERT(lnet_ptl_is_wildcard(ptl) || lnet_ptl_is_unique(ptl));
 
-       mtable = lnet_match2mt(ptl, id, mbits);
+       mtable = lnet_match2mt(ptl, info->mi_id, info->mi_mbits);
        if (mtable != NULL)
                return mtable;
 
        /* it's a wildcard portal */
        if (mtable != NULL)
                return mtable;
 
        /* it's a wildcard portal */
-       if (!portal_rotor) {
+       routed = LNET_NIDNET(msg->msg_hdr.src_nid) !=
+                LNET_NIDNET(msg->msg_hdr.dest_nid);
+
+       if (portal_rotor == LNET_PTL_ROTOR_OFF ||
+           (portal_rotor != LNET_PTL_ROTOR_ON && !routed)) {
                cpt = lnet_cpt_current();
                if (ptl->ptl_mtables[cpt]->mt_enabled)
                        return ptl->ptl_mtables[cpt];
        }
 
                cpt = lnet_cpt_current();
                if (ptl->ptl_mtables[cpt]->mt_enabled)
                        return ptl->ptl_mtables[cpt];
        }
 
-       rotor = ptl->ptl_rotor++;
-       cpt = rotor % LNET_CPT_NUMBER;
+       rotor = ptl->ptl_rotor++; /* get round-robin factor */
+       if (portal_rotor == LNET_PTL_ROTOR_HASH_RT && routed)
+               cpt = lnet_cpt_of_nid(msg->msg_hdr.src_nid);
+       else
+               cpt = rotor % LNET_CPT_NUMBER;
 
        if (!ptl->ptl_mtables[cpt]->mt_enabled) {
                /* is there any active entry for this portal? */
 
        if (!ptl->ptl_mtables[cpt]->mt_enabled) {
                /* is there any active entry for this portal? */
@@ -303,6 +311,49 @@ lnet_mt_of_match(unsigned int index, lnet_process_id_t id, __u64 mbits)
        return ptl->ptl_mtables[cpt];
 }
 
        return ptl->ptl_mtables[cpt];
 }
 
+static int
+lnet_mt_test_exhausted(struct lnet_match_table *mtable, int pos)
+{
+       __u64   *bmap;
+       int     i;
+
+       if (!lnet_ptl_is_wildcard(the_lnet.ln_portals[mtable->mt_portal]))
+               return 0;
+
+       if (pos < 0) { /* check all bits */
+               for (i = 0; i < LNET_MT_EXHAUSTED_BMAP; i++) {
+                       if (mtable->mt_exhausted[i] != (__u64)(-1))
+                               return 0;
+               }
+               return 1;
+       }
+
+       LASSERT(pos <= LNET_MT_HASH_IGNORE);
+       /* mtable::mt_mhash[pos] is marked as exhausted or not */
+       bmap = &mtable->mt_exhausted[pos >> LNET_MT_BITS_U64];
+       pos &= (1 << LNET_MT_BITS_U64) - 1;
+
+       return ((*bmap) & (1ULL << pos)) != 0;
+}
+
+static void
+lnet_mt_set_exhausted(struct lnet_match_table *mtable, int pos, int exhausted)
+{
+       __u64   *bmap;
+
+       LASSERT(lnet_ptl_is_wildcard(the_lnet.ln_portals[mtable->mt_portal]));
+       LASSERT(pos <= LNET_MT_HASH_IGNORE);
+
+       /* set mtable::mt_mhash[pos] as exhausted/non-exhausted */
+       bmap = &mtable->mt_exhausted[pos >> LNET_MT_BITS_U64];
+       pos &= (1 << LNET_MT_BITS_U64) - 1;
+
+       if (!exhausted)
+               *bmap &= ~(1ULL << pos);
+       else
+               *bmap |= 1ULL << pos;
+}
+
 cfs_list_t *
 lnet_mt_match_head(struct lnet_match_table *mtable,
                   lnet_process_id_t id, __u64 mbits)
 cfs_list_t *
 lnet_mt_match_head(struct lnet_match_table *mtable,
                   lnet_process_id_t id, __u64 mbits)
@@ -310,8 +361,7 @@ lnet_mt_match_head(struct lnet_match_table *mtable,
        struct lnet_portal *ptl = the_lnet.ln_portals[mtable->mt_portal];
 
        if (lnet_ptl_is_wildcard(ptl)) {
        struct lnet_portal *ptl = the_lnet.ln_portals[mtable->mt_portal];
 
        if (lnet_ptl_is_wildcard(ptl)) {
-               return &mtable->mt_mlist;
-
+               return &mtable->mt_mhash[mbits & LNET_MT_HASH_MASK];
        } else {
                unsigned long hash = mbits + id.nid + id.pid;
 
        } else {
                unsigned long hash = mbits + id.nid + id.pid;
 
@@ -331,12 +381,16 @@ lnet_mt_match_md(struct lnet_match_table *mtable,
        int                     exhausted = 0;
        int                     rc;
 
        int                     exhausted = 0;
        int                     rc;
 
-       /* NB: only wildcard portal can return LNET_MATCHMD_EXHAUSTED */
+       /* any ME with ignore bits? */
+       if (!cfs_list_empty(&mtable->mt_mhash[LNET_MT_HASH_IGNORE]))
+               head = &mtable->mt_mhash[LNET_MT_HASH_IGNORE];
+       else
+               head = lnet_mt_match_head(mtable, info->mi_id, info->mi_mbits);
+ again:
+       /* NB: only wildcard portal needs to return LNET_MATCHMD_EXHAUSTED */
        if (lnet_ptl_is_wildcard(the_lnet.ln_portals[mtable->mt_portal]))
                exhausted = LNET_MATCHMD_EXHAUSTED;
 
        if (lnet_ptl_is_wildcard(the_lnet.ln_portals[mtable->mt_portal]))
                exhausted = LNET_MATCHMD_EXHAUSTED;
 
-       head = lnet_mt_match_head(mtable, info->mi_id, info->mi_mbits);
-
        cfs_list_for_each_entry_safe(me, tmp, head, me_list) {
                /* ME attached but MD not attached yet */
                if (me->me_md == NULL)
        cfs_list_for_each_entry_safe(me, tmp, head, me_list) {
                /* ME attached but MD not attached yet */
                if (me->me_md == NULL)
@@ -355,6 +409,17 @@ lnet_mt_match_md(struct lnet_match_table *mtable,
                }
        }
 
                }
        }
 
+       if (exhausted == LNET_MATCHMD_EXHAUSTED) { /* @head is exhausted */
+               lnet_mt_set_exhausted(mtable, head - mtable->mt_mhash, 1);
+               if (!lnet_mt_test_exhausted(mtable, -1))
+                       exhausted = 0;
+       }
+
+       if (exhausted == 0 && head == &mtable->mt_mhash[LNET_MT_HASH_IGNORE]) {
+               head = lnet_mt_match_head(mtable, info->mi_id, info->mi_mbits);
+               goto again; /* re-check MEs w/o ignore-bits */
+       }
+
        if (info->mi_opc == LNET_MD_OP_GET ||
            !lnet_ptl_is_lazy(the_lnet.ln_portals[info->mi_portal]))
                return LNET_MATCHMD_DROP | exhausted;
        if (info->mi_opc == LNET_MD_OP_GET ||
            !lnet_ptl_is_lazy(the_lnet.ln_portals[info->mi_portal]))
                return LNET_MATCHMD_DROP | exhausted;
@@ -491,8 +556,7 @@ lnet_ptl_match_md(struct lnet_match_info *info, struct lnet_msg *msg)
        if (rc != 0) /* matched or delayed early message */
                return rc;
 
        if (rc != 0) /* matched or delayed early message */
                return rc;
 
-       mtable = lnet_mt_of_match(info->mi_portal,
-                                 info->mi_id, info->mi_mbits);
+       mtable = lnet_mt_of_match(info, msg);
        lnet_res_lock(mtable->mt_cpt);
 
        if (the_lnet.ln_shutdown) {
        lnet_res_lock(mtable->mt_cpt);
 
        if (the_lnet.ln_shutdown) {
@@ -578,7 +642,7 @@ lnet_ptl_attach_md(lnet_me_t *me, lnet_libmd_t *md,
 
        if (cfs_list_empty(&ptl->ptl_msg_stealing) &&
            cfs_list_empty(&ptl->ptl_msg_delayed) &&
 
        if (cfs_list_empty(&ptl->ptl_msg_stealing) &&
            cfs_list_empty(&ptl->ptl_msg_delayed) &&
-           mtable->mt_enabled)
+           !lnet_mt_test_exhausted(mtable, me->me_pos))
                return;
 
        lnet_ptl_lock(ptl);
                return;
 
        lnet_ptl_lock(ptl);
@@ -641,8 +705,11 @@ lnet_ptl_attach_md(lnet_me_t *me, lnet_libmd_t *md,
                goto again;
        }
 
                goto again;
        }
 
-       if (lnet_ptl_is_wildcard(ptl) && !exhausted && !mtable->mt_enabled)
-               lnet_ptl_enable_mt(ptl, cpt);
+       if (lnet_ptl_is_wildcard(ptl) && !exhausted) {
+               lnet_mt_set_exhausted(mtable, me->me_pos, 0);
+               if (!mtable->mt_enabled)
+                       lnet_ptl_enable_mt(ptl, cpt);
+       }
 
        lnet_ptl_unlock(ptl);
 }
 
        lnet_ptl_unlock(ptl);
 }
@@ -673,25 +740,17 @@ lnet_ptl_cleanup(struct lnet_portal *ptl)
 
                mhash = mtable->mt_mhash;
                /* cleanup ME */
 
                mhash = mtable->mt_mhash;
                /* cleanup ME */
-               while (!cfs_list_empty(&mtable->mt_mlist)) {
-                       me = cfs_list_entry(mtable->mt_mlist.next,
-                                           lnet_me_t, me_list);
-                       CERROR("Active wildcard ME %p on exit\n", me);
-                       cfs_list_del(&me->me_list);
-                       lnet_me_free(me);
-               }
-
-               for (j = 0; j < LNET_MT_HASH_SIZE; j++) {
+               for (j = 0; j < LNET_MT_HASH_SIZE + 1; j++) {
                        while (!cfs_list_empty(&mhash[j])) {
                                me = cfs_list_entry(mhash[j].next,
                                                    lnet_me_t, me_list);
                        while (!cfs_list_empty(&mhash[j])) {
                                me = cfs_list_entry(mhash[j].next,
                                                    lnet_me_t, me_list);
-                               CERROR("Active unique ME %p on exit\n", me);
+                               CERROR("Active ME %p on exit\n", me);
                                cfs_list_del(&me->me_list);
                                lnet_me_free(me);
                        }
                }
                                cfs_list_del(&me->me_list);
                                lnet_me_free(me);
                        }
                }
-
-               LIBCFS_FREE(mhash, sizeof(*mhash) * LNET_MT_HASH_SIZE);
+               /* the extra entry is for MEs with ignore bits */
+               LIBCFS_FREE(mhash, sizeof(*mhash) * (LNET_MT_HASH_SIZE + 1));
        }
 
        cfs_percpt_free(ptl->ptl_mtables);
        }
 
        cfs_percpt_free(ptl->ptl_mtables);
@@ -724,19 +783,22 @@ lnet_ptl_setup(struct lnet_portal *ptl, int index)
 # endif
 #endif
        cfs_percpt_for_each(mtable, i, ptl->ptl_mtables) {
 # endif
 #endif
        cfs_percpt_for_each(mtable, i, ptl->ptl_mtables) {
+               /* the extra entry is for MEs with ignore bits */
                LIBCFS_CPT_ALLOC(mhash, lnet_cpt_table(), i,
                LIBCFS_CPT_ALLOC(mhash, lnet_cpt_table(), i,
-                                sizeof(*mhash) * LNET_MT_HASH_SIZE);
+                                sizeof(*mhash) * (LNET_MT_HASH_SIZE + 1));
                if (mhash == NULL) {
                        CERROR("Failed to create match hash for portal %d\n",
                               index);
                        goto failed;
                }
 
                if (mhash == NULL) {
                        CERROR("Failed to create match hash for portal %d\n",
                               index);
                        goto failed;
                }
 
+               memset(&mtable->mt_exhausted[0], -1,
+                      sizeof(mtable->mt_exhausted[0]) *
+                      LNET_MT_EXHAUSTED_BMAP);
                mtable->mt_mhash = mhash;
                mtable->mt_mhash = mhash;
-               for (j = 0; j < LNET_MT_HASH_SIZE; j++)
+               for (j = 0; j < LNET_MT_HASH_SIZE + 1; j++)
                        CFS_INIT_LIST_HEAD(&mhash[j]);
 
                        CFS_INIT_LIST_HEAD(&mhash[j]);
 
-               CFS_INIT_LIST_HEAD(&mtable->mt_mlist);
                mtable->mt_portal = index;
                mtable->mt_cpt = i;
        }
                mtable->mt_portal = index;
                mtable->mt_cpt = i;
        }
@@ -836,6 +898,7 @@ LNetSetLazyPortal(int portal)
 
        return 0;
 }
 
        return 0;
 }
+EXPORT_SYMBOL(LNetSetLazyPortal);
 
 /**
  * Turn off the lazy portal attribute. Delayed requests on the portal,
 
 /**
  * Turn off the lazy portal attribute. Delayed requests on the portal,
@@ -883,3 +946,4 @@ LNetClearLazyPortal(int portal)
 
        return 0;
 }
 
        return 0;
 }
+EXPORT_SYMBOL(LNetClearLazyPortal);