1 2 Previous Next 17 Replies Latest reply on May 2, 2015 9:01 AM by ttc7152

    Consistently slow WiFi peformance on Edison after running my TCP server

    aneedles

      Hi,

       

      I am having consistently slow WiFi performance after running my TCP server. I have included code below that opens a single TCP socket. The code then blocks on the accept() command while waiting for the remote TCP client to connect. If I kill the process at this point, then I start seeing network issues indicated by a consistently slow (~1000mSecs) ping response when I ping my host laptop or any internet address from the Edison. This is just one symptom of this behavior, since I can also run my server successfully for a while and then successfully shut it down  - but then get the same ~1000msec delay when trying to ping.

       

      I have just re-flashed the Edison with the latest image (as of 4/9/15), so I know that that should not be an issue.

      I have turned on power management, but this did not resolve the issue.

       

      Please let me know if you have any ideas on what I can try.

       

      Thanks,

           Aaron

       

      int main()

      {

          int buflen;

          int optval;

          int status;

       

        tcp_portnum = 10000;

        udp_portnum = UDP_LOCAL_PORTNUM;

        udp_remote_portnum = UDP_REMOTE_PORTNUM;

       

        // TCP socket

          init_sockfd = socket(AF_INET, SOCK_STREAM, 0);

          if (init_sockfd < 0)

             error("ERROR opening TCP socket");

       

        // UDP socket

          udp_sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

          if (init_sockfd < 0)

             error("ERROR opening UDP socket");

       

          // TCP bind and listen

          //

        // Set SO_REUSEADDR option on the socket to true (1)

        // to avoid "Address already in use" error messages when restarting server

        //  after a recent crash or shutdown.

        optval = 1;

        setsockopt(init_sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);

       

        bzero((char *) &serv_addr, sizeof(serv_addr));

        serv_addr.sin_family = AF_INET;

        serv_addr.sin_addr.s_addr = INADDR_ANY;

        serv_addr.sin_port = htons(tcp_portnum);

        if (bind(init_sockfd, (struct sockaddr *) &serv_addr,

        sizeof(serv_addr)) < 0)

        error("ERROR on TCP binding");

       

        listen(init_sockfd,5);

       

        printf("Waiting for accept()...\n");

        clilen = sizeof(cli_addr);

        tcp_sockfd = accept(init_sockfd,

        (struct sockaddr *) &cli_addr,

        &clilen);

        if (tcp_sockfd < 0)

        error("ERROR on accept");

      ...

        • 1. Re: Consistently slow WiFi peformance on Edison after running my TCP server
          CMata_Intel

          Hi aneedles

           

          Could you add a screenshot of a ping to google with and without the TCP server to compare the results?

          How did you turned on power management and which changes are you able to see after this?

           

          Have you tried to test the packages in the server with netstat or tcpdump?

          You can also disable the other interfaces you are not using like lo or usb0

           

          Regards;

          CMata

          • 2. Re: Consistently slow WiFi peformance on Edison after running my TCP server
            aneedles

            Hi CMata,

             

            I tried to built a minimal C application that demonstrates the issue so that others can replicate it. The results were surprising. One function causing the issue appears to be mraa_gpio_init(7).  There seem to be other things that trigger the issue as well, but this the simplest case I have found. Please take a look.

             

            /*

            * EdisonNetworkTest2.c

            * Author: Aaron Needles

            *

            * Desc: A test program to illustrate the WiFi issues caused by this mraa

            *  function call. From a console, ping both local and remote targets before and after

            *  calling EdisonNetworkTest2. On my Edison I see ping performance degrade to ~1000ms

            *  response times.

            */

             

            #include "mraa.h"

            mraa_gpio_context digIn;

             

            int main()

            {

              printf("Performing mraa_gpio_init(7) and then hang.\r\n");

              digIn = mraa_gpio_init(7);

             

              while (1) {}; // Hang

            }

             

            To replicate the issue:

            1. Run Putty to connect to a console over the virtual serial port.

            2. Give the Edison a fresh boot.

            3. Login

            4. Run the ping command for several targets

            5. Launch Eclipse and download and run the text program (below).

            6. Wait for Eclipse console to indicate that the program is running.

            7. Run the ping command for several targets as before.

             

            Please see my output below. After this program runs, the ping response rate degrades to ~1000ms.

             

            Are you able to replicate this simple test on your end?

             

            Thanks,

            Aaron

             

            ========================================================

            Poky (Yocto Project Reference Distro) 1.6.1 three ttyMFD2

             

            three login: root

            Password:

            root@three:~# ping 192.168.0.2

            PING 192.168.0.2 (192.168.0.2): 56 data bytes

            64 bytes from 192.168.0.2: seq=0 ttl=128 time=29.411 ms

            64 bytes from 192.168.0.2: seq=1 ttl=128 time=21.971 ms

            64 bytes from 192.168.0.2: seq=2 ttl=128 time=20.050 ms

            64 bytes from 192.168.0.2: seq=3 ttl=128 time=25.305 ms

            ^C

            --- 192.168.0.2 ping statistics ---

            4 packets transmitted, 4 packets received, 0% packet loss

            round-trip min/avg/max = 20.050/24.184/29.411 ms

            root@three:~# ping netgear.com

            PING netgear.com (54.200.99.0): 56 data bytes

            64 bytes from 54.200.99.0: seq=0 ttl=110 time=45.426 ms

            64 bytes from 54.200.99.0: seq=1 ttl=110 time=63.181 ms

            64 bytes from 54.200.99.0: seq=2 ttl=110 time=61.290 ms

            64 bytes from 54.200.99.0: seq=3 ttl=110 time=60.315 ms

            ^C

            --- netgear.com ping statistics ---

            4 packets transmitted, 4 packets received, 0% packet loss

            round-trip min/avg/max = 45.426/57.553/63.181 ms

             

            < Here is where I run Eclise to download and run my test application EclipseNetworkTest2 >

             

            root@three:~# ping 192.168.0.2

            PING 192.168.0.2 (192.168.0.2): 56 data bytes

            64 bytes from 192.168.0.2: seq=0 ttl=128 time=1014.923 ms

            64 bytes from 192.168.0.2: seq=1 ttl=128 time=1014.558 ms

            64 bytes from 192.168.0.2: seq=2 ttl=128 time=1013.911 ms

            64 bytes from 192.168.0.2: seq=3 ttl=128 time=1013.646 ms

            64 bytes from 192.168.0.2: seq=4 ttl=128 time=1013.291 ms

            ^C

            --- 192.168.0.2 ping statistics ---

            6 packets transmitted, 5 packets received, 16% packet loss

            round-trip min/avg/max = 1013.291/1014.065/1014.923 ms

            root@three:~# ping netgear.com

            PING netgear.com (54.218.118.186): 56 data bytes

            64 bytes from 54.218.118.186: seq=0 ttl=110 time=1018.741 ms

            64 bytes from 54.218.118.186: seq=1 ttl=110 time=1018.433 ms

            64 bytes from 54.218.118.186: seq=2 ttl=110 time=1018.072 ms

            64 bytes from 54.218.118.186: seq=3 ttl=110 time=1017.600 ms

            64 bytes from 54.218.118.186: seq=4 ttl=110 time=1017.243 ms

            ^C

            --- netgear.com ping statistics ---

            6 packets transmitted, 5 packets received, 16% packet loss

            round-trip min/avg/max = 1017.243/1018.017/1018.741 ms

            root@three:~#

            • 3. Re: Consistently slow WiFi peformance on Edison after running my TCP server
              aneedles

              I'm still struggling with unreliable WiFi, and I hoped that someone at Intel could try the test above - which could perhaps point you towards uncovering and solving this issue. I am able to run my application fine using Ethernet over USB, but not over various WiFi networks.  Reliable WiFi is critical for my application, and it appears that this is an issue with Edison running the latest image as provided by Intel.  The WiFi feature is core to the Edison product line as well as core to many of our projects throughout the community. I have seen similar requests in other threads. Is Intel looking into this issue? Please let us know...

               

              Thanks,

                   Aaron

              • 4. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                CMata_Intel

                Hi aneedles

                 

                I apologize for the delay in my response. In the Release Notes for the latest image there is a known issue (Section 3.2) with GPIO 48 (Linux) / 7 (Arduino Expansion Board) that affects WiFi performance. Have you tried to run your code directly in the board without Eclipse? and with other pins? In your main code are you using this pin?

                 

                Regards;

                CMata

                • 5. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                  aneedles

                  Hi CMata,

                   

                  Thanks for the response. Yes, I have the same issue if I run my app from the Edison, not using Eclipse.

                  Initially turning the power management off (using "iwconfig wlan0 power off") before

                   

                  Thanks, I see the note about Arduino pin 7. I am only using it as an input, so I don't set it to an output. Not the same conditions, but the same pin.

                   

                  This is not the only call into mraa library that causes the same WiFi issue. I get the issue after most other calls to other IOs (such as digital inputs 5, 6 and 8).  I think this needs a thorough review by Intel, and I hope someone there can run some tests to figure out where this dependency exists.

                   

                  Another interesting item...

                  Once the WiFi is running in the slow state, if I then call "iwconfig wlan0 power off", WiFi goes dead and the wlan0 driver is no longer listed when I run "ifconfig".

                   

                  Thanks,

                     Aaron

                  • 6. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                    aneedles

                    In reviewing this thread, I realize that I might have missed a few details that would make it more clear to some who are reading it through.  In my original post, I was thinking that the WiFi issues that I was experiencing were somehow related to my socket programming, so this is all that I included in my post. Later, I spent several hours trying to narrow the problem down to a minimal code section that could be more easily tested. I was surprised to find that my socket code was not responsible for triggering the issue. Instead, the mraa library calls appear to be the culprit. I am running the Edison on an Arduino breakout board (Intel® Edison and Arduino Breakout Kit), and this could be related to the issue somehow.

                     

                    Thanks in advance to anyone who can provide their own experience, work-arounds or insights into this issue.

                     

                    -Aaron

                    • 7. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                      CMata_Intel

                      Hi aneedles

                       

                      How are you powering the board? If you are powering it with the USB cable, have you tried to power the board with a power supply?

                      Do you have the same behavior if you use the Arduino IDE to control the pins?

                      Have you tried to get a clean image with the flashall file? Do you have the same results? In some cases flashing the board with reboot ota can cause some issues, so try with that and let me know your results. I will do some tests too with a breakout board and some calls to MRAA.

                       

                      Regards;

                      CMata

                      • 8. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                        romankubanek

                        Hi,

                        Maybe this could be help you:

                         

                        non blocking mode for socket: fcntl(soc, F_SETFL, O_NONBLOCK);

                        or set socket timeouts:

                        setsockopt(soc, SOL_SOCKET, SO_KEEPALIVE, (const char *) &iOption,  sizeof(int)

                         

                        struct timeval recvTimeout;

                        recvTimeout.tv_sec = 20;

                        recvTimeout.tv_usec = 1;

                        setsockopt(soc, SOL_SOCKET, SO_SNDTIMEO, (const char *) &recvTimeout,  sizeof(recvTimeout))

                        setsockopt(soc, SOL_SOCKET, SO_RCVTIMEO, (const char *) &recvTimeout,  sizeof(recvTimeout))

                         

                        Roman

                        • 9. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                          MarkHaysHarris777

                          hello, glad to read your post about wifi performance;  I have exactly the same issue, and I have reproduced it on two different Edison stacks using only the mraa library.

                           

                          I do not use the Arduino breakout board, and I am not doing any socket(s) programming.  This problem is caused by invoking the gpio init on one or more pins.

                           

                          I am using the Sparkfun blocks (just to let you guys know my setup, not really related) and I am writing on gpio  pins  gpio44 gpio45 gpio46 gpio47 gpio48 gpio49 and I am inputing on  gpio15 and gpio14 with a rising edge interrupt on gpio14.  I am also reading an i2c ADC block from Sparkfun, but not related (if that code is removed I still have the issue).

                             gpio->pin8 = mraa_gpio_init(31);                                            

                             gpio->pin7 = mraa_gpio_init(45);                                            

                             gpio->pin6 = mraa_gpio_init(32);                                            

                             gpio->pin5 = mraa_gpio_init(46);                                            

                             gpio->pin4 = mraa_gpio_init(33);                                            

                             gpio->pin3 = mraa_gpio_init(47);                                

                             gpio->pin2 = mraa_gpio_init(48);                                

                             gpio->pin1 = mraa_gpio_init(36);    

                           

                          The pin8 - pin1 are my pin designations. The 31,45,32,46,33,47,48,and 36 are mraa designations  which map to Sparkfun gpio breadout as gpio44, gpio45,gpio46,gpio47,gpio48,gpio49,gpio15,gpio14....  neither here nor there...

                           

                          It is the mraa_gpio_init(xx) code that is causing the wpa_supplicant to get fouled up (wifi performance really drags down).  I HAVE FOUND THIS WORK AROUND:

                           

                          After you run your code (after I start my interrupt line driver) all you need to do as root on the edison is to restart the wpa_supplicant service like this:

                           

                          systemctl restart wpa_supplicant

                           

                          That will take some seconds or maybe half a minute... after that your wifi will work again.  Also, I am able to start and stop my line driver without affecting the wpa_supplicant after the first time.   The first time after a reboot, then running mraa_gpio_init() I will have the wifi problem until I restart the wpa_supplicant service.

                           

                          The bottome line:   for some reason the mraa_gpio_init() library code is honking up the wifi wpa_supplicant performance dramatically!  It makes the wifi use a show stopper.

                           

                          I am able to send my complete reduced codes to anyone who would like to look at them as a tarball (its small).   Any and all help with this is appreciated.

                           

                          By the way,  I am not using Eclipse... I code directly on the Edison in C. I have verified this wifi performance using the Sparkfun gpio breakout block, and using the Intel mini breakout board,   on two Edison SoC(s) both updated with the latest firmware, and both running the latest mraa library 0.6.2

                           

                          Thanks

                          1 of 1 people found this helpful
                          • 10. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                            aneedles

                            Hi CMata,

                            A. I am powering with an external power supply of ~12VDC.

                            B. Please see MarkHaysHarris777 post below for similar issues in using the mraa library outside of Eclipse. I am glad to hear I am not the only one struggling with this fault.

                            C. Yes, I have installed a fresh image, and the new image does not help.

                            D. This is related to the mraa_gpio_init() call. Now that we have confirmation of a second person with the same issue, please submit this as a bug so that it can be researched and fixed. I need my application to work with this library, or I need to move on to other hardware.

                             

                            Many thanks,

                            Aaron

                            • 11. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                              aneedles

                              Hi Roman,

                              Thanks, but how would this help?

                              -Aaron

                              • 12. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                                aneedles

                                Thanks MarkHaysHarris777,

                                It is good to get some outside confirmation of the issue.

                                I will try restarting wpa_supplicant to see if I get the same behavior.

                                -Aaron

                                • 13. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                                  CMata_Intel

                                  Hi guys;

                                   

                                  I was testing and I will continue doing it in order to pass these results and your feedback to a proper team.

                                   

                                  Hi MarkHaysHarris777 ; there is a known bug that affects WiFi performance when the GPIO48 is being used. If you use all the other ones but not the 48 do you still have problems?

                                  Hi aneedles  I used your code and yes when I used the same code I had network issues then I stopped the code and the issue continues so I ran configure_edison --wifi again to connect to the same network and check if it change something. Then when I was doing ping calls seems to be fine. I ran your code again and when using ping calls to test this I received normal times. Could you check if after configuring again the WiFi connection with configure_edison --wifi you get the same behavior? Also let me know the outcome of Mark's suggestion.

                                   

                                  Kind Regards;

                                  CMata

                                  • 14. Re: Consistently slow WiFi peformance on Edison after running my TCP server
                                    MarkHaysHarris777

                                    hi CMata,  thank you!   You are correct.  If I comment out my codes for my pin4 [ (mraa 33) (gpio48) ] then I do not have wifi degradation or any wifi performance issue.

                                     

                                    So it looks like the trigger in my code is  mraa_gpio_init(33) , which maps to gpio48, which is my pin4 designation.

                                     

                                    I commented out the gpio48 and used only the others and my wifi performance issue vanished even after first reboot. When I put the lines back into my project codes then I get wifi performance issue first time after reboot;  which I can correct by restarting the wpa_supplicant service.

                                     

                                    In order to avoid conflicts within my Sparkfun block stack I really only get to use the eight(8) pins I listed.  If I cannot use gpio48 then my project breaks (I really need that pin)!

                                     

                                    Thanks for your help to get this to the right team for fix !

                                     

                                    PS:  This bug appears to be a similar issue as previously reported via pdf in February as  EDISON:2326, and EDISON:2356

                                    PPS:  I do note that the mraa 0.6.2 'related files' page for Intel Edison  (under Arduino breakout board) list the fact that Arduino pin7 can cause problems with wifi and further recommends not using pin7 if using wifi. The problem here is that the spec sheet for mraa Intel Edison does not list a cross mapping between gpio48 and Arduino pin7 (this can be done of course, with extra work if you know the problem).  There should be a warning on the mraa site under Intel Edison that mraa_gpio_init(33) , init and output on gpio48, will 'probably' cause problems with wifi;  also, work-arounds should be listed as well.  With a work-around I can move forward with development, but this problem is going to be a show-stopper for Intel Edison if it does not get fixed soon, particularly for folks using the dual H bridge and the Sparkfun blocks...

                                     

                                    Kind regards,

                                    marcus

                                     

                                    1 2 Previous Next