A data transmission method and device, an electronic device and a medium

By adding a write queue to the USB serial port logic file, skipping two memory copies and buffers, the problem of low data transmission efficiency under the tty architecture is solved, and more efficient data transmission is achieved.

CN114968535BActive Publication Date: 2025-11-04SHANGHAI KINDROID NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210691741.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-17
Publication Date
2025-11-04
Estimated Expiration
2042-06-17

AI Technical Summary

Technical Problem

In existing Linux operating systems, USB drivers using the tty architecture require three memory copies for data transfer, resulting in high memory consumption and impacting data transfer efficiency.

Method used

Add a write queue to the port structure under the USB serial port logic file. Use the function of the USB serial port logic file to temporarily store user space data in the queue and transmit it directly to UDC, skipping two unnecessary memory copies and a large memory buffer.

Benefits of technology

This reduces the Linux kernel's memory usage and improves data transfer efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114968535B_ABST
    Figure CN114968535B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a data transmission method and device, electronic equipment and medium. The method comprises: adding a write queue in a port structure under a USB serial port logic file; moving, by a first write file function of the USB serial port logic file, user space transmitted data to be processed to the write queue; and transmitting, by a data sending function of the USB serial port logic file, the data to be processed in the write queue to UDC in sequence until the data to be processed in the write queue is transmitted completely. By adding the write queue in the port structure under the USB serial port logic file, changing part of data structure and data processing flow during sending, user data is first temporarily stored in the write queue and then transmitted to the sending queue of UDC, and two redundant memory copies and a large memory buffer are removed, so that the occupation of memory by the Linux kernel is reduced and the efficiency of data transmission is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of computer, and particularly relate to a data transmission method and device, electronic equipment and medium. BACKGROUND

[0002] At present, the teletypewriter (tty) architecture based USB driver has been implemented completely in Linux operating system, and a user can only implement the UDC driver. The existing tty architecture, for the Linux APP, if the USB virtual serial port (such as "ttyGSx" port) provided by the USB driver under the tty architecture is opened to send data to a PC, the USB driver under the tty architecture will contain three corresponding memory copies, and finally the data is sent to the PC through the USB controller.

[0003] However, in the above data transmission process, three memory copies are required to send data to the PC, and too many memory copies will also occupy more memory, thereby affecting the efficiency of data transmission. SUMMARY

[0004] Embodiments of the present application provide a data transmission method and device, electronic equipment and medium to improve the efficiency of data transmission.

[0005] According to an aspect of embodiments of the present application, a data transmission method is provided, comprising:

[0006] adding a write queue in a port structure under a USB serial port logical file, the write queue being used as a memory space for storing the user space transmission data to be processed;

[0007] moving the user space transmission data to be processed to the write queue through a first write file function of the USB serial port logical file;

[0008] transmitting the user space transmission data to be processed in the write queue to the UDC through a data sending function of the USB serial port logical file, until the user space transmission data to be processed in the write queue is transmitted completely.

[0009] According to another aspect of embodiments of the present application, a data transmission device is provided, comprising:

[0010] A queue adding module is configured to add a write queue in a port structure under a USB serial port logic file, and the write queue is used as a memory space for storing data to be processed transmitted by a user space;

[0011] A transmission module is configured to move the data to be processed transmitted by the user space to the write queue through a first write file function of the USB serial port logic file;

[0012] A copying module is configured to sequentially transmit the data to be processed in the write queue to a UDC through a data sending function of the USB serial port logic file until the data to be processed in the write queue is completely transmitted.

[0013] According to another aspect of the embodiment of the present application, an electronic device is provided, and the electronic device comprises:

[0014] at least one processor; and

[0015] a memory connected with the at least one processor in communication; wherein

[0016] the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the data transmission method according to any one of the embodiments of the present application.

[0017] According to another aspect of the embodiment of the present application, a computer readable storage medium is provided, and the computer readable storage medium stores computer instructions for enabling a processor to implement the data transmission method according to any one of the embodiments of the present application when executed.

[0018] The technical solution of the embodiment of the present application first adds a write queue in a port structure under a USB serial port logic file, and the write queue is used as a memory space for storing data to be processed transmitted by a user space; then moves the data to be processed transmitted by the user space to the write queue through a first write file function of the USB serial port logic file; and finally sequentially transmits the data to be processed in the write queue to a UDC through a data sending function of the USB serial port logic file until the data to be processed in the write queue is completely transmitted. The method adds a write queue in a port structure under a USB serial port logic file, changes part of data structures and data processing procedures during transmission, realizes that user data is first temporarily stored in the write queue and then transmitted to a sending queue of the UDC, and realizes that two redundant memory copies and a large memory buffer are removed, thereby reducing the occupation of memory by a Linux kernel and improving the efficiency of data transmission.

[0019] It is to be understood that the embodiments described herein are merely exemplary of the application and that a person skilled in the art can devise other embodiments without departing from the scope of the present application. It is also to be understood that not all of the features and / or benefits described and / or illustrated herein need be present in every embodiment of the application. The scope of the application should therefore not be limited to the features and / or benefits described and / or illustrated herein, but should be given the full scope that the claims afford based on the entirety of the specification. BRIEF DESCRIPTION OF DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments will be briefly introduced as follows. Obviously, the drawings in the following description only represent some of the embodiments of the present application, and other drawings can be obtained by those skilled in the art without any creative effort based on these drawings.

[0021] Figure 1 An implementation schematic diagram of a data transmission method provided by the embodiment of the present application;

[0022] Figure 2 A flowchart of the data transmission method provided by the first embodiment of the present application;

[0023] Figure 3 A flowchart of the data transmission method provided by the second embodiment of the present application;

[0024] Figure 4 An implementation schematic diagram of the data transmission method provided by the second embodiment of the present application;

[0025] Figure 5 An implementation schematic diagram of another data transmission method provided by the second embodiment of the present application;

[0026] Figure 6 A structural schematic diagram of a data transmission device provided by the third embodiment of the present application;

[0027] Figure 7 A structural schematic diagram of an electronic device provided by the fourth embodiment of the present application. DETAILED DESCRIPTION

[0028] In order to make the technical personnel in the art better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely in the following with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, not all. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without any creative effort should be within the scope of protection of the present application.

[0029] It is to be understood that the terminology "first", "second" and the like used in the specification and the claims of the application as well as the foregoing drawings is merely intended to distinguish between similar objects and not necessarily for describing a special sequential order. It is to be understood that the data so described using these terms can be interchanged, under appropriate circumstances, to describe the embodiments of the application described herein in other than the special sequential order described. Additionally, the terms "comprising", "having", "including" and "containing" and any variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, system, product or apparatus that comprises, has, includes or contains an item or list of items does not include only those items, but can include other items not expressly listed or inherent to such process, method, system, product or apparatus.

[0030] The USB driver of the existing tty architecture sends data to the PC, and three memory copies exist, in addition to the memory copy from the user mode to the kernel mode, the other two memory copies are redundant, and the memory is additionally occupied. Embodiments of the present application provide a data transmission method, which removes two redundant memory copies, improves data transmission efficiency; and by removing the two redundant memory copies, a large memory buffer (i.e. a memory buffer corresponding to a memory copy with large memory occupation) can be removed, thereby reducing the memory occupation of the Linux kernel.

[0031] In order to better understand the embodiments of the present application, the related terms are introduced as follows.

[0032] Kernel space and user space: in order to avoid the user process directly operating the kernel and ensure the safety of the kernel, the Linux system divides its virtual memory into two parts, one part is the core software, which can be called kernel, also called kernel space; the other part is the ordinary application program, which can be called user space, represented as user. The kernel code and data are stored in the kernel space, and the user program code and data are stored in the user space of the user process. Whether it is the kernel space or the user space, they are all in the virtual memory space, which is a mapping of the physical address.

[0033] Memory copy from user mode to kernel mode: copy can mean copy, copy data from user mode memory to kernel mode memory, that is, copy data from user space to kernel space.

[0034] Figure 1 An implementation schematic diagram of the data transmission method provided by the embodiments of the present application is shown in FIG. 1. Figure 1As shown, the USB driver under the existing tty architecture will exist three times of memory copy when transmitting data to PC, the first memory copy is the kernel space tty copying memory from user space (i.e. copy_from_user), 2K Buffer can represent 2K memory buffer; the second memory copy is u_serial (i.e. USB serial port logical file) copying memory from tty (i.e. copying memory from tty through memory copy function (i.e. memcpy)), 4M Buffer can represent 4M memory buffer; the third memory copy is UDC copying memory from u_serial (i.e. copying memory from u_serial through memory copy function (i.e. memcpy)), 1K Buffer Queue can represent 1K memory buffer queue.

[0035] Embodiment One

[0036] Figure 2 A flow chart of a data transmission method provided for the embodiment one of the present application, the embodiment can be applicable to the case of transmitting data through USB virtual serial port, the method can be executed by a data transmission device, the data transmission device can be realized in the form of hardware and / or software, and the data transmission device can be configured in an electronic device. As shown, the method comprises: Figure 2

[0037] S110, adding a write queue in a port structure body under a USB serial port logical file, the write queue is used as a memory space for storing to-be-processed data transmitted by user space.

[0038] In the embodiment, the USB serial port logical file can be understood as a file used for indicating the running logic related to the USB virtual serial port. It can also be understood that the USB serial port logical file is a file containing the running code information related to the USB virtual serial port.

[0039] ​For the application program of Linux, if the USB virtual serial port (such as the "ttyGSx" port) provided by the USB driver under the tty architecture is opened to send data to the PC, the execution of the USB virtual serial port related running logic will be involved. In the programming field, the USB virtual serial port related running logic can be stored in the form of a file (such as a binary file) in a related directory (such as the USB driver directory and the USB driver framework directory). For example, taking the Linux 4.4 version as an example, the USB serial port logic file can refer to the "u_serial.c" file under the "usb / gadget" directory, where "usb" can represent the USB driver directory, "gadget" can represent the USB driver framework directory, and "u_serial.c" can represent the USB serial port logic file; the "u_serial.c" file under "usb / gadget" can refer to the "u_serial.c" file under the "gadget" directory in the "usb" directory as the USB serial port logic file.

[0040] In the programming field, a structure can refer to a data structure, which can be a data collection composed of a series of data of the same type or different types; the structure can be declared as a variable, a pointer, or an array, etc. to realize a more complex data structure. The port structure can be understood as a structure associated with the USB virtual serial port; for example, the port structure can be represented as "gs_port".

[0041] The write queue can be used as a memory space for storing the user space transmission pending data; that is, the write queue can be used as the write cache of the UDC, and the UDC can read and send the data from the write queue in sequence when sending data. For example, the write queue can be represented as "write_queue". The pending data can be understood as data waiting to be processed.

[0042] Specifically, the write queue can be added in the port structure under the USB serial port logic file to be used as a memory space for storing the user space transmission pending data, so that the UDC can read and send the data from the write queue in sequence. For example, the write queue can be added in the port structure under the USB serial port logic file, which can be represented as adding "struct list_head write_queue" in the port structure "gs_port" under the "u_serial.c" file to be used as the write cache of the UDC, and the UDC can read the data from here in sequence when sending data.

[0043] S120, by the first write file function of the USB serial port logic file, the user space transmission pending data is moved to the write queue.

[0044] In the embodiment, the first write file function can be understood as a function for writing data into a file under the USB serial port logic file. For example, the first write file function can be represented as "gs_write". The first write file function already exists under the USB serial port logic file, and by changing the relevant logic code in the first write file function, the user space transmitted data to be processed can be moved to the write queue.

[0045] In an embodiment, since the USB driver under the existing tty architecture transmits data to the PC with three times of memory copying, in addition to the memory copying from the user space to the kernel space, the other two times of memory copying (i.e., the memory copying from the user space to the kernel space of the tty, and the memory copying from the tty to the u_serial) are redundant, and also occupy additional memory, so the memory of the user space can be directly copied to the UDC. Therefore, before moving the user space transmitted data to be processed to the write queue, the first memory copying (i.e., the 2K Buffer is not used) can be skipped, that is, the process of copying memory from the user space through the 2K Buffer is skipped; on this basis, the memory copying related information (i.e., the second memory copying) under the USB serial port logic file can also be deleted, that is, the memory buffer (i.e., the 4M Buffer) corresponding to the memory copying is not used, but the write queue added in the port structure under the USB serial port logic file is directly used as the memory space for storing the user space transmitted data to be processed.

[0046] S130, through the data sending function of the USB serial port logic file, the user space transmitted data to be processed in the write queue is sequentially transmitted to the UDC until the user space transmitted data to be processed in the write queue is transmitted.

[0047] In the embodiment, the data sending function can be understood as a function for sending data under the USB serial port logic file. For example, the data sending function can be represented as the "gs_start_tx" function.

[0048] After the user space transmitted data to be processed is moved to the write queue, the data sending function of the USB serial port logic file can be used to sequentially transmit the data to be processed in the write queue to the UDC (such as to the sending queue of the UDC, and the sending queue can be understood as a message queue for storing data to be sent in the UDC), until the data to be processed in the write queue is transmitted.

[0049] The embodiment one of the present application provides a data transmission method, first, adding a write queue in a port structure under a USB serial port logic file, the write queue is used as a memory space for storing to-be-processed data transmitted by a user space; then, moving the to-be-processed data transmitted by the user space to the write queue through a first write file function of the USB serial port logic file; finally, transmitting the to-be-processed data in the write queue to a UDC in sequence through a data sending function of the USB serial port logic file, until the to-be-processed data in the write queue is transmitted completely. The method adds the write queue in the port structure under the USB serial port logic file, changes part of data structure and data processing flow during sending, realizes that user data is first temporarily stored in the write queue and then transmitted to a sending queue of the UDC, and realizes that two times of redundant memory copying and a large memory buffer are removed, so that the occupation of memory by a Linux kernel is reduced, and the efficiency of data transmission is improved.

[0050] Embodiment two

[0051] Figure 3 A flowchart of a data transmission method provided by the embodiment two of the present application is provided, and the embodiment two is refined on the basis of the above-mentioned embodiments. In the embodiment, the process of deleting the first copy information, skipping the second memory copy information and moving the to-be-processed data transmitted by the user space to the write queue is described in detail. It should be noted that the technical details not described in detail in the embodiment can refer to any of the above-mentioned embodiments. As shown in the embodiment, the method comprises the following steps. Figure 3

[0052] S210, adding a preset identifier in a serial port calling function of a USB serial port logic file, the preset identifier is used for indicating a USB virtual serial port.

[0053] In the embodiment, the serial port calling function can be understood as a function used for calling the USB virtual serial port under the USB serial port logic file. For example, the serial port calling function can be represented as "gs_open".

[0054] The preset identifier can be understood as an identifier set in advance and used for indicating the USB virtual serial port. The setting of the preset identifier is not limited here, for example, the preset identifier can be a string of numbers and characters, such as 0x80000000.

[0055] In order to distinguish the USB virtual serial port from a general serial port device, the preset identifier can be added in the serial port calling function of the USB serial port logic file, and the USB virtual serial port is indicated through the preset identifier. For example, adding the preset identifier in the serial port calling function of the USB serial port logic file can be represented as "tty->flags|=0x80000000".

[0056] ​S220, according to the preset identifier, changing the second write file function under the input and output function implementation file, and the changed second write file function is used to indicate that the second memory copy information under the input and output function implementation file is skipped when transmitting the to-be-processed data through the USB virtual serial port.

[0057] In the embodiment, the input and output function implementation file can be understood as a file under a tty architecture directory (such as a “tty” directory) for implementing input and output functions. For example, the input and output function implementation file can be represented as a “tty_io.c” file. The second write file function can be understood as a function under the input and output function implementation file for writing data into a file. For example, the second write file function can be represented as a “tty_write” function. The second memory copy information can be understood as memory copy information under the input and output function implementation file; the memory copy information can be understood as logical code information associated with memory copy. The second memory copy information can be considered as the first memory copy described above.

[0058] According to the preset identifier, the original execution logic related to the second memory copy information in the second write file function under the input and output function implementation file is changed, so that the changed second write file function is used to indicate that the second memory copy information under the input and output function implementation file is skipped and not executed when transmitting the to-be-processed data through the USB virtual serial port.

[0059] For example, the “tty_write” function is modified, and ret = do_tty_write (ld->ops->write, tty, file, buf, count); (i.e. the original execution logic related to the second memory copy information in the second write file function) is changed to:

[0060] if (tty->flags & 0x80000000) {

[0061] ret = tty->ops->write (tty, buf, count);

[0062] } else {

[0063] ret = do_tty_write (ld->ops->write, tty, file, buf, count)

[0064] }; (i.e. the changed second write file function)

[0065] According to the preset identifier, the second write file function is changed to obtain a changed second write file function, an if judgment logic is set based on the preset identifier to judge whether the current serial port is a USB virtual serial port, if the current serial port is the USB virtual serial port, the changed second write file function is used to indicate that the second memory copy information under the input and output function implementation file is skipped when the USB virtual serial port indicated by the preset identifier is used to transmit the data to be processed, otherwise (for example, a general serial port device), the original execution logic related to the second memory copy information in the second write file function is executed.

[0066] S230, deleting the first memory copy information under the USB serial port logic file, so that the data to be processed transmitted by the user space is transmitted to the write queue.

[0067] In the embodiment, the first memory copy information can be understood as the memory copy information under the USB serial port logic file; the first memory copy information can be considered as the second memory copy mentioned above.

[0068] On the basis of skipping the second memory copy information under the input and output function implementation file, the first memory copy information under the USB serial port logic file is deleted, so that the data to be processed transmitted by the user space does not use the first memory copy information and the second memory copy information, and can be directly transmitted to the write queue. For example, deleting the first memory copy information under the USB serial port logic file can be represented as deleting all "port_write_buf" related code information in the "u_serial.c" file; all "port_write_buf" related code information can be considered as the first memory copy information.

[0069] It should be noted that the present application does not specifically limit the execution sequence between S210 to S220 and S230. For example, S210 to S220 can be executed first, and then S230 can be executed. S230 can also be executed first, and then S210 to S220 can be executed.

[0070] S240, adding the write queue in the port structure under the USB serial port logic file.

[0071] In the embodiment, after skipping the second memory copy information and deleting the first memory copy information, the write queue can be added in the port structure under the USB serial port logic file, so that the write queue is used as a memory space for storing the data to be processed transmitted by the user space in the subsequent process.

[0072] S250, obtaining a USB request structure from a preset write space through the first write file function of the USB serial port logic file, the USB request structure being the smallest data unit of the cached data.

[0073] In this embodiment, the preset write space can be understood as a write space preset in the first write file function. The preset write space can include a plurality of USB request structures, and the plurality of USB request structures are arranged in a list form in the preset write space in a certain order; that is, the preset write space can be considered as a structure list including a plurality of USB request structures. For example, the preset write space can be represented as "write_pool".

[0074] The USB request structure can be understood as a minimum data unit for buffering data; for example, one USB request structure can include a 1K buffer (i.e., 1K Buffer), or can include a 2K Buffer, which is not limited here and can be flexibly set according to actual needs. For example, the USB request structure can be represented as "usb_request".

[0075] Specifically, one USB request structure can be obtained from the preset write space through the first write file function of the USB serial port logical file, so as to be used for subsequent copying of the to-be-processed data transmitted by the user space into the USB request structure.

[0076] S260, copying the to-be-processed data transmitted by the user space into the USB request structure.

[0077] In this embodiment, after obtaining one USB request structure from the preset write space, the to-be-processed data transmitted by the user space can be copied into the USB request structure. For example, the to-be-processed data transmitted by the user space can be copied into the USB request structure through a corresponding copy function.

[0078] Optionally, copying the to-be-processed data transmitted by the user space into the USB request structure includes: copying the to-be-processed data transmitted by the user space into a data buffer of the USB request structure through a copy function.

[0079] The copy function can be understood as a function for copying the to-be-processed data transmitted by the user space. For example, the copy function can be a "copy_from_user" function. The data buffer of the USB request structure can be understood as a storage space of the USB request structure for buffering input or output data, such as a 1K Buffer. The USB request structure can be represented as "usb_request".

[0080] The to-be-processed data transmitted by the user space can be copied into the data buffer of the USB request structure by calling the copy function.

[0081] S270, moving the USB request structure including the to-be-processed data from the preset write space to the write queue.

[0082] In this embodiment, after the data to be processed is copied into the USB request structure, the USB request structure containing the data to be processed can be moved from the preset write space to the write queue for storage, so that the UDC can read the USB request structure containing the data to be processed from the write queue and send it out subsequently.

[0083] S280, judging whether the data to be processed in the user space is transmitted completely, if yes, executing S290; otherwise, returning to execute S250.

[0084] In this embodiment, whether the data to be processed in the user space is transmitted completely or the preset write space is empty is judged, if the data to be processed in the user space is transmitted completely, the process of moving the data to be processed transmitted from the user space to the write queue is ended, and S290 is executed continuously.

[0085] If the data to be processed in the user space is not transmitted completely, the operation of acquiring a USB request structure from the preset write space is executed continuously until the data to be processed in the user space is transmitted completely.

[0086] It can be understood that if the preset write space is empty, it indicates that the USB request structures in the preset write space have been acquired completely, and no matter whether the data to be processed in the user space is transmitted completely, the process of moving the data to be processed transmitted from the user space to the write queue is ended, and S290 is executed continuously.

[0087] S290, transmitting the USB request structures in the write queue to the UDC in sequence through the data sending function of the USB serial logical file until the USB request structures in the write queue are transmitted completely.

[0088] In this embodiment, after all the USB request structures containing the data to be processed are moved from the preset write space to the write queue, the USB request structures in the write queue can be transmitted to the UDC in sequence through the data sending function of the USB serial logical file until the USB request structures in the write queue are transmitted completely.

[0089] S2100, moving the USB request structures in the write queue back to the preset write space.

[0090] In this embodiment, after the USB request structures in the write queue are transmitted completely, the USB request structures in the write queue can be moved back to the preset write space for the transmission of the data to be processed next time.

[0091] It should be noted that although the USB request structure in the write queue is transmitted to the UDC, the USB request structure containing the to-be-processed data in the write queue still exists after the transmission. The USB request structure containing the to-be-processed data in the write queue is moved back to the preset write space to wait for the next time for standby, and when the next USB request structure containing to-be-processed data is acquired and used, the new to-be-processed data will overwrite the original to-be-processed data contained in the USB request structure.

[0092] Embodiment two of the present application provides a data transmission method, which specifically implements the processes of deleting the first copy information, skipping the second memory copy information, and moving the to-be-processed data transmitted from the user space to the write queue. The method directly transmits the to-be-processed data transmitted from the user space to the write queue by skipping the second memory copy information and deleting the first memory copy information, can remove the two redundant memory copies of the first memory copy information and the second memory copy information, and can also avoid the first memory copy information and the second memory copy information occupying additional memory, thereby reducing the memory occupation of the Linux kernel and improving the efficiency of data transmission.

[0093] The present application is exemplarily described below.

[0094] Figure 4 An implementation schematic diagram of the data transmission method provided by embodiment two of the present application is shown in FIG. 2. Figure 4 As shown in FIG. 2, the first memory copy (i.e., the second memory copy information) of copying the memory from the user space by the tty is skipped, the first memory copy (i.e., the first memory copy information) of copying the memory from the tty by the u_serial is deleted, the to-be-processed data transmitted from the user space is directly moved to the write queue (i.e., the 1K Buffer Queue) through the first write file function of the USB serial port logical file, and the to-be-processed data in the write queue is sequentially copied to the UDC through the data sending function of the USB serial port logical file, thereby realizing the transmission of data.

[0095] The data transmission method provided by the embodiment of the present application mainly changes the USB driver under the tty architecture of the Linux kernel, and the calling interface for the application layer remains unchanged.

[0096] Taking a computer device with a USB device accessing a Windows system as an example, it is assumed that an application program on a Linux system needs to output a large amount of log (i.e., Log) data to an application program on a Windows system, so as to facilitate a user to view, analyze or process the Log data.

[0097] Figure 5 An implementation schematic diagram of another data transmission method provided by embodiment two of the present application is shown in FIG. 3. Figure 5As shown, an application program (i.e. Log App) on the Linux system that wants to transmit log data transmits the log data to an application program on the Windows system for log viewing. On the Linux system, the second memory copy information is skipped and the first memory copy information is deleted, and the user space-transmitted log data is copied to the UDC through a write queue (i.e. 1K Buffer Queue). The UDC transmits the log data to the USB host controller (i.e. USB Host Controller) on the Windows system through the USB device, and then transmits the log data to the user space for user viewing, analysis or processing of the log data.

[0098] Suppose that the "ttyGS0" port (i.e. USB virtual serial port device) is the Log data channel of the application A, then the application A on the Linux system can implement data transmission in the following manner:

[0099] Step 1, allocate corresponding data space;

[0100] Step 2, open the USB virtual serial port device;

[0101] Step 3, execute corresponding original execution logic, which is not described here;

[0102] Step 4, format or prepare Log data;

[0103] Step 5, write the Log data into the USB virtual serial port device;

[0104] Step 6, return to Step 4 until the Log data is written completely;

[0105] Step 7, close the USB virtual serial port device.

[0106] Embodiment Three

[0107] Figure 6 A structural schematic diagram of a data transmission device provided for Embodiment Three of the present application is shown in FIG. 3. As shown, the device includes: Figure 6

[0108] a queue adding module 310 for adding a write queue in a port structure body under a USB serial port logic file, the write queue being used as a memory space for storing user space-transmitted to-be-processed data;

[0109] a first transmission module 320 for moving the user space-transmitted to-be-processed data into the write queue through a first write file function of the USB serial port logic file;

[0110] ​The second transmission module 330 is configured to sequentially transmit the to-be-processed data in the write queue to the UDC through a data sending function of the USB serial port logical file until the to-be-processed data in the write queue is completely transmitted.

[0111] The third embodiment of the present application provides a data transmission device. First, the write queue is added in the port structure under the USB serial port logical file through the queue adding module 310, and the write queue is used as a memory space for storing the to-be-processed data transmitted by the user space. Then, the to-be-processed data transmitted by the user space is moved to the write queue through the first transmission module 320 and the first write file function of the USB serial port logical file. Finally, the to-be-processed data in the write queue is sequentially transmitted to the UDC through the second transmission module 330 and the data sending function of the USB serial port logical file until the to-be-processed data in the write queue is completely transmitted. The device adds the write queue in the port structure under the USB serial port logical file, changes part of the data structure and the data processing flow during transmission, realizes that the user data is first temporarily stored in the write queue and then transmitted to the sending queue of the UDC, and realizes that the two redundant memory copies and the large memory buffer are removed, thereby reducing the occupation of the memory by the Linux kernel and improving the efficiency of data transmission.

[0112] Optionally, the device further comprises:

[0113] The deleting module is configured to delete the first memory copy information under the USB serial port logical file, so that the to-be-processed data transmitted by the user space is transmitted to the write queue.

[0114] Optionally, the device further comprises:

[0115] The identification adding module is configured to add a preset identification in a serial port calling function of the USB serial port logical file before adding the write queue in the port structure under the USB serial port logical file, and the preset identification is used to indicate the USB virtual serial port.

[0116] Optionally, the device further comprises:

[0117] The changing module is configured to change the second write file function according to the preset identification under the input-output function implementation file, and the changed second write file function is used to indicate that the second memory copy information under the input-output function implementation file is skipped when the to-be-processed data is transmitted through the USB virtual serial port.

[0118] Optionally, the first transmission module 320 specifically comprises:

[0119] The structure obtaining unit is configured to obtain a USB request structure from a preset write space, the USB request structure being a minimum data unit of cached data;

[0120] The copying unit is configured to copy the to-be-processed data transmitted by the user space into the USB request structure;

[0121] The moving unit is configured to move the USB request structure containing the to-be-processed data from the preset write space to the write queue;

[0122] The executing unit is configured to repeatedly perform the operation of obtaining a USB request structure from the preset write space until the to-be-processed data transmitted by the user space is completely transmitted, wherein the USB request structure obtained each time is different.

[0123] Optionally, the copying unit is specifically configured to:

[0124] copy the to-be-processed data transmitted by the user space into a data buffer of the USB request structure through a copy function.

[0125] Optionally, the apparatus further comprises:

[0126] The moving module is configured to move the USB request structure in the write queue back to the preset write space after the USB request structure in the write queue is completely transmitted.

[0127] The data transmission apparatus provided by the embodiment of the present application can execute the data transmission method provided by any embodiment of the present application, and has the corresponding function modules and beneficial effects of the execution method.

[0128] Embodiment Four

[0129] Figure 7 A structural schematic diagram of an electronic device is provided for embodiment four of the present application. The electronic device is intended to represent various forms of digital computers, such as laptops, desktops, tablets, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular telephones, smart phones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not intended to limit the implementations of the present application described and / or claimed in this document.

[0130] As Figure 7As shown, the electronic device 10 includes at least one processor 11, and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., connected to the at least one processor 11 in communication. The memory stores computer programs executable by the at least one processor 11, and the processor 11 can perform various appropriate actions and processes according to the computer programs stored in the read-only memory (ROM) 12 or loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0131] Various components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc., an output unit 17, such as various types of displays, a speaker, etc., a storage unit 18, such as a magnetic disk, an optical disk, etc., and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks.

[0132] The processor 11 can be various general and / or special-purpose processing components having processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs various methods and processes described above, such as the data transmission method.

[0133] In some embodiments, the data transmission method can be implemented as a computer program tangibly embodied in a computer readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded onto the RAM 13 and executed by the processor 11, one or more steps of the data transmission method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform the data transmission method by any other appropriate means, such as by means of firmware.

[0134] The various embodiments of the systems and techniques described above can be implemented in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a load programmable logic device (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.

[0135] Computer programs used to implement the processes of the application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer program, when executed, can cause instructions defined in the flow charts and / or block diagrams to be implemented. The computer program can be executed entirely on a machine, partially on a machine, partially on a machine as a standalone software package and partially on a remote machine or entirely on a remote machine or server.

[0136] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store computer programs for use by or in connection with an instruction execution system, apparatus, or device. Computer-readable storage media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of the machine-readable storage medium will include one or more lines of electrical connections, portable computer disks, hard disk drives, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), optical fibers, portable compact disc read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0137] To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.

[0138] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0139] The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. A server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system, to solve the defects of large management difficulty and weak business scalability in traditional physical host and VPS service.

[0140] It should be understood that the various forms of flow shown above can be re-ordered, added to, or deleted from without departing from the scope of the present disclosure. For example, the steps recited in the present disclosure can be executed in parallel, executed in sequence, or executed in a different order, as long as the desired results of the present disclosure are achieved, and the present disclosure is not limited herein.

[0141] The specific embodiments described above are not intended to be limiting, and persons skilled in the art will appreciate that various modifications, combinations, sub-combinations and alternatives can be made to the specific embodiments without departing from the spirit and principles of the disclosure. Accordingly, the disclosure is not limited to the specific embodiments described above, but only by the scope of the appended claims.

Claims

1. A data transmission method, characterized by, The method comprises: adding a write queue in a port structure under a universal serial bus (USB) serial port logic file, the write queue being used as a memory space for storing to-be-processed data transmitted by a user space; wherein the USB serial port logic file is a file used for indicating running logic related to a USB virtual serial port; moving to-be-processed data transmitted by the user space to the write queue through a first write file function of the USB serial port logic file; before the to-be-processed data transmitted by the user space is moved to the write queue, the method further comprises: skipping second memory copy information under an input / output function implementation file, and deleting first memory copy information under the USB serial port logic file, so that the to-be-processed data transmitted by the user space is transmitted to the write queue; wherein the memory copy information is logic code information associated with memory copy; transmitting to-be-processed data in the write queue to a USB device controller (UDC) through a data sending function of the USB serial port logic file, until the to-be-processed data in the write queue is completely transmitted.

2. The method of claim 1, wherein, before the write queue is added in the port structure under the USB serial port logic file, the method further comprises: adding a preset identifier in a serial port calling function of the USB serial port logic file, the preset identifier being used for indicating the USB virtual serial port.

3. The method of claim 2, wherein, The method further comprises: under the input / output function implementation file, changing a second write file function according to the preset identifier, the changed second write file function being used for indicating that the second memory copy information under the input / output function implementation file is skipped when the to-be-processed data is transmitted through the USB virtual serial port.

4. The method of claim 1, wherein, The moving of the to-be-processed data transmitted by the user space to the write queue comprises: obtaining a USB request structure from a preset write space, the USB request structure being a smallest data unit for buffering data; copying the to-be-processed data transmitted by the user space to the USB request structure; moving the USB request structure containing the to-be-processed data from the preset write space to the write queue; and returning to the operation of obtaining a USB request structure from the preset write space, until the to-be-processed data of the user space is completely transmitted, wherein the USB request structure obtained each time is different.

5. The method of claim 4, wherein, The copying of the to-be-processed data transmitted by the user space to the USB request structure comprises: copying the to-be-processed data transmitted by the user space to a data buffer of the USB request structure through a copy function.

6. The method of claim 4, wherein, The method further comprises: after the USB request structure in the write queue is completely transmitted, moving the USB request structure in the write queue back to the preset write space.

7. A data transmission apparatus, characterized by comprising: The device comprises: a queue adding module, configured to add a write queue in a port structure under a universal serial bus (USB) serial port logic file, the write queue being used as a memory space for storing to-be-processed data transmitted by a user space; wherein the USB serial port logic file is a file used for indicating running logic related to a USB virtual serial port; The first transmission module is configured to move the user space transmission data to be processed into the write queue by a first write file function of the USB serial port logic file; Before moving the user space transmission data to be processed into the write queue, the method further comprises: skipping second memory copy information under an input / output function implementation file, and deleting first memory copy information under the USB serial port logic file, so that the user space transmission data to be processed is transmitted to the write queue; wherein the memory copy information is logical code information associated with memory copy; The second transmission module is configured to sequentially transmit the data to be processed in the write queue to a USB device controller (UDC) by a data sending function of the USB serial port logic file until the data to be processed in the write queue is completely transmitted.

8. An electronic device, comprising: The electronic device comprises: at least one processor; and a memory connected to the at least one processor in communication; wherein The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the data transmission method of any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions for enabling the processor to implement the data transmission method of any one of claims 1-6 when executed.

Citation Information

Patent Citations

  • Method for intercepting and capturing serial port information under Linux system

    CN112948311A

  • Data transmission processing method and device

    CN113656334A