netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache
@ 2012-02-21 17:26 Tony Zelenoff
  2012-02-21 17:26 ` [PATCH rhel6 1/3] net/netfilter: whitespace removed Tony Zelenoff
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Tony Zelenoff @ 2012-02-21 17:26 UTC (permalink / raw)
  To: netdev; +Cc: antonz, davem

While working at my project, saw some issues that better to refactor and
save a bit of CPU cycles. So, here they are.

Patches based on net-next tree.

Tony Zelenoff (3):
  net/netfilter: whitespace removed
  net/netfilter: refactor notifier registration
  net/netfilter: refactor nf_ct_deliver_cached_events

 net/netfilter/nf_conntrack_ecache.c |   81 +++++++++++++++++------------------
 1 files changed, 39 insertions(+), 42 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH rhel6 1/3] net/netfilter: whitespace removed
  2012-02-21 17:26 [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache Tony Zelenoff
@ 2012-02-21 17:26 ` Tony Zelenoff
  2012-02-21 17:26 ` [PATCH rhel6 2/3] net/netfilter: refactor notifier registration Tony Zelenoff
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Tony Zelenoff @ 2012-02-21 17:26 UTC (permalink / raw)
  To: netdev; +Cc: antonz, davem

Signed-off-by: Tony Zelenoff <antonz@parallels.com>
---
 net/netfilter/nf_conntrack_ecache.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index 14af632..aa15977 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -70,7 +70,7 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)
 			else
 				e->missed &= ~missed;
 			spin_unlock_bh(&ct->lock);
-		} 
+		}
 	}
 
 out_unlock:
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH rhel6 2/3] net/netfilter: refactor notifier registration
  2012-02-21 17:26 [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache Tony Zelenoff
  2012-02-21 17:26 ` [PATCH rhel6 1/3] net/netfilter: whitespace removed Tony Zelenoff
