A method for executing instructions based on shared thread read-write lock

By adopting instruction execution method based on shared thread read and write locks in the processor, the problem of memory access atomicity in the prior art is solved, the atomicity of data access and the stability of application are realized, and the compatibility of the system and the data reading efficiency of the processor are improved.

CN114003280BActive Publication Date: 2025-04-22WUHAN SHENZHIDU TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111287741.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-02
Publication Date
2025-04-22
Estimated Expiration
2041-11-02

AI Technical Summary

Technical Problem

In the prior art, when the processor cannot directly handle special memory access instructions, it needs to be converted into multiple memory accesses, resulting in the atomicity of memory accesses being corrupted, which may lead to data errors or abnormal application operation.

Method used

The instruction execution method based on shared thread read and write lock is adopted. By generating appropriate storage and read instructions, it ensures that in the thread-shared memory of internal memory, data storage and read operations will not be performed simultaneously, thereby maintaining the atomicity of data access.

Benefits of technology

It effectively avoids the abnormal operation problems of application programs caused by the atomicity of memory access, improves the stability of the application and system compatibility, and improves the efficiency of the processor to read data from internal memory.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114003280B_ABST
    Figure CN114003280B_ABST
Patent Text Reader

Abstract

The present invention discloses an instruction execution method, computing device and storage medium based on a shared thread read-write lock. The method comprises the steps of: submitting a first storage instruction for storing data in an internal memory to a processor; generating a second storage instruction; judging whether to store data in a thread shared memory of the internal memory; locking the first thread; storing data in the internal memory through a processor; judging whether to read data in a thread shared memory of the internal memory; if data is read in the thread shared memory, obtaining a shared thread read lock of a second thread that executes the first read instruction; if the shared thread read lock cannot be obtained, obtaining the shared thread read lock again; if the shared thread read lock is obtained, locking the second thread that executes the first read instruction; and reading data from the internal memory through a processor. The present invention can prevent the atomicity of data access from being lost and avoid abnormal operation of certain special applications.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer instruction execution, and in particular to an instruction execution method based on a shared thread read-write lock. Background Art

[0002] With the continuous development of computer technology, more and more applications have been developed. Correspondingly, the application data is increasing, and the data structure is becoming more and more complex. Therefore, the system's memory access performance for complex data structures in memory is becoming more and more important, directly affecting the running speed of key applications. When storing data, special storage situations often occur. When the application accesses these stored data, the processor does not support special memory access instructions for the data, and an error will occur. The processor cannot directly process this type of memory access instruction to operate the data.

[0003] Therefore, in the prior art, in order to access these stored data, the data access instructions are changed so that the instructions for application accessing these data become normal instructions, and the processor can execute the data access. One of the solutions is to convert the original cross-border access instructions into two cross-border access instructions. By executing the two cross-border access instructions, the complete data can be successfully stored or read.

[0004] However, this method converts one memory access into multiple memory accesses, which essentially changes the memory access model of the application. For some special application scenarios, the atomicity of one memory access is destroyed by multiple memory accesses. If the application relies on the atomicity of memory access, in this case, the destruction of atomicity will cause data errors or errors, which may cause the application to run abnormally in severe cases.

[0005] Therefore, a new instruction execution method based on shared thread read-write lock is needed. Summary of the invention

[0006] To this end, the present invention provides an instruction execution method based on a shared thread read-write lock, in an effort to solve or at least alleviate the above problems.

[0007] According to one aspect of the present invention, there is provided an instruction execution method based on a shared thread read-write lock, which is suitable for execution in a computing device, wherein the computing device includes a processor, an internal memory, and runs one or more applications, wherein a storage area of ​​the internal memory is mapped to a storage space, and the application uses a storage address in the storage space to read and write data in the internal memory, and the method includes the steps of: submitting a first storage instruction for storing data in the internal memory to the processor; when the processor cannot normally execute the first storage instruction due to the storage address of the data stored in the first storage instruction, generating a second storage instruction according to a data storage exception message generated by the processor, the second storage instruction being suitable for storing the data to be stored by the first storage instruction, and the processor will not generate a data storage exception message when executing the second storage instruction; judging whether to store the data in the thread shared memory of the internal memory according to the storage address of the data stored in the first storage instruction; if the data is stored in the thread shared memory, then Acquire the shared thread write lock of the first thread that executes the storage instruction, and lock the first thread; through the processor, store data in the internal memory according to the first thread executing the second storage instruction; when receiving the first read instruction to read data in the internal memory, determine whether to read the data in the thread shared memory of the internal memory according to the read address of the data read by the first read instruction; if the data is read in the thread shared memory, acquire the shared thread read lock of the second thread that executes the first read instruction, the shared thread write lock and the shared thread read lock are mutually exclusive, and when locking according to the shared thread write lock or the shared thread read lock, data cannot be stored and read at the same address at the same time; if there is a shared thread write lock and the shared thread read lock cannot be obtained, acquire the shared thread read lock again; if the shared thread read lock is obtained, lock the second thread that executes the first read instruction; through the processor, read data from the internal memory according to the second thread executing the first read instruction.

