[PATCH] ipv4 : igmp : optimize timer modify logic in igmp_mod_timer()

Subsystems: networking [general], networking [ipv4/ipv6], the rest

STALE5386d

3 messages, 2 authors, 2011-11-23 · open the first message on its own page

[PATCH] ipv4 : igmp : optimize timer modify logic in igmp_mod_timer()

From: Jun Zhao <hidden>
Date: 2011-11-23 15:28:02

When timer is pending and expires less-than-or-equal-to new delay,
we need not used del_timer()/add_timer().

Signed-off-by: Jun Zhao <redacted>
---
 net/ipv4/igmp.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index c7472ef..50d06c5 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -215,14 +215,14 @@ static void igmp_mod_timer(struct ip_mc_list *im, int max_delay)
 {
 	spin_lock_bh(&im->lock);
 	im->unsolicit_count = 0;
-	if (del_timer(&im->timer)) {
-		if ((long)(im->timer.expires-jiffies) < max_delay) {
-			add_timer(&im->timer);
-			im->tm_running = 1;
-			spin_unlock_bh(&im->lock);
+	if (timer_pending(&im->timer)) {
+		if (time_before_eq(im->timer.expires, (jiffies + max_delay))) {
+			spin_lock_bh(&im->lock);
 			return;
+		} else {
+			del_timer(&im->timer);
+			atomic_dec(&im->refcnt);
 		}
-		atomic_dec(&im->refcnt);
 	}
 	igmp_start_timer(im, max_delay);
 	spin_unlock_bh(&im->lock);
-- 
1.7.2.5

Re: [PATCH] ipv4 : igmp : optimize timer modify logic in igmp_mod_timer()

From: Eric Dumazet <hidden>
Date: 2011-11-23 15:42:50

Le mercredi 23 novembre 2011 à 23:26 +0800, Jun Zhao a écrit :
quoted hunk
When timer is pending and expires less-than-or-equal-to new delay,
we need not used del_timer()/add_timer().

Signed-off-by: Jun Zhao <redacted>
---
 net/ipv4/igmp.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index c7472ef..50d06c5 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -215,14 +215,14 @@ static void igmp_mod_timer(struct ip_mc_list *im, int max_delay)
 {
 	spin_lock_bh(&im->lock);
 	im->unsolicit_count = 0;
-	if (del_timer(&im->timer)) {
-		if ((long)(im->timer.expires-jiffies) < max_delay) {
-			add_timer(&im->timer);
-			im->tm_running = 1;
-			spin_unlock_bh(&im->lock);
+	if (timer_pending(&im->timer)) {
+		if (time_before_eq(im->timer.expires, (jiffies + max_delay))) {
+			spin_lock_bh(&im->lock);
And you actually tested this patch ?
 			return;
+		} else {
+			del_timer(&im->timer);
+			atomic_dec(&im->refcnt);
 		}
-		atomic_dec(&im->refcnt);
 	}
 	igmp_start_timer(im, max_delay);
 	spin_unlock_bh(&im->lock);

Not sure why you want to optimize this very rare function call, risking
adding bugs in it.

Re: [PATCH] ipv4 : igmp : optimize timer modify logic in igmp_mod_timer()

From: Jun Zhao <hidden>
Date: 2011-11-23 15:45:25

On Wed, 2011-11-23 at 16:42 +0100, Eric Dumazet wrote:
Le mercredi 23 novembre 2011 à 23:26 +0800, Jun Zhao a écrit :
quoted
When timer is pending and expires less-than-or-equal-to new delay,
we need not used del_timer()/add_timer().

Signed-off-by: Jun Zhao <redacted>
---
 net/ipv4/igmp.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index c7472ef..50d06c5 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -215,14 +215,14 @@ static void igmp_mod_timer(struct ip_mc_list *im, int max_delay)
 {
 	spin_lock_bh(&im->lock);
 	im->unsolicit_count = 0;
-	if (del_timer(&im->timer)) {
-		if ((long)(im->timer.expires-jiffies) < max_delay) {
-			add_timer(&im->timer);
-			im->tm_running = 1;
-			spin_unlock_bh(&im->lock);
+	if (timer_pending(&im->timer)) {
+		if (time_before_eq(im->timer.expires, (jiffies + max_delay))) {
+			spin_lock_bh(&im->lock);
And you actually tested this patch ?
Sorry for this mistake. :(.  spin_lock_bh -> spin_unlock_bh
quoted
 			return;
+		} else {
+			del_timer(&im->timer);
+			atomic_dec(&im->refcnt);
 		}
-		atomic_dec(&im->refcnt);
 	}
 	igmp_start_timer(im, max_delay);
 	spin_unlock_bh(&im->lock);

Not sure why you want to optimize this very rare function call, risking
adding bugs in it.

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help