Skip to contentSkip to conversation

Realtek r8168 slow outbound transfer - potential fix/workaround

DISCUSSION David Gundersen 2 participants 3 messages Jun 13, 2007 – Jun 14, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi all,

I've been doing a bit of investigation work into a problem that I've been experiencing with the latest available r8168 driver from realtek ('r8168-8.001.00') & linux kernel 2.6.21.1.

I have been experiencing wierd problems with slow outbound traffic that seem to go away if there's traffic coming into the device. Googling seen reports of this in a number of places on the web so I get the feeling I'm not alone.

I decided to spend a few hours looking into this and as best I could tell it's because back-to-back outbound packets result in the 2nd packet being mysteriously dropped.

What I found was that line 2505:

RTL_W8(TxPoll, NPQ);

in the rtl8168_start_xmit() handler is the part that's telling the NIC to kick off the next transfer.

I'm guessing that the signal must be edge triggered because after a few checks I noticed that during times of heavy transmission, it was possible for the card to still have this bit set from the previous packet's transmission request, with the result being that the command to kick off the next packets' transmission would be lost. The net effect of this was that timeouts & retransmits were occurring further up the protocol stack, and I believe that was what was responsible for the terrible performance.

Now, on to my workaround. Putting a spin style wait like the following in front of the line above seemed to solve the problem for me:

if (RTL_R8(TxPoll) & NPQ) {
    for (i = 20; i > 0; i--) {
     if (!(RTL_R8(TxPoll) & NPQ))
      break;
     udelay(25);

}
}

...

RTL_W8(TxPoll, NPQ);

This waits for the card to signal that it's dealt with the previous packet before telling it to process the next. YMMV.

It would be interesting to hear if other people have similar success with the above workaround. Also, I'm not convinced that having a spin style wait is the best solution here - if anybody else is able to offer a better solution it'd be great to hear it.

Kind Regards,

Dave.

#1 lore raw

David Gundersen <[email protected]> :
[...]

Quoted 8 lines

I've been doing a bit of investigation work into a problem that I've been experiencing with the latest available r8168 driver from realtek ('r8168-8.001.00') & linux kernel 2.6.21.1.

I have been experiencing wierd problems with slow outbound traffic that seem to go away if there's traffic coming into the device. Googling seen reports of this in a number of places on the web so I get the feeling I'm not alone.

What is the value of the MTU for your 8168 device ?

Signature · 1 line
Ueimor
#2 lore raw
Quoted 2 lines

What is the value of the MTU for your 8168 device ?

Hi Francois,

The MTU for the adapter is set at the default of 1500.

A bit more background on how I came across this might be in order. I noticed it when performing very simple SQL queries against a postgres database on my server. I captured the traffic on an XP client machine using wireshark and on the linux server with tcpdump. I noticed that although the linux server claimed to have sent 2 reply packets, XP was seeing only the first.

What got me thinking was the fact that the time between the first and second response packets from postgres was 0.000005 seconds (according to the tcpdump timestamps). Another 0.4 seconds after that a retry was attempted and the packet managed to make it though to the windows client. I started wondering if there might be something going on with tightly spaced packets and that's how I ended up checking the NPQ flag.
(I also looked into increasing the default interframe gap between
packets, but that didn't seem to help).

I'm happy to help with additional information including the packet captures if you'd like to take a look.

Also, I realised after I posted that first message that having a minimum udelay of 25us in that delay loop was probably a bit foolish. I guess I was just so happy to have found something that worked for me that I needed to get it off my chest before thinking it through fully. The udelay(25) ends up increasing the minimum inter-frame gap way beyond what should be reasonable. I haven't had a good chance to test this yet, but I tried dropping the udelay(25) and using ndelay(10) instead and it appeared to load the cpu less that way.

Regards,
Dave.