Whamcloud - gitweb
LU-1756 kernel: cleanup lustre_compat25.h
authorPeng Tao <tao.peng@emc.com>
Tue, 30 Oct 2012 09:15:02 +0000 (17:15 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 8 Jan 2013 05:54:46 +0000 (00:54 -0500)
Use cpumask_of_node() rather than node_to_cpumask().
cpumask_of_node() is availabe in latest kernel, while
node_to_cpumask() isn't.

Also fix how cpumask_of_node() is detected. Some OFED
backports cpumask_of_node() and put it in private
include/linux/cpumask.h.

Signed-off-by: Peng Tao <tao.peng@emc.com>
Change-Id: I770fcb549c354c2c925c821d2a8920d867274d7a
Reviewed-on: http://review.whamcloud.com/4588
Tested-by: Hudson
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Yang Sheng <yang.sheng@intel.com>
libcfs/autoconf/lustre-libcfs.m4
libcfs/libcfs/linux/linux-cpu.c
lustre/include/linux/lustre_compat25.h
lustre/ptlrpc/ptlrpcd.c

index 389e4de..04f61a6 100644 (file)
@@ -214,6 +214,21 @@ LB_LINUX_TRY_COMPILE([
                AC_MSG_RESULT(no)
        ])
 
+       AC_MSG_CHECKING([whether OFED backports have cpumask_of_node])
+       # Some OFED has cpumask_of_node backports defined in
+       # its private include/linux/cpumask.h. However, it is
+       # defined conflictingly with kernel's cpumask_of_node.
+       if test -f $OFED_BACKPORT_PATH/linux/cpumask.h; then
+               grep -q cpumask_of_node $OFED_BACKPORT_PATH/linux/cpumask.h 2>/dev/null
+               rc=$?
+               if test $rc -eq 0; then
+                       AC_DEFINE(HAVE_OFED_CPUMASK_OF_NODE, 1, [have cpumask_of_node])
+                       AC_MSG_RESULT(yes)
+               else
+                       AC_MSG_RESULT(no)
+               fi
+       fi
+
        AC_MSG_CHECKING([whether have cpumask_of_node])
        LB_LINUX_TRY_COMPILE([
                #include <linux/topology.h>
@@ -226,6 +241,18 @@ LB_LINUX_TRY_COMPILE([
                AC_MSG_RESULT(no)
        ])
 
+       AC_MSG_CHECKING([whether have cpumask_copy])
+       LB_LINUX_TRY_COMPILE([
+               #include <linux/cpumask.h>
+       ],[
+               cpumask_copy(NULL, NULL);
+       ],[
+               AC_DEFINE(HAVE_CPUMASK_COPY, 1, [have cpumask_copy])
+               AC_MSG_RESULT(yes)
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+
        AC_MSG_CHECKING([whether have node_to_cpumask])
        LB_LINUX_TRY_COMPILE([
                #include <linux/topology.h>
index 720aedc..4cb06d3 100644 (file)
@@ -79,7 +79,7 @@ static struct cfs_cpt_data    cpt_data;
 void
 cfs_cpu_core_siblings(int cpu, cpumask_t *mask)
 {
-#if defined(HAVE_TOPOLOGY_CORE_CPUMASK)
+#if defined(HAVE_TOPOLOGY_CORE_CPUMASK) && defined(HAVE_CPUMASK_COPY)
        /* return cpumask of cores in the same socket */
        cpumask_copy(mask, topology_core_cpumask(cpu));
 #elif defined(HAVE_TOPOLOGY_CORE_SIBLINGS)
@@ -112,7 +112,7 @@ EXPORT_SYMBOL(cfs_cpu_core_nsiblings);
 void
 cfs_cpu_ht_siblings(int cpu, cpumask_t *mask)
 {
-#if defined(HAVE_TOPOLOGY_THREAD_CPUMASK)
+#if defined(HAVE_TOPOLOGY_THREAD_CPUMASK) && defined(HAVE_CPUMASK_COPY)
        cpumask_copy(mask, topology_thread_cpumask(cpu));
 #elif defined(HAVE_TOPOLOGY_THREAD_SIBLINGS)
        *mask = topology_thread_siblings(cpu);
@@ -143,7 +143,7 @@ EXPORT_SYMBOL(cfs_cpu_ht_nsiblings);
 void
 cfs_node_to_cpumask(int node, cpumask_t *mask)
 {
-#if defined(HAVE_CPUMASK_OF_NODE)
+#if defined(HAVE_CPUMASK_OF_NODE) && defined(HAVE_CPUMASK_COPY)
        cpumask_copy(mask, cpumask_of_node(node));
 #elif defined(HAVE_NODE_TO_CPUMASK)
        *mask = node_to_cpumask(node);
index 593b3ac..cc26fdb 100644 (file)
@@ -645,9 +645,12 @@ static inline int ll_quota_off(struct super_block *sb, int off, int remount)
 #define ll_pagevec_lru_add_file(pv)     pagevec_lru_add_file(pv)
 #endif
 
-#if !defined(HAVE_NODE_TO_CPUMASK) && defined(HAVE_CPUMASK_OF_NODE)
-#define node_to_cpumask(i)         (*(cpumask_of_node(i)))
-#define HAVE_NODE_TO_CPUMASK
+#if !defined(HAVE_CPUMASK_OF_NODE) && defined(HAVE_NODE_TO_CPUMASK)
+# ifdef HAVE_OFED_CPUMASK_OF_NODE
+# undef cpumask_of_node
+# define HAVE_CPUMASK_OF_NODE
+# endif
+#define cpumask_of_node(i)     (&node_to_cpumask(i))
 #endif
 
 #ifndef QUOTA_OK
index c93a8df..8a842cb 100644 (file)
@@ -410,20 +410,21 @@ static int ptlrpcd(void *arg)
         int rc, exit = 0;
         ENTRY;
 
-        cfs_daemonize_ctxt(pc->pc_name);
-#if defined(CONFIG_SMP) && defined(HAVE_NODE_TO_CPUMASK)
+       cfs_daemonize_ctxt(pc->pc_name);
+#if defined(CONFIG_SMP) && \
+(defined(HAVE_CPUMASK_OF_NODE) || defined(HAVE_NODE_TO_CPUMASK))
        if (test_bit(LIOD_BIND, &pc->pc_flags)) {
-                int index = pc->pc_index;
+               int index = pc->pc_index;
 
                 if (index >= 0 && index < cfs_num_possible_cpus()) {
-                        while (!cpu_online(index)) {
-                                if (++index >= cfs_num_possible_cpus())
-                                        index = 0;
-                        }
-                        cfs_set_cpus_allowed(cfs_current(),
-                                     node_to_cpumask(cpu_to_node(index)));
-                }
-        }
+                       while (!cpu_online(index)) {
+                               if (++index >= cfs_num_possible_cpus())
+                                       index = 0;
+                       }
+                       cfs_set_cpus_allowed(cfs_current(),
+                                    *cpumask_of_node(cpu_to_node(index)));
+               }
+       }
 #endif
         /*
          * XXX So far only "client" ptlrpcd uses an environment. In
@@ -526,14 +527,13 @@ static int ptlrpcd(void *arg)
 # endif
 static int ptlrpcd_bind(int index, int max)
 {
-        struct ptlrpcd_ctl *pc;
-        int rc = 0;
-#if defined(CONFIG_NUMA) && defined(HAVE_NODE_TO_CPUMASK)
-        struct ptlrpcd_ctl *ppc;
-        int node, i, pidx;
-        cpumask_t mask;
+       struct ptlrpcd_ctl *pc;
+       int rc = 0;
+#if defined(CONFIG_NUMA) && \
+(defined(HAVE_CPUMASK_OF_NODE) || defined(HAVE_NODE_TO_CPUMASK))
+       cpumask_t mask;
 #endif
-        ENTRY;
+       ENTRY;
 
         LASSERT(index <= max - 1);
         pc = &ptlrpcds->pd_threads[index];
@@ -549,14 +549,17 @@ static int ptlrpcd_bind(int index, int max)
                 LASSERT(max % 2 == 0);
                 pc->pc_npartners = 1;
                 break;
-        case PDB_POLICY_NEIGHBOR:
-#if defined(CONFIG_NUMA) && defined(HAVE_NODE_TO_CPUMASK)
-                node = cpu_to_node(index);
-                mask = node_to_cpumask(node);
-                for (i = max; i < cfs_num_online_cpus(); i++)
-                        cpu_clear(i, mask);
-                pc->pc_npartners = cpus_weight(mask) - 1;
+       case PDB_POLICY_NEIGHBOR:
+#if defined(CONFIG_NUMA) && \
+(defined(HAVE_CPUMASK_OF_NODE) || defined(HAVE_NODE_TO_CPUMASK))
+       {
+               int i;
+               mask = *cpumask_of_node(cpu_to_node(index));
+               for (i = max; i < cfs_num_online_cpus(); i++)
+                       cpu_clear(i, mask);
+               pc->pc_npartners = cpus_weight(mask) - 1;
                set_bit(LIOD_BIND, &pc->pc_flags);
+       }
 #else
                 LASSERT(max >= 3);
                 pc->pc_npartners = 2;
@@ -584,23 +587,28 @@ static int ptlrpcd_bind(int index, int max)
                                                 pc_partners[0] = pc;
                                 }
                                 break;
-                        case PDB_POLICY_NEIGHBOR:
-#if defined(CONFIG_NUMA) && defined(HAVE_NODE_TO_CPUMASK)
-                                /* partners are cores in the same NUMA node.
-                                 * setup partnership only with ptlrpcd threads
-                                 * that are already initialized
-                                 */
-                                for (pidx = 0, i = 0; i < index; i++) {
-                                        if (cpu_isset(i, mask)) {
-                                                ppc = &ptlrpcds->pd_threads[i];
-                                                pc->pc_partners[pidx++] = ppc;
-                                                ppc->pc_partners[ppc->
-                                                          pc_npartners++] = pc;
-                                        }
-                                }
+                       case PDB_POLICY_NEIGHBOR:
+#if defined(CONFIG_NUMA) && \
+(defined(HAVE_CPUMASK_OF_NODE) || defined(HAVE_NODE_TO_CPUMASK))
+                       {
+                               struct ptlrpcd_ctl *ppc;
+                               int i, pidx;
+                               /* partners are cores in the same NUMA node.
+                                * setup partnership only with ptlrpcd threads
+                                * that are already initialized
+                                */
+                               for (pidx = 0, i = 0; i < index; i++) {
+                                       if (cpu_isset(i, mask)) {
+                                               ppc = &ptlrpcds->pd_threads[i];
+                                               pc->pc_partners[pidx++] = ppc;
+                                               ppc->pc_partners[ppc->
+                                                         pc_npartners++] = pc;
+                                       }
+                               }
                                 /* adjust number of partners to the number
                                  * of partnership really setup */
                                 pc->pc_npartners = pidx;
+                       }
 #else
                                 if (index & 0x1)
                                        set_bit(LIOD_BIND, &pc->pc_flags);