Skip to contentSkip to conversation

gianfar ethernet driver

RFR Applied jamal 6 participants 25 messages Jul 7, 2004 – Aug 22, 2004 7 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

jamal

author
#2 lore raw
In reply to a message not in the archive
Quoted 14 lines · Andy Fleming

I've made many of the changes, and am working on others, but I would like a few clarifications:

Jeff Wrote:

Quoted 3 lines
Quoted 3 lines

2) I'm strongly pondering vetoing try_fastroute() code in this driver. Surely this should be in core net stack code... if it isn't already? Jamal?

Quoted 4 lines · Jamal

I hardly know anybody still using this interface - i believe it is not useful after NAPI; maybe this comment would bring out some of the believers out of the woodwork to comment.
Otherwise i would say kill it.

Quoted 6 lines

Hmm.. We had some testing done (admittedly in 2.4), and this code substantially increased routing speed for some cases. I admit, though, that the code is ugly. It would be nice if the part which is clearly generic across all controllers were inside the stack, but if no one uses it (and finding an example of a driver which did was difficult), then maybe it's not worth the effort.

Can you describe your test scenarios where it was valuable and what kind of throughput (and possibly latency) you were seeing?
BTW, is this a gige interface?

Quoted 10 lines
Quoted 4 lines
Quoted 4 lines

8) I recommend enabling _both_ hardware interrupt coalescing and NAPI, at the same time. Several other Linux net drivers need to be changed to
do this, as well

Ok... but this is possible with the driver as it is. Interrupt Coalescing is runtime configurable, and NAPI is a compile-time option. NAPI can sometimes hurt performance, and so we'd like to have the ability to disable it for some deployments. I guess I'm not sure what change this suggestion was meant to cause.

In your observation when is NAPI hurting performance? I am familiar with one case where extra PCI reads become a problem consuming extra CPU. We have so far rejected to "fix" that.

Quoted 7 lines
Quoted 7 lines
if (txbdp == priv->dirty_tx) {
	netif_stop_queue(dev)
	unlock
	return 1;
}

The rest of your code goes here ..

Quoted 7 lines
Quoted 3 lines

Do this before the skb is touched. Note the return 1. This means dont add it to your priv->tx_skbuff[priv->skb_curtx] = skb before you do this.

Right. Technically, I'm doing that one full call before the skb is touched. I think you're just missing the line above it where I increment the descriptor pointer to the next one.

You dont return a 1 anywhere.
Heres what i mean (substitute your code):
if no more descriptors
netif_stop_queue(dev)
unlock
return 1
process packet and stash on ring
return 0

Quoted 4 lines
Quoted 1 line

Dont understand why you have your own proivate list btw.

Is there another list which deallocates skbs after I have transmitted them?

TX completion interupt is supposed to keep free them typically at the interupt handler. So no need to track them unless you are trying something fancy - hence my question.

Quoted 6 lines
Quoted 5 lines

2) Also its pretty scary if you are doing:
txbdp->status |= TXBD_INTERRUPT for every packet. Look at other drivers, they try to do this every few packets; or enable tx mitigation to slow the rate of those interupts.

Quoted 6 lines

I don't believe this is as dire as you think. This bit only indicates that, if the conditions are right, an interrupt will be generated once that descriptor is processed, and its data sent. Conditions which mitigate that are:
1) coalescing is on, and the timer and counter have not triggered the interrupt yet

This is what i was recommending; but even without this, look at the Becker style approach in a lot of drivers of not triggering interupts in all cases.

Quoted 2 lines

2) NAPI is enabled, and so interrupts are disabled after the first packet arrives

Depends on approach you took for NAPI (sorry deleted code/email). If you went e1000 styloe, then you are correct. If you went tulip style, the tx interupts are still on.

Quoted 5 lines

3) NAPI is disabled, but the driver is currently handling a previous interrupt, so the interrupts are disabled for now.

Since interrupts are so often disabled at the controller, this has the effect of not letting each packet trigger an interrupt.

You are theorizing here and doing a very poor job. Have you actually tried and proven this? This will discount everything to date thats been done to reduce interupt rates.

Quoted 4 lines

However, in a
low-traffic case, not setting the Interrupt bit in the descriptor will cause the packet to sit around indefinitely, until a packet with the bit set is sent.

