Skip to contentSkip to conversation

ipv4 : igmp : optimize timer modify logic in igmp_mod_timer()

PATCH Superseded Jun Zhao 2 participants 3 messages Nov 23, 2011

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jun Zhao

author
#0 lore raw

PATCH 1/1 ipv4 : igmp : optimize timer modify logic in igmp_mod_timer()

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

---
 net/ipv4/igmp.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
net/ipv4/igmp.c +6 -6
index c7472ef..50d06c5 100644
@@ -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);
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 14 lines · Jun Zhao

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

---
 net/ipv4/igmp.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
net/ipv4/igmp.c +0 -0
index c7472ef..50d06c5 100644
@@ -215,14 +215,14 @@ static void igmp_mod_timer(struct ip_mc_list *im, int max_delay)
 {

net/ipv4/igmp.c static void igmp_mod_timer(struct ip_mc_list *im, int max_delay) · line 220

Quoted 10 lines
net/ipv4/igmp.c +3 -5
 	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 ?

net/ipv4/igmp.c static void igmp_mod_timer(struct ip_mc_list *im, int max_delay) · line 228

Quoted 9 lines
net/ipv4/igmp.c +3 -1
 			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.

author
#2 lore raw
Quoted 19 lines · Eric Dumazet
Quoted 18 lines · Jun Zhao

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

---
 net/ipv4/igmp.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
net/ipv4/igmp.c +0 -2
index c7472ef..50d06c5 100644
@@ -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) {
Quoted 8 lines

net/ipv4/igmp.c static void igmp_mod_timer(struct ip_mc_list *im, int max_delay) · line 220

Quoted 6 lines
net/ipv4/igmp.c +3 -3
-			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 17 lines

net/ipv4/igmp.c static void igmp_mod_timer(struct ip_mc_list *im, int max_delay) · line 228

Quoted 10 lines
net/ipv4/igmp.c +3 -1
 			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.