[En-Nut-Discussion] NutThreadYield() in NutTcpReceive()

Ole Reinhardt ole.reinhardt at embedded-it.de
Thu Jan 7 23:36:16 CET 2016


Hi Vlaidimir and all others,

thank you very much for your patch. Indeed I do not understand the
reason, why these NutThreadYields had been placed in these functions.

It in deed tuned out, that removing these yields improved the stream
throughput reasonably.

I removed these yields by default but added a new configurator option
TCP_REENABLE_THREADYIELDS to re-enable the yields again.

Best regards,

Ole Reinhardt

Am 23.11.2015 um 13:09 schrieb Vladimir Isaev:
> Hi!
> 
> In our project we use the Nut/Net TCP stack for a small HTTP server
> implementation. It was noticed it works very slow due to current
> NutTcpReceive() implementation: every time it is invoked it calls
> NutThreadYield() just at the very beginning, yielding the time to
> all other threads before it finally reads the next piece of data.
> Thus, when the program wants to read a lot of small pieces of data
> from a TCP stream (for instance, by calling fgets() on the stream),
> then it yields the CPU to other threads *for every char* dramatically
> slowing down the process.
> 
> Finally, we have decided to remove the NutThreadYield() call from
> NutTcpReceive() (and NutTcpSend() too). With this patch calling
> fgets() on a TCP stream works much faster. As to the yielding of
> CPU time, it is possible (and resonable) to call NutThreadYield()
> at a higher level, outside of TCP stack, without forcing a yield
> on every send/receive operation, isn't it?
> 
> Index: nut/net/tcpsm.c
> ===================================================================
> --- nut/net/tcpsm.c     (revision 6229)
> +++ nut/net/tcpsm.c     (working copy)
> @@ -884,7 +884,6 @@
>      if (sock == NULL) {
>          return -1;
>      }
> -    NutThreadYield();
> 
>      switch (sock->so_state) {
>      case TCPS_LISTEN:
> Index: nut/net/tcpsock.c
> ===================================================================
> --- nut/net/tcpsock.c   (revision 6229)
> +++ nut/net/tcpsock.c   (working copy)
> @@ -536,7 +536,6 @@
>      /*
>       * Check parameters.
>       */
> -    NutThreadYield();
> 
> sion at egnite.de
> -    NutThreadYield();
>      /*
>       * Check parameters.
>       */
> 

-- 
kernel concepts GmbH            Tel: +49-271-771091-14
Sieghuetter Hauptweg 48         Mob: +49-177-7420433
D-57072 Siegen
http://www.embedded-it.de
http://www.kernelconcepts.de


More information about the En-Nut-Discussion mailing list