mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: Eliezer Tamir <eliezer.tamir@linux.intel.com>
Cc: David Miller <davem@davemloft.net>,
	<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
	Jesse Brandeburg <jesse.brandeburg@intel.com>,
	"Don Skidmore" <donald.c.skidmore@intel.com>,
	<e1000-devel@lists.sourceforge.net>,
	Willem de Bruijn <willemb@google.com>,
	Eric Dumazet <erdnetdev@gmail.com>,
	Andi Kleen <andi@firstfloor.org>, HPA <hpa@zytor.com>,
	Eilon Greenstien <eilong@broadcom.com>,
	Or Gerlitz <or.gerlitz@gmail.com>,
	Alex Rosenbaum <alexr@mellanox.com>,
	Eliezer Tamir <eliezer@tamir.org.il>
Subject: Re: [PATCH v6 net-next 1/5] net: add napi_id and hash
Date: Wed, 29 May 2013 21:09:52 +0100	[thread overview]
Message-ID: <1369858192.1971.21.camel@bwh-desktop.uk.level5networks.com> (raw)
In-Reply-To: <20130529063925.27486.46649.stgit@ladj378.jer.intel.com>

On Wed, 2013-05-29 at 09:39 +0300, Eliezer Tamir wrote:
> Adds a napi_id and a hashing mechanism to lookup a napi by id.
> This will be used by subsequent patches to implement low latency
> Ethernet device polling.
> Based on a code sample by Eric Dumazet.
> 
> Signed-off-by: Eliezer Tamir <eliezer.tamir@linux.intel.com>
[...]
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
[...]
> @@ -4136,6 +4143,53 @@ void napi_complete(struct napi_struct *n)
>  }
>  EXPORT_SYMBOL(napi_complete);
>  
> +void napi_hash_add(struct napi_struct *napi)
> +{
> +	if (!test_and_set_bit(NAPI_STATE_HASHED, &napi->state)) {
> +
> +		spin_lock(&napi_hash_lock);
> +
> +		/* 0 is not a valid id */
> +		napi->napi_id = 0;
> +		while (!napi->napi_id)
> +			napi->napi_id = ++napi_gen_id;

Suppose we're loading/unloading one driver repeatedly while another one
remains loaded the whole time.  Then once napi_gen_id wraps around, the
same ID can be assigned to multiple contexts.

So far as I can see, assigning the same ID twice will just make polling
stop working for one of the NAPI contexts; I don't think it causes a
crash.  And it is exceedingly unlikely to happen in production.  But if
you're going to the trouble of handling wrap-around at all, you'd better
handle this.

[...]
> +/* must be called under rcu_read_lock(), as we dont take a reference */
> +struct napi_struct *napi_by_id(int napi_id)
> +{
> +	unsigned int hash = napi_id % HASH_SIZE(napi_hash);
[...]

napi_id should be declared unsigned int here, as elsewhere.  The
division can't actually yield a negative result because HASH_SIZE() has
type size_t and napi_id is promoted to match, but I had to go and look
at hashtable.h to check that.

Ben.

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


  parent reply	other threads:[~2013-05-29 20:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29  6:39 [PATCH v6 net-next 0/5] net: low latency Ethernet device polling Eliezer Tamir
2013-05-29  6:39 ` [PATCH v6 net-next 1/5] net: add napi_id and hash Eliezer Tamir
2013-05-29 12:56   ` Eric Dumazet
2013-05-29 13:09     ` David Laight
2013-05-29 13:43       ` Eric Dumazet
2013-05-29 15:04     ` Eliezer Tamir
2013-05-29 20:09   ` Ben Hutchings [this message]
2013-05-30  6:51     ` Eliezer Tamir
2013-05-29  6:39 ` [PATCH v6 net-next 2/5] net: implement support for low latency socket polling Eliezer Tamir
2013-05-29 13:37   ` Eric Dumazet
2013-05-29 13:42     ` David Laight
2013-05-29 13:48       ` Eric Dumazet
2013-05-29 14:01     ` Eliezer Tamir
     [not found]       ` <CALuTh9EvzhDaqnVV35wytNg6kJhm+HbOjp5tdxWS9bCTVM5YSA@mail.gmail.com>
2013-05-29 15:01         ` Eliezer Tamir
2013-05-29 14:14   ` Or Gerlitz
2013-05-29 14:40     ` yaniv saar
2013-05-29 14:59     ` Eliezer Tamir
2013-05-29 18:52       ` Or Gerlitz
2013-05-29 19:08         ` Eric Dumazet
2013-05-30  5:58           ` Eliezer Tamir
2013-05-30  6:04         ` Eliezer Tamir
2013-05-29 20:20     ` Ben Hutchings
2013-05-29  6:39 ` [PATCH v6 net-next 3/5] tcp: add TCP support for low latency receive poll Eliezer Tamir
2013-05-29 13:38   ` Eric Dumazet
2013-05-29  6:39 ` [PATCH v6 net-next 4/5] ixgbe: Add support for ndo_ll_poll Eliezer Tamir
2013-05-29  6:40 ` [PATCH v6 net-next 5/5] ixgbe: add extra stats " Eliezer Tamir

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=1369858192.1971.21.camel@bwh-desktop.uk.level5networks.com \
    --to=bhutchings@solarflare.com \
    --cc=alexr@mellanox.com \
    --cc=andi@firstfloor.org \
    --cc=davem@davemloft.net \
    --cc=donald.c.skidmore@intel.com \
    --cc=e1000-devel@lists.sourceforge.net \
    --cc=eilong@broadcom.com \
    --cc=eliezer.tamir@linux.intel.com \
    --cc=eliezer@tamir.org.il \
    --cc=erdnetdev@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=or.gerlitz@gmail.com \
    --cc=willemb@google.com \
    /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

all inboxes | Powered by JetHome®