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: Fri, 19 Mar 2010 04:54:07 -0700 [thread overview]
Message-ID: <20100319115407.GG2894@linux.vnet.ibm.com> (raw)
In-Reply-To: <1268975642.2894.218.camel@edumazet-laptop>
On Fri, Mar 19, 2010 at 06:14:02AM +0100, Eric Dumazet wrote:
> Le jeudi 18 mars 2010 à 19:32 -0700, Paul E. McKenney a écrit :
> > 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".
> >
>
> Thanks for reviewing Paul !
>
> Not only it helps, its necessary :)
>
> for_each_netdev_rcu(net, dev) {
> if (cond) {
> dev_hold(dev);
> break;
> }
> }
> makes no guarantee dev is NULL if we hit the list end :
>
>
> /**
> * list_for_each_entry_rcu - iterate over rcu list of given type
> * @pos: the type * to use as a loop cursor.
> * @head: the head for your list.
> * @member: the name of the list_struct within the struct.
> *
> * This list-traversal primitive may safely run concurrently with
> * the _rcu list-mutation primitives such as list_add_rcu()
> * as long as the traversal is guarded by rcu_read_lock().
> */
> #define list_for_each_entry_rcu(pos, head, member) \
> for (pos = list_entry_rcu((head)->next, typeof(*pos), member); \
> prefetch(pos->member.next), &pos->member != (head); \
> pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
Right! Got it, thank you!
Thanx, Paul
next prev parent reply other threads:[~2010-03-19 11:54 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
2010-03-19 5:14 ` Eric Dumazet
2010-03-19 11:54 ` Paul E. McKenney [this message]
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=20100319115407.GG2894@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 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).