Thursday, December 14th 2017, 11:05am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Date of registration: Apr 8th 2015

Posts: 8

Location: Darmstadt, Germany

Occupation: Software Developer

1

Wednesday, April 8th 2015, 3:59pm

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
while(1)
{
    IP_PACKET * pPacket;
    U32 bytes = 512;

    do
    {
        pPacket = IP_TCP_Alloc(bytes);
    } while(pPacket == NULL);

    /* memset(pPacket->pData, '.', bytes); */

    int iSend = 0;
    do
    {
        iSend = IP_TCP_Send(fd, pPacket);
    } while(iSend < 0);
}

This post has been edited 1 times, last edit by "stefan.waldschmidt" (Apr 8th 2015, 4:35pm)


Date of registration: Apr 8th 2015

Posts: 8

Location: Darmstadt, Germany

Occupation: Software Developer

2

Thursday, April 9th 2015, 2:52pm

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

SEGGER - Oliver

Super Moderator

Date of registration: Nov 14th 2007

Posts: 41

3

Friday, May 29th 2015, 11:26am

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