linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: rt@linutronix.de,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	"David S. Miller" <davem@davemloft.net>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	netdev@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 09/25] net/flowcache: Convert to hotplug state machine
Date: Thu,  3 Nov 2016 15:50:05 +0100	[thread overview]
Message-ID: <20161103145021.28528-10-bigeasy@linutronix.de> (raw)
In-Reply-To: <20161103145021.28528-1-bigeasy@linutronix.de>

Install the callbacks via the state machine. Use multi state support to avoid
custom list handling for the multiple instances.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: netdev@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/cpuhotplug.h |  1 +
 include/net/flow.h         |  1 +
 include/net/flowcache.h    |  2 +-
 net/core/flow.c            | 60 ++++++++++++++++++++--------------------------
 net/xfrm/xfrm_policy.c     |  1 +
 5 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index 394eb7ed53be..86b940f19df8 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -56,6 +56,7 @@ enum cpuhp_state {
 	CPUHP_ARM_SHMOBILE_SCU_PREPARE,
 	CPUHP_SH_SH3X_PREPARE,
 	CPUHP_BLK_MQ_PREPARE,
+	CPUHP_NET_FLOW_PREPARE,
 	CPUHP_TIMERS_DEAD,
 	CPUHP_NOTF_ERR_INJ_PREPARE,
 	CPUHP_MIPS_SOC_PREPARE,
diff --git a/include/net/flow.h b/include/net/flow.h
index 035aa7716967..2e386bd6ee63 100644
--- a/include/net/flow.h
+++ b/include/net/flow.h
@@ -239,6 +239,7 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
 					    void *ctx);
 int flow_cache_init(struct net *net);
 void flow_cache_fini(struct net *net);
+void flow_cache_hp_init(void);
 
 void flow_cache_flush(struct net *net);
 void flow_cache_flush_deferred(struct net *net);
diff --git a/include/net/flowcache.h b/include/net/flowcache.h
index c8f665ec6e0d..9caf3bfc8d2d 100644
--- a/include/net/flowcache.h
+++ b/include/net/flowcache.h
@@ -17,7 +17,7 @@ struct flow_cache_percpu {
 struct flow_cache {
 	u32				hash_shift;
 	struct flow_cache_percpu __percpu *percpu;
-	struct notifier_block		hotcpu_notifier;
+	struct hlist_node		node;
 	int				low_watermark;
 	int				high_watermark;
 	struct timer_list		rnd_timer;
diff --git a/net/core/flow.c b/net/core/flow.c
index 3937b1b68d5b..841fd7f87b30 100644
--- a/net/core/flow.c
+++ b/net/core/flow.c
@@ -419,28 +419,20 @@ static int flow_cache_cpu_prepare(struct flow_cache *fc, int cpu)
 	return 0;
 }
 
-static int flow_cache_cpu(struct notifier_block *nfb,
-			  unsigned long action,
-			  void *hcpu)
+static int flow_cache_cpu_up_prep(unsigned int cpu, struct hlist_node *node)
 {
-	struct flow_cache *fc = container_of(nfb, struct flow_cache,
-						hotcpu_notifier);
-	int res, cpu = (unsigned long) hcpu;
+	struct flow_cache *fc = hlist_entry_safe(node, struct flow_cache, node);
+
+	return flow_cache_cpu_prepare(fc, cpu);
+}
+
+static int flow_cache_cpu_dead(unsigned int cpu, struct hlist_node *node)
+{
+	struct flow_cache *fc = hlist_entry_safe(node, struct flow_cache, node);
 	struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, cpu);
 
-	switch (action) {
-	case CPU_UP_PREPARE:
-	case CPU_UP_PREPARE_FROZEN:
-		res = flow_cache_cpu_prepare(fc, cpu);
-		if (res)
-			return notifier_from_errno(res);
-		break;
-	case CPU_DEAD:
-	case CPU_DEAD_FROZEN:
-		__flow_cache_shrink(fc, fcp, 0);
-		break;
-	}
-	return NOTIFY_OK;
+	__flow_cache_shrink(fc, fcp, 0);
+	return 0;
 }
 
 int flow_cache_init(struct net *net)
@@ -467,18 +459,8 @@ int flow_cache_init(struct net *net)
 	if (!fc->percpu)
 		return -ENOMEM;
 
-	cpu_notifier_register_begin();
-
-	for_each_online_cpu(i) {
-		if (flow_cache_cpu_prepare(fc, i))
-			goto err;
-	}
-	fc->hotcpu_notifier = (struct notifier_block){
-		.notifier_call = flow_cache_cpu,
-	};
-	__register_hotcpu_notifier(&fc->hotcpu_notifier);
-
-	cpu_notifier_register_done();
+	if (cpuhp_state_add_instance(CPUHP_NET_FLOW_PREPARE, &fc->node))
+		goto err;
 
 	setup_timer(&fc->rnd_timer, flow_cache_new_hashrnd,
 		    (unsigned long) fc);
