lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Socket read/write and threads


From: Yoav Nissim
Subject: Re: [lwip-users] Socket read/write and threads
Date: Tue, 12 Jan 2010 18:41:50 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0



On 12/01/10 17:17 PM, Nicolas Pinault wrote:


Yoav Nissim a écrit :
select() should not block on write_fds for long, so I would agree that something is not working properly.
That said, you do have to make sure that your output buffers are large enough to take the screen updates you expect the system to maintain.
If not, I guess that packets are lost.
Are you using TCP or UDP connections? If you are using TCP connections, the packets would not be lost; I believe that selecting on the socket would block until some buffers are recovered.

The porting and IF init code is the best place to start. AFAIK:
1. The call from your Rx thread should not call ethernetif_input() directly. It should call netif->input() - which in turn is initialized to tcpip_input() when you call netif_add().
2. Your output logic seems OK.
3. All input and output should be called from within the TCPIP thread. Therefore actual input and output operations do not occur simultaneously. Only queueing of operations occurs simultaneously.
4. The call to the your if_init/netif_add function should be done from within TCPIP's thread context (using the callback given to tcpip_init())

Nicolas, please post your initialization code - the call to netif_add(), who calls it, and your interface initialization function (the 6th parameter in the netif_add() API)
Here is my init code :
   // Start the TCP/IP thread & init stuff
   tcpip_init(NULL, NULL);

   // Interface ethernet
   IP4_ADDR(&ipaddr, 0,0,0,0);
   IP4_ADDR(&netmask, 0,0,0,0);
   IP4_ADDR(&gw, 0,0,0,0);

   netifapi_netif_add(&fec_eth, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input);
   netif_set_default(&fec_eth);
   netifapi_dhcp_start(&fec_eth);

Although I do not use the netifapi, your initialization code seems fine to me.

What about application thread priority ? Do you set them at higher priority than TCPIP thread priority ?
My setup is quite different than yours. I have no control over application thread priorities, while the TCPIP thread runs at 'normal' priority - i.e most of the time app threads are of the same priority as the TCPIP thread, but not always.
Generally speaking, I would say your tcpip thread should have a higher priority than your apps so that it does not become a bottleneck. I do believe though that the more important contention is between other important components in the system and the effect on them if tcpip takes up too much cpu time.

Nicolas

Yoav.

p.s  All of my comments are based on my experience with lwIP which is by no means complete. I defer all my remarks to Simon, Kieran, et al...



On 12/01/10 10:31 AM, Nicolas Pinault wrote:


Yoav Nissim a écrit :
Pardon me for barging in... I have encountered the same issue about a
week or two ago.
Using select() would be the natural choice for performing multiple
non-blocking operations.

You can either:
1. Use select() in a single thread to perform both Rx & Tx (recommended)
2. Keep Rx and Tx threads locked and waiting on a select running in
another thread (in essence adding the locking mechanism that lwIP does
not support)

 
As with a single thread my application still does not work correctly, I suspect there is a bug in my port.
I'd like to check some points :

I use a thread for MAC rx. This thread waits for MAC rx frames and calls ethernetif_input().
This thread has a lower priority than TCPIP_THREAD_PRIO. Is this ok ?

My current port implementation is simple and when transmitting, low_level_output() waits for the packet to be sent before returning (wait on a semaphore set by Tx interrupt). Is this ok ?

There is no mutex between tx and rx functions. That is, ethernetif_input() can be entered while low_level_output() is running and vice-versa.
Is this a problem ?

What must be the application thread priorities ? Higher priority than TCPIP_THREAD_PRIO ? Lower priority than TCPIP_THREAD_PRIO ?

Regards,
Nicolas





HTH,
Yoav.


On 11/01/10 9:46 AM, Nicolas Pinault wrote:
 
address@hidden a écrit :
  
Nicolas Pinault wrote:
    
Is this a threading problem ?
          
Yep, using a socket from more than one thread at the same time is
currently not supported.
     
Ok.
So, what do you recommend to asynchronously send and receive data
(with a socket).

Nicolas
  
Simon


_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users

     
_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users


   

 


_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users

-- 
Yoav Nissim
Software Engineer, Software Tools Division
Jungo Software Technologies
Email: address@hidden
Web: http://www.jungo.com
Phone: +972-74-7212138
Fax: +972-74-7212122
Mobile: +972-54-2271315
------------------------------------------------------------------------

_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________ lwip-users mailing list address@hidden http://lists.nongnu.org/mailman/listinfo/lwip-users

-- 
Yoav Nissim
Software Engineer, Software Tools Division
Jungo Software Technologies
Email: address@hidden
Web: http://www.jungo.com
Phone: +972-74-7212138
Fax: +972-74-7212122
Mobile: +972-54-2271315

reply via email to

[Prev in Thread] Current Thread [Next in Thread]