I am not sure i followed. But it seems to me thats a bug.

Quoted 3 lines

Obviously, with interrupt coalescing enabled, this
becomes less of an issue (assuming our hardware doesn't require the bit in order to increment the frame counter or start the timeout timer...).

Your hardware seems to be buggy or you not explaining well. Anyways, you know what to do in this area.

cheers,
jamal

#3 lore raw
Quoted 1 line · jamal

You dont return a 1 anywhere.

That OK in one model.

Quoted 7 lines

Heres what i mean (substitute your code):
if no more descriptors
netif_stop_queue(dev)
unlock
return 1
process packet and stash on ring
return 0

When you are not dealing with fragments, the most optimal model eliminates the overflow case completely, so your ->hard_start_xmit looks like

lock
queue packet to DMA ring
if (DMA ring full)
netif_stop_queue()
unlock

return 0

If you can be sure -- by design -- that room is always available when the queue is not stopped, then that's fine.

With fragments, you cannot be sure of this, if you do not wish to reserve MY_HW_MAX_FRAGMENTS slots on the DMA. Such a case would require moving the "if no more descriptors" check up, and returning 1 when the ring is empty.

But ideally, you should write the driver where such a condition does not occur at all.

Jeff

author
#4 lore raw
Quoted 4 lines · Jeff Garzik
Quoted 1 line · jamal

You dont return a 1 anywhere.

That OK in one model.

True returning 0 this is not wrong; it
results in an extra call in the layer above the driver. (I was trying to point that out in earlier email)

Quoted 15 lines

When you are not dealing with fragments, the most optimal model eliminates the overflow case completely, so your ->hard_start_xmit looks like

lock
queue packet to DMA ring
if (DMA ring full)
netif_stop_queue()
unlock

return 0

If you can be sure -- by design -- that room is always available when the queue is not stopped, then that's fine.

Quoted 7 lines

With fragments, you cannot be sure of this, if you do not wish to reserve MY_HW_MAX_FRAGMENTS slots on the DMA. Such a case would require moving the "if no more descriptors" check up, and returning 1 when the ring is empty.

But ideally, you should write the driver where such a condition does not occur at all.

Ok, I overlooked fragments. I think it would be useful to capture this in the doc you were preping. BTW, why can you figure out the fragment count? If you can then the check for number of descriptors availabel could account for that.

cheers,
jamal

#17 lore raw
In reply to a message not in the archive
Quoted 8 lines · Andy Fleming
Quoted 5 lines
Quoted 5 lines

7) ethtool_ops should not be kmalloc'd.

(quoted diff) +2 -0
+       dev_ethtool_ops =
+               (struct ethtool_ops *)kmalloc(sizeof(struct 

ethtool_ops),
+ GFP_KERNEL);

Is there a particular reason? The reason I did it this way is because the driver supports a 10/100 controller which does not have the RMON statistics, and therefore should not read from that register space. So I needed to use different functions to fill in the statistics lists.

Just switch out one static pointer for another, once you know the hardware you're dealing with. You _must_ have that knowledge anyway, before calling register_netdev(), otherwise you're got a race in initialization versus interface-up.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

8) I recommend enabling _both_ hardware interrupt coalescing and NAPI, at the same time. Several other Linux net drivers need to be changed to do this, as well

Ok... but this is possible with the driver as it is. Interrupt Coalescing is runtime configurable, and NAPI is a compile-time option. NAPI can sometimes hurt performance, and so we'd like to have the ability to disable it for some deployments. I guess I'm not sure what change this suggestion was meant to cause.

Default hardware mitigation to on in all cases, and preferably NAPI as well.

If you see cases that hurt performance, that wants investigating.

Quoted 4 lines
Quoted 1 line
Quoted 1 line

14) surely gfar_set_mac_address() needs some sort of synchronization?

I'm not sure why. It only gets called during gfar_open(), and startup_gfar() gets called after it.

Incorrect. Set-mac-address can be called when the interface is up and active, such as by the bonding driver.

Quoted 4 lines
Quoted 1 line
Quoted 1 line

15) gfar_change_mtu() synchronization appears absent?

I'm not exactly sure what kind of synchronization is expected here. stop_gfar() and startup_gfar() do modify the appropriate hardware values.

Same conditions (and response) as set-mac-address. These can be called while you're actively DMAing packets.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

