SPRACT8 September   2020 66AK2H06 , 66AK2H12 , 66AK2H14

 

  1.   Abstract
  2.   Trademarks
  3. 1Introduction
    1. 1.1 TI Processor SDK RTOS
    2. 1.2 TI NDK
    3. 1.3 66AK2H Device
    4. 1.4 FTP Offering in TI Processor SDK RTOS
  4. 2Hardware and Software
  5. 3Develop the FTP Server on K2H
    1. 3.1 Reference FTP Server Example
    2. 3.2 Create K2H FTP Server Example
    3. 3.3 Test K2H FTP Server Example
  6. 4Performance Tuning
    1. 4.1 Quick Code Check
      1. 4.1.1 FTP Transmitting Code Check
      2. 4.1.2 FTP Receiving Code Check
      3. 4.1.3 CCS Project Optimization
    2. 4.2 Increase the TCP Buffer Sizes
    3. 4.3 UIA CPU Load Instrumentation
    4. 4.4 What Can We Do on the PC Side?
      1. 4.4.1 TCP Window Scaling Check
      2. 4.4.2 Receive Interrupt Coalescing Check
    5. 4.5 What Else Can We Do on the K2H Side?
      1. 4.5.1 TCP/IP Checksum Offloading Check
      2. 4.5.2 NIMU Driver Efficiency Profiling
      3. 4.5.3 Receive Interrupt Coalescing
    6. 4.6 Final FTP Throughput Results
  7. 5Summary
  8. 6References

Increase the TCP Buffer Sizes

The default TCP transmitting and receiving buffer sizes are defined in ndk_3_xx_xx_xx\packages\ti\ndk\inc\stack\inc\resif.h with 8192 bytes for devices with small memory footprint:

#define DEF_SOCK_TCPTXBUF           8192
#define DEF_SOCK_TCPRXBUF           8192
#define DEF_SOCK_TCPRXLIMIT         8192

Those buffers can be increased in the FTP server main_k2h.c code before NC_NetStart() is called:

    //
    // This code sets up the TCP and UDP buffer sizes
    // (Note 8192 is actually the default. This code is here to
    // illustrate how the buffer and limit sizes are configured.)
    //
    // TCP Transmit buffer size
    rc = 65536;
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPTXBUF,
             CFG_ADDMODE_UNIQUE, sizeof(uint32_t), (uint8_t *)&rc, 0 );

    // TCP Receive buffer size (copy mode)
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXBUF,
             CFG_ADDMODE_UNIQUE, sizeof(uint32_t), (uint8_t *)&rc, 0 );

    // TCP Receive limit (non-copy mode)
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXLIMIT,
             CFG_ADDMODE_UNIQUE, sizeof(uint32_t), (uint8_t *)&rc, 0 );

65,536 bytes is the maximum size for a TCP buffer. However, with such changes, you may see the FTP connection is refused while ping to the EVM is still responsive.

The most common reason is memory allocation failure. To check this, one can add print statement for failure code in socket() and accept() API calls inside ftpserver.c:

    if ((listen_sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET)
    {
        printf("Failed to open listen socket with error %d\n", fdError());
}

    if( (client_sock = accept(listen_sock, (struct sockaddr*)&client_addr, &len)) == INVALID_SOCKET)
    {
        /* Timeout, Wait a short time and try again */
	 printf("Failed to accept with error %d\n", fdError());
        …
    }

As expected, the fdError() returns NDK_ENOMEM (12) in one of the error conditions. So the NDK memory needs to be increased. If another number returns, one can translate that number with ndk_3_xx_xx_xx\packages\ti\ndk\inc\serrno.h.

TCP buffers are directly allocated from heap, while all other NDK modules allocate buffers from NDK memory table, which is also allocated from heap. The heap size is controlled by BIOS.heapSize inside the .cfg file, increasing it from 0x40000 to 0x100000 resolves the FTP connection failure issue. The ROV view provides a snapshot of heap memory usage. The Ethernet throughput is improved to 50-60MB/s after increasing the TCP buffer sizes.

GUID-20200819-CA0I-SP7K-7WN2-JLZCCS4LMLKJ-low.png Figure 4-2 Heap Memory RTOS Object View