[0008] Optionally, in the method according to the present invention, generating a second storage instruction according to a data storage exception message generated by a processor includes the steps of: generating a first half storage instruction and a second half storage instruction according to the storage address of the first storage instruction, the first half storage instruction and the second half storage instruction being suitable for storing data according to the first half address and the half address, respectively; and using the first half storage instruction and the second half storage instruction as the second storage instruction.

[0009] Optionally, the method according to the present invention further includes the following steps: if a shared thread read lock exists and the shared thread write lock cannot be obtained, then obtaining the shared thread write lock again; if the shared thread write lock is obtained, storing data through a second storage instruction.

[0010] Optionally, in the method according to the present invention, executing a second storage instruction through a memory to store data in an internal memory includes the steps of: generating first half data and second half data based on the data; executing the first half storage instruction through a processor to store the first half data according to the first half address; executing the second half storage instruction through a processor to store the second half data according to the second half address.

[0011] Optionally, the method according to the present invention further includes the step of: after the processor completes storing the data in the internal memory, releasing the shared thread write lock so that other threads of the processor acquire the shared thread read lock and read the data.

[0012] Optionally, in the method according to the present invention, the first read instruction includes a first half read instruction and a second half read instruction, and reading data through the first read instruction includes the steps of: executing the first half read instruction through the processor, and reading the stored first half data according to the first half address; executing the second half read instruction through the processor, and reading the stored second half data according to the second half address; combining the first half data read from the first half address with the second half data read from the second half address to obtain data.

[0013] Optionally, the method according to the present invention further includes the step of: after the processor finishes reading the data in the internal memory, releasing the shared thread read lock so that other threads of the processor acquire the shared thread write lock and store data.

[0014] Optionally, the method according to the present invention also includes the steps of: setting a read lock number threshold, the read lock number threshold specifies the number of shared thread read locks that can be allowed simultaneously; when acquiring a shared thread read lock, determining whether the number of shared thread read locks that have been acquired reaches the read lock number threshold; if the read lock number threshold is not reached, acquiring the shared thread read lock.

[0015] Optionally, the method according to the present invention also includes the steps of: if a second read instruction is received, submitting the second read instruction to the processor; when the processor cannot execute the second read instruction normally due to the address of the data read by the second read instruction, generating a first read instruction according to the data access exception message generated by the processor, the first read instruction is suitable for reading the data to be read by the second read instruction, and the processor will not generate a data read exception message when executing the first read instruction.

[0016] Optionally, in the method according to the present invention, generating a first read instruction based on a data access exception message generated by a processor includes the steps of: generating a first half read instruction and a second half read instruction based on a storage address of a second read instruction, the first half read instruction and the second half read instruction being suitable for reading data according to the first half address and the second half address, respectively; and using the first half read instruction and the second half read instruction as the first read instruction.

[0017] Optionally, in the method according to the present invention, the first storage instruction includes a non-boundary storage instruction, and the first half storage instruction and the second half storage instruction include bounded storage instructions.

[0018] Optionally, in the method according to the present invention, the second read instruction includes a non-boundary read instruction, and the first half read instruction and the second half read instruction include bounded read instructions.

[0019] According to another aspect of the present invention, a computing device is provided, comprising: one or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include instructions for executing an instruction execution method based on a shared thread read-write lock according to the present invention.

[0020] According to another aspect of the present invention, a computer-readable storage medium storing one or more programs is provided, wherein the one or more programs include instructions that, when executed by a computing device, cause the computing device to execute a method in an instruction execution method based on a shared thread read-write lock according to the present invention.