23) gfar_set_multi() does not appear to take into account huge multi-cast lists. Drivers usually handle large dev->mc_count by falling back to ALLMULTI behavior.

Actually, it does. The bits which are set represent hash table values.
Essentially, the MAC addr is converted to an 8-bit CRC. This value
then serves as an index to the 256-bit hash table. If the list is large, then certain bits may be written twice, but if all the bits are set, then the behavior is the same as in the ALLMULTI behavior -- every multicast packet arrives. It would be a mistake, IMHO, to cut it off after N entries, as several of those entries could overlap in the bitmap. Clearly, the less bits which are set, the more effective the hardware filter, so checking each address will, I think, always be a performance win or tie (on the filtering side) over ALLMULTI

ok

Quoted 8 lines
Quoted 5 lines

Review

Quoted 5 lines

24) setting IFF_MULTICAST is suspicious at best, possibly wrong:

(quoted diff) +4 -0
+       dev->mtu = 1500;
+       dev->set_multicast_list = gfar_set_multi;
+       dev->flags |= IFF_MULTICAST;
+

I'll believe you, but is there a reason for this? I guess it's already set, by default, so easy fix.

follow the other drivers, and behave predictably :)

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

28) I see you support register dump (good!), now please send the register-pretty-print patch to the ethtool package :)

Heh. Well, I haven't written that, yet. There's actually a slight problem, in that the 85xx registers are 32-bit, and refuse to be accessed as bytes. I'll be sure to look at that in the near...ish future.

Nothing wrong with accessing registers as 32-bit quantities. That attribute is common to a lot of NICs.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

31) infinite loops, particularly on 1-bits, are discouraged:

(quoted diff) +2 -0
+       /* Wait for the transaction to finish */
+       while (gfar_read(&regbase->miimind) & (MIIMIND_NOTVALID |

MIIMIND_BUSY))
+ cpu_relax();

What is the suggested method for waiting for the bus to be free? Should I timeout after some time, and bring the driver down?

it's really up to you, as it depends on the implementation platforms.

The most simple is to include a counter that counts down to zero, and starts some absurdly large number like 100000.

Quoted 10 lines
Quoted 2 lines
Quoted 2 lines

33) merge-stopper: mii_parse_sr(). never wait for autonegotiation to complete. it is an asynchronous operation that could exceed 30 seconds.

Hmm...

Quoted 1 line
Quoted 1 line

34) merge-stopper: dm9161_wait(). same thing as #33.

This may be a problem. That function is there to work around an issue in the PHY, wherein if you try to configure it before it has come up all the way, it refuses to bring the link up. We've sworn at this code many times, but there has, as of yet, not been a good suggestion as to how we can ensure that the 9161 is ready before we configure it.

I interpret that as a driver bug :)

As common sense, regardless of phy bugs, you should not be trying to configure the MAC _or_ the phy in the middle of autonegotiation. Presumeably you are using a combination of netif_stop_queue(), netif_carrier_off(), and netif_device_detach() to achieve this.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

35) liberally borrow code and ideas from Ben H's sungem_phy.c. Eventually we want to move to a generic phy module.

Heh. ironically, I stole liberally from the ibm_emac driver, which now looks exactly like the sungem_phy code for phy handling. A generic phy module would be a good thing, and I'm even interested in helping with code and/or suggestions. If nothing else, I'll jump on the new generic phy module bandwagon!

Cool. This item #35 is more of a long term "think about it" type of request. Please do not hesitate to think of ways that you could share code with sungem_phy.c, and/or make them both use the same API, and submit patches along those lines :)

It's not enough to just write a driver, help change Linux for the better :)

Quoted 9 lines

From Jamal:

Quoted 4 lines

1) The check (in gfar_start_xmit()):

Should happen much sooner - i.e before the skb is touched.

I'm not sure I agree here. What I am doing is detecting the full state before an skb needs to be rejected. I am testing the NEXT descriptor to see if it is ready (if not, dirty_tx will be pointing to it). This way, I always handle any skb that is passed to gfar_start_xmit()

See my comments to jamal as well: if you guarantee that you always have room on the DMA ring for an additional skb, that check should never be needed.

Some extremely cautious/paranoid programmers will add a check, with a printk noting it's a BUG (i.e. impossible) condition, such as

	if (unlikely(... no more descriptors ...)) {
		printk(KERN_ERR "%s: BUG: no room for TX\n", dev->name);
		netif_stop_queue();
		spin_unlock_irqrestore();
		return 1;
	}

	... queue TX to hardware ...

	if (no more descriptors)
		netif_stop_queue()

	spin_unlock_irqrestore()
Quoted 10 lines
Quoted 4 lines

2) Also its pretty scary if you are doing:
txbdp->status |= TXBD_INTERRUPT for every packet. Look at other drivers, they try to do this every few packets; or enable tx mitigation to slow the rate of those interupts.

I don't believe this is as dire as you think. This bit only indicates that, if the conditions are right, an interrupt will be generated once that descriptor is processed, and its data sent. Conditions which mitigate that are:
1) coalescing is on, and the timer and counter have not triggered the interrupt yet
2) NAPI is enabled, and so interrupts are disabled after the first packet arrives
3) NAPI is disabled, but the driver is currently handling a previous interrupt, so the interrupts are disabled for now.

Even at 10/100 speeds, you really don't want to be generating one interrupt per Tx...

Jeff

#5 lore raw
In reply to jamal
Quoted 4 lines · jamal
Quoted 2 lines · Jeff Garzik

On Tue, Jul 06, 2004 at 11:18:02PM -0400, jamal wrote:

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

You dont return a 1 anywhere.

That OK in one model.

True returning 0 this is not wrong; it
results in an extra call in the layer above the driver. (I was trying to point that out in earlier email)

er, I'm confused now?

Every single ethernet driver returns zero, when it has queued a packet to hardware :) That's the common case, I would hope it doesn't result in additional work.

Quoted 20 lines
Quoted 20 lines

When you are not dealing with fragments, the most optimal model eliminates the overflow case completely, so your ->hard_start_xmit looks like

lock
queue packet to DMA ring
if (DMA ring full)
netif_stop_queue()
unlock

return 0

If you can be sure -- by design -- that room is always available when the queue is not stopped, then that's fine.

With fragments, you cannot be sure of this, if you do not wish to reserve MY_HW_MAX_FRAGMENTS slots on the DMA. Such a case would require moving the "if no more descriptors" check up, and returning 1 when the ring is empty.

Quoted 8 lines
Quoted 2 lines

But ideally, you should write the driver where such a condition does not occur at all.

Ok, I overlooked fragments. I think it would be useful to capture this in the doc you were preping. BTW, why can you figure out the fragment count? If you can then the check for number of descriptors availabel could account for that.

In one design, you can say

queue packet
if (free descriptors < MAX_SKB_FRAGS)
netif_stop_queue()
return 0

That design wastes descriptors, but ensures you always have enough room when ->hard_start_xmit is called, and thus ensures you never have to return 1.

Another design, that attempts to use more descriptors, is

	if (free descriptors < skb->frags)
		netif_stop_queue()
		return 1

	queue packet

	if (free descriptors == 0)
		netif_stop_queue()
	return 0
author
#6 lore raw
Quoted 10 lines · Jeff Garzik
Quoted 4 lines

True returning 0 this is not wrong; it
results in an extra call in the layer above the driver. (I was trying to point that out in earlier email)

er, I'm confused now?

Every single ethernet driver returns zero, when it has queued a packet to hardware :) That's the common case, I would hope it doesn't result in additional work.

Its a small optimization. In either case, the xmit() will not be invoked again until device wakes up - so both models are fine from that perspective. In the case of returning a zero there will be a few more lines of code executed trying to see if qdisc has a packet before realizing the device is stopped and requeueing that packet. Not something to sweat over to be honest. If i had 1000 hours available and nothing fun to work on (theres always something fun to do) then i will start changing things. I think you should encourage new drivers to use the return 1 scheme though.

Quoted 19 lines
Quoted 5 lines

Ok, I overlooked fragments. I think it would be useful to capture this in the doc you were preping. BTW, why can you figure out the fragment count? If you can then the check for number of descriptors availabel could account for that.

In one design, you can say

queue packet
if (free descriptors < MAX_SKB_FRAGS)
netif_stop_queue()
return 0

That design wastes descriptors, but ensures you always have enough room when ->hard_start_xmit is called, and thus ensures you never have to return 1.

