Skip to contentSkip to conversation

net: remove redundant checking for sock timer state

PATCH In review Ying Xue 5 participants 9 messages Feb 1, 2013

Subsystems (3)
lore
Share & tools
lore

Ying Xue

author
#0 lore raw

PATCH 1/1 net: remove redundant checking for sock timer state

It's unnecessary to check whether the sock timer to be stopped is pending or not in sk_stop_timer() as del_timer() will do the same thing later.

---
 net/core/sock.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/core/sock.c +1 -1
index bc131d4..33144bd 100644
@@ -2212,7 +2212,7 @@ EXPORT_SYMBOL(sk_reset_timer);
 
 void sk_stop_timer(struct sock *sk, struct timer_list* timer)
 {
-	if (timer_pending(timer) && del_timer(timer))
+	if (del_timer(timer))
 		__sock_put(sk);
 }
 EXPORT_SYMBOL(sk_stop_timer);
Signature · 1 line
1.7.1
maintainer
#1 lore raw

From: Ying Xue <[email protected]>
Date: Fri, 1 Feb 2013 13:53:00 +0800

Quoted 5 lines

It's unnecessary to check whether the sock timer to be stopped is pending or not in sk_stop_timer() as del_timer() will do the same thing later.

Did it even occur to you that when this code was written, this "redundant" testing was also redundant, but that it might have been done on purpose?

If you are going to change this code, you must understand why it was written this way, because that is the only context in which you will be able to justify removing the test.

Otherwise I'm ignoring this patch.

#2 lore raw
Quoted 9 lines · David Miller

From: Ying Xue <[email protected]>
Date: Fri, 1 Feb 2013 13:53:00 +0800

Quoted 5 lines

It's unnecessary to check whether the sock timer to be stopped is pending or not in sk_stop_timer() as del_timer() will do the same thing later.

Quoted 8 lines

Did it even occur to you that when this code was written, this "redundant" testing was also redundant, but that it might have been done on purpose?

If you are going to change this code, you must understand why it was written this way, because that is the only context in which you will be able to justify removing the test.

I had the same reaction but maybe its not anymore a valid thing.

Before commit 55c888d6d ([PATCH] timers fixes/improvements) there was indeed a significant cost calling del_timer() because of unconditional spinlock acquisition.

But nowadays del_timer() doesn't blindly lock the spinlock.

So I guess we could change all occurrences of :

if (timer_pending(X))

    del_timer(X);

It would save some bytes of code.

But please Ying, do a complete patch for net tree, don't send 30 patches.

#3 lore raw
Quoted 28 lines · Eric Dumazet
Quoted 10 lines · David Miller

From: Ying Xue <[email protected]>
Date: Fri, 1 Feb 2013 13:53:00 +0800

Quoted 6 lines

It's unnecessary to check whether the sock timer to be stopped is pending or not in sk_stop_timer() as del_timer() will do the same thing later.

Quoted 9 lines

Did it even occur to you that when this code was written, this "redundant" testing was also redundant, but that it might have been done on purpose?

If you are going to change this code, you must understand why it was written this way, because that is the only context in which you will be able to justify removing the test.

I had the same reaction but maybe its not anymore a valid thing.

Before commit 55c888d6d ([PATCH] timers fixes/improvements) there was indeed a significant cost calling del_timer() because of unconditional spinlock acquisition.

Quoted 9 lines

But nowadays del_timer() doesn't blindly lock the spinlock.

So I guess we could change all occurrences of :

if (timer_pending(X))

    del_timer(X);

It would save some bytes of code.

Eric, thanks for your explanation and suggestion.

But I cannot understand why we should first call timer_pending() before del_timer() in your proposal. By my understanding, we might get an unreal timer pending state out of timer base lock (ie, lock_timer_base()), and the "unreal" is only for pending state, on the contrary, the value is real for inactive sate.
So calling timer_pending() out of timer base lock scope can make us avoid some unnecessary grabbing spin lock operations. However, in del_timer() there already has placed a timer_pending() before lock_timer_base() is called. So why do we need another before calling del_timer()?

Please you explain more.

Thanks,
Ying

Quoted 11 lines

But please Ying, do a complete patch for net tree, don't send 30 patches.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 31 lines · Xue Ying
Quoted 6 lines · Eric Dumazet

I had the same reaction but maybe its not anymore a valid thing.

