Choosing the right lwip API...

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Choosing the right lwip API...

DownyTif
Hi all,

I was wondering what API I should use to do what I want to do. By the way, I'm new to the mail-list/forum and lwip world. I tried to find the differences between the Raw, sockets or sequential (netconn) APIs, but I haven't found anything useful.

I started to write a program using the netconn API, mainly because the example I had was using it (Control Panel Demo application on the Atmel EVK1100 evaluation board). The communication is between the board and a host PC using 2 ports (so, 2 sockets). One port is dedicated to bidir requests/responses communication between the board and the host PC. The second port is dedicated to "as fast as possible" transfers from the board to the host PC using big packets (ideally around 32768-byte packets to minimize hand-shaking). Each port has is own task (using FreeRTOS), but I could make it with one port only if necessary.

I currently have a problem right now, described in this post:
http://www.nabble.com/netconn_write-throughput-stuck-at-1024-bytes-to21571019.html

So, I was thinking that maybe the sequential API (netconn) was not the way to go. According to what I have written above, does anybody of you have a suggestion on the correct API to use? Or at least information that could help me choose between the three?

Thanks a lot,
Downy
Reply | Threaded
Open this post in threaded view
|

Re: Choosing the right lwip API...

Jonathan Larmour
DownyTif wrote:
> Hi all,
>
> I was wondering what API I should use to do what I want to do. By the way,
> I'm new to the mail-list/forum and lwip world. I tried to find the
> differences between the Raw, sockets or sequential (netconn) APIs, but I
> haven't found anything useful.

http://lwip.wikia.com/wiki/LwIP_Wiki has a lot of stuff about the APIs. In
essence the raw API is event-driven, the sequential (netconn) API, is a
more traditional API with calls to e.g. netconn_write() which can block
until the operation completes, and the sockets API is the same sort of
thing as the sequential API, but using the well-known BSD sockets
functions (like socket(), bind(), listen() accept(), etc.).

Each API (raw->sequential->sockets) in turn has more overhead (both code
and data) and is slightly slower than the previous one, and for some
hardware, you can get much better performance with the raw or sequential
APIs than the sockets API in some situations, but that doesn't mean the
sequential or sockets APIs are slow. If performance is critical for you
(and your other mail implies this might be tree) it could be that the raw
API is a better choice. Although you have to do more things yourself with
the raw API.

> So, I was thinking that maybe the sequential API (netconn) was not the way
> to go.

It's unrelated to your other mail about large packet sizes. An
event-driven model such as the raw API affects your program design a lot.
Some people like the familiarity of the sockets API if they've used it
elsewhere, or if they are reusing existing code. It's a choice with
trade-offs between them, which is why lwIP has all three!

Jifl
--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------      Opinions==mine


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Choosing the right lwip API...

DownyTif
I do have some more questions on this topic... I decided to test the speed improvements using the RAW API. This API allows me to use only one thread to do whatever I want instead of two threads using the sequential API because the "recv" is blocking and I need to send data in the idle time.

1- I just read from the Wiki that the RAW API can only be used by the main thread?? In my project, I need the main thread to call "vTaskStartScheduler()" to run FreeRTOS for multithreading, which never returns. So, I can't use my main thread to manage the RAW API, but I can call "tcp_new", "tcp_bind", "tcp_listen" and "tcp_accept" before. Is that sufficient?

2-
What do I need to call to use/init the RAW API? For the sequential, I was using sys_init(), mem_init(), memp_init(), pbuf_init(), netif_init(), tcpip_init(EthernetConfigInterface, NULL). I'm not sure if I still need those... or if I'm missing something.

3-
I haven't found it, so I think it would be good to have a little resume of what are the #defines needed by all the API. For example, if I want to use the RAW API, I must absolutly define some values in the lwipopts.h file. Personally, I'm not sure I have everything configured ok..

Thanks,
Downy




Jonathan Larmour wrote
DownyTif wrote:
> Hi all,
>
> I was wondering what API I should use to do what I want to do. By the way,
> I'm new to the mail-list/forum and lwip world. I tried to find the
> differences between the Raw, sockets or sequential (netconn) APIs, but I
> haven't found anything useful.

http://lwip.wikia.com/wiki/LwIP_Wiki has a lot of stuff about the APIs. In
essence the raw API is event-driven, the sequential (netconn) API, is a
more traditional API with calls to e.g. netconn_write() which can block
until the operation completes, and the sockets API is the same sort of
thing as the sequential API, but using the well-known BSD sockets
functions (like socket(), bind(), listen() accept(), etc.).

Each API (raw->sequential->sockets) in turn has more overhead (both code
and data) and is slightly slower than the previous one, and for some
hardware, you can get much better performance with the raw or sequential
APIs than the sockets API in some situations, but that doesn't mean the
sequential or sockets APIs are slow. If performance is critical for you
(and your other mail implies this might be tree) it could be that the raw
API is a better choice. Although you have to do more things yourself with
the raw API.