[0021] The instruction execution method based on the shared thread read-write lock in the present invention is suitable for execution in a computing device, the computing device includes a processor, an internal memory, and runs one or more applications, including the steps of submitting a first storage instruction for storing data in the internal memory to the processor, when the processor cannot normally execute the first storage instruction due to the storage address of the data stored in the first storage instruction, generating a second storage instruction according to the data storage exception message generated by the processor, the second storage instruction is suitable for storing the data to be stored by the first storage instruction, and the processor will not generate a data storage exception message when executing the second storage instruction. In order to avoid that when storing data, threads of other cores of the processor execute data reading instructions, and incomplete data is read from the location where data storage has not been completed, causing the application to run incorrectly, first, it is necessary to determine whether to store data in the thread shared memory of the internal memory according to the storage address of the data stored in the first storage instruction. Since the thread shared memory has multiple threads reading and storing data in it, in order to improve the security of accessing data in the thread shared memory, it is necessary to set a special shared thread read-write lock for it. If data is stored in the thread shared memory, the shared thread write lock of the first thread that executes the storage instruction is obtained, and the first thread is locked. Then, the processor executes the second storage instruction according to the first thread to store data in the internal memory. When the first read instruction for reading data in the internal memory is received, it is determined whether the data is read in the thread shared memory of the internal memory according to the read address read by the first read instruction; if the data is read in the thread shared memory, the thread read lock of the shared second thread that executes the first read instruction is obtained, and the shared thread write lock and the shared thread read lock are mutually exclusive. When locking according to the shared thread write lock or the shared thread read lock, data cannot be stored and read at the same address at the same time. If there is a shared thread write lock and the shared thread read lock cannot be obtained, the shared thread read lock is obtained again. If there are thread writes by other threads, the thread read lock cannot be obtained, and the current storage location is storing data. At this time, reading the data will destroy the integrity of the data and read the wrong data, so the data cannot be read. If the shared thread read lock is obtained, the second thread that executes the first read instruction is locked, and the processor reads the data from the internal memory according to the second thread executing the first read instruction. If the write lock is obtained, the data is read through the first read instruction, indicating that the data storage has been completed at this time and the data can be read normally. The present invention can constrain the edge effects caused by the change of the memory access model of the application program, so that the atomicity of data access is not lost, thereby avoiding the abnormal operation of some special application programs caused by such edge effects, thereby improving the stability of the application program and the compatibility of the entire system. In addition, multiple shared thread read locks are set, and by allocating shared thread read locks to one or more threads, multiple threads can read data at the same time, thereby improving the efficiency of the processor in reading data from the internal memory. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to achieve the above and related purposes, certain illustrative aspects are described herein in conjunction with the following description and accompanying drawings, which indicate various ways in which the principles disclosed herein can be practiced, and all aspects and their equivalents are intended to fall within the scope of the claimed subject matter. By reading the following detailed description in conjunction with the accompanying drawings, the above and other purposes, features and advantages disclosed by the present invention will become more apparent. Throughout the present disclosure, the same reference numerals generally refer to the same parts or elements.

[0023] Figure 1 A schematic diagram showing a structure of a processor and an internal memory deployed in a computing device according to an exemplary embodiment of the present invention is shown;

[0024] Figure 2 shows a block diagram of a computing device 200 according to an exemplary embodiment of the present invention;

[0025] Figure 3 A schematic flow chart of an instruction execution method 300 based on a shared thread read-write lock according to an exemplary embodiment of the present invention is shown;

[0026] Figure 4 A schematic diagram showing generating a second storage instruction according to an exemplary embodiment of the present invention; and

[0027] Figure 5 A schematic diagram of destroying instruction atomicity according to an exemplary embodiment of the present invention is shown. DETAILED DESCRIPTION

[0028] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to enable the scope of the present disclosure to be fully conveyed to those skilled in the art. The same reference numerals generally refer to the same components or elements.

[0029] Figure 1 FIG. 1 shows a schematic diagram of a structure in which a processor and an internal memory are deployed in a computing device according to an exemplary embodiment of the present invention. Figure 1 As shown, the computing device 200 includes a processor 204 and an internal memory 140. An operating system 220 is also installed in the computing device 200, and the application 110 runs on the operating system 220. The present invention does not limit the specific type of the operating system 220. Figure 1The number of applications shown is only exemplary. There is no limit to the number and type of applications running on the operating system 220. The internal memory 140 is suitable for storing the operating data of the operating system 220 and the applications 110, and the processor 204 is suitable for processing the operating data.

[0030] Figure 1 The specific structure of the computing device 200 is as follows: Figure 2 Provide detailed explanation. Figure 2 FIG. 2 shows a block diagram of a computing device 200 according to an exemplary embodiment of the present invention. Figure 2 As shown, in a basic configuration 202, computing device 200 typically includes a system memory 206 and one or more processors 204. A memory bus 208 may be used for communication between processor 204 and system memory 206.

[0031] Depending on the desired configuration, the processor 204 can be any type of processor, including but not limited to: a microprocessor (μP), a microcontroller (μC), a digital information processor (DSP), or any combination thereof. The processor 204 can include one or more levels of cache such as a primary cache 210 and a secondary cache 212, a processor core 214, and registers 216. An example processor core 214 can include an arithmetic logic unit (ALU), a floating point unit (FPU), a digital signal processing core (DSP core), or any combination thereof. An example memory controller 218 can be used with the processor 204, or in some implementations, the memory controller 218 can be an internal part of the processor 204.

[0032] Depending on the desired configuration, the system memory 206 may be any type of memory, including but not limited to: volatile memory (such as RAM), non-volatile memory (such as ROM, flash memory, etc.), or any combination thereof. The system memory 206 may include an operating system 220, one or more programs 222, and program data 228. In some embodiments, the program 222 may be arranged to be executed by one or more processors 204 on the operating system using the program data 228 to execute the instructions 223 of the method 300 according to the present invention.