@ 2012-02-21 17:26 ` Tony Zelenoff
  2012-02-21 17:26 ` [PATCH rhel6 3/3] net/netfilter: refactor nf_ct_deliver_cached_events Tony Zelenoff
  2012-02-21 19:04 ` [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache David Miller
  3 siblings, 0 replies; 6+ messages in thread
From: Tony Zelenoff @ 2012-02-21 17:26 UTC (permalink / raw)
  To: netdev; +Cc: antonz, davem

* ret variable initialization removed as useless
* Similar code strings concatenated and functions code
  flow became more plain

Signed-off-by: Tony Zelenoff <antonz@parallels.com>
---
 net/netfilter/nf_conntrack_ecache.c |   26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index aa15977..9b8e986 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -81,21 +81,18 @@ EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);
 int nf_conntrack_register_notifier(struct net *net,
 				   struct nf_ct_event_notifier *new)
 {
-	int ret = 0;
+	int ret;
 	struct nf_ct_event_notifier *notify;
 
 	mutex_lock(&nf_ct_ecache_mutex);
 	notify = rcu_dereference_protected(net->ct.nf_conntrack_event_cb,
 					   lockdep_is_held(&nf_ct_ecache_mutex));
-	if (notify != NULL) {
+	if (likely(!notify)) {
+		rcu_assign_pointer(net->ct.nf_conntrack_event_cb, new);
+		ret = 0;
+	} else
 		ret = -EBUSY;
-		goto out_unlock;
-	}
-	rcu_assign_pointer(net->ct.nf_conntrack_event_cb, new);
-	mutex_unlock(&nf_ct_ecache_mutex);
-	return ret;
 
-out_unlock:
 	mutex_unlock(&nf_ct_ecache_mutex);
 	return ret;
 }
@@ -118,21 +115,18 @@ EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);
 int nf_ct_expect_register_notifier(struct net *net,
 				   struct nf_exp_event_notifier *new)
 {
-	int ret = 0;
+	int ret;
 	struct nf_exp_event_notifier *notify;
 
 	mutex_lock(&nf_ct_ecache_mutex);
 	notify = rcu_dereference_protected(net->ct.nf_expect_event_cb,
 					   lockdep_is_held(&nf_ct_ecache_mutex));
-	if (notify != NULL) {
+	if (likely(!notify)) {
+		rcu_assign_pointer(net->ct.nf_expect_event_cb, new);
+		ret = 0;
+	} else
 		ret = -EBUSY;
-		goto out_unlock;
-	}
-	rcu_assign_pointer(net->ct.nf_expect_event_cb, new);
-	mutex_unlock(&nf_ct_ecache_mutex);
-	return ret;
 
-out_unlock:
 	mutex_unlock(&nf_ct_ecache_mutex);
 	return ret;
 }
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH rhel6 3/3] net/netfilter: refactor nf_ct_deliver_cached_events
  2012-02-21 17:26 [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache Tony Zelenoff
  2012-02-21 17:26 ` [PATCH rhel6 1/3] net/netfilter: whitespace removed Tony Zelenoff
  2012-02-21 17:26 ` [PATCH rhel6 2/3] net/netfilter: refactor notifier registration Tony Zelenoff
@ 2012-02-21 17:26 ` Tony Zelenoff
  2012-02-21 19:04 ` [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache David Miller
  3 siblings, 0 replies; 6+ messages in thread
From: Tony Zelenoff @ 2012-02-21 17:26 UTC (permalink / raw)
  To: netdev; +Cc: antonz, davem

* identation lowered
* some CPU cycles saved at delayed item variable initialization

Signed-off-by: Tony Zelenoff <antonz@parallels.com>
---
 net/netfilter/nf_conntrack_ecache.c |   55 ++++++++++++++++++----------------
 1 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index 9b8e986..577a0e8 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -32,9 +32,11 @@ static DEFINE_MUTEX(nf_ct_ecache_mutex);
 void nf_ct_deliver_cached_events(struct nf_conn *ct)
 {
 	struct net *net = nf_ct_net(ct);
-	unsigned long events;
+	unsigned long events, missed;
 	struct nf_ct_event_notifier *notify;
 	struct nf_conntrack_ecache *e;
+	struct nf_ct_event item;
+	int ret;
 
 	rcu_read_lock();
 	notify = rcu_dereference(net->ct.nf_conntrack_event_cb);
@@ -47,31 +49,32 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)
 
 	events = xchg(&e->cache, 0);
 
-	if (nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct) && events) {
-		struct nf_ct_event item = {
-			.ct	= ct,
-			.pid	= 0,
-			.report	= 0
-		};
-		int ret;
-		/* We make a copy of the missed event cache without taking
-		 * the lock, thus we may send missed events twice. However,
-		 * this does not harm and it happens very rarely. */
-		unsigned long missed = e->missed;
-
-		if (!((events | missed) & e->ctmask))
-			goto out_unlock;
-
-		ret = notify->fcn(events | missed, &item);
-		if (unlikely(ret < 0 || missed)) {
-			spin_lock_bh(&ct->lock);
-			if (ret < 0)
-				e->missed |= events;
-			else
-				e->missed &= ~missed;
-			spin_unlock_bh(&ct->lock);
-		}
-	}
+	if (!nf_ct_is_confirmed(ct) || nf_ct_is_dying(ct) || !events)
+		goto out_unlock;
+
+	/* We make a copy of the missed event cache without taking
+	 * the lock, thus we may send missed events twice. However,
+	 * this does not harm and it happens very rarely. */
+	missed = e->missed;
+
+	if (!((events | missed) & e->ctmask))
+		goto out_unlock;
+
+	item.ct = ct;
+	item.pid = 0;
+	item.report = 0;
+
+	ret = notify->fcn(events | missed, &item);
+
+	if (likely(ret >= 0 && !missed))
+		goto out_unlock;
+
+	spin_lock_bh(&ct->lock);
+	if (ret < 0)
+		e->missed |= events;
+	else
+		e->missed &= ~missed;
+	spin_unlock_bh(&ct->lock);
 
 out_unlock:
 	rcu_read_unlock();
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache
  2012-02-21 17:26 [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache Tony Zelenoff
                   ` (2 preceding siblings ...)
  2012-02-21 17:26 ` [PATCH rhel6 3/3] net/netfilter: refactor nf_ct_deliver_cached_events Tony Zelenoff
@ 2012-02-21 19:04 ` David Miller
  2012-02-21 19:21   ` Tony Zelenoff
  3 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2012-02-21 19:04 UTC (permalink / raw)
  To: antonz; +Cc: netdev

From: Tony Zelenoff <antonz@parallels.com>
Date: Tue, 21 Feb 2012 21:26:28 +0400

> While working at my project, saw some issues that better to refactor and
> save a bit of CPU cycles. So, here they are.

Send netfilter patches to the netfilter developer list, not here.

> Patches based on net-next tree.

Then why does your subject line say "rhel6"?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache
  2012-02-21 19:04 ` [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache David Miller
@ 2012-02-21 19:21   ` Tony Zelenoff
  0 siblings, 0 replies; 6+ messages in thread
From: Tony Zelenoff @ 2012-02-21 19:21 UTC (permalink / raw)
  To: David Miller; +Cc: netdev@vger.kernel.org

2/21/12 11:04 PM, David Miller пишет:
> From: Tony Zelenoff<antonz@parallels.com>
> Date: Tue, 21 Feb 2012 21:26:28 +0400
>
>> While working at my project, saw some issues that better to refactor and
>> save a bit of CPU cycles. So, here they are.
>
> Send netfilter patches to the netfilter developer list, not here.
ok, thanks, looks like i've missed it.

>
>> Patches based on net-next tree.
>
> Then why does your subject line say "rhel6"?
It's default patch subject, that i've set. So sometimes i did not notice 
and send it... sorry.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-02-21 19:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-21 17:26 [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache Tony Zelenoff
2012-02-21 17:26 ` [PATCH rhel6 1/3] net/netfilter: whitespace removed Tony Zelenoff
2012-02-21 17:26 ` [PATCH rhel6 2/3] net/netfilter: refactor notifier registration Tony Zelenoff
2012-02-21 17:26 ` [PATCH rhel6 3/3] net/netfilter: refactor nf_ct_deliver_cached_events Tony Zelenoff
2012-02-21 19:04 ` [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache David Miller
2012-02-21 19:21   ` Tony Zelenoff

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).