Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

How to bypass checksum calculation?

To speed up transmition of udp packet, i tried to bypass the checksum calculation by

modifying 2 lines of file opt.h in folder:

...\components\altera_lwip\UCOSII\src\downloads\lwip-1.10\src\include\lwip

define CHECKSUM_GEN_UDP 0

define CHECKSUM_CHECK_UDP 0

But no any improvement on speed can be seen. Could somebody here tell me how to do this? Thanks a lot.

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi johnd,

    you should open the file udp.c and comment 4 lines out:

    // if ((pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {

    // udphdr->chksum = inet_chksum_pseudo(q, src_ip, &pcb->remote_ip, IP_PROTO_UDP, q->tot_len);

    /* chksum zero must become 0xffff, as zero means 'no checksum' */

    // if (udphdr->chksum == 0x0000) udphdr->chksum = 0xffff;

    // }

    this way you should get a bandwith of + 50%, that was in our case

    cheers,

    Danny
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Danny,

    Thank you. But it's very strange, after doing that you told me above and re-building my project, still no improvement. I find that your method has the same effect with that i did by following up the trace of the udp routine by putting some printf() phrase at place interested.

    it's true, the routine has jumped over checksum calculation, but the result is still not good. Any idea else?

    johnd
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Danny,

    Thank you for your help. I think I have got a key in my case and like to share with you and other friends.

    My system is based on a IS10 DEV kit from Altera, uses Nios2/f cpu. UDP transmition runs on ucos II as a task. My work is to collect image(320*256 pixels,16bit) into SDRAM and send they to a host. Here is my UDP routine:

    # define TOTAL_UDP 160 // total packets, 1K bytes a packet# define UDP_EACH_DATA 1024 // bytes,# define UDP_PAYLOAD_BYTES UDP_EACH_DATA+2 // add index number of

    packet

    volatile int num_udp_completed=0;

    void SSSUDPSendTask()

    {

    struct netconn *conn;

    struct netbuf *buf;

    struct ip_addr addr;

    INT8U err;

    unsigned short* udp_packet_addr;

    unsigned int udp_addr_offset;

    int j;

    /* confique connection to host as UDP */

    conn = netconn_new(NETCONN_UDP);

    /* set up the IP address of the remote host */

    addr.addr = htonl(HostIPAddress);

    /* connect the connection to the remote host */

    netconn_connect(conn, &addr, HostUDPPortNum);

    /* create a new netbuf */

    buf = netbuf_new();

    while(1)

    {

    // wait for a semaphore from DMA task

    OSSemPend(CAMDMAFinishSem,0,&err);

    for(j=0;j<4;j++) // send 2k pixels each time

    {

    /* set the base and offset address of UDP packet */

    udp_addr_offset = UDP_EACH_DATA * num_udp_completed;

    udp_packet_addr = (unsigned short*)(dma_data_base + udp_addr_offset-2);

    /* insert index before data */

    *udp_packet_addr = num_udp_completed;

    /* reference the data into the netbuf */

    netbuf_ref(buf, (unsigned char*)udp_packet_addr, UDP_PAYLOAD_BYTES);

    netconn_send(conn, buf);

    num_udp_completed++;

    }

    if (num_udp_completed == TOTAL_UDP)

    {

    num_udp_completed = 0;

    }

    } //while(1)

    }

    Now in my system the time spending on collecting 100 frame pictures has decreased from 40.5 to 7 sec via following steps.

    (1) move phrases (netconn_new().. buf =) to outside while(1) loop as above routine shows. this makes the time drop from 40.5 to 20.2 seconds.

    (2) next step, use your udp.c routine, the time reaches 15.4 sec. i doubt if the lwip calculates checksum for each element of data.

    (3) change the compile option, configuration, from Debug to Release. that is in c/c++builder of properties of myproject and myproject_syslib. the time is 7 sec.

    The result is not bad although something still let me maze.

    Thanks to you again,

    Cheers,

    Johnd
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi John,

    I think the main difference is that I don&#39;t use an OS. Ik can reach speed up to 80 MBit/s with UDP. With a modified NIOS II/f and use the lwIP-stack. Is your program based on the simple socket server-example!?

    Also set the option optimize most in the NIOS IDE... you get a large footprint of code, but large bandwith...

    If you would like my workspace and my NIOS II, just let me know...

    Good luck,

    Danny
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Danny,

    So high throughput! that&#39;s great!

    Yes, my program is based on simple socket server modified. I also set compile optimize to -O3. as you said that the OS and hardware optimization will be a big reason to influnce UDP throughput. If you can, i would like to learn from your design very much. but the workspace is too big, how can you..?

    Have a good weekend,

    Johnd