[0033] The computing device 200 may also include a storage interface bus 234. The storage interface bus 234 enables communication from storage devices 232 (e.g., removable storage 236 and non-removable storage 238) to the basic configuration 202 via the bus / interface controller 230. At least a portion of the operating system 220, the program 222, and the data 224 may be stored on the removable storage 236 and / or the non-removable storage 238, and when the computing device 200 is powered on or the program 222 is to be executed, it is loaded into the system memory 206 via the storage interface bus 234 and executed by the one or more processors 204.

[0034] The computing device 200 may also include an interface bus 240 that facilitates communication from various interface devices (e.g., output devices 242, peripheral interfaces 244, and communication devices 246) to the basic configuration 202 via the bus / interface controller 230. Example output devices 242 include a graphics processing unit 248 and an audio processing unit 250. They can be configured to facilitate communication with various external devices such as a display or speakers via one or more A / V ports 252. Example peripheral interfaces 244 may include a serial interface controller 254 and a parallel interface controller 256, which may be configured to facilitate communication with external devices such as input devices (e.g., keyboards, mice, pens, voice input devices, touch input devices) or other peripherals (e.g., printers, scanners, etc.) via one or more I / O ports 258. Example communication devices 246 may include a network controller 260, which may be arranged to communicate with one or more other computing devices 262 via a network communication link via one or more communication ports 264.

[0035] A network communication link can be an example of a communication medium. Communication media can generally be embodied as computer-readable instructions, data structures, program modules in a modulated data signal such as a carrier wave or other transmission mechanism, and can include any information delivery medium. A "modulated data signal" can be a signal in which one or more of its data sets or its changes can be carried out in a manner that encodes information in the signal. As non-limiting examples, communication media can include wired media such as a wired network or a dedicated line network, and various wireless media such as sound, radio frequency (RF), microwave, infrared (IR) or other wireless media. The term computer-readable medium used herein can include both storage media and communication media.

[0036] In the computing device 200 according to the present invention, the program 222 includes multiple program instructions of the instruction execution method 300 based on a shared thread read-write lock, and these program instructions can instruct the processor 204 to execute some steps in running the instruction execution method 300 based on a shared thread read-write lock in the computing device 200 of the present invention, so that each part in the computing device 200 executes instructions by executing the instruction execution method 300 based on a shared thread read-write lock.

[0037] The computing device 200 can be implemented as a server, such as a file server 240, a database 250, a server, an application server, etc. These electronic devices can be such as personal digital assistants (PDAs), wireless network browsing devices, application-specific devices, or hybrid devices that can include any of the above functions. It can be implemented as a personal computer including desktop computers and notebook computer configurations. In some embodiments, the computing device 200 is configured to execute the instruction execution method 300 based on a shared thread read-write lock.

[0038] Figure 3 FIG. 3 is a flow chart of an instruction execution method 300 based on a shared thread read-write lock according to an exemplary embodiment of the present invention. The instruction execution method 300 based on a shared thread read-write lock in the present invention is suitable for execution in a computing device, and is further suitable for execution by a computer such as Figure 1 The operating system 220 shown in FIG. Figure 3 As shown, the instruction execution method 300 based on the shared thread read-write lock begins with step S301, submitting the first storage instruction of the application 110 to store data in the internal memory 140 to the processor 204. When the application 110 needs to store data in the internal memory 140, it needs to submit the first storage instruction of the storage data to the processor 204 for execution via the operating system 220. The storage area of ​​the internal memory 140 is mapped to the storage space, and the application 110 stores data in the internal memory 140 with the storage address in the storage space.

[0039] Subsequently, step S302 is executed. When the processor 204 cannot normally execute the first storage instruction due to the storage address of the data stored in the first storage instruction, a second storage instruction is generated according to the data storage exception message generated by the processor 204. The second storage instruction is suitable for storing the data to be stored by the first storage instruction, and the processor 204 does not generate a data storage exception message when executing the second storage instruction.

[0040] According to one embodiment of the present invention, when the storage address is not bounded in the internal memory 140, the processor 204 cannot execute the special operation instruction, and a data storage exception message will be generated. The first storage instruction includes a non-bounded storage instruction. When the data to be read by the application 110 is not stored in the internal memory 140, the first operation instruction is a non-bounded memory access instruction, and the data storage exception message is a non-bounded memory storage exception. Non-bounded means that the starting position of the data stored in the memory is not aligned with the natural boundary of the data of this type stored sequentially in the memory. For example, a 32-bit register, when storing data normally, the register stores a complete 32-bit data, and the first address of the data storage is the first address of the register. However, when the storage is not bounded, the calculator only stores a part of the 32-bit data, and the first address of the 32-bit data is offset from the first address of the register, and the first address of the data is at a certain address in the middle of the register. The other part of the 32-bit data is stored in the next register. Or for a 32-bit register, the processor 204 supports reading 16 bits of data at a time. When the first address of the 16-bit data is in the middle of the 32-bit register, that is, cross-border storage of the 16-bit data occurs, the processor 204 cannot read the data normally. The processor 204 cannot completely retrieve the 16-bit data stored separately according to one instruction, so the processor 204 will throw an exception. The non-bounded memory storage exception means that on a processor 204 that does not support direct storage of non-bounded data, directly storing non-bounded data will cause the processor 204 to throw an exception.

