Sending data using zero-copy

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Sending data using zero-copy

    Hi all,

    does anyone have experience sending data using zero-copy, especially with TCP?

    With the code below I am experiencing system-lockups (either in HardError-handler or an endless-loop somewhere in the IP-stack) after 5 to 30 seconds.
    Until then, the performance is awesome :)

    What is wrong with my code? Any working example, or link to some documentation?

    Thanks
    Stefan

    Source Code

    1. while(1)
    2. {
    3. IP_PACKET * pPacket;
    4. U32 bytes = 512;
    5. do
    6. {
    7. pPacket = IP_TCP_Alloc(bytes);
    8. } while(pPacket == NULL);
    9. /* memset(pPacket->pData, '.', bytes); */
    10. int iSend = 0;
    11. do
    12. {
    13. iSend = IP_TCP_Send(fd, pPacket);
    14. } while(iSend < 0);
    15. }
    Display All

    The post was edited 1 time, last by stefan.waldschmidt ().

  • Some reasons for the problems

    To follow up on my own post:

    One major reason for my problems was probably the lack of network buffers:
    After all available buffers are in use by low-priority tasks, the high-priority zero-copy task endlessly loops in

    Source Code

    1. do
    2. {
    3. pPacket = IP_TCP_Alloc(bytes);
    4. } while(pPacket == NULL);


    Increasing the number of configured buffers and adding a sleep() helped a lot.

    Still, I would love to see some working examples and/or documentation.

    Some other improvements were made to my code, here is the complete version. Any comments?

    Thanks
    Stefan

    Source Code

    1. while(1) {
    2. IP_PACKET * pPacket;
    3. U32 bytes = 512;
    4. do {
    5. pPacket = IP_TCP_Alloc(bytes);
    6. if (pPacket == NULL) {
    7. /* If this happens, increase the number of buffers! */
    8. OS_Delay(1);
    9. }
    10. } while(pPacket == NULL);
    11. /* fillData(pPacket->pData, bytes); */
    12. int iSend = 0;
    13. do {
    14. iSend = IP_TCP_Send(client->fd, pPacket);
    15. if(iSend == IP_ERR_RESOURCE) {
    16. /* No free space in socket's TX-buffer */
    17. /* This OS_Delay is critical;
    18. * for resposiveness of low-priority tasks and throughput */
    19. OS_Delay(1);
    20. }
    21. } while(iSend == IP_ERR_RESOURCE);
    22. if(iSend != 0) {
    23. IP_TCP_Free(pPacket);
    24. break;
    25. }
    26. } /* while(1) */
    Display All
  • Hello Stefan,

    Thank you for your report and the mail sent to the support address.
    As you already know by mail the problem with TCP zero copy has been found and will be officially fixed in the next release.

    Best regards,
    Oliver
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.