Terminal device and data transmission method
By configuring physical memory page pools and direct memory access address mappings in terminal devices, zero-copy transmission is achieved, solving the problem of low data transmission efficiency in USB networks and improving system resource utilization and data processing speed.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HISENSE VISUAL TECH CO LTD
- Filing Date
- 2026-03-12
- Publication Date
- 2026-07-21
Smart Images

Figure CN122432080A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal equipment technology, and in particular to a terminal equipment and a data transmission method. Background Technology
[0002] Terminal devices refer to Linux system devices equipped with Universal Serial Bus (USB) network modules, including embedded terminals, industrial control terminals, and smart hardware terminals. The efficiency of USB network data transmission directly determines the device's communication throughput, processing latency, and system resource usage.
[0003] In related technologies, the USB network driver of the terminal device adopts a layered processing model of pre-allocated fixed memory pool and multi-stage data copying. The core execution process is as follows: a fixed-size memory buffer pool is pre-allocated, then the USB device writes network data into the pre-allocated buffer in the memory buffer pool through direct memory access, then the driver copies the valid data from the buffer to the network data packet, and finally reports the constructed network data packet to the kernel network protocol stack for processing.
[0004] However, the USB network driver of the aforementioned terminal devices needs to copy the network data twice to the network data packet before the kernel network protocol stack can report the data. This secondary copying of data in high-throughput or high-concurrency scenarios leads to significant CPU resource consumption, resulting in low memory utilization and persistently high transmission latency, thus impacting the efficiency of USB network data transmission. Summary of the Invention
[0005] This application provides a terminal device and a data transmission method to solve the problem of low data transmission efficiency in USB networks.
[0006] In a first aspect, this application provides a terminal device, including: The memory is configured to store a pool of physical memory pages, the pool of physical memory pages comprising physical page frames that have direct memory access address mappings; The controller, running a kernel network protocol stack, is configured as follows: In response to a USB network data reception interruption signal, a physical page frame in an idle state is obtained from the physical memory page pool to obtain the target page frame; The USB network data is written into the target page frame according to the direct memory access address of the target page frame; Construct a packet structure shell containing metadata corresponding to the USB network data, and the data pointer of the packet structure shell points to the storage address of the target page frame; The packet structure shell is reported to the kernel network protocol stack.
[0007] The above technical solution has the following beneficial effects or advantages: Terminal devices can achieve zero-copy transmission of USB network data from hardware to kernel protocol stack, eliminating the large amount of system resource consumption caused by copying operations, while shortening the data transmission path, reducing processing latency, and reducing memory usage through a lightweight data packet structure shell, thereby improving overall data transmission efficiency.
[0008] In some embodiments of this application, the controller is further configured to: In response to a kernel USB driver load event, the physical memory page pool is created in the memory; The physical page frames of the physical memory page pool are pre-allocated according to the configuration parameters, which include the number of physical page frames, the size of a single page frame, and the direct memory access address mapping attribute. Establish the mapping relationship between the physical page frame and the direct memory access address.
[0009] The above technical solution has the following beneficial effects or advantages: Terminal devices can dynamically manage physical memory page pools, pre-allocate and map DMA addresses to enable direct writing of USB network data without temporary address translation, and configure parameters to adapt to different application scenarios, thereby improving the versatility of physical memory page pools and the smoothness of data transmission, while reducing memory fragmentation.
[0010] In some embodiments of this application, the terminal device further includes a USB sub-controller, which executes the writing of the USB network data into the target page frame, specifically configured as follows: The direct memory access address of the target page frame is determined as the transport address; Generate a USB request block based on the transmission address; The USB request block is sent to the USB sub-controller to trigger the USB sub-controller to write the USB network data into the target page frame using direct memory access.
[0011] The above technical solution has the following beneficial effects or advantages: The interaction between the master controller and the USB slave controller is achieved through USB request blocks, ensuring the accurate transmission of DMA transfer addresses. This allows the USB controller to directly write data to physical page frames, skipping the intermediate buffer steps, thereby improving the accuracy and reliability of data writing.
[0012] In some embodiments of this application, the controller is specifically configured to construct the packet structure shell for the USB network data as follows: Call the unbuffered request interface; Based on the application interface, apply for a socket buffer shell containing metadata corresponding to the USB network data; Mark the socket buffer shell as recyclable; The socket buffer shell in the reclaimable state is identified as the packet structure shell.
[0013] The above technical solution has the following beneficial effects or advantages: By using a bufferless socket buffer shell, memory usage and initialization overhead are reduced, and memory waste caused by redundant data storage is avoided. At the same time, the shell is reused cyclically through a recyclable tag, reducing the system overhead of repeatedly allocating and destroying shells, thereby improving memory utilization efficiency and data processing speed.
[0014] In some embodiments of this application, the controller is further configured to: Call the virtual address to physical page frame function to convert the fragment address of the USB network data into a physical page frame address; The page offset of the target page frame is calculated using the physical page frame address; Based on the page offset, the data pointer of the data packet structure shell is set to point to the storage address of the target page frame.
[0015] The above technical solution has the following beneficial effects or advantages: By binding the data packet structure shell to the data in the target page frame, the terminal device allows the shell data pointer to directly locate the valid data position within the physical page frame, avoiding access to invalid blank data. This ensures that the kernel network protocol stack can accurately and directly access the USB network data in the physical page frame, guaranteeing the accuracy and effectiveness of zero-copy transmission.
[0016] In some embodiments of this application, after the controller executes the writing of the USB network data into the target page frame, it is further configured to: Perform a validity check on the USB network data in the target page frame, the validity check including at least one of cyclic redundancy check and length check; If the validity check result indicates that the data is invalid, the target page frame is recycled to the physical memory page pool. In response to the validity check result indicating that the data is valid, the operation of constructing the packet structure shell of the USB network data is performed.
[0017] The above technical solution has the following beneficial effects or advantages: Terminal devices filter out erroneous USB network data through data validity checks to avoid wasting system resources caused by invalid data; the target page frames corresponding to invalid data are promptly reclaimed to ensure the resource reuse efficiency of the physical memory page pool, while improving the integrity and reliability of data transmission.
[0018] In some embodiments of this application, when the controller performs the task of acquiring a physical page frame that is in an idle state from the physical memory page pool, it is further configured to: Detect the working status of the physical page frame in the physical memory page pool, wherein the working status is idle or non-idle. If there are no physical page frames in the idle state in the physical memory page pool, the USB network data is discarded.
[0019] The above technical solution has the following beneficial effects or advantages: When physical memory page pool resources are exhausted, USB network data can be discarded in a timely manner to reduce meaningless resource consumption in the terminal device, prevent system lag, memory overflow and other problems caused by forced processing, and thus ensure the stable operation of the terminal device.
[0020] In some embodiments of this application, the controller is further configured to: Detect the write status of the USB network data being written to the target page frame; In response to the write status indicating a write failure, the target page frame is recycled to the physical memory page pool.
[0021] The above technical solution has the following beneficial effects or advantages: Terminal devices can promptly identify abnormal scenarios where DMA data writes fail. The target page frame after the failure is quickly recycled to the physical memory page pool, preventing the physical page frame from being invalidally occupied due to write anomalies and ensuring the resource recycling efficiency of the physical memory page pool. At the same time, avoiding invalid processing of failed data can further save system resources.
[0022] In some embodiments of this application, after the controller reports the packet structure shell to the kernel network protocol stack, it is further configured to: In response to the kernel network protocol stack completing the processing of the data packet structure shell, the page release callback function is triggered; Based on the page release callback function, the target page frame is recycled to the physical memory page pool.
[0023] The above technical solution has the following beneficial effects or advantages: Terminal devices can accurately reclaim target page frames, immediately reclaiming them to the physical memory page pool after protocol stack processing, which can improve the reuse efficiency of physical page frames and avoid idle waste of memory resources; automated reclamation through callback functions can also reduce manual intervention and improve the intelligence and efficiency of system processing.
[0024] Secondly, this application also provides a data transmission method applied to a terminal device, wherein the terminal device stores a physical memory page pool, the physical memory page pool includes physical page frames with direct memory access address mapping relationships, and the terminal device also runs a kernel network protocol stack; the method includes: In response to a USB network data reception interruption signal, a physical page frame in an idle state is obtained from the physical memory page pool to obtain the target page frame; The USB network data is written into the target page frame according to the direct memory access address of the target page frame; After the USB network data is written to the target page frame, a data packet structure shell containing the metadata corresponding to the USB network data is constructed, and the data pointer of the data packet structure shell points to the storage address of the target page frame; The packet structure shell is reported to the kernel network protocol stack.
[0025] The above technical solution has the following beneficial effects or advantages: The data transmission method can be adapted to terminal devices equipped with physical memory page pools to achieve zero-copy USB network data transmission, thereby reducing system resource overhead, improving memory utilization and shortening processing latency; the data transmission method also reduces memory usage by using a lightweight data packet structure shell, which can improve overall data transmission efficiency. Attached Figure Description
[0026] To more clearly illustrate the technical solution of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0027] Figure 1 A schematic diagram illustrating terminal device operation scenarios provided in some embodiments of this application; Figure 2 This is a schematic diagram of the hardware configuration of a terminal device provided in some embodiments of this application; Figure 3 This is a schematic diagram of the software configuration of a terminal device provided in some embodiments of this application; Figure 4 This application provides schematic diagrams illustrating the transmission process of USB network data in some embodiments of the related technologies. Figure 5 A schematic diagram illustrating the creation process of a dynamically managed physical memory page pool provided for some embodiments of this application; Figure 6 A flowchart illustrating a data transmission method provided in some embodiments of this application; Figure 7 A flowchart illustrating the process of verifying the validity of written data provided in some embodiments of this application; Figure 8 A flowchart illustrating the process of setting a data pointer in a data packet structure shell, provided for some embodiments of this application; Figure 9 A schematic diagram illustrating the data transmission process provided in some embodiments of this application; Figure 10 Timing diagrams for terminal devices performing USB network data transmission provided in some embodiments of this application; Figure 11 This is a schematic diagram illustrating the USB network data transmission process provided in some embodiments of this application. Detailed Implementation
[0028] The embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described below do not represent all embodiments consistent with this application. They are merely examples of systems and methods consistent with some aspects of this application as detailed in the claims.
[0029] In this application embodiment, terminal device 200 generally refers to a device with data processing capabilities. For example, terminal device 200 includes, but is not limited to, smart TVs, mobile terminals, computers, monitors, advertising screens, wearable devices, virtual reality devices, augmented reality devices, etc.
[0030] Figure 1 These are schematic diagrams illustrating terminal device usage scenarios provided in some embodiments of this application. For example... Figure 1 As shown, terminal device 200 also communicates with server 400 via various communication methods. Terminal device 200 can communicate via local area network (LAN), wireless local area network (WLAN), and other networks.
[0031] Figure 2 Provided for some embodiments of this application Figure 1 Hardware configuration block diagram of terminal device 200.
[0032] In some embodiments, the terminal device 200 may include at least one of a tuner 210, a communication device 220, a detector 230, a device interface 240, a controller 250, a display 260, an audio output device 270, a memory 290, a power supply, and a user input interface 280.
[0033] In some embodiments, the communication device 220 is a component used to communicate with external devices or the server 400 according to various communication protocol types. The terminal device 200 may be equipped with multiple communication devices 220 depending on the supported communication methods. The communication devices 220 can enable the terminal device 200 to communicate with the external devices or the server 400 via wireless or wired connections.
[0034] Wired connections allow the terminal device 200 to connect to external devices via data cables, interfaces, or other components. Wireless connections allow the terminal device 200 to connect to external devices via wireless signals or wireless networks. The terminal device 200 can establish a direct connection with external devices or indirectly through gateways, routers, or other connection devices.
[0035] In some embodiments, the controller 250 may include at least one of a central processing unit, a video processor, an audio processor, a graphics processor, and a power processor, and a first to an nth interface for input / output. The controller 250 controls the operation of the terminal device and responds to user operations through various software control programs stored in memory. The controller 250 controls the overall operation of the terminal device 200.
[0036] In some embodiments, the controller 250 and the tuner 210 may be located in different separate devices, that is, the tuner 210 may also be located in an external device of the main device where the controller 250 is located, such as an external set-top box.
[0037] In some embodiments, a user can input user commands through a graphical user interface (GUI) displayed on a display 260, and the user input interface receives user input commands through the graphical user interface (GUI).
[0038] In some embodiments, the user input interface 280 can be used to receive instructions input by a user. The user input interface 280 may include at least one of a microphone, touchpad, sensor, remote control, etc. Then, the terminal device 200 can receive user-input instructions based on the user input interface 280 to perform interactive functions with the user.
[0039] In some embodiments, to enable user interaction, the terminal device 200 may run an operating system. An operating system is a computer program that manages and controls the hardware and software resources of the terminal device 200. The operating system can control the terminal device to provide a user interface; for example, the operating system can directly control the terminal device to provide a user interface, or it can provide a user interface by running applications. The operating system also allows users to interact with the terminal device 200.
[0040] It should be noted that the operating system can be a native operating system based on a specific operating platform, a third-party operating system that is deeply customized based on a specific operating platform, or an independent operating system specifically developed for terminal devices.
[0041] An operating system can be divided into different modules or levels based on the functions it implements, for example... Figure 3 As shown, in some embodiments, the system is divided into four layers, from top to bottom: the Applications layer (referred to as the "Application Layer"), the Application Framework layer (referred to as the "Framework Layer"), the System Library layer, and the Kernel layer.
[0042] In some embodiments, the application layer provides services and interfaces for applications, enabling the terminal device 200 to run applications and interact with the user based on the applications. The application layer may contain at least one application, which may be a built-in Windows program, system settings program, or clock program of the operating system; or it may be an application developed by a third-party developer. In specific implementations, the application packages in the application layer are not limited to the examples above.
[0043] The framework layer provides application programming interfaces (APIs) and a programming framework for applications. The application framework layer includes predefined functions. It acts as a central processing unit, determining the actions taken by applications within the application layer. Through the API, applications can access system resources and obtain system services during execution.
[0044] like Figure 3As shown, the application framework layer in this embodiment includes a view system, managers, and content providers. The view system designs and implements the application's interface and interactions, and includes lists, grids, text boxes, and buttons. The managers include at least one of the following modules: an activity manager for interacting with all running activities in the system; a location manager for providing system services or applications with access to system location services; a package manager for retrieving various information related to application packages currently installed on the device; a notification manager for controlling the display and clearing of notification messages; and a window manager for managing icons, windows, toolbars, wallpapers, and desktop widgets on the user interface.
[0045] In some embodiments, the Activity Manager manages the lifecycle of individual applications and common navigation and back functions, such as controlling application exit, opening, and back actions. The Window Manager manages all window programs, such as obtaining the screen size, determining if a status bar is present, locking the screen, capturing the screen, and controlling changes to the display window, such as shrinking the display window, shaking the display, or distorting the display.
[0046] In some embodiments, the system runtime library layer can provide support for the framework layer. When the framework layer is used, the operating system runs the instruction library contained in the system runtime library layer, such as the C / C++ instruction library, to implement the functions to be performed by the framework layer.
[0047] In some embodiments, the kernel layer is a functional layer situated between the hardware and software of the terminal device 200. The kernel layer can implement functions such as hardware abstraction, multitasking, and memory management. For example, ... Figure 3 As shown, hardware drivers can be configured in the kernel layer. The kernel layer can contain at least one of the following drivers: audio driver, display driver, Bluetooth driver, camera driver, WIFI driver, USB driver, HDMI driver, sensor driver (such as fingerprint sensor, temperature sensor, pressure sensor, etc.), and power driver, etc.
[0048] In some embodiments, the kernel layer is the Linux operating system kernel, which runs a corresponding kernel network protocol stack, namely the Linux protocol stack.
[0049] Based on the aforementioned terminal device 200, the terminal device 200 can connect to a USB network peripheral (such as a USB network card, USB to Ethernet module, etc.) via a USB interface. The USB network peripheral sends USB network data (or simply USB data) to the terminal device 200. The USB network data is transmitted to the terminal device 200 via the USB bus. The terminal device 200 needs to process the USB network data to ensure that it can be transmitted to the kernel network protocol stack at the kernel layer. The kernel network protocol stack then distributes the USB network data to the corresponding upper-layer application for parsing and processing.
[0050] In related technologies, the process of transmitting USB network data from the USB bus to the kernel network protocol stack, such as... Figure 4 As shown, terminal device 200 is configured to perform the following steps: S41, Pre-allocated fixed memory pool.
[0051] Terminal device 200 first pre-allocates a fixed-size memory buffer to form a static fixed memory pool.
[0052] S42 and USB write data via DMA.
[0053] After the allocation of the fixed memory pool is completed, the USB network data in the USB bus is written to the memory buffer of the fixed memory pool via DMA.
[0054] S43. Copy valid data.
[0055] After writing the USB network data is complete, the valid data of the USB network data is copied a second time from the memory buffer to the network data packet through the USB driver. The network data packet is SKB (Socket Buffer).
[0056] S44, Submit to the kernel network protocol stack.
[0057] The network data packets constructed as described above are reported to the kernel network protocol stack for processing.
[0058] Clearly, the aforementioned USB network data transmission method requires copying the USB network data twice to the network data packet before it can be reported by the kernel network protocol stack. This copying operation consumes a significant amount of CPU resources from the terminal device, especially in high-throughput network scenarios, which can have a substantial impact on system performance. Furthermore, Figure 4The multi-layered processing architecture shown also increases the length of the USB network data transmission path and processing latency, affecting network response speed and thus reducing the efficiency of USB network data transmission. Furthermore, the pre-allocated memory buffer needs to be reserved according to the maximum packet size, resulting in low utilization of the memory buffer.
[0059] To address the aforementioned issues, some embodiments of this application provide a terminal device 200 that reconstructs the USB network data reception path by directly associating a physical memory page pool with a packet structure shell. Physical page frames are pre-allocated in the physical memory page pool, and a Direct Memory Access (DMA) mapping is established. When USB network data arrives, the data is directly written to the target page frame in the physical memory page pool via DMA. Subsequently, a packet structure shell containing only metadata is requested, allowing the data pointer of the packet structure shell to directly point to the storage address of the target page frame containing the valid data. This eliminates the large data overhead caused by secondary CPU copying, achieving zero-copy transmission of USB network data and thus improving the transmission efficiency of USB network data.
[0060] In some embodiments, the memory 290 of the terminal device 200 is configured to store a physical memory page pool, which includes physical page frames that have direct memory access address mapping relationships. The physical memory page pool can dynamically manage each physical page frame to improve the utilization rate of the physical memory page pool.
[0061] like Figure 5 As shown, in some embodiments, terminal device 200 is configured to perform the following steps: S501, in response to the kernel USB driver loading event, creates a physical memory page pool.
[0062] When terminal device 200 detects a kernel USB driver load event, it creates a physical memory page pool in memory 290 in response to this event. The physical memory page pool is used to dynamically manage physical memory page frames. For example, the physical memory page pool is created by calling the page_pool_create() function.
[0063] S502. Pre-allocate physical page frames for the physical memory page pool according to the configuration parameters.
[0064] After the terminal device 200 completes the creation of the physical memory page pool, it allocates physical page frames according to the configuration parameters. The configuration parameters include the number of physical page frames, the size of a single page frame, and direct memory access address mapping attributes (such as direct memory access alignment requirements and memory allocation strategies).
[0065] In some implementations, the single-page frame size is configured according to application requirements; for example, a smaller page frame size is configured for small data packet transmission scenarios, and a larger page frame size is configured for large data packet transmission scenarios.
[0066] In some implementations, the number of physical page frames is configured based on the system memory capacity and the number of concurrent connections. For example, when memory resources are sufficient, a larger number of pages is configured to improve concurrent processing capabilities; when memory resources are limited, a smaller number of pages is configured to ensure stable system operation.
[0067] In some implementations, direct memory access alignment requirements are used to ensure that the start address of a physical page frame meets the alignment requirements of direct memory access, thereby improving data transfer efficiency.
[0068] S503. Based on the pre-allocated physical page frames, establish the mapping relationship between physical page frames and direct memory access addresses.
[0069] After pre-allocating physical page frames through configuration parameters, the terminal device 200 establishes a mapping relationship between physical page frames and DMA addresses, forming a DMA address list (dma_addr_list) for subsequent calling and judgment logic by the terminal device 200.
[0070] In this embodiment of the disclosure, the terminal device 200 can realize dynamic management of the physical memory page pool, pre-allocate and map DMA addresses to enable direct writing of USB network data without the need for temporary address translation; and the configuration parameters can be adapted to different application scenarios, thereby improving the versatility of the physical memory page pool and the smoothness of data transmission, while reducing memory fragmentation accumulation.
[0071] It should be noted that the direct memory access address mentioned in the embodiments of this application refers to the mapping address of the physical page frame in the direct memory access address space.
[0072] In some embodiments, direct memory access addresses are generated through mapping using the dma_map_page() function and used to perform data transfer operations. There is a one-to-one correspondence between direct memory access addresses and physical addresses, ensuring that the direct memory access controller can correctly access physical memory.
[0073] For example, during the USB driver loading phase (initialization phase), in response to the kernel USB driver loading event, terminal device 200 calls `page_pool_create()` to create a page pool and configures the number of physical page frames, the size of a single page frame, and the DMA address mapping attributes. It then pre-allocates physical page frames and maps them to DMA addresses, forming `dma_addr_list`. This completes the creation and configuration of the physical memory page pool.
[0074] It should be noted that the physical memory page pool described in this application embodiment refers to a dynamically managed memory region composed of multiple physical page frames. Each physical page frame is pre-allocated and mapped to a direct memory access address for storing data written via direct memory access.
[0075] In some embodiments, the physical memory page pool supports dynamic allocation and reclamation of page frames, providing the memory management functionality required for zero-copy data transfer. For example, the management of the physical memory page pool can be implemented based on the Linux kernel's page_pool.
[0076] Based on the aforementioned physical memory page pool, such as Figure 6 As shown, in some embodiments, the controller 250 of the terminal device 200 is configured to perform the following procedure steps: S601, in response to the USB network data reception interrupt signal, obtains an idle physical page frame from the physical memory page pool to obtain the target page frame.
[0077] When USB network data arrives at the USB bus, the terminal device 200 triggers a USB network data reception interrupt signal and, in response to the reception interrupt signal, retrieves an idle physical page frame from the physical memory page pool stored in the memory 290 as the target page frame.
[0078] In some embodiments, the terminal device 200 includes a USB sub-controller, which is responsible for USB-related processing. For example, when the USB sub-controller receives USB network data provided by a USB network peripheral, it generates a receive interrupt signal.
[0079] In some embodiments, the controller 250 of the terminal device 200 captures an interrupt signal, identifies the interrupt source as a USB receive interrupt, and calls the corresponding interrupt handler function. The interrupt handler function performs a security check of the interrupt context, including an interrupt nesting depth check, a kernel lock state check, and a memory allocation flag check, to ensure the security and reliability of the interrupt handling process.
[0080] In some embodiments, the terminal device 200 obtains physical page frames (free pages) that are in an idle state through page_pool_get_page().
[0081] In some embodiments, the terminal device 200 detects the working status of physical page frames in the physical memory page pool, wherein the working status is idle or non-idle. It then acquires an idle physical page frame to obtain the target page frame. If there are no idle physical page frames in the physical memory page pool, meaning all physical page frames in the physical memory page pool are in a non-idle state, the terminal device 200 discards the USB network data and does not perform subsequent transmission.
[0082] In this embodiment of the disclosure, when the physical memory page pool resources are exhausted, USB network data can be discarded in a timely manner to reduce meaningless resource consumption in the terminal device 200 system, prevent system lag, memory overflow and other problems caused by forced processing, and thus ensure the stable operation of the terminal device 200.
[0083] In some embodiments, when multiple physical page frames are in an idle state, the terminal device 200, based on the last used time information of the physical memory pages, preferentially allocates the physical page frame with the earliest last used time as the target page frame. This improves the cache hit rate and allocation efficiency of physical page frames in the physical memory page pool, avoiding cache pollution and performance fluctuations caused by random allocation.
[0084] S602. Write the USB network data into the target page frame according to the direct memory access address of the target page frame.
[0085] After determining the target page frame (free page) in the physical memory page pool, the terminal device 200 writes the USB network data into the target page frame using its DMA address. In this way, USB network data can be directly written to the specified physical page frame via the DMA address upon arrival, without requiring a copy operation in the intermediate buffer.
[0086] In some embodiments, the terminal device 200 determines the direct memory access address of the target page frame as the transport address. Then, it generates a USB Request Block (URB) based on the transport address. The USB Request Block is sent to the USB sub-controller to trigger the USB sub-controller to write USB network data into the target page frame using direct memory access.
[0087] For example, terminal device 200 identifies a free page in the physical memory page pool as the target page frame and extracts the DMA address dma_addr_x of the target page frame. Then, it calls usb_submit_urb() to submit the URB, using dma_addr_x as the transfer address, enabling the USB sub-controller to directly write USB network data to the target page frame via DMA, reducing the copy operations in the intermediate buffer.
[0088] In this embodiment of the disclosure, the interaction between the controller 250 and the USB sub-controller is realized through the USB request block, which ensures the accurate transmission of the DMA transfer address, so that the USB controller can directly write data into the physical page frame, skipping the intermediate buffer step, thereby improving the accuracy and reliability of data writing.
[0089] In some embodiments, the terminal device 200 also supports a bulk direct memory access operation mode, which is configured to process direct memory access transfers of multiple physical memory pages simultaneously. Upon receiving a bulk transfer request for USB network data, the terminal device 200 obtains the direct memory access addresses of multiple contiguous or non-contiguous physical memory pages from the physical memory page pool as target page frames and initiates multiple parallel direct memory access transfer operations.
[0090] In some embodiments, the terminal device 200 also detects the write status of USB network data being written to the target page frame. In response to a write status indicating a write failure, meaning the terminal device 200 has failed to successfully write the USB network data to the target page frame, the target page frame is recycled to the physical memory page pool for subsequent use.
[0091] In some embodiments, the write status is characterized as a write failure, including but not limited to DMA transfer timeout error, address alignment error, and length overflow error.
[0092] S603. After the USB network data is written to the target page frame, construct a data packet structure shell containing the metadata corresponding to the USB network data.
[0093] The packet structure shell contains metadata (metadata only) of the USB network data, and its data pointer points to the storage address of the target page frame to associate the packet structure shell with the target page frame. This minimally structured network packet structure shell eliminates redundant data storage fields, minimizing memory usage and initialization overhead. It also mitigates memory waste and processing latency caused by unnecessary fields in the SKB structure, thereby improving memory efficiency and reducing the processing overhead of the terminal device 200.
[0094] like Figure 7 As shown, in some embodiments, after the terminal device 200 writes USB network data to the target page frame, it is further configured to perform the following steps: S701. Perform a validity check on the USB network data in the target page frame.
[0095] USB network data is written to the target page frame via DMA, and the written USB network data is validated. The validation includes at least one of Cyclic Redundancy Check (CRC) and Length Check.
[0096] S702. In response to the validity check result indicating that the data is invalid, the target page frame is recycled to the physical memory page pool.
[0097] If the validity check indicates that the written USB network data is invalid (i.e., the cyclic redundancy check or length check fails), the terminal device 200 will reclaim the target page frame into the physical memory page pool for later use. In other words, the USB network data and the target page frame will be released.
[0098] S703. In response to the validity check result indicating that the data is valid, perform the operation of constructing the data packet structure shell of the USB network data.
[0099] If the validity check result indicates that the written USB network data is valid, i.e., the cyclic redundancy check or length check passes, the terminal device 200 continues to execute the operation of requesting the data packet structure shell, i.e., step S603, and performs subsequent data transmission processing.
[0100] In this embodiment of the disclosure, the terminal device 200 filters out USB network data with transmission errors through data validity verification to avoid wasting system resources caused by invalid data; at the same time, the target page frame corresponding to invalid data is recycled in a timely manner, which can ensure the resource reuse efficiency of the physical memory page pool and improve the integrity and reliability of data transmission.
[0101] In some embodiments, when the terminal device 200 constructs the packet structure shell for USB network data, it calls a bufferless request interface, such as dev_alloc_skb(0, GFP_ATOMIC|__GFP_NOWARN). Then, based on the request interface, it requests a socket buffer shell (bufferless) containing the metadata corresponding to the USB network data. This socket buffer shell only contains the metadata of the USB network data and does not contain other unnecessary fields.
[0102] The terminal device 200 also marks the socket buffer shell as recyclable and identifies the recyclable socket buffer shell as the packet structure shell. In this way, by marking it as recyclable, the terminal device 200 can put the SKB shell into the recycling pool after the kernel network protocol stack has finished processing the data, instead of destroying it directly, thereby realizing the circular reuse of the SKB shell and reducing the memory overhead caused by repeatedly allocating and destroying SKB structures.
[0103] In some embodiments, the metadata contained in the socket buffer shell includes, but is not limited to, protocol type, data length, and checksum. For example, for Ethernet packets, the protocol type identifier field is set to 0x0800 to indicate the IP protocol, the data length identifier field is set to the actual received data length, and the receive timestamp identifier field is set to the timestamp of the packet arrival.
[0104] like Figure 8 As shown, in some embodiments, the terminal device 200 is also configured to perform the following steps: S801: Call the virtual address to physical page frame function to convert the fragment address of the USB network data into a physical page frame address.
[0105] After the terminal device 200 completes the DMA direct write and validity verification of the USB network data, it first calls the virtual address to physical page frame function to convert the virtual segment address of the USB network data in memory into the corresponding physical page frame address, thereby locking the target page frame for storing the data.
[0106] S802. Calculate the page offset of the target page frame using the physical page frame address.
[0107] After locking the target page frame, the terminal device 200 calculates the page offset of the current USB network data segment within the target page frame by using the difference between the base address (physical page frame address) of the target page frame and the address of the current USB network data segment, so as to determine the specific storage location of the current USB network data segment in the physical page.
[0108] S803. Based on the page offset, set the data pointer of the data packet structure shell to point to the storage address of the target page frame.
[0109] After calculating the page offset, the terminal device 200 can precisely set the data pointer of the packet structure shell according to the page offset, so that the pointer directly points to the actual storage address of the USB network data in the target page frame, realizing the copy-free association between the packet structure shell and the physical page data, and ensuring that the subsequent kernel network protocol stack can directly access the USB network data in the physical page frame through this pointer.
[0110] For example, the virtual fragment address `frag_addr` of the USB network data is converted to the descriptor of the corresponding physical page frame using `virt_to_page`. Then, the main descriptor of the physical page frame is obtained through `compound_head` and assigned to `Page`, locking the target page frame storing the USB network data and avoiding address corruption in compound big pages. Next, the virtual base address of the target page frame is obtained through `page_address`, cast to a byte pointer, and subtracted from the data virtual fragment address `frag_addr` to calculate the byte offset `Frag_offset` of the USB network data within the target physical page frame, thus determining the precise storage location of the data within the page.
[0111] Then, the kernel fragment mounting interface is called to mount the target physical page frame onto the lightweight SKB shell (data packet structure shell). The input parameters are, in order, the SKB shell to be bound, the current number of SKB fragments mounted, the target physical page descriptor, the page offset, and the valid length of the USB network data. This achieves copy-free binding between the SKB and the USB network data within the physical page, allowing the SKB to directly access the USB network data in the physical page. Next, the kernel SKB reclamation marking interface is called to mark the SKB shell with mounted physical page data as reclaimable. This allows the kernel to place the SKB in the reclamation pool after processing it in the protocol stack, rather than destroying it directly. This enables the cyclic reuse of the SKB shell, reducing the overhead of memory allocation and destruction.
[0112] In this embodiment of the disclosure, the terminal device 200 binds the data packet structure shell to the data in the target page frame, so that the shell data pointer can directly locate the valid data position in the physical page frame, avoiding access to invalid blank data, ensuring that the kernel network protocol stack can accurately and directly access the USB network data in the physical page frame, and guaranteeing the accuracy and effectiveness of zero-copy transmission.
[0113] S604. Report the packet structure shell to the kernel network protocol stack.
[0114] After the terminal device 200 completes the application for the aforementioned data packet structure shell, it reports the data packet structure shell to the kernel network protocol stack, enabling the kernel network protocol stack to directly access and process the USB network data through the data pointer of the data packet structure shell. In this way, zero-copy processing can be achieved during USB network data transmission, reducing CPU resource consumption and improving data transmission efficiency.
[0115] In some implementations, terminal device 200 calls netif_receive_skb(skb) to submit the packet structure shell to the kernel network protocol stack.
[0116] In some embodiments, after the terminal device 200 reports the packet structure shell to the kernel network protocol stack, it also triggers a page release callback function, such as page_pool_release_page(), in response to the kernel network protocol stack completing the processing of the packet structure shell. Based on the page release callback function, the target page frame is then recycled to the physical memory page pool for subsequent use (awaiting reuse).
[0117] In this embodiment of the disclosure, the terminal device 200 can accurately reclaim the target page frame and immediately reclaim the page frame to the physical memory page pool after the protocol stack processing is completed, thereby improving the reuse efficiency of physical page frames and avoiding the idle waste of memory resources; at the same time, the automatic reclamation achieved through the page release callback function can also reduce manual intervention and improve the intelligence and efficiency of system processing.
[0118] In some embodiments, direct memory access address mapping is implemented using the `dma_map_page()` function. This function maps physical page frames to direct memory access addresses and returns the mapped direct memory access addresses. Direct memory access address unmapping is implemented using the `dma_unmap_page()` function, which is called during page frame reclamation to release the mapping between direct memory access addresses and physical page frames. Direct memory access address mapping ensures that the direct memory access controller 250 can correctly access physical page frames while maintaining cache consistency.
[0119] In some embodiments, when the terminal device 200 constructs the packet structure shell for USB network data, it also performs a reference count increment operation on the target page frame; after the kernel network protocol stack completes the processing of the network packet structure shell, it performs a reference count decrement operation on the target page frame. When the reference count decreases to zero, the terminal device 200 returns the target page frame to the physical memory page pool. In this way, by controlling the lifecycle of physical page frames through the above-mentioned reference counting management mechanism, precise reclamation and reuse management of memory resources can be achieved, avoiding memory page access conflicts and resource leaks in a multi-threaded environment.
[0120] In some embodiments, a reference count is a counter that represents the number of times a physical memory page is referenced and is used to manage the lifecycle of a physical page frame.
[0121] In some embodiments, the terminal device 200 employs atomic operations to perform the reference count increment and decrement operations. In this way, the terminal device 200 can guarantee the atomicity and consistency of reference counting operations in a multi-threaded environment through atomic operation configuration.
[0122] According to the above technical solution, for example, such as Figure 9 As shown, after detecting a USB network data reception interrupt signal, the terminal device 200 responds to the interrupt signal by determining whether the physical page frames in the physical memory page pool are in an idle or non-idle state. If the physical memory page pool does not contain any physical page frames in an idle state, the terminal device 200 discards the USB network data packets.
[0123] If the physical memory page pool contains a physical page frame that is in an idle state, the terminal device 200 will use the idle physical page frame as the target page frame and obtain the DMA address of the target page frame. Then, based on the DMA address, it will submit the URB and initiate the DMA data write, writing the USB network data into the target page frame.
[0124] If writing USB network data to the target page frame fails, the target page frame is recycled to the physical memory page pool, awaiting reuse. If writing USB network data to the target page frame succeeds, an SKB shell is constructed, and the target page frame (the target page frame with data already written) is associated with the SKB shell (the data pointer points to the memory address of the target page frame). The SKB shell is then reported to the kernel network protocol stack. After the kernel network protocol stack processes the data, the target page frame is released (i.e., the reference to the target page frame is released), and the target page frame is recycled to the physical memory page pool, awaiting subsequent reuse.
[0125] In this way, by reconstructing the data transmission path of the USB network device, the terminal device 200 establishes a chain directly associated with the USB DMA direct writing to physical memory pages and the lightweight network data packet structure, enabling zero-copy data transmission and efficient memory management.
[0126] Figure 10 This is a timing diagram showing the execution of USB network data transmission by a terminal device provided in an embodiment of this application. Figure 10 As shown, the controller 250 of the terminal device 200 can create a physical memory page pool in the memory 290 to dynamically manage physical page frames in response to a kernel USB driver loading event. The physical page frame contains a direct memory access address mapping. When the controller 250 detects a USB network data reception interrupt signal, it retrieves an idle physical page frame (free page) from the physical memory page pool as the target page frame. Then, based on the direct memory access address of the target page frame, it writes USB network data into the target page frame and constructs a packet structure shell containing only metadata. This packet structure shell is then reported to the kernel network protocol stack, allowing the kernel network protocol stack to directly access the USB network data in the target page frame based on the packet structure shell.
[0127] Based on the aforementioned terminal device 200, this application embodiment also provides a data transmission method, which can be applied to the terminal device 200 described in the above embodiment. The terminal device 200 stores a physical memory page pool, the physical memory page pool including physical page frames with direct memory access address mapping relationships, and the terminal device also runs a kernel network protocol stack; as... Figure 6 As shown, the method includes the following steps: S601, in response to the USB network data reception interrupt signal, obtains an idle physical page frame from the physical memory page pool to obtain the target page frame.
[0128] S602. Write the USB network data into the target page frame according to the direct memory access address of the target page frame.
[0129] S603. After the USB network data is written to the target page frame, construct a data packet structure shell containing the metadata corresponding to the USB network data.
[0130] The packet structure shell contains metadata of the USB network data, and the data pointer of the packet structure shell points to the storage address of the target page frame; S604. Report the packet structure shell to the kernel network protocol stack.
[0131] For example, such as Figure 11 As shown, the data transfer method can write USB network data received from the USB bus into a target page frame in the physical memory page pool via DMA. The target page frame is then mounted to the SKB shell via address mapping, allowing the kernel network protocol stack to directly access the USB network data in the target page frame through the SKB shell. Clearly, compared to... Figure 4 The data transmission process shown includes a secondary copy operation. The data transmission method provided in this application can shorten the transmission path and reduce the secondary copy operation, thereby reducing the overhead of system resources and improving data transmission efficiency.
[0132] It should be noted that the data transmission method described in the embodiments of this application can refer to the embodiments described in the above-mentioned terminal device, and the two can adopt the same principles and logic. Here, this application will not elaborate further.
[0133] Based on the above data transmission method, the data transmission method can realize zero-copy transmission of USB network data from hardware to kernel protocol stack, eliminate the large amount of system resource consumption caused by copy operation, shorten the data transmission path, reduce processing latency, and reduce memory occupation by using a lightweight data packet structure shell, thereby improving the overall data transmission efficiency.
[0134] Similar parts between the embodiments provided in this application can be referred to mutually. The specific implementation methods provided above are only a few examples under the overall concept of this application and do not constitute a limitation on the scope of protection of this application. For those skilled in the art, any other implementation methods extended from the solution of this application without creative effort shall fall within the scope of protection of this application.
Claims
1. A terminal device, characterized in that, include: The memory is configured to store a pool of physical memory pages, the pool of physical memory pages comprising physical page frames that have direct memory access address mappings; The controller, running a kernel network protocol stack, is configured as follows: In response to a USB network data reception interruption signal, a physical page frame in an idle state is obtained from the physical memory page pool to obtain the target page frame; The USB network data is written into the target page frame according to the direct memory access address of the target page frame; Construct a packet structure shell containing metadata corresponding to the USB network data, and the data pointer of the packet structure shell points to the storage address of the target page frame; The packet structure shell is reported to the kernel network protocol stack.
2. The terminal device according to claim 1, characterized in that, The controller is also configured to: In response to a kernel USB driver load event, the physical memory page pool is created in the memory; The physical page frames of the physical memory page pool are pre-allocated according to the configuration parameters, which include the number of physical page frames, the size of a single page frame, and the direct memory access address mapping attribute. Establish the mapping relationship between the physical page frame and the direct memory access address.
3. The terminal device according to claim 1, characterized in that, It also includes a USB sub-controller, which executes the writing of the USB network data into the target page frame, specifically configured as follows: The direct memory access address of the target page frame is determined as the transport address; Generate a USB request block based on the transmission address; The USB request block is sent to the USB sub-controller to trigger the USB sub-controller to write the USB network data into the target page frame using direct memory access.
4. The terminal device according to claim 1, characterized in that, The controller is configured to construct the data packet structure shell for the USB network data, specifically as follows: Call the unbuffered request interface; Based on the application interface, apply for a socket buffer shell containing metadata corresponding to the USB network data; Mark the socket buffer shell as recyclable; The socket buffer shell in the reclaimable state is identified as the packet structure shell.
5. The terminal device according to claim 4, characterized in that, The controller is also configured to: Call the virtual address to physical page frame function to convert the fragment address of the USB network data into a physical page frame address; The page offset of the target page frame is calculated using the physical page frame address; Based on the page offset, the data pointer of the data packet structure shell is set to point to the storage address of the target page frame.
6. The terminal device according to claim 1, characterized in that, After the controller executes the writing of the USB network data into the target page frame, it is further configured to: Perform a validity check on the USB network data in the target page frame, the validity check including at least one of cyclic redundancy check and length check; If the validity check result indicates that the data is invalid, the target page frame is recycled to the physical memory page pool. In response to the validity check result indicating that the data is valid, the operation of constructing the packet structure shell of the USB network data is performed.
7. The terminal device according to claim 1, characterized in that, When the controller retrieves an idle physical page frame from the physical memory page pool, it is also configured to: Detect the working status of the physical page frame in the physical memory page pool, wherein the working status is idle or non-idle. If there are no physical page frames in the idle state in the physical memory page pool, the USB network data is discarded.
8. The terminal device according to claim 1, characterized in that, The controller is also configured to: Detect the write status of the USB network data being written to the target page frame; In response to the write status indicating a write failure, the target page frame is recycled to the physical memory page pool.
9. The terminal device according to claim 1, characterized in that, After the controller reports the packet structure shell to the kernel network protocol stack, it is further configured to: In response to the kernel network protocol stack completing the processing of the data packet structure shell, the page release callback function is triggered; Based on the page release callback function, the target page frame is recycled to the physical memory page pool.
10. A data transmission method, characterized in that, The method is applied to a terminal device, wherein the terminal device stores a physical memory page pool, the physical memory page pool includes physical page frames with direct memory access address mappings, and the terminal device also runs a kernel network protocol stack; the method includes: In response to a USB network data reception interruption signal, a physical page frame in an idle state is obtained from the physical memory page pool to obtain the target page frame; The USB network data is written into the target page frame according to the direct memory access address of the target page frame; Construct a packet structure shell containing metadata corresponding to the USB network data, and the data pointer of the packet structure shell points to the storage address of the target page frame; The packet structure shell is reported to the kernel network protocol stack.