[0041] Figure 4 FIG. 4 is a schematic diagram showing a method of generating a second storage instruction according to an exemplary embodiment of the present invention. Figure 4 As shown, when converting the out-of-bounds memory access instruction, the instruction decomposition calculation sequence is first executed, and the first half storage instruction and the second half storage instruction are generated according to the storage address of the first storage instruction. The first half storage instruction and the second half storage instruction are respectively suitable for storing data according to the first half address and the half address, and finally the first half storage instruction and the second half storage instruction are used as the second storage instruction. The first half storage instruction and the second half storage instruction include the in-bounds storage instruction.

[0042] In the above instruction conversion process, the memory access model of application 110 is changed, and one memory operation is split into multiple operations, which leads to edge effects, especially changes in the atomicity of memory access. When the correctness of the running logic of application 110 depends on the assumption of atomicity, the lack of atomicity will cause the application 110 to run abnormally.

[0043] Figure 5 FIG. 2 shows a schematic diagram of destroying instruction atomicity according to an exemplary embodiment of the present invention. Figure 5As shown, since the first half memory access instruction and the second half memory access instruction are two independent operations, there is no atomicity, and there is a horizon gap between them, and other horizons can be inserted. If a thread of another processing core performs a memory access and write operation in its horizon, the integrity of the data will be destroyed, which may cause the application 110 to run abnormally.

[0044] Then, step S303 is executed to determine whether to store the data in the thread shared memory of the internal memory according to the storage address of the data stored by the first storage instruction. Since the thread shared memory has multiple threads reading and storing data therein, in order to improve the security of accessing data in the thread shared memory, a special shared thread read-write lock needs to be set for it.

[0045] Subsequently, step S304 is executed. If data is stored in the thread shared memory, the shared thread write lock of the first thread that executes the storage instruction is obtained, and the first thread is locked. The shared thread read-write lock includes a shared thread write lock and multiple shared thread read locks. Each thread can obtain a shared thread write lock and a shared thread read lock. The shared thread write lock and the shared thread read lock respectively lock the thread that executes the storage instruction and the thread that executes the read instruction, so that data cannot be stored and read at the same address of the internal memory at the same time. The shared thread write lock and the shared thread read lock are mutually exclusive, and there is only one shared thread write lock. Only one thread among multiple threads can obtain the shared thread write lock to store data; during this period, other threads cannot obtain the shared thread read lock to read data. When no thread obtains the shared thread read lock, one or more threads can obtain the shared thread read lock and read data at the same time. Improve data reading and writing efficiency. The storage instruction includes a first storage instruction and a second storage instruction, and the read instruction includes a first read instruction and a second read instruction. After the first thread executing the storage instruction is locked, data reading operation cannot be performed at the storage address of the storage instruction in the internal memory, thereby avoiding damage to data integrity when reading data and reading wrong data, so that data cannot be read.

[0046] According to one embodiment of the present invention, when acquiring the shared thread write lock at this time, if there is a shared thread read lock and the shared thread write lock cannot be acquired, the shared thread write lock is acquired again. The existence of a shared thread read lock indicates that the data at the storage address is being read, and writing data at this time will cause a storage error. It should be necessary to acquire the shared thread write lock again. If the shared thread write lock is acquired, the data is stored through the second storage instruction. If the shared thread write lock is acquired, it means that the data at the storage address has been read and new data can be written. If there is still a shared thread read lock, the shared write lock continues to be acquired until there is no shared thread read lock and the shared thread write lock is acquired.

[0047] Then, step S305 is executed, and the processor executes the second storage instruction according to the first thread to store data in the internal memory 140. Specifically, the first half of the data and the second half of the data are first generated according to the data, and then the processor 204 executes the first half of the storage instruction to store the first half of the data according to the first half of the address, and finally the processor 204 executes the second half of the storage instruction to store the second half of the data according to the second half of the address.

[0048] After the processor 204 finishes storing the data in the internal memory 140 , the shared thread write lock is released so that other threads of the processor can obtain the shared thread read lock and read the data.

[0049] During the data storage process, if other threads need to execute instructions to access data and need to operate in the storage segment of the thread shared memory currently writing data, step S306 is executed to protect the atomicity of the data writing process. When a first read instruction to read data in the internal memory is received, it is determined whether to read data in the thread shared memory of the internal memory according to the read address of the data read by the first read instruction.

[0050] Then, step S307 is executed. If data is read in the thread shared memory, the shared thread read lock of the second thread executing the first read instruction is acquired. If there is no shared thread write lock, the shared thread read lock is successfully acquired, indicating that the storage segment has completed data storage and data can be read normally.