Before commit 55c888d6d ([PATCH] timers fixes/improvements) there was indeed a significant cost calling del_timer() because of unconditional spinlock acquisition.

Quoted 9 lines

But nowadays del_timer() doesn't blindly lock the spinlock.

So I guess we could change all occurrences of :

if (timer_pending(X))

    del_timer(X);

It would save some bytes of code.

Eric, thanks for your explanation and suggestion.

But I cannot understand why we should first call timer_pending() before del_timer() in your proposal.
By my understanding, we might get an unreal timer pending state out of timer base lock (ie, lock_timer_base()),
and the "unreal" is only for pending state, on the contrary, the value is real for inactive sate.
So calling timer_pending() out of timer base lock scope can make us avoid some unnecessary grabbing spin lock operations. However, in del_timer() there already has placed a timer_pending() before lock_timer_base() is called. So why do we need another before calling del_timer()?

Quoted 1 line

Please you explain more.

I think you misunderstood me.

I said that the old construct :

if (timer_pending(X))

    del_timer(X);

could be changed to

del_timer(X);

Thats what your patch does.

But instead of changing sk_stop_timer(), I suggested you do a patch on whole net tree.

author
#5 lore raw
Quoted 36 lines · Eric Dumazet
Quoted 19 lines · Xue Ying
Quoted 6 lines · Eric Dumazet

I had the same reaction but maybe its not anymore a valid thing.

Before commit 55c888d6d ([PATCH] timers fixes/improvements) there was indeed a significant cost calling del_timer() because of unconditional spinlock acquisition.

Quoted 9 lines

But nowadays del_timer() doesn't blindly lock the spinlock.

So I guess we could change all occurrences of :

if (timer_pending(X))

    del_timer(X);

It would save some bytes of code.

Eric, thanks for your explanation and suggestion.

Quoted 8 lines

But I cannot understand why we should first call timer_pending() before del_timer() in your proposal. By my understanding, we might get an unreal timer pending state out of timer base lock (ie, lock_timer_base()), and the "unreal" is only for pending state, on the contrary, the value is real for inactive sate.
So calling timer_pending() out of timer base lock scope can make us avoid some unnecessary grabbing spin lock operations. However, in del_timer() there already has placed a timer_pending() before lock_timer_base() is called. So why do we need another before calling del_timer()?

Please you explain more.

I think you misunderstood me.

I said that the old construct :

if (timer_pending(X))

    del_timer(X);
Quoted 9 lines

could be changed to

del_timer(X);

Thats what your patch does.

But instead of changing sk_stop_timer(), I suggested you do a patch on whole net tree.

Fine :) I will do.

Regards,
Ying

Quoted 3 lines
#6 lore raw
In reply to Eric Dumazet
Quoted 8 lines

I said that the old construct :

if (timer_pending(X))

    del_timer(X);

could be changed to

del_timer(X);

If timer_pending() is an inline function then the additional check might be beneficial in very hot paths.

David

#7 lore raw
Quoted 2 lines · David Laight

If timer_pending() is an inline function then the additional check might be beneficial in very hot paths.

The 'If' word you use show you didn't even read the code, and you are talking to linux netdev mailing list. We already know these things.

So what are these very hot paths you identified ?

If this was a real concern, the right thing to do is to have a generic helper so that its real clear and self documented.

BTW sk_stop_timer() could be inlined.

author
#8 lore raw
In reply to David Miller
Quoted 7 lines · David Miller

From: Ying Xue <[email protected]>
Date: Fri, 1 Feb 2013 13:53:00 +0800

Quoted 4 lines

It's unnecessary to check whether the sock timer to be stopped is pending or not in sk_stop_timer() as del_timer() will do the same thing later.

Quoted 6 lines
Quoted 1 line

Did it even occur to you that when this code was written, this "redundant" testing was also redundant, but that it might have been done on purpose?

Sorry, at least I really cannot figure out the redundant test has some special purpose. However, it seems I found some clues which may prove the "redundant" test is really redundant:

The sk_stop_timer() function is never changed after kernel initial git repository is built. But calling timer_pending() in del_timer() is involved by 55c888d6 commit.

Regards,
Ying

Quoted 6 lines

If you are going to change this code, you must understand why it was written this way, because that is the only context in which you will be able to justify removing the test.

Otherwise I'm ignoring this patch.

Hi Dave,