Skip to content

Commit 7b73796

Browse files
anna-marialxKAGA-KOKO
authored andcommitted
staging/lustre/libcfs: Convert to hotplug state machine
Install the callbacks via the state machine. No functional change. Signed-off-by: Anna-Maria Gleixner <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Cc: [email protected] Cc: Andreas Dilger <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Oleg Drokin <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Thomas Gleixner <[email protected]>
1 parent e210faa commit 7b73796

File tree

2 files changed

+46
-40
lines changed

2 files changed

+46
-40
lines changed

drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -967,48 +967,38 @@ cfs_cpt_table_create_pattern(char *pattern)
967967
}
968968

969969
#ifdef CONFIG_HOTPLUG_CPU
970-
static int
971-
cfs_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu)
972-
{
973-
unsigned int cpu = (unsigned long)hcpu;
974-
bool warn;
975-
976-
switch (action) {
977-
case CPU_DEAD:
978-
case CPU_DEAD_FROZEN:
979-
case CPU_ONLINE:
980-
case CPU_ONLINE_FROZEN:
981-
spin_lock(&cpt_data.cpt_lock);
982-
cpt_data.cpt_version++;
983-
spin_unlock(&cpt_data.cpt_lock);
984-
/* Fall through */
985-
default:
986-
if (action != CPU_DEAD && action != CPU_DEAD_FROZEN) {
987-
CDEBUG(D_INFO, "CPU changed [cpu %u action %lx]\n",
988-
cpu, action);
989-
break;
990-
}
970+
static enum cpuhp_state lustre_cpu_online;
991971

992-
mutex_lock(&cpt_data.cpt_mutex);
993-
/* if all HTs in a core are offline, it may break affinity */
994-
cpumask_copy(cpt_data.cpt_cpumask,
995-
topology_sibling_cpumask(cpu));
996-
warn = cpumask_any_and(cpt_data.cpt_cpumask,
997-
cpu_online_mask) >= nr_cpu_ids;
998-
mutex_unlock(&cpt_data.cpt_mutex);
999-
CDEBUG(warn ? D_WARNING : D_INFO,
1000-
"Lustre: can't support CPU plug-out well now, performance and stability could be impacted [CPU %u action: %lx]\n",
1001-
cpu, action);
1002-
}
972+
static void cfs_cpu_incr_cpt_version(void)
973+
{
974+
spin_lock(&cpt_data.cpt_lock);
975+
cpt_data.cpt_version++;
976+
spin_unlock(&cpt_data.cpt_lock);
977+
}
1003978

1004-
return NOTIFY_OK;
979+
static int cfs_cpu_online(unsigned int cpu)
980+
{
981+
cfs_cpu_incr_cpt_version();
982+
return 0;
1005983
}
1006984

1007-
static struct notifier_block cfs_cpu_notifier = {
1008-
.notifier_call = cfs_cpu_notify,
1009-
.priority = 0
1010-
};
985+
static int cfs_cpu_dead(unsigned int cpu)
986+
{
987+
bool warn;
988+
989+
cfs_cpu_incr_cpt_version();
1011990

991+
mutex_lock(&cpt_data.cpt_mutex);
992+
/* if all HTs in a core are offline, it may break affinity */
993+
cpumask_copy(cpt_data.cpt_cpumask, topology_sibling_cpumask(cpu));
994+
warn = cpumask_any_and(cpt_data.cpt_cpumask,
995+
cpu_online_mask) >= nr_cpu_ids;
996+
mutex_unlock(&cpt_data.cpt_mutex);
997+
CDEBUG(warn ? D_WARNING : D_INFO,
998+
"Lustre: can't support CPU plug-out well now, performance and stability could be impacted [CPU %u]\n",
999+
cpu);
1000+
return 0;
1001+
}
10121002
#endif
10131003

10141004
void
@@ -1018,7 +1008,9 @@ cfs_cpu_fini(void)
10181008
cfs_cpt_table_free(cfs_cpt_table);
10191009

10201010
#ifdef CONFIG_HOTPLUG_CPU
1021-
unregister_hotcpu_notifier(&cfs_cpu_notifier);
1011+
if (lustre_cpu_online > 0)
1012+
cpuhp_remove_state_nocalls(lustre_cpu_online);
1013+
cpuhp_remove_state_nocalls(CPUHP_LUSTRE_CFS_DEAD);
10221014
#endif
10231015
if (cpt_data.cpt_cpumask)
10241016
LIBCFS_FREE(cpt_data.cpt_cpumask, cpumask_size());
@@ -1027,6 +1019,8 @@ cfs_cpu_fini(void)
10271019
int
10281020
cfs_cpu_init(void)
10291021
{
1022+
int ret = 0;
1023+
10301024
LASSERT(!cfs_cpt_table);
10311025

10321026
memset(&cpt_data, 0, sizeof(cpt_data));
@@ -1041,8 +1035,19 @@ cfs_cpu_init(void)
10411035
mutex_init(&cpt_data.cpt_mutex);
10421036

10431037
#ifdef CONFIG_HOTPLUG_CPU
1044-
register_hotcpu_notifier(&cfs_cpu_notifier);
1038+
ret = cpuhp_setup_state_nocalls(CPUHP_LUSTRE_CFS_DEAD,
1039+
"staging/lustre/cfe:dead", NULL,
1040+
cfs_cpu_dead);
1041+
if (ret < 0)
1042+
goto failed;
1043+
ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
1044+
"staging/lustre/cfe:online",
1045+
cfs_cpu_online, NULL);
1046+
if (ret < 0)
1047+
goto failed;
1048+
lustre_cpu_online = ret;
10451049
#endif
1050+
ret = -EINVAL;
10461051

10471052
if (*cpu_pattern) {
10481053
cfs_cpt_table = cfs_cpt_table_create_pattern(cpu_pattern);
@@ -1075,7 +1080,7 @@ cfs_cpu_init(void)
10751080

10761081
failed:
10771082
cfs_cpu_fini();
1078-
return -1;
1083+
return ret;
10791084
}
10801085

10811086
#endif

include/linux/cpuhotplug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum cpuhp_state {
4141
CPUHP_NET_DEV_DEAD,
4242
CPUHP_PCI_XGENE_DEAD,
4343
CPUHP_IOMMU_INTEL_DEAD,
44+
CPUHP_LUSTRE_CFS_DEAD,
4445
CPUHP_SCSI_BNX2FC_DEAD,
4546
CPUHP_SCSI_BNX2I_DEAD,
4647
CPUHP_WORKQUEUE_PREP,

0 commit comments

Comments
 (0)