[0051] Then, step S308 is executed. If a shared thread write lock exists and the thread read lock cannot be obtained, the shared thread read lock is obtained again. If a shared thread write lock exists, it means that the storage segment is storing data. If data is read at this time, wrong and incomplete data will be read. The shared thread read lock is obtained again, that is, it is determined again whether a shared thread write lock still exists.

[0052] If there is still a shared thread write lock and the shared thread read lock cannot be obtained at this time, the shared thread read lock will continue to be obtained, and the determination of whether the data storage is complete will continue until the data storage is complete and the shared thread read lock can be obtained. In the process of repeatedly obtaining the shared thread read lock, the thread that obtains the shared thread write lock is also writing data. When the data writing is completed, the data can be read normally and the loop can be exited, thereby preventing the reading of incorrect data.

[0053] Then, step S309 is executed, and if the shared thread read lock is acquired, the second thread executing the first read instruction is locked. After the second thread executing the read instruction is locked, the data storage operation cannot be performed under the read address of the read instruction in the internal memory, thereby avoiding storage data errors when storing data, destroying the integrity of the data, reading wrong data, and therefore being unable to write data.

[0054] Finally, step S310 is executed, and data is read from the internal memory through the processor according to the second thread executing the first read instruction. When reading data, the processor 204 executes the first half read instruction to read the stored first half data according to the first half address; the processor 204 executes the second half instruction to read the stored second half data according to the second half address; then the first half data read from the first half address is combined with the second half data read from the second half address to obtain data. When the first half data and the second half data are combined and sorted, according to the data structure of the first half data and the second half data, the obtained first half data and the second half data are subjected to logical bit operations such as shift, AND, OR, and the required data is intercepted from the data obtained by the boundary access instruction and aligned.

[0055] After the processor 204 finishes reading the data in the internal memory 140 , the shared thread read lock is released so that other threads of the processor can obtain the shared thread write lock and store the data.

[0056] According to one embodiment of the present invention, a read lock number threshold is also set, and the read lock number threshold specifies the number of shared thread read locks that can be allowed at the same time. Avoid obtaining too many thread read locks, which causes large computing resource consumption and reduces the execution speed of the application. When obtaining a shared thread read lock, it is determined whether the number of shared thread read locks that have been obtained has reached the read lock number threshold. If the read lock number threshold is not reached, the shared thread read lock is obtained. If the read lock number threshold is reached, the thread read lock fails to be obtained, and the thread read lock continues to be obtained until the number of thread read locks that have been obtained is less than the read lock number threshold, and then the thread read lock is obtained.

[0057] According to one embodiment of the present invention, when performing instruction conversion, when a certain instruction in the execution instruction stream is a non-bounded memory access instruction, it will be converted to an in-bounded memory access instruction. And all instructions after the instruction stream are traversed, and subsequent non-bounded memory access instructions are converted to in-bounded memory access instructions. Non-bounded memory access instructions include non-bounded read instructions and non-bounded store instructions, and in-bounded memory access instructions include in-bounded read instructions and in-bounded store instructions.

[0058] If a second read instruction is received in the instruction stream, and the second read instruction includes an out-of-bounds read instruction that has not been converted, the second read instruction is first submitted to the processor 204. When the processor 204 cannot normally execute the second read instruction due to the address of the data read by the second read instruction, a first read instruction is generated according to the data access exception message generated by the processor 204, and the first read instruction is suitable for reading the data to be read by the second read instruction, and the processor 204 does not generate a data read exception message when executing the first read instruction.

[0059] When the first read instruction is generated according to the data access exception message generated by the processor 204, the instruction decomposition sequence is executed first, and the first half read instruction and the second half read instruction are generated according to the storage address of the second read instruction. The first half read instruction and the second half read instruction are suitable for reading data according to the first half address and the second half address, respectively. The first half read instruction and the second half read instruction are used as the first read instruction.

