*/
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2012, 2013, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
* 1 : disable multiple partitions
* >1 : specify number of partitions
*/
-/* NB: we set it to 1 for now, multiple partitions will be enabled after
- * all smp node affinity code landed */
-static int cpu_npartitions = 1;
+static int cpu_npartitions;
CFS_MODULE_PARM(cpu_npartitions, "i", int, 0444, "# of CPU partitions");
/**
* i.e: "0[0,1,2,3] 1[4,5,6,7]", number before bracket is CPU partition ID,
* number in bracket is processor ID (core or HT)
*
- * i.e: "N 0[0,1] 1[2,3]" the first character 'n' means numbers in bracket
+ * i.e: "N 0[0,1] 1[2,3]" the first character 'N' means numbers in bracket
* are NUMA node ID, number before bracket is CPU partition ID.
*
* NB: If user specified cpu_pattern, cpu_npartitions will be ignored
/* reserved for hotplug */
unsigned long cpt_version;
/* mutex to protect cpt_cpumask */
- struct semaphore cpt_mutex;
+ struct mutex cpt_mutex;
/* scratch buffer for set/unset_node */
cpumask_t *cpt_cpumask;
};
void
cfs_cpu_core_siblings(int cpu, cpumask_t *mask)
{
-#if defined(HAVE_TOPOLOGY_CORE_CPUMASK)
/* return cpumask of cores in the same socket */
cpumask_copy(mask, topology_core_cpumask(cpu));
-#elif defined(HAVE_TOPOLOGY_CORE_SIBLINGS)
- *mask = topology_core_siblings(cpu);
-#else
- cpus_clear(*mask);
- cpu_set(cpu, *mask);
-#endif
}
EXPORT_SYMBOL(cfs_cpu_core_siblings);
{
int num;
- down(&cpt_data.cpt_mutex);
+ mutex_lock(&cpt_data.cpt_mutex);
cfs_cpu_core_siblings(cpu, cpt_data.cpt_cpumask);
num = cpus_weight(*cpt_data.cpt_cpumask);
- up(&cpt_data.cpt_mutex);
+ mutex_unlock(&cpt_data.cpt_mutex);
return num;
}
void
cfs_cpu_ht_siblings(int cpu, cpumask_t *mask)
{
-#if defined(HAVE_TOPOLOGY_THREAD_CPUMASK)
cpumask_copy(mask, topology_thread_cpumask(cpu));
-#elif defined(HAVE_TOPOLOGY_THREAD_SIBLINGS)
- *mask = topology_thread_siblings(cpu);
-#else
- cpus_clear(*mask);
- cpu_set(cpu, *mask);
-#endif
}
EXPORT_SYMBOL(cfs_cpu_ht_siblings);
{
int num;
- down(&cpt_data.cpt_mutex);
+ mutex_lock(&cpt_data.cpt_mutex);
cfs_cpu_ht_siblings(cpu, cpt_data.cpt_cpumask);
num = cpus_weight(*cpt_data.cpt_cpumask);
- up(&cpt_data.cpt_mutex);
+ mutex_unlock(&cpt_data.cpt_mutex);
return num;
}
void
cfs_node_to_cpumask(int node, cpumask_t *mask)
{
-#if defined(HAVE_CPUMASK_OF_NODE)
cpumask_copy(mask, cpumask_of_node(node));
-#elif defined(HAVE_NODE_TO_CPUMASK)
- *mask = node_to_cpumask(node);
-#else
- cpus_clear(*mask);
- for_each_online_cpu(i) {
- if (cpu_to_node(i) == node)
- cpu_set(i, *mask);
- }
-#endif
}
EXPORT_SYMBOL(cfs_node_to_cpumask);
return 0;
}
- down(&cpt_data.cpt_mutex);
+ mutex_lock(&cpt_data.cpt_mutex);
mask = cpt_data.cpt_cpumask;
cfs_node_to_cpumask(node, mask);
rc = cfs_cpt_set_cpumask(cptab, cpt, mask);
- up(&cpt_data.cpt_mutex);
+ mutex_unlock(&cpt_data.cpt_mutex);
return rc;
}
return;
}
- down(&cpt_data.cpt_mutex);
+ mutex_lock(&cpt_data.cpt_mutex);
mask = cpt_data.cpt_cpumask;
cfs_node_to_cpumask(node, mask);
cfs_cpt_unset_cpumask(cptab, cpt, mask);
- up(&cpt_data.cpt_mutex);
+ mutex_unlock(&cpt_data.cpt_mutex);
}
EXPORT_SYMBOL(cfs_cpt_unset_node);
if (cpu_isset(i, *cpumask))
continue;
-#ifdef HAVE_SET_CPUS_ALLOWED
- rc = set_cpus_allowed(cfs_current(), *cpumask);
-#else
- rc = set_cpus_allowed_ptr(cfs_current(), cpumask);
-#endif
-#ifdef HAVE_SET_MEMS_ALLOWED
+ rc = set_cpus_allowed_ptr(current, cpumask);
set_mems_allowed(*nodemask);
-#endif
if (rc == 0)
- cfs_schedule(); /* switch to allowed CPU */
+ schedule(); /* switch to allowed CPU */
return rc;
}
- /* don't need to set affinity baecause all online CPUs are covered */
+ /* don't need to set affinity because all online CPUs are covered */
return 0;
}
EXPORT_SYMBOL(cfs_cpt_bind);
if (ncpt <= 0)
ncpt = rc;
- if (ncpt > rc) {
+ if (ncpt > num_online_cpus() || ncpt > 4 * rc) {
CWARN("CPU partition number %d is larger than suggested "
- "value(%d), your system may have performance"
+ "value (%d), your system may have performance"
"issue or run out of memory while under pressure\n",
ncpt, rc);
}
struct cfs_cpu_partition *part;
int n;
- if (cpt >= ncpt)
- goto failed;
+ /* Each emulated NUMA node has all allowed CPUs in
+ * the mask.
+ * End loop when all partitions have assigned CPUs.
+ */
+ if (cpt == ncpt)
+ break;
part = &cptab->ctb_parts[cpt];
break;
}
- if (sscanf(str, "%u%n", &cpt, &n) < 1) {
+ if (sscanf(str, "%d%n", &cpt, &n) < 1) {
CERROR("Invalid cpu pattern %s\n", str);
goto failed;
}
goto failed;
}
- cfs_list_for_each_entry(range, &el->el_exprs, re_link) {
+ list_for_each_entry(range, &el->el_exprs, re_link) {
for (i = range->re_lo; i <= range->re_hi; i++) {
if ((i - range->re_lo) % range->re_stride != 0)
continue;
static int
cfs_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu)
{
- unsigned int cpu = (unsigned long)hcpu;
+ unsigned int cpu = (unsigned long)hcpu;
+ bool warn;
switch (action) {
case CPU_DEAD:
cpt_data.cpt_version++;
spin_unlock(&cpt_data.cpt_lock);
default:
- CWARN("Lustre: can't support CPU hotplug well now, "
- "performance and stability could be impacted"
- "[CPU %u notify: %lx]\n", cpu, action);
+ if (action != CPU_DEAD && action != CPU_DEAD_FROZEN) {
+ CDEBUG(D_INFO, "CPU changed [cpu %u action %lx]\n",
+ cpu, action);
+ break;
+ }
+
+ 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);
+ warn = any_online_cpu(*cpt_data.cpt_cpumask) >= nr_cpu_ids;
+ mutex_unlock(&cpt_data.cpt_mutex);
+ CDEBUG(warn ? D_WARNING : D_INFO,
+ "Lustre: can't support CPU plug-out well now, "
+ "performance and stability could be impacted"
+ "[CPU %u action: %lx]\n", cpu, action);
}
return NOTIFY_OK;
}
spin_lock_init(&cpt_data.cpt_lock);
- sema_init(&cpt_data.cpt_mutex, 1);
+ mutex_init(&cpt_data.cpt_mutex);
#ifdef CONFIG_HOTPLUG_CPU
register_hotcpu_notifier(&cfs_cpu_notifier);