Whamcloud - gitweb
LU-9859 libcfs: move percpt_lock into lnet 32/50832/5
authorMr NeilBrown <neilb@suse.de>
Mon, 23 Nov 2020 04:41:06 +0000 (15:41 +1100)
committerOleg Drokin <green@whamcloud.com>
Fri, 9 Jun 2023 05:27:07 +0000 (05:27 +0000)
lnet is the only users of percpt_lock - and there are only two such
locks!
So move the code into lnet, as part of deprecating libcfs.

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Id7091e88cf61228aa031921747fb9c7b08214931
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50832
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/libcfs_cpu.h
libcfs/libcfs/Makefile.in
libcfs/libcfs/autoMakefile.am
lnet/include/lnet/Makefile.am
lnet/include/lnet/lib-lnet.h
lnet/include/lnet/lock.h [new file with mode: 0644]
lnet/lnet/Makefile.in
lnet/lnet/lock.c [moved from libcfs/libcfs/libcfs_lock.c with 87% similarity]

index 20cd8c6..1009318 100644 (file)
@@ -337,68 +337,6 @@ int cfs_percpt_number(void *vars);
        for (i = 0; i < cfs_percpt_number(vars) &&      \
                ((var) = (vars)[i]) != NULL; i++)
 
-/*
- * percpu partition lock
- *
- * There are some use-cases like this in Lustre:
- * . each CPU partition has it's own private data which is frequently changed,
- *   and mostly by the local CPU partition.
- * . all CPU partitions share some global data, these data are rarely changed.
- *
- * LNet is typical example.
- * CPU partition lock is designed for this kind of use-cases:
- * . each CPU partition has it's own private lock
- * . change on private data just needs to take the private lock
- * . read on shared data just needs to take _any_ of private locks
- * . change on shared data needs to take _all_ private locks,
- *   which is slow and should be really rare.
- */
-enum {
-       CFS_PERCPT_LOCK_EX      = -1,   /* negative */
-};
-
-struct cfs_percpt_lock {
-       /* cpu-partition-table for this lock */
-       struct cfs_cpt_table     *pcl_cptab;
-       /* exclusively locked */
-       unsigned int              pcl_locked;
-       /* private lock table */
-       spinlock_t              **pcl_locks;
-};
-
-/* return number of private locks */
-#define cfs_percpt_lock_num(pcl)       cfs_cpt_number(pcl->pcl_cptab)
-
-/*
- * create a cpu-partition lock based on CPU partition table \a cptab,
- * each private lock has extra \a psize bytes padding data
- */
-struct cfs_percpt_lock *cfs_percpt_lock_create(struct cfs_cpt_table *cptab,
-                                              struct lock_class_key *keys);
-/* destroy a cpu-partition lock */
-void cfs_percpt_lock_free(struct cfs_percpt_lock *pcl);
-
-/* lock private lock \a index of \a pcl */
-void cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index);
-
-/* unlock private lock \a index of \a pcl */
-void cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index);
-
-#define CFS_PERCPT_LOCK_KEYS   256
-
-/* NB: don't allocate keys dynamically, lockdep needs them to be in ".data" */
-#define cfs_percpt_lock_alloc(cptab)                                   \
-({                                                                     \
-       static struct lock_class_key ___keys[CFS_PERCPT_LOCK_KEYS];     \
-       struct cfs_percpt_lock *___lk;                                  \
-                                                                       \
-       if (cfs_cpt_number(cptab) > CFS_PERCPT_LOCK_KEYS)               \
-               ___lk = cfs_percpt_lock_create(cptab, NULL);            \
-       else                                                            \
-               ___lk = cfs_percpt_lock_create(cptab, ___keys);         \
-       ___lk;                                                          \
-})
-
 /**
  * allocate \a nr_bytes of physical memory from a contiguous region with the
  * properties of \a flags which are bound to the partition id \a cpt. This
index 5f46a94..2205ad7 100644 (file)
@@ -18,7 +18,7 @@ libcfs-crypto-objs := $(addprefix crypto/,$(libcfs-crypto-objs))
 libcfs-objs-$(CONFIG_SMP) = libcfs_cpu.o
 libcfs-all-objs := debug.o fail.o module.o tracefile.o \
                   libcfs_string.o hash.o \
-                  libcfs_mem.o libcfs_lock.o \
+                  libcfs_mem.o \
                   linux-crypto.o linux-crypto-adler.o \
                   $(libcfs-objs-y)
 
index fc5debc..70698e6 100644 (file)
@@ -59,5 +59,4 @@ endif # MODULES
 MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ linux/*.o libcfs crypto/*.o
 EXTRA_DIST := $(libcfs-all-objs:%.o=%.c) tracefile.h \
              fail.c libcfs_cpu.c \
-             libcfs_mem.c libcfs_lock.c \
-             linux-crypto.h
+             libcfs_mem.c linux-crypto.h
index 1eaa042..88a4e4c 100644 (file)
@@ -5,4 +5,5 @@ EXTRA_DIST = \
        udsp.h \
        lnet_rdma.h \
        lnet_gds.h \
+       lock.h \
        socklnd.h
index 9b09467..0d0ddd9 100644 (file)
@@ -49,6 +49,8 @@
 #include <uapi/linux/lnet/lnetctl.h>
 #include <uapi/linux/lnet/nidstr.h>
 
+#include "lock.h"
+
 extern struct lnet the_lnet;                   /* THE network */
 
 #if (BITS_PER_LONG == 32)
