Home > Article > Operation and Maintenance > How to optimize SylixOS network card driver
Operating system: SylixOS
Programming environment: RealEvo-IDE3.1
Hardware platform: AT9x25 development board
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.
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); }
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.
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
Program List 23 Release the semaphore
#ifAT_TX_REALTIME > 0 API_SemaphoreCPost(pEnet->NET_hTxRdyCnt); #endif
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!