From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753693AbcKZXPV (ORCPT ); Sat, 26 Nov 2016 18:15:21 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:43571 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753410AbcKZXOq (ORCPT ); Sat, 26 Nov 2016 18:14:46 -0500 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: rt@linutronix.de, tglx@linutronix.de, Anna-Maria Gleixner , Oleg Drokin , Andreas Dilger , James Simmons , Greg Kroah-Hartman , lustre-devel@lists.lustre.org, devel@driverdev.osuosl.org, Sebastian Andrzej Siewior Subject: [PATCH 21/22] staging/lustre/libcfs: Convert to hotplug state machine Date: Sun, 27 Nov 2016 00:13:49 +0100 Message-Id: <20161126231350.10321-22-bigeasy@linutronix.de> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161126231350.10321-1-bigeasy@linutronix.de> References: <20161126231350.10321-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anna-Maria Gleixner Install the callbacks via the state machine. Cc: Oleg Drokin Cc: Andreas Dilger Cc: James Simmons Cc: Greg Kroah-Hartman Cc: lustre-devel@lists.lustre.org Cc: devel@driverdev.osuosl.org Signed-off-by: Anna-Maria Gleixner Signed-off-by: Sebastian Andrzej Siewior --- .../staging/lustre/lnet/libcfs/linux/linux-cpu.c | 89 ++++++++++++------= ---- include/linux/cpuhotplug.h | 1 + 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c b/drivers= /staging/lustre/lnet/libcfs/linux/linux-cpu.c index e8b1a61420de..a75113ab2903 100644 --- a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c +++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c @@ -73,6 +73,9 @@ struct cfs_cpt_data { }; =20 static struct cfs_cpt_data cpt_data; +#ifdef CONFIG_HOTPLUG_CPU +static enum cpuhp_state lustre_cpu_online; +#endif =20 static void cfs_node_to_cpumask(int node, cpumask_t *mask) @@ -942,48 +945,38 @@ cfs_cpt_table_create_pattern(char *pattern) } =20 #ifdef CONFIG_HOTPLUG_CPU -static int -cfs_cpu_notify(struct notifier_block *self, unsigned long action, void *hc= pu) + +static void cfs_cpu_incr_cpt_version(void) { - unsigned int cpu =3D (unsigned long)hcpu; - bool warn; - - switch (action) { - case CPU_DEAD: - case CPU_DEAD_FROZEN: - case CPU_ONLINE: - case CPU_ONLINE_FROZEN: - spin_lock(&cpt_data.cpt_lock); - cpt_data.cpt_version++; - spin_unlock(&cpt_data.cpt_lock); - /* Fall through */ - default: - if (action !=3D CPU_DEAD && action !=3D 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 */ - cpumask_copy(cpt_data.cpt_cpumask, - topology_sibling_cpumask(cpu)); - warn =3D cpumask_any_and(cpt_data.cpt_cpumask, - cpu_online_mask) >=3D 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 sta= bility could be impacted [CPU %u action: %lx]\n", - cpu, action); - } - - return NOTIFY_OK; + spin_lock(&cpt_data.cpt_lock); + cpt_data.cpt_version++; + spin_unlock(&cpt_data.cpt_lock); } =20 -static struct notifier_block cfs_cpu_notifier =3D { - .notifier_call =3D cfs_cpu_notify, - .priority =3D 0 -}; +static int cfs_cpu_online(unsigned int cpu) +{ + cfs_cpu_incr_cpt_version(); + return 0; +} =20 +static int cfs_cpu_dead(unsigned int cpu) +{ + bool warn; + int next; + + cfs_cpu_incr_cpt_version(); + + mutex_lock(&cpt_data.cpt_mutex); + /* if all HTs in a core are offline, it may break affinity */ + cpumask_copy(cpt_data.cpt_cpumask, topology_sibling_cpumask(cpu)); + next =3D cpumask_any_and(cpt_data.cpt_cpumask, cpu_online_mask); + warn =3D next >=3D 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 stab= ility could be impacted [CPU %u]\n", + cpu); + return 0; +} #endif =20 void @@ -993,7 +986,9 @@ cfs_cpu_fini(void) cfs_cpt_table_free(cfs_cpt_table); =20 #ifdef CONFIG_HOTPLUG_CPU - unregister_hotcpu_notifier(&cfs_cpu_notifier); + if (lustre_cpu_online) + cpuhp_remove_state_nocalls(lustre_cpu_online); + cpuhp_remove_state_nocalls(CPUHP_LUSTRE_CFS_DEAD); #endif if (cpt_data.cpt_cpumask) LIBCFS_FREE(cpt_data.cpt_cpumask, cpumask_size()); @@ -1002,6 +997,10 @@ cfs_cpu_fini(void) int cfs_cpu_init(void) { +#ifdef CONFIG_HOTPLUG_CPU + int ret; +#endif + LASSERT(!cfs_cpt_table); =20 memset(&cpt_data, 0, sizeof(cpt_data)); @@ -1016,7 +1015,17 @@ cfs_cpu_init(void) mutex_init(&cpt_data.cpt_mutex); =20 #ifdef CONFIG_HOTPLUG_CPU - register_hotcpu_notifier(&cfs_cpu_notifier); + ret =3D cpuhp_setup_state_nocalls(CPUHP_LUSTRE_CFS_DEAD, + "staging/lustre/cfe:dead", NULL, + cfs_cpu_dead); + if (ret < 0) + goto failed; + ret =3D cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, + "staging/lustre/cfe:online", + cfs_cpu_online, NULL); + if (ret < 0) + goto failed; + lustre_cpu_online =3D ret; #endif =20 if (*cpu_pattern !=3D 0) { diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 22acee76cf4c..141c3be242d1 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -41,6 +41,7 @@ enum cpuhp_state { CPUHP_NET_DEV_DEAD, CPUHP_PCI_XGENE_DEAD, CPUHP_IOMMU_INTEL_DEAD, + CPUHP_LUSTRE_CFS_DEAD, CPUHP_WORKQUEUE_PREP, CPUHP_POWER_NUMA_PREPARE, CPUHP_HRTIMERS_PREPARE, --=20 2.10.2