Another design, that attempts to use more descriptors, is

Quoted 10 lines
	if (free descriptors < skb->frags)
		netif_stop_queue()
		return 1

	queue packet

	if (free descriptors == 0)
		netif_stop_queue()
	return 0

Looking good.

cheers,
jamal

#19 lore raw
In reply to a message not in the archive
Quoted 1 line · Andy Fleming

Ok, I will change the defaults. Our performance testing indicates that ttcp performance with mtu=1500 drops if NAPI is enabled vs. when it is not. This is for both TCP and UDP packets. This made sense to me, as NAPI incurs a slight latency penalty, and for 1518 byte frames, it does not gain much advantage from interrupt reduction.

NAPI only begins to mitigate at the weighted traffic level. Maybe your poll weight is too low? It sounds like you still need to do some tuning and profiling.

For periodic but not high volume traffic, NAPI shouldn't incur latency penalties as you should be re-enabling interrupts shortly thereafter.

Only when you start hitting the NAPI thresholds does it start reducing interrupts. At which point you should be at traffic levels where eliminating interrupt overhead should -decrease- your CPU usage.

Quoted 1 line

Hmm... Does it call dev->set_mac_addr()? Because that only seems to copy the new address into the dev structure. While I haven't been able to trace the notification chain to discover the exact sequence of events when someone changes the MAC address, I was thought that, in order for the change to take effect, the interface needed to be brought down, then up. gfar_set_mac_address() is only called during gfar_open(), so I am not aware of any way someone else could cause it to be called without restarting the interface. How should I set it up so that some other code could call it?

[...]

Quoted 1 line

Yes, which is why gfar_change_mtu() halts the controller (thus ceasing all DMA activity, and freeing buffer memory), then changes the MTU, and then starts the controller again, causing buffers to be reallocated. I feel like I'm missing something obvious. Perhaps I don't understand exactly what you mean when you say "synchronization"? Are we talking about locking, or making sure the hardware is configured without screwing things up? Or...what?

Through ifconfig, you can test changing MTU and MAC address while the interface is up. Probably other tools (/sbin/ip?) also.

Synchronization means, what happens if all of the following occur at the same time:
1) RX packet received
2) net stack calls dev->hard_start_xmit() to transmit a packet
3) user decides he wants to change MAC addr/MTU

?

By synchronization, I mean that you must ensure all entry points into your driver are protected from racing against each other, or simultaneously accessing the same data structure(s).

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

33) merge-stopper: mii_parse_sr(). never wait for autonegotiation to complete. it is an asynchronous operation that could exceed 30 seconds.

Hmm...

Quoted 1 line
Quoted 1 line

34) merge-stopper: dm9161_wait(). same thing as #33.

This may be a problem. That function is there to work around an issue in the PHY, wherein if you try to configure it before it has come up all the way, it refuses to bring the link up. We've sworn at this code many times, but there has, as of yet, not been a good suggestion as to how we can ensure that the 9161 is ready before we configure it.

Quoted 6 lines
Quoted 3 lines

I interpret that as a driver bug :)

As common sense, regardless of phy bugs, you should not be trying to configure the MAC _or_ the phy in the middle of autonegotiation. Presumeably you are using a combination of netif_stop_queue(), netif_carrier_off(), and netif_device_detach() to achieve this.

Hrm... This will require some fun, then. My current scheme for PHY configuration/management does not allow me to stop if autonegotiation isn't done. Clearly, I will have to rework the PHY code...

I'm not sure I understand the "My current scheme" sentence. Clearly RX/TX DMA is not running, if you are in the middle of autonegotiation. So just make efforts to ensure that the kernel doesn't try to TX packets during that time (netif_carrier_off and/or netif_stop_queue), and make sure that random user ioctls (such as change-mtu or set-mac-addr :)) do not stomp all over the MAC while the phy is in the middle of autoneg.

Good hardware will give you an interrupt when it link is up, otherwise you'll probably have to use a timer to poll for link (which isn't present until autoneg ends, obviously).

Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

2) Also its pretty scary if you are doing:
txbdp->status |= TXBD_INTERRUPT for every packet. Look at other drivers, they try to do this every few packets; or enable tx mitigation to slow the rate of those interupts.

Quoted 7 lines
Quoted 4 lines

