ipv4 : igmp : optimize timer modify logic in igmp_mod_timer()
Subsystems (3)
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
@@ -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
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().
Signed-off-by Jun Zhao <[email protected]>--- net/ipv4/igmp.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)net/ipv4/igmp.c +0
-0@@ -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
-5spin_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
-1return ; + }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.
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().
Signed-off-by Jun Zhao <[email protected]>--- net/ipv4/igmp.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)net/ipv4/igmp.c +0
-2@@ -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
-1return ; + }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.