Whamcloud - gitweb
LU-8703 libcfs: fix error messages
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-cpu.c
index b0c55e8..f9c2206 100644 (file)
@@ -23,7 +23,7 @@
 /*
  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -48,7 +48,8 @@
  * >1 : specify number of partitions
  */
 static int     cpu_npartitions;
-CFS_MODULE_PARM(cpu_npartitions, "i", int, 0444, "# of CPU partitions");
+module_param(cpu_npartitions, int, 0444);
+MODULE_PARM_DESC(cpu_npartitions, "# of CPU partitions");
 
 /**
  * modparam for setting CPU partitions patterns:
@@ -63,8 +64,9 @@ CFS_MODULE_PARM(cpu_npartitions, "i", int, 0444, "# of CPU partitions");
  *
  * NB: If user specified cpu_pattern, cpu_npartitions will be ignored
  */
-static char    *cpu_pattern = "";
-CFS_MODULE_PARM(cpu_pattern, "s", charp, 0444, "CPU partitions pattern");
+static char    *cpu_pattern = "N";
+module_param(cpu_pattern, charp, 0444);
+MODULE_PARM_DESC(cpu_pattern, "CPU partitions pattern");
 
 struct cfs_cpt_data {
        /* serialize hotplug etc */
@@ -79,13 +81,6 @@ struct cfs_cpt_data {
 
 static struct cfs_cpt_data     cpt_data;
 
-void
-cfs_cpu_core_siblings(int cpu, cpumask_t *mask)
-{
-       /* return cpumask of cores in the same socket */
-       cpumask_copy(mask, topology_core_cpumask(cpu));
-}
-
 /* return number of cores in the same socket of \a cpu */
 int
 cfs_cpu_core_nsiblings(int cpu)
@@ -94,7 +89,7 @@ cfs_cpu_core_nsiblings(int cpu)
 
        mutex_lock(&cpt_data.cpt_mutex);
 
-       cfs_cpu_core_siblings(cpu, cpt_data.cpt_cpumask);
+       cpumask_copy(cpt_data.cpt_cpumask, topology_core_cpumask(cpu));
        num = cpumask_weight(cpt_data.cpt_cpumask);
 
        mutex_unlock(&cpt_data.cpt_mutex);
@@ -681,7 +676,7 @@ cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt,
                cpu = cpumask_first(node);
 
                /* get cpumask for cores in the same socket */
-               cfs_cpu_core_siblings(cpu, socket);
+               cpumask_copy(socket, topology_core_cpumask(cpu));
                cpumask_and(socket, socket, node);
 
                LASSERT(!cpumask_empty(socket));
@@ -690,7 +685,7 @@ cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt,
                        int     i;
 
                        /* get cpumask for hts in the same core */
-                       cfs_cpu_ht_siblings(cpu, core);
+                       cpumask_copy(core, topology_sibling_cpumask(cpu));
                        cpumask_and(core, core, node);
 
                        LASSERT(!cpumask_empty(core));
@@ -1038,7 +1033,8 @@ cfs_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu)
 
                mutex_lock(&cpt_data.cpt_mutex);
                /* if all HTs in a core are offline, it may break affinity */
-               cfs_cpu_ht_siblings(cpu, cpt_data.cpt_cpumask);
+               cpumask_copy(cpt_data.cpt_cpumask,
+                            topology_sibling_cpumask(cpu));
                warn = cpumask_any_and(cpt_data.cpt_cpumask,
                                       cpu_online_mask) >= nr_cpu_ids;
                mutex_unlock(&cpt_data.cpt_mutex);
@@ -1092,7 +1088,15 @@ cfs_cpu_init(void)
 #endif
 
        if (*cpu_pattern != 0) {
-               cfs_cpt_table = cfs_cpt_table_create_pattern(cpu_pattern);
+               char *cpu_pattern_dup = kstrdup(cpu_pattern, GFP_KERNEL);
+
+               if (cpu_pattern_dup == NULL) {
+                       CERROR("Failed to duplicate cpu_pattern\n");
+                       goto failed;
+               }
+
+               cfs_cpt_table = cfs_cpt_table_create_pattern(cpu_pattern_dup);
+               kfree(cpu_pattern_dup);
                if (cfs_cpt_table == NULL) {
                        CERROR("Failed to create cptab from pattern %s\n",
                               cpu_pattern);
@@ -1116,8 +1120,9 @@ cfs_cpu_init(void)
        }
        spin_unlock(&cpt_data.cpt_lock);
 
-       LCONSOLE(0, "HW CPU cores: %d, npartitions: %d\n",
-                num_online_cpus(), cfs_cpt_number(cfs_cpt_table));
+       LCONSOLE(0, "HW nodes: %d, HW CPU cores: %d, npartitions: %d\n",
+                    num_online_nodes(), num_online_cpus(),
+                    cfs_cpt_number(cfs_cpt_table));
        return 0;
 
  failed: