Information about napi_struct and net_device

11 messages, 6 authors, 2012-10-29 · open the first message on its own page

Information about napi_struct and net_device

From: Javier Domingo <hidden>
Date: 2012-10-27 16:19:00

Hello,

I am updating a kernel patch from 2.6.23-rc7 to v3.6, using git
facilities, and I have found that there have been lots of changes in
networking. Now the drivers are all by vendor, and more important,
net_device is not used always, as napi_struct took its place.

I have asked in #kernel but no one answered me, so I subscribed here.
Is there any place I can read about how is it now designed the use of
napi_struct and net_device? I have found a presentation[1] about how
networking was changing etc, and I wondered if there is anything more
precise about how it is actually implemented.

I understand a little why napi_struct, but don't really know much
about the change,

Hope someone can help me,

Javier Domingo


[1]: http://vger.kernel.org/~davem/davem_nyc09.pdf

Re: Information about napi_struct and net_device

From: Eric Dumazet <hidden>
Date: 2012-10-27 17:03:45

On Sat, 2012-10-27 at 18:18 +0200, Javier Domingo wrote:
Hello,

I am updating a kernel patch from 2.6.23-rc7 to v3.6, using git
facilities, and I have found that there have been lots of changes in
networking. Now the drivers are all by vendor, and more important,
net_device is not used always, as napi_struct took its place.
Yes, some directories were created and files moved around.

Not really a big deal (no real code change)

I have asked in #kernel but no one answered me, so I subscribed here.
Is there any place I can read about how is it now designed the use of
napi_struct and net_device? I have found a presentation[1] about how
networking was changing etc, and I wondered if there is anything more
precise about how it is actually implemented.

I understand a little why napi_struct, but don't really know much
about the change,

Hope someone can help me,
Seems quite straightforward, we probably should add some docs in 
Documentation/networking/netdevices.txt

You could take a look at a small driver like
drivers/net/ethernet/realtek/8139cp.c

and grep for "napi" in it


# grep -n napi drivers/net/ethernet/realtek/8139cp.c
327:	struct napi_struct	napi;
436:	napi_gro_receive(&cp->napi, skb);
468:static int cp_rx_poll(struct napi_struct *napi, int budget)
470:	struct cp_private *cp = container_of(napi, struct cp_private, napi);
566:		napi_gro_flush(napi, false);
568:		__napi_complete(napi);
605:		if (napi_schedule_prep(&cp->napi)) {
607:			__napi_schedule(&cp->napi);
1132:	napi_enable(&cp->napi);
1149:	napi_disable(&cp->napi);
1160:	napi_disable(&cp->napi);
1933:	netif_napi_add(dev, &cp->napi, cp_rx_poll, 16);

Re: Information about napi_struct and net_device

From: Francois Romieu <romieu@fr.zoreil.com>
Date: 2012-10-27 18:43:38

Eric Dumazet [off-list ref] :
[...]
# grep -n napi drivers/net/ethernet/realtek/8139cp.c
327:	struct napi_struct	napi;
436:	napi_gro_receive(&cp->napi, skb);
468:static int cp_rx_poll(struct napi_struct *napi, int budget)
470:	struct cp_private *cp = container_of(napi, struct cp_private, napi);
566:		napi_gro_flush(napi, false);
568:		__napi_complete(napi);
605:		if (napi_schedule_prep(&cp->napi)) {
607:			__napi_schedule(&cp->napi);
1132:	napi_enable(&cp->napi);
1149:	napi_disable(&cp->napi);
1160:	napi_disable(&cp->napi);
1933:	netif_napi_add(dev, &cp->napi, cp_rx_poll, 16);
Not all drivers use napi_gro_receive/napi_gro_flush.

It could be worth comparing with drivers/net/ethernet/via/via-rhine.c (small)
or drivers/net/ethernet/broadcom/tg3.c (bigger).

-- 
Ueimor

Re: Information about napi_struct and net_device

From: Rami Rosen <hidden>
Date: 2012-10-27 20:10:47

Hi,
You can find some info about net_device in this wiki page:
https://www.linuxfoundation.org/collaborate/workgroups/networking/networkoverview


A shameless plug - I wrote it.

Regards,
Rami Rosen

http://ramirose.wix.com/ramirosen



On Sat, Oct 27, 2012 at 6:18 PM, Javier Domingo [off-list ref] wrote:
Hello,

I am updating a kernel patch from 2.6.23-rc7 to v3.6, using git
facilities, and I have found that there have been lots of changes in
networking. Now the drivers are all by vendor, and more important,
net_device is not used always, as napi_struct took its place.

I have asked in #kernel but no one answered me, so I subscribed here.
Is there any place I can read about how is it now designed the use of
napi_struct and net_device? I have found a presentation[1] about how
networking was changing etc, and I wondered if there is anything more
precise about how it is actually implemented.

I understand a little why napi_struct, but don't really know much
about the change,

Hope someone can help me,

Javier Domingo


[1]: http://vger.kernel.org/~davem/davem_nyc09.pdf
--
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

Re: Information about napi_struct and net_device

From: Eric Dumazet <hidden>
Date: 2012-10-27 23:02:28

On Sat, 2012-10-27 at 20:22 +0200, Francois Romieu wrote:
Not all drivers use napi_gro_receive/napi_gro_flush.
Yes, note that I only mentioned "grep napi", not these specific verbs

Also, napi_gro_receive() could be used now GRO doesnt mandate hardware
checksums.
It could be worth comparing with drivers/net/ethernet/via/via-rhine.c (small)
or drivers/net/ethernet/broadcom/tg3.c (bigger).
Unfortunately tg3.c uses internal stuff sith napi substring, so I
ignored it :

$ grep napi drivers/net/ethernet/broadcom/tg3.c | wc -l
376

Re: Information about napi_struct and net_device

From: Javier Domingo <hidden>
Date: 2012-10-28 23:23:25

Hi all,

I am going to read all the netdevice.h declarations, and try to obtain
a more general view about what does each function do. At the moment,
I've read the page Rami Rosen [1] told be about, but there isn't the
explanation I was looking for, but had links to the netdev conferences
from the past years, and I read many of them.

I wish to ask/state a few questions/words about the napi_struct
creation etc. correct me please if I'm wrong

    1. napi_struct has the fields that usually had net_device about
all control about the polling, so that the device structure where each
driver puts its functions is now much cleaner. With this, though you
have the particular net_device struct it uses in the napi_struct, you
can make as if they would be separated [3].

          a. I need to work with net_device, but I also need to work
with napi_struct, I found these lines of code:
		/*
		 *	Some hardware also needs these fields, but they are not
		 *	part of the usual set specified in Space.c.
		 */

			unsigned long		state;

		struct list_head	dev_list;
		struct list_head	napi_list;
		struct list_head	unreg_list;

              inside of the net_device structure, I know I can take
the net_device pointer as documented in [3], but how may  I obtain the
napi_struct from the netdevice? or I am doing it the wrong way?

    2. I found what napi GRO was in a David S. Miller blog post [2],
which explains many things I found about GRO, that it is about
improving packet processing in the network stack functions.

Javier Domingo

[1]: http://www.linuxfoundation.org/collaborate/workgroups/networking/networkoverview
[2]: http://vger.kernel.org/~davem/cgi-bin/blog.cgi/2010/08/30
[3]: http://lwn.net/Articles/214457/

2012/10/28 Eric Dumazet [off-list ref]:
On Sat, 2012-10-27 at 20:22 +0200, Francois Romieu wrote:
quoted
Not all drivers use napi_gro_receive/napi_gro_flush.
Yes, note that I only mentioned "grep napi", not these specific verbs

Also, napi_gro_receive() could be used now GRO doesnt mandate hardware
checksums.
quoted
It could be worth comparing with drivers/net/ethernet/via/via-rhine.c (small)
or drivers/net/ethernet/broadcom/tg3.c (bigger).
Unfortunately tg3.c uses internal stuff sith napi substring, so I
ignored it :

$ grep napi drivers/net/ethernet/broadcom/tg3.c | wc -l
376

Re: Information about napi_struct and net_device

From: Francois Romieu <romieu@fr.zoreil.com>
Date: 2012-10-28 23:34:37

Javier Domingo [off-list ref] :
[...]
              inside of the net_device structure, I know I can take
the net_device pointer as documented in [3], but how may  I obtain the
napi_struct from the netdevice? or I am doing it the wrong way?
You are doing it the wrong way. The napi_struct you need is not embedded
here. See

$ less +/napi drivers/net/ethernet/realtek/8139cp.c

(first match in struct cp_private).

You should really read one of the existing drivers.

-- 
Ueimor

Re: Information about napi_struct and net_device

From: Stephen Hemminger <hidden>
Date: 2012-10-29 01:10:05

On Sat, 27 Oct 2012 18:18:39 +0200
Javier Domingo [off-list ref] wrote:
Hello,

I am updating a kernel patch from 2.6.23-rc7 to v3.6, using git
facilities, and I have found that there have been lots of changes in
networking. Now the drivers are all by vendor, and more important,
net_device is not used always, as napi_struct took its place.

I have asked in #kernel but no one answered me, so I subscribed here.
Is there any place I can read about how is it now designed the use of
napi_struct and net_device? I have found a presentation[1] about how
networking was changing etc, and I wondered if there is anything more
precise about how it is actually implemented.

I understand a little why napi_struct, but don't really know much
about the change,

Hope someone can help me,

Javier Domingo


[1]: http://vger.kernel.org/~davem/davem_nyc09.pdf
--
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
First, off put your driver upstream. The kernel developers do not care
about drivers not in the tree. They can wither up and die.

Second, learn to look in the right place.
  http://lwn.net/Articles/244640/

Re: Information about napi_struct and net_device

From: Ben Hutchings <hidden>
Date: 2012-10-29 02:41:08

On Sat, 2012-10-27 at 18:18 +0200, Javier Domingo wrote:
Hello,

I am updating a kernel patch from 2.6.23-rc7 to v3.6, using git
facilities, and I have found that there have been lots of changes in
networking. Now the drivers are all by vendor, and more important,
net_device is not used always, as napi_struct took its place.

I have asked in #kernel but no one answered me, so I subscribed here.
Is there any place I can read about how is it now designed the use of
napi_struct and net_device? I have found a presentation[1] about how
networking was changing etc, and I wondered if there is anything more
precise about how it is actually implemented.

I understand a little why napi_struct, but don't really know much
about the change,

Hope someone can help me,
The initial change to napi_struct is explained in
<http://lwn.net/Articles/244640/>.

Since then there have been further changes:

- netif_napi_del() has been added.  You must call it to clean up NAPI
contexts before freeing the associated net device(s).

- Instead of netif_rx_schedule(), netif_rx_complete(), etc. you must use
napi_schedule(), napi_complete() etc. which just take a napi_struct
pointer.

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.

Re: Information about napi_struct and net_device

From: Javier Domingo <hidden>
Date: 2012-10-29 11:50:12

Hi Francois,

I have been reading the code you recommended, and I think I must have
misexplained myself. I am not developing a driver, I am updating a
patch that we use at our research group, in which we modify linux to
make our custom packet processing, getting all the packets from the
NICs into a custom queue for processing.

It will obviously not going to be integrated in the linux kernel,
because its way to work is just useful to us, thought when we have
something that works, we have planned to distribute it.

I work with net_device, because I mainly use its fields, but I provide
functions to enable/disable capturing from a specific net_device. Now,
as napi_struct has appeared, I can't no longer use the
netif_rx_disable/enable functions, but I still need to know how to get
the already created napi_struct from my net_device pointers.

I think I have been looking in a too low level,

Regards,

Javier Domingo


2012/10/29 Francois Romieu [off-list ref]:
Javier Domingo [off-list ref] :
[...]
quoted
              inside of the net_device structure, I know I can take
the net_device pointer as documented in [3], but how may  I obtain the
napi_struct from the netdevice? or I am doing it the wrong way?
You are doing it the wrong way. The napi_struct you need is not embedded
here. See

$ less +/napi drivers/net/ethernet/realtek/8139cp.c

(first match in struct cp_private).

You should really read one of the existing drivers.

--
Ueimor

Re: Information about napi_struct and net_device

From: Javier Domingo <hidden>
Date: 2012-10-29 17:41:06

I finally found the problem, and I think also the answer.

I am modifying netif_receive_skb(), putting there my own queue. So the
only problem I face now is how may I disable the main netpoll through.

Looking at dev.c file, and knowing that there must be some way the
solution I was looking for, I discovered enqueue_to_backlog function,
that does what I want to do, from a packet, after processing it, be
able to take the napi_struct that was responsible from it.

I if you could tell me if using the method to obtain the napi_struct
from the net_device pointer used in enqueue_to_backlog is ok, it would
be great,

Any way I will continue doing experiments and reading,

Thanks a lot for your help and attention, and for whoever did [1]

Javier Domingo

[1]: http://www.linuxfoundation.org/images/1/1c/Network_data_flow_through_kernel.png

2012/10/29 Ben Hutchings [off-list ref]:
On Sat, 2012-10-27 at 18:18 +0200, Javier Domingo wrote:
quoted
Hello,

I am updating a kernel patch from 2.6.23-rc7 to v3.6, using git
facilities, and I have found that there have been lots of changes in
networking. Now the drivers are all by vendor, and more important,
net_device is not used always, as napi_struct took its place.

I have asked in #kernel but no one answered me, so I subscribed here.
Is there any place I can read about how is it now designed the use of
napi_struct and net_device? I have found a presentation[1] about how
networking was changing etc, and I wondered if there is anything more
precise about how it is actually implemented.

I understand a little why napi_struct, but don't really know much
about the change,

Hope someone can help me,
The initial change to napi_struct is explained in
<http://lwn.net/Articles/244640/>.

Since then there have been further changes:

- netif_napi_del() has been added.  You must call it to clean up NAPI
contexts before freeing the associated net device(s).

- Instead of netif_rx_schedule(), netif_rx_complete(), etc. you must use
napi_schedule(), napi_complete() etc. which just take a napi_struct
pointer.

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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help