Data transmission method, apparatus, device, storage medium, and program product
By utilizing mapping relationships to determine the target data channel in the data communication system, the problems of insufficient isolation and low efficiency of data transmission channels are solved, achieving efficient data transmission and hardware resource management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN CONSYS SCI&TECH CO LTD
- Filing Date
- 2026-01-30
- Publication Date
- 2026-06-16
AI Technical Summary
Existing methods suffer from insufficient data transmission channel isolation and low transmission efficiency in high-concurrency, low-latency, and multi-channel isolated data communication systems.
By obtaining the user-mode data transmission request and the target file descriptor, the target data structure is determined using the first mapping relationship, carrying the minor device number. Based on the minor device number and the second mapping relationship, the target data channel is determined, and data transmission operations are performed. This ensures that each user-mode process's access to the device is accurately mapped to the corresponding channel resource, avoiding interference between devices or processes.
It improves the independence and isolation of data transmission, enhances the management efficiency of multi-channel systems, ensures the effective allocation and utilization of hardware resources, and avoids resource waste and conflicts.
Smart Images

Figure CN122220296A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and in particular to a data transmission method, apparatus, device, storage medium, and program product. Background Technology
[0002] In high-concurrency, low-latency, and multi-channel isolated data communication systems, character devices typically need to process data streams from multiple independent channels simultaneously, and each channel needs to meet independent data buffering, interrupt handling, and user-mode interface access requirements.
[0003] Existing methods mainly employ a combination of a single character device and software identification. This involves registering a character device and passing a channel number parameter in user mode to distinguish data transmission channels, or using a multiple master device number method to assign an independent master device number to each data transmission channel.
[0004] However, existing methods suffer from insufficient isolation of data transmission channels and low data transmission efficiency. Summary of the Invention
[0005] This application provides data transmission methods, apparatus, devices, storage media, and program products to improve resource utilization.
[0006] In a first aspect, embodiments of this application provide a data transmission method, including:
[0007] Obtain a user-mode data transfer request and a target file descriptor used to identify the data transfer request, wherein the data transfer request carries a data transfer type;
[0008] Based on the target file descriptor and the first mapping relationship, a target data structure is determined. The first mapping relationship includes a correspondence between at least one file descriptor and at least one data structure. The target data structure carries a target minor device number.
[0009] The target data channel is determined based on the target secondary device number and the second mapping relationship, wherein the second mapping relationship includes the correspondence between at least one secondary device number and at least one available data channel;
[0010] According to the data transmission type, data transmission operations are performed on the target data channel and the user state.
[0011] In one or more embodiments, before determining the target data channel based on the target secondary device number and the second mapping relationship, the method further includes:
[0012] Obtain at least one available data channel;
[0013] Register the character device with the kernel and determine the major device number and at least one minor device number of the character device;
[0014] The at least one available data channel and the at least one secondary device number are mapped to obtain the second mapping relationship, wherein the at least one available data channel shares the primary device number.
[0015] In one or more embodiments, the data transmission type includes a read transmission type and a write transmission type, and the data transmission operation includes a data read operation and a data write operation;
[0016] Accordingly, the step of performing data transmission operations on the target data channel and the user space according to the data transmission type includes:
[0017] If the data transmission type is a read transmission type, then the user state performs a data read operation on the target data channel;
[0018] If the data transmission type is a write transmission type, then the user state performs a data write operation on the target data channel.
[0019] In one or more embodiments, for each available data channel, the available data channel includes a lock-free buffer, a hardware interrupt vector, and a data processing context;
[0020] In one or more embodiments, the second mapping relationship includes the correspondence between the interrupt identifier corresponding to the hardware interrupt vector carried by at least one data channel, the buffer identifier corresponding to the lockless buffer, and the at least one minor device number;
[0021] Accordingly, the method further includes:
[0022] When the hardware device triggers an interrupt in the data channel to be processed, the hardware interrupt signal is acquired;
[0023] The interrupt signal is parsed and processed to determine the target interrupt identifier;
[0024] Based on the target interrupt identifier and the second mapping relationship, determine the minor device number to be processed;
[0025] Based on the minor device number to be processed and the second mapping relationship, determine the lock-free buffer to be processed;
[0026] Perform data read or data write operations on the lock-free buffer to be processed.
[0027] In one or more embodiments, the target data channel includes a data storage area;
[0028] Accordingly, the method further includes:
[0029] Obtain the data traffic of the target data channel;
[0030] Based on the data flow and preset threshold, the data storage area corresponding to the target data channel is updated.
[0031] Secondly, embodiments of this application provide a data transmission apparatus, including:
[0032] The acquisition module is used to acquire a data transmission request in user space and a target file descriptor used to identify the data transmission request, wherein the data transmission request carries a data transmission type;
[0033] The first determining module is configured to determine a target data structure based on the target file descriptor and the first mapping relationship, wherein the first mapping relationship includes a correspondence between at least one file descriptor and at least one data structure, and the target data structure carries a target minor device number.
[0034] The second determining module is used to determine the target data channel based on the target secondary device number and the second mapping relationship, wherein the second mapping relationship includes a correspondence between at least one secondary device number and at least one available data channel;
[0035] The processing module is used to perform data transmission operations on the target data channel and the user state according to the data transmission type.
[0036] In one or more embodiments, before determining the target data channel based on the target secondary device number and the second mapping relationship, the second determining module is further configured to:
[0037] Obtain at least one available data channel;
[0038] Register the character device with the kernel and determine the major device number and at least one minor device number of the character device;
[0039] The at least one available data channel and the at least one secondary device number are mapped to obtain the second mapping relationship, wherein the at least one available data channel shares the primary device number.
[0040] In one or more embodiments, the data transmission type includes a read transmission type and a write transmission type, and the data transmission operation includes a data read operation and a data write operation;
[0041] Accordingly, the processing module is specifically used for:
[0042] If the data transmission type is a read transmission type, then the user state performs a data read operation on the target data channel;
[0043] If the data transmission type is a write transmission type, then the user state performs a data write operation on the target data channel.
[0044] In one or more embodiments, the second mapping relationship includes the correspondence between the interrupt identifier corresponding to the hardware interrupt vector carried by at least one data channel, the buffer identifier corresponding to the lockless buffer, and the at least one minor device number;
[0045] Accordingly, the processing module is also used for:
[0046] When the hardware device triggers an interrupt in the data channel to be processed, the hardware interrupt signal is acquired;
[0047] The interrupt signal is parsed and processed to determine the target interrupt identifier;
[0048] Based on the target interrupt identifier and the second mapping relationship, determine the minor device number to be processed;
[0049] Based on the minor device number to be processed and the second mapping relationship, determine the lock-free buffer to be processed;
[0050] Perform data read or data write operations on the lock-free buffer to be processed.
[0051] In one or more embodiments, the target data channel includes a data storage area;
[0052] Accordingly, the processing module is also used for:
[0053] Obtain the data traffic of the target data channel;
[0054] Based on the data flow and preset threshold, the data storage area corresponding to the target data channel is updated.
[0055] Thirdly, embodiments of this application provide an electronic device, including: a memory and a processor;
[0056] The memory stores computer-executed instructions;
[0057] The processor executes computer execution instructions stored in the memory, such that the processor, when executed, is used to implement the method described in the first aspect and any of the embodiments above.
[0058] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the methods described in the first aspect and any of the embodiments above.
[0059] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, is used to implement the data transmission method as described in the first aspect and various possible implementations of the first aspect.
[0060] This application provides a data transmission method, apparatus, device, storage medium, and program product. The method first obtains a user-mode data transmission request and a target file descriptor used to identify the data transmission request, wherein the data transmission request carries a data transmission type. Next, based on the target file descriptor and a first mapping relationship, a target data structure is determined, wherein the target data structure carries a target secondary device number. Then, based on the target secondary device number and a second mapping relationship, a target data channel is determined, wherein the second mapping relationship includes a correspondence between at least one secondary device number and at least one available data channel. Finally, based on the data transmission type, a data transmission operation is performed on the target data channel and in user mode. In the above method, by mapping file descriptors to corresponding data structures, it can be ensured that each user-mode process's access to the device can be accurately mapped to the corresponding channel resource. By mapping minor device numbers to corresponding data channels, it can be ensured that each minor device number corresponds to a specific, available data channel, avoiding interference between different devices or processes, effectively ensuring data independence and isolation, and enhancing the management efficiency of multi-channel systems. The resources of each available data channel are uniquely identified by the minor device number, and the second mapping relationship ensures that each user-mode process is bound to the corresponding hardware resource. Different user processes can concurrently operate different device channels without conflict, and the effective allocation and utilization of hardware resources are guaranteed. Attached Figure Description
[0061] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0062] Figure 1 A flowchart illustrating the data transmission method provided in the embodiments of this application. Figure 1 ;
[0063] Figure 2 A flowchart illustrating the data transmission method provided in the embodiments of this application. Figure 2 ;
[0064] Figure 3 A flowchart illustrating the data transmission method provided in the embodiments of this application. Figure 3 ;
[0065] Figure 4 A flowchart illustrating the data transmission method provided in the embodiments of this application. Figure 4 ;
[0066] Figure 5 This is a schematic diagram of the structure of the data transmission device provided in the embodiments of this application;
[0067] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0068] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation
[0069] Exemplary 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 denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0070] Before introducing the embodiments of this application, the terms involved in the embodiments of this application will be explained first:
[0071] Character devices: These are a type of device in the Linux operating system kernel that interacts with other devices through file operation interfaces (open / read / write).
[0072] Major device number: refers to the number in the Linux operating system kernel that identifies the type of character device. Devices of the same type share the major device number;
[0073] Minor device number: refers to the number used to identify a specific device instance in a character device, which together with the major device number constitutes the device identifier;
[0074] User space refers to the space in which user programs (such as applications, scripts, and utility software) run.
[0075] Kernel mode refers to the space where the Linux operating system kernel runs. It is the highest level of privilege in the Linux operating system and directly manages all hardware and core resources.
[0076] Driver: refers to a dedicated program that runs in kernel mode and is used to enable the kernel to recognize and control specific hardware devices;
[0077] Device node: refers to the interface file for user-mode access to the device;
[0078] File descriptor: refers to an identifier used by user-mode programs to access files or devices.
[0079] Secondly, the application background of the embodiments of this application will be explained:
[0080] In high-concurrency, low-latency, and multi-channel isolated data communication systems (such as radar data acquisition systems and high-speed fiber optic transmission systems), character devices typically need to process data streams from multiple independent channels simultaneously (such as 16 receive channels and 16 transmit channels in a radar system), and each channel needs to meet independent data buffering, interrupt handling, and user-mode interface access requirements.
[0081] For example, in radar data acquisition systems, multi-channel data needs to be acquired in real time and processed separately to avoid data aliasing between channels; in high-speed fiber optic communication transmission systems, multi-channel data needs to be transmitted with low latency through independent hardware interrupts and buffers.
[0082] Existing methods mainly employ a combination of a single character device and software identification. This involves registering a character device and passing a channel number parameter in user mode to distinguish data transmission channels, or using a multiple master device number method to assign an independent master device number to each data transmission channel.
[0083] However, existing methods suffer from insufficient isolation of data transmission channels and low data transmission efficiency.
[0084] The data transmission method provided in this application aims to solve the aforementioned technical problems of the prior art. The technical concept of this application is as follows: Existing methods use a single character device combined with software identification, which suffers from insufficient isolation of data transmission channels and low data transmission efficiency. Compared to using multiple major device numbers, this application considers using only one major device number, and uniquely identifying the data transmission channel through a minor device number, thereby improving the independence between different data transmission channels. This application first obtains the user-mode data transmission request and the target file descriptor used to identify the data transmission request. Then, based on the target file descriptor and a first mapping relationship, a target data structure is determined. By mapping the file descriptor to the corresponding data structure, it can be ensured that each user-mode process's access to the device can be accurately mapped to the corresponding channel resource. Next, based on the target minor device number and a second mapping relationship, the target data channel is determined. The second mapping relationship includes a correspondence between at least one minor device number and at least one available data channel. By mapping the minor device number to the corresponding data channel, it can be ensured that each minor device number corresponds to a specific, available data channel, avoiding interference between different devices or processes, and effectively ensuring data independence and isolation.
[0085] The execution subject of this application embodiment is an electronic device including an operating system. This electronic device can be a terminal device, such as a laptop, desktop computer, or tablet computer, or it can be a server. In practical applications, whether the electronic device is a terminal device or a server can be determined according to the actual situation, and there is no specific limitation on this.
[0086] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0087] Figure 1 A flowchart illustrating the data transmission method provided in the embodiments of this application. Figure 1 .like Figure 1 As shown, the data transmission method includes the following steps:
[0088] S110. Obtain the user-mode data transfer request and the target file descriptor used to identify the data transfer request;
[0089] The data transmission request includes the data transmission type.
[0090] In this step, in order to transmit data, we can first obtain the data transmission request initiated by the user space, which carries the data transmission type and the target file descriptor that identifies the data transmission request.
[0091] For example, data transfer types include data read operations and data write operations. The target file descriptor is the smallest available positive integer unique to the process, allocated by the kernel when the user space opens the character device node in advance. It is the core credential for user space to interact with the kernel on hardware resources.
[0092] In one possible implementation, this application embodiment relates to a Linux operating system, including a three-layer system architecture of user mode, kernel mode, and hardware devices, wherein the kernel mode includes the kernel and kernel drivers.
[0093] Kernel mode is the core hub connecting user mode and hardware devices, while kernel drivers are dedicated modules in kernel mode responsible for hardware device adaptation.
[0094] User space initiates data transfer requests through operating system call instructions such as read / write. The data transfer request carries the data transfer type, such as read or write. When user space opens a character device node through the open operation instruction, the kernel allocates a file descriptor (fd) for the data transfer request.
[0095] For example, when a user-space user initiates a read data request (fd=3, buf, 1024), the kernel driver can obtain the data transfer type of the data request as "read" and the target file descriptor 3 that identifies the data request from the operating system call parameters.
[0096] S120. Determine the target data structure based on the target file descriptor and the first mapping relationship;
[0097] The first mapping relationship includes a correspondence between at least one file descriptor and at least one data structure, wherein the target data structure carries the target minor device number.
[0098] In this step, the target data structure corresponding to the target file descriptor is determined based on the first mapping relationship between the target file descriptor and the correspondence between at least one file descriptor and at least one data structure, and the target data structure carries the target minor device number.
[0099] For example, the first mapping relationship is maintained by the Linux operating system kernel, which is essentially the correspondence between the "file descriptor index" and the "kernel struct file pointer" in the process-specific file descriptor table;
[0100] The minor device number carried in the target data structure can be stored in the structinode associated with the target data structure, or it can be pre-stored in the private data area of the data structure by the driver when the device is opened.
[0101] In one possible implementation, after the kernel receives a read request for fd=3, it traverses the file descriptor table of the current process, finds the struct file pointer corresponding to index 3, determines the target data structure, and then the kernel driver parses the target minor device number 5 from the inode->i_rdev associated with the structure using the MINOR() macro.
[0102] S130. Determine the target data channel based on the target secondary device number and the second mapping relationship;
[0103] The second mapping relationship includes a correspondence between at least one secondary device number and at least one available data channel.
[0104] In this step, the target data channel corresponding to the target secondary device number is determined based on the second mapping relationship between the target secondary device number and the correspondence between at least one secondary device number and at least one available data channel.
[0105] In one possible implementation, the second mapping relationship is constructed by the kernel driver during the initialization phase. It is usually stored in the form of an array, hash table, etc., and records the one-to-one correspondence between the minor device number and the hardware data channel. The driver can directly associate the dedicated resources of the data channel through this mapping relationship, such as the kernel KFIFO ring buffer, hardware register address, etc.
[0106] For example, during the initialization phase, multiple data channels are allocated kernel KFIFO ring buffers. When the kernel driver is initialized, an array minor_to_channel
[32] is created, and minor device number 5 is bound to the KFIFO ring buffer of channel 5. The array elements store the resource pointers related to the KFIFO ring buffer of channel 5, including the status information of the KFIFO (data block starting physical address, data length), waiting queue, etc.
[0107] After obtaining the target minor device number 5, the driver directly locates the KFIFO circular buffer of channel 5 by accessing the array minor_to_channel[5], reads its status information (data block starting physical address and data length), and reads the corresponding data from the KFIFO circular buffer (if it is a read operation) based on this information in the form of mmap address mapping.
[0108] S140. Perform data transmission operations on the target data channel and user space according to the data transmission type.
[0109] In this step, different data transmission types correspond to different data transmission operations, and different data transmission operations correspond to different data transmission directions. Based on the data transmission type, the data flow between the target data channel and the user space can be controlled.
[0110] In one possible implementation, the data transmission type includes a read transmission type and a write transmission type, and the data transmission operation includes a data read operation and a data write operation.
[0111] Accordingly, one possible implementation of step S140 above also includes:
[0112] The first type is if the data transmission type is read transmission type, then the user space performs a data read operation on the target data channel;
[0113] For example, if the transmission type is "read", the FPGA receives and parses the fiber optic data from data channel 5, writes the data to the kernel physical memory via DMA, and then triggers an interrupt to notify that the data copy is complete. After the kernel driver captures the interrupt, it locates data channel 5 based on the interrupt number and writes the description information of the channel data (including the starting address and data length of the data in the kernel physical memory) to the dedicated KFIFO circular buffer for channel 5. When user space initiates a read operation on / dev / chan5, the kernel driver first calls the copy_to_user instruction to copy the data description information stored in the KFIFO of channel 5 to the user-space buf buffer. The user space then accesses the kernel physical memory based on the description information using mmap address mapping to read the actual data at the corresponding position and length. The kernel finally returns the number of bytes actually read to the user space.
[0114] The second method involves writing data to the target data channel in user space if the data transmission type is write.
[0115] For example, if the transmission type is "write", the user space first writes the configuration data to be sent into its own buf buffer. After initiating a write request, the kernel driver calls the copy_from_user instruction to copy the configuration data in the user space buf to the kernel physical memory and generates a description of the data (including the starting address and data length of the data in the kernel physical memory). Then, this description is written into the dedicated KFIFO circular buffer of data channel 5. Subsequently, the kernel driver triggers an interrupt for the FPGA hardware device. The FPGA hardware device reads the corresponding configuration data from the kernel physical memory through DMA based on the description information stored in the KFIFO of channel 5, and finally sends the data to other devices through data channel 5.
[0116] The data transmission method provided in this application first obtains a data transmission request in user space and a target file descriptor used to identify the data transmission request. The data transmission request carries a data transmission type. Next, a target data structure is determined according to the target file descriptor and a first mapping relationship. The first mapping relationship includes a correspondence between at least one file descriptor and at least one data structure. The target data structure carries a target secondary device number. Then, a target data channel is determined according to the target secondary device number and a second mapping relationship. The second mapping relationship includes a correspondence between at least one secondary device number and at least one available data channel. Finally, a data transmission operation is performed on the target data channel and user space according to the data transmission type. In this embodiment, by mapping file descriptors to corresponding data structures, it can be ensured that each user-mode process's access to the device is accurately mapped to the corresponding channel resource. By mapping minor device numbers to corresponding data channels, it can be ensured that each minor device number corresponds to a specific, available data channel, avoiding interference between different devices or processes, effectively ensuring data independence and isolation, and enhancing the management efficiency of the multi-channel system. The resources of each available data channel are uniquely identified by the minor device number, and the second mapping relationship ensures that each user-mode process is bound to the corresponding hardware resource. Different user processes can concurrently operate different device channels without conflict, and the effective allocation and utilization of hardware resources are guaranteed.
[0117] Based on the above embodiments, Figure 2 A flowchart illustrating the data transmission method provided in the embodiments of this application. Figure 2 .like Figure 2 As shown, prior to step S120 above, the data transmission method further includes the following steps:
[0118] S210. Obtain at least one available data channel.
[0119] For example, at least one available data channel can be obtained in a multi-channel hardware device according to data transmission requirements.
[0120] For example, an FPGA multichannel device contains 32 physical data channels (including 16 receive channels and 16 transmit channels). During kernel driver initialization, the channel status bits in the hardware registers are read to identify that channels 0 to 31 are all available.
[0121] In one possible implementation, for each available data channel, the available data channel includes a lock-free buffer, a hardware interrupt vector, and a data processing context.
[0122] For example, each available data channel is not a single physical link, but a complete functional unit composed of hardware resources and software context. The lock-free buffer is used for temporary storage of data in kernel mode, the hardware interrupt vector is used to associate interrupt signals of the data channel, and the data processing context is used to record key information such as the channel status (e.g., data ready flag, number of bytes transferred).
[0123] In one possible implementation, the kernel driver creates an independent KFIFO lockless buffer for each available data channel, binds the hardware interrupt vector corresponding to interrupt number 10 for data channel 5, and initializes the struct channel_ctx context structure to record information such as the buffer size, transmission mode, and interrupt enable status of each channel.
[0124] S220. Register the character device with the kernel and determine the major device number and at least one minor device number of the character device.
[0125] In this step, the kernel recognizes and manages the character device by registering it, and at the same time, it assigns major and minor device numbers to identify the device.
[0126] For example, the major device number is used by the kernel to distinguish different types of character devices. Unused numbers can be dynamically allocated by the kernel. The minor device number is used by the driver to distinguish different data channels under the same character device. The number corresponds one-to-one with the available data channels.
[0127] In one possible implementation, the kernel driver calls the alloc_chrdev_region() function to dynamically register the character device with the kernel, and the kernel allocates a major device number of 240.
[0128] Next, the kernel driver assigns minor device numbers 0 to 31 to the available data channels (32), where minor device number 5 corresponds to data channel 5 of the FPGA and minor device number 16 corresponds to data channel 16.
[0129] S230. Assign at least one available data channel to at least one secondary device number to obtain a second mapping relationship;
[0130] At least one available data channel shares the same master device number.
[0131] In this step, at least one available data channel shares the same major device number, and at least one available data channel and at least one minor device number are mapped one-to-one to obtain the second mapping relationship.
[0132] In one possible implementation, a one-to-one correspondence is established between the minor device number and the available data channel, enabling the kernel driver to quickly locate the available data channel based on the kernel-standardized minor device number, and uniquely identify an available data channel by "major device number + minor device number".
[0133] The second mapping relationship is usually stored in the kernel driver in the form of arrays, hash tables, etc., as the basis for channel positioning during subsequent data transmission.
[0134] For example, for 32 available data channels (including 16 receive channels and 16 transmit channels), receive channels 0-15 correspond to minor device numbers 0-15, and transmit channels 0-15 correspond to minor device numbers 16-31.
[0135] In one possible implementation, based on the above description, the available data channel includes a lock-free buffer, hardware interrupt vectors, and a data processing context. The hardware interrupt vectors are 32 interrupt numbers (these interrupt numbers are consecutive numbers, ranging from 64 to 95) requested through the MSI (Message Signaled Interrupt) interrupt during kernel driver initialization. When an interrupt event is triggered, the interrupt number is 80. The difference between this interrupt number and the minimum interrupt number 64 is 80-64=26. In the subsequent stage of interrupt handling, the data of KFIFO26 will be processed to realize the mapping between interrupt number 80 and KFIFO26. There is also a one-to-one correspondence between KFIFO and minor device number. Based on the above mapping and correspondence, the mapping relationship between channel number, interrupt number, KFIFO, context number, and minor device number is obtained.
[0136] The data transmission method provided in this application first obtains at least one available data channel, then registers a character device with the kernel, determines the major device number and at least one minor device number of the character device, and then maps the at least one available data channel to the at least one minor device number to obtain a second mapping relationship, wherein the at least one available data channel shares the major device number. In this embodiment, registering the character device with the kernel and allocating major and minor device numbers is the core of character device management in the kernel. Multiple available data channels sharing a single major device number can greatly simplify device management and avoid the waste of resources that would otherwise be allocated a separate major device number for each device. By mapping available data channels to minor device numbers, each data channel can access and operate according to its corresponding minor device number, ensuring that data transmission between data channels of different devices does not conflict. Through the mechanism of sharing the mapping between major and minor device numbers, the management of character devices and the allocation of data channels are optimized, resource utilization is improved, and the scalability, concurrent processing capabilities, and device access independence of the operating system are enhanced, ensuring the accuracy and high performance of data transmission operations.
[0137] Based on the above embodiments, Figure 3 A flowchart illustrating the data transmission method provided in the embodiments of this application. Figure 3 .like Figure 3 As shown, the second mapping relationship includes the correspondence between the interrupt identifier corresponding to the hardware interrupt vector carried by at least one data channel, and the buffer identifier corresponding to the lock-free buffer, and at least one minor device number; correspondingly, the data transmission method further includes:
[0138] S310. When the hardware device triggers an interrupt in the data channel to be processed, acquire the hardware interrupt signal.
[0139] In this step, after a data channel of the hardware device completes data reception or transmission, it sends an electrical signal to the Central Processing Unit (CPU) through the interrupt controller. The CPU suspends the current task and switches to kernel mode. The kernel captures the interrupt signal and then forwards it to the corresponding kernel driver.
[0140] In one possible implementation, after receiving the acquired data, the data channel 6 of the FPGA multi-channel device stores it in the hardware cache and triggers an interrupt. The interrupt controller sends an interrupt signal (interrupt number 11) to the CPU. When the kernel receives the hardware interrupt signal, it immediately passes the interrupt signal to the kernel driver for subsequent processing.
[0141] S320: Analyze and process the interrupt signal to determine the target interrupt identifier.
[0142] For example, after receiving an interrupt signal, the driver reads the interrupt status register of the hardware and parses out the target interrupt identifier in the interrupt signal. This identifier can be an independent interrupt number or a combination of a shared interrupt number and an interrupt source flag.
[0143] In one possible implementation, the FPGA multi-channel device adopts an interrupt sharing mode, with multiple channels multiplexing interrupt number 11. After the driver receives the interrupt signal, it reads the interrupt status register of the FPGA and detects that bit 6 in the register is set to 1. Thus, the target interrupt identifier is determined to be "interrupt number 11 + channel 6 flag bit", accurately identifying that the interrupt is triggered by data channel 6.
[0144] S330. Determine the minor device number to be processed based on the target interrupt identifier and the second mapping relationship.
[0145] In this step, the second mapping relationship includes the correspondence between the interrupt identifier corresponding to the hardware interrupt vector carried by at least one data channel, the buffer identifier corresponding to the lockless buffer, and at least one minor device number. Then, the minor device number to be processed is determined according to the target interrupt identifier and the second mapping relationship.
[0146] In one possible implementation, if the target interrupt identifier is an independent interrupt number, i.e., corresponding to the target interrupt number, and the second mapping relationship includes the correspondence between at least one data channel, interrupt number, buffer identifier, and secondary device number, then the secondary device number corresponding to the target interrupt number can be determined based on the second mapping relationship, and the secondary device number can be used as the secondary device number to be processed.
[0147] S340. Determine the lock-free buffer to be processed based on the minor device number to be processed and the second mapping relationship.
[0148] In this step, based on the minor device number to be processed and the second mapping relationship, the minor device number to be processed and the dedicated lock-free buffer of the corresponding data channel are determined to provide a storage carrier for subsequent data read and write operations.
[0149] In one possible implementation, the kernel driver maintains a second mapping relationship in which the minor device number is bound to all resources of the available data channel, including the channel-specific lock-free buffer (such as KFIFO). By indexing the minor device number mapping table, key information such as the buffer's address, size, and read / write pointers can be directly obtained.
[0150] S350: Perform data read or write operations on the lock-free buffer to be processed.
[0151] In this step, based on the triggering cause of the hardware interrupt, the corresponding data transfer operation (data read operation or data write operation) is performed on the lock-free buffer to realize the interaction between hardware data and kernel buffer.
[0152] In one possible implementation, the interrupt is triggered by receiving data from data channel 6. The kernel driver first reads 512 bytes of data description information from the memory address of channel 6 of the FPGA multi-channel device, and then calls the kfifo_in() function to write the data description information into the corresponding KFIFO unlocked buffer, while updating the write pointer of the unlocked buffer. If it is a transmit completion interrupt, the kernel driver calls kfifo_out() to read the data description information from the unlocked buffer, writes it into the hardware device's transmit buffer, and triggers a new round of data transmission.
[0153] In addition, interrupt events from multiple data channels can be aggregated into a single interrupt vector, reducing the number of CPU interrupts.
[0154] For example, the interrupt trigger signals of 32 channels can be merged into a single interrupt through hardware logic or software polling, and the driver can parse the minor device number during interrupt handling to distinguish the specific channel.
[0155] In one possible implementation, the target data channel includes a data storage area;
[0156] Accordingly, the data transmission method also includes:
[0157] Step 1: Obtain the data traffic of the target data channel;
[0158] For example, data traffic can be acquired from both hardware and software dimensions: at the hardware level, the hardware cache data counter register of the channel is read; at the software level, the number of bytes read and written in the kernel's unlocked buffer is counted; or the traffic per unit time (such as the number of bytes transferred per second) can be calculated by combining time windows.
[0159] The kernel driver selects the collection method according to the needs of the scenario to ensure that the traffic data can truly reflect the transmission load of the channel.
[0160] Step 2: Update the data storage area corresponding to the target data channel based on the data flow and preset threshold.
[0161] For example, the resource configuration of the data storage area can be dynamically adjusted based on the comparison between the data traffic and the preset threshold, so as to avoid wasting memory due to the data storage area being too large or causing data overflow due to the data storage area being too small.
[0162] Preset thresholds are usually divided into upper and lower limits (e.g., 1MB / s is the upper limit of traffic and 200KB / s is the lower limit of traffic).
[0163] In one possible implementation, the kernel driver dynamically adjusts the size of the data storage area or the interrupt trigger threshold based on the relationship between data traffic and preset thresholds. For example, high-traffic channels automatically expand the capacity of the data storage area, while low-traffic channels reclaim redundant resources.
[0164] The data transmission method provided in this application embodiment includes a second mapping relationship between the interrupt identifier corresponding to the hardware interrupt vector carried by at least one data channel, the buffer identifier corresponding to the lock-free buffer, and at least one minor device number. Accordingly, when a hardware device triggers an interrupt in a data channel to be processed, a hardware interrupt signal is acquired, and then the interrupt signal is parsed to determine the target interrupt identifier. Then, based on the target interrupt identifier and the second mapping relationship, the minor device number to be processed is determined, and based on the minor device number to be processed and the second mapping relationship, the lock-free buffer to be processed is determined. Finally, a data read operation or a data write operation is performed on the lock-free buffer to be processed. In this embodiment, the interrupt signal triggered by the hardware device is usually a response to a certain event during data processing. After the hardware interrupt signal arrives, signal parsing is performed to identify the interrupt identifier. The target interrupt identifier is associated with the corresponding minor device number through the second mapping relationship. The minor device number represents a specific device instance or data channel in the kernel, ensuring that the interrupt signal can be mapped to the correct hardware resource. The lock-free buffer design reduces performance bottlenecks caused by lock contention, and through precise resource mapping and efficient data access mechanisms, improves the utilization of hardware resources and ensures efficient parallel processing of multiple hardware devices and multiple data channels.
[0165] In one possible implementation, this application embodiment is based on the Linux operating system and includes a three-layer system architecture of user mode, kernel mode, and hardware devices. The kernel mode includes the kernel and kernel drivers. The user mode accesses the hardware devices through character device nodes, and the kernel drivers are used to connect the user mode and the hardware devices. Figure 4 A flowchart illustrating the data transmission method provided in the embodiments of this application. Figure 4 , combined Figure 4 The specific process of the data transmission method provided in the embodiments of this application will be described as follows:
[0166] S1. User mode opens a character device node using the open command;
[0167] S2. The kernel driver extracts the minor device number N from the character device node and binds it to the dedicated resources of the data channel N (KFIFO[N] buffer, interrupt number). Finally, it returns the file descriptor fd to the user space as an identifier for subsequent operations.
[0168] The difference between the interrupt number and the minimum interrupt number assigned during kernel driver initialization configuration is N. Based on this, the difference between the interrupt number and the minimum interrupt number can be determined according to the known interrupt number, and then the correspondence between the interrupt number and the data channel and the minor device number can be constructed.
[0169] S3: After the FPGA hardware device writes data into the hardware cache of data channel N, it triggers an interrupt and sends it to the kernel driver.
[0170] S4. After receiving the interrupt, the kernel driver copies the data in the hardware cache to the KFIFO[N] buffer corresponding to the data channel N;
[0171] S5. The KFIFO[N] buffer corresponding to data channel N is marked as "buffer not empty" and the buffer not empty signal is sent to the kernel driver;
[0172] S6. User space sends a read data request to the kernel driver: read(fd, buf, len).
[0173] S7. The kernel driver receives the data read request and associates it with the minor device number N through the file descriptor fd. It reads the data from the KFIFO[N] buffer and then copies the data to the user-space buf buffer, completing one data transfer.
[0174] For example, the data description information of the corresponding channel in the KFIFO buffer can be copied to the user-space buf buffer in the kernel using copy_to_user, and then the data described in the data description information can be obtained through mmap mapping.
[0175] Based on the above embodiments, the following is a data transmission device provided in the embodiments of this application, which can execute the methods provided in the above method embodiments.
[0176] Figure 5 This is a schematic diagram of the structure of a data transmission device provided in an embodiment of this application. Figure 5 As shown, the data transmission device 500 includes:
[0177] The acquisition module 510 is used to acquire a data transmission request in user space and a target file descriptor used to identify the data transmission request, wherein the data transmission request carries a data transmission type;
[0178] The first determining module 520 is used to determine the target data structure based on the target file descriptor and the first mapping relationship, wherein the first mapping relationship includes the correspondence between at least one file descriptor and at least one data structure, and the target data structure carries the target minor device number;
[0179] The second determining module 530 is used to determine the target data channel based on the target secondary device number and the second mapping relationship, wherein the second mapping relationship includes a correspondence between at least one secondary device number and at least one available data channel;
[0180] The processing module 540 is used to perform data transmission operations on the target data channel and user space according to the data transmission type.
[0181] In one or more embodiments, before determining the target data channel based on the target secondary device number and the second mapping relationship, the second determining module 530 is further configured to:
[0182] Obtain at least one available data channel;
[0183] Register the character device with the kernel and determine the major device number and at least one minor device number for the character device;
[0184] A second mapping relationship is obtained by mapping at least one available data channel to at least one secondary device number, wherein at least one available data channel shares the primary device number.
[0185] In one or more embodiments, the data transmission type includes a read transmission type and a write transmission type, and the data transmission operation includes a data read operation and a data write operation;
[0186] Correspondingly, processing module 540 is specifically used for:
[0187] If the data transmission type is read transmission, then the user space performs a data read operation on the target data channel;
[0188] If the data transmission type is write transmission, then the user space performs a data write operation on the target data channel.
[0189] In one or more embodiments, the second mapping relationship includes the correspondence between the interrupt identifier corresponding to the hardware interrupt vector carried by at least one data channel, the buffer identifier corresponding to the lockless buffer, and at least one minor device number;
[0190] Correspondingly, processing module 540 is also used for:
[0191] When the hardware device triggers an interrupt in the data channel to be processed, the hardware interrupt signal is acquired;
[0192] The interrupt signal is parsed and processed to determine the target interrupt identifier;
[0193] Based on the target interrupt identifier and the second mapping relationship, determine the minor device number to be processed;
[0194] The lock-free buffer to be processed is determined based on the minor device number to be processed and the second mapping relationship;
[0195] Perform data read or write operations on the lock-free buffer to be processed.
[0196] In one or more embodiments, the processing module 540 is further configured to:
[0197] Acquire the data traffic of the target data channel;
[0198] Based on the data flow and preset thresholds, the lock-free buffer corresponding to the target data channel is updated.
[0199] The data transmission device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.
[0200] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 6 As shown, the electronic device 600 includes: a processor 610, a memory 620, and a bus 630;
[0201] The memory 620 is used to store the computer-executed instructions of the processor 610;
[0202] The processor 610 is configured to execute the technical solutions of any of the foregoing method embodiments by executing computer execution instructions.
[0203] The specific implementation process of processor 610 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0204] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0205] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.
[0206] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0207] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0208] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.
[0209] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random-Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0210] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an application-specific integrated circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.
[0211] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0212] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0213] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0214] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory, random access memory (RAM), magnetic disks, or optical disks.
[0215] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0216] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. A data transmission method, characterized in that, include: Obtain a user-mode data transfer request and a target file descriptor used to identify the data transfer request, wherein the data transfer request carries a data transfer type; Based on the target file descriptor and the first mapping relationship, a target data structure is determined. The first mapping relationship includes a correspondence between at least one file descriptor and at least one data structure. The target data structure carries a target minor device number. The target data channel is determined based on the target secondary device number and the second mapping relationship, wherein the second mapping relationship includes the correspondence between at least one secondary device number and at least one available data channel; According to the data transmission type, data transmission operations are performed on the target data channel and the user state.
2. The method according to claim 1, characterized in that, Before determining the target data channel based on the target secondary device number and the second mapping relationship, the method further includes: Obtain at least one available data channel; Register the character device with the kernel and determine the major device number and at least one minor device number of the character device; The at least one available data channel and the at least one secondary device number are mapped to obtain the second mapping relationship, wherein the at least one available data channel shares the primary device number.
3. The method according to claim 2, characterized in that, The data transmission types include read transmission types and write transmission types, and the data transmission operations include data read operations and data write operations; Accordingly, the step of performing data transmission operations on the target data channel and the user space according to the data transmission type includes: If the data transmission type is a read transmission type, then the user state performs a data read operation on the target data channel; If the data transmission type is a write transmission type, then the user state performs a data write operation on the target data channel.
4. The method according to any one of claims 1-3, characterized in that, For each available data channel, the available data channel includes a lock-free buffer, a hardware interrupt vector, and a data processing context.
5. The method according to claim 4, characterized in that, The second mapping relationship includes the correspondence between the interrupt identifier corresponding to the hardware interrupt vector carried by at least one data channel, the buffer identifier corresponding to the lockless buffer, and the at least one minor device number; Accordingly, the method further includes: When the hardware device triggers an interrupt in the data channel to be processed, the hardware interrupt signal is acquired; The interrupt signal is parsed and processed to determine the target interrupt identifier; Based on the target interrupt identifier and the second mapping relationship, determine the minor device number to be processed; Based on the minor device number to be processed and the second mapping relationship, determine the lock-free buffer to be processed; Perform data read or data write operations on the lock-free buffer to be processed.
6. The method according to claim 4, characterized in that, The target data channel includes a data storage area; Accordingly, the method further includes: Obtain the data traffic of the target data channel; Based on the data flow and preset threshold, the data storage area corresponding to the target data channel is updated.
7. A data transmission device, characterized in that, include: The acquisition module is used to acquire a data transmission request in user space and a target file descriptor used to identify the data transmission request, wherein the data transmission request carries a data transmission type; The first determining module is configured to determine a target data structure based on the target file descriptor and the first mapping relationship, wherein the first mapping relationship includes a correspondence between at least one file descriptor and at least one data structure, and the target data structure carries a target minor device number. The second determining module is used to determine the target data channel based on the target secondary device number and the second mapping relationship, wherein the second mapping relationship includes a correspondence between at least one secondary device number and at least one available data channel; The processing module is used to perform data transmission operations on the target data channel and the user state according to the data transmission type.
8. An electronic device, characterized in that, include: Memory, processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-6.
10. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-6.