Home > Operation and Maintenance > Safety > How to optimize SylixOS network card driver

How to optimize SylixOS network card driver

WBOY
Release: 2023-05-14 11:16:14
forward
1395 people have browsed it

1. Development environment

  • Operating system: SylixOS

  • Programming environment: RealEvo-IDE3.1

  • Hardware platform: AT9x25 development board

1. Technical implementation

After the network card driver is written and the basic sending and receiving functions can be realized, This article will briefly introduce how to optimize the sending function of the network card driver and improve the throughput and real-time performance of sending.

1.1 Network card sending throughput optimization

The network card driver can improve sending throughput through zero copy. The driver calls the enetCoreTx sending function to realize the sending of Ethernet messages. This function receives two parameters, which are netdev structure type pointer and pbuf type pointer. enetCoreTx will copy the content pointed to by pbuf to the DMA send buffer pointed to by the send descriptor. This copy will have a certain impact on the sending throughput.

Therefore, when optimizing, you can change the buffer address pointed by the DMA descriptor to the pbuf structure member payload to point to the address where the message actually needs to be sent. The specific implementation is as shown in program listing 21.

Program List 21 Zero-copy Optimization

  if (usLen == pstPbuf->len) {
        if ((pstPbuf->type != PBUF_REF)&& (pstPbuf->type != PBUF_ROM)) {
            bCopy = LW_FALSE;
        }
    }
 
    if (!bCopy) {
        pbuf_ref(pstPbuf);
       pEnet->pTxRing[iHead].iTxBaddr = (UINT32)pstPbuf->payload;
        API_CacheFlushPage(DATA_CACHE,pstPbuf->payload, pstPbuf->payload, LW_CFG_VMM_PAGE_SIZE);
    } else {
       pEnet->pTxRing[iHead].iTxBaddr =(UINT32)pEnet->NET_pTxInfo[iHead].TXI_pvDmaAddr;
        pbuf_copy_partial(pstPbuf,(PVOID)(pEnet->pTxRing[iHead].iTxBaddr), usLen, 0);
    }
Copy after login

In the above code, the bCopy variable indicates whether zero-copy operation is required.

When using zero-copy optimization, you need to pay attention to the following aspects:

1. When the pbuf type is REF or ROM type, zero copy cannot be performed.

2. When performing zero copy, you need to call the API_CacheFlushPage function to clear the cache. At the same time, you also need to call the pbuf_ref function to increase the member ref value of pbuf by 1.

3. After calling the pbuf_ref function, you need to manually free the zero-copy pbuf in the interrupt. Call function pbuf_free when free. But because this operation is performed in an interrupt, if this function is called directly in the interrupt service function, an error will be reported. In specific implementation, the work queue can be used to add operations that need to release pbuf to the work queue.

2.2 The network card driver sends in real time

When the network card driver sends, it needs to determine whether the current descriptor can be used to send the message. The general operation is to wait through a while loop. When a descriptor is available, the sending operation is performed. This will have a certain impact on real-time performance.

Here you can use semaphores to optimize the sending process, thereby optimizing the real-time nature of network sending.

First, create a counting semaphore during network initialization. The value is the number of currently set send descriptors.

When you need to send, you need to call the API_SemaphoreCPend function to obtain the semaphore. After successfully obtaining it, you can perform the following sending operation.

Similarly, in the interrupt service function, if the successful interrupt is detected, the API_SemaphoreCPost function needs to be called to release the semaphore.

The specific implementation is shown in Program Listing 22 and Program Listing 23.

Program List 22 Get the semaphore

#ifAT_TX_REALTIME > 0
    API_SemaphoreCPend(pEnet->NET_hTxRdyCnt,LW_OPTION_WAIT_INFINITE);
#else
Copy after login

Program List 23 Release the semaphore

#ifAT_TX_REALTIME > 0
     API_SemaphoreCPost(pEnet->NET_hTxRdyCnt);
#endif
Copy after login

The above is the detailed content of How to optimize SylixOS network card driver. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template