@@ -494,8 +476,6 @@ int flow_cache_init(struct net *net)
 		fcp->hash_table = NULL;
 	}
 
-	cpu_notifier_register_done();
-
 	free_percpu(fc->percpu);
 	fc->percpu = NULL;
 
@@ -509,7 +489,8 @@ void flow_cache_fini(struct net *net)
 	struct flow_cache *fc = &net->xfrm.flow_cache_global;
 
 	del_timer_sync(&fc->rnd_timer);
-	unregister_hotcpu_notifier(&fc->hotcpu_notifier);
+
+	cpuhp_state_remove_instance_nocalls(CPUHP_NET_FLOW_PREPARE, &fc->node);
 
 	for_each_possible_cpu(i) {
 		struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, i);
@@ -521,3 +502,14 @@ void flow_cache_fini(struct net *net)
 	fc->percpu = NULL;
 }
 EXPORT_SYMBOL(flow_cache_fini);
+
+void __init flow_cache_hp_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state_multi(CPUHP_NET_FLOW_PREPARE,
+				      "net/flow:prepare",
+				      flow_cache_cpu_up_prep,
+				      flow_cache_cpu_dead);
+	WARN_ON(ret < 0);
+}
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index fd6986634e6f..4a8eff11bdad 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -3111,6 +3111,7 @@ static struct pernet_operations __net_initdata xfrm_net_ops = {
 
 void __init xfrm_init(void)
 {
+	flow_cache_hp_init();
 	register_pernet_subsys(&xfrm_net_ops);
 	seqcount_init(&xfrm_policy_hash_generation);
 	xfrm_input_init();
-- 
2.10.2

  parent reply	other threads:[~2016-11-03 14:50 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03 14:49 cpu hotplug: convert more drivers (batch #4) Sebastian Andrzej Siewior
2016-11-03 14:49 ` [PATCH 01/25] fs/buffer: Convert to hotplug state machine Sebastian Andrzej Siewior
2016-11-09 22:52   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-10 16:24   ` [PATCH 01/25] " Al Viro
2016-11-10 16:31     ` Thomas Gleixner
2016-11-03 14:49 ` [PATCH 02/25] kernel/printk: " Sebastian Andrzej Siewior
2016-11-09 22:52   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:49 ` [PATCH 03/25] mm/memcg: " Sebastian Andrzej Siewior
2016-11-09 22:53   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 04/25] lib/percpu_counter: " Sebastian Andrzej Siewior
2016-11-09 22:53   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 05/25] lib/radix-tree: " Sebastian Andrzej Siewior
2016-11-09 22:54   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 06/25] mm/page_alloc: " Sebastian Andrzej Siewior
2016-11-09 22:54   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 07/25] mm/vmscan: " Sebastian Andrzej Siewior
2016-11-09 22:55   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 08/25] net/dev: " Sebastian Andrzej Siewior
2016-11-09 22:55   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` Sebastian Andrzej Siewior [this message]
2016-11-09 22:56   ` [tip:smp/hotplug] net/flowcache: " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 10/25] s390/smp: Make cpu notifier symetric Sebastian Andrzej Siewior
2016-11-04 14:22   ` Heiko Carstens
2016-11-04 14:41     ` [PATCH 10/25 v2] " Sebastian Andrzej Siewior
2016-11-09 22:56       ` [tip:smp/hotplug] " tip-bot for Thomas Gleixner
2016-11-03 14:50 ` [PATCH 11/25] s390/smp: Convert to hotplug state machine Sebastian Andrzej Siewior
2016-11-04 14:34   ` Heiko Carstens
2016-11-04 14:45     ` [PATCH 11/25 v2] " Sebastian Andrzej Siewior
2016-11-09 22:57       ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 12/25] drivers base/cacheinfo: " Sebastian Andrzej Siewior
2016-11-09 22:57   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 13/25] drivers base/topology: " Sebastian Andrzej Siewior
2016-11-09 22:57   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 14/25] ia64/err-inject: " Sebastian Andrzej Siewior
2016-11-09 22:58   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 15/25] ia64/palinfo: " Sebastian Andrzej Siewior
2016-11-09 22:58   ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 16/25] ia64/salinfo: " Sebastian Andrzej Siewior
2016-11-03 15:45   ` kbuild test robot
2016-11-03 17:31     ` [PATCH 16/25 v2] " Sebastian Andrzej Siewior
2016-11-09 22:59       ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 16:22   ` [PATCH 16/25] " kbuild test robot
2016-11-03 14:50 ` [PATCH 17/25] ia64/topology: " Sebastian Andrzej Siewior
2016-11-03 15:53   ` kbuild test robot
2016-11-03 17:33     ` [PATCH 17/25 v2] " Sebastian Andrzej Siewior
2016-11-09 22:59       ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 18/25] x86/mcheck: Move threshold_create_device() Sebastian Andrzej Siewior
2016-11-07 10:32   ` Borislav Petkov
2016-11-03 14:50 ` [PATCH 19/25] x86/mcheck: Explicit cleanup on failure in mce_amd Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 20/25] x86/mcheck: Be prepared for a rollback back to the ONLINE state Sebastian Andrzej Siewior
2016-11-07 10:32   ` Borislav Petkov
2016-11-07 10:40     ` Sebastian Andrzej Siewior
2016-11-07 12:31       ` Borislav Petkov
2016-11-07 17:23         ` Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 21/25] x86/mcheck: Split threshold_cpu_callback into two callbacks Sebastian Andrzej Siewior
2016-11-07 13:20   ` Borislav Petkov
2016-11-07 13:25     ` Sebastian Andrzej Siewior
2016-11-07 15:07       ` Borislav Petkov
2016-11-07 15:14         ` Sebastian Andrzej Siewior
2016-11-07 17:26         ` Sebastian Andrzej Siewior
2016-11-07 18:19           ` Borislav Petkov
2016-11-03 14:50 ` [PATCH 22/25] x86/mcheck: Do the init in one place Sebastian Andrzej Siewior
2016-11-07 18:45   ` Borislav Petkov
2016-11-07 18:55     ` Luck, Tony
2016-11-07 20:12       ` Borislav Petkov
2016-11-08  9:23         ` Borislav Petkov
2016-11-09 14:22           ` Sebastian Andrzej Siewior
2016-11-09 15:38             ` Borislav Petkov
2016-11-09 16:24               ` Sebastian Andrzej Siewior
2016-11-09 17:01                 ` Borislav Petkov
2016-11-09 17:22                   ` Sebastian Andrzej Siewior
2016-11-09 18:37               ` Luck, Tony
2016-11-10  9:00                 ` Sebastian Andrzej Siewior
2016-11-10  9:18                   ` Borislav Petkov
2016-11-10 17:44                     ` x86/mcheck: convert to hotplug state engine, take #2 Sebastian Andrzej Siewior
2016-11-10 17:44                       ` [PATCH 1/7] x86/mcheck: Move threshold_create_device() Sebastian Andrzej Siewior
2016-11-16  8:39                         ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-10 17:44                       ` [PATCH 2/7] x86/mcheck: Explicit cleanup on failure in mce_amd Sebastian Andrzej Siewior
2016-11-16  8:40                         ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-10 17:44                       ` [PATCH 3/7] x86/mcheck: Be prepared for a rollback back to the ONLINE state Sebastian Andrzej Siewior
2016-11-16  8:40                         ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-10 17:44                       ` [PATCH 4/7] x86/mcheck: Split threshold_cpu_callback into two callbacks Sebastian Andrzej Siewior
2016-11-16  8:41                         ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-10 17:44                       ` [PATCH 5/7] x86/mcheck: reorganize the hotplug callbacks Sebastian Andrzej Siewior
2016-11-11 18:44                         ` Borislav Petkov
2016-11-11 19:36                           ` Sebastian Andrzej Siewior
2016-11-11 19:57                             ` Borislav Petkov
2016-11-14 10:47                               ` [PATCH 5/7 v2] " Sebastian Andrzej Siewior
2016-11-16  8:41                         ` [tip:smp/hotplug] x86/mcheck: Reorganize " tip-bot for Sebastian Andrzej Siewior
2016-11-10 17:44                       ` [PATCH 6/7] x86/mcheck: Move CPU_ONLINE and CPU_DOWN_PREPARE to hotplug state machine Sebastian Andrzej Siewior
2016-11-16  8:42                         ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-10 17:44                       ` [PATCH 7/7] x86/mcheck: Move CPU_DEAD " Sebastian Andrzej Siewior
2016-11-11 20:18                         ` Borislav Petkov
2016-11-16  8:42                         ` [tip:smp/hotplug] " tip-bot for Sebastian Andrzej Siewior
2016-11-10 10:22                   ` [PATCH 22/25] x86/mcheck: Do the init in one place Thomas Gleixner
2016-11-10 10:27                     ` Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 23/25] x86/mcheck: Make CPU_DOWN_PREPARE the counter part of CPU_STARTING Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 24/25] x86/mcheck: Move CPU_ONLINE to hotplug state machine Sebastian Andrzej Siewior
2016-11-03 14:50 ` [PATCH 25/25] x86/mcheck: Move CPU_DEAD " Sebastian Andrzej Siewior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161103145021.28528-10-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rt@linutronix.de \
    --cc=steffen.klassert@secunet.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).