@@ -1291,7 +1293,6 @@ __u32 lnet_sum_stats(struct lnet_element_stats *stats,
 
 void lnet_usr_translate_stats(struct lnet_ioctl_element_msg_stats *msg_stats,
                              struct lnet_element_stats *stats);
-
 static inline void
 lnet_set_route_aliveness(struct lnet_route *route, bool alive)
 {
diff --git a/lnet/include/lnet/lock.h b/lnet/include/lnet/lock.h
new file mode 100644 (file)
index 0000000..5364d2f
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * GPL HEADER END
+ */
+
+/* percpu partition lock
+ *
+ * There are some use-cases like this in Lustre:
+ * . each CPU partition has it's own private data which is frequently changed,
+ *   and mostly by the local CPU partition.
+ * . all CPU partitions share some global data, these data are rarely changed.
+ *
+ * LNet is typical example.
+ * CPU partition lock is designed for this kind of use-cases:
+ * . each CPU partition has it's own private lock
+ * . change on private data just needs to take the private lock
+ * . read on shared data just needs to take _any_ of private locks
+ * . change on shared data needs to take _all_ private locks,
+ *   which is slow and should be really rare.
+ */
+enum {
+       CFS_PERCPT_LOCK_EX      = -1,   /* negative */
+};
+
+struct cfs_percpt_lock {
+       /* cpu-partition-table for this lock */
+       struct cfs_cpt_table     *pcl_cptab;
+       /* exclusively locked */
+       unsigned int              pcl_locked;
+       /* private lock table */
+       spinlock_t              **pcl_locks;
+};
+
+/* return number of private locks */
+#define cfs_percpt_lock_num(pcl)       cfs_cpt_number(pcl->pcl_cptab)
+
+/* create a cpu-partition lock based on CPU partition table \a cptab,
+ * each private lock has extra \a psize bytes padding data
+ */
+struct cfs_percpt_lock *cfs_percpt_lock_create(struct cfs_cpt_table *cptab,
+                                              struct lock_class_key *keys);
+/* destroy a cpu-partition lock */
+void cfs_percpt_lock_free(struct cfs_percpt_lock *pcl);
+
+/* lock private lock \a index of \a pcl */
+void cfs_percpt_lock(struct cfs_percpt_lock *pcl, int index);
+
+/* unlock private lock \a index of \a pcl */
+void cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index);
+
+#define CFS_PERCPT_LOCK_KEYS   256
+
+/* NB: don't allocate keys dynamically, lockdep needs them to be in ".data" */
+#define cfs_percpt_lock_alloc(cptab)                                   \
+({                                                                     \
+       static struct lock_class_key ___keys[CFS_PERCPT_LOCK_KEYS];     \
+       struct cfs_percpt_lock *___lk;                                  \
+                                                                       \
+       if (cfs_cpt_number(cptab) > CFS_PERCPT_LOCK_KEYS)               \
+               ___lk = cfs_percpt_lock_create(cptab, NULL);            \
+       else                                                            \
+               ___lk = cfs_percpt_lock_create(cptab, ___keys);         \
+       ___lk;                                                          \
+})
index 96ebd61..b5a7c77 100644 (file)
@@ -1,6 +1,6 @@
 MODULES := lnet
 
-lnet-objs := api-ni.o config.o nidstrings.o lnet_rdma.o
+lnet-objs := api-ni.o config.o nidstrings.o lnet_rdma.o lock.o
 lnet-objs += lib-me.o lib-msg.o lib-md.o lib-ptl.o
 lnet-objs += lib-socket.o lib-move.o module.o lo.o
 lnet-objs += router.o router_proc.o acceptor.o peer.o net_fault.o udsp.o
similarity index 87%
rename from libcfs/libcfs/libcfs_lock.c
rename to lnet/lnet/lock.c
index c4ad568..721d56d 100644 (file)
  * General Public License version 2 for more details (a copy is included
  * in the LICENSE file that accompanied this code).
  *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA
- *
  * GPL HEADER END
  */
 /* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2012, 2015, Intel Corporation.
  */
-/*
- * This file is part of Lustre, http://www.lustre.org/
+/* This file is part of Lustre, http://www.lustre.org/
  *
  * Author: liang@whamcloud.com
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
 
-#include <libcfs/libcfs.h>
+#include <lnet/lib-lnet.h>
 
 /** destroy cpu-partition lock, see libcfs_private.h for more detail */
 void
@@ -73,8 +67,7 @@ cfs_percpt_lock_create(struct cfs_cpt_table *cptab,
        }
 
        if (keys == NULL) {
-               CWARN("Cannot setup class key for percpt lock, you may see "
-                     "recursive locking warnings which are actually fake.\n");
+               CWARN("Cannot setup class key for percpt lock, you may see recursive locking warnings which are actually fake.\n");
        }
 
        cfs_percpt_for_each(lock, i, pcl->pcl_locks) {
@@ -123,7 +116,8 @@ __acquires(pcl->pcl_locks)
                if (i == 0) {
                        LASSERT(!pcl->pcl_locked);
                        /* nobody should take private lock after this
-                        * so I wouldn't starve for too long time */
+                        * so I wouldn't starve for too long time
+                        */
                        pcl->pcl_locked = 1;
                }
        }