Data transmission method and related device
Patent Information
- Application Number
- CN202380058585.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-05
- Publication Date
- 2025-03-25
AI Technical Summary
In communication devices, the multi-threaded parallel processing of sending and receiving messages will cause a large additional delay when the amount of data is small, and cannot meet the user's delay requirements for data transmission of small amounts of data.
In the communication device, when the amount of data is small, a single thread is used for message encapsulation and pre-sending processing to avoid scheduling other threads to participate, reducing thread scheduling time, thereby reducing message transmission delay. Specific methods include adding a mark to the message to indicate the amount of data, and deciding whether to process it individually based on the mark. When the amount of data is greater than the preset value, multi-thread collaborative processing is used.
It effectively reduces the transmission delay of small data packets, especially on smartphones, tablets and other devices. The delay can be reduced by more than 30%, improving data transmission efficiency.
Smart Images

Figure CN119698595A_ABST
Abstract
Description
A data transmission method and related device Technical Field
[0001] The present application relates to the field of computer network technology, and in particular to a data transmission method and related devices. Background Art
[0002] In the field of network communications, with the advancement of hardware technology, more and more communication devices are equipped with multiple processors, such as smartphones with multi-core processors. To fully utilize the hardware capabilities of multiple processors in communication devices and achieve high throughput, communication devices typically break down the entire transmission and reception process into several steps. Multiple processors are used to implement parallel execution of multiple threads, with each thread responsible for handling a specific step in the transmission and reception process. This allows for multi-threaded parallel processing on communication devices with multiple processors, improving message throughput.
[0003] In most scenarios, using multi-threaded parallel processing of message sending and receiving processes can effectively improve message throughput and minimize message sending and receiving latency. However, in some scenarios, if the amount of data exchanged between communication devices via messages is relatively small, using multi-threaded parallel processing of message sending and receiving processes can result in significant additional message latency, leading to relatively long message sending and receiving latency.
[0004] Therefore, there is an urgent need for a method that can reduce the delay in sending and receiving messages.
[0005] Summary of the Invention
[0006] The present application provides a data transmission method that can effectively reduce the delay in sending and receiving messages when transmitting messages with a low data volume.
[0007] In a first aspect, the present application provides a data transmission method, applied to a first communication device serving as a data transmitter. The method includes: a first thread in the first communication device obtains first data to be transmitted, where the data volume of the first data is no greater than a preset data volume. The first thread may be a thread in the first communication device responsible for message encapsulation, such as an application thread.
[0008] Then, the first thread encapsulates the first data and performs pre-message processing on the encapsulated message to obtain a first message. The pre-message processing is used to ensure that the first message meets the message sending requirements. That is, the first thread independently completes the message sending process for the first data without scheduling other threads to collaboratively execute the message sending process.
[0009] Next, the first thread transmits the first message to the network card, and the network card is used to send the first message to the second communication device.
[0010] In this solution, when a communication device needs to transmit relatively small amounts of data, a single thread performs message encapsulation and pre-transmission processing on the data. This avoids the need to schedule additional threads to participate in the message transmission process, reduces thread scheduling time, and thus reduces message transmission latency. In particular, when this data transmission method is applied to mobile devices such as smartphones, tablets, or laptops, the transmission latency of small messages can be reduced by over 30%.
[0011] In a possible implementation, the first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than a preset data volume.
[0012] In this solution, the communication device at the sending end can indicate the amount of data corresponding to the current message to the communication device at the receiving end by adding a first mark in the message, thereby enabling the communication device at the receiving end to reduce thread scheduling when processing the received message, reduce thread scheduling time, and thus reduce the transmission delay of the message.
[0013] In one possible implementation, the first marker is located in a reserved field or an extended field in a message header of the first message. For example, when the value of the field used to indicate the first marker is 1, it indicates that the message includes the first marker; when the value of the field used to indicate the first marker is 0, it indicates that the message does not include the first marker.
[0014] In one possible implementation, the preset data amount is related to the maximum length of the first message. The larger the maximum length of the first message, the larger the preset data amount; and the smaller the maximum length of the first message, the smaller the preset data amount.
[0015] In a possible implementation, the message pre-sending processing includes one or more of the following processes: performing flow control processing on the first message, and modifying the message header of the first message based on the network transmission protocol adopted by the network card.
[0016] In one possible implementation, the method further includes: the first thread obtains second data to be transmitted, and the data volume of the second data is greater than a preset data volume; the first thread encapsulates the second data to obtain a second message; the first thread transmits the second message to the second thread, and the second thread is used to perform pre-message processing on the second message.
[0017] In this solution, when the amount of data to be transmitted is large, the communication device coordinates the transmission of the data by scheduling multiple threads, thereby effectively improving the throughput of the message and enhancing the flexibility of the solution.
[0018] In a possible implementation, the first thread is an application thread, and the second thread is a soft interrupt thread or a driver thread.
[0019] A second aspect of the present application provides a data transmission method, applied to a first communication device serving as a message receiving end. The method comprises: a first thread in the first communication device obtains a first message from a second communication device, wherein the amount of first data corresponding to the first message is no greater than a preset amount of data, and the first data is valid data transmitted from the second communication device to the first communication device; the first thread decapsulates the first message to obtain a payload in the first message; and the first thread transmits the payload to a second thread, wherein the second thread is the destination thread for the payload.
[0020] In this solution, when the communication device transmits less data, a single thread performs message decapsulation processing on the data, avoiding scheduling more threads to participate in the message sending process, reducing thread scheduling time, and thus reducing message transmission delay.
[0021] In a possible implementation, the first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than a preset data volume.
[0022] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0023] In a possible implementation, the preset data volume is related to the maximum length of the first message.
[0024] In one possible implementation, the method also includes: the first thread obtains a second message from the second communication device, the data volume of the second data corresponding to the second message is greater than the preset data volume, and the second data is valid data transmitted by the second communication device to the first communication device; the first thread decapsulates part of the message header in the second message to obtain a third message; the first thread transmits the third message to the third thread, and the third thread is used to decapsulate the message header in the third message and transmit the decapsulated payload to the second thread.
[0025] In a possible implementation, the first thread is a driver thread, and the second thread is an application thread.
[0026] A third aspect of the present application provides a communication device, which is a first communication device, including: an acquisition module, used to enable a first thread to acquire first data to be transmitted, and the data volume of the first data is not greater than a preset data volume; a processing module, used to enable the first thread to encapsulate the first data and perform pre-message processing on the encapsulated message to obtain a first message, and the pre-message processing is used to enable the first message to meet the message sending requirements; the processing module is also used to enable the first thread to transmit the first message to a network card, and the network card is used to send the first message to a second communication device.
[0027] In a possible implementation, the first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than a preset data volume.
[0028] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0029] In a possible implementation, the preset data volume is related to the maximum length of the first message.
[0030] In a possible implementation, the message pre-sending processing includes one or more of the following processes: performing flow control processing on the first message, and modifying the message header of the first message based on the network transmission protocol adopted by the network card.
[0031] In a possible implementation, the acquisition module is further configured to enable the first thread to acquire second data to be transmitted, where the amount of the second data is greater than a preset amount of data;
[0032] The processing module is further configured to cause the first thread to encapsulate the second data to obtain a second message;
[0033] The processing module is further configured to enable the first thread to transmit the second message to the second thread, and the second thread is configured to perform pre-message processing on the second message.
[0034] In a possible implementation, the first thread is an application thread, and the second thread is a soft interrupt thread or a driver thread.
[0035] The fourth aspect of the present application provides a communication device, which is a first communication device, including: an acquisition module, used to enable a first thread to acquire a first message from a second communication device, the data volume of first data corresponding to the first message is not greater than a preset data volume, and the first data is valid data transmitted from the second communication device to the first communication device; a processing module, used to enable the first thread to decapsulate the first message to obtain a valid payload in the first message; the processing module is also used to enable the first thread to transfer the valid payload to the second thread, and the second thread is the destination thread of the valid payload.
[0036] In a possible implementation, the first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than a preset data volume.
[0037] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0038] In a possible implementation, the preset data volume is related to the maximum length of the first message.
[0039] In one possible implementation, the acquisition module is further configured to enable the first thread to acquire a second message from the second communication device, where the amount of second data corresponding to the second message is greater than a preset amount of data, and the second data is valid data transmitted by the second communication device to the first communication device;
[0040] The processing module is further configured to cause the first thread to decapsulate part of the message header in the second message to obtain a third message;
[0041] The processing module is further configured to enable the first thread to transmit the third message to the third thread, and the third thread is configured to decapsulate the message header in the third message and transmit the decapsulated payload to the second thread.
[0042] In a possible implementation, the first thread is a driver thread, and the second thread is an application thread.
[0043] In a fifth aspect, the present application provides a communication device comprising: a memory and a processor; the memory stores code, and the processor is configured to execute the code. When the code is executed, the communication device executes a method as implemented in any one of the first and second aspects.
[0044] In a sixth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer-readable storage medium is run on a computer, the computer executes a method as implemented in any one of the first and second aspects.
[0045] In a seventh aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute a method as implemented in any one of the first and second aspects.
[0046] In an eighth aspect, the present application provides a chip comprising one or more processors, wherein some or all of the processors are configured to read and execute a computer program stored in a memory to perform the method in any one of the implementations of the first or second aspects.
[0047] Optionally, the chip includes a memory, and the memory is connected to the processor via a circuit or wire. Optionally, the chip also includes a communication interface, and the processor is connected to the communication interface. The communication interface is used to receive data and / or information to be processed, and the processor obtains the data and / or information from the communication interface, processes the data and / or information, and outputs the processing results through the communication interface. The communication interface can be an input / output interface. The method provided in this application can be implemented by a single chip or by multiple chips working together.
[0048] Among them, the technical effects brought about by any design method in the second to eighth aspects can refer to the technical effects brought about by different implementation methods in the above-mentioned first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] FIG1 is a schematic diagram of a scenario of interaction between a smart phone and a personal computer provided in an embodiment of the present application;
[0050] FIG2 is a schematic diagram of a process of multi-threaded message processing in the related art;
[0051] FIG3 is a schematic diagram of a message sending and receiving process in the related art;
[0052] FIG4 is a schematic diagram of a message sending time consumption according to an embodiment of the present application;
[0053] FIG5 is a schematic diagram of a message sending process using multiple threads to collaboratively process a message according to an embodiment of the present application;
[0054] FIG6 is a schematic structural diagram of a communication device 101 provided in an embodiment of the present application;
[0055] FIG7 is a flow chart of a data transmission method provided in an embodiment of the present application;
[0056] FIG8A is a schematic diagram of a message format provided in an embodiment of the present application;
[0057] FIG8B is a schematic diagram of another message format provided in an embodiment of the present application;
[0058] FIG9 is a schematic flow chart of another data transmission method provided in an embodiment of the present application;
[0059] FIG10 is a schematic diagram of a process for performing data transmission between communication devices through threads according to an embodiment of the present application;
[0060] FIG11 is a schematic diagram of a process of executing message sending by a communication device as a sending end through a thread provided in an embodiment of the present application;
[0061] FIG12 is a schematic diagram of a flow chart of a communication device as a receiving end performing message reception through a thread according to an embodiment of the present application;
[0062] FIG13 is a schematic structural diagram of a communication device provided in an embodiment of the present application;
[0063] FIG14 is a schematic structural diagram of a communication device provided in an embodiment of the present application;
[0064] FIG15 is a schematic diagram of a structure of an execution device provided in an embodiment of the present application;
[0065] FIG16 is a schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION
[0066] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments.
[0067] The terms "first," "second," "third," "fourth," and the like (if any) in the specification and claims of this application and in the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or sequential sequence. It should be understood that the terms used in this manner are interchangeable where appropriate so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having," and any variations thereof, are intended to cover non-exclusive inclusions, e.g., a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0068] To facilitate understanding, some technical terms involved in the embodiments of this application are first introduced below.
[0069] (1) Open System Interconnection Reference Model (OSI model)
[0070] The OSI model is a conceptual model proposed by the International Organization for Standardization. It is essentially a standard framework designed to interconnect various computers worldwide into a network. The OSI divides computer network architecture into seven layers: physical layer, data link layer, network layer, transport layer, session layer, presentation layer, and application layer. The functions of these seven layers are described below.
[0071] Physical layer: Converts data into electronic signals that can be transmitted through physical media, equivalent to the porters in the post office.
[0072] Data Link Layer: Determines how the network medium is accessed. Data is typically framed and flow control is handled at the Data Link Layer. The Data Link Layer specifies the topology and provides hardware addressing, similar to the post office's box loader.
[0073] Network layer: Routes data through large networks, acting like a sorting worker in a post office.
[0074] Transport layer: provides reliable end-to-end connections, equivalent to the postman in the company.
[0075] Session layer: allows users to establish connections using simple and easy-to-remember names, which is equivalent to a secretary in a company who receives and sends letters, writes envelopes, and opens envelopes.
[0076] Presentation layer: negotiates data exchange formats, equivalent to the assistant who briefs the boss and writes letters for the boss in the company.
[0077] Application layer: The interface between the user's application and the network.
[0078] (2) Transmission Control Protocol (TCP)
[0079] TCP is a connection-oriented, reliable, byte-stream-based transport layer communication protocol. Specifically, TCP is a transmission protocol designed to provide reliable end-to-end byte streams over unreliable internet networks.
[0080] (3) Internet Protocol (IP)
[0081] IP is the network layer protocol in the TCP / IP architecture. Its purpose is to improve network scalability: first, to solve Internet problems and enable interconnection among large-scale, heterogeneous networks; second, to decouple top-level network applications from underlying network technologies, facilitating their independent development. Based on end-to-end design principles, IP provides only a connectionless, unreliable, best-effort data packet transmission service for hosts.
[0082] (4) TCP / IP protocol suite
[0083] The TCP / IP protocol suite is essentially a collection of protocols, including TCP at the transport layer and IP at the network layer. Each protocol in the TCP / IP protocol suite is responsible for a specific part of network data transmission, providing a specific service for data transmission within the network.
[0084] The TCP / IP protocol suite was developed based on the OSI model, and the layered structure defined by the TCP / IP protocol suite differs from the OSI model. Specifically, the layered structure defined by the TCP / IP protocol suite includes the application layer, transport layer, network layer, data link layer, and physical layer. The application layer defined by the TCP / IP protocol suite is equivalent to unifying the application layer, presentation layer, and session layer in the OSI model into a single application layer, thereby more closely integrating functions such as data format representation and session establishment with application software.
[0085] (5) User Datagram Protocol (UDP)
[0086] UDP is a connectionless transport layer protocol in the OSI model, providing simple, transaction-oriented, unreliable information delivery services. Like TCP, UDP handles data packets. In the OSI model, both reside in the transport layer, above the network layer. UDP has the disadvantage of not providing packet grouping, reassembly, or sequencing. This means that once a message is sent, it is impossible to determine whether it has arrived safely and intact. UDP is used to support network applications that require data transmission between computers. Many client / server network applications, including online video conferencing systems, rely on UDP. Currently, many applications, such as multimedia data streams, exclusively support UDP, generating no additional data and refusing to retransmit known corrupted packets. UDP is the best choice when transmission performance is prioritized over integrity, such as in audio and multimedia applications. UDP is also a good choice when data transmission is so short that the preceding connection process constitutes the bulk of the traffic.
[0087] (6) Message
[0088] A message is a unit of data exchanged and transmitted on a network, a block of data that a station sends at one time. A message contains the complete data to be sent and can be of variable length. A message typically consists of a header and a payload.
[0089] (7) Message Header
[0090] The message header is usually also referred to as the message header. It refers to some information segments encapsulated in the head of the message to indicate some information required for the message during transmission.
[0091] (8) Payload
[0092] The payload is a part of a message, usually located at the end of the message, and is used to carry valid data that actually needs to be exchanged between communication devices.
[0093] (9) Media Access Control (MAC) address
[0094] Each device on the network has a unique network identifier, which is usually called a MAC address or network card address and is written inside the hardware when the network device manufacturer produces it.
[0095] (10) Network card
[0096] A network card is a piece of hardware designed to allow devices to communicate over a communications network. Each network card has a unique 48-bit serial number called a MAC address, which is stored in a memory area on the card. Because of its MAC address, a network card falls between Layers 1 and 2 of the OSI model. Network cards enable users to connect to each other via cables or wirelessly.
[0097] (11) Maximum Transmission Unit (MTU)
[0098] MTU generally refers to the maximum length of a message, typically expressed in bytes. It is used to inform the other party of the maximum size of a data unit that can be accepted, indicating the payload size that the sender can accept. Specifically, Ethernet has a limit on message length, and its MTU is generally 1500 bytes. Most message lengths of different types of networks have an upper limit. If a communication device has a data packet to transmit, and the packet length is larger than the MTU, the communication device needs to perform fragmentation, that is, to divide the data packet into pieces so that each piece of data is no larger than the MTU.
[0099] (12) User mode
[0100] In central processing unit (CPU) design, user mode refers to a non-privileged state, a CPU operating state. In this state, the executed code is hardware-restricted and cannot perform certain operations, such as writing to the storage space of other processes, to prevent security risks to the operating system. Similarly, in operating system design, user mode refers to a non-privileged execution state. The kernel prohibits code in this state from performing potentially dangerous operations, such as writing to system configuration files, killing other users' processes, and restarting the system.
[0101] (13) Kernel state
[0102] Kernel state refers to a privileged state, as opposed to user state, and is also a CPU operating state. Generally speaking, when a thread is executing its own code, it is said to be in user state. When a thread executes a system call and falls into kernel code, it is said to be in kernel state. At this time, the CPU is executing in kernel code at the highest privilege level.
[0103] Simply put, when a thread runs in kernel space, it is in kernel state, and when a thread runs in user space, it is in user state.
[0104] In kernel mode, threads run in the kernel address space, and the CPU can execute any instruction. The running code is not restricted and can freely access any valid address and directly access ports.
[0105] In user mode, threads run in the user address space, and the executed code is subject to many checks by the CPU. They can only access the virtual addresses of the pages accessible in user mode as specified in the page table entries that map their address space, and can only directly access the specified accessible ports.
[0106] (14)Hard interrupt
[0107] A hard interrupt is an electrical signal generated by hardware. When a device experiences an event, it generates an interrupt and sends the signal to the interrupt controller via the bus. Hard interrupts are generated by hardware such as disks, network cards, keyboards, and clocks. Each device or set of devices generates its own interrupt request. Based on the interrupt request generated by the device, the CPU can dispatch the request to the corresponding hardware driver.
[0108] In a computer system, when the CPU is running a program normally, due to the program's pre-arrangement or internal and external events, the CPU interrupts the running program and switches to the program that serves the pre-arranged event or internal and external events. This is commonly called an interrupt.
[0109] (15)Soft interrupt
[0110] Soft interrupts leverage the concept of hardware interrupts, simulating them in software to achieve a macroscopic effect of asynchronous execution. In many cases, soft interrupts are similar to signals. They also correspond to hard interrupts. A hard interrupt is an interrupt to the CPU from an external device, while a soft interrupt is typically an interrupt to the kernel from the hard interrupt service routine.
[0111] (16)Thread
[0112] A thread is the smallest unit of computation that an operating system can schedule. It is contained within a process and is the actual unit of operation within that process. A thread is a single, sequential flow of control within a process. A process can have multiple threads running concurrently, each executing different tasks in parallel.
[0113] Currently, to fully utilize the hardware capabilities of multiple processors in communication devices and achieve high throughput, communication devices typically break down the entire message transmission and reception process into several steps. Multiple processors are then used to implement parallel execution of multiple threads, with each thread responsible for handling a specific step in the transmission and reception process. This allows for multi-threaded parallel processing in communication devices with multiple processors, improving message throughput.
[0114] In most communication scenarios, the amount of data exchanged between communication devices is large. By using multi-threaded parallel processing of message sending and receiving, the message throughput can be effectively improved and the overall message sending and receiving delay can be reduced. However, in some communication scenarios, when the amount of data exchanged between communication devices through messages is small, using multi-threaded parallel processing of message sending and receiving processes will result in a large additional message delay, which in turn makes the message sending and receiving delay relatively large. In addition, when these communication devices exchange small amounts of data through messages, they often have high requirements for the message sending and receiving delay. Therefore, when communication devices exchange small amounts of data, the current way of processing the message sending and receiving process by communication devices often cannot meet user needs.
[0115] For example, please refer to Figure 1, which is a schematic diagram of a scenario of interaction between a smartphone and a personal computer provided in an embodiment of the present application. As shown in Figure 1, taking the collaboration between a smartphone and a personal computer (PC) as an example, when a user is working, he needs to work on the PC and process messages or calls received from time to time on the smartphone. In this scenario, the user can often map the smartphone screen to the PC, operate the smartphone with a mouse on the PC, and click on the interface on the mapped smartphone on the PC with the mouse, just like operating the smartphone directly with his fingers, without having to pay attention to the smartphone all the time.
[0116] When a user operates a smartphone with a mouse on a PC, the PC treats the operations performed on the smartphone as control data and encapsulates this control data into a message and sends it to the smartphone. In this way, the smartphone can perform the corresponding operations according to the control data carried in the message, refresh the phone interface according to the operations, and then send the refreshed interface content to the PC. In this scenario, the control data sent by the PC to the smartphone is very small, and the user hopes that the delay in transmitting the control data from the PC to the smartphone is low to avoid noticeable sluggishness when operating the smartphone on the PC.
[0117] However, the applicant has found that when related technologies use multi-threaded parallel processing to process the sending and receiving of messages, additional delays are often caused due to the interaction between threads, resulting in a high delay in the communication device even when the amount of interactive data is low.
[0118] For ease of understanding, the following details the reasons why the communication device still has a high delay when exchanging data with a low amount of data due to the use of multi-threaded parallel processing of message receiving and sending processes in related technologies.
[0119] Please refer to FIG. 2 and FIG. 3 . FIG. 2 is a flow chart of multi-thread message processing in the related art; FIG. 3 is a flow chart of message sending and receiving in the related art.
[0120] As shown in Figure 2, communication device 1 is the message transmitter, and communication device 2 is the message receiver. When communication device 1 sends data to communication device 2, the data to be sent by communication device 1 is processed sequentially by three threads within communication device 1: application thread 1, softirq thread 1, and driver thread 1. The resulting message is then sent by network card 1 within communication device 1 to communication device 2.
[0121] After the network card 2 in the communication device 2 receives the message sent by the communication device 1, it passes the message to the hard interrupt thread, driver thread 2, soft interrupt thread 2 and application thread 2 for processing in sequence, so that the application thread 2 can finally obtain the data sent by the communication device 1.
[0122] As shown in FIG3 , the working process of each thread in the communication device 1 and the communication device 2 is described below.
[0123] Application thread 1 in communication device 1: In user mode, application thread 1 calls the message sending function (i.e., send()). Application thread 1 then enters kernel mode and performs message encapsulation at the transport, network, and link layers on the data to be transmitted, thereby encapsulating the data into a message. After encapsulation, the message is added to the kernel protocol stack's send queue.
[0124] Soft interrupt thread 1 in communication device 1: The soft interrupt thread takes out a message from the sending queue of the protocol stack, performs corresponding flow control processing on the message, and then adds the message to the sending queue of the driver.
[0125] Driver thread 1 in communication device 1: takes out a message from the driver's sending queue, re-encapsulates the link layer header of the message (for example, re-encapsulates it based on the 802.11 protocol of WiFi), and then sends it to the network card for physical transmission.
[0126] Network card 1 in communication device 1: After receiving the message from driver thread 1, it sends the message to network card 2 in communication device 2 via wired or wireless means.
[0127] Network card 2 in communication device 2: After receiving the message from network card 1 in communication device 1, it sends an interrupt request to the hard interrupt thread to request the hard interrupt thread to process the message.
[0128] The hard interrupt thread in the communication device 2 processes the interrupt request triggered by the network card and puts the message received by the network card 2 into the driver's receiving queue.
[0129] Driver thread 2 in communication device 2: takes the message from the driver receive queue, parses the link layer message header, and then puts the message into the protocol stack receive queue.
[0130] Soft interrupt thread 2 in communication device 2: takes out the message from the protocol stack receive queue, parses the network layer message header and the transport layer message header, obtains the data in the message payload, and then puts the data into the receive queue of application thread 2.
[0131] Application thread 2 in communication device 2: copies data from the receive queue to the user-mode buffer.
[0132] In general, the solution of the related art is a fixed thread model, and the sending and receiving of messages requires the collaboration of multiple threads. In other words, whether the data actually needed to be sent by the application is a large batch of data (such as a 100-megabyte (MByte, MB) file) or a small batch of data (such as a 100-byte control message), the process is the same. However, such a multi-threaded collaborative processing process fully utilizes the multi-core pipeline operation mode, which can prevent the processor from becoming a bottleneck and achieve high throughput, but it also incurs a large additional delay when sending small messages. Please refer to the analysis below for details.
[0133] For example, please refer to Figure 4, which is a schematic diagram of the time consumption for sending a message provided in an embodiment of the present application. As shown in Figure 4, it is assumed that it takes 16 time units to send a message using a single-threaded mode. Among them, the length of the line segment in Figure 4 represents time, each grid represents a time unit, it takes 16 time units to send a message, and it takes 16*4=64 time units to send 4 messages continuously. If the process of sending a message is divided into 4 stages, each stage corresponds to 4 time units, then the stages 1 to 4 shown in Figure 4 can be obtained.
[0134] For example, please refer to Figure 5, which is a schematic diagram of an embodiment of the present application that uses multiple threads to collaboratively process the message sending process. As shown in Figure 5, in Figure 5, four threads are used to concurrently process the message sending process, each thread processes one stage, and thread scheduling takes 2 time units.
[0135] When sending the first message, the first thread processes it for 4 time units and then hands it over to the second thread for processing, which consumes 2 units of thread scheduling time. Similarly, when the last thread, that is, thread 4, finishes processing the first message, the total time consumed is: 4+2+4+2+4+2+4=22 (time units).
[0136] After the first message, each additional message processed only consumes 4 more time units. If a total of 4 messages are sent, the total time consumption is: 22+(4-1)*3=34 (time units).
[0137] From the above analysis, it can be seen that the comparison of using a single-thread model and a four-thread model to execute message sending is shown in Table 1 below.
[0138] Table 1
[0139] Time consumption under different thread models: Sending 1 message Sending 4 messages Single thread model 16 (excellent) 644 Thread model 2234 (excellent)
[0140] Obviously, the multi-thread model takes less time to send a large number of messages, while the single-thread model takes less time to send a small number of messages. The fixed multi-thread model used in the related art takes a long time to send a small number of messages.
[0141] Furthermore, the above example assumes that thread scheduling takes 2 time units, which is a 1:8 ratio compared to the 16 time units consumed by sending a message. In reality, on terminal devices such as smartphones and tablets, many processor cores are often dormant to reduce power consumption. Because a processor core can only run one thread at a time, thread scheduling often requires waking up dormant cores to achieve multi-threaded collaboration, which consumes more time. In some cases, the time consumed by a single thread scheduling operation may even exceed the total time required to process a message (corresponding to the 16 time units mentioned above).
[0142] In light of this, embodiments of the present application provide a data transmission method. When a communication device has a small amount of data to transmit, a single thread performs message encapsulation and pre-transmission processing on the data. This avoids scheduling additional threads to participate in the message transmission process, reduces thread scheduling time, and thus reduces message transmission latency. In particular, when this data transmission method is applied to mobile devices such as smartphones, tablets, or laptops, the transmission latency of small data packets can be reduced by more than 30%.
[0143] The data transmission method provided in the embodiments of the present application can be applied to a communication device. For example, the communication device can be a server, a mobile phone, a personal computer (PC), a laptop, a tablet computer, a smart TV, a mobile internet device (MID), a wearable device, a virtual reality (VR) device, an augmented reality (AR) device, a wireless communication device in industrial control, a wireless communication device in self-driving, a wireless communication device in remote medical surgery, a wireless communication device in a smart grid, a wireless communication device in transportation safety, a wireless communication device in a smart city, a wireless communication device in a smart home, a router, a switch, a firewall, a hub, etc.
[0144] Please refer to Figure 6, which is a schematic diagram of the structure of a communication device 101 provided in an embodiment of the present application. As shown in Figure 6, the communication device 101 includes a processor 103, which is coupled to a system bus 105. The processor 103 can be one or more processors, each of which can include one or more processor cores. A display adapter (video adapter) 107 can drive a display 109, which is coupled to the system bus 105. The system bus 105 is coupled to an input / output (I / O) bus via a bus bridge 111. An I / O interface 115 is coupled to the I / O bus. The I / O interface 115 communicates with various I / O devices, such as an input device 117 (e.g., a touch screen), an external memory 121 (e.g., a hard disk, floppy disk, optical disk, or USB flash drive), a multimedia interface, etc., a transceiver 123 (capable of sending and / or receiving radio communication signals), a camera 155 (capable of capturing still and dynamic digital video images), and an external USB port 125. Optionally, the interface connected to the I / O interface 115 may be a USB interface.
[0145] The processor 103 may be any conventional processor, including a reduced instruction set computing (RISC) processor, a complex instruction set computing (CISC) processor, or a combination thereof. Alternatively, the processor may be a dedicated device such as an ASIC.
[0146] Communication device 101 can communicate with software deployment server 149 via network interface 129. Exemplarily, network interface 129 is a hardware network interface, such as a network card. Network 127 can be an external network, such as the Internet, or an internal network, such as Ethernet or a virtual private network (VPN). Alternatively, network 127 can be a wireless network, such as a WiFi network or a cellular network.
[0147] The hard drive interface 131 is coupled to the system bus 105. The hard drive interface is connected to the hard drive 133. The internal memory 135 is coupled to the system bus 105. The data running in the internal memory 135 may include the operating system (OS) 137 of the communication device 101, the application program 143, and the scheduler.
[0148] The operating system consists of a shell 139 and a kernel 141. Shell 139 is an interface between the user and the operating system's kernel. The shell is the outermost layer of the operating system. The shell manages the interaction between the user and the operating system: it waits for user input, interprets user input to the operating system, and processes various operating system output.
[0149] The kernel 141 consists of the parts of the operating system that manage memory, files, peripherals, and system resources. The kernel 141 directly interacts with the hardware. The operating system kernel typically runs processes and provides inter-process communication, CPU time slice management, interrupts, memory management, and I / O management.
[0150] For example, when the communication device 101 is a smart phone, the application 143 includes an instant messaging-related program. In one embodiment, when the application 143 needs to be executed, the communication device 101 can download the application 143 from the software deployment server 149 .
[0151] Please refer to Figure 7, which is a flow chart of a data transmission method provided by an embodiment of the present application. As shown in Figure 7, the data transmission method includes the following steps 701-707.
[0152] Step 701 : Thread A1 in communication device 1 obtains data 1 to be transmitted.
[0153] In this step, thread A1 is the thread responsible for message encapsulation. When communication device 1 needs to send data 1 to communication device 1, thread A1 encapsulates data 1 into a message.
[0154] Exemplarily, thread A1 may be an application thread in communication device 1. This application thread communicates with other application threads in communication device 2 and, in user mode, generates data 1 that needs to be sent to other application threads in communication device 2. For example, thread A1 may be a thread of a social application in communication device 1. Thread A1 obtains user input and converts the user input into data 1 that needs to be sent to the thread of the social application in communication device 2.
[0155] In this way, after thread A1 generates data 1 to be transmitted in user mode, thread A1 calls a system function (such as send() function), and then enters kernel mode, so as to encapsulate data 1 into a message in kernel mode.
[0156] In step 702, based on the fact that the data volume of data 1 is not greater than the preset data volume, thread A1 encapsulates data 1 and performs message pre-sending processing on the encapsulated message to obtain message 1, wherein the message pre-sending processing is used to make message 1 meet the message sending requirements.
[0157] Before executing message encapsulation on Data 1, Thread A1 can obtain the data size of Data 1. For example, when Thread A1 calls a system function to enter kernel mode, Thread A1 enters the data size of Data 1 in the call command. Therefore, Thread A1 can still obtain the data size of Data 1 after entering kernel mode. Thread A1 can then compare the data size of Data 1 with the preset data size. If the data size of Data 1 is not greater than the preset data size, Thread A1 encapsulates Data 1 and performs pre-message processing before sending the message. In other words, Thread A1 independently completes the message sending process for Data 1, without scheduling other threads to cooperate in the message sending process.
[0158] It is understandable that due to the maximum length limit of a message, when the amount of data to be transmitted is large, the data often needs to be divided into multiple data segments, and different messages are used to carry different data segments to achieve data transmission. In other words, the larger the amount of data to be transmitted, the more messages are used to transmit the data; the smaller the amount of data to be transmitted, the fewer messages are used to transmit the data.
[0159] Then, if the amount of data 1 is not greater than the preset amount, and the number of messages used to transmit data 1 is also within the preset range (e.g., 1 or 2), thread 1 can independently execute the message sending process for data 1 to reduce thread scheduling time and lower the transmission latency of data 1.
[0160] Optionally, the preset data volume may be related to the maximum length of message 1. The larger the maximum length of message 1, the larger the preset data volume; the smaller the maximum length of message 1, the smaller the preset data volume.
[0161] Specifically, when the maximum length of message 1 is determined and the protocol used to execute message sending is also determined, the length of the message header in message 1 is fixed, and therefore the maximum length of the effective load in message 1 is also fixed (i.e., the length of the effective load of message 1 is the difference between the maximum length of message 1 and the length of the message header). After the maximum length of the effective load of message 1 is fixed, it means that the amount of effective data that message 1 can carry is fixed. By comparing the amount of data 1 with the maximum length of the effective load of message 1, it can be determined how many messages are needed to carry data 1, that is, the number of messages corresponding to data 1 can be determined.
[0162] As described above, if the time required for each thread to process the message sending process is determined and the thread scheduling time is determined, the latency of executing the message sending process for a fixed number of messages using a single thread or multiple threads can be determined. In other words, based on the amount of data to be transmitted, the number of messages used to carry that data can be determined, and thus the latency required to execute the message sending process using a single thread or multiple threads can be determined. This allows us to determine under what circumstances the data volume will result in a lower latency when processing the data using a single thread than when processing the data using multiple threads.
[0163] In general, the setting principle of the preset data volume can be specifically as follows: when the data volume of the data to be transmitted is not greater than the preset data volume, the delay of the single-thread processing of the data to be transmitted is not higher than the delay of the multi-thread processing of the data to be transmitted; when the data volume of the data to be transmitted is greater than the preset data volume, the delay of the single-thread processing of the data to be transmitted is higher than the delay of the multi-thread processing of the data to be transmitted. For example, when using the TCP protocol to transmit data, the preset data volume can be specifically set to 1460 bytes; when using the UDP protocol to transmit data, the preset data volume can be specifically set to 1472 bytes. That is, when the data volume of the data to be transmitted is greater than the preset data volume, the data to be transmitted needs to be carried by more than one message. In addition, the preset data volume can also be set or adjusted according to the actual application situation. This embodiment does not specifically limit the size of the preset data volume.
[0164] Optionally, the message 1 obtained by thread A1 encapsulating data 1 further includes a first marker, which is used to indicate that the data volume of data 1 corresponding to message 1 is not greater than a preset data volume. In this way, when communication device 2 receives message 1, the thread in communication device 2 can determine, based on the first marker in message 1, that the data volume of the data corresponding to message 1 is not greater than the preset data volume, that is, the number of messages used to carry the data to be transmitted is not large. Therefore, communication device 2 can also reduce the threads used to process the message reception process to reduce the message reception delay.
[0165] The first marker may be a reserved field or an extension field located in the header of message 1. The first marker may be specifically represented by a 1-bit field, and the 1-bit field may be a reserved field or an extension field located in the header of message 1. For example, when the value of the field used to represent the first marker is 1, it indicates that the message includes the first marker; when the value of the field used to represent the first marker is 0, it indicates that the message does not include the first marker.
[0166] For example, please refer to Figure 8A, which is a schematic diagram of the format of a message provided in an embodiment of the present application. As shown in Figure 8A, the message generally includes a payload and multiple message headers, and the multiple message headers specifically include a transport layer header (corresponding to the TCP / UDP protocol), a network layer header (corresponding to the IP protocol) and a data link layer header. In the multiple message headers, reserved fields or extension fields may be included, so the first tag can be set in the reserved field or extension field of any message header. As shown in Figure 8A, the fields in the transport layer header specifically include: version number, header length, source port, destination port, sequence number, confirmation sequence number, total message length and options. Among them, the option field is an extension field, so the first tag can be set in the option field of the transport layer header. In addition, in addition to the fields in the transport layer header, the first tag can also be set in the data link layer header or the network layer header, and this embodiment does not make specific limitations here.
[0167] In addition, please refer to Figure 8B, which is a schematic diagram of another message format provided in an embodiment of the present application. As shown in Figure 8B, in some cases, the message may also include a private protocol header, that is, a header obtained based on a transmission protocol published by a non-standard organization. In this case, the first tag can also be set in a reserved field or an extension field of the private protocol header.
[0168] Specifically, thread A1 encapsulates data 1 as a message: thread A1 sequentially encapsulates the transport layer header, network layer header, and data link layer header before data 1 to obtain an encapsulated message. After obtaining the encapsulated message, thread A1 continues to perform pre-message processing on the encapsulated message to obtain message 1.
[0169] The message pre-sending processing may specifically include one or more of the following processes: performing flow control on message 1, and modifying the message header of message 1 based on the network transmission protocol used by the network card. Furthermore, the message pre-sending processing may also include other processes, which are not specifically limited in this embodiment.
[0170] Specifically, if the user has set a flow control policy, for example, setting the bandwidth for traffic transmission to no more than 1MB / s, the amount of data sent per unit time cannot exceed the set threshold. Therefore, the process of thread A1 performing flow control on message 1 effectively ensures that the transmission of message 1 remains within the limits of the flow control policy. That is, if the amount of message data sent per unit time has reached the threshold set by the flow control policy, the transmission of message 1 is suspended for the current unit time. If the amount of message data sent per unit time has not reached the threshold set by the flow control policy, the transmission of message 1 continues for the current unit time.
[0171] Furthermore, when thread A1 performs message encapsulation on data 1, the data link layer header encapsulated by thread A1 in kernel mode is typically encapsulated based on the format specified by the default communication protocol (e.g., the 802.3 protocol). If the network card in communication device 1 actually transmits message 1 via a wireless network, the network card transmits message 1 in accordance with the 802.11 protocol. Therefore, after obtaining the message based on data 1 encapsulation, it is often necessary to modify the data link layer header in the message to match the transmission protocol followed by the network card.
[0172] For example, when thread A1 encapsulates the data link layer header according to the 802.3 protocol in kernel mode, the data link layer header consists of 14 bytes, including a 6-byte destination MAC address, a 6-byte source MAC address, and a 2-byte protocol type. When the message needs to be sent via wireless Wi-Fi, the data link layer header in the message needs to be converted to the 802.11 protocol format. The 802.11 protocol format header contains 30 bytes of content. For details, please refer to the relevant technology and will not be repeated here.
[0173] Step 703: Thread A1 transmits message 1 to network card A.
[0174] After thread A1 executes the message sending process for data 1 and obtains message 1, thread A1 transmits message 1 to network card A in communication device 1 so that network card A can realize physical transmission of message 1, that is, network card A sends message 1 to communication device 2 via wired or wireless means.
[0175] Step 704 : Network card A sends message 1 to communication device 2 .
[0176] The network card A may send the message 1 to the communication device 2 via a wired cable or wirelessly (such as wifi).
[0177] Step 705 : Thread B1 in communication device 2 obtains message 1 from communication device 1 .
[0178] After network card A of communication device 1 sends message 1 to communication device 2, network card B in communication device 2 can receive message 1 and pass message 1 to the thread in communication device 2 for processing, so thread B1 in communication device 2 can obtain message 1 from communication device 1.
[0179] Exemplarily, the thread B1 in the communication device 2 may be a driving thread, for example.
[0180] Step 706 : Based on the fact that the amount of data 1 corresponding to message 1 is not greater than the preset amount of data, thread B1 decapsulates message 1 to obtain the payload in message 1 .
[0181] If the amount of data 1 corresponding to message 1 is no larger than the preset amount, thread B1 decapsulates message 1 independently, that is, it decapsulates all headers in message 1, without scheduling other threads to collaboratively decapsulate all headers in message 1. In this way, after thread B1 decapsulates all headers in message 1, it can obtain the payload of message 1, that is, the valid data actually carried by message 1.
[0182] Specifically, thread B1 may parse message 1 and determine, based on the first flag included in message 1, that the amount of data 1 corresponding to message 1 is not greater than a preset amount of data.
[0183] Step 707: Thread B1 transmits the payload in message 1 to thread B2, which is the destination thread for the payload.
[0184] After thread B1 completes the decapsulation process of message 1 and obtains the payload in message 1, thread B1 passes the payload to the final destination thread, namely thread B2, thereby completing the data transmission. For example, thread B2 can be an application thread in communication device 2.
[0185] The above introduction is that when the amount of data to be transmitted is not greater than the preset data amount, the communication device as the sending end performs message encapsulation and message pre-sending processing through a single thread, and the communication device as the receiving end performs message decapsulation through a single thread.
[0186] Optionally, in some embodiments, when the amount of data to be transmitted is greater than the preset data amount, the communication device serving as the sending end may collaboratively complete message encapsulation and message pre-sending processing through multiple threads, and the communication device serving as the receiving end may collaboratively complete message decapsulation through multiple threads.
[0187] Please refer to Figure 9, which is a flowchart of another data transmission method provided by an embodiment of the present application. As shown in Figure 9, the data transmission method includes the following steps 901-909.
[0188] Step 901 : Thread A1 in the communication device 1 obtains data 2 to be transmitted.
[0189] Among them, step 901 is similar to the above-mentioned step 701. Please refer to the above-mentioned step 701 for details, and will not be repeated here.
[0190] It should be noted that, in step 701, the amount of data 1 obtained by thread A1 is not greater than the preset amount of data. In this step, the amount of data 2 obtained by thread A1 is greater than the preset amount of data.
[0191] In step 902 , based on the fact that the amount of data 2 is greater than a preset amount of data, thread A1 encapsulates data 2 to obtain an encapsulated message.
[0192] When the data volume of data 2 is greater than the preset data volume, thread A1 only performs message encapsulation on data 2 to obtain an encapsulated message, and no longer performs message pre-sending processing on the encapsulated message.
[0193] Since the amount of data 2 is larger than the preset amount of data, thread A1 does not add the first marker to the message when encapsulating data 2, that is, the message encapsulated by thread A1 does not include the first marker.
[0194] Furthermore, it should be noted that when the amount of data 2 exceeds the preset amount, thread A1, when performing message encapsulation on data 2, often needs to divide data 2 into multiple data slices and sequentially encapsulate each data slice into a different message, thereby transmitting data 1 by sending multiple messages. This embodiment uses a message obtained by thread A1 based on the encapsulation of data 2 as an example for illustration.
[0195] In step 903, thread A1 transmits the encapsulated message to thread A2 in the communication device 1, and thread A2 performs pre-message processing on the encapsulated message.
[0196] The message pre-sending processing may specifically include one or more of the following processes: performing flow control on message 1, and modifying the message header of message 1 based on the network transmission protocol used by the network card. Furthermore, the message pre-sending processing may also include other processes, which are not specifically limited in this embodiment.
[0197] Optionally, thread A2 may independently perform pre-sending processing on the encapsulated message, or it may collaborate with other threads to perform pre-sending processing on the encapsulated message. For example, thread A2 may be a soft interrupt thread. Thread A2 may perform flow control processing on the encapsulated message and pass the processed message to the driver thread, which then further modifies the message header in the processed message.
[0198] Step 904: Thread A2 transmits message 2 to network card A.
[0199] After thread A2 completes the pre-message processing on the encapsulated message, it obtains message 2. Thread A2 then transmits message 2 to the network card A in the communication device 1 so that the network card A can realize the physical transmission of message 2, that is, the network card A sends message 1 to the communication device 2 via wired or wireless means.
[0200] In addition, when thread A2 collaborates with other threads to complete the pre-processing of the message, the other threads can transmit message 2 to the network card.
[0201] Step 905 : Network card A sends message 2 to communication device 2 .
[0202] The network card A may send the message 1 to the communication device 2 via a wired cable or wirelessly (such as wifi).
[0203] Step 906 : Thread B1 in communication device 2 obtains message 2 from communication device 1 .
[0204] In step 907 , based on the fact that the data volume of data 2 corresponding to message 2 is greater than the preset data volume, thread B1 decapsulates the data link layer header in message 2 to obtain a message with a partial header decapsulated.
[0205] If the amount of data 2 corresponding to message 2 exceeds the preset amount, thread B1 collaborates with other threads to complete the decapsulation of message 2. Specifically, thread B1 may first decapsulate the data link layer header in message 2 and then schedule thread B3 to pass the message after decapsulation of the data link layer header to thread B3.
[0206] Specifically, thread B1 may parse message 2 and determine that the amount of data 2 corresponding to message 2 is greater than a preset amount of data based on the fact that message 2 does not include the first mark.
[0207] In step 908, thread B1 transmits the message after partially decapsulating the message header to thread B3, and thread B3 decapsulates the remaining message headers in the message after partially decapsulating the message header to obtain a valid payload.
[0208] Specifically, thread B1 passes the message after decapsulating the data link layer header to thread B3, which also includes the network layer header and the transport layer header. In this way, thread B3 can continue to decapsulate the remaining network layer header and transport layer header in the message to obtain the payload.
[0209] Thread B1 may be a driver thread, for example, and thread B3 may be a soft interrupt thread, for example.
[0210] Step 909: Thread B3 transmits the payload in message 2 to thread B2, which is the destination thread for the payload.
[0211] After thread B3 completes the decapsulation process of message 1 and obtains the payload in message 2, thread B3 passes the payload to the final destination thread, namely thread B2, thereby completing the data transmission. For example, thread B2 can be an application thread in communication device 2.
[0212] The above describes the specific execution process of the data transmission method provided in this embodiment. The following will describe the application process of the data transmission method in detail with reference to specific examples.
[0213] For example, please refer to Figures 10-12, Figure 10 is a flow chart of executing data transmission through threads between communication devices provided in an embodiment of the present application; Figure 11 is a flow chart of executing message sending through threads by a communication device as a sending end provided in an embodiment of the present application; Figure 12 is a flow chart of executing message receiving through threads by a communication device as a receiving end provided in an embodiment of the present application.
[0214] As shown in Figure 10, the communication device 1 serving as the message sending end includes an application thread 1, a soft interrupt thread 1, a driver thread 1 and a network card; the communication device 2 serving as the message receiving end includes an application thread 2, a soft interrupt thread 2, a driver thread 2, a hard interrupt thread and a network card 2.
[0215] As shown in FIG10 and FIG11 , the process of the communication device 1 sending a message is as follows.
[0216] First, application thread 1 in communication device 1 generates data to be transmitted in user mode and calls a system function to enter kernel mode to encapsulate and send the message. When calling the system function, application thread 1 carries the data to be transmitted and specifies the data volume (i.e., the size of the data to be transmitted).
[0217] After the application thread 1 enters the kernel state, the application thread 1 determines whether the amount of data to be transmitted is greater than a preset amount of data.
[0218] If the amount of data to be transmitted does not exceed a preset data volume, application thread 1 encapsulates the data into a message and sets a first tag for the message, namely, adding the first tag to the message header. Application thread 1 then performs flow control on the message and processes the data link layer header of the message based on the network transmission protocol of the network card. Application thread 1 does not dispatch other sites to coordinate pre-transmission processing of the message. Finally, application thread 1 passes the resulting message to network card 1, which then transmits the message to communication device 2.
[0219] If the amount of data to be transmitted exceeds the preset data volume, application thread 1 encapsulates the data to be transmitted into a message and does not set the first flag for the message. Application thread 1 then passes the message to softirq thread 1, which performs flow control on the message. After performing flow control on the message, softirq thread 1 passes the message to driver thread 1, which processes the data link layer header of the message based on the network transmission protocol of the network card. Finally, driver thread 1 passes the resulting message to network card 1, which sends the message to communication device 2.
[0220] As shown in FIG10 and FIG12 , the process of the communication device 2 receiving a message is as follows.
[0221] Network card 2 in communication device 2 receives a message from network card 1 in communication device 1 and passes the message to the hard interrupt thread. The hard interrupt thread adds the message to the receive queue of driver thread 2, waiting for driver thread 2 to process the message. Driver thread 2 then removes the message from the receive queue and decapsulates the data link layer header of the message. Driver thread 2 also parses the message header to determine whether the message contains the first flag.
[0222] If the message includes the first marker, driver thread 2 continues to decapsulate the message's network layer header and transport layer header without scheduling other threads to collaborate on the decapsulation process. Finally, after completing the decapsulation process, driver thread 2 passes the message's payload to application thread 2, i.e., the payload's destination thread.
[0223] If the message does not contain the first marker, driver thread 2 schedules softirq thread 2 and passes the message after decapsulating the data link layer header to softirq thread 2. Softirq thread 2 then decapsulates the network layer header and transport layer header of the message. Finally, after decapsulating the message, softirq thread 2 passes the payload to application thread 2, which is the destination thread for the payload.
[0224] In one possible embodiment, the data transmission method provided by the embodiment of the present application includes: a first thread in a first communication device obtains first data to be transmitted; based on the data volume of the first data being no greater than a preset data volume, the first thread encapsulates the first data and performs message pre-sending processing on the encapsulated message to obtain a first message, and the message pre-sending processing is used to make the first message meet the message sending requirements; the first thread transmits the first message to a network card, and the network card is used to send the first message to a second communication device.
[0225] The first communication device is, for example, the communication device 1 mentioned above, the second communication device is, for example, the communication device 2 mentioned above, the first thread is, for example, the thread A1 mentioned above, and the first message is, for example, the message 1 mentioned above.
[0226] Optionally, the first message includes a first mark, and the first mark is used to indicate that the data volume of the first data corresponding to the first message is not greater than the preset data volume.
[0227] Optionally, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0228] Optionally, the preset data volume is related to the maximum length of the first message.
[0229] Optionally, the pre-message processing includes one or more of the following processes: performing flow control processing on the first message, and modifying the message header of the first message based on the network transmission protocol adopted by the network card.
[0230] Optionally, the method also includes: the first thread obtains the second data to be transmitted; based on the data volume of the second data being greater than the preset data volume, the first thread encapsulates the second data to obtain a second message; the first thread passes the second message to the second thread, and the second thread is used to perform the pre-message processing on the second message.
[0231] The second thread may be, for example, thread A2 in the above embodiment.
[0232] Optionally, the first thread is an application thread, and the second thread is a soft interrupt thread or a driver thread.
[0233] In another possible embodiment, the data transmission method provided in the embodiment of the present application includes: a first thread in a first communication device obtains a first message from a second communication device, and the data volume of the first data corresponding to the first message is not greater than the preset data volume; the first thread decapsulates the first message to obtain the effective load in the first message, and the first data is the effective data transmitted by the second communication device to the first communication device; the first thread passes the effective load to the second thread, and the second thread is the destination thread of the effective load.
[0234] The first communication device is, for example, the communication device 2 mentioned above, the second communication device is, for example, the communication device 1 mentioned above, the first thread is, for example, the thread B1 mentioned above, the second thread is, for example, the thread B2 mentioned above, and the first message is, for example, the message 1 mentioned above.
[0235] Optionally, the first message includes a first mark, and the first mark is used to indicate that the data volume of the first data corresponding to the first message is not greater than the preset data volume.
[0236] Optionally, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0237] Optionally, the preset data volume is related to the maximum length of the first message.
[0238] Optionally, the method also includes: the first thread obtains a second message from the second communication device; based on the fact that the data volume of the second data corresponding to the second message is greater than the preset data volume, the first thread decapsulates part of the message header in the second message to obtain a third message, and the second data is valid data transmitted by the second communication device to the first communication device; the first thread passes the third message to the third thread, and the third thread is used to decapsulate the message header in the third message and pass the decapsulated payload to the second thread.
[0239] The third thread is, for example, the aforementioned thread B3.
[0240] Optionally, the first thread is a driver thread, and the second thread is an application thread.
[0241] The above embodiments introduce the data transmission method provided in the embodiments of the present application. The following will introduce the device that executes the above data transmission method.
[0242] Please refer to Figure 13, which is a schematic diagram of the structure of a communication device provided in an embodiment of the present application. As shown in Figure 13, the communication device is a first communication device, specifically comprising: an acquisition module 1301, configured to enable a first thread to acquire first data to be transmitted, where the data volume of the first data is no greater than a preset data volume; a processing module 1302, configured to enable the first thread to encapsulate the first data and perform pre-message processing on the encapsulated message to obtain a first message, where the pre-message processing is used to ensure that the first message meets the message sending requirements; and processing module 1302, further configured to enable the first thread to transmit the first message to a network card, which is used to send the first message to a second communication device.
[0243] In a possible implementation, the first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than a preset data volume.
[0244] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0245] In a possible implementation, the preset data volume is related to the maximum length of the first message.
[0246] In a possible implementation, the message pre-sending processing includes one or more of the following processes: performing flow control processing on the first message, and modifying the message header of the first message based on the network transmission protocol adopted by the network card.
[0247] In a possible implementation, the acquisition module 1301 is further configured to enable the first thread to acquire second data to be transmitted, where the amount of the second data is greater than a preset amount of data;
[0248] The processing module 1302 is further configured to cause the first thread to encapsulate the second data to obtain a second message;
[0249] The processing module 1302 is further configured to enable the first thread to transmit the second message to the second thread, and the second thread is configured to perform pre-message processing on the second message.
[0250] In a possible implementation, the first thread is an application thread, and the second thread is a soft interrupt thread or a driver thread.
[0251] Please refer to Figure 14, which is a schematic diagram of the structure of a communication device provided in an embodiment of the present application. As shown in Figure 14, the communication device is a first communication device, comprising: an acquisition module 1401, configured to enable a first thread to acquire a first message from a second communication device, wherein the amount of first data corresponding to the first message is no greater than a preset amount of data, and the first data is valid data transmitted from the second communication device to the first communication device; a processing module 1402, configured to enable the first thread to decapsulate the first message to obtain a payload in the first message; and processing module 1402 is further configured to enable the first thread to transfer the payload to the second thread, with the second thread being the destination thread for the payload.
[0252] In a possible implementation, the first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than a preset data volume.
[0253] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0254] In a possible implementation, the preset data volume is related to the maximum length of the first message.
[0255] In one possible implementation, the acquisition module 1401 is further configured to enable the first thread to acquire a second message from the second communication device, where the amount of second data corresponding to the second message is greater than a preset data amount, and the second data is valid data transmitted by the second communication device to the first communication device;
[0256] The processing module 1402 is further configured to cause the first thread to decapsulate part of the message header in the second message to obtain a third message;
[0257] The processing module 1402 is further configured to enable the first thread to transmit the third message to the third thread, and the third thread is configured to decapsulate the message header in the third message and transmit the decapsulated payload to the second thread.
[0258] In a possible implementation, the first thread is a driver thread, and the second thread is an application thread.
[0259] Next, an execution device provided in an embodiment of the present application is introduced. Please refer to Figure 15. Figure 15 is a structural schematic diagram of an execution device provided in an embodiment of the present application. The execution device 1500 can be specifically manifested as a mobile phone, a tablet, a laptop computer, a smart wearable device, a server, etc., which is not limited here. Specifically, the execution device 1500 includes: a receiver 1501, a transmitter 1502, a processor 1503 and a memory 1504 (wherein the number of processors 1503 in the execution device 1500 can be one or more, and Figure 15 takes one processor as an example), wherein the processor 1503 may include an application processor 15031 and a communication processor 15032. In some embodiments of the present application, the receiver 1501, the transmitter 1502, the processor 1503 and the memory 1504 may be connected via a bus or other means.
[0260] Memory 1504 may include read-only memory and random access memory, and provides instructions and data to processor 1503. A portion of memory 1504 may also include non-volatile random access memory (NVRAM). Memory 1504 stores processor and operation instructions, executable modules, or data structures, or subsets or extended sets thereof. The operation instructions may include various operation instructions for implementing various operations.
[0261] Processor 1503 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together via a bus system. In addition to a data bus, the bus system may also include a power bus, a control bus, and a status signal bus. However, for clarity, all bus systems are referred to as a bus system in the figure.
[0262] The methods disclosed in the above embodiments of the present application can be applied to or implemented by processor 1503. Processor 1503 can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits or software instructions in processor 1503. The above processor 1503 can be a general-purpose processor, a digital signal processor (DSP), a microprocessor, or a microcontroller, and can further include an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The processor 1503 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in conjunction with the embodiments of the present application can be directly implemented as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in memory 1504, and processor 1503 reads the information in memory 1504 and, in conjunction with its hardware, completes the steps of the above method.
[0263] Receiver 1501 can be used to receive input digital or character information and generate signal input related to executing device-related settings and function control. Transmitter 1502 can be used to output digital or character information through the first interface. Transmitter 1502 can also be used to send instructions to the disk pack through the first interface to modify data in the disk pack. Transmitter 1502 can also include a display device such as a display screen.
[0264] In an embodiment of the present application, in one case, the processor 1503 is configured to execute the method in the embodiment corresponding to FIG5 .
[0265] The electronic device provided in the embodiment of the present application may specifically be a chip, and the chip includes: a processing unit and a communication unit, wherein the processing unit may be, for example, a processor, and the communication unit may be, for example, an input / output interface, a pin or a circuit, etc. The processing unit may execute the computer execution instructions stored in the storage unit so that the chip in the execution device executes the rendering method described in the above embodiment. Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit may also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.
[0266] Please refer to Figure 16, which is a schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present application. The present application also provides a computer-readable storage medium. In some embodiments, the method disclosed in Figure 7 above can be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or on other non-transitory media or products.
[0267] 16 schematically illustrates a conceptual partial view of an example computer-readable storage medium including a computer program for executing a computer process on a computing device, arranged in accordance with at least some embodiments presented herein.
[0268] In one embodiment, computer-readable storage medium 1600 is provided using signal-bearing medium 1601. Signal-bearing medium 1601 may include one or more program instructions 1602 that, when executed by one or more processors, may provide the functionality or portions of the functionality described above with respect to FIG5. Furthermore, program instructions 1602 in FIG16 also depict example instructions.
[0269] In some examples, the signal bearing medium 1601 may include a computer readable medium 1603 such as, but not limited to, a hard drive, a compact disk (CD), a digital video disk (DVD), a digital tape, a memory, a ROM or RAM, and the like.
[0270] In some embodiments, the signal-bearing medium 1601 may include a computer-recordable medium 1604, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, or the like. In some embodiments, the signal-bearing medium 1601 may include a communication medium 1605, such as, but not limited to, a digital and / or analog communication medium (e.g., a fiber optic cable, a waveguide, a wired communication link, a wireless communication link, or the like). Thus, for example, the signal-bearing medium 1601 may be communicated via a wireless form of the communication medium 1605 (e.g., a wireless communication medium conforming to the IEEE 802 standard or other transmission protocol).
[0271] The one or more program instructions 1602 may be, for example, computer-executable instructions or logic-implemented instructions. In some examples, the computing device may be configured to provide various operations, functions, or actions in response to the program instructions 1602 communicated to the computing device via one or more of computer-readable media 1603, computer-recordable media 1604, and / or communication media 1605.
[0272] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0273] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0274] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0275] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0276] The units described as separate components may or may not be physically separate, and 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 these units may be selected to achieve the purpose of the solution of this embodiment according to actual needs.
[0277] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0278] If the integrated unit is implemented in the form of 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 the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0279] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A data transmission method, characterized in that: include: A first thread in the first communication device obtains first data to be transmitted, where the amount of the first data is no greater than a preset amount of data; The first thread encapsulates the first data and performs message pre-sending processing on the encapsulated message to obtain a first message, wherein the message pre-sending processing is used to ensure that the first message meets message sending requirements; The first thread transmits the first message to a network card, and the network card is used to send the first message to a second communication device.
2. The method according to claim 1, characterized in that The first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than the preset data volume.
3. The method according to claim 2, characterized in that The first tag is located in a reserved field or an extended field in a message header of the first message.
4. The method according to any one of claims 1 to 3, characterized in that The preset data volume is related to the maximum length of the first message.
5. The method according to any one of claims 1 to 4, characterized in that The message pre-sending processing includes one or more of the following processing: performing flow control processing on the first message, and modifying the message header of the first message based on the network transmission protocol adopted by the network card.
6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: The first thread obtains second data to be transmitted, where the amount of the second data is greater than the preset amount of data; The first thread encapsulates the second data to obtain a second message; The first thread transmits the second message to the second thread, and the second thread is used to perform the pre-message sending processing on the second message.
7. The method according to claim 6, characterized in that The first thread is an application thread, and the second thread is a soft interrupt thread or a driver thread.
8. A data transmission method, characterized in that: include: A first thread in a first communication device obtains a first message from a second communication device, where the amount of first data corresponding to the first message is no greater than a preset amount of data, and the first data is valid data transmitted from the second communication device to the first communication device; Decapsulating the first message by the first thread to obtain a payload in the first message; The first thread transfers the payload to a second thread, where the second thread is a destination thread for the payload.
9. The method according to claim 8, characterized in that The first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than the preset data volume.
10. The method according to claim 9, characterized in that The first tag is located in a reserved field or an extended field in a message header of the first message.
11. The method according to any one of claims 8 to 10, characterized in that: The preset data volume is related to the maximum length of the first message.
12. The method according to any one of claims 8 to 11, characterized in that: The method further comprises: The first thread obtains a second message from the second communication device, the amount of second data corresponding to the second message is greater than the preset data amount, and the second data is valid data transmitted by the second communication device to the first communication device; The first thread decapsulates part of the message header in the second message to obtain a third message; The first thread transmits the third message to the third thread, and the third thread is used to decapsulate the message header in the third message and transmit the decapsulated payload to the second thread.
13. The method according to any one of claims 8 to 12, characterized in that: The first thread is a driver thread, and the second thread is an application thread.
14. A communication device, characterized in that: The communication device is a first communication device, comprising: An acquisition module, configured to enable the first thread to acquire first data to be transmitted, where the amount of the first data is no greater than a preset amount of data; a processing module, configured to cause the first thread to encapsulate the first data and perform message pre-sending processing on the encapsulated message to obtain a first message, wherein the message pre-sending processing is used to ensure that the first message meets message sending requirements; The processing module is further configured to enable the first thread to transmit the first message to a network card, and the network card is configured to send the first message to a second communication device.
15. The device according to claim 14, characterized in that The first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than the preset data volume.
16. The device according to claim 15, characterized in that The first tag is located in a reserved field or an extended field in a message header of the first message.
17. The device according to any one of claims 14 to 16, characterized in that The preset data volume is related to the maximum length of the first message.
18. The device according to any one of claims 14 to 17, characterized in that The message pre-sending processing includes one or more of the following processing: performing flow control processing on the first message, and modifying the message header of the first message based on the network transmission protocol adopted by the network card.
19. The device according to any one of claims 14 to 18, characterized in that The acquisition module is further configured to enable the first thread to acquire second data to be transmitted, where the amount of the second data is greater than the preset amount of data; The processing module is further configured to enable the first thread to encapsulate the second data to obtain a second message; The processing module is further configured to enable the first thread to transfer the second message to the second thread, and the second thread is configured to perform the pre-message sending processing on the second message.
20. The device according to claim 19, characterized in that The first thread is an application thread, and the second thread is a soft interrupt thread or a driver thread.
21. A communication device, characterized in that: The communication device is a first communication device, comprising: an acquisition module, configured to enable the first thread to acquire a first message from the second communication device, wherein the amount of first data corresponding to the first message is no greater than a preset amount of data, and the first data is valid data transmitted from the second communication device to the first communication device; a processing module, configured to enable the first thread to decapsulate the first message to obtain a payload in the first message; The processing module is further configured to enable the first thread to transfer the payload to a second thread, where the second thread is a destination thread for the payload.
22. The device according to claim 21, characterized in that The first message includes a first flag, and the first flag is used to indicate that the data volume of the first data corresponding to the first message is not greater than the preset data volume.
23. The device according to claim 22, characterized in that The first tag is located in a reserved field or an extended field in a message header of the first message.
24. The device according to any one of claims 21 to 23, characterized in that The preset data volume is related to the maximum length of the first message.
25. The device according to any one of claims 21 to 24, characterized in that The acquisition module is further configured to enable the first thread to acquire a second message from the second communication device, where the amount of second data corresponding to the second message is greater than the preset data amount, and the second data is valid data transmitted by the second communication device to the first communication device; The processing module is further configured to enable the first thread to decapsulate part of the message header in the second message to obtain a third message; The processing module is further configured to enable the first thread to transfer the third message to a third thread, and the third thread is configured to decapsulate a message header in the third message and transfer a decapsulated payload to the second thread.
26. The device according to any one of claims 21 to 25, characterized in that The first thread is a driver thread, and the second thread is an application thread.
27. A communication device, characterized in that: The device comprises a memory and a processor; the memory stores codes, the processor is configured to execute the codes, and when the codes are executed, the device executes the method according to any one of claims 1 to 13.
28. A computer storage medium, characterized in that The computer storage medium stores instructions, which, when executed by a computer, cause the computer to implement the method according to any one of claims 1 to 13.
29. A computer program product, characterized in that The computer program product stores instructions, which, when executed by a computer, cause the computer to implement the method according to any one of claims 1 to 13.