I don't believe this is as dire as you think. This bit only indicates that, if the conditions are right, an interrupt will be generated once that descriptor is processed, and its data sent. Conditions which mitigate that are:
1) coalescing is on, and the timer and counter have not triggered the interrupt yet
2) NAPI is enabled, and so interrupts are disabled after the first packet arrives
3) NAPI is disabled, but the driver is currently handling a previous interrupt, so the interrupts are disabled for now.

Even at 10/100 speeds, you really don't want to be generating one interrupt per Tx...

Hmm... My concern is this from Documentation/networking/driver.txt:

Quoted 7 lines

"For example, this means that it is not allowed for your TX
mitigation scheme to let TX packets "hang out" in the TX ring unreclaimed forever if no new TX packets are sent. This error can deadlock sockets waiting for send buffer room to be freed up."

Is this no longer accurate? Anyway, as long as coalescing is on, there won't be one interrupt per frame.

Hopefully your hardware provides something other than purely packet-based intr mitigation? Usually there is a timeout, if no TX (or RX) interrupt has been sent in X time period.

Jeff

author
#8 lore raw
In reply to a message not in the archive
Quoted 4 lines · Jeff Garzik

To see if I understand you correctly, tell me if these two rules are right or wrong:

1) If netif_stop_queue() is called, return 1

Return 1 _iff_ you dont stash the packet on ring. If you return 1, the toplayer will retry later with the same skb. If you stash it on the ring, the danger is tx complete will try to free it later while the toplayer code is still referencing it. A good oops.

Quoted 1 line

2) Otherwise, return 0

This will always work, but not the most optimal.

Quoted 10 lines

?

Note carefully that with #1, you have two sub-cases:
a) queue packet
check free descriptors
maybe stop queue
b) check free descriptors

	maybe stop queue
	queue packet
	...

In both above cases return 0.

c) check free descriptors
if no space
stop queue; return 1
/* free space */
queue packet

Quoted 2 lines

i.e. the packet passed to dev->hard_start_xmit may or may not have been sent to hardware's DMA ring, when you stop the queue and return 1.

Dangerous to return 1 and queue packet.

Quoted 6 lines

Second point of note:

I worry that returning 1 when skb has -not- been queued to DMA ring will result in loss of packet, with certain packet schedulers. For example, a real-time packet scheduler may choose to drop rather than requeue the skb, as the NIC driver author would intend.

This is well taken care queueing code; if the scheduler decides that the packet to be returned is the one thats to be dropped then thats the responsibility of the scheduler. all we do is hand it a packet and say "please requeue that". This is a clean separation of tasks in Alexeys architecture. The driver is just a transmitter; the intelligence(real time, rate control) is above it.

Quoted 7 lines

While it may be reasonable for the packet scheduler to drop the packet, in normal use with skb fragments (sendfile/TSO) that would result in a packet potentially being dropped each time the NIC driver's dev->hard_start_xmit() could not queue a packet to hardware. The test (described in another email) of "free descriptors < MAX_SKB_FRAGS" following the queueing of an skb to hardware is intended to avoid this condition.

I think if thats what the scheduler is designed to do, it should, None of the current schedulers that mostly do rate control do so.

cheers,
jamal

author
#21 lore raw
In reply to a message not in the archive
Quoted 7 lines · Andy Fleming

I guess we'll have to do some more testing. The latency I'm talking about for NAPI, however, is the delay between calling __netif_rx_schedule(), and actually processing the packets. If you are dealing with a benchmark where you send a packet, and then wait for a response, and then send the next, and so on, doesn't this mean that there will be a performance penalty? Or have I misunderstood how NAPI works?

There may be some confusion.
There is overhead with NAPI in the case of low packet rates. What "low rate" means is dependent on your cpu capacity. For example consider the following:
- CPU interupted, interupt disabled, rx thread scheduled
- rx thread picks a packet off the DMA ring and process it to completion
- receive thread asks for another packet but none has come in since last one --> interupts enabled
.. x ms go by
- another packet comes in and process repeats.

