search
HomeOperation and MaintenanceSafetyHow to optimize SylixOS network card driver

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);
#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!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools