Data writing method and device, data reading method and device, electronic equipment and storage medium

By performing block management and local metadata statistics on the circular storage queue, global metadata access is reduced and specific instructions are used for data exchange, the efficiency of the circular storage queue in a multi-threaded environment is solved, and system performance and throughput are improved.

CN118963991APending Publication Date: 2024-11-15HUAWEI TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410932151.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2022-07-08
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

In a multi-threaded environment, the existing circular storage queues have reduced system operation efficiency due to mutual waiting when writing and reading data, high bus preemption, poor multi-core throughput, and each read and write operation requires access and update of global metadata. , resulting in high resource competition and cache miss rate.

Method used

By chunking management of the loop queue, using global write pointers and read pointers to allocate locations, local local metadata is counted in each storage area, reducing access to global metadata, and using FAA and MAX instructions for data exchange and space management, avoiding Allocate space hyperboundary situations to reduce operation complexity and synchronization overhead.

Benefits of technology

Reduces system bus pressure, reduces competitive interference and cache miss rate between readers and writers, improves system performance and scalability, avoids data loss and mutual blockage, and improves overall system performance and throughput.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118963991A_ABST
    Figure CN118963991A_ABST
Patent Text Reader

Abstract

The invention provides a data writing method and device, a data reading method and device, electronic equipment and a storage medium. The data writing method comprises the steps of determining first data to be written into a circular storage queue; a global write pointer of the circular storage queue is obtained, the circular storage queue comprises a plurality of storage areas, each storage area comprises a plurality of sub-areas, and the global write pointer points to a first storage area in the plurality of storage areas; obtaining a first write pointer of the first storage area, and determining the size of the allocated space in the first storage area according to the first write pointer of the first storage area; if it is determined that the size of the allocated space in the first storage area is smaller than the size of the space of the first storage area, FAA operation is carried out on the first storage area to allocate a first sub-area in the first storage area; and writing the first data into the first sub-region. According to the method, the system performance can be improved, and the Cache Miss rate can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application. The application number of the original application is 202210806780.3, and the original application date is July 8, 2022. The entire contents of the original application are incorporated into this application by reference. Technical Field

[0002] The present application relates to the technical field of data storage, and in particular to a data writing method, a reading method, a device, an electronic device, and a storage medium. Background Art

[0003] In the operating system, a circular storage queue is a special first-in-first-out (FIFO) queue. The circular storage queue connects the last position in the storage space to the first position to form a logical ring space. As a general data structure, the circular storage queue is widely used in scenarios such as sending and receiving data packets in network communications and recording log data in kernel profiling tools. For example, a lock-free circular storage queue is implemented in the Data Plane Development Kit (DPDK) to realize data transmission between the network card and the kernel; in the Linux system tracking tool ftrace, a circular storage queue is also used to access log data.

[0004] The existing circular storage queue includes corresponding global metadata, and the global metadata includes a global write pointer and a global read pointer. The thread can store data at the global write pointer position and read data at the global read pointer position. In the existing data writing method, after each thread writes the corresponding data into the circular storage queue, it is necessary to perform sequential commit operations in the allocation order, resulting in a problem of mutual waiting between multiple threads writing data. There are also similar mutual waiting operations between multiple threads reading data, and this mutual waiting operation reduces the system operation efficiency. At the same time, each thread shares the global metadata, and the global metadata must be read each time the read and write position is determined, and the global metadata must be updated each time a read and write operation is performed, resulting in high bus preemption and poor multi-core throughput. Summary of the invention

[0005] Some embodiments of the present application provide a data writing method, a reading method, a device, an electronic device, and a storage medium. The present application is introduced from multiple aspects below, and the embodiments and beneficial effects of the following aspects can be referenced to each other.

[0006] In a first aspect, an embodiment of the present application provides a data writing method, which is applied to an electronic device. The execution subject of the data writing method can be a thread, an operating system, or an electronic device with an operating system installed. The method includes:

[0007] Determining first data to be written into the circular storage queue;

[0008] Obtaining a global write pointer of the circular storage queue, wherein the circular storage queue includes a plurality of storage areas, each storage area includes a plurality of sub-areas, and the global write pointer points to a first storage area in the plurality of storage areas;

[0009] Obtaining a first write pointer of the first storage area, and determining the size of the allocated space in the first storage area according to the first write pointer of the first storage area;

[0010] Determining that the size of the space already allocated in the first storage area is smaller than the size of the space of the first storage area, allocating a first sub-area in the first storage area by performing an FAA operation on the first storage area;

[0011] The first data is written into the first sub-area.

[0012] According to the implementation mode of the present application, the circular queue is managed in blocks, the writer position is allocated using a global write pointer, and the information produced is locally counted in each storage area (including local metadata related to the writer: the first write pointer allocated and the second write pointer committed). The electronic device only needs to access the local metadata related to the writer in the storage area to determine the writable state of the storage area, without accessing the local metadata and global metadata related to the reader, which reduces the pressure on the system bus, reduces the competition and interference between readers and writers, and reduces the cache misses (Cache Miss) caused by the metadata being updated by the reader, thereby improving the overall performance of the system. In addition, by using the FAA instruction to implement data exchange operations and record the size of the allocated space, there is no need to consider the situation where the allocated space exceeds the upper limit, which effectively reduces the complexity of the operation, reduces the system synchronization overhead, and improves the scalability of the system.

[0013] In some embodiments, the method further comprises:

[0014] Determining that the size of the allocated space in the first storage area is equal to the size of the space in the first storage area, and determining that the state of the second storage area is a writable state, wherein the second storage area is a next storage area adjacent to the first storage area;

[0015] The global write pointer is updated so that the updated global write pointer points to the second storage area.

[0016] According to an embodiment of the present application, after determining that the first storage area has no storage space, the electronic device can determine whether to update the global write pointer based on the state of the next storage area (ie, the second storage area) adjacent to the first storage area.

[0017] In some implementations, determining that the state of the second storage area is a writable state includes:

[0018] It is determined that the second storage area is in an unallocated state.

[0019] According to an implementation manner of the present application, when the second storage area has not been allocated, the electronic device determines that data can be written directly without determining the reading and writing status of the second storage area in the previous round.

[0020] In some implementations, determining that the state of the second storage area is a writable state includes:

[0021] Determine that the size of the space in the second storage area that has been read is equal to the size of the space in the second storage area; and

[0022] Determining that the number of local read wraparounds that have been read in the second storage area is equal to the number of global write wraparounds;

[0023] Wherein, the number of global write wraparounds is determined according to the global write pointer;

[0024] The size of the space that has been read in the second storage area and the number of local read wraps that have been read are determined based on the second read pointer of the second storage area, and the second read pointer of the second storage area is obtained when the current data writing mode is the first mode.

[0025] According to the implementation mode of the present application, when the current data writing mode is the first mode, the electronic device cannot update the global write pointer when the last round of data in the second storage area has not been read completely, otherwise the last round of written data may be overwritten, resulting in data loss.

[0026] It should be understood that in the embodiment of the present application, each storage area also counts the consumed information locally (including local metadata related to the reader: the first read pointer reserved and the second read pointer consumed). After the first storage area has been allocated, the electronic device can access the local metadata related to the reader in the second storage area (i.e., the next storage area) to determine whether the last round of reading in the second storage area has been completed. If it has been completed, the global write pointer will be updated. There is no need to access the global metadata, which reduces the pressure on the system bus, improves the overall system performance, and reduces the competition and interference between readers and readers, and readers and writers, ensuring the reliability of the system.

[0027] In addition, in the embodiment of the present application, the size of the space that has been read in the storage area is used to determine whether the last round of reading in the storage area is complete, and the judgment is made based on the dimension of the storage area. Therefore, inside each storage area of ​​the circular storage queue, the disorderly destruction (consumption) of the reader does not affect the judgment of the state of whether the storage area has been read, that is, the disorderly consumption does not affect the correctness of the written data. Therefore, after reading data in each storage area of ​​the circular storage queue, the thread does not need to wait for other threads to complete the consume operation, avoiding mutual blocking between readers, thereby improving the system throughput.

[0028] In some implementations, determining that the state of the second storage area is a writable state includes:

[0029] Determine that the size of the space that has been written in the second storage area is equal to the size of the space of the second storage area; and

[0030] Determining that the number of local write-back wraps written in the second storage area is equal to the number of global write-back wraps;

[0031] Wherein, the number of global write wraparounds is determined according to the global write pointer;

[0032] The size of the space that has been written in the second storage area and the number of local write wraps that have been written are determined based on the second write pointer of the second storage area, and the second write pointer of the second storage area is obtained when the current data writing mode is the second mode.

[0033] According to the implementation mode of the present application, when the current data writing mode is the second mode, the electronic device cannot update the global write pointer when the previous round has not been written to the second storage area. Otherwise, two threads may write data to the same sub-area at the same time, thereby causing system abnormality.

[0034] It should be understood that in the embodiment of the present application, after the first storage area has been allocated, the electronic device can access the local metadata related to the writer in the second storage area (i.e., the next storage area) to determine whether the previous round of writing in the second storage area has been completed. The global write pointer is updated only when it has been completed, without the need to access the global metadata, thereby alleviating the pressure on the system bus, reducing the competition and interference between writers, and improving the overall performance of the system.

[0035] In a second aspect, an embodiment of the present application provides a data reading method, which is applied to an electronic device, and the method includes:

[0036] Obtaining a global read pointer of a circular storage queue storing data to be read, wherein the circular storage queue includes a plurality of storage areas, each storage area includes a plurality of sub-areas, and the global read pointer points to a third storage area among the plurality of storage areas;

[0037] Obtaining a first write pointer and a second write pointer of the third storage area, determining the size of the allocated space in the third storage area according to the first write pointer of the third storage area, and determining the size of the written space in the third storage area according to the second write pointer of the third storage area;

[0038] Determining that the size of the space that has been written in the third storage area is equal to the size of the space that has been allocated in the third storage area, and then performing a MAX operation on the third storage area to occupy the second sub-area in the third storage area;

[0039] The second data stored in the second sub-region is read.

[0040] According to an embodiment of the present application, the electronic device can determine the commit status of the third storage area based on the size of the space that has been written in the third storage area and the size of the space that has been allocated in the third storage area. The commit status includes full commit and incomplete commit. Full commit means that the size of the space that has been written in the third storage area is equal to the size of the space that has been allocated in the third storage area, and incomplete commit means that the size of the space that has been written in the third storage area is less than the size of the space that has been allocated in the third storage area. When the electronic device determines that the commit status of the third storage area is full commit, it occupies the second sub-area in the third storage area by using the MAX instruction, and reads the second data in the second sub-area.

[0041] It should be understood that in the embodiment of the present application, the circular queue is managed in blocks, the reader position is allocated using a global read pointer, and the information produced is locally counted in each storage area (including local metadata related to the writer: the first write pointer allocated and the second write pointer committed). The electronic device can access the local metadata related to the writer in the storage area to determine the commit state of the storage area, and only read the data when the commit state of the storage area is fully committed, which can reduce the competition and interference between readers and writers. In addition, the commit state of the storage area is determined in the embodiment of the present application using the size of the space that has been written in the storage area, which is a judgment based on the dimension of the storage area. Therefore, within each storage area of ​​the circular storage queue, the out-of-order commit of the writer does not affect the judgment of the commit state, that is, the out-of-order commit does not affect the correctness of the read data. Therefore, after writing data in each storage area of ​​the circular storage queue, the thread does not need to wait for other threads to complete the commit operation, avoiding mutual blocking between writers, thereby improving the system throughput.

[0042] In some embodiments, before the performing of the MAX operation on the third storage area to occupy the second sub-area in the third storage area, the method further comprises:

[0043] Determine that the size of the occupied space in the third storage area is smaller than the size of the written space in the third storage area;

[0044] The size of the occupied space in the third storage area is determined based on the first read pointer of the third storage area.

[0045] According to an embodiment of the present application, the electronic device can determine whether the subspace in the third storage area that has been written is completely occupied based on the size of the occupied space in the third storage area and the size of the written space in the third storage area. When the electronic device determines that the subspace in the third storage area that has been written is completely occupied, it indicates that there is no data written and not read in the third storage area, and the electronic device cannot read the data. Therefore, the electronic device does not need to determine the commit status of the third storage area, thereby saving system processing resources.

[0046] It should be understood that in the embodiment of the present application, each storage area also counts the consumed information locally (including the local metadata related to the reader, reserved and consumed). The electronic device only needs to access the local metadata related to the reader in the storage area to determine whether the storage area is fully occupied, without accessing the global metadata, which reduces the pressure on the system bus, reduces the competition and interference between readers and writers, and improves the overall performance of the system.

[0047] In some implementations, performing a MAX operation on the third storage area to occupy the second sub-area in the third storage area includes:

[0048] Increasing the first read pointer of the third storage area by performing a MAX operation, and determining whether the first read pointer of the third storage area is updated by other threads;

[0049] If the first read pointer of the third storage area is not updated by other threads, the second sub-area in the third storage area is occupied.

[0050] It should be understood that by using the MAX instruction to implement data exchange operations and record the size of the occupied space, there is no need to consider the situation where the allocated space exceeds the upper limit, which effectively reduces the operation complexity, reduces the system synchronization overhead, and improves the scalability of the system.

[0051] In some implementations, reading the second data stored in the second sub-region includes:

[0052] Determining that the current data writing mode is the second mode, and the number of local write wraparounds allocated in the third storage area is equal to the number of local read wraparounds occupied in the third storage area, then reading and returning the second data stored in the second sub-area;

[0053] The number of local write wraparounds that have been allocated in the third storage area is determined based on the first write pointer of the third storage area, and the number of local read wraparounds that have been occupied in the third storage area is determined based on the first read pointer of the third storage area.

[0054] According to the implementation mode of the present application, the electronic device can determine whether to overwrite the second sub-area based on the number of local write wraps that have been allocated in the third storage area and the number of local read wraps that have been occupied in the third storage area. When the current data write mode is the second mode, when the electronic device determines that the second sub-area has been overwritten, it indicates that the data stored in the second sub-area has changed and needs to be re-read.

[0055] It should be understood that when the current data writing mode of the electronic device is the second mode, it only needs to access the local metadata related to the reader in the storage area to determine whether the sub-area in the corresponding storage area is overwritten, and there is no need to access the global metadata. This not only ensures that the data read by the reader is the data written in the latest round and ensures the real-time data reading, but also reduces the pressure on the system bus and improves the overall performance of the system.

[0056] In some embodiments, the method further comprises:

[0057] Determining that the size of the occupied space in the third storage area is equal to the size of the space in the third storage area, and determining that the state of the fourth storage area is a readable state, wherein the fourth storage area is the next storage area adjacent to the third storage area;

[0058] The global read pointer is updated so that the updated global read pointer points to the fourth storage area.

[0059] According to an embodiment of the present application, the electronic device can determine whether the third storage area is fully occupied based on the size of the space already occupied in the third storage area. When the electronic device determines that the third storage area is fully occupied, it can determine whether to update the global read pointer based on the state of the next storage area (i.e., the fourth storage area) adjacent to the third storage area.

[0060] In some implementations, determining that the state of the fourth storage area is a readable state includes:

[0061] Determine that the number of local write wraparounds written in the fourth storage area is equal to the number of global read wraparounds plus 1;

[0062] Wherein, the number of global read wraparounds is determined according to the global read pointer;

[0063] The number of partial write wraps that have been written in the fourth storage area is determined based on a second write pointer of the fourth storage area, and the second write pointer of the fourth storage area is obtained when the current data writing mode is the first mode.

[0064] According to an implementation manner of the present application, the electronic device can determine whether a new round of data has been written in the fourth storage area based on the number of local write wraparounds and the number of global read wraparounds that have been written in the fourth storage area. When the current data writing mode is the first mode, the electronic device determines that the state of the fourth storage area is a readable state and updates the global read pointer when determining that a new round of data has been written in the fourth storage area. When the electronic device determines that a new round of data has not been written in the fourth storage area, it indicates that unread data has not been written in the fourth storage area, and the electronic device cannot read the data. When the electronic device determines that more than one round of new data has been written in the fourth storage area, it indicates that an abnormality has occurred in the system.

[0065] It should be understood that when the electronic device determines that the third storage area has been fully occupied, it can access the local metadata related to the reader in the fourth storage area (i.e., the next storage area) to determine whether a new round of data has been written in the fourth storage area. The global read pointer is updated only when a new round of data has been written. This can reduce the access to global metadata, alleviate the pressure on the system bus, improve the overall performance of the system, and ensure the reliability of the system.

[0066] In some implementations, determining that the state of the fourth storage area is a readable state includes:

[0067] Determine that the number of local write wraps written in the fourth storage area is greater than or equal to the sum of the number of local read wraps occupied in the third storage area and the target increment;

[0068] The number of partial write wraps that have been written in the fourth storage area is determined based on a second write pointer of the fourth storage area, and the second write pointer of the fourth storage area is obtained when the current data writing mode is the second mode;

[0069] The number of occupied local read wraparounds in the third storage area is determined based on a first read pointer of the third storage area, and the target increment value is determined based on a position of the third storage area.

[0070] According to an implementation manner of the present application, the electronic device can determine whether at least one new round of data has been written in the fourth storage area based on the number of local write wraparounds that have been written in the fourth storage area and the number of local read wraparounds that have been occupied in the third storage area. In the case where the current data writing mode is the second mode, when the electronic device determines that at least one new round of data has been written in the fourth storage area, it determines that the state of the fourth storage area is a readable state and updates the global read pointer. When the electronic device determines that a new round of data has not been written in the fourth storage area, it indicates that unread data has not been written in the fourth storage area, and the electronic device cannot read the data.

[0071] It should be understood that when the electronic device determines that the third storage area has been fully occupied, it can access the local metadata related to the reader in the fourth storage area (i.e., the next storage area) to determine whether at least one new round of data has been written in the fourth storage area. The global read pointer is updated only when at least one new round of data has been written. This can reduce the access to global metadata, alleviate the pressure on the system bus, improve the overall performance of the system, and ensure the reliability of the system.

[0072] In some embodiments, the method further comprises:

[0073] A MAX operation is performed on the fourth storage area to set the number of local read wraparounds that have been occupied in the fourth storage area to the number of local write wraparounds that have been written in the fourth storage area.

[0074] In a third aspect, an embodiment of the present application provides a data writing device, which is provided in an electronic device, and the device includes:

[0075] A determination module, used for determining first data to be written into the circular storage queue;

[0076] A first acquisition module, configured to acquire a global write pointer of the circular storage queue, wherein the circular storage queue includes a plurality of storage areas, each storage area includes a plurality of sub-areas, and the global write pointer points to a first storage area in the plurality of storage areas;

[0077] a second acquisition module, configured to acquire a first write pointer of the first storage area, and determine a size of an allocated space in the first storage area according to the first write pointer of the first storage area;

[0078] an allocation module, configured to determine that the size of the allocated space in the first storage area is smaller than the size of the space in the first storage area, and allocate a first sub-area in the first storage area by performing an FAA operation on the first storage area;

[0079] A writing module is used to write the first data into the first sub-area.

[0080] In a fourth aspect, an embodiment of the present application provides a data reading device, which is provided in an electronic device, and the device includes:

[0081] A third acquisition module is used to acquire a global read pointer of a circular storage queue storing data to be read, wherein the circular storage queue includes multiple storage areas, each storage area includes multiple sub-areas, and the global read pointer points to a third storage area among the multiple storage areas;

[0082] A fourth acquisition module is used to acquire the first write pointer and the second write pointer of the third storage area, determine the size of the allocated space in the third storage area according to the first write pointer of the third storage area, and determine the size of the written space in the third storage area according to the second write pointer of the third storage area;

[0083] an occupation module, configured to determine that the size of the space that has been written in the third storage area is equal to the size of the space that has been allocated in the third storage area, and then occupy the second sub-area in the third storage area by performing a MAX operation on the third storage area;

[0084] A reading module is used to read the second data stored in the second sub-area.

[0085] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing instructions executed by one or more processors of the electronic device; a processor, when the processor executes the instructions in the memory, the electronic device can execute the data writing method provided by any embodiment of the first aspect of the present application or the data reading method provided by any embodiment of the second aspect of the present application. The beneficial effects that can be achieved in the fifth aspect can refer to the beneficial effects of any embodiment of the first aspect of the present application or the beneficial effects of any embodiment of the second aspect of the present application, and will not be repeated here.

[0086] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, on which instructions are stored, and when the instructions are executed on a computer, the computer executes the data writing method provided by any embodiment of the first aspect of the present application or executes the data reading method provided by any embodiment of the second aspect of the present application. The beneficial effects that can be achieved in the sixth aspect can refer to the beneficial effects of any embodiment of the first aspect of the present application or the beneficial effects of any embodiment of the second aspect of the present application, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0087] Figure 1 A schematic diagram of an application scenario provided for an embodiment of the present application;

[0088] Figure 2 A schematic diagram of an application scenario provided for another embodiment of the present application;

[0089] Figure 3 A schematic diagram of an application scenario provided for another embodiment of the present application;

[0090] Figure 4a is a schematic diagram of the structure of a circular storage queue according to some embodiments;

[0091] Figure 4b to Figure 4e A schematic diagram of multiple writers writing data according to some embodiments;

[0092] Figure 5 A flowchart of a data writing method provided by one embodiment of the present application;

[0093] Figure 6 A schematic diagram of the structure of a circular storage queue provided for one embodiment of the present application;

[0094] Figure 7 A flowchart of a data writing method provided by another embodiment of the present application;

[0095] Figure 8 A schematic diagram of the structure of a circular storage queue provided in another embodiment of the present application;

[0096] Fig. 9 A flowchart of a data reading method provided by an embodiment of the present application;

[0097] Fig.10 A flowchart of a data reading method provided by another embodiment of the present application;

[0098] Figures 11a to 11c A performance comparison diagram provided by an embodiment of the present application is shown;

[0099] Fig.12 A performance comparison diagram provided for another embodiment of the present application;

[0100] Fig.13 A block diagram of a data writing device provided by one embodiment of the present application;

[0101] Fig.14 A block diagram of a data reading device provided by one embodiment of the present application;

[0102] Fig.15 A block diagram of an electronic device provided for one embodiment of the present application;

[0103] Fig.16A schematic diagram of the structure of a system on chip (SOC) provided in one embodiment of the present application. DETAILED DESCRIPTION

[0104] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. In order to facilitate the understanding of the solution of the present application, some professional terms involved in the embodiments of the present application are first introduced below.

[0105] Weak memory model: Under the architecture defined by a specific combination of central processing unit (CPU) and tool chain, the memory access sequence executed by the program may be inconsistent with the order in which the code is written. The architecture with arbitrary memory access reordering is called weak memory order architecture, and the rules for its reordering are called weak memory model.

[0106] Atomic operation: Atomic operation refers to an operation that will not be interrupted by the thread scheduling mechanism; once this operation starts, it will run until it ends without switching to another thread in the middle.

[0107] Compare and Swap (CAS) operation: An atomic operation used to implement uninterrupted data exchange operations in multi-threaded programming, thereby avoiding data inconsistency problems caused by uncertainty in execution order and unpredictable interruptions when multiple threads simultaneously rewrite a certain data.

[0108] Head: In a circular storage queue, the head refers to the location where the next read or write occurs.

[0109] Writer (producer, producer) / Reader (consumer, consumer): Producer refers to the thread that writes data to the circular storage queue, and consumer refers to the thread that reads data from the circular storage queue.

[0110] MAX operation: An atomic operation, similar to the CAS operation, used to compare two values. If the second value is greater than the first value, the second value is assigned to the first value and the first value before the update is returned; if the second value is less than or equal to the first value, the first value is returned directly without updating.

[0111] Fetch And Add (FAA) operation: An atomic operation that increases the contents of a storage location by a specified value.

[0112] Figure 1 A schematic diagram of an application scenario provided by an embodiment of the present application is shown. Figure 1As shown, the method provided in the embodiment of the present application can be applied to the memory pool module of the storage product. Specifically, the compressed data in the memory pool 110 is written into the circular storage queue 120, the thread reads data from the circular storage queue 120, and stores the read data into the object cache 130 for use by the operating system kernel 140. The circular storage queue and the corresponding data writing method and data reading method provided in the embodiment of the present application can improve the end-to-end performance of the product by 4%.

[0113] Figure 2 FIG. 2 shows a schematic diagram of an application scenario provided by another embodiment of the present application. Figure 2 As shown, the method provided in the embodiment of the present application can be applied to the scenario of the network card driver sending and receiving data packets. Specifically, the network card driver 210 communicates with the kernel space 220 through the circular storage queue 211. When the input data packet arrives at the network card, the network card driver 210 first stores the input data packet in the network card memory 212, and writes the input data packets in the network card memory 212 into the circular storage queue 211 one by one by calling the direct memory access engine (Direct Memory Access Engine, DMA Engine) 213. After DMAEngine213 reads the input data packet in the network card memory 212, the interrupt generator 214 can trigger an interrupt request. After the interrupt handler 221 of the kernel space 220 receives the interrupt request, the network card 222 can register the poll function, use the poll function to read the data packet from the circular storage queue 211, and put it into the list to transfer the data packet stored in the network card memory 212 to the kernel memory 223. When the poll function is reading data packets, the interrupt request will be disabled so that no new interrupt request will be made before the poll function has finished reading all data packets. After the poll function has finished reading the data, the interrupt request will be enabled. The Internet protocol layer 224 can obtain the data packet from the list and put it into the socket waiting connection queue 225. The transmission control protocol process 226 can obtain the data packet from the socket waiting connection queue 225 and store it in the transmission control protocol receiving buffer 227 to be sent to the application 231 of the user space 230.

[0114] Figure 3 FIG. 2 shows a schematic diagram of an application scenario provided by another embodiment of the present application. Figure 3As shown, the method provided by the embodiment of the present application can be applied to high-frequency trading scenarios. Specifically, the receiver 310 is used to receive data and write the received data into the circular storage queue 321 in the input disruptor 320. The logger 322, the replicator 223 and the decoder 324 can read the data in the circular storage queue 321 to perform logging, replication and deserialization operations. The business logic consumer 330 can read the data in the circular storage queue 321, and the data is processed by the business logic processor 340 and sent to the business logic producer 350. The business logic producer 350 can write the received data into the circular storage queue 361 in the output disruptor 360. The encoder 362 and the publisher 370 can read the data in the circular storage queue 361 to perform serialization and issuance operations.

[0115] The circular storage queue is a special first-in-first-out queue that connects the first position of the sequential queue, that is, the last position of the storage space is connected to the first position, forming a logical circular space. The circular storage queue can not only be used in the above-mentioned Memory pool module, but also can be used in the kernel driver framework to implement communication between devices and protocol stacks, network communication data packets, kernel profiling tools to record log data, and concurrency control basic libraries. Compared with sequential queues, the implementation of circular storage queues is more complicated and special situations such as read and write wraparound need to be considered. In particular, in the case of multiple readers and multiple writers concurrently, it is necessary to consider complex situations such as synchronization between readers and writers, synchronization between writers, and synchronization between readers. Especially in the weak memory model, there is uncertainty in the read and write order, which brings great difficulties to implementation.

[0116] Figure 4a FIG. 4 shows a schematic diagram of a circular storage queue structure according to some embodiments. Figure 4a As shown, the circular storage queue includes corresponding global write pointers and global read pointers. In the counterclockwise direction, the area between the global write pointer and the global read pointer is storage area b, and the area between the global read pointer and the global write pointer is area a. The data in area a is about to be read, and the data in area b is about to be written. As the data is written and read, the global write pointer and the global read pointer move in the counterclockwise direction. For example, after thread 1 is allocated to storage area b1, the global write pointer moves to storage area b2. After thread 2 is allocated to storage area b2, the global write pointer moves to storage area b3.

[0117] After writing data, different threads update the global metadata in the allocation order and perform sequential commit operations. The allocation order refers to the movement direction of the global write pointer and the global read pointer. For example, in Figure 4a, the allocation order is counterclockwise. Specifically, after writing data in storage area b1, thread 1 performs a commit operation. The commit operation indicates that data has been written to storage area b1, and the data in storage area b1 can be read. Similarly, after writing data in storage area b2, thread 2 performs a commit operation. The commit operation indicates that data has been written to storage area b2, and the data in storage area b2 can be read.

[0118] When executing a sequential commit, even if thread 2 writes data before thread 1, it must wait for thread 1 to complete the commit operation. If thread 1 has not yet executed the commit operation, thread 2 will enter a waiting state and can only execute the commit operation after thread 1 completes the commit operation. During the waiting period, thread 2 needs to frequently determine whether thread 1 has completed the commit operation, which reduces the operating efficiency of the system.

[0119] Specifically, in the first embodiment, refer to Figure 4b to Figure 4e For a multi-reader multi-writer lock-free circular storage queue, when multiple writers (local variable core 1 and local variable core 2) write data to the lock-free circular storage queue, multiple writers first read the global write head pointer prod_head in the global metadata to determine the global write position. Figure 4b As shown, both the local variable core 1 and the local variable core 2 determine that the position 410 pointed to by the global write head pointer prod_head is the global write position (as pointed to by prod_head of the local variable core 1 and the local variable core 2).

[0120] After determining the global write position, the multiple writers perform a head grab operation to confirm their respective write positions. Specifically, the multiple writers update the global write head pointer prod_head through atomic operations respectively. If the update of the global write head pointer prod_head is successful, it means that the head grab is successful. Figure 4c As shown, the local variable core 1 successfully grabs the head, updates the global write head pointer prod_head to point to the next position of the global write position (as pointed to by prod_next of the local variable core 1), and determines that position 410 is the position written by the local variable core 1 (as pointed to by prod_head of the local variable core 1). If the local variable core 2 fails to grab the head, the grab head operation is performed again, and determines that position 420 is the position written by the local variable core 2 (as pointed to by prod_head of the local variable core 2).

[0121] Then, the multiple writers respectively perform write operations at their respective write locations. Figure 4dAs shown, local variable core 1 writes data obj4 to location 410, and local variable core 2 writes data obj5 to location 420. After writing the data, the multiple writers update the global write tail pointer prod_tail in the global metadata in the allocation order to perform a commit operation. Figure 4e As shown, the local variable core 1 first performs a commit operation, and updates the global write tail pointer prod_tail to point to the next position of the position where it is written (such as indicated by prod_next of the local variable core 1). After the operation is completed, the local variable core 2 performs a commit operation.

[0122] When there are multiple readers reading data in the lock-free circular storage queue, similar to multiple writers writing data, multiple readers read the global read head pointer cons_head in the global metadata to determine the global read position. After reading the data, the global read tail pointer cons_tail in the global metadata is updated in the order of occupancy to perform the consume operation. The specific operation process is similar to the above-mentioned multiple writers writing data, and the embodiment of the present application will not be repeated here.

[0123] In the above implementation, after each writer writes data, the global metadata is updated in sequence according to the allocation order, and the commit operation is performed. The writer assigned later needs to wait for the previous writer to complete. There are similar mutual waiting operations for multiple readers, which cause poor multi-core throughput. Each thread shares the global metadata, and the global metadata must be read each time the read and write position is determined. The global metadata must be updated each time a read and write operation is performed, resulting in high bus preemption and poor multi-core throughput.

[0124] Specifically, in the second implementation mode, for a lock-free circular storage queue with multiple readers and writers, two global metadata Head and Tail are set for the lock-free circular storage queue, which respectively represent the write position and read position of the lock-free circular storage queue. A Cycle, Index and IsSafe bit are set for each storage area, where Cycle represents the number of wraps of the circular storage queue, and Index represents the offset in the circular storage queue. In this implementation mode, when the writer writes out of order, in order to ensure the linearization of the operation, when the reader exceeds the writer who writes out of order, it is necessary to close the storage area currently being written, move to the next storage area and read again; in another case, since FAA cannot make atomic judgments and executions, it may cause the reader position to exceed the writer position, and at this time the reader still needs to close the storage area being written. Both scenarios will cause a large performance loss. The specific content of the above implementation mode can refer to the relevant description in the article "A Scalable, Portable, and Memory-Efficient Lock-Free FIFO Queue", and the embodiments of this application will not be repeated here.

[0125] To this end, embodiments of the present application provide a data writing method, a reading method, an apparatus, an electronic device, and a storage medium for reducing cache miss rates and improving overall system performance.

[0126] According to the method provided in the embodiment of the present application, the circular queue is managed in blocks, the writer position is allocated using a global write pointer, and the information produced is locally counted in each storage area (including local metadata related to the writer: the first write pointer allocated and the second write pointer committed). The electronic device can determine the size of the allocated space in the first storage area based on the first write pointer allocated in the first storage area. When the size of the allocated space in the first storage area is less than the size of the space in the first storage area, the electronic device can determine that there is still storage space in the first storage area. When the electronic device determines that there is still storage space in the first storage area, it allocates a first sub-area in the first storage area using the FAA instruction to store the data to be stored.

[0127] In the embodiment of the present application, the circular queue is managed in blocks, so that when readers and writers are not in the same storage area, there is no competition and interference, which reduces the cache miss caused by the data competition between readers and writers, and improves the system performance. At the same time, in the process of allocating storage space for writers, the electronic device only needs to access the local metadata related to the writer in the storage area to determine the writable state of the storage area, without accessing the local metadata and global metadata related to the reader, which reduces the pressure on the system bus, reduces the competition and interference between readers and writers in the same storage area, and reduces the cache miss caused by the metadata updated by the reader, further improving the overall performance of the system. In addition, by using the FAA instruction to implement data exchange operations, the size of the allocated space is recorded, and there is no need to consider the situation where the allocated space exceeds the upper limit, which effectively reduces the operation complexity, reduces the system synchronization overhead, and improves the scalability of the system.

[0128] It should be noted that the above application scenarios are only examples, and the method provided in the embodiments of the present application can also be applied in other scenarios using circular storage queues, such as recording kernel events in an operating system kernel using a circular storage queue, and scenarios such as inter-process communication. It should be understood that the "first", "second", "target", etc. used in this application are only used to distinguish the purpose of description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order. In addition, for simplicity and clarity, reference numbers and / or letters are repeated in multiple figures of the present application. Repetition does not indicate that there is a strict limiting relationship between various embodiments and / or configurations.

[0129] The specific process of the data writing method provided in the embodiment of the present application is introduced below.

[0130] Figure 5 A schematic diagram of an implementation flow of a data writing method provided by an embodiment of the present application is shown. It should be understood that the execution subject of the data writing method can be a thread, an operating system, or an electronic device installed with an operating system. The data writing method will be described later by taking the execution subject as an electronic device as an example.

[0131] The embodiment of the present application adopts another circular storage queue. Specifically, the circular storage queue is divided into M logical storage areas, where M is an integer greater than 1, and each storage area is logically continuous. Each storage area is divided into N logical sub-areas, where N is an integer greater than 1, and each sub-area is logically continuous. The queue header of the circular storage queue includes corresponding global metadata, and the global metadata includes a global write pointer and a global read pointer. As data is written and read, the positions of the global write pointer and the global read pointer change continuously along the logical direction. The area header of each storage area includes corresponding local metadata, and the local metadata includes a first write pointer allocated.

[0132] The space sizes of the various storage areas in the circular storage queue provided in the embodiment of the present application can be the same or different; the space sizes of the various sub-areas can be the same or different. The specific values ​​of the space sizes of the various storage areas / sub-areas can be preset by the user according to actual needs, and the embodiment of the present application does not limit this. Preferably, the space sizes of the various storage areas can be set to be the same, and the space sizes of the various sub-areas can also be set to be the same.

[0133] For example, Figure 6 FIG. 1 shows a schematic diagram of the structure of a circular storage queue provided by an embodiment of the present application. Figure 6 As shown, the circular storage queue includes three storage areas, and the space sizes of the three storage areas can be set as needed. In this embodiment, for the convenience of explanation, it is assumed that the space sizes of the three storage areas are the same. The three storage areas are storage area 610, storage area 620 and storage area 630. Each storage area includes multiple sub-areas, and the space size of each sub-area can also be set as needed. In this embodiment, for the convenience of explanation, it is assumed that the space size of each sub-area is the same. For example, storage area 610 includes sub-area 611, sub-area 612 and sub-area 613. The three storage areas correspond to three first write pointers allocated, and the three storage areas correspond to the three allocated one-to-one.

[0134] like Figure 6 As shown, the circular storage queue includes global metadata 640, and the global metadata 640 includes a global write pointer 641 and a global read pointer 642. Figure 6 In the example, the logical direction is counterclockwise. It should be understood that in practical applications, the logical direction may also be clockwise. The circular storage queue is a logically circular space. Therefore, the global write pointer or the global read pointer may circulate through the same area.

[0135] like Figure 5 As shown, the process of the data writing method includes the following steps S501-S505.

[0136] S501: The electronic device determines first data to be written into a circular storage queue.

[0137] In different scenarios, the first data to be written into the circular storage queue may be different types of data. For example, in a scenario where kernel events are recorded in an operating system kernel using a circular storage queue, the first data is kernel event data, and in a scenario where a network card driver sends and receives data packets, the first data is an input data packet, which is not limited in the embodiments of the present application.

[0138] S502: The electronic device obtains a global write pointer of the circular storage queue, where the global write pointer points to a storage area 610 (as an example of a first storage area) in the circular storage queue.

[0139] In an embodiment of the present application, the electronic device may obtain a global write pointer from the queue head of the circular storage queue, and the global write pointer points to the storage area 610. Specifically, the global write pointer may point to the starting position of the storage area 610, and the starting position may be the first byte of the storage area 610. In the process of writing data, the electronic device writes data in sub-areas. For example, the storage area 610 includes sub-areas 611, sub-areas 612, and sub-areas 613, and the electronic device assigns sub-area 611 to thread 1 and assigns sub-area 612 to thread 2. Thread 1 writes data in the first sub-area 611, and thread 2 writes data in the second sub-area 612.

[0140] S503: The electronic device obtains a first write pointer of the storage area 610, and determines the size of the allocated space in the storage area 610 according to the first write pointer of the storage area 610.

[0141] In an embodiment of the present application, each storage area corresponds to a local metadata, and the local metadata includes a first write pointer allocated, which consists of 64 bits and includes two parts: offset and version. The offset value is used to represent the position of the last allocated sub-area in the corresponding storage area in the last write wrap, and the version value is used to represent the number of local write wraps currently allocated in the corresponding storage area. According to the offset value in the first write pointer allocated, the size of the space allocated in the corresponding storage area in the last write wrap can be determined.

[0142] It should be understood that in the embodiment of the present application, the size of the space that has been allocated in the storage area 610 only includes the size of the storage space that has been allocated to the electronic device in the last write-back wrap. Specifically, as the data is written, the electronic device cyclically allocates the storage space of the storage area 610. For example, in the first write-back wrap, the electronic device allocates the three sub-areas of the storage area 610 to thread 1, thread 2, and thread 3. In the second write-back wrap, the electronic device allocates the three sub-areas of the storage area 610 to thread 2, thread 3, and thread 4. In the last write-back wrap, the electronic device only allocates sub-area 611 to thread 5. Then the size of the space that has been allocated in the storage area 610 is the size of the space of the first sub-area allocated in the last write-back wrap.

[0143] In the embodiment of the present application, the offset value and the version value in the first write pointer allocated change with the allocation operation of the electronic device to allocate storage space in the storage area. For example, the storage area 610 includes sub-area 611, sub-area 612 and sub-area 613. When the storage area 610 is not allocated, the offset value and the version value in the first write pointer allocated of the storage area 610 can both be 0. The electronic device allocates the sub-area 611 to thread 1, at which time, the offset value in the first write pointer allocated of the storage area 610 becomes 1, and the electronic device allocates the sub-area 612 to thread 2, at which time, the offset value in the first write pointer allocated of the storage area 610 becomes 2.

[0144] S504 : The electronic device determines that the size of the allocated space in the storage area 610 is smaller than the size of the space in the storage area 610 , and then allocates a first sub-area in the storage area 610 by performing an FAA operation on the storage area 610 .

[0145] In the embodiment of the present application, the electronic device can compare the size of the allocated space in the storage area 610 with the size of the space in the storage area 610 to determine whether the storage area 610 is fully allocated. When the size of the allocated space in the storage area 610 is less than the size of the space in the storage area 610, it indicates that the storage area 610 is not fully allocated; otherwise, it indicates that the storage area 610 is fully allocated.

[0146] In one embodiment, the global metadata of the circular storage queue may also include the space size of each storage area, and the electronic device may read the space size of the storage area 610 from the queue head of the circular storage queue. Alternatively, the local metadata of each storage area of ​​the circular storage queue may also include the corresponding space size, and the electronic device may read the space size of the storage area 610 from the area head of the storage area 610. It should be understood that the space size of the storage area 610 may be set in advance as needed, and the embodiment of the present application does not limit this.

[0147] In the embodiment of the present application, if the electronic device determines that the storage area 610 has not been fully allocated, the electronic device allocates the first sub-area in the storage area 610 by performing an FAA operation on the storage area 610. Specifically, the first write pointer of the storage area 610 can be incremented by 1 by performing an FAA (blk.allocated, 1) operation to perform the sub-area allocation operation. If the FAA operation is successfully performed, it indicates that the electronic device has updated the first write pointer of the storage area 610.

[0148] It should be understood that the electronic device pre-checks whether the storage area 610 has been fully allocated, which can avoid the problem of data overflow and performance loss caused by performing FAA operations when multiple threads write data even if the size of the allocated space in the storage area 610 is greater than or equal to the size of the space in the storage area 610.

[0149] S505: The electronic device writes the first data into the first sub-area.

[0150] In the embodiment of the present application, data is written according to the allocation-write data-commit process. After the electronic device determines that the first sub-area is successfully allocated in the storage area 610, the first data to be written into the circular storage queue is written into the first sub-area, and a commit operation is performed to complete the data writing.

[0151] In one embodiment of the present application, refer to the attached Figure 7 , Figure 7 FIG. 2 shows a schematic diagram of an implementation flow of a data writing method provided by another embodiment of the present application. Figure 7 As shown, the process includes the following steps S701-S712.

[0152] S701: The electronic device determines first data to be written into a circular storage queue.

[0153] The specific content in step S701 can be found in Figure 5 The relevant description of the illustrated embodiment will not be repeated here for the embodiments of the present application.

[0154] S702: The electronic device obtains a current global write pointer of the circular storage queue, where the current global write pointer points to a current storage area.

[0155] The electronic device can obtain the current global write pointer from the queue head of the circular storage queue. The description of the circular storage queue can refer to the aforementioned Figure 5 or Figure 6 The electronic device obtains the current global write pointer of the circular storage queue, which is also called the current global write pointer. The current global write pointer points to the storage area 610 (as an example of the first storage area) in the circular storage queue, which is also called the current storage area.

[0156] Specifically, the queue head of the circular storage queue can be used to store corresponding global metadata, which includes a global write pointer widx and a global read pointer ridx. The global write pointer widx and the global read pointer ridx are composed of 64 bits, which respectively represent the indexes of the storage areas currently read (ridx) and written (widx). widx and ridx are composed of two parts: index and version. The index value indicates the location of the current read-write storage area, such as the number of the current read-write storage area; the version value indicates the current global read-write wraparound times. The index bit algorithm is as follows:

[0157] |index|=log2(num_block)bits

[0158] Among them, num_block represents the number of storage areas, which can be set by the user and stored in the queue configuration information (buffer config) during initialization. That is to say, the queue head of the circular storage queue can also be used to store configuration information such as the queue size (that is, the number of storage areas) and the space size of each storage area. The remaining bits in widx and ridx except the |index| bit are |version|. Among them, index occupies the low |index| bit of the global metadata, and version occupies the high |version| bit. When the queue is initialized, all version values ​​are 0.

[0159] For example, Figure 8 FIG. 2 shows a schematic diagram of the structure of a circular storage queue provided by another embodiment of the present application. Figure 8As shown, the circular storage queue includes three storage areas. The three storage areas are storage area 810, storage area 820 and storage area 830. Storage area 810 includes sub-area 811, sub-area 812 and sub-area 813, storage area 820 includes sub-area 821, sub-area 822 and sub-area 823, and storage area 830 includes sub-area 831, sub-area 832 and sub-area 833. The circular storage queue also includes a queue head 800. The queue head 800 can be used to store a global write pointer widx and a global read pointer ridx. Figure 8 In the example, the global write pointer widx points to the storage area 820, and the global read pointer ridx points to the storage area 810.

[0160] S703: The electronic device obtains a first write pointer of the current storage area, and determines the size of the allocated space in the current storage area according to the first write pointer of the current storage area.

[0161] The electronic device may obtain the first write pointer from the region header of the current storage region. The description of the current storage region may refer to the aforementioned Figure 5 or Figure 6 Related description.

[0162] Specifically, each storage area may also include a corresponding area header, which is used to store corresponding local metadata. The local metadata may include four pointers: a first write pointer allocated, a second write pointer committed, a first read pointer reserved, and a second read pointer consumed. Similar to global metadata, local metadata is also composed of 64 bits and includes two parts: offset and version. Among them, the offset value in allocated / reserved is used to represent the position of a sub-area that was last allocated / occupied in the corresponding storage area in the last write / read wraparound. According to the offset value in allocated / reserved, the size of the space that has been allocated / occupied in the corresponding storage area in the last write / read wraparound can be determined; the version value in allocated / reserved is used to represent the number of local write wraparounds currently allocated / the number of local read wraparounds currently occupied in the corresponding storage area. The offset value in committed / consumed is used to represent the size of the space that has been written / read in the corresponding storage area in the last write / read wraparound; the version value in committed / consumed is used to represent the number of local write wraparounds currently written / the number of local read wraparounds currently read in the corresponding storage area.

[0163] Specifically, the algorithm for calculating the number of digits of offset is as follows:

[0164] |offset|=1+log2(block_size)bits

[0165] Among them, block_size indicates the number of sub-regions, which can be set by the user and stored in the queue configuration information (buffer config) during initialization. The remaining bits of allocated, committed, reserved, and consumed except for the |offset| bits are the bits of the version |version|, where offset occupies the low |offset| bits of the local metadata and version occupies the high |version| bits. When the queue is initialized, all version values ​​are 0.

[0166] For example, Figure 8 As shown, storage area 810 includes area header 814. Area header 814 is used to store local metadata of storage area 810, including allocated, committed, reserved, and consumed. Similarly, storage area 820 includes area header 824. Storage area 830 includes area header 834.

[0167] S704: The electronic device determines whether the size of the allocated space in the current storage area is smaller than the size of the space in the current storage area.

[0168] In the embodiment of the present application, the electronic device can compare the size of the space that has been allocated in the current storage area with the size of the space in the current storage area to determine whether the current storage area has been allocated. If the electronic device determines that the current storage area has not been allocated, the electronic device executes step S705; if the electronic device determines that the current storage area has been allocated, the electronic device executes step S708.

[0169] S705: The electronic device allocates a first sub-area in the current storage area by performing an FAA operation on the current storage area.

[0170] Among them, other related contents in step S702 to step S705 can be referred to Figure 5 The relevant description of the illustrated embodiment will not be repeated here for the embodiments of the present application.

[0171] S706: The electronic device determines again whether the size of the space allocated in the current storage area before the FAA operation is performed is smaller than the size of the space in the current storage area.

[0172] In the embodiment of the present application, since there may be multiple threads writing data at the same time, the electronic device needs to perform FAA operations on the current storage area respectively and allocate sub-areas to each thread. In order to avoid performing FAA operations at the same time, resulting in the sub-areas in the current storage area being allocated, after step S705, step S706 can also be performed.

[0173] Specifically, the offset value in the first write pointer (recorded as blk.allocated) of the current storage area before the FAA operation is implemented can be obtained, and the obtained offset value can be rechecked to determine whether the size of the allocated space in the current storage area is still smaller than the size of the space in the current storage area. If so, the information of the allocated first sub-area is returned, and the electronic device executes step S707; if not, it is determined that the current storage area has been allocated (i.e., there is no storage space), and the electronic device executes step S708.

[0174] In practical applications, each sub-area may also include a corresponding metadata offset, which is used to indicate the position of the sub-area in the corresponding storage area. The electronic device returns the information EntryDesc of the sub-area allocated in the current storage area, and EntryDesc includes two parts, block and offset, wherein the block value indicates the storage area where the allocated sub-area is located (i.e., the current storage area), and the offset value indicates the position of the allocated sub-area in the corresponding storage area.

[0175] S707: The electronic device writes the first data into the first sub-area.

[0176] The specific content of step S707 can be found in Figure 5 During the commit operation of the electronic device, the second write pointer of the current storage area can be increased by 1. If the commit operation is successful, it indicates that the electronic device has updated the second write pointer of the current storage area.

[0177] S708: When the current storage area has been allocated, the electronic device determines whether the next storage area is in an unallocated state.

[0178] The next storage area is the next storage area that is logically adjacent to the current storage area, that is, the next storage area that is adjacent to the current storage area in the logical direction. Figure 8In the example, if the current storage area is storage area 830, the next storage area is storage area 810 adjacent to storage area 830. When the electronic device determines that the current storage area has been allocated, it can determine whether the next storage area is in an unallocated state. If the electronic device determines that the next storage area is in an unallocated state, the electronic device can determine that the state of the next storage area is a writable state. At this time, the electronic device determines that the current global write pointer can be updated, and the electronic device executes step S711; if the electronic device determines that the next storage area is in an allocated state, the electronic device executes step S709 or executes step S710.

[0179] Specifically, the electronic device can determine whether the next storage area has been allocated according to the first write pointer allocated corresponding to the next storage area. If the offset value and the version value in the first write pointer allocated corresponding to the next storage area are both 0, the electronic device determines that the next storage area has not been allocated; if the offset value or the version value in the first write pointer allocated corresponding to the next storage area is not 0, the electronic device determines that the next storage area has been allocated.

[0180] S709: The electronic device determines whether the previous round in the next storage area has been read completely.

[0181] In an embodiment of the present application, when the electronic device determines that the next storage area has been allocated, the electronic device can determine the current data writing mode. If the current data writing mode is the retry-new mode (as an example of the first mode), when the previous round in the next storage area has not been read, the overwriting data will not be continued to be written to reduce data loss. Therefore, when the current data writing mode of the electronic device is the retry-new mode, it can first determine whether the previous round in the next storage area has been read. If it has been read, it determines that the state of the next storage area is a writable state. At this time, the electronic device determines that the current global write pointer can be updated, and the electronic device executes step S711; if the electronic device determines that the previous round in the next storage area has not been read, and the state of the next storage area is a non-writable state, the electronic device executes step S712.

[0182] Specifically, when the current data writing mode of the electronic device is the retry-new mode, the second read pointer consumed of the next storage area can be obtained, and the size of the space that has been read in the next storage area can be determined according to the offset value in the second read pointer consumed of the next storage area, and the number of local read wraparounds that have been read in the next storage area can be determined according to the version value in the second read pointer consumed of the next storage area. The electronic device determines the number of global write wraparounds according to the current global write pointer. When the electronic device determines that the size of the space that has been read in the next storage area is equal to the size of the space of the next storage area, and determines that the number of local read wraparounds that have been read in the next storage area is equal to the number of global write wraparounds, it can be determined that the previous round in the next storage area has been read, and the state of the next storage area is a writable state, and the electronic device executes step S711. Among them, the size of the space of the next storage area can also be set in advance according to actual needs, and the embodiment of the present application does not limit this.

[0183] Specifically, if the electronic device determines that the size of the space that has been read in the next storage area is not equal to the size of the space in the next storage area, it means that the previous round of reading in the next storage area has not been completed, and the state of the next storage area is not writable, and the electronic device executes step S712.

[0184] Specifically, in the aforementioned step S702, the electronic device obtains the current global write pointer. In a multi-threaded concurrent scenario, there may be other threads that have modified the current global write pointer. For example, there are other threads that have completed the subsequent step S711. Therefore, the electronic device determines whether other threads have updated the current global write pointer by determining whether the number of local read wraparounds that have been read in the next storage area is equal to the number of global write wraparounds. If the above conditions are not met, it means that other threads have already updated the current global write pointer. In this case, the current global write pointer is no longer updated, and the electronic device executes step S712.

[0185] In one embodiment, when the previous round of the next storage area has not been read, the electronic device can also obtain the first read pointer reserved of the next storage area, and determine the size of the occupied space in the next storage area according to the offset value in the first read pointer reserved of the next storage area. The electronic device can determine whether the size of the occupied space in the next storage area is equal to the size of the space that has been read in the next storage area. If so, it means that the previous round of writing in the next storage area has not been completed (that is, not all sub-areas in the storage area have been commite), but all sub-areas that have been written have been read. In this case, it can be defined as the queue is full and can no longer be written. The electronic device returns FULL and executes step S712. In other cases, it means that other threads are performing write or read operations. The electronic device returns BUSY and executes step S712.

[0186] S710: The electronic device determines whether the previous round has been written in the next storage area.

[0187] In the embodiment of the present application, if the current data writing mode is the drop-old mode (as an example of the second mode), when the previous round in the next storage area has not been read, the overwriting data is directly written to improve the efficiency of writing data. Therefore, when the current data writing mode of the electronic device is the drop-old mode, it only needs to determine whether the previous round in the next storage area has been written. If the previous round in the next storage area has been written, it is determined that the state of the next storage area is a writable state. At this time, the electronic device determines that the current global write pointer can be updated, and the electronic device executes step S711; if the electronic device determines that the previous round in the next storage area has not been written, and the state of the next storage area is a non-writable state, the electronic device executes step S712.

[0188] Specifically, when the current data writing mode of the electronic device is the drop-old mode, the second write pointer committed of the next storage area can be obtained, and the size of the space that has been written in the next storage area can be determined according to the offset value in the second write pointer committed of the next storage area, and the number of local write wraps that have been written in the next storage area can be determined according to the version value in the second write pointer committed of the next storage area. The electronic device determines the number of global write wraps according to the current global write pointer. When the electronic device determines that the size of the space that has been written in the next storage area is equal to the size of the space of the next storage area, and determines that the number of local write wraps that have been written in the next storage area is equal to the number of global write wraps, it can be determined that the previous round in the next storage area has been written, and the state of the next storage area is a writable state, and the electronic device executes step S711. .

[0189] Specifically, if the electronic device determines that the size of the space that has been written in the next storage area is not equal to the size of the space in the next storage area, it means that the previous round of writing in the next storage area has not been completed (that is, the sub-area in the storage area has not been completely committed), the state of the next storage area is not writable, the electronic device returns BUSY, and executes step S712. If the electronic device determines that the number of local write-back wraps that have been written in the next storage area is not equal to the number of global write-back wraps, it means that an abnormality has occurred, and the electronic device executes step S712.

[0190] S711: The electronic device updates the current global write pointer so that the updated current global write pointer points to the next storage area.

[0191] In the embodiment of the present application, the electronic device may perform a MAX operation on the first write pointer and the second write pointer of the next storage area to increase the first write pointer and the second write pointer of the next storage area by 1. The electronic device may perform a MAX operation on the current global write pointer to update the current global write pointer so that the current global write pointer points to the next storage area.

[0192] It should be understood that when updating metadata, the electronic device first updates the local metadata and then updates the global metadata. In addition, in the retry-new mode, when the storage area is written, the corresponding local metadata is updated only after the reader has read it. This can reduce the competition and interference between readers and writers and reduce readers' Cache Miss.

[0193] S712: End. The end may mean that the current thread in the electronic device gives up storing the first data, or the current thread in the electronic device returns to step S702.

[0194] In an embodiment of the present application, after the electronic device executes the step S711, it can return to step S702. At this time, the current global write pointer points to the next storage area, and the next storage area can be used as the current storage area to allocate a first sub-area in the next storage area, and write the first data into the first sub-area to complete the data writing.

[0195] The specific process of the data reading method provided in the embodiment of the present application is introduced below.

[0196] Fig. 9 The following is a schematic diagram of the implementation process of a data reading method provided by an embodiment of the present application. It should be understood that the execution subject of the data reading method can be a thread, an operating system, or an electronic device installed with an operating system. The data reading method will be described later using the execution subject being an electronic device as an example. In the embodiment of the present application, the description of the circular storage queue can refer to the aforementioned Figure 7 or Figure 8 Related descriptions. Fig. 9 As shown, the process includes the following steps S901-S904.

[0197] S901: The electronic device obtains a global read pointer of a circular storage queue storing data to be read, wherein the global read pointer points to a storage area 810 (as an example of a third storage area) in the circular storage queue.

[0198] In different scenarios, the data to be read may be different types of data. For example, in a scenario where kernel events are recorded in an operating system kernel using a circular storage queue, the data to be read is kernel event data, and in a scenario where a network card driver sends and receives data packets, the data to be read is an input data packet, which is not limited in the present embodiment of the application.

[0199] In the embodiment of the present application, the electronic device can obtain a global read pointer from the queue head of the circular storage queue, and the global read pointer points to the storage area 810. Specifically, the global read pointer can point to the starting position of the storage area 810, and the starting position can be the first byte of the storage area 810. In the process of reading data, the electronic device reads data in sub-areas. For example, Figure 8 As shown, storage area 810 includes sub-area 811, sub-area 812 and sub-area 813. The electronic device allocates sub-area 811 to thread 1 and allocates sub-area 812 to thread 2. Thread 1 reads data in the first sub-area 811, and thread 2 reads data in the second sub-area 812.

[0200] S902: The electronic device obtains a first write pointer and a second write pointer of the storage area 810, determines the size of the allocated space in the storage area 810 according to the first write pointer of the storage area 810, and determines the size of the written space in the storage area 810 according to the second write pointer of the storage area 810.

[0201] In the embodiment of the present application, the region header of each storage region of the circular storage queue stores corresponding local metadata, and the local metadata includes a first write pointer allocated and a second write pointer committed. The description of the local metadata can refer to the aforementioned Figure 7 or Figure 8 Related description.

[0202] It should be understood that in the embodiment of the present application, the size of the allocated space in the storage area 810 only includes the size of the storage space that has been allocated to the electronic device in the last write-back, and the size of the written space in the storage area 810 only includes the size of the storage space that has been written to the electronic device in the last write-back.

[0203] In the embodiment of the present application, the offset value and version value in the first write pointer allocated / the second write pointer committed are changed with the allocation operation / commit operation of the electronic device to allocate storage space in the storage area. For example, the storage area 810 includes sub-area 811, sub-area 812 and sub-area 813. When the storage area 810 is not allocated, the offset value and version value in the first write pointer of the storage area 810 can both be 0. The electronic device allocates the sub-area 811 to thread 1, at which time, the offset value in the first write pointer of the storage area 810 becomes 1, and the electronic device allocates the sub-area 812 to thread 2, at which time, the offset value in the first write pointer of the storage area 810 becomes 2. After thread 1 writes data to sub-area 811, it performs a commit operation, at which time, the offset value in the second write pointer of the storage area 810 becomes 1, and after thread 2 writes data to sub-area 812, it performs a commit operation, at which time, the offset value in the second write pointer of the storage area 810 becomes 2.

[0204] S903: The electronic device determines that the size of the space that has been written in the storage area 810 is equal to the size of the space that has been allocated in the storage area 810, and then performs a MAX operation on the storage area 810 to occupy the second sub-area in the storage area 810.

[0205] In the embodiment of the present application, the electronic device can determine the commit state of the storage area 810 according to the size of the space that has been written in the storage area 810 and the size of the space that has been allocated in the storage area 810. The commit state includes a complete commit and an incomplete commit. When the electronic device determines that the size of the space that has been written in the storage area 810 is equal to the size of the space that has been allocated in the storage area 810, the commit state of the storage area 810 is determined to be a complete commit; otherwise, the commit state of the storage area 810 is determined to be an incomplete commit (i.e., there are still some sub-areas that have been allocated but not yet committed). Before writing data to the storage area 810, the electronic device needs to allocate the storage space in the storage area 810 to one or more threads. According to the previous description, it can be seen that the electronic device writes data in the storage area 810 cyclically, so the electronic device cyclically allocates the storage space in the third storage space to the thread. It should be understood that in the embodiment of the present application, the size of the space that has been allocated in the storage area 810 only includes the size of the space allocated by the electronic device in the last write-back wrap, and the size of the space that has been written in the storage area 810 only includes the size of the space where the electronic device writes data in the last write-back wrap.

[0206] In the embodiment of the present application, if the electronic device determines that the commit state of the storage area 810 is fully committed, that is, the storage area 810 is determined to be in a readable state, the electronic device occupies the second sub-area in the storage area 810 by performing a MAX operation on the storage area 810. If the electronic device determines that the commit state of the storage area 810 is not fully committed, that is, the storage area 810 is determined to be in an unreadable state, the electronic device returns BUSY and ends the process.

[0207] In one embodiment, if the electronic device determines that the commit state of the storage area 810 is fully committed, it can also obtain the first read pointer reserved of the storage area 810, and determine the size of the occupied space in the storage area 810 according to the offset value in the first read pointer reserved. When the electronic device determines that the size of the occupied space in the storage area 810 is less than the size of the written space in the storage area 810, it can be determined that the subspace that has been written in the storage area 810 has not been occupied; otherwise, it can be determined that the subspace that has been written in the storage area 810 has been occupied. When the electronic device determines that the subspace that has been written in the storage area 810 has not been occupied, the electronic device occupies the second subarea in the storage area 810 by performing a MAX operation on the storage area 810. When the electronic device determines that the subspace that has been written in the storage area 810 has been occupied, it is determined that there is no written data in the storage area 810 that can be read, and the electronic device returns EMPTY and ends the process, or the electronic device updates the global read pointer.

[0208] It should be understood that in the embodiment of the present application, the size of the space already occupied in the storage area 810 only includes the size of the space occupied by the electronic device in the last read wrap. By determining whether the subspace that has been written in the storage area 810 has been occupied, it is ensured that the reader will not exceed the writer, and the reader is prevented from reading old data.

[0209] Specifically, the electronic device can add 1 to the first read pointer of the storage area 810 by implementing the MAX operation, and determine whether the first read pointer of the storage area 810 is updated by other threads; if the first read pointer of the storage area 810 is not updated by other threads, it is determined that the second sub-area in the storage area 810 is occupied.

[0210] In actual applications, the electronic device can perform a MAX (blk.reserved, reversed+1) operation to add 1 to the first read pointer of the storage area 810 to perform the sub-area occupation operation. If the MAX operation is successfully performed, it indicates that the electronic device has updated the first read pointer of the storage area 810. Among them, blk.reserved represents the current first read pointer of the storage area 810 obtained again, and reversed represents the first read pointer obtained in step S902.

[0211] In the embodiment of the present application, since there may be multiple threads that read data at the same time, the electronic device needs to perform MAX operations on the storage area 810 respectively to occupy sub-areas for each thread. In order to avoid the situation where the sub-areas that have been written in the storage area 810 are allocated after the MAX operation is performed at the same time, the electronic device can compare the current first read pointer of the storage area 810 obtained again with the first read pointer obtained in step S902. If it is determined that the current first read pointer of the storage area 810 obtained again is the same as the first read pointer obtained in step S902, the electronic device determines that the first read pointer of the storage area 810 has not been updated by other threads, and the MAX operation is successfully performed, that is, it is determined that the second sub-area is successfully occupied in the storage area 810, and the electronic device returns the information of the second sub-area occupied in the storage area 810. If it is determined that the current first read pointer of the storage area 810 obtained again is different from the first read pointer obtained in step S902, the electronic device determines that the first read pointer of the storage area 810 has been updated by other threads, and the execution of the MAX operation fails. The electronic device determines that the sub-area in the storage area 810 has been occupied by other threads, and the electronic device needs to re-occupy it, that is, the electronic device returns to step S901.

[0212] In actual applications, each sub-area may also include a corresponding metadata offset, which is used to indicate the position of the sub-area in the corresponding storage area. The information EntryDesc of the sub-area occupied in the storage area 810 returned by the electronic device includes three parts: block, offset, and version, wherein the block value indicates the storage area (i.e., storage area 810) where the occupied sub-area is located, the offset value indicates the position of the occupied sub-area in the corresponding storage area, and the version value is used to verify the consistency of the data when the current data writing mode is the drop-old mode (as an example of the second mode).

[0213] It should be understood that the electronic device determines whether the first read pointer of the storage area 810 has been updated by other threads, so as to avoid the problem of data overflow and performance loss caused by performing the occupation operation when multiple threads read data even if the size of the occupied space in the storage area 810 is greater than or equal to the size of the written space in the storage area 810.

[0214] S904: The electronic device reads the second data stored in the second sub-region.

[0215] In the embodiment of the present application, data reading is performed according to the occupation-reading-consume process. After the electronic device determines that the second sub-area in the storage area 810 is successfully occupied, the second data stored in the second sub-area is read and the consume operation is performed to complete the data reading.

[0216] In one embodiment of the present application, refer to the attached Fig.10 , Fig.10 FIG. 2 shows a schematic diagram of an implementation flow of a data reading method provided by another embodiment of the present application. Fig.10 As shown, the process includes the following steps S1001-S1012.

[0217] S1001: The electronic device obtains a current global read pointer of a circular storage queue storing data to be read, where the current global read pointer points to a current storage area.

[0218] In the embodiment of the present application, the electronic device can obtain the current global read pointer from the queue head of the circular storage queue. The description of the circular storage queue can refer to the aforementioned Figure 7 or Figure 8 The electronic device obtains the current global read pointer of the circular storage queue, which is also called the current global read pointer. The current global read pointer points to the storage area 810 (as an example of the third storage area) in the circular storage queue, which is also called the current storage area.

[0219] S1002: The electronic device obtains a first write pointer and a second write pointer of the current storage area, determines the size of the allocated space in the current storage area according to the first write pointer of the current storage area, and determines the size of the written space in the current storage area according to the second write pointer of the current storage area.

[0220] In the embodiment of the present application, the electronic device can obtain the first write pointer and the second write pointer from the region header of the current storage region. The description of the current storage region can refer to the aforementioned Figure 7 or Figure 8 Related description.

[0221] S1003: The electronic device determines whether the size of the space that has been written in the current storage area is equal to the size of the space that has been allocated in the current storage area.

[0222] In an embodiment of the present application, when the electronic device determines that the size of the space that has been written in the current storage area is equal to the size of the space that has been allocated in the current storage area, it determines whether the commit status of the current storage area is fully committed; otherwise, it determines whether the commit status of the current storage area is incompletely committed. If the electronic device determines that the commit status of the current storage area is fully committed, that is, it determines that the current storage area is in a readable state, the electronic device executes step S1004. If the electronic device determines that the commit status of the current storage area is incompletely committed, that is, it determines that the current storage area is in an unreadable state, the electronic device returns BUSY and executes step S1012.

[0223] S1004: The electronic device obtains a first read pointer of the current storage area, and determines the size of the occupied space in the current storage area according to the first read pointer of the current storage area.

[0224] In the embodiment of the present application, the electronic device can obtain the first read pointer from the region header of the current storage region. The description of the current storage region can refer to the aforementioned Figure 7 or Figure 8 Related description.

[0225] S1005: The electronic device determines whether the size of the occupied space in the current storage area is smaller than the size of the written space in the current storage area.

[0226] In the embodiment of the present application, when the electronic device determines that the size of the space already occupied in the current storage area is less than the size of the space already written in the current storage area, it can be determined that the subspace already written in the current storage area has not been completely occupied; otherwise, it can be determined that the subspace already written in the current storage area has been completely occupied. When the electronic device determines that the subspace already written in the current storage area has not been completely occupied, the electronic device executes step S1006; when the electronic device determines that the subspace already written in the current storage area has been completely occupied, the electronic device executes step S1008.

[0227] S1006: When it is determined that the subspace in the current storage area that has been written has not been fully occupied, the electronic device occupies a second subspace in the current storage area by performing a MAX operation on the current storage area.

[0228] S1007: The electronic device reads the second data stored in the second sub-area.

[0229] The specific contents of step S1001 to step S1007 can be referred to Fig. 9 The relevant description of the illustrated embodiment will not be repeated here for the embodiments of the present application.

[0230] In one embodiment, since when the current data writing mode is the drop-old mode (as an example of the second mode), the overwriting data can be directly written when the previous round has not been read in the next storage area. Therefore, when the current data writing mode is the drop-old mode, after the electronic device reads the second data stored in the second sub-area, it can determine whether the second sub-area is overwritten. If the electronic device determines that the second sub-area is not overwritten, the electronic device returns the second data stored in the second sub-area. If the electronic device determines that the second sub-area is overwritten, the electronic device does not return the second data, returns a null value, and returns to step S1001.

[0231] Specifically, when the electronic device determines that the current data write mode is the drop-old mode, the number of local write wraps that have been allocated in the current storage area can be determined according to the version value in the first write pointer allocated of the current storage area, and the number of local read wraps that have been occupied in the current storage area can be determined according to the version value in the first read pointer reserved of the current storage area. When the number of local write wraps that have been allocated in the current storage area is equal to the number of local read wraps that have been occupied in the current storage area, the electronic device can determine that the second sub-area has not been overwritten; otherwise, the electronic device can determine that the second sub-area has been overwritten.

[0232] In actual applications, when the electronic device occupies the second sub-area in the current storage area, the version value in the first read pointer reserved of the current storage area can be saved in the version corresponding to the second sub-area, and then the saved version value corresponding to the second sub-area can be compared with the version value in the first write pointer allocated of the current storage area. If they are the same, the electronic device determines that the second sub-area is not overwritten; if they are not the same, the electronic device determines that the second sub-area is overwritten.

[0233] It should be understood that in the embodiment of the present application, the reader first reads data from the circular storage queue, and then compares the version value in the first write pointer allocated in the current storage area with the version value corresponding to the second sub-area to determine whether the second sub-area has been overwritten, and if it has been overwritten, it is read again. The method provided in the embodiment of the present application makes speculative reading easy to implement, and does not need to consider the situation where the data is not stored continuously at the tail, reduces the cache miss rate, and improves the overall performance of the system.

[0234] S1008: The electronic device determines whether the size of the occupied space in the current storage area is equal to the size of the space in the current storage area.

[0235] In an embodiment of the present application, when the electronic device determines that the sub-space that has been written in the current storage area has been fully occupied, it can determine whether the size of the occupied space in the current storage area is equal to the size of the space of the current storage area, thereby determining whether the current storage area is fully occupied (that is, all sub-areas in the current storage area have been written and occupied).

[0236] In one embodiment, the global metadata of the circular storage queue may also include the space size of each storage area, and the electronic device may read the space size of the current storage area from the queue head of the circular storage queue. Alternatively, the local metadata of each storage area of ​​the circular storage queue may also include the corresponding space size, and the electronic device may read the space size of the current storage area from the area head of the current storage area. It should be understood that the space size of the current storage area may be set in advance as needed, and the embodiment of the present application does not limit this.

[0237] In an embodiment of the present application, if the electronic device determines that the size of the occupied space in the current storage area is equal to the size of the space in the current storage area, then it is determined that the current storage area has been fully occupied, otherwise it is determined that the current storage area has not been fully occupied. When the electronic device determines that the current storage area has been fully occupied, the electronic device determines that the global read pointer needs to be updated, and the electronic device executes step S1009 or step S1010. When the electronic device determines that the current storage area has not been fully occupied, it indicates that the subspace that has been written in the current storage area has been fully occupied, but there is still a subspace that has not been allocated. At this time, the electronic device can determine that there is no data in the current storage area that can be read, the electronic device returns EMPTY, and executes step S1012.

[0238] S1009: The electronic device determines whether a new round of data has been written into the next storage area.

[0239] The next storage area is the next storage area that is logically adjacent to the current storage area, that is, the next storage area that is adjacent to the current storage area in the logical direction. Figure 8, if the current storage area is storage area 830, then the next storage area is storage area 810 adjacent to storage area 830. When the electronic device determines that the current storage area has been occupied and the global read pointer needs to be updated, the electronic device can determine the current data write mode. If the current data write mode is the retry-new mode (as an example of the first mode), then in the case where a new round of data has been written in the next storage area, the electronic device determines that the state of the next storage area is a readable state. In the case where a new round of data has not been written in the next storage area, or more rounds of data have been written, the electronic device determines that the state of the next storage area is an unreadable state. If the electronic device determines that the state of the next storage area is a readable state, the electronic device determines that the current global read pointer can be updated, and the electronic device executes step S1011; if the electronic device determines that the state of the next storage area is an unreadable state, the electronic device does not update the current global read pointer, and executes step S1012.

[0240] Specifically, when the electronic device determines that the current data writing mode is the retry-new mode, it can obtain the second write pointer committed of the next storage area, and determine the number of local write wraps that have been written in the next storage area according to the version value in the second write pointer committed of the next storage area. The electronic device determines the number of global read wraps according to the global read pointer. When the number of local write wraps that have been written in the next storage area is equal to the number of global read wraps plus 1, the electronic device can determine that a new round of data has been written in the next storage area, and the state of the next storage area is a readable state, and the electronic device executes step S1011. When the number of local write wraps that have been written in the next storage area is less than the number of global read wraps plus 1, the electronic device determines that no new data has been written in the next storage area, the electronic device returns EMPTY, and executes step S1012. When the number of local write wraps that have been written in the next storage area is greater than the number of global read wraps plus 1, the electronic device determines that an abnormality has occurred, and executes step S1012.

[0241] S1010: The electronic device determines whether at least one round of new data has been written into the next storage area.

[0242] In an embodiment of the present application, if the current data writing mode is the drop-old mode (as an example of the second mode), then when at least one new round of data has been written in the next storage area, the electronic device determines that the state of the next storage area is a readable state, then the current global read pointer can be updated; otherwise, the current global read pointer is not updated.

[0243] Specifically, when the electronic device determines that the current data writing mode is the drop-old mode, the electronic device can determine the number of local read wraps that have been occupied in the current storage area according to the version value in the first read pointer reserved of the current storage area, and determine the corresponding target increment value according to the position of the current storage area. The electronic device can also obtain the second write pointer committed of the next storage area, and determine the number of local write wraps that have been written in the next storage area according to the version value in the second write pointer committed of the next storage area. When the electronic device determines that the number of local write wraps that have been written in the next storage area is greater than or equal to the sum of the number of local read wraps that have been occupied in the current storage area and the target increment, the electronic device can determine that at least one round of new data has been written in the next storage area, and the state of the next storage area is a readable state, and the electronic device executes step S1011. When the electronic device determines that the number of local write wraps that have been written in the next storage area is less than the sum of the number of local read wraps that have been occupied in the current storage area and the target increment, it can be determined that no new data has been written in the next storage area, and the electronic device returns EMPTY and executes step S1012.

[0244] Among them, when the current storage area is the first storage area in the circular storage queue, the target incremental value corresponding to the current storage area can be set to 1, and when the current storage area is not the first storage area in the circular storage queue, the target incremental value corresponding to the current storage area can be set to 0.

[0245] In actual applications, since the electronic device will not update the global write pointer / global read pointer when writing / reading data to the first storage area in the initial situation, the version value of the first storage area is 0 in the first read / write wraparound, and when writing / reading data to other storage areas, the version values ​​of other storage areas are 1. It can be seen that even in the same wraparound, the version value of the first storage area and other storage areas differs by 1. Therefore, the special case of the first storage area needs to be considered here. When the current storage area is the first storage area, the number of occupied local read wraparounds is increased by 1.

[0246] S1011: The electronic device updates the current global read pointer so that the updated current global read pointer points to the next storage area.

[0247] In the embodiment of the present application, the electronic device may update the current global read pointer by performing a MAX operation on the current global read pointer, so that the current global read pointer points to the next storage area.

[0248] In an embodiment of the present application, when the electronic device determines that the current data write mode is the retry-new mode, before updating the current global read pointer, the electronic device can perform a MAX operation on the first read pointer and the second read pointer of the next storage area to increase the first read pointer and the second read pointer of the next storage area by 1.

[0249] In an embodiment of the present application, when the electronic device determines that the current data write mode is the drop-old mode, before updating the current global read pointer, the electronic device can perform a MAX operation on the next storage area to set the number of local read wraparounds that have been occupied in the next storage area to the number of local write wraparounds that have been written in the next storage area. Specifically, the electronic device can perform a MAX operation on the version in the first read pointer reserved of the next storage area to assign the version value in the second write pointer committed of the next storage area to the version in the first read pointer reserved of the next storage area.

[0250] In actual applications, since overwriting can be performed in drop-old mode, the version value in the second write pointer committed may be much larger than the version value in the first read pointer reserved.

[0251] S1012: End. The end may mean that the current thread in the electronic device gives up reading data, or the current thread in the electronic device returns to step S1001.

[0252] In an embodiment of the present application, after the electronic device executes the step S1011, it can return to step S1001. At this time, the current global read pointer points to the next storage area, and the next storage area can be used as the current storage area to occupy the second sub-area in the next storage area, and read the second data stored in the second sub-area to complete the data reading.

[0253] It should be noted that, in some embodiments, each part of the above method implemented by MAX operation can be replaced by using CAS operation. For example, on the hardware platform X86 platform without MAX instruction, CAS instruction can be used instead.

[0254] It should be understood that for the convenience of description, Figure 7 and Fig.10In the flowchart in , descriptions such as the current global write pointer, the current global read pointer, the current storage area, and the next storage area are used. In actual applications, "current" can be modified to descriptions such as "first", "second", or "third". For example, the current storage area can be the first storage area or the third storage area.

[0255] It should be understood that in the aforementioned Figure 7 In the description of , the current global write pointer corresponds to the current storage area. Fig.10 In the description of , the current global read pointer corresponds to the current storage area. The two current storage areas may be the same storage area or may not be the same storage area.

[0256] It should be understood that the aforementioned Figure 5 and Figure 7 A flowchart of a method for writing data. Fig. 9 and Fig.10 Flow chart of the method for reading data. In the circular storage queue, writing data and reading data are related to each other. Fig. 9 and Fig.10 For the description in Figure 5 and Figure 7 About Figure 5 and Figure 7 For descriptions in Fig. 9 and Fig.10 Description in .

[0257] The method provided in the embodiment of the present application is applied to the ARM platform and the X86 platform respectively, and compared with the implementation method in the prior art under the conditions of different numbers of writers, the following results can be obtained: Fig.11a and Fig.11b The performance comparison chart shown. Among them, bbq represents the throughput change curve of the method provided in the embodiment of the present application, dpdkrb represents the throughput change curve of the implementation method in DPDK, linuxrb represents the throughput change curve of the implementation method in the Linux system, boostq represents the throughput change curve of the implementation method in the boost library, follyq represents the throughput change curve of the implementation method provided by Facebook (meta), and scqd represents the throughput change curve of the implementation method in the above-mentioned second implementation mode. According to Fig.11a and Fig.11b It can be seen that on the X86 platform and the ARM platform, the throughput of the method provided in the embodiment of the present application is significantly higher than the throughput of the implementation method in the prior art. The method provided in the embodiment of the present application can improve the system performance by dozens of times.

[0258] In the ARM platform, the FAA instruction and the CAS instruction are used to implement the method provided in the embodiment of the present application, and the comparison is performed under the state of different numbers of writers, and the following can be obtained: Fig.11c The performance comparison chart is shown in Figure 1. Among them, bbq-faa-lse represents the throughput change curve when the ARM LSE instruction set FAA instruction is used, and bbq-cas represents the throughput change curve when the CAS instruction is used. Fig.11c It can be seen that when the number of writers is large, the performance of the CAS instruction can be achieved more than 5 times by using the ARM LSE instruction set FAA instruction implementation.

[0259] By comparing the performance of the circular storage queue provided in the embodiment of the present application with the circular storage queue ring buffer in DPDK, it can be obtained as follows: Fig.12 The performance comparison chart shown in FIG. bbq represents the throughput of the circular storage queue provided in the embodiment of the present application at different queue sizes, and dpdkrb represents the throughput of the circular storage queue in DPDK at different queue sizes. Fig.12 It can be seen that in the L2F scenario, the circular storage queue performance provided by the embodiment of the present application is at least 50% better end-to-end than the circular storage queue performance in DPDK.

[0260] The data writing method and the data reading method in the present application are described above, and the data writing device and the data reading device in the present application are described below.

[0261] refer to Fig.13 , Fig.13 FIG. 1 shows a schematic diagram of the structure of a data writing device 1300 provided in an embodiment of the present application. Fig.13 As shown, the data writing device 1300 may include:

[0262] A determination module 1310, configured to determine first data to be written into the circular storage queue;

[0263] A first acquisition module 1320 is used to acquire a global write pointer of the circular storage queue, the circular storage queue includes multiple storage areas, each storage area includes multiple sub-areas, and the global write pointer points to a first storage area in the multiple storage areas;

[0264] A second acquisition module 1330 is used to acquire a first write pointer of the first storage area, and determine the size of the allocated space in the first storage area according to the first write pointer of the first storage area;

[0265] an allocation module 1340, configured to determine that the size of the allocated space in the first storage area is smaller than the size of the space in the first storage area, and to allocate a first sub-area in the first storage area by performing an FAA operation on the first storage area;

[0266] The writing module 1350 is configured to write the first data into the first sub-area.

[0267] In some embodiments, the data writing device 1300 may also include: a first update module, used to determine that the size of the allocated space in the first storage area is equal to the size of the space of the first storage area, and to determine that the state of the second storage area is a writable state, wherein the second storage area is the next storage area adjacent to the first storage area; and to update the global write pointer so that the updated global write pointer points to the second storage area.

[0268] refer to Fig.14 , Fig.14 FIG. 1 shows a schematic diagram of the structure of a data reading device 1400 provided in an embodiment of the present application. Fig.14 As shown, the data reading device 1400 may include:

[0269] A third acquisition module 1410 is used to acquire a global read pointer of a circular storage queue storing data to be read, wherein the circular storage queue includes multiple storage areas, each storage area includes multiple sub-areas, and the global read pointer points to a third storage area among the multiple storage areas;

[0270] A fourth acquisition module 1420 is used to acquire a first write pointer and a second write pointer of the third storage area, determine the size of the allocated space in the third storage area according to the first write pointer of the third storage area, and determine the size of the written space in the third storage area according to the second write pointer of the third storage area;

[0271] The occupation module 1430 is used to determine that the size of the space that has been written in the third storage area is equal to the size of the space that has been allocated in the third storage area, and then perform a MAX operation on the third storage area to occupy the second sub-area in the third storage area;

[0272] The reading module 1440 is configured to read the second data stored in the second sub-region.

[0273] In some embodiments, the occupancy module 1430 is also used to determine that the size of the occupied space in the third storage area is smaller than the size of the space that has been written in the third storage area; wherein the size of the occupied space in the third storage area is determined based on the first read pointer of the third storage area.

[0274] In some embodiments, the data reading device 1400 may also include: a second update module, used to determine that the size of the occupied space in the third storage area is equal to the size of the space of the third storage area, and to determine that the state of the fourth storage area is a readable state, wherein the fourth storage area is the next storage area adjacent to the third storage area; and to update the global read pointer so that the updated global read pointer points to the fourth storage area.

[0275] In some embodiments, the data reading device 1400 may further include: a setting module for setting the number of local read wraparounds occupied in the fourth storage area to the number of local write wraparounds written in the fourth storage area by performing a MAX operation on the fourth storage area.

[0276] It should be noted that the device provided in the above embodiment, when implementing its functions, only uses the division of the above functional modules as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device provided in the above embodiment and the corresponding method embodiment belong to the same concept, and the specific implementation process is detailed in the corresponding method embodiment, which will not be repeated here.

[0277] The present application also provides an electronic device, including:

[0278] a memory for storing instructions executed by one or more processors of the electronic device;

[0279] The processor, when the processor executes the instructions in the memory, can cause the electronic device to execute the above embodiment Figures 5 to 10 The method shown.

[0280] The present application also provides a computer-readable storage medium on which instructions are stored. When the instructions are executed by a processor, the processor executes the above-mentioned embodiment. Figures 5 to 10 The method shown.

[0281] The present application also provides a computer program product comprising instructions, which, when executed on an electronic device, enables a processor to execute the above-mentioned embodiments. Figures 5 to 10 The method shown.

[0282] refer to Fig.15, shown is a block diagram of an electronic device 1500 according to one embodiment of the present application. The electronic device 1500 may include one or more processors 1501 coupled to a controller hub 1503. For at least one embodiment, the controller hub 1503 communicates with the processor 1501 via a multi-drop bus such as a front side bus (FSB), a point-to-point interface such as a Quick Path Interconnect (QPI), or a similar connection 1506. The processor 1501 executes instructions that control general types of data processing operations. In one embodiment, the controller hub 1503 includes, but is not limited to, a graphics memory controller hub (Graphics Memory Controller Hub, GMCH) (not shown) and an input / output hub (Input Output Hub, IOH) (which may be on a separate chip) (not shown), wherein the GMCH includes a memory and a graphics controller and is coupled to the IOH.

[0283] The electronic device 1500 may also include a coprocessor 1502 and a memory 1504 coupled to the controller hub 1503. Alternatively, one or both of the memory and the GMCH may be integrated within the processor (as described in this application), with the memory 1504 and the coprocessor 1502 being directly coupled to the processor 1501 and the controller hub 1503, with the controller hub 1503 being in a single chip with the IOH.

[0284] The memory 1504 may be, for example, a dynamic random access memory (DRAM), a phase change memory (PCM), or a combination of the two. The memory 1504, as a computer-readable storage medium, may include one or more tangible, non-temporary computer-readable media for storing data and / or instructions. For example, the memory 1504 may include any suitable non-volatile memory such as a flash memory and / or any suitable non-volatile storage device, such as one or more hard disk drives (HDD(s)), one or more compact disc (CD) drives, and / or one or more digital versatile disc (DVD) drives.

[0285] According to some embodiments of the present application, the memory 1504 as a computer-readable storage medium stores instructions, and when the instructions are executed on the computer, the system 1500 executes the data writing method or the data reading method according to the above embodiments. Figures 5 to 10The method shown will not be repeated here.

[0286] In one embodiment, the coprocessor 1502 is a special purpose processor, such as, for example, a high throughput many integrated core (MIC) processor, a network or communication processor, a compression engine, a graphics processor, a general purpose graphics processor (GPGPU), or an embedded processor. The optional nature of the coprocessor 1502 is indicated by a dashed line in Fig.15 middle.

[0287] In one embodiment, the electronic device 1500 may further include a network interface (Network Interface Controller, NIC) 1506. The network interface 1506 may include a transceiver for providing a radio interface for the electronic device 1500, thereby communicating with any other suitable device (such as a front-end module, an antenna, etc.). In various embodiments, the network interface 1506 may be integrated with other components of the electronic device 1500. The network interface 1506 may implement the functions of the communication unit in the above-mentioned embodiments.

[0288] The electronic device 1500 may further include an input / output (I / O) device 1505. The I / O 1505 may include: a user interface designed to enable a user to interact with the electronic device 1500; a peripheral component interface designed to enable peripheral components to interact with the electronic device 1500; and / or a sensor designed to determine environmental conditions and / or location information related to the electronic device 1500.

[0289] It is worth noting that Fig.15 This is for illustrative purposes only. Fig.15 It is shown that the electronic device 1500 includes multiple devices such as a processor 1501, a controller hub 1503, and a memory 1504. However, in actual applications, the devices using the methods of the present application may only include a part of the devices of the electronic device 1500, for example, it may only include the processor 1501 and the network interface 1506. Fig.15 The properties of optional devices are shown with dashed lines.

[0290] refer to Fig.16 , which is a block diagram of a SoC (System on Chip) 1600 according to an embodiment of the present application. Fig.16 In the FIG, similar components have the same reference numerals. In addition, the dashed boxes are optional features of more advanced SoCs. Fig.16In the embodiment, SoC 1600 includes: an interconnect unit 1650, which is coupled to a processor 1610; a system agent unit 1680; a bus controller unit 1690; an integrated memory controller unit 1640; a group or one or more coprocessors 1620, which may include integrated graphics logic, an image processor, an audio processor, and a video processor; a static random access memory (SRAM) unit 1630; and a direct memory access (DMA) unit 1660. In one embodiment, the coprocessor 1620 includes a special-purpose processor, such as, for example, a network or communication processor, a compression engine, a GPGPU, a high-throughput MIC processor, or an embedded processor.

[0291] The static random access memory (SRAM) unit 1630 may include one or more tangible, non-temporary computer-readable storage media for storing data and / or instructions. The computer-readable storage medium may store instructions, specifically, temporary and permanent copies of the instructions. The instructions may include: when executed by at least one unit in the processor, causing the Soc 1600 to perform the data writing method or the data reading method according to the above embodiments, which may be specifically referred to in the above embodiments. Figures 5 to 10 The method shown will not be repeated here.

[0292] The various embodiments of the mechanism disclosed in the present application can be implemented in hardware, software, firmware or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device and at least one output device.

[0293] Program code can be applied to input instructions to perform the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, a processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.

[0294] Program code can be implemented with high-level programming language or object-oriented programming language to communicate with the processing system. When necessary, program code can also be implemented with assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any specific programming language. In either case, the language can be a compiled language or an interpreted language.

[0295] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, instructions may be distributed over a network or by other computer-readable media. Therefore, machine-readable media may include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including, but not limited to, floppy disks, optical disks, optical disks, compact disc read-only memories (Compact Disc Read Only Memory, CD-ROMs), magneto-optical disks, read-only memories (Read Only Memory, ROM), random access memories (RAM), erasable programmable read-only memories (Erasable Programmable Read Only Memory, EPROM), electrically erasable programmable read-only memories (Electrically Erasable Programmable Read Only Memory, EEPROM), magnetic cards or optical cards, flash memory, or a tangible machine-readable memory for transmitting information (e.g., carrier waves, infrared signal digital signals, etc.) using the Internet in electrical, optical, acoustic, or other forms of propagation signals. Accordingly, machine-readable media include any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a form readable by a machine (eg, a computer).

[0296] In the accompanying drawings, some structural or method features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be required. Instead, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the accompanying drawings of the specification. In addition, the inclusion of structural or method features in a particular figure does not mean that such features are required in all embodiments, and in some embodiments, these features may not be included or may be combined with other features.

[0297] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation method of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed by the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned device embodiments of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed by the present application, which does not mean that there are no other units / modules in the above-mentioned device embodiments.

[0298] It should be noted that, in the examples and description of the present application, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of further restrictions, the elements defined by the statement "comprise one" do not exclude the presence of other identical elements in the process, method, article or equipment including the elements.

[0299] Although the present application has been illustrated and described with reference to certain preferred embodiments thereof, it will be apparent to those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present application.

Claims

1. A data writing method, applied to an electronic device, characterized in that: The method comprises: Determining first data to be written into the circular storage queue; Obtaining a global write pointer of the circular storage queue, wherein the circular storage queue includes a plurality of storage areas, and the global write pointer points to a first storage area in the plurality of storage areas; Obtaining a first write pointer of the first storage area, and determining the size of the allocated space in the first storage area according to the first write pointer of the first storage area; Determine that the size of the space already allocated in the first storage area is smaller than the size of the space in the first storage area, and allocate a first sub-area in the first storage area; The first data is written into the first sub-area.

2. The method according to claim 1, characterized in that The method further comprises: Determining that the size of the allocated space in the first storage area is equal to the size of the space in the first storage area, and determining that the state of the second storage area is a writable state, wherein the second storage area is a next storage area adjacent to the first storage area; The global write pointer is updated so that the updated global write pointer points to the second storage area.

3. The method according to claim 2, characterized in that Determining that the state of the second storage area is a writable state includes: It is determined that the second storage area is in an unallocated state.

4. The method according to claim 2, characterized in that: Determining that the state of the second storage area is a writable state includes: Determine that the size of the space in the second storage area that has been read is equal to the size of the space in the second storage area; and Determining that the number of local read wraparounds that have been read in the second storage area is equal to the number of global write wraparounds; Wherein, the number of global write wraparounds is determined according to the global write pointer; The size of the space that has been read in the second storage area and the number of local read wraps that have been read are determined based on the second read pointer of the second storage area, and the second read pointer of the second storage area is obtained when the current data writing mode is the first mode.

5. The method according to claim 4, characterized in that The method further comprises: Determine that the size of the space in the second storage area that has been read is not equal to the size of the space in the second storage area; The global write pointer is updated so that the updated global write pointer points to a next storage area adjacent to the second storage area.

6. The method according to claim 4, characterized in that The method further comprises: Determine that the size of the space in the second storage area that has been read is not equal to the size of the space in the second storage area; Obtaining a second read pointer of the second storage area, and determining the size of the occupied space in the second storage area according to the second read pointer of the second storage area; Determine that the size of the occupied space in the second storage area is equal to the size of the space that has been read in the second storage area, and update the global write pointer so that the updated global write pointer points to the next storage area adjacent to the second storage area.

7. The method according to claim 2, characterized in that: Determining that the state of the second storage area is a writable state includes: Determine that the size of the space that has been written in the second storage area is equal to the size of the space of the second storage area; and Determining that the number of local write-back wraps written in the second storage area is equal to the number of global write-back wraps; Wherein, the number of global write wraparounds is determined according to the global write pointer; The size of the space that has been written in the second storage area and the number of local write wraps that have been written are determined based on the second write pointer of the second storage area, and the second write pointer of the second storage area is obtained when the current data writing mode is the second mode.

8. The method according to claim 7, characterized in that The method further comprises: Determine that the size of the space that has been written in the second storage area is not equal to the size of the space of the second storage area; The global write pointer is updated so that the updated global write pointer points to a next storage area adjacent to the second storage area.

9. A data reading method, applied to an electronic device, characterized in that: The method comprises: Obtaining a global read pointer of a circular storage queue storing data to be read, wherein the circular storage queue includes a plurality of storage areas, each storage area includes a plurality of sub-areas, and the global read pointer points to a third storage area among the plurality of storage areas; Obtaining a first write pointer and a second write pointer of the third storage area, determining the size of the allocated space in the third storage area according to the first write pointer of the third storage area, and determining the size of the written space in the third storage area according to the second write pointer of the third storage area; Determine that the size of the space that has been written in the third storage area is equal to the size of the space that has been allocated in the third storage area, and occupy the second sub-area in the third storage area; The second data stored in the second sub-region is read.

10. The method according to claim 9, characterized in that The occupying the second sub-area in the third storage area comprises: occupying the second sub-area in the third storage area through a MAX operation; Before occupying the second sub-area in the third storage area by the MAX operation, the method further includes: Determine that the size of the occupied space in the third storage area is smaller than the size of the written space in the third storage area; The size of the occupied space in the third storage area is determined based on the first read pointer of the third storage area.

11. The method according to claim 10, characterized in that The performing a MAX operation on the third storage area to occupy the second sub-area in the third storage area comprises: Increasing the first read pointer of the third storage area by performing a MAX operation, and determining whether the first read pointer of the third storage area is updated by other threads; If the first read pointer of the third storage area is not updated by other threads, the second sub-area in the third storage area is occupied.

12. The method according to claim 10, characterized in that The reading the second data stored in the second sub-area comprises: Determining that the current data writing mode is the second mode, and the number of local write wraparounds allocated in the third storage area is equal to the number of local read wraparounds occupied in the third storage area, then reading and returning the second data stored in the second sub-area; The number of local write wraparounds that have been allocated in the third storage area is determined based on the first write pointer of the third storage area, and the number of local read wraparounds that have been occupied in the third storage area is determined based on the first read pointer of the third storage area.

13. The method according to claim 10, characterized in that The method further comprises: Determining that the size of the occupied space in the third storage area is equal to the size of the space in the third storage area, and determining that the state of the fourth storage area is a readable state, wherein the fourth storage area is the next storage area adjacent to the third storage area; The global read pointer is updated so that the updated global read pointer points to the fourth storage area.

14. The method according to claim 13, characterized in that Determining that the state of the fourth storage area is a readable state includes: Determine that the number of local write wraparounds written into the fourth storage area is equal to the number of global read wraparounds plus 1; Wherein, the number of global read wraparounds is determined according to the global read pointer; The number of partial write wraps that have been written in the fourth storage area is determined based on a second write pointer of the fourth storage area, and the second write pointer of the fourth storage area is obtained when the current data writing mode is the first mode.

15. The method according to claim 13, characterized in that Determining that the state of the fourth storage area is a readable state includes: Determine that the number of local write wraps written in the fourth storage area is greater than or equal to the sum of the number of local read wraps occupied in the third storage area and the target increment; The number of partial write wraps that have been written in the fourth storage area is determined based on a second write pointer of the fourth storage area, and the second write pointer of the fourth storage area is obtained when the current data writing mode is the second mode; The number of occupied local read wraparounds in the third storage area is determined based on a first read pointer of the third storage area, and the target increment value is determined based on a position of the third storage area.

16. The method according to claim 15, characterized in that The method further comprises: A MAX operation is performed on the fourth storage area to set the number of local read wraparounds that have been occupied in the fourth storage area to the number of local write wraparounds that have been written in the fourth storage area.

17. A data writing device, arranged in an electronic device, characterized in that: The device comprises: A determination module, used for determining first data to be written into the circular storage queue; A first acquisition module, configured to acquire a global write pointer of the circular storage queue, wherein the circular storage queue includes a plurality of storage areas, and the global write pointer points to a first storage area in the plurality of storage areas; a second acquisition module, configured to acquire a first write pointer of the first storage area, and determine a size of an allocated space in the first storage area according to the first write pointer of the first storage area; An allocation module, configured to determine that the size of the space already allocated in the first storage area is smaller than the size of the space in the first storage area, and allocate a first sub-area in the first storage area; A writing module is used to write the first data into the first sub-area.

18. A data reading device, arranged in an electronic device, characterized in that: The device comprises: A third acquisition module is used to acquire a global read pointer of a circular storage queue storing data to be read, wherein the circular storage queue includes multiple storage areas, each storage area includes multiple sub-areas, and the global read pointer points to a third storage area among the multiple storage areas; A fourth acquisition module is used to acquire the first write pointer and the second write pointer of the third storage area, determine the size of the allocated space in the third storage area according to the first write pointer of the third storage area, and determine the size of the written space in the third storage area according to the second write pointer of the third storage area; An occupation module, configured to determine that the size of the space written in the third storage area is equal to the size of the space allocated in the third storage area, and occupy the second sub-area in the third storage area; A reading module is used to read the second data stored in the second sub-area.

19. An electronic device, characterized in that: include: a memory for storing instructions executed by one or more processors of the electronic device; A processor, when the processor executes the instructions in the memory, can enable the electronic device to execute the data writing method described in any one of claims 1 to 8 or the data reading method described in any one of claims 9 to 16.

20. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the data writing method according to any one of claims 1 to 8 or the data reading method according to any one of claims 9 to 16.

Citation Information

Cited By

  • Network card cache management method and device, computer equipment and storage medium

    CN119324905A