All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: David Miller <davem@davemloft.net>, netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH] net: dev_getfirstbyhwtype() optimization
Date: Thu, 18 Mar 2010 19:32:56 -0700	[thread overview]
Message-ID: <20100319023256.GD2894@linux.vnet.ibm.com> (raw)
In-Reply-To: <1268947645.2894.166.camel@edumazet-laptop>

On Thu, Mar 18, 2010 at 10:27:25PM +0100, Eric Dumazet wrote:
> Use RCU to avoid RTNL use in dev_getfirstbyhwtype()
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
> ---
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 17b1686..0f2e9fc 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -772,14 +772,17 @@ EXPORT_SYMBOL(__dev_getfirstbyhwtype);
> 
>  struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type)
>  {
> -	struct net_device *dev;
> +	struct net_device *dev, *ret = NULL;
> 
> -	rtnl_lock();
> -	dev = __dev_getfirstbyhwtype(net, type);
> -	if (dev)
> -		dev_hold(dev);
> -	rtnl_unlock();
> -	return dev;
> +	rcu_read_lock();
> +	for_each_netdev_rcu(net, dev)
> +		if (dev->type == type) {
> +			dev_hold(dev);
> +			ret = dev;
> +			break;
> +		}
> +	rcu_read_unlock();
> +	return ret;

Looks good, but I don't understand how it helps to introduce the
local variable "ret".

							Thanx, Paul

>  }
>  EXPORT_SYMBOL(dev_getfirstbyhwtype);
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2010-03-19  2:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-18 21:27 [PATCH] net: dev_getfirstbyhwtype() optimization Eric Dumazet
2010-03-18 21:54 ` Laurent Chavey
2010-03-19  2:32 ` Paul E. McKenney [this message]
2010-03-19  5:14   ` Eric Dumazet
2010-03-19 11:54     ` Paul E. McKenney
2010-03-22  3:39 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100319023256.GD2894@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.