Data replication method and apparatus based on DMA, device, and storage medium
By receiving data copy instructions in the on-chip system, determining address differences, and establishing an associated ID table, the problem of misaligned read and write addresses is solved, the software system is simplified, and data transmission efficiency and accuracy are improved.
Patent Information
- Application Number
- CN202511333033.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-18
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2045-09-18
AI Technical Summary
In a System-on-a-Chip (SoC), the misalignment of the starting source address of a read request and the starting destination address of a write request leads to data shifting and mismatch between read and write data. Existing technologies increase the complexity of the software system by restricting address space allocation through software.
By receiving data copy instructions, the alignment difference between the starting source address and the starting destination address is determined, an association ID table is established, the association ID is used to identify the association between read and write requests, the read request result is obtained based on the alignment difference and written to the destination storage medium, thus solving the problem of misaligned starting addresses.
It effectively solves the problem of misaligned starting addresses, simplifies the complexity of the software system, and improves the efficiency and accuracy of data transmission.
Smart Images

Figure CN120821680B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of chips, and in particular to a DMA-based data copying method, apparatus, device, and storage medium. Background Technology
[0002] Large-scale data transfer between various IPs in a System-on-a-Chip (SoC) is generally achieved using a general-purpose standard bus. Direct Memory Access (DMA) transfer copies data from one address space to another via a general-purpose standard bus, providing high-speed data transfer between peripherals and memory or between memory devices. This enables efficient transfer of large amounts of data while reducing the processor's workload.
[0003] In typical SOC systems, data descriptions are based on bytes as the smallest basic unit. However, when transmitting read and write transactions via a bus, the transmission unit is much larger than 1 byte to consider transmission performance. This can lead to misalignment between the starting source address of a read request and the starting destination address of a write request, potentially causing data shifting and resulting in a mismatch between read and write data.
[0004] In existing technologies, to avoid the problem of misaligned starting addresses, software can impose restrictions when allocating address space. However, this increases the complexity of the software system. Summary of the Invention
[0005] Therefore, it is necessary to provide a DMA-based data copying method, apparatus, device, and storage medium that can effectively solve the problem of misaligned start addresses, in order to address the above-mentioned technical problems.
[0006] In a first aspect, this application provides a DMA-based data copying method, including:
[0007] Receive data copy instructions, which include the starting source address, the starting destination address, and the length of data to be copied.
[0008] Determine the alignment difference between the starting source address and the starting destination address;
[0009] The association ID table is determined based on the data replication instructions and alignment differences. In the association ID table, the association ID of a write request corresponds to one or two association IDs of read requests.
[0010] For a write request, the corresponding read request is obtained based on the associated ID table and alignment difference. Based on the address of the write request, the target result corresponding to the read request is written to the destination storage medium.
[0011] In one embodiment, the alignment difference includes a difference value and a data displacement attribute, whereby the data displacement attribute includes left shift, right shift, or no shift. Determining the associated ID table based on the data copying instruction and the alignment difference includes:
[0012] Obtain the preset data length of the unit read / write request; determine multiple sets of read / write requests based on the data copy instruction and the data length of the unit read / write request, and assign an independent association ID to each read / write request. In a set of read / write requests, the association ID of the read request is the same as the association ID of the write request; determine the association ID table based on each association ID and the alignment difference.
[0013] In one embodiment, determining the association ID table based on each association ID and alignment difference includes: if the data displacement attribute is no movement, the association ID of each write request corresponds one-to-one with the association ID of each read request, and the association ID of the write request is the same as the association ID of the read request.
[0014] For a write request, the corresponding read request is obtained based on the association ID table and alignment difference. Based on the address of the write request, the target result corresponding to the read request is written to the destination storage medium. This includes: obtaining the association ID of the write request and obtaining the address of the corresponding write request based on the association ID; obtaining the result of the read request corresponding to the association ID and using the result of the read request as the target result; and writing the target result to the destination storage medium based on the address of the write request.
[0015] In one embodiment, determining the association ID table based on each association ID and alignment difference further includes: if the data displacement attribute is right shift, the association ID of each write request corresponds to the association ID of two read requests, wherein the association ID of the two read requests includes a first read request association ID and a second read request association ID, the first read request association ID is the same as the association ID of the write request, and the second read request association ID is the next adjacent association ID of the association ID of the write request.
[0016] For a write request, the process involves obtaining the corresponding read request based on the association ID table and alignment difference, writing the target result corresponding to the read request to the destination storage medium based on the address of the write request, and further including: obtaining the association IDs of the two read requests corresponding to the write request, and obtaining the first read request result and the second read request result respectively; dividing the first read request result into a first result and a second result based on the difference value, wherein the data length of the first result is the same as the difference value, and the first result is the low-order part of the first read request result; dividing the second read request result into a third result and a fourth result based on the difference value, wherein the data length of the third result is the same as the difference value, and the third result is the low-order part of the second read request result; recombining the second result and the third result to obtain the target result, wherein the second result is located in the low-order part of the target result, and the third result is located in the high-order part; and writing the target result to the destination storage medium based on the address of the write request.
[0017] In one embodiment, determining the association ID table based on each association ID and alignment difference further includes: if the data shift attribute is left shift, the association ID of each write request corresponds to the third read request association ID, or the third read request association ID and the fourth read request association ID, the third read request association ID is the same as the association ID of the write request, and the fourth read request association ID is the previous adjacent association ID of the association ID of the read request.
[0018] For a write request, the process includes: obtaining the corresponding read request based on the associated ID table and alignment difference; writing the target result corresponding to the read request to the destination storage medium based on the address of the write request; obtaining the read request associated ID corresponding to the write request and obtaining the read request result corresponding to the read request associated ID, where the read request result includes a third read request result, or a third read request result and a fourth read request result; if the read request result includes a third read request result, dividing the third read request result into a fifth result and a sixth result based on the difference value, wherein the data length of the sixth result is the same as the difference value, and the sixth result is the high-order part of the third read request result; using the fifth result as the target result, and writing the target result to the destination storage medium based on the address of the write request.
[0019] In one embodiment, the method further includes:
[0020] If the read request result includes the third read request result and the fourth read request result, the fourth read request result is divided into the seventh result and the eighth result based on the difference value. The data length of the eighth result is the same as the difference value, and the eighth result is the high-order part of the fourth read request result. The fifth result and the eighth result are recombined to obtain the target result. In the target result, the eighth result is located in the low-order part, and the fifth result is located in the high-order part. The target result is written to the destination storage medium according to the address of the write request.
[0021] In one embodiment, determining the alignment difference between the starting source address and the starting destination address includes:
[0022] Obtain the bus width, which is a power of 2 in M bytes; determine the alignment difference based on the lower M bits of the starting source address and the lower M bits of the starting destination address.
[0023] In one embodiment, if the lower M bits of the starting source address and the lower M bits of the starting destination address are equal, the difference value is 0, and the data shift attribute is no shift; if the lower M bits of the starting source address are greater than the lower M bits of the starting destination address, the difference value is the difference between the lower M bits of the starting source address and the lower M bits of the starting destination address, and the data shift attribute is right shift; if the lower M bits of the starting source address are less than the lower M bits of the starting destination address, the difference value is the difference between the lower M bits of the starting destination address and the lower M bits of the starting source address, and the data shift attribute is left shift.
[0024] Secondly, this application also provides a DMA-based data copying apparatus, comprising:
[0025] The receiving module is used to receive data copying instructions, which include the starting source address, the starting destination address, and the length of data to be copied.
[0026] The calculation module is used to determine the alignment difference between the starting source address and the starting destination address;
[0027] The association module is used to determine the association ID table based on the data replication instructions and alignment differences. In the association ID table, the association ID of a write request corresponds to one or two association IDs of read requests.
[0028] The replication module is used to retrieve the corresponding read request based on the associated ID table and alignment difference for a write request, and write the target result corresponding to the read request to the destination storage medium according to the address of the write request.
[0029] In one embodiment, the alignment difference includes a difference value and a data displacement attribute, whereby the data displacement attribute includes left shift, right shift, or no shift. The association module is specifically used to obtain a preset data length for a unit read / write request; determine multiple sets of read / write requests based on the data copy instruction and the data length of the unit read / write request; assign an independent association ID to each read / write request, wherein, in a set of read / write requests, the association ID of the read request is the same as the association ID of the write request; and determine an association ID table based on each association ID and the alignment difference.
[0030] In one embodiment, the association module is specifically used to ensure that, if the data displacement attribute is no movement, the association ID of each write request corresponds one-to-one with the association ID of each read request, and the association ID of the write request is the same as the association ID of the read request.
[0031] The replication module is specifically used to obtain the associated ID of a write request, obtain the address of the corresponding write request based on the associated ID, obtain the result of the read request corresponding to the associated ID, use the result of the read request as the target result, and write the target result to the destination storage medium based on the address of the write request.
[0032] In one embodiment, the association module is specifically used to ensure that, if the data displacement attribute is right shift, the association ID of each write request corresponds to the association ID of two read requests. The association ID of the two read requests includes a first read request association ID and a second read request association ID. The first read request association ID is the same as the association ID of the write request, and the second read request association ID is the next adjacent association ID of the association ID of the write request.
[0033] The replication module is specifically used to obtain the association IDs of the two read requests corresponding to the write request, and to obtain the results of the first read request and the second read request, respectively; based on the difference value, the first read request result is divided into a first result and a second result, wherein the data length of the first result is the same as the difference value, and the first result is the low-order part of the first read request result; based on the difference value, the second read request result is divided into a third result and a fourth result, wherein the data length of the third result is the same as the difference value, and the third result is the low-order part of the second read request result; the second result and the third result are recombined to obtain the target result, in which the second result is located in the low-order part and the third result is located in the high-order part; based on the address of the write request, the target result is written to the destination storage medium.
[0034] In one embodiment, the association module is specifically used to, if the data shift attribute is left shift, assign the association ID of each write request to the association ID of the third read request, or assign the association ID of the third read request to the association ID of the fourth read request, wherein the association ID of the third read request is the same as the association ID of the write request, and the association ID of the fourth read request is the previous adjacent association ID of the association ID of the read request.
[0035] The replication module is specifically used to obtain the read request association ID corresponding to the write request, and to obtain the read request result corresponding to the read request association ID. The read request result includes the third read request result, or the third read request result and the fourth read request result. If the read request result includes the third read request result, the third read request result is divided into the fifth result and the sixth result according to the difference value. The data length of the sixth result is the same as the difference value, and the sixth result is the high-order part of the third read request result. The fifth result is used as the target result, and the target result is written to the destination storage medium according to the address of the write request.
[0036] In one embodiment, the copying module is specifically configured to: if the read request result includes a third read request result and a fourth read request result, divide the fourth read request result into a seventh result and an eighth result based on the difference value, wherein the data length of the eighth result is the same as the difference value, and the eighth result is the high-order part of the fourth read request result; reassemble the fifth result and the eighth result to obtain the target result, wherein the eighth result is located in the low-order part and the fifth result is located in the high-order part; and write the target result to the destination storage medium according to the address of the write request.
[0037] In one embodiment, the calculation module is specifically used to obtain the bus width, which is a power of 2 bytes; and to determine the alignment difference based on the lower M bits of the starting source address and the lower M bits of the starting destination address.
[0038] In one embodiment, if the lower M bits of the starting source address and the lower M bits of the starting destination address are equal, the difference value is 0, and the data shift attribute is no shift; if the lower M bits of the starting source address are greater than the lower M bits of the starting destination address, the difference value is the difference between the lower M bits of the starting source address and the lower M bits of the starting destination address, and the data shift attribute is right shift; if the lower M bits of the starting source address are less than the lower M bits of the starting destination address, the difference value is the difference between the lower M bits of the starting destination address and the lower M bits of the starting source address, and the data shift attribute is left shift.
[0039] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement any of the methods described in the first aspect above.
[0040] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the methods described in the first aspect above.
[0041] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements any of the methods described in the first aspect above.
[0042] The aforementioned DMA-based data copying method, apparatus, device, and storage medium, by receiving a data copying instruction (including a starting source address, a starting destination address, and the length of the copied data), determining the alignment difference between the starting source address and the starting destination address, and determining an association ID table based on the data copying instruction and the alignment difference (where an association ID for one write request corresponds to one or two association IDs for read requests), and for a write request, obtaining the corresponding read request based on the association ID table and the alignment difference, and writing the target result corresponding to the read request to the destination storage medium according to the address of the write request, effectively solves the problem of misaligned starting addresses by determining the alignment difference between the starting source address and the starting destination address, and combining the association ID with the alignment difference to determine the association ID table, thereby identifying the association between read and write requests. Attached Figure Description
[0043] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0044] Figure 1 This is a flowchart illustrating a DMA-based data copying method in one embodiment;
[0045] Figure 2 This is a flowchart illustrating the steps for determining the alignment difference between the starting source address and the starting destination address in one embodiment.
[0046] Figure 3 This is a schematic diagram illustrating the principle of determining alignment differences in one embodiment;
[0047] Figure 4 This is a schematic diagram illustrating the principle of determining alignment differences in another embodiment;
[0048] Figure 5 This is a schematic diagram illustrating the principle of determining alignment differences in another embodiment;
[0049] Figure 6 This is a schematic diagram illustrating the principle of determining alignment differences in another embodiment;
[0050] Figure 7 This is a schematic diagram illustrating the principle of determining alignment differences in another embodiment;
[0051] Figure 8 This is a flowchart illustrating the steps for determining the associated ID table in one embodiment;
[0052] Figure 9This is a schematic diagram of the associated ID and the corresponding associated ID table in one embodiment;
[0053] Figure 10 This is a schematic diagram of the association ID and the corresponding association ID table in another embodiment;
[0054] Figure 11 This is a schematic diagram of the association ID and the corresponding association ID table in another embodiment;
[0055] Figure 12 This is a flowchart illustrating a DMA-based data copying method in another embodiment;
[0056] Figure 13 This is a structural block diagram of a DMA-based data copying apparatus in one embodiment;
[0057] Figure 14 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0058] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0059] Large-scale data transfer between various IPs in a System-on-a-Chip (SoC) is generally implemented using a general-purpose standard bus. Direct Memory Access (DMA) transfer copies data from one address space to another via a general-purpose standard bus, providing high-speed data transfer between peripherals and memory, or between memory devices. This enables efficient transfer of large amounts of data while reducing the processor's workload. Taking the AXI (Advanced deXtensible Interface) protocol as an example, the AXI bus is a high-performance, high-bandwidth, low-latency on-chip bus. Its address / control and data phases are separated, supporting unaligned data transfers. In burst transfers, only the starting address is needed. Furthermore, its separate read / write data channels support significant transfer access and out-of-order access, and timing convergence is easier to achieve. The AXI bus protocol meets the needs of ultra-high performance and complex system-on-chip (SoC) designs and is applied to high-volume data transfer scenarios. The advantage of DMA transfer mode is that it can directly transfer large amounts of data without occupying CPU (Host) resources. It does not require direct control by the CPU (Host) and there is no process of saving and restoring the context in interrupt handling. It opens up a dedicated channel for data transfer in hardware and processes it in parallel with the CPU (Host). The DMA mode, together with high-performance and low-latency bus technology, meets the high-speed data transfer requirements of SoC.
[0060] In typical SOC systems, data descriptions are based on bytes as the smallest basic unit. However, when transmitting read and write transactions via a bus, the transmission unit is much larger than 1 byte to consider transmission performance. This can lead to misalignment between the starting source address of a read request and the starting destination address of a write request, potentially causing data shifting and resulting in a mismatch between read and write data.
[0061] In existing technologies, to avoid the problem of misaligned starting addresses, software can impose restrictions when allocating address space. However, this increases the complexity of the software system.
[0062] In view of this, this application provides a DMA-based data copying method that can effectively solve the problem of misaligned start addresses. The DMA-based data copying method provided in this application can be executed by a DMA-based data copying device, which can be implemented as part or all of an electronic device through software, hardware, or a combination of both. The electronic device can be a personal computer, laptop, smartphone, or tablet computer, etc., and is not exhaustively exemplified here.
[0063] In one exemplary embodiment, such as Figure 1 As shown, a DMA-based data copying method is provided, including the following steps 101 to 104. Wherein:
[0064] Step 101: Receive data copy instruction.
[0065] The data copy instruction includes the starting source address, the starting destination address, and the length of the copied data.
[0066] Optionally, data copying can be from the CPU or GPU and is used to copy data from one address space to another, providing high-speed data transfer between peripherals and memory or between memory and memory.
[0067] Optionally, the data storage unit of the SOC system is a byte, and the smallest data unit for data replication is also a byte. Each physical address corresponds to one byte of data, and similarly, a virtual address also corresponds to one byte of data.
[0068] Optionally, the data copying instruction may also include copying data space types, including two-dimensional linear data and three-dimensional solid data.
[0069] Optionally, upon receiving a data copy instruction, the instruction can be parsed and the starting source address, starting destination address, copied data length, and copied data space type recorded. Specifically, for two-dimensional linear data, the starting source address and starting destination address identify the source and destination addresses of the first byte of data to be copied, and all address sequences in the copied space are calculated based on these addresses. For three-dimensional data, the starting source address includes the origin of the three-dimensional space and the coordinates of the starting point of the copied object, while the corresponding starting destination address includes the origin of the three-dimensional space and the coordinates of the corresponding destination write start point.
[0070] Optionally, the starting source address and starting destination address refer to a continuous data copying space. Two-dimensional linear data has only one set of starting source address and starting destination address, while three-dimensional data can have multiple non-contiguous continuous data copying spaces, so there will be multiple sets of starting source address and starting destination address, and they are not related to each other. It can be understood that the method in the embodiments of this application is for two-dimensional linear data copying. For three-dimensional data copying, it can be regarded as a combination of multiple two-dimensional linear data copyings.
[0071] Step 102: Determine the alignment difference between the starting source address and the starting destination address.
[0072] It should be noted that, in the embodiments of this application, the alignment difference is related to the bus data width of the transmission bus and the set unit read / write request data length. At the same time, the unit read / write request data length is generally a multiple of the bus data width, such as one, two, four, etc.
[0073] Optionally, the alignment difference can be a data matching difference value, which can be calculated based on the start source address, start destination address, and bus data width to determine the data matching difference value and data shift attributes. For example, if the data width is 32 bits, then the start source address or start destination address should be an integer multiple of 4 bytes (corresponding to 32 bits). Such a start source address or start destination address is aligned. Addresses like 0x1000 and 0x1004 are start addresses that meet the word (32-bit) alignment requirements, while 0x1001 and 0x1003 do not meet the address alignment requirements.
[0074] Optionally, if either the starting source address or the starting destination address does not meet the address alignment requirement, or if the difference between the starting source address and the starting destination address is not an integer multiple of the bytes corresponding to the data width, there is an alignment difference between the starting source address and the starting destination address, and the alignment difference can be determined based on the difference between the starting source address and the starting destination address.
[0075] Step 103: Determine the associated ID table based on the data copying instructions and alignment differences.
[0076] In the association ID table, the association ID of a write request corresponds to one or two association IDs of read requests.
[0077] Optionally, data replication requires breaking down the operations of the entire replication space into one or more read-write request pairs. A read-write request pair includes a read request and a write request, and the read and write requests are in one-to-one correspondence. Read and write requests can use association IDs to identify the relevance of read and write operations. There is no coupling between different read-write request pairs, and the association IDs do not have a natural order requirement because the read and write operations do not have an order restriction. For example, the read-write operation with association ID 1 is not necessarily the first one, and can be executed after the read-write operation with association ID 7.
[0078] Optionally, due to alignment differences, and assuming a one-to-one correspondence between read and write requests, a data matching operation is added. That is, the associated ID of a read request can correspond to the associated IDs of two write requests, meaning that the data of a read request can be split and written into two write requests. Similarly, the associated ID of a write request can also correspond to the associated IDs of two read requests, meaning that the data of a write request is combined from the data of two read requests.
[0079] In one possible implementation, the association ID table can be a list with two columns: one column stores the association ID of a write request, and the other column stores the association ID of the read request corresponding to that write request.
[0080] It is understood that there may also be one column for storing the associated ID of the read request and another column for storing the associated ID of the write request corresponding to the read request. This application embodiment does not limit this.
[0081] In another possible implementation, the association ID table can be in the form of a linked list. A node in the linked list is a structure that can store the association ID of a write request and the association ID of the corresponding read request. When the association ID of a read request in a node is different from the association ID of a write request, the association ID of the write request corresponds to the association IDs of two read requests, that is, including the association ID of the read request that is the same as the association ID of the write request and the association ID of the read request in the node.
[0082] Similarly, it can also be a linked list built on the basis of read requests. That is, when the read request association ID and the write request association ID in a node are different, the association ID of the read request corresponds to the association IDs of two write requests, that is, the write-read request association ID that is the same as the read request association ID and the read request association ID in the node.
[0083] In another possible implementation, the association ID table can also be in the form of an array, where the index is used to represent the association ID of a write request, and the values in the array are used to represent the association ID of a read request. Taking the example where both the index and the association ID start from 0, when the index and the value corresponding to that index are different, the association ID of the write request corresponds to the association ID of two read requests, that is, the association ID of the read request that is the same as the association ID of the write request and the association ID of the read request in the node.
[0084] Similarly, it can also be an array built based on read requests. That is, when the index and the value corresponding to the index are different, the association ID of the read request corresponds to the association ID of two write requests, that is, including the write-read request association ID that is the same as the read request association ID and the read request association ID in the node.
[0085] Step 104: For a write request, obtain the corresponding read request based on the associated ID table and alignment difference, and write the target result corresponding to the read request to the destination storage medium according to the address of the write request.
[0086] Optionally, read requests can be sent to the source storage medium via the on-chip bus, and then the read request result can be obtained via the on-chip bus. After obtaining the read request result, the data needs to be matched and reassembled according to the alignment difference. The read request association ID is used as the write request association ID. If there is no alignment difference, the read request result is written to the destination storage medium as the target result. If there is an alignment difference, the association ID table is queried according to the write request association ID to obtain other association IDs related to the current write request association ID, and the read request results corresponding to the other association IDs are obtained. After matching and reassembling the two read request results, the target result is obtained, and then the target result is written to the destination storage medium.
[0087] Optionally, data replication consists of one or more sets of read and write requests, each set of read and write requests is independent of the others, and the replication command is completed after all read and write requests are completed.
[0088] The aforementioned DMA-based data copying method receives a data copying instruction, which includes the starting source address, starting destination address, and the length of the copied data. It then determines the alignment difference between the starting source and destination addresses. Based on the data copying instruction and the alignment difference, it establishes an association ID table, where the association ID of one write request corresponds to one or two read request association IDs. For a write request, it retrieves the corresponding read request based on the association ID table and the alignment difference, and writes the target result corresponding to the read request to the destination storage medium according to the address of the write request. In this way, by determining the alignment difference between the starting source and destination addresses and combining it with the association IDs and alignment difference to determine the association ID table, the association between read and write requests is identified using the association ID table, effectively solving the problem of misaligned starting addresses.
[0089] In one exemplary embodiment, such as Figure 2 As shown, optionally, determining the alignment difference between the starting source address and the starting destination address includes steps 201 to 202. Wherein:
[0090] Step 201: Obtain the bus width.
[0091] The bus width is an M-th power of 2 bytes.
[0092] Optionally, the bus width, or the bus data width of the transmission bus, can refer to the number of bits of data that the bus can transmit at the same time.
[0093] Step 202: Determine the alignment difference based on the lower M bits of the starting source address and the lower M bits of the starting destination address.
[0094] For example, taking a bus width of 64 bytes as an example, if the data length of a unit read / write request is set to 64 bytes, then the lsb6 (lower 6 bits of valid data) of the starting source address and the starting destination address are compared. If they are equal, the data does not need to be shifted or reassembled, that is, there is no alignment difference; if they are not equal, the read data needs to be shifted left or right to match the write data, and the difference value rw_diff between the starting source address and the starting destination address is calculated. The value of rw_diff is the lsb6 of the starting source address minus the lsb6 of the starting destination address.
[0095] The alignment difference can be accurately determined by obtaining the bus width and determining the alignment difference based on the lower M bits of the starting source address and the lower M bits of the starting destination address.
[0096] Optionally, the alignment difference includes the difference value and the data displacement attribute, which can be left-shifted, right-shifted, or not shifted.
[0097] Optionally, if the lower M bits of the starting source address and the lower M bits of the starting destination address are equal, the difference value is 0, and the data shift attribute is no shift; if the lower M bits of the starting source address are greater than the lower M bits of the starting destination address, the difference value is the difference between the lower M bits of the starting source address and the lower M bits of the starting destination address, and the data shift attribute is right shift; if the lower M bits of the starting source address are less than the lower M bits of the starting destination address, the difference value is the difference between the lower M bits of the starting destination address and the lower M bits of the starting source address, and the data shift attribute is left shift.
[0098] Optionally, the data shift attribute can be the data shift attribute of the read request.
[0099] For example, such as Figure 3 As shown, if the lsb6 of the starting source address is greater than the lsb6 of the starting destination address, then for a read request and a write request, the data length of the read request is less than the data length of the write request. The data from the first valid read request and a portion of the data from the second read request (length rw_diff) are needed to concatenate the corresponding write data, with the data shift attribute being right-shifted. If the lsb6 of the starting source address is less than the lsb6 of the starting destination address, then for a read request and a write request, the data length of the read request is greater than the data length of the write request. The high-order part of the read request data (length rw_diff) needs to be removed and given to the next write request. The remaining part in the read request is the corresponding write data.
[0100] Optionally, if the unit read / write request length is greater than the bus width, taking a bus width of 64 bytes and a unit read / write request length of 4 × 64 bytes as an example, it is necessary not only to calculate the total difference value, but also to determine the difference between the four transmitted data entries. There are four different shift and reassembly methods, such as... Figure 4 As shown, since the data length of the read request associated with ID 0 is less than the data length of the write request associated with ID 0, the write request data needs to be determined based on the two read requests (ID0 and ID1). The data shift attribute is right shift, but for a set of read data transmitted on the bus, each unit of data needs to be shifted left; that is, for each unit of data, the original low-order bits need to be shifted left to the high-order bits. Figure 5 As shown, since the data length of the read request associated with ID 0 is greater than the data length of the write request associated with ID 0, a portion of the high-order data from the read request needs to be removed and used to create a write request ID 1. The remaining data becomes the write request data for write request ID 0. The data shift attribute is left shift, but for a set of read data transmitted on the bus, each unit of data needs to be right shifted; that is, for each unit of data, the original high-order data needs to be right-shifted to the low-order data. Figure 6As shown, since the data length of the read request associated with ID 0 is less than the data length of the write request associated with ID 0, the write request data needs to be determined based on the two read requests (ID0 and ID1). The data shift attribute is right shift. Additionally, for a set of read data transmitted over the bus, each unit of data needs to be right shifted. Figure 7 As shown, since the data length of the read request associated with ID 0 is greater than the data length of the write request associated with ID 0, a portion of the high-order data of the read request needs to be removed and used to write a write request ID 1. The remaining data is used as the write request data for write request ID 0. The data shift attribute is left shift. At the same time, for a set of read data transmitted on the bus, each unit of data needs to be left shifted.
[0101] In one exemplary embodiment, such as Figure 8 As shown, optionally, the associated ID table is determined based on the data replication instructions and alignment differences, including steps 801 to 803. Wherein:
[0102] Step 801: Obtain the preset data length of the unit read / write request.
[0103] Step 802: Determine multiple sets of read / write requests based on the data copying instructions and the data length of the unit read / write requests, and assign an independent association ID to each read / write request.
[0104] In a set of read and write requests, the associated ID of the read request is the same as the associated ID of the write request.
[0105] Optionally, the number of associated IDs can be set according to requirements or bus protocol limitations, such as 256 or 512. It's understandable that the number of associated IDs can be set differently depending on the SOC bus.
[0106] Optionally, after all read and write requests corresponding to an associated ID are completed, the associated ID can be released, meaning that new read and write requests can be assigned to that associated ID.
[0107] Step 803: Determine the association ID table based on each association ID and alignment difference.
[0108] Optionally, the process of determining the associated ID table varies depending on the data shift attribute in the alignment difference. The associated ID linked lists for data shift attributes of no shift, left shift, and right shift are described below.
[0109] In one possible implementation, if the data displacement attribute is not moved, the associated ID of each write request corresponds one-to-one with the associated ID of each read request, and the associated ID of the write request is the same as the associated ID of the read request.
[0110] In this scenario, for a write request, the corresponding read request is retrieved based on the associated ID table and alignment difference. Then, based on the address of the write request, the target result corresponding to the read request is written to the destination storage medium, including:
[0111] Get the associated ID of the write request, and get the address of the corresponding write request based on the associated ID; get the result of the read request corresponding to the associated ID, and use the result of the read request as the target result; write the target result to the destination storage medium based on the address of the write request.
[0112] Optional, such as Figure 9 As shown, taking 256 associated IDs as an example, when the data displacement attribute is not moved, the starting source address and the starting destination address are aligned. The associated ID of a read request corresponds to the write request with the same associated ID, and no shifting and reassembly operation is required during the data copying process.
[0113] Optionally, upon receiving a completion response for a write request, the corresponding read / write operation can be marked as complete, the corresponding data replication task can be completed, and the associated ID can be released.
[0114] In another possible implementation, if the data shift attribute is right shift, the associated ID of each write request corresponds to the associated ID of two read requests. The associated ID of the two read requests includes the first read request associated ID and the second read request associated ID. The first read request associated ID is the same as the associated ID of the write request, and the second read request associated ID is the next adjacent associated ID of the associated ID of the write request.
[0115] Optionally, the address of the next adjacent associated ID is greater than the address of the associated ID, and the address interval is the data length of a unit read / write request.
[0116] In this scenario, for a write request, the corresponding read request is retrieved based on the associated ID table and alignment difference. Then, based on the address of the write request, the target result corresponding to the read request is written to the destination storage medium. This also includes:
[0117] Obtain the associated IDs of the two read requests corresponding to the write request, and obtain the results of the first and second read requests respectively. Based on the difference value, divide the first read request result into a first result and a second result, where the data length of the first result is the same as the difference value, and the first result is the low-order part of the first read request result. Based on the difference value, divide the second read request result into a third result and a fourth result, where the data length of the third result is the same as the difference value, and the third result is the low-order part of the second read request result. Reassemble the second and third results to obtain the target result, where the second result is located in the low-order part and the third result is located in the high-order part. Write the target result to the destination storage medium according to the address of the write request.
[0118] Optionally, when obtaining the association IDs of the two corresponding read requests, the association ID of the write request can be used as the association ID of the first read request, and then the association ID table can be queried using the association ID of the write request as an index to obtain the corresponding second read request ID.
[0119] Optional, such as Figure 10 As shown, it can be understood that when the address of the write request is the same as the starting and destination addresses, that is, when the associated ID of the write request is the first associated ID, there is no need to divide the result of the first read request. For the write request with associated ID 7, the associated ID table can be queried with 7 as the index to obtain associated ID 1. Therefore, its target result is determined by a part of the result of the first read request of associated ID 7 and the result of the second read request of associated ID 1. For the write request with associated ID 1, the associated ID table can be queried with 1 as the index to obtain associated ID 6. Therefore, the target result corresponding to the write request with associated ID 1 is determined by a part of the result of the first read request of associated ID 1 and a part of the result of the second read request of associated ID 6.
[0120] Optionally, in the above operation, after obtaining the read request result, the read request result can be stored in the execution unit of the SOC system and a shift and reorganization operation can be performed. Then, the target data is stored in the cache space with the associated ID corresponding to the write request as the index. After the write data is complete, the corresponding write operation will be started, and the target data and the corresponding write address will be pushed to the bus and then written to the destination storage medium.
[0121] Optionally, after a read / write operation related to an associated ID is completed, the associated ID can be released. Simultaneously, it's necessary to determine if the contiguous data space has been used by an additional associated ID due to the read operation. If so, both associated IDs need to be released upon completion of the last write operation, including the additional associated ID used by the corresponding read operation. Figure 10 As shown, the association ID of the last write operation is 15. The read operation uses association IDs 15 and 19 to combine the write data of association ID 15. Therefore, when association ID 15 is released, association ID 19 is also released. It is understood that this application embodiment does not restrict the order between different read and write operations, so when the last write operation of the continuously copied space is completed, there may be cases where previous read and write operations have not been completed.
[0122] In another possible implementation, if the data shift attribute is left shift, the associated ID of each write request corresponds to the associated ID of the third read request, or the associated ID of the third read request and the associated ID of the fourth read request, where the associated ID of the third read request is the same as the associated ID of the write request, and the associated ID of the fourth read request is the adjacent associated ID of the associated ID of the read request.
[0123] Optionally, the address of the previous adjacent associated ID is less than the address of this associated ID, and the address interval is the data length of a unit read / write request.
[0124] In this scenario, for a write request, the corresponding read request is retrieved based on the associated ID table and alignment difference. Then, based on the address of the write request, the target result corresponding to the read request is written to the destination storage medium. This also includes:
[0125] Get the read request associated ID corresponding to the write request, and get the read request result corresponding to the read request associated ID. The read request result includes the third read request result, or the third read request result and the fourth read request result.
[0126] Optionally, when obtaining the read request association ID, the association ID of the write request can be used as an index to query the association ID table and obtain the corresponding value. If the value is an association ID and the value is different from the current association ID, then the read request result is determined to include the third read request result and the fourth read request result; if the corresponding value is not an association ID, then the read request result includes the third request result.
[0127] If the read request result includes the third read request result, the third read request result is divided into the fifth result and the sixth result according to the difference value. The data length of the sixth result is the same as the difference value, and the sixth result is the high-order part of the third read request result. The fifth result is taken as the target result, and the target result is written to the destination storage medium according to the address of the write request.
[0128] Optional, such as Figure 11 As shown, when the write request association ID is the first association ID, the read request result includes the third read request result. The high-order part of the third read request result corresponding to read request association ID 7 should be removed, and the remaining low-order part should be used as the target result.
[0129] If the read request result includes the third read request result and the fourth read request result, the fourth read request result is divided into the seventh result and the eighth result based on the difference value. The data length of the eighth result is the same as the difference value, and the eighth result is the high-order part of the fourth read request result. The fifth result and the eighth result are recombined to obtain the target result. In the target result, the eighth result is located in the low-order part, and the fifth result is located in the high-order part. The target result is written to the destination storage medium according to the address of the write request.
[0130] Optional, such as Figure 11 As shown, when the write request is associated with ID 1, the associated ID table can be queried using 1 as the index to obtain associated ID 7. Therefore, the target result corresponding to the write request of associated ID 1 is determined by a part of the third read request result of associated ID 7 and a part of the fourth read request result of associated ID 1.
[0131] The above method determines the association ID table based on each association ID and the alignment difference. Then, during the data replication process, the corresponding read request is obtained based on the association ID table and the alignment difference. Based on the address of the write request, the target result corresponding to the read request is written to the destination storage medium, which can effectively solve the problem of misaligned starting address.
[0132] As an optional implementation method, such as Figure 12 As shown, the DMA-based data copying method provided in this application embodiment may include the following specific steps:
[0133] Step 1201: Receive data copy instruction.
[0134] The data copy instruction includes the starting source address, the starting destination address, and the length of the copied data.
[0135] Step 1202: Obtain the bus width, which is a power of 2 in bytes.
[0136] Step 1203: Determine the alignment difference based on the lower M bits of the starting source address and the lower M bits of the starting destination address.
[0137] The alignment difference includes the difference value and the data displacement attribute, which includes left shift, right shift, or no shift.
[0138] Step 1204: Obtain the preset data length of the unit read / write request.
[0139] Step 1205: Determine multiple sets of read / write requests based on the data copying instructions and the data length of the unit read / write request, and assign an independent association ID to each read / write request.
[0140] In a set of read and write requests, the associated ID of the read request is the same as the associated ID of the write request.
[0141] Step 1206: If the data displacement attribute is not moved, for a write request, obtain the associated ID of the write request, and obtain the address of the corresponding write request based on the associated ID.
[0142] Each write request has a corresponding ID to each read request, and the write request's ID is the same as the read request's ID.
[0143] Step 1207: For a write request, obtain the result of the read request corresponding to the associated ID, and use the result of the read request as the target result.
[0144] Step 1208: If the data shift attribute is right shift, for a write request, obtain the associated IDs of the two read requests corresponding to the write request, and obtain the results of the first read request and the second read request respectively.
[0145] The association IDs of the two read requests include the first read request association ID and the second read request association ID. The first read request association ID is the same as the write request association ID, and the second read request association ID is the next adjacent association ID of the write request association ID.
[0146] Step 1209: For a write request, the result of the first read request is divided into a first result and a second result based on the difference value.
[0147] The first result has the same data length as the difference value, and the first result is the low-order part of the first read request result.
[0148] Step 1210: For a write request, the result of the second read request is divided into the third result and the fourth result based on the difference value.
[0149] The third result has the same data length as the difference value, and it is the lower-order part of the second read request result.
[0150] Step 1211: For a write request, reassemble the second and third results to obtain the target result.
[0151] Among the target results, the second result is located in the lower position and the third result is located in the higher position.
[0152] Step 1212: If the data shift attribute is left shift, for a write request, obtain the read request association ID corresponding to the write request, and obtain the third read request result corresponding to the read request association ID, or the third read request result and the fourth read request result.
[0153] Among them, the third read request association ID is the same as the write request association ID, and the fourth read request association ID is the previous adjacent association ID of the read request association ID.
[0154] Step 1213: For a write request, if the read request result includes the third read request result, divide the third read request result into the fifth result and the sixth result according to the difference value, and take the fifth result as the target result.
[0155] The sixth result has the same data length as the difference value, and it is the high-order part of the third read request result.
[0156] Step 1214: For a write request, if the read request result includes the third read request result and the fourth read request result, divide the fourth read request result into the seventh result and the eighth result according to the difference value.
[0157] The eighth result has the same data length as the difference value, and it is the high-order part of the fourth read request result.
[0158] Step 1215: For a write request, reassemble the fifth and eighth results to obtain the target result.
[0159] Among the target results, the eighth result is located in the lower position, and the fifth result is located in the higher position.
[0160] Step 1216: For a write request, write the target result to the destination storage medium according to the address of the write request.
[0161] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0162] Based on the same inventive concept, this application also provides a DMA-based data copying apparatus for implementing the DMA-based data copying method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more DMA-based data copying apparatus embodiments provided below can be found in the limitations of the DMA-based data copying method described above, and will not be repeated here.
[0163] In one exemplary embodiment, such as Figure 13 As shown, a DMA-based data copying device is provided, comprising: a receiving module 1301, a calculation module 1302, an association module 1303, and a copying module 1304, wherein:
[0164] The receiving module 1301 is used to receive a data copying instruction, which includes the starting source address, the starting destination address, and the length of the copied data.
[0165] Calculation module 1302 is used to determine the alignment difference between the starting source address and the starting destination address;
[0166] The association module 1303 is used to determine the association ID table based on the data copying instructions and alignment differences. In the association ID table, the association ID of a write request corresponds to one or two association IDs of read requests.
[0167] The replication module 1304 is used to obtain the corresponding read request based on the associated ID table and alignment difference for a write request, and write the target result corresponding to the read request to the destination storage medium according to the address of the write request.
[0168] In one embodiment, the alignment difference includes a difference value and a data displacement attribute, whereby the data displacement attribute includes left shift, right shift, or no shift. The association module 1303 is specifically used to obtain a preset data length for a unit read / write request; determine multiple sets of read / write requests based on the data copy instruction and the data length of the unit read / write request; assign an independent association ID to each read / write request, wherein, in a set of read / write requests, the association ID of the read request is the same as the association ID of the write request; and determine an association ID table based on each association ID and the alignment difference.
[0169] In one embodiment, the association module 1303 is specifically used to ensure that, if the data displacement attribute is no movement, the association ID of each write request corresponds one-to-one with the association ID of each read request, and the association ID of the write request is the same as the association ID of the read request.
[0170] The replication module 1304 is specifically used to obtain the associated ID of the write request, obtain the address of the corresponding write request based on the associated ID, obtain the result of the read request corresponding to the associated ID, use the result of the read request as the target result, and write the target result to the destination storage medium according to the address of the write request.
[0171] In one embodiment, the association module 1303 is specifically used to ensure that if the data displacement attribute is right shift, the association ID of each write request corresponds to the association ID of two read requests. The association ID of the two read requests includes a first read request association ID and a second read request association ID. The first read request association ID is the same as the association ID of the write request, and the second read request association ID is the next adjacent association ID of the association ID of the write request.
[0172] The replication module 1304 is specifically used to obtain the association IDs of the two read requests corresponding to the write request, and to obtain the results of the first read request and the second read request respectively; based on the difference value, the first read request result is divided into a first result and a second result, wherein the data length of the first result is the same as the difference value, and the first result is the low-order part of the first read request result; based on the difference value, the second read request result is divided into a third result and a fourth result, wherein the data length of the third result is the same as the difference value, and the third result is the low-order part of the second read request result; the second result and the third result are recombined to obtain the target result, wherein the second result is located in the low-order part and the third result is located in the high-order part of the target result; and the target result is written to the destination storage medium according to the address of the write request.
[0173] In one embodiment, the association module 1303 is specifically used to, if the data displacement attribute is left shift, assign the association ID of each write request to the association ID of the third read request, or assign the association ID of the third read request to the association ID of the fourth read request, wherein the association ID of the third read request is the same as the association ID of the write request, and the association ID of the fourth read request is the previous adjacent association ID of the association ID of the read request.
[0174] The replication module 1304 is specifically used to obtain the read request association ID corresponding to the write request, and to obtain the read request result corresponding to the read request association ID. The read request result includes the third read request result, or the third read request result and the fourth read request result. If the read request result includes the third read request result, the third read request result is divided into the fifth result and the sixth result according to the difference value. The data length of the sixth result is the same as the difference value, and the sixth result is the high-order part of the third read request result. The fifth result is used as the target result, and the target result is written to the destination storage medium according to the address of the write request.
[0175] In one embodiment, the copy module 1304 is specifically configured to: if the read request result includes a third read request result and a fourth read request result, divide the fourth read request result into a seventh result and an eighth result based on the difference value, wherein the data length of the eighth result is the same as the difference value, and the eighth result is the high-order part of the fourth read request result; reassemble the fifth result and the eighth result to obtain the target result, wherein the eighth result is located in the low-order part and the fifth result is located in the high-order part; and write the target result to the destination storage medium according to the address of the write request.
[0176] In one embodiment, the calculation module 1302 is specifically used to obtain the bus width, which is a power of 2 bytes; and to determine the alignment difference based on the lower M bits of the starting source address and the lower M bits of the starting destination address.
[0177] In one embodiment, if the lower M bits of the starting source address and the lower M bits of the starting destination address are equal, the difference value is 0, and the data shift attribute is no shift; if the lower M bits of the starting source address are greater than the lower M bits of the starting destination address, the difference value is the difference between the lower M bits of the starting source address and the lower M bits of the starting destination address, and the data shift attribute is right shift; if the lower M bits of the starting source address are less than the lower M bits of the starting destination address, the difference value is the difference between the lower M bits of the starting destination address and the lower M bits of the starting source address, and the data shift attribute is left shift.
[0178] The modules in the aforementioned DMA-based data copying device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can invoke and execute requests corresponding to each module.
[0179] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 14 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores a request system, computer programs, and a database. The internal memory provides an environment for the execution of the request system and computer programs in the non-volatile storage media. The database stores data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When executed by the processor, the computer program implements a DMA-based data copying method.
[0180] Those skilled in the art will understand that Figure 14 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0181] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps described in any of the above method embodiments.
[0182] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps described in any of the above method embodiments.
[0183] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps described in any of the above method embodiments.
[0184] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0185] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0186] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A DMA-based data copying method, characterized in that, The method includes: Receive a data copy instruction, the data copy instruction including the starting source address, the starting destination address, and the length of the copied data; Obtain the bus width, which is a power of M bytes of 2; The alignment difference is determined based on the lower M bits of the starting source address and the lower M bits of the starting destination address; An association ID table is determined based on the data copying instruction and the alignment difference. In the association ID table, the association ID of a write request corresponds to one or two association IDs of read requests. For a write request, the corresponding read request is obtained according to the associated ID table and the alignment difference, and the target result corresponding to the read request is written to the destination storage medium according to the address of the write request. The alignment difference includes a difference value and a data displacement attribute, wherein the data displacement attribute includes left shift, right shift, or no shift. The step of determining the associated ID table based on the data copy instruction and the alignment difference includes: Get the preset data length of the unit read / write request; Multiple sets of read and write requests are determined based on the data copying instruction and the data length of the unit read and write request. Each read and write request is assigned an independent association ID. In a set of read and write requests, the association ID of the read request is the same as the association ID of the write request. A related ID table is determined based on each of the related IDs and the alignment differences; If the lower M bits of the starting source address and the lower M bits of the starting destination address are equal, then the difference value is 0, and the data displacement attribute is no movement. If the lower M bits of the starting source address are greater than the lower M bits of the starting destination address, then the difference value is the difference between the lower M bits of the starting source address and the lower M bits of the starting destination address, and the data shift attribute is right shift. If the lower M bits of the starting source address are less than the lower M bits of the starting destination address, then the difference value is the difference between the lower M bits of the starting destination address and the lower M bits of the starting source address, and the data shift attribute is left shift.
2. The method according to claim 1, characterized in that, The step of determining the association ID table based on each of the association IDs and the alignment difference includes: If the data displacement attribute is no movement, the associated ID of each write request corresponds one-to-one with the associated ID of each read request, and the associated ID of the write request is the same as the associated ID of the read request. For a write request, the process of obtaining the corresponding read request based on the associated ID table and the alignment difference, and writing the target result corresponding to the read request to the destination storage medium based on the address of the write request, includes: Obtain the associated ID of the write request, and obtain the address of the corresponding write request based on the associated ID; Obtain the result of the read request corresponding to the associated ID, and use the result of the read request as the target result; Based on the address of the write request, the target result is written to the destination storage medium.
3. The method according to claim 1, characterized in that, The step of determining the association ID table based on each of the association IDs and the alignment difference further includes: If the data displacement attribute is right shift, the associated ID of each write request corresponds to the associated ID of two read requests. The associated ID of the two read requests includes a first read request associated ID and a second read request associated ID. The first read request associated ID is the same as the associated ID of the write request, and the second read request associated ID is the next adjacent associated ID of the associated ID of the write request. For a write request, obtaining the corresponding read request based on the associated ID table and the alignment difference, and writing the target result corresponding to the read request to the destination storage medium according to the address of the write request, further includes: Obtain the associated IDs of the two read requests corresponding to the write request, and obtain the results of the first read request and the second read request respectively; Based on the difference value, the first read request result is divided into a first result and a second result, wherein the data length of the first result is the same as the difference value, and the first result is the low-order part of the first read request result; Based on the difference value, the second read request result is divided into a third result and a fourth result, wherein the data length of the third result is the same as the difference value, and the third result is the low-order part of the second read request result; The second result and the third result are recombined to obtain the target result, wherein the second result is located in the lower part and the third result is located in the higher part. Based on the address of the write request, the target result is written to the destination storage medium.
4. The method according to claim 1, characterized in that, The step of determining the association ID table based on each of the association IDs and the alignment difference further includes: If the data shift attribute is left shift, the associated ID of each write request corresponds to the associated ID of the third read request, or the associated ID of the third read request and the associated ID of the fourth read request. The associated ID of the third read request is the same as the associated ID of the write request, and the associated ID of the fourth read request is the previous adjacent associated ID of the associated ID of the read request. For a write request, obtaining the corresponding read request based on the associated ID table and the alignment difference, and writing the target result corresponding to the read request to the destination storage medium according to the address of the write request, further includes: Obtain the read request association ID corresponding to the write request, and obtain the read request result corresponding to the read request association ID. The read request result includes the third read request result, or the third read request result and the fourth read request result. If the read request result includes a third read request result, the third read request result is divided into a fifth result and a sixth result according to the difference value, wherein the data length of the sixth result is the same as the difference value, and the sixth result is the high-order part of the third read request result; The fifth result is taken as the target result, and the target result is written to the destination storage medium according to the address of the write request.
5. The method according to claim 4, characterized in that, The method further includes: If the read request result includes a third read request result and a fourth read request result, the request result of the fourth read request is divided into a seventh result and an eighth result according to the difference value, wherein the data length of the eighth result is the same as the difference value, and the eighth result is the high-order part of the fourth read request result; The fifth result and the eighth result are recombined to obtain the target result, wherein the eighth result is located in the lower part and the fifth result is located in the higher part; Based on the address of the write request, the target result is written to the destination storage medium.
6. A DMA-based data copying device, characterized in that, The device includes: The receiving module is used to receive data copying instructions, which include the starting source address, the starting destination address, and the length of the copied data; A calculation module is used to obtain the bus width, which is a power of 2 bytes; and to determine the alignment difference based on the lower M bits of the starting source address and the lower M bits of the starting destination address. The association module is used to determine an association ID table based on the data copying instruction and the alignment difference. In the association ID table, the association ID of a write request corresponds to one or two association IDs of read requests. The replication module is used to obtain the corresponding read request based on the associated ID table and the alignment difference for a write request, and write the target result corresponding to the read request to the destination storage medium according to the address of the write request; The alignment difference includes a difference value and a data displacement attribute, wherein the data displacement attribute includes left shift, right shift, or no shift. The association module is specifically used to obtain a preset data length for a unit read / write request; determine multiple sets of read / write requests based on the data copy instruction and the data length of the unit read / write request; assign an independent association ID to each read / write request, wherein in a set of read / write requests, the association ID of the read request is the same as the association ID of the write request; and determine an association ID table based on each association ID and the alignment difference. If the lower M bits of the starting source address and the lower M bits of the starting destination address are equal, then the difference value is 0, and the data displacement attribute is no movement. If the lower M bits of the starting source address are greater than the lower M bits of the starting destination address, then the difference value is the difference between the lower M bits of the starting source address and the lower M bits of the starting destination address, and the data shift attribute is right shift. If the lower M bits of the starting source address are less than the lower M bits of the starting destination address, then the difference value is the difference between the lower M bits of the starting destination address and the lower M bits of the starting source address, and the data shift attribute is left shift.
7. The apparatus according to claim 6, characterized in that, The association module is specifically used to ensure that, when the data displacement attribute is not moved, the association ID of each write request corresponds one-to-one with the association ID of each read request, and the association ID of the write request is the same as the association ID of the read request. The replication module is specifically used to obtain the association ID of the write request and obtain the address of the corresponding write request based on the association ID; Obtain the result of the read request corresponding to the associated ID, and use the result of the read request as the target result; Based on the address of the write request, the target result is written to the destination storage medium.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 5.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Technologies for scaling user interface backend clusters for database-bound applications
CN110325980A
Data buffering method and device
CN110968538A