Whamcloud - gitweb
LU-12678 lnet: remove locking protection ln_testprotocompat 56/36856/4
authorMr NeilBrown <neilb@suse.de>
Fri, 17 Jan 2020 19:36:51 +0000 (14:36 -0500)
committerOleg Drokin <green@whamcloud.com>
Thu, 23 Jan 2020 05:31:42 +0000 (05:31 +0000)
lnet_net_lock(LNET_LOCK_EX) is a heavy-weight lock that is not
necessary here.  The bits in this field are only set rarely - via an
ioctl - and the pattern for reading and clearing them exactly
matches test_and_clear_bit().  So change the field to "unsigned
long" (so test_and_clear_bit() can be used), and use
test_and_clear_bit(), discarding all other locking.

Test-Parameters: trivial testlist=sanity-lnet
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Ie420fcb3d547d9ec04025b921d5b24bd8f2fcce3
Reviewed-on: https://review.whamcloud.com/36856
Reviewed-by: Alexey Lyashkov <c17817@cray.com>
Reviewed-by: Chris Horn <hornc@cray.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/include/lnet/lib-types.h
lnet/klnds/socklnd/socklnd_proto.c
lnet/lnet/acceptor.c
lnet/lnet/api-ni.c

index c5d6b2b..cff32f1 100644 (file)
@@ -1113,7 +1113,7 @@ struct lnet {
        const struct lnet_lnd           *ln_lnds[NUM_LNDS];
 
        /* test protocol compatibility flags */
-       int                             ln_testprotocompat;
+       unsigned long                   ln_testprotocompat;
 
        /* 0 - load the NIs from the mod params
         * 1 - do not load the NIs from the mod params
index 5fb7811..c5cc07b 100644 (file)
@@ -473,19 +473,14 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)
         hmv->version_major = cpu_to_le16 (KSOCK_PROTO_V1_MAJOR);
         hmv->version_minor = cpu_to_le16 (KSOCK_PROTO_V1_MINOR);
 
-        if (the_lnet.ln_testprotocompat != 0) {
-                /* single-shot proto check */
-                LNET_LOCK();
-                if ((the_lnet.ln_testprotocompat & 1) != 0) {
-                        hmv->version_major++;   /* just different! */
-                        the_lnet.ln_testprotocompat &= ~1;
-                }
-                if ((the_lnet.ln_testprotocompat & 2) != 0) {
-                        hmv->magic = LNET_PROTO_MAGIC;
-                        the_lnet.ln_testprotocompat &= ~2;
-                }
-                LNET_UNLOCK();
-        }
+       if (the_lnet.ln_testprotocompat) {
+               /* single-shot proto check */
+               if (test_and_clear_bit(0, &the_lnet.ln_testprotocompat))
+                       hmv->version_major++;   /* just different! */
+
+               if (test_and_clear_bit(1, &the_lnet.ln_testprotocompat))
+                       hmv->magic = LNET_PROTO_MAGIC;
+       }
 
         hdr->src_nid        = cpu_to_le64 (hello->kshm_src_nid);
         hdr->src_pid        = cpu_to_le32 (hello->kshm_src_pid);
@@ -531,15 +526,11 @@ ksocknal_send_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello)
         hello->kshm_magic   = LNET_PROTO_MAGIC;
         hello->kshm_version = conn->ksnc_proto->pro_version;
 
-        if (the_lnet.ln_testprotocompat != 0) {
-                /* single-shot proto check */
-                LNET_LOCK();
-                if ((the_lnet.ln_testprotocompat & 1) != 0) {
-                        hello->kshm_version++;   /* just different! */
-                        the_lnet.ln_testprotocompat &= ~1;
-                }
-                LNET_UNLOCK();
-        }
+       if (the_lnet.ln_testprotocompat) {
+               /* single-shot proto check */
+               if (test_and_clear_bit(0, &the_lnet.ln_testprotocompat))
+                       hello->kshm_version++;   /* just different! */
+       }
 
        rc = lnet_sock_write(sock, hello, offsetof(struct ksock_hello_msg, kshm_ips),
                                lnet_acceptor_timeout());
index 9f1fc51..3f48c7b 100644 (file)
@@ -181,18 +181,12 @@ lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
                cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION;
                cr.acr_nid     = peer_nid;
 
-               if (the_lnet.ln_testprotocompat != 0) {
+               if (the_lnet.ln_testprotocompat) {
                        /* single-shot proto check */
-                       lnet_net_lock(LNET_LOCK_EX);
-                       if ((the_lnet.ln_testprotocompat & 4) != 0) {
+                       if (test_and_clear_bit(2, &the_lnet.ln_testprotocompat))
                                cr.acr_version++;
-                               the_lnet.ln_testprotocompat &= ~4;
-                       }
-                       if ((the_lnet.ln_testprotocompat & 8) != 0) {
+                       if (test_and_clear_bit(3, &the_lnet.ln_testprotocompat))
                                cr.acr_magic = LNET_PROTO_MAGIC;
-                               the_lnet.ln_testprotocompat &= ~8;
-                       }
-                       lnet_net_unlock(LNET_LOCK_EX);
                }
 
                rc = lnet_sock_write(sock, &cr, sizeof(cr),
index 2ccbecc..7f89503 100644 (file)
@@ -3916,9 +3916,7 @@ LNetCtl(unsigned int cmd, void *arg)
                return 0;
 
        case IOC_LIBCFS_TESTPROTOCOMPAT:
-               lnet_net_lock(LNET_LOCK_EX);
                the_lnet.ln_testprotocompat = data->ioc_flags;
-               lnet_net_unlock(LNET_LOCK_EX);
                return 0;
 
        case IOC_LIBCFS_LNET_FAULT: