Data receiving method, apparatus, device, and storage medium
Patent Information
- Application Number
- CN202110686660.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-21
- Publication Date
- 2026-08-18
- Estimated Expiration
- 2041-06-21
AI Technical Summary
[0004]在软中断处理过程中,只有一个目标线程对接收到的数据进行格式转换,使得数据接收速率较低
[0036]The beneficial effects of the technical solution provided in this disclosure are as follows: After receiving a hard interrupt from the network card, the software interrupt handler calls the first thread on the multiple processors to perform format conversion on the data in the kernel buffer. That is, multiple first threads are called to perform format conversion on the data in the kernel buffer in parallel, thereby improving the data receiving rate. Furthermore, since multiple processors process data simultaneously, the upper limit of data processing capability is the sum of the upper limits of the processing capabilities of these multiple processors, thus increasing the upper limit of the data receiving rate of the terminal device.
Smart Images

Figure CN115576660B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computers, and in particular to a data receiving method, apparatus, device, and storage medium. Background Technology
[0002] Terminal devices, such as cloud screens, need to download large amounts of data from the network, such as installation packages, high-definition videos, and audio, and then process them, such as installing software packages, displaying, and playing them.
[0003] In related technologies, the process of a terminal device receiving data sent from the network includes: after the network card of the terminal device receives the data, the network card informs the processor that the data has been received through a hardware interrupt; after the processor receives the hardware interrupt, it interrupts the program that the processor is running, and calls a default target thread through a software interrupt handler to perform format conversion on the received data.
[0004] During soft interrupt handling, only one target thread performs format conversion on the received data, resulting in a low data reception rate. Furthermore, if the data volume is too large, reaching the processing capacity limit of the processor corresponding to the target thread, the data reception rate cannot be further increased, thus limiting the data reception rate. Summary of the Invention
[0005] This disclosure provides a data receiving method, apparatus, device, and storage medium, which can improve the data receiving rate. The technical solution is as follows:
[0006] In a first aspect, embodiments of this disclosure provide a data receiving method, characterized in that it is applied to a terminal device, the terminal device including multiple processors and memory, each of the multiple processors running a first thread, the first thread being used to perform format conversion on data in a kernel buffer in the memory; the method includes: writing received data into the kernel buffer; in response to a hardware interrupt sent by a network card, starting a software interrupt handler; and calling the first thread on the multiple processors through the software interrupt handler to convert the data in the kernel buffer into a target format.
[0007] In one implementation of this disclosure, the data includes multiple network frames, the kernel buffer includes multiple queues, and the data in each queue is format-converted by a corresponding first thread; writing the received data into the kernel buffer includes adding each of the multiple network frames to one of the multiple queues respectively.
[0008] In one implementation of this disclosure, adding each network frame from the plurality of network frames to one of the plurality of queues includes: obtaining the load of each processor; determining a first queue based on the size of the load; and adding a first network frame to the first queue, wherein the first network frame is any one of the plurality of network frames.
[0009] In one implementation of this disclosure, determining the first queue based on the load includes: using the queue corresponding to the processor with the lowest load as the first queue; or, using the queue corresponding to any one of the at least one processors whose load does not exceed a threshold as the first queue.
[0010] In one implementation of this disclosure, the terminal device further includes a wireless communication module, which is connected to the processor via a USB interface; the step of writing the received data into the kernel buffer includes: storing the data received by the wireless communication module into a USB request block; and copying the data in the USB request block into the kernel buffer via a USB network card driver.
[0011] In one implementation of this disclosure, the terminal device further includes a first memory and a second memory, wherein the read / write speed of the first memory is higher than that of the second memory; the method includes: processing the data of the target format layer by layer according to the protocol stack; writing the processed data into the first memory; and transferring the data in the first memory to the second memory.
[0012] In one implementation of this disclosure, transferring data from the first memory to the second memory includes: transferring data from the first memory to the second memory when a set condition is met, wherein the set condition includes at least one of the following: the storage capacity of the first memory reaches a storage threshold; a data transfer instruction is received; or the terminal device is in an idle state.
[0013] In one implementation of this disclosure, the method further includes: disabling the network card's hardware interrupt in response to a hardware interrupt sent by the network card; and re-enabling the network card's hardware interrupt in response to all data packets of the target format in the memory being processed.
[0014] Secondly, embodiments of this disclosure provide a data receiving device, which includes a memory module including a memory buffer; multiple processing modules, each of which runs a first thread, the first thread being used to perform format conversion on data in the kernel buffer; a receiving module for writing received data into the kernel buffer; a startup module for starting a software interrupt handler in response to a hardware interrupt sent by a network card; and a conversion module for calling the first thread on each of the multiple processing modules through the software interrupt handler to convert the data in the kernel buffer into a target format.
[0015] In one implementation of this disclosure, the data includes multiple network frames, and the kernel buffer in the memory module includes multiple queues, with the data in each queue being format-converted by a corresponding first thread;
[0016] The receiving module is used to add each of the multiple network frames into one of the multiple queues.
[0017] In one implementation of this disclosure, the receiving module includes:
[0018] The `get` submodule is used to obtain the load of each processor;
[0019] A determination submodule is used to determine the first queue based on the size of the load;
[0020] The addition submodule is used to add a first network frame to the first queue, wherein the first network frame is any one of the plurality of network frames.
[0021] In one implementation of this disclosure, the determining submodule is used to: select the queue corresponding to the processing module with the lowest load as the first queue; or select the queue corresponding to any one of the processing modules whose load does not exceed a threshold as the first queue.
[0022] In one implementation of this disclosure, the data receiving device further includes a wireless communication module, which is connected to the processing module via a USB interface.
[0023] The receiving module is used to store the data received by the wireless communication module into a USB request block;
[0024] The data in the USB request block is copied to the kernel buffer via the USB network card driver.
[0025] In one implementation of this disclosure, the data receiving device further includes a first memory and a second memory, wherein the read / write speed of the first memory is higher than that of the second memory.
[0026] The device further includes:
[0027] The processing module is used to process the target format data layer by layer according to the protocol stack;
[0028] The writing module is used to write the processed data into the first memory;
[0029] A transfer module is used to transfer data from the first memory to the second memory.
[0030] In one implementation of this disclosure, the transfer module is used to transfer data in the first memory to the second memory when a set condition is met. The set condition includes at least one of the following: the storage capacity of the first memory reaches a storage threshold; a data transfer instruction is received; or the device is in an idle state.
[0031] In one implementation of this disclosure, the apparatus further includes:
[0032] Disable module, used to disable the network card's hardware interrupt in response to hardware interrupts sent by the network card;
[0033] The startup module is also used to re-enable the network card's hardware interrupt in response to the completion of processing all data packets of the target format in the memory.
[0034] Thirdly, embodiments of this disclosure provide a computer device, the computer device including a processor and a memory; wherein the memory is used to store a computer program; and the processor is used to execute the computer program stored in the memory to implement any of the foregoing methods.
[0035] Fourthly, embodiments of this disclosure provide a computer-readable storage medium storing computer instructions that, when executed by a processor, can implement any of the aforementioned methods.
[0036] The beneficial effects of the technical solution provided in this disclosure are as follows: After receiving a hard interrupt from the network card, the software interrupt handler calls the first thread on the multiple processors to perform format conversion on the data in the kernel buffer. That is, multiple first threads are called to perform format conversion on the data in the kernel buffer in parallel, thereby improving the data receiving rate. Furthermore, since multiple processors process data simultaneously, the upper limit of data processing capability is the sum of the upper limits of the processing capabilities of these multiple processors, thus increasing the upper limit of the data receiving rate of the terminal device. Attached Figure Description
[0037] To more clearly illustrate the technical solutions in the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0038] Figure 1 This is a schematic diagram of the structure of a cloud screen provided in an embodiment of this disclosure;
[0039] Figure 2 This is a flowchart of a data receiving method provided in an embodiment of this disclosure;
[0040] Figure 3 This is a flowchart of another data receiving method provided in an embodiment of this disclosure;
[0041] Figure 4 This is a schematic diagram of a network frame allocation process provided in an embodiment of this disclosure;
[0042] Figure 5 This is a schematic diagram of another network frame allocation process provided in an embodiment of this disclosure;
[0043] Figure 6 This is a schematic diagram of a function call process for a data receiving method provided in an embodiment of this disclosure;
[0044] Figure 7 This is a schematic diagram of the TCP / IP protocol stack provided in the embodiments of this disclosure;
[0045] Figure 8 This is a flowchart illustrating the layer-by-layer processing of the TCP / IP protocol stack, as provided in this embodiment.
[0046] Figure 9 This is a schematic diagram of a data storage process provided in an embodiment of this disclosure;
[0047] Figure 10 This is a schematic diagram of a memory space allocation process provided in an embodiment of this disclosure;
[0048] Figure 11 This is a schematic diagram of a data reading process provided in an embodiment of this disclosure;
[0049] Figure 12 This is a schematic diagram of the structure of the data receiving device provided in the embodiments of this disclosure;
[0050] Figure 13 This is a schematic diagram of the structure of a computer device provided in an embodiment of this disclosure. Detailed Implementation
[0051] To make the objectives, technical solutions, and advantages of this disclosure clearer, the embodiments of this disclosure will be described in further detail below with reference to the accompanying drawings.
[0052] This disclosure applies to various terminal devices that need to download large amounts of data from the network, such as cloud screens. A cloud screen is a smart display device placed in a public place, which usually needs to download a large amount of multimedia data from the network for playback; therefore, it has high requirements for data reception speed.
[0053] The following uses a cloud screen as an example to illustrate the structure of the terminal device in this embodiment of the disclosure.
[0054] Figure 1 This is a schematic diagram of the structure of a cloud screen provided in an embodiment of this disclosure. For example... Figure 1 As shown, the cloud screen includes: a wireless communication module 11, a system on chip (SoC) 12, and a memory 13. The wireless communication module 11 and SoC 12 are connected via a USB interface, and SoC 12 and memory 13 are connected via a bus.
[0055] The wireless communication module 11 is used to receive data and transmit the received data to the SoC 12. The wireless communication module 11 includes a USB network card 111 and a wireless module 112. The wireless communication technologies used by the wireless module 112 include, but are not limited to, 4G and 5G.
[0056] Because the data reception and processing are all performed under the Linux system, the USB network card 111 needs to be dialed up to become a USB network card under the Linux system. After the data packets received by the wireless module 112 arrive at the USB network card 111, the USB network card 111 can transfer the data to the SoC's memory via DMA (Direct Memory Access).
[0057] SoC 12 includes a processor group 121 and memory 122. Processor group 121 contains multiple processors, each running a first thread. Optionally, the processors may be central processing units (CPUs). Memory 122 includes a kernel buffer for storing data received by the USB network card; the first thread is used to perform format conversion on the data in the kernel buffer to transform the data in the kernel buffer into a target format. In this embodiment, the first thread may be a ksoftirqd thread.
[0058] The memory 13 is used to store the downloaded data. The memory 13 includes one or more of the following: hard disk drive (HDD), embedded multi-media card (eMMC), solid-state drive (SSD), etc.
[0059] It should be noted that the aforementioned processor group and memory may not be in the form of a SoC, and this disclosure does not impose any restrictions on this.
[0060] This disclosure provides a data receiving method, which can be executed by a terminal device, such as a... Figure 1 The cloud screen shown. Figure 2 This is a flowchart of a data receiving method provided in an embodiment of this disclosure. Figure 2 As shown, the method includes:
[0061] In step 201, the received data is written to the kernel buffer.
[0062] In step 202, in response to a hardware interrupt sent by the network card, a software interrupt handler is started.
[0063] After copying the data to the kernel buffer, the network card notifies the processor of the arrival of new network data via a hardware interrupt. Upon receiving the hardware interrupt from the network card, the processor suspends the currently executing program and then starts a software interrupt handler.
[0064] In step 203, the first thread on the plurality of processors is invoked through a software interrupt handler to convert the data in the kernel buffer into the target format.
[0065] In this embodiment of the disclosure, the data in the kernel buffer sk buffer is converted into a target format that the kernel network module can recognize, such as the skb (Struct sk_buffer) format.
[0066] In this embodiment, after receiving a hardware interrupt from the network card, a software interrupt handler calls the first thread on the plurality of processors to perform format conversion on the data in the kernel buffer. That is, multiple first threads are called in parallel to perform format conversion on the data in the kernel buffer, thereby improving the data reception rate. Furthermore, since multiple processors process data simultaneously, the upper limit of data processing capability is the sum of the upper limits of the processing capabilities of these multiple processors, thus increasing the upper limit of the data reception rate of the terminal device.
[0067] Figure 3 This is a flowchart of another data receiving method provided in an embodiment of this disclosure. For example... Figure 3 As shown, the method includes:
[0068] In step 301, the data received by the wireless communication module is stored in the USB request block.
[0069] In step 301, the USB request block is the basic carrier and core data structure used for communication between USB devices. When transmitting data, a USB request block needs to be allocated for the transmitted data.
[0070] In step 302, the data in the USB request block is copied to the kernel buffer via the USB network card driver.
[0071] In step 303, in response to a hardware interrupt sent by the network card, a software interrupt handler is started.
[0072] Optionally, after receiving a hardware interrupt from the network card, the method also includes disabling the network card's interrupts. The purpose of this is to avoid frequent interrupts to the processor. When the network card receives new data, it can directly write it into memory without notifying the processor.
[0073] In step 304, the first thread on multiple processors is invoked through a software interrupt handler to convert the data in the kernel buffer into the target format.
[0074] In this embodiment of the disclosure, the kernel buffer includes multiple queues, and the data in each queue is format-converted by a corresponding first thread. The data includes multiple network frames, and step 304 includes adding each network frame from the multiple network frames to one of the multiple queues respectively.
[0075] For example, Figure 4 This is a schematic diagram of a network frame allocation process provided in an embodiment of this disclosure, as shown below. Figure 4 As shown, the network frame allocation process includes:
[0076] In step 401, the load of multiple processors is obtained.
[0077] Processor load information is a statistical summary of the sum of the number of processes that the processor is processing and the number of processes waiting for the processor to process over a period of time; in other words, it is a statistical summary of the length of the queue used by the processor.
[0078] Alternatively, system commands such as cat / proc / loadavg, uptime, and dumpsys cpuinfo can be used to obtain processor load information.
[0079] In step 402, the first queue is determined based on the size of the load.
[0080] In some embodiments, the first queue may be the queue corresponding to the processor with the least load.
[0081] In other embodiments, the first queue may also be the queue corresponding to any one of at least one processor whose load does not exceed a threshold. The threshold may be any pre-set value. For example, the threshold may be 80%.
[0082] In step 403, the first network frame is added to the first queue. That is, the first network frame is placed at the end of the first queue.
[0083] For example, Figure 5 This is a schematic diagram of another network frame allocation process provided in an embodiment of this disclosure, such as... Figure 5 As shown, the network frame allocation process includes:
[0084] In step 501, the numbering information of multiple processors is obtained.
[0085] The serial numbers of multiple processors are information pre-set by the manufacturer or user.
[0086] For example, the multiple processors are numbered as processor 0, processor 1, ..., processor N.
[0087] In step 502, multiple network frames are allocated according to the order of the numbering information of multiple processors.
[0088] For example, the first network frame is placed at the end of the receive queue corresponding to processor 0, the second network frame is placed at the end of the receive queue corresponding to processor 1, and so on. The (N+1)th network frame is placed at the end of the receive queue corresponding to processor N, and the (N+2)th network frame is placed at the end of the receive queue corresponding to processor 0. The Nth network frame indicates that it is the Nth frame received, which is the order in which the network frames are received.
[0089] Figure 6 This is a schematic diagram of the function call process of a data receiving method provided in an embodiment of this disclosure. For example... Figure 6 As shown, the method includes:
[0090] In step 601, a USB request block is created. The USB request block is created using the usb_alloc_urb() function.
[0091] In step 602, USB request blocks are initialized. Specifically, `usb_fill_int_urb()` initializes interrupt USB request blocks, `usb_fill_bulk_urb()` initializes bulk USB request blocks, and `usb_fill_control_urb()` initializes control USB request blocks. Interrupt USB request blocks, bulk USB request blocks, and control USB request blocks are the three types of USB request blocks.
[0092] In step 603, the USB request block is submitted to the USB core. The USB request block is submitted to the USB core using the `usb_submit_urb()` function. The USB core is used to transmit the USB request block.
[0093] In step 604, the USB request block is submitted to the USB network card driver specified by the USB core.
[0094] In step 605, the USB network card driver receives data packets.
[0095] In step 606, multiple ksoftirqd threads are enabled to process the received data packets.
[0096] The ksoftirqd thread is woken up by the kernel during soft interrupt handling. It ensures that each soft interrupt is eventually processed when dealing with a large number of interrupts, without preempting resources from other important tasks. Upon receiving a soft interrupt, it calls the corresponding handler function. For soft interrupts thrown by the network card driver module, ksoftirqd's final processing logic is to convert the data packets written to memory by the network card into skb format recognizable by the kernel network module. Each ksoftirqd thread corresponds to one processor; enabling multiple ksoftirqd threads means multiple corresponding processors will handle the received data.
[0097] In step 607, the USB network card driver is notified that it can continue receiving data packets. This step is implemented through the net_rx_action function.
[0098] In step 608, the data packets are assembled and distributed, and multiple network frames in the data packets are assigned to multiple processors. This step is implemented by the napi_gro_receive function.
[0099] In step 609, the network frame is added to the tail of the processor's receive queue, which is achieved by the enqueue_to_backlog function.
[0100] In step 610, multiple processor receive queues corresponding to multiple ksoftirqd threads process data packets. The CPU0input_pkt_queue function indicates that the receive queue of processor 0 processes the data packets. The other functions in this step are similar in function and will not be described in detail here.
[0101] In step 611, the skb format data is extracted and handed over to the protocol stack for processing. This step is implemented by the netif_receive_skb_core function.
[0102] In step 612, the protocol stack processes skb format data.
[0103] This embodiment of the disclosure improves the data download speed, i.e., the data reception rate, by enabling multiple ksoftirqd threads during the soft interrupt handling process in data reception, so that multiple processors corresponding to multiple ksoftirqd threads process the received data.
[0104] In step 612, the protocol stack processes the skb format data. That is, the target format data is processed layer by layer by the TCP / IP (Transmission Control Protocol / Internet Protocol) protocol stack.
[0105] Optionally, after all data packets of the target format have been processed, the network card's hardware interrupt is re-enabled. That is, when a new data packet arrives, the processor is notified to receive the data packet.
[0106] To facilitate understanding of the embodiments of this disclosure, the following is combined with... Figure 7 This section explains the basic components of the protocol stack used in network communication. Figure 7 This is a schematic diagram of the TCP / IP protocol stack provided in an embodiment of this disclosure. Figure 7 As shown, the TCP / IP protocol stack 70 is the core skeleton of network communication, defining how data is transmitted between different devices. The TCP / IP protocol stack 70 includes the application layer 701, transport layer 702, network layer 703, data link layer 704, and physical layer 705.
[0107] The application layer 701 defines the data format and interprets the data according to the corresponding format; the transport layer 702 defines the port, identifies each application, and confirms the identity of the application on the host; the network layer 703 defines the IP address, that is, confirms the network address of the host; the data link layer 704 defines the MAC address, that is, confirms the physical address of the host; and the physical layer 705 is responsible for the physical transmission of data.
[0108] Figure 8 This is a flowchart illustrating the layer-by-layer processing of the TCP / IP protocol stack according to an embodiment of this disclosure, such as... Figure 8 As shown, the protocol stack's layer-by-layer processing includes:
[0109] In step 801, the data link layer checks the validity of the data frame, finds out the type of the upper layer protocol, removes the frame header and frame trailer, and hands the data packet over to the network layer.
[0110] A data frame consists of a frame header, a data packet, and a frame trailer. The frame header and frame trailer contain the data's MAC address (Media Access Control Address), which is the physical address, while the data packet contains the data's IP address (Internet Protocol Address), which is the network address.
[0111] In step 802, the network layer removes the IP header and hands it over to the transport layer for processing. The IP header is used to identify the destination of the data packet.
[0112] In step 803, the transport layer locates the corresponding socket and copies the data into the socket's buffer. Sockets provide a mechanism for sending data packets to the application layer.
[0113] In step 804, after all data packets in memory have been processed, the network card's hardware interrupt is enabled. This way, the network card will notify the processor the next time it receives data.
[0114] In step 805, the application reads data from the socket buffer using a data read command. For example, the data read command could be the function `read()`.
[0115] Optionally, after the protocol stack has completed processing layer by layer, the method may further include storing the processed data in memory.
[0116] Optionally, in this embodiment of the disclosure, the terminal device includes a first memory and a second memory, wherein the read / write speed of the first memory is greater than that of the second memory.
[0117] Optionally, the first storage device can be eMMC, a solid-state drive (SSD), etc. Optionally, the second storage device can be a hard disk drive (HDD), etc.
[0118] Figure 9 This is a schematic diagram of a data storage process provided in an embodiment of this disclosure, such as... Figure 9 As shown, the data storage process includes:
[0119] In step 901, the target format data is processed layer by layer according to the protocol stack.
[0120] See detailed steps Figure 7 , Figure 8 The corresponding implementation examples.
[0121] In step 902, the data processed layer by layer by the protocol stack is written into the first memory.
[0122] For example, Figure 10 This is a schematic diagram of a memory space allocation process provided in an embodiment of this disclosure, as shown below. Figure 10 As shown, the space in the first memory is divided into several basic units called buckets, with each small square corresponding to a bucket. A bucket is the basic unit of data caching, and cached data is managed according to buckets. The initial data block of the first memory, i.e., Figure 10 The black squares in the diagram contain control information for the first memory, such as its size and the number of basic unit buckets. Shaded squares represent buckets with stored data, while blank squares represent buckets without stored data. Bucket allocation uses a copy-on-write (COW) method, meaning that each allocated module is a bucket, and data is appended to every bucket, preventing overwriting. When new data containing existing data is written—for example, data added to existing data—the writing is redirected to a new data block bucket before being written.
[0123] In step 903, the data in the first memory is transferred to the second memory.
[0124] For example, step 903 is performed when the set conditions are met.
[0125] In some embodiments, the setting condition may be that the storage amount of the first memory reaches a storage threshold. The storage threshold may be any value that is preset to be greater than 0% and not more than 100%, for example, the storage threshold may be 80%.
[0126] In other embodiments, the setting condition may be receiving a data transfer instruction. The data transfer instruction may be issued directly by the user, or it may be an instruction pre-set by the user and issued by the computer system at fixed intervals.
[0127] In other embodiments, the setting condition may be that the terminal device is in an idle state. That is, all processors are in an idle state.
[0128] In step 903, a data transfer thread is started, which is responsible for transferring the data in the first memory to the second memory in the back end.
[0129] The data transfer thread traverses all buckets stored in the first memory, finds all data indices pointing to dirty data blocks in the second memory, and sorts them according to the specific write position information in the second memory contained in the index. In this way, the data blocks in the first memory are read out sequentially according to the sorted indexes and written into the second memory in combination with the specific write position information, thus realizing sequential disk flushing and reducing the number of read and write operations in the second memory.
[0130] Dirty data refers to data that has been modified but has not yet been written to the database, and a dirty data block is a data block that stores dirty data.
[0131] For example, to ensure data transfer performance while minimizing impact on business I / O (input / output) read / write operations, the transfer rate is adjusted based on the "water level" of the data to be transferred. A higher water level, or a faster rate of increase, results in a faster transfer speed. The "water level" refers to the boundary between transferred and untransferred data. All data to be transferred to the second storage can be likened to a reservoir, and untransferred data to water in the reservoir. A higher water level or a faster rate of increase indicates more untransferred data.
[0132] Optionally, the method in this embodiment of the disclosure further includes: reclaiming allocated space in the first memory.
[0133] For example, a garbage collection thread can be used to reclaim allocated space in the first memory. Because storage space in the first memory is allocated using a copy-and-write (COW) method on a bucket basis, cached data and metadata already in the first memory are written to new space when new data containing old data is written. This creates voids in the buckets occupied by invalid old data, wasting bucket space. However, since space reclamation is done in buckets, an asynchronous garbage collection thread is needed to mark and clean up this data, and to compress multiple buckets containing a lot of invalid data into a single bucket. The asynchronous garbage collection thread means that garbage collection occurs after new data is written, not simultaneously with the new data writing.
[0134] Cached data refers to data written to eMMC that needs to be stored later, while metadata describes the attributes of cached data, including storage location, historical data, file records, etc.
[0135] The waste recycling process is divided into two stages:
[0136] Phase 1: Data garbage collection.
[0137] Invalid cached data, valid cached data, and the corresponding metadata for both are marked, and then the metadata bucket is compressed and cleaned up. Valid cached data refers to newly written cached data to the first memory, while invalid cached data refers to existing cached data in the first memory that is at least partially identical to the newly written cached data. For example, if data A is existing cached data in the first memory, and data B is newly written cached data to the first memory, and data B contains all of data A, then data A is invalid cached data, and data B is valid cached data.
[0138] Phase 2: Garbage collection of cached data.
[0139] The main principle is to identify multiple buckets containing invalid cached data exceeding the recycling ratio based on the tagging information from the metadata garbage collection phase. The valid cached data from these identified buckets is then moved to a newly allocated bucket, allowing for the timely recycling of more buckets. The recycling ratio refers to the proportion of invalid cached data to all data in multiple buckets; this ratio can be freely set by the user.
[0140] Optionally, the method provided in this disclosure further includes reading data from a memory. For example, when multimedia data needs to be displayed, it is necessary to read data from a memory.
[0141] Figure 11 This is a schematic diagram of a data reading process provided in an embodiment of this disclosure, such as... Figure 11 As shown, the data reading process includes:
[0142] In step 1101, it is checked whether the data to be read is in the first memory.
[0143] Because the first memory allocates storage space in basic units (buckets), it is necessary to check whether the data to be read is in the first memory based on the bucket. If the data to be read is in the first memory, then proceed to step 1102; if the data to be read is not in the first memory, then proceed to step 1103.
[0144] In step 1102, the desired data is read from the first memory.
[0145] In step 1103, the desired data is read from the second memory and simultaneously written back to the first memory. The next time the same data is read, it can be directly read from the faster first memory, thus improving the data reading speed.
[0146] This disclosure utilizes fast read / write devices for data reading and writing, and low-cost, high-capacity storage devices for data storage, thus ensuring both fast data reading and writing speeds and achieving low-cost, high-capacity storage.
[0147] During the operation of the cloud screen signage project, it is necessary to download a large amount of high-definition video from the network server to the local machine for playback. Due to the large amount of high-definition video data downloaded, slow read and write speeds may occur. However, using devices with faster read and write speeds for storage increases costs. Therefore, the data read, write, and storage method provided in this disclosure is particularly suitable for cloud screen signage projects.
[0148] This disclosure also provides a data receiving device. Figure 12 This is a structural diagram of the data receiving device provided in the embodiments of this disclosure, as shown below. Figure 12 As shown, the device includes:
[0149] Memory module 1201 includes a memory buffer;
[0150] Multiple processing modules 1202, each of which runs a first thread, the first thread being used to perform format conversion on the data in the kernel buffer;
[0151] The receiving module 1203 is used to write the received data into the kernel buffer;
[0152] Startup module 1204 is used to start the software interrupt handler in response to a hardware interrupt sent by the network card;
[0153] The conversion module 1205 is used to call the first thread on the plurality of processing modules through the software interrupt handler to convert the data in the kernel buffer into the target format.
[0154] In one possible implementation of the embodiments of this disclosure,
[0155] The data includes multiple network frames, and the kernel buffer in the memory module 1201 includes multiple queues. The data in each queue is format-converted by a corresponding first thread.
[0156] The receiving module 1203 is used to add each of the multiple network frames into one of the multiple queues.
[0157] In one implementation of this disclosure, the receiving module 1203 includes:
[0158] Get submodule 1203a, used to get the load of each processor;
[0159] Determine submodule 1203b, used to determine the first queue based on the size of the load;
[0160] Submodule 1203c is added to add a first network frame to the first queue, wherein the first network frame is any one of the plurality of network frames.
[0161] In one implementation of this disclosure, the determining submodule 1203b is used to: select the queue corresponding to the processing module with the smallest load as the first queue; or select the queue corresponding to any one of the at least one processing module whose load does not exceed a threshold as the first queue.
[0162] In one implementation of this disclosure, the terminal device further includes a wireless communication module, which is connected to the processing module 1202 via a USB interface.
[0163] The receiving module 1203 is used to store the data received by the wireless communication module into a USB request block;
[0164] The data in the USB request block is copied to the kernel buffer via the USB network card driver.
[0165] The data receiving device further includes a processing module 1203, used to process the target format data layer by layer according to the protocol stack.
[0166] Optionally, after the protocol stack has completed processing layer by layer, the method may further include storing the processed data in memory.
[0167] In one implementation of this disclosure, the memory further includes a first memory and a second memory, wherein the read / write speed of the first memory is higher than that of the second memory.
[0168] The writing module 1207 is used to write the processed data into the first memory;
[0169] The transfer module 1208 is used to transfer data from the first memory to the second memory.
[0170] In one implementation of this disclosure, the transfer module 1208 is used to transfer data in the first memory to the second memory when a set condition is met. The set condition includes at least one of the following: the storage capacity of the first memory reaches a storage threshold; a data transfer instruction is received; or the device is in an idle state.
[0171] In one implementation of this disclosure, the data receiving device further includes:
[0172] Disable module 1209, used to disable the network card's hardware interrupt in response to a hardware interrupt sent by the network card;
[0173] The startup module 1204 is also used to re-enable the network card's hard interrupt in response to the completion of processing of all data packets of the target format in the memory.
[0174] It should be noted that the data receiving device provided in the above embodiments is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the data receiving device and the data receiving method embodiments provided in the above embodiments belong to the same concept, and the implementation process is detailed in the method embodiments, which will not be repeated here.
[0175] Figure 13 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present disclosure, such as... Figure 13 As shown, the computer device 1300 includes a memory 1301 and a processor 1302, as those skilled in the art will understand. Figure 13 The structure of the computer device 1300 shown in the figure does not constitute a limitation on the computer device 1300. In actual application, it may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0176] Memory 1301 can be used to store computer programs and modules. Memory 1301 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function, etc. Memory 1301 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, memory 1301 may also include a memory controller to provide processor 1302 with access to memory 1301.
[0177] The processor 1302 executes various functional applications and data processing by running software programs and modules stored in the memory 1301, such as performing the methods provided in the embodiments of this disclosure.
[0178] In an exemplary embodiment, a computer device is also provided, the computer device including a processor and a memory; wherein the memory is used to store a computer program; the processor is used to execute the computer program stored in the memory, and is capable of executing the data receiving method provided in the embodiments of this disclosure.
[0179] In an exemplary embodiment, a computer-readable storage medium is also provided. This computer-readable storage medium is a non-volatile storage medium that stores a computer program. When the computer program in the computer-readable storage medium is executed by a processor, it can perform the data receiving method provided in the embodiments of this disclosure.
[0180] In an exemplary embodiment, a computer program product is also provided, which stores instructions that, when run on a computer, enable the computer to execute the data receiving method provided in the embodiments of this disclosure.
[0181] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0182] The above description is merely an optional embodiment of this disclosure and is not intended to limit this disclosure. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this disclosure should be included within the protection scope of this disclosure.
Claims
1. A data receiving method characterized by comprising: The invention is applied to a terminal device, which includes multiple processors, memory, a first memory and a second memory. The read / write speed of the first memory is higher than that of the second memory. Each of the multiple processors runs a first thread, which is used to perform format conversion on the data in the kernel buffer in the memory. The method includes: The received data is written to the kernel buffer; In response to a hardware interrupt sent by the network card, a software interrupt handler is started; The first thread on the plurality of processors is called by the soft interrupt handler to convert the data in the kernel buffer into the target format. The first thread is the ksoftirqd thread, which is the thread that is woken up by the kernel when performing soft interrupt handling. The target format data is processed layer by layer according to the protocol stack; The processed data is written into the first memory; Transfer the data from the first memory to the second memory.
2. The method of claim 1, wherein, The data includes multiple network frames, and the kernel buffer includes multiple queues. The data in each queue is format-converted by a corresponding first thread. The step of writing the received data into the kernel buffer includes: Each of the multiple network frames is added to one of the multiple queues.
3. The method of claim 2, wherein, The step of adding each of the plurality of network frames to one of the plurality of queues includes: Get the load of each processor; The first queue is determined based on the size of the load. Add the first network frame to the first queue, where the first network frame is any one of the plurality of network frames.
4. The method of claim 3, wherein, Determining the first queue based on the size of the load includes: The queue corresponding to the processor with the lowest load is designated as the first queue; Alternatively, the queue corresponding to any one of the processors whose load does not exceed the threshold can be used as the first queue.
5. The method of claim 1, wherein, The terminal device further includes a wireless communication module, which is connected to the processor via a USB interface; The step of writing the received data into the kernel buffer includes: The data received by the wireless communication module is stored in a USB request block; The data in the USB request block is copied to the kernel buffer via the USB network card driver.
6. The method according to any one of claims 1 to 5, characterized in that, The step of transferring data from the first memory to the second memory includes: When certain conditions are met, data in the first memory is transferred to the second memory, wherein the conditions include at least one of the following: The storage capacity of the first memory has reached the storage threshold; Data transfer instruction received; The terminal device is in an idle state.
7. The method according to any one of claims 1 to 5, characterized in that, The method further includes: In response to a hardware interrupt sent by the network card, disable the network card's hardware interrupts; In response to the completion of processing of all data packets of the target format in the memory, the hardware interrupt of the network card is re-enabled.
8. A data receiving device, characterized in that, include: Memory modules, including kernel buffers; Multiple processing modules, each of which runs a first thread, the first thread being used to perform format conversion on the data in the kernel buffer; The receiving module is used to write the received data into the kernel buffer; The startup module is used to start the software interrupt handler in response to a hardware interrupt sent by the network card. The conversion module is used to call the first thread on the plurality of processing modules through the soft interrupt handler to convert the data in the kernel buffer into the target format. The first thread is the ksoftirqd thread, which is the thread that the kernel wakes up when performing soft interrupt handling. A first memory and a second memory, wherein the read / write speed of the first memory is higher than that of the second memory; The processing module is used to process the target format data layer by layer according to the protocol stack; The writing module is used to write the processed data into the first memory; A transfer module is used to transfer data from the first memory to the second memory.
9. The apparatus according to claim 8, characterized in that, The data includes multiple network frames, and the kernel buffer in the memory module includes multiple queues. The data in each queue is format-converted by a corresponding first thread. The receiving module is used to add each of the multiple network frames into one of the multiple queues.
10. The apparatus according to claim 9, characterized in that, The receiving module includes: The `get` submodule is used to obtain the load of each processor; A determination submodule is used to determine the first queue based on the size of the load; The addition submodule is used to add a first network frame to the first queue, wherein the first network frame is any one of the plurality of network frames.
11. The apparatus according to claim 10, characterized in that, The determining submodule is used for, The queue corresponding to the processing module with the least load is designated as the first queue; Alternatively, the queue corresponding to any one of the processing modules whose load does not exceed the threshold can be used as the first queue.
12. The apparatus according to claim 8, characterized in that, The data receiving device further includes a wireless communication module, which is connected to the processing module via a USB interface; The receiving module is used to store the data received by the wireless communication module into a USB request block; The data in the USB request block is copied to the kernel buffer via the USB network card driver.
13. The apparatus according to any one of claims 8 to 12, characterized in that, The transfer module is used to transfer data from the first memory to the second memory when a set condition is met, wherein the set condition includes at least one of the following: The storage capacity of the first memory has reached the storage threshold; Data transfer instruction received; The device is in an idle state.
14. The apparatus according to any one of claims 8 to 12, characterized in that, The device further includes: Disable module, used to disable the network card's hardware interrupt in response to hardware interrupts sent by the network card; The startup module is also used to re-enable the network card's hardware interrupt in response to the completion of processing all data packets of the target format in the memory.
15. A computer device, characterized in that, The computer device includes a processor and memory; The memory is used to store computer programs; the processor is used to execute the computer programs stored in the memory to implement the method according to any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, enable the implementation of the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Method for improving the efficiency of network packet processing
CN109117270A
Data packet transceiving method and device, and medium
CN111211942A
Network message processing method and network access equipment
CN111884945A