In the above case as you can see the CPU can process each packet fast enough i.e before next packet comes in. How fast depends on your CPU. The above also shows that there are now at least two extra PCI operations (dis/enabling) interupts which wouldnt happen in the non-NAPI case. This will show up via slightly increased CPU usage typically. Yep, those web bench people bitch about this but so far weve seen no reason to change this. At low rates you should have plenty of CPU anyways.
Thats what i meant earlier that NAPI could be problematic at "low rates". Infact as hinted to you already once you exceed that "low rate" threshold, the CPU availability goes down.

What you can do is amortize the cost of that interupt enable/disable operation by rx coalescing as suggested by Jeff. So now instead of getting an immediate interupt for each incoming packet you get it for more than one or after a timeout.

Hopefully this helps.

cheers,
jamal

author
#22 lore raw
Quoted 11 lines · jamal

There may be some confusion.
There is overhead with NAPI in the case of low packet rates. What "low rate" means is dependent on your cpu capacity. For example consider the following:
- CPU interupted, interupt disabled, rx thread scheduled
- rx thread picks a packet off the DMA ring and process it to completion
- receive thread asks for another packet but none has come in since last one --> interupts enabled
.. x ms go by
- another packet comes in and process repeats.

Quoted 2 lines

In the above case as you can see the CPU can process each packet fast enough i.e before next packet comes in. How fast depends on your CPU.

I should have said also how loaded your CPU is. If your CPU is already loaded with other work it probably wont be processing those packets fast enough. Try running a while(1); loop program in user space and see.

Quoted 9 lines

The above also shows that there are now at least two extra PCI operations (dis/enabling) interupts which wouldnt happen in the non-NAPI case. This will show up via slightly increased CPU usage typically. Yep, those web bench people bitch about this but so far weve seen no reason to change this. At low rates you should have plenty of CPU anyways.
Thats what i meant earlier that NAPI could be problematic at "low rates". Infact as hinted to you already once you exceed that "low rate" threshold, the CPU availability goes down.

Meant: CPU becomes more available.

Quoted 12 lines

What you can do is amortize the cost of that interupt enable/disable operation by rx coalescing as suggested by Jeff. So now instead of getting an immediate interupt for each incoming packet you get it for more than one or after a timeout.

Hopefully this helps.

cheers,
jamal

#30 lore raw
In reply to a message not in the archive
Quoted 10 lines · Jeff Garzik
Quoted 5 lines · Andy Fleming

Ok, I've got the new PHY code working, and I've done most of the changes, but I have a couple more questions:

Quoted 2 lines
Quoted 2 lines

6) sysfs support: call SET_NETDEV_DEV()

Ok, the first argument should be dev, but what should the second argument be? This isn't a PCI device, it's an on-chip peripheral, so I'm not sure what the class_device should be.

It's a struct device, which all devices need to have.

I could have sworn OCP does struct device these days. If not, poke the platform people.

Ah, I found it. ocpdev->dev. Done.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

19) I think your gfar_poll() needs spin_lock_irqsave(), not spin_lock().

Hmm... I tried that, but netif_receive_skb() will eventually call local_bh_enable(), which dislikes my disabling interrupts. I could avoid this by unlocking around netif_receive_skb(), but this solution seems ugly to me. What is the preferred way of doing this?

Duh. I had a brainfart.

RX "synchronization" is normally done by simply ensuring that no other code will cause a NAPI poll. You shouldn't need spinlocks around that section of code at all. Take a look at drivers/net/tg3.c, tg3_rx()

Ok. I will send a new patch tomorrow.

Quoted 2 lines

Jeff

#31 lore raw
Quoted 4 lines · Andy Fleming
Quoted 2 lines

I could have sworn OCP does struct device these days. If not, poke the platform people.

Ah, I found it. ocpdev->dev. Done.

So we have BenH talking about pre-populating sysfs with objects for all the on-chip peripherals and metadata like MAC addresses. We have some PPC platforms using 'OCP' which does much the same thing, and ARM platforms using yet another implementation. Some drivers support more than one of these.

I suspect we need to bash some heads together... :)

Signature · 1 line
dwmw2
#9 lore raw
In reply to Jeff Garzik

Ok, here's the new patch to apply on top of the old patch. This is my first time using bk to generate a patch, so I beg forgiveness if something goes wrong.

...
Ok, I had to find a bug in the patch, first, so this got delayed from yesterday. But now it works. The patch includes a one-line addition to mii.h, declaring BMCR_SPEED1000, which is undefined on 10/100 PHYs, but seems to be used on all gigabit PHYs to form a two-bit field with BMCR_SPEED100, indicating gigabit speeds when their values are 1 and 0, respectively.

Andy

#10 lore raw
Quoted 1 line · Andy Fleming

Ok, here's the new patch to apply on top of the old patch.

Thanks. Will test when I get back from OLS and add the BCM5421S PHY support again.

Signature · 1 line
dwmw2
#23 lore raw
In reply to Jeff Garzik

Argh. We found a couple bugs in that last patch. This patch fixes those bugs. However, please note that the patch is done against the original submission from weeks ago. This patch replaces my most recent patch.

#24 lore raw
Quoted 1 line · Andy Fleming

Argh. We found a couple bugs in that last patch. This patch fixes those bugs. However, please note that the patch is done against the original submission from weeks ago. This patch replaces my most recent patch.

Thanks, I'll look it over.

I've been away celebrating (or mourning) my 30th birthday, and have several patches to run through. I'll add it to the pile, though it may be a few days before I get to it.

Jeff

#25 lore raw

Jeff,

Any update on this review of Andy's latest fixes?

thanks

- kumar

Quoted 9 lines · Jeff Garzik
Quoted 1 line · Andy Fleming

Argh. We found a couple bugs in that last patch. This patch fixes those bugs. However, please note that the patch is done against the original submission from weeks ago. This patch replaces my most recent patch.

Thanks, I'll look it over.

I've been away celebrating (or mourning) my 30th birthday, and have several patches to run through. I'll add it to the pile, though it may be a few days before I get to it.

Jeff

#26 lore raw
Quoted 7 lines · Kumar Gala

Jeff,

Any update on this review of Andy's latest fixes?

thanks

- kumar

So when will you fix the modular compile?

#27 lore raw

hch,

Will look at it today. Was not aware of this still not work.

thanks

- kumar

Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Kumar Gala

Jeff,

Any update on this review of Andy's latest fixes?

thanks

- kumar

So when will you fix the modular compile?

#11 lore raw
In reply to Jeff Garzik

Here's an updated patch which fixes module support which does this:

* More cleanup/minor bug fixes
* Added locking to PHY read/write wrappers
* Fixed module support
* Removed fastroute code

As before, this patch replaces the previous ones I have submitted.

Thanks,
Andy Fleming

#12 lore raw
Quoted 8 lines · Andy Fleming

Here's an updated patch which fixes module support which does this:

* More cleanup/minor bug fixes
* Added locking to PHY read/write wrappers
* Fixed module support
* Removed fastroute code

As before, this patch replaces the previous ones I have submitted.

the patch? :)

Jeff

#13 lore raw

D'oh!

Quoted 14 lines · Jeff Garzik
Quoted 8 lines · Andy Fleming

Here's an updated patch which fixes module support which does this:

* More cleanup/minor bug fixes
* Added locking to PHY read/write wrappers
* Fixed module support
* Removed fastroute code

As before, this patch replaces the previous ones I have submitted.

the patch? :)

Jeff

#14 lore raw

Ok, while we're still waiting, I found a couple of bugs, so here's another patch: same as before, only correct (I hope)

Andy

Quoted 16 lines · Andy Fleming

D'oh!

Quoted 13 lines · Jeff Garzik
Quoted 8 lines · Andy Fleming

Here's an updated patch which fixes module support which does this:

* More cleanup/minor bug fixes
* Added locking to PHY read/write wrappers
* Fixed module support
* Removed fastroute code

As before, this patch replaces the previous ones I have submitted.

the patch? :)

Jeff

#15 lore raw

Jeff,

Now that 2.6.8.1 is out what is the status of reviewing andy's changes?

thanks

- kumar

Quoted 21 lines · Andy Fleming

Ok, while we're still waiting, I found a couple of bugs, so here's another patch: same as before, only correct (I hope) Andy

Quoted 16 lines · Andy Fleming

D'oh!

Quoted 13 lines · Jeff Garzik
Quoted 8 lines · Andy Fleming

Here's an updated patch which fixes module support which does this:

* More cleanup/minor bug fixes
* Added locking to PHY read/write wrappers
* Fixed module support
* Removed fastroute code

As before, this patch replaces the previous ones I have submitted.

the patch? :)

Jeff

<patch_2004_8_4>