netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* kfree_skb: unnecessary check ?
@ 2002-06-19 16:53 Patrick McHardy
  2002-06-19 19:51 ` Thomas 'Dent' Mirlacher
  2002-06-19 20:26 ` kuznet
  0 siblings, 2 replies; 4+ messages in thread
From: Patrick McHardy @ 2002-06-19 16:53 UTC (permalink / raw)
  To: netdev

Hi everyone.

In skbuff.h one sees:

static inline void kfree_skb(struct sk_buff *skb)
{
        if (atomic_read(&skb->users) == 1 || 
atomic_dec_and_test(&skb->users))
                __kfree_skb(skb);
}

Is atomic_dec_and_test really necessary ? atomic_dec_and_test only 
returns true if its argument has hit zero, so it was 1 before.
If atomic_dec is only a bit cheaper than atomic_dec_and_test (which i 
guess it is), wouldn't it make more sense to use something like this:

static inline void kfree_skb(struct sk_buff *skb)
{
    if (atomic_read(&skb->users) == 1)
        __kfree(skb);
    else
        atomic_dec(&skb->users);
}

Bye,
Patrick

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

* Re: kfree_skb: unnecessary check ?
  2002-06-19 16:53 kfree_skb: unnecessary check ? Patrick McHardy
@ 2002-06-19 19:51 ` Thomas 'Dent' Mirlacher
  2002-06-19 20:26 ` kuznet
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas 'Dent' Mirlacher @ 2002-06-19 19:51 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netdev

patrick,

--snip/snip
> static inline void kfree_skb(struct sk_buff *skb)
> {
-     if (atomic_read(&skb->users) == 1)
+     if (likely(atomic_read(&skb->users) == 1))
>         __kfree(skb);
>     else
>         atomic_dec(&skb->users);
> }

is even faster for the likely case by 1 2 jmps (gcc3.1).
(well, is it the likely case?)

	tm

-- 
in some way i do, and in some way i don't.

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

* Re: kfree_skb: unnecessary check ?
  2002-06-19 16:53 kfree_skb: unnecessary check ? Patrick McHardy
  2002-06-19 19:51 ` Thomas 'Dent' Mirlacher
@ 2002-06-19 20:26 ` kuznet
  2002-06-19 21:32   ` Patrick McHardy
  1 sibling, 1 reply; 4+ messages in thread
From: kuznet @ 2002-06-19 20:26 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netdev

Hello!

> Is atomic_dec_and_test really necessary ? atomic_dec_and_test only 
> returns true if its argument has hit zero, so it was 1 before.
> If atomic_dec is only a bit cheaper than atomic_dec_and_test (which i 
> guess it is), wouldn't it make more sense to use something like this:

Does the prefix "atomic" not scare you? :-)


> static inline void kfree_skb(struct sk_buff *skb)
> {
>     if (atomic_read(&skb->users) == 1)
>         __kfree(skb);
>     else
>         atomic_dec(&skb->users);
> }

      else if (atomic_dec_and_test(&skb->users))
	   __kfree_skb(skb);

If you still do not understand think why it does not look like:

static inline void kfree_skb(struct sk_buff *skb)
{
    int users = skb->users;
    if (users == 1)
        __kfree(skb);
    else
        skb->users = users - 1;
}

Alexey

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

* Re: kfree_skb: unnecessary check ?
  2002-06-19 20:26 ` kuznet
@ 2002-06-19 21:32   ` Patrick McHardy
  0 siblings, 0 replies; 4+ messages in thread
From: Patrick McHardy @ 2002-06-19 21:32 UTC (permalink / raw)
  To: kuznet; +Cc: netdev

kuznet@ms2.inr.ac.ru wrote:

>Hello!
>
>>Is atomic_dec_and_test really necessary ? atomic_dec_and_test only 
>>returns true if its argument has hit zero, so it was 1 before.
>>If atomic_dec is only a bit cheaper than atomic_dec_and_test (which i 
>>guess it is), wouldn't it make more sense to use something like this:
>>
>
>Does the prefix "atomic" not scare you? :-)
>
>
>>static inline void kfree_skb(struct sk_buff *skb)
>>{
>>    if (atomic_read(&skb->users) == 1)
>>        __kfree(skb);
>>    else
>>        atomic_dec(&skb->users);
>>}
>>
>
>      else if (atomic_dec_and_test(&skb->users))
>	   __kfree_skb(skb);
>
>If you still do not understand think why it does not look like:
>
>static inline void kfree_skb(struct sk_buff *skb)
>{
>    int users = skb->users;
>    if (users == 1)
>        __kfree(skb);
>    else
>        skb->users = users - 1;
>}
>
>Alexey
>

Hehe got it :)
Thanks
Patrick

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

end of thread, other threads:[~2002-06-19 21:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-19 16:53 kfree_skb: unnecessary check ? Patrick McHardy
2002-06-19 19:51 ` Thomas 'Dent' Mirlacher
2002-06-19 20:26 ` kuznet
2002-06-19 21:32   ` Patrick McHardy

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