[0060] The instruction execution method based on the shared thread read-write lock in the present invention is suitable for execution in a computing device, the computing device includes a processor, an internal memory, and runs one or more applications, including the steps of submitting a first storage instruction for storing data in the internal memory to the processor, when the processor cannot normally execute the first storage instruction due to the storage address of the data stored in the first storage instruction, generating a second storage instruction according to the data storage exception message generated by the processor, the second storage instruction is suitable for storing the data to be stored by the first storage instruction, and the processor will not generate a data storage exception message when executing the second storage instruction. In order to avoid that when storing data, threads of other cores of the processor execute data reading instructions, and incomplete data is read from the location where data storage has not been completed, causing the application to run incorrectly, first, it is necessary to determine whether to store data in the thread shared memory of the internal memory according to the storage address of the data stored in the first storage instruction. Since the thread shared memory has multiple threads reading and storing data in it, in order to improve the security of accessing data in the thread shared memory, it is necessary to set a special shared thread read-write lock for it. If data is stored in the thread shared memory, the shared thread write lock of the first thread that executes the storage instruction is obtained, and the first thread is locked. Then, the processor executes the second storage instruction according to the first thread to store data in the internal memory. When the first read instruction for reading data in the internal memory is received, it is determined whether the data is read in the thread shared memory of the internal memory according to the read address read by the first read instruction; if the data is read in the thread shared memory, the thread read lock of the shared second thread that executes the first read instruction is obtained, and the shared thread write lock and the shared thread read lock are mutually exclusive. When locking according to the shared thread write lock or the shared thread read lock, data cannot be stored and read at the same address at the same time. If there is a shared thread write lock and the shared thread read lock cannot be obtained, the shared thread read lock is obtained again. If there are thread writes by other threads, the thread read lock cannot be obtained, and the current storage location is storing data. At this time, reading the data will destroy the integrity of the data and read the wrong data, so the data cannot be read. If the shared thread read lock is obtained, the second thread that executes the first read instruction is locked, and the processor reads the data from the internal memory according to the second thread executing the first read instruction. If the write lock is obtained, the data is read through the first read instruction, indicating that the data storage has been completed at this time and the data can be read normally. The present invention can constrain the edge effects caused by the change of the memory access model of the application program, so that the atomicity of data access is not lost, thereby avoiding the abnormal operation of some special application programs caused by such edge effects, thereby improving the stability of the application program and the compatibility of the entire system. In addition, multiple shared thread read locks are set, and by allocating shared thread read locks to one or more threads, multiple threads can read data at the same time, thereby improving the efficiency of the processor in reading data from the internal memory.

[0061] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

[0062] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this method of disclosure should not be interpreted as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim.

[0063] Those skilled in the art will appreciate that the modules or units or groups of the devices in the examples disclosed herein may be arranged in the device as described in the embodiment, or alternatively may be located in one or more devices different from the devices in the example. The modules in the foregoing examples may be combined into one module or may be divided into multiple submodules.

[0064] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or groups in the embodiments may be combined into one module or unit or group, and in addition they may be divided into a plurality of submodules or subunits or subgroups. All features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device so disclosed may be combined in any combination, except that at least some of such features and / or processes or units are mutually exclusive. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.

[0065] Furthermore, those skilled in the art will appreciate that although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features from different embodiments is meant to be within the scope of the present invention and to form different embodiments.

[0066] In addition, some of the embodiments are described herein as methods or combinations of method elements that can be implemented by a processor of a computer system or by other devices that perform the functions. Therefore, a processor with necessary instructions for implementing the method or method elements forms a device for implementing the method or method elements. In addition, the elements described herein of the device embodiments are examples of devices for implementing the functions performed by the elements for the purpose of implementing the invention.

[0067] The various techniques described herein may be implemented in combination with hardware or software, or a combination thereof. Thus, the method and apparatus of the present invention, or some aspects or portions of the method and apparatus of the present invention may be in the form of program codes (i.e., instructions) embedded in a tangible medium, such as a floppy disk, a CD-ROM, a hard disk drive, or any other machine-readable storage medium, wherein when the program is loaded into a machine such as a computer and executed by the machine, the machine becomes a device for practicing the present invention.

[0068] In the case where the program code is executed on a programmable computer, the computing device generally includes a processor, a storage medium readable by the processor (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device. The memory is configured to store the program code; the processor is configured to execute the instruction execution method based on the shared thread read-write lock of the present invention according to the instructions in the program code stored in the memory.

[0069] By way of example and not limitation, computer readable media include computer storage media and communication media. Computer readable media include computer storage media and communication media. Computer storage media stores information such as computer readable instructions, data structures, program modules or other data. Communication media generally embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and includes any information delivery medium. Any combination of the above is also included within the scope of computer readable media.

[0070] As used herein, unless otherwise specified, the use of ordinal numbers "first," "second," "third," etc. to describe common objects merely indicates that different instances of similar objects are involved, and is not intended to imply that the objects so described must have a given order in time, space, order, or in any other manner.

[0071] Although the present invention has been described according to a limited number of embodiments, it will be apparent to those skilled in the art, with the benefit of the above description, that other embodiments may be envisioned within the scope of the invention thus described. In addition, it should be noted that the language used in this specification is selected primarily for readability and teaching purposes, rather than for explaining or defining the subject matter of the present invention. Therefore, many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the appended claims. The disclosure of the present invention is illustrative, not restrictive, with respect to the scope of the present invention, which is defined by the appended claims.

Claims

1. A method for executing instructions based on a shared thread read-write lock, suitable for execution in a computing device, the computing device comprising a processor, an internal memory, and running one or more applications, the storage area of ​​the internal memory is mapped as a storage space, and the application reads and writes data in the internal memory with a storage address in the storage space, the method comprising the steps of: submitting a first storage instruction of the application to store data in the internal memory to the processor; When the processor cannot normally execute the first storage instruction due to the storage address of the data stored by the first storage instruction, a second storage instruction is generated according to the data storage exception message generated by the processor, the first storage instruction includes an out-of-bounds storage instruction, the second storage instruction is suitable for storing the data to be stored by the first storage instruction, and the processor does not generate a data storage exception message when executing the second storage instruction; Determining whether to store the data in the thread shared memory of the internal memory according to the storage address of the data stored by the first storage instruction; If the data is stored in the thread shared memory, a shared thread write lock of the first thread executing the storage instruction is acquired, and the first thread is locked; executing, by the processor, the second storage instruction according to the first thread to store data in the internal memory; When receiving a first read instruction to read data in the internal memory, determining whether to read the data in the thread shared memory of the internal memory according to a read address of the data read by the first read instruction; If data is read in the thread shared memory, the shared thread read lock of the second thread executing the first read instruction is acquired, and the shared thread write lock and the shared thread read lock are mutually exclusive. When locking according to the shared thread write lock or the shared thread read lock, data cannot be stored and read at the same address at the same time; If there is a shared thread write lock and the shared thread read lock cannot be obtained, the shared thread read lock is obtained again; If the shared thread read lock is acquired, locking the second thread executing the first read instruction; By means of the processor, executing the first read instruction according to the second thread to read data from the internal memory; Wherein, generating a second storage instruction according to the data storage exception message generated by the processor comprises the steps of: Generate a first half storage instruction and a second half storage instruction according to the storage address of the first storage instruction, wherein the first half storage instruction and the second half storage instruction are respectively suitable for storing data according to the first half address and the second half address; Using the first half storage instruction and the second half storage instruction as the second storage instruction; The method further comprises: If a second read instruction is received, submitting the second read instruction to the processor, the second read instruction comprising an out-of-bounds read instruction; When the processor cannot normally execute the second read instruction due to the address of the data to be read by the second read instruction, generating a first read instruction according to the data access exception message generated by the processor, the first read instruction is suitable for reading the data to be read by the second read instruction, and the processor does not generate a data read exception message when executing the first read instruction; Generating a first read instruction according to the data access exception message generated by the processor comprises the steps of: Generate a first half read instruction and a second half read instruction according to the storage address of the second read instruction, wherein the first half read instruction and the second half read instruction are respectively suitable for reading data according to the first half address and the second half address, and the first half read instruction and the second half read instruction are two independent operations; The first half read instruction and the second half read instruction are used as the first read instruction.

2. The method of claim 1, wherein: The method further comprises the steps of: If there is a shared thread read lock and the shared thread write lock cannot be obtained, the shared thread write lock is obtained again; If the shared thread write lock is acquired, the data is stored through the second storage instruction.

3. The method of claim 2, wherein: The storing of data in the internal memory by executing the second storage instruction by the first thread through the processor comprises the steps of: Generate first half data and second half data according to the data; Executing the first half storage instruction by the processor, storing the first half data according to the first half address; The processor executes the second half storage instruction and stores the second half data according to the second half address.

4. The method of claim 3, wherein: The method further comprises the steps of: After the processor finishes storing the data in the internal memory, the shared thread write lock is released so that other threads of the processor can obtain the shared thread read lock and read the data.

5. The method of claim 4, wherein: The first read instruction includes a first half read instruction and a second half read instruction, and reading data through the first read instruction includes the steps of: Executing the first half read instruction by the processor to read the first half data stored according to the first half address; Executing the second half read instruction by the processor to read the stored second half data according to the second half address; The first half data read from the first half address and the second half data read from the second half address are combined to obtain data.

6. The method of claim 5, wherein: The method further comprises the steps of: After the processor finishes reading the data in the internal memory, the shared thread read lock is released so that other threads of the processor can obtain the shared thread write lock and store the data.

7. The method of claim 6, wherein: The method further comprises the steps of: Setting a read lock number threshold, wherein the read lock number threshold specifies the number of shared thread read locks that can be allowed simultaneously; When acquiring a shared thread read lock, determine whether the number of shared thread read locks that have been acquired reaches the read lock number threshold; If the read lock number threshold is not reached, the shared thread read lock is acquired.

8. The method according to any one of claims 1 to 7, wherein: The first half storage instruction and the second half storage instruction include boundary storage instructions.

9. The method according to any one of claims 1 to 7, wherein: The second read instruction includes a non-boundary read instruction, and the first half read instruction and the second half read instruction include boundary read instructions.

10. A computing device comprising: one or more processors; Memory; as well as One or more devices comprising instructions for executing the method according to any one of claims 1-9.

11. A computer-readable storage medium storing one or more programs, the one or more programs comprising instructions which, when executed by a computing device, cause the computing device to perform the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Internal memory access method and device

    CN106407131A

  • Reading / writing-lock operation method, reading / writing-lock operation system and reading / writing-lock operation equipment

    CN107807858A

  • Processing method and device for access exception of processor, storage medium and computing equipment

    CN113535451A