> So, I was thinking that maybe the sequential API (netconn) was not the way
> to go.

It's unrelated to your other mail about large packet sizes. An
event-driven model such as the raw API affects your program design a lot.
Some people like the familiarity of the sockets API if they've used it
elsewhere, or if they are reusing existing code. It's a choice with
trade-offs between them, which is why lwIP has all three!

Jifl
--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------      Opinions==mine


_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Choosing the right lwip API...

Jonathan Larmour
DownyTif wrote:

> I do have some more questions on this topic... I decided to test the speed
> improvements using the RAW API. This API allows me to use only one thread to
> do whatever I want instead of two threads using the sequential API because
> the "recv" is blocking and I need to send data in the idle time.
>
> 1- I just read from the Wiki that the RAW API can only be used by the main
> thread?? In my project, I need the main thread to call
> "vTaskStartScheduler()" to run FreeRTOS for multithreading, which never
> returns. So, I can't use my main thread to manage the RAW API, but I can
> call "tcp_new", "tcp_bind", "tcp_listen" and "tcp_accept" before. Is that
> sufficient?

It just means a single thread. It doesn't have to be the thread used for
main(). What really matters is that nothing can call into lwIP core code
from more than one context at the same time, whether it be another thread,
interrupt handler, etc.

> 2-
> What do I need to call to use/init the RAW API? For the sequential, I was
> using sys_init(), mem_init(), memp_init(), pbuf_init(), netif_init(),
> tcpip_init(EthernetConfigInterface, NULL). I'm not sure if I still need
> those... or if I'm missing something.

What version of lwIP are you using? For 1.3.0, you can use lwip_init()
instead for much of it, except for tcpip_init (which is specific to when
using the sequential or sockets APIs). See src/core/init.c. I would have
hoped it would be in the wiki, but from a look around I'm not sure it's
there yet.

Actually it should also be described in doc/rawapi.txt in the source
distribution. Patches welcome from anyone who's tried it recently!

> 3-
> I haven't found it, so I think it would be good to have a little resume of
> what are the #defines needed by all the API. For example, if I want to use
> the RAW API, I must absolutly define some values in the lwipopts.h file.
> Personally, I'm not sure I have everything configured ok..

Most of the defines are still relevant when using the raw API. And the
ones that aren't relevant are ignored. After all, the sequential API is
essentially just a user of the raw API itself.

Jifl
--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------      Opinions==mine


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Choosing the right lwip API...

DownyTif


On Wed, Jan 28, 2009 at 6:50 PM, Jonathan Larmour <[hidden email]> wrote:
DownyTif wrote:
I do have some more questions on this topic... I decided to test the speed
improvements using the RAW API. This API allows me to use only one thread to
do whatever I want instead of two threads using the sequential API because
the "recv" is blocking and I need to send data in the idle time.

1- I just read from the Wiki that the RAW API can only be used by the main
thread?? In my project, I need the main thread to call
"vTaskStartScheduler()" to run FreeRTOS for multithreading, which never
returns. So, I can't use my main thread to manage the RAW API, but I can
call "tcp_new", "tcp_bind", "tcp_listen" and "tcp_accept" before. Is that
sufficient?

It just means a single thread. It doesn't have to be the thread used for main(). What really matters is that nothing can call into lwIP core code from more than one context at the same time, whether it be another thread, interrupt handler, etc.
 
Alright, understood.
 


2- What do I need to call to use/init the RAW API? For the sequential, I was
using sys_init(), mem_init(), memp_init(), pbuf_init(), netif_init(),
tcpip_init(EthernetConfigInterface, NULL). I'm not sure if I still need
those... or if I'm missing something.

What version of lwIP are you using? For 1.3.0, you can use lwip_init() instead for much of it, except for tcpip_init (which is specific to when using the sequential or sockets APIs). See src/core/init.c. I would have hoped it would be in the wiki, but from a look around I'm not sure it's there yet.

Actually it should also be described in doc/rawapi.txt in the source distribution. Patches welcome from anyone who's tried it recently!
 
 
I didn't know about this text file, thanks. I'm using lwip 1.2.0 for Atmel AVR32 UC3 included in the framework they provided. Is there significant improvements in 1.3.0? Cause I don't know if they ported it or just used it plain as downloaded... And I surely don't have time to port it right now.
 
 


3-
I haven't found it, so I think it would be good to have a little resume of
what are the #defines needed by all the API. For example, if I want to use
the RAW API, I must absolutly define some values in the lwipopts.h file.
Personally, I'm not sure I have everything configured ok..

Most of the defines are still relevant when using the raw API. And the ones that aren't relevant are ignored. After all, the sequential API is essentially just a user of the raw API itself.
 
 
Understood also. I was setting to 0 what I was presuming to not be used by the API. I'll make a .h usable both by the raw and sequential API to ease my testings.
 


Jifl
--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------      Opinions==mine


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users


_______________________________________________
lwip-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/lwip-users