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);
}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);
#elseProgram List 23 Release the semaphore
#ifAT_TX_REALTIME > 0
API_SemaphoreCPost(pEnet->NET_hTxRdyCnt);
#endifThe 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft






