Lock address contention predictor
By using the speculative lock mechanism and contention prediction in the shared memory architecture, the lock execution strategy is adjusted according to the contention situation, which solves the problem of atomic access between threads and improves efficiency but requires attention to the potential time loss.
Patent Information
- Application Number
- CN201780056416.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2017-09-06
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2037-09-06
AI Technical Summary
In shared memory architectures, atomic accesses between threads can lead to data corruption, existing locking mechanisms are costly in terms of processing time and delay the thread or process that maintains the lock, and relaxing lock properties can lead to invalid data and time loss.
By detecting the thread's lock instruction on the memory entry, using the speculative lock mechanism, deciding whether to execute the lock non-speculatively or speculatively based on the contention during the previous speculative lock period and the threshold number, using lock address contention prediction and time lock contention prediction To adjust the locking strategy to avoid flushing the execution pipeline.
It reduces the burden of the lock mechanism on processing time, improves the efficiency of inter-thread access, and avoids the generation of invalid data. However, attention should be paid to the time loss of flushing and restarting, which may be more costly in some cases.
Smart Images

Figure CN109791470B_ABST
Abstract
Description
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims the benefit of U.S. Patent Application No. 15 / 273,304, filed September 22, 2016, which is incorporated by reference as if fully set forth herein. Background Art
[0003] Shared memory computing architectures allow multiple threads to access the same memory, such as cache memory or other levels of a memory hierarchy. For example, a single processor or processor core can execute multiple threads or processes, each thread or process accessing a shared memory shared by the threads and / or processes, such as a cache. Similarly, multiple processors or cores of a multi-core processor can execute multiple threads or processes, each thread and / or process accessing a shared memory shared by the processor or core and by the threads and / or processes, such as a cache. BRIEF DESCRIPTION OF THE DRAWINGS
[0004] A more detailed understanding may be obtained from the following description given by way of example in conjunction with the accompanying drawings, in which:
[0005] Figure 1 is a block diagram of an exemplary apparatus in which one or more disclosed embodiments may be implemented.
[0006] Figure 2 It shows that Figure 1 A block diagram of an example multi-core processor that can be used in conjunction with an apparatus and that can be used to implement one or more disclosed embodiments.
[0007] Figure 3 is a flow chart illustrating an example method for performing speculative locks.
[0008] Figure 4 is a flow chart illustrating an example method for performing speculative locks using lock address contention prediction.
[0009] Figure 5 is a block diagram illustrating the functionality of an example lock address contention prediction write request monitoring circuitry.
[0010] Figure 6 is a block diagram illustrating an example lock address contention prediction mechanism.
[0011] Figure 7 is a flow chart illustrating an example method for performing speculative locks using temporal lock contention prediction.
[0012] Figure 8 is a flow chart illustrating an example method for performing speculative locks using temporal lock contention prediction. DETAILED DESCRIPTION
[0013] Some embodiments provide a method for locking an entry in a memory device. A lock instruction executed by a thread for a particular memory entry of a memory device is detected. Under the condition that the lock instruction includes a speculative lock instruction, whether contention occurred for the particular memory entry during a previous speculative lock. If contention occurred for the particular memory entry during the previous speculative lock, the lock is performed non-speculatively. If contention did not occur for the particular memory entry during the previous speculative lock, the lock is performed speculatively.
[0014] Some embodiments provide a method for locking an entry in a memory device. Detecting a lock instruction executed by a thread for a particular memory entry of a memory device. Under the condition that the lock instruction includes a speculative lock instruction, detecting whether a number of previous speculative locks of the memory that were contended for during a particular time period exceeds a threshold number. If the number exceeds the threshold number, executing the lock non-speculatively. If the number does not exceed the threshold number, executing the lock speculatively.
[0015] Some embodiments provide a processing device configured for speculative locking. The device includes: a processor core having an execution pipeline; a lock instruction detection circuit system configured to detect a lock instruction executed by a thread for a specific memory entry of a memory device; a contention detection circuit system configured to detect whether contention occurred for the specific memory entry during a previous speculative lock if the lock instruction includes a speculative lock instruction; a locking circuit system configured to non-speculatively execute the lock if contention occurred for the specific memory entry during a previous speculative lock; and the locking circuit system is further configured to speculatively execute the lock if contention did not occur for the specific memory entry during a previous speculative lock.
[0016] Some embodiments provide a processing device configured for speculative locking. The device includes: a processor core, the processor core including an execution pipeline; a lock instruction detection circuit system, the lock instruction detection circuit system is configured to detect a lock instruction executed by a thread for a specific memory entry of a memory device; a contention detection circuit system, the contention detection circuit system is configured to detect whether the number of previous speculative locks of the memory that have been contented during a specific time period exceeds a threshold number if the lock instruction includes a speculative lock instruction; a locking circuit system, the locking circuit system is configured to non-speculatively execute the lock if the number exceeds the threshold number; and the locking circuit system is further configured to speculatively execute the lock if the number does not exceed the threshold number.
[0017] Figure 1 1 is a block diagram of an example device 100 in which one or more disclosed embodiments may be implemented. Device 100 may include, for example, a computer, a gaming device, a handheld device, a set-top box, a television, a mobile phone, or a tablet computer. Device 100 includes a processor 102, a memory 104, a storage device 106, one or more input devices 108, and one or more output devices 110. Device 100 may also optionally include an input driver 112 and an output driver 114. It should be understood that device 100 may include Figure 1 Additional components not shown.
[0018] Processor 102 may include a central processing unit (CPU), a graphics processing unit (GPU), a CPU and a GPU on the same die, or one or more processor cores, where each processor core may be a CPU or a GPU. Memory 104 may be on the same die as processor 102, or may be located separately from processor 102. Memory 104 may include volatile or non-volatile memory, such as random access memory (RAM), dynamic RAM, or cache.
[0019] The storage device 106 may include a fixed storage device or a removable storage device, such as a hard disk drive, a solid state drive, an optical disk, or a flash drive. The input device 108 may include a keyboard, a keypad, a touch screen, a touch pad, a detector, a microphone, an accelerometer, a gyroscope, a biometric scanner, or a network connection (e.g., a wireless LAN card for transmitting and / or receiving wireless IEEE 802 signals). The output device 110 may include a display, a speaker, a printer, a tactile feedback device, one or more lights, an antenna, or a network connection (e.g., a wireless LAN card for transmitting and / or receiving wireless IEEE 802 signals).
[0020] The input driver 112 communicates with the processor 102 and the input device 108 and allows the processor 102 to receive input from the input device 108. The output driver 114 communicates with the processor 102 and the output device 110 and allows the processor 102 to send output to the output device 110. It should be noted that the input driver 112 and the output driver 114 are optional components and that the device 100 would operate in the same manner if the input driver 112 and the output driver 114 were not present.
[0021] Figure 2is a schematic diagram illustrating an example multi-core processor 200 including two processing cores 210 and 220. Processor 200 may be used with device 100, for example, as processor 102. Cores 210 and 220 may be any suitable computing cores, such as a CPU core, a GPU core, or one of each of a CPU core and a GPU core. Cores 210 and 220 share access to cache memory 230. Cores 210 and 220 may each execute a thread that may access at least some of the same cache entries 240 in cache 230. In some implementations, either or both of cores 210 and 220 may each execute multiple threads that may access at least some of the same cache entries 240 in cache memory 230. Although the examples discussed herein relate to cache memory, the principles described herein apply to any suitable memory or portion of a memory hierarchy, such as another cache layer (not shown) or a cache memory such as a cache memory. Figure 1 Memory 104 is shown and described with respect thereto. Processor 200 is exemplary, and the principles described herein are also applicable to a single core processor or a processor having more than two cores.
[0022] One problem that may arise in a shared memory architecture involves atomic access. For example, if a first thread accesses a particular memory location (e.g., Figure 2 If a cache entry 250 in , for example, operates (eg, reads and writes) data, then the data may be corrupted if a second thread simultaneously operates on the same memory location.
[0023] This problem can be solved using locks. A lock is a mutual exclusion (mutual exclusion) mechanism that allows only one thread to access a specific memory location until the lock is released. A thread that acquires a lock is generally guaranteed atomic access to the locked memory location until it releases the lock.
[0024] A thread may acquire a lock on a specific memory location, for example, by executing a lock instruction before executing other instructions (such as a store instruction) that may affect the data stored at the memory location. For exemplary purposes herein, a lock is acquired by a lock instruction executed by a thread, and the lock is also released by an instruction executed by the thread. However, in some implementations, a lock may be acquired and / or released by a prefix of an instruction executed by a thread, an instruction of a specific type or version, or in any other suitable manner. Regardless of whether they include discrete lock instructions or whether a lock instruction is combined with another instruction or operation into, for example, a tag, a bit, or a prefix, any of these may be referred to as a lock instruction. In general, if a specific memory location is locked by a thread or process, a different thread or process attempting to access the memory location will not be permitted to access the memory location and will typically receive a negative acknowledgement (NAK) signal or other suitable signal. However, the various techniques and devices discussed herein are not limited to any specific implementation of a lock.
[0025] Locks can be costly in terms of processing time, which can delay the thread or process maintaining the lock. A lock instruction that guarantees its atomicity by locking a memory location in a processor cache requires the lock instruction to wait for all older instructions in its thread to complete before locking the line in the cache. While the lock instruction is waiting for older instructions to complete, a buffer in the processor can back up (i.e., become full or nearly full), thereby stalling the processor.
[0026] One way to mitigate or avoid these possible disadvantages is to relax one or more properties of the lock, such as atomicity or fences. For example, the lock can be relaxed by not performing or not strictly performing atomic access. In such cases, the second thread will be allowed to access the memory location locked by the first thread. However, in order for the relaxed atomic access to work, it must be established that the second thread does not access the memory location when the lock is maintained by the first thread, or that the access of the second thread during the lock will not have a negative impact on the execution of the first thread (for example, the result produced by the calculation performed by the second thread under the relaxed lock is the same as it would produce under the strict lock). Since it is not necessarily known in advance whether relaxing the lock attribute will produce valid data at the locked memory location, the thread maintaining the relaxed lock can be referred to as executing speculatively or under speculative lock.
[0027] In a simple example of a speculative lock with relaxed atomicity, the second thread is only allowed to read access to the locked memory location, which does not change the data. In this case, the lock is relaxed relative to the read, thereby allowing the second thread to perform such a read, rather than waiting for the first thread to release the lock.
[0028] In a more complex example of a speculative lock with relaxed atomicity, a second thread is permitted to write to or otherwise modify a locked memory location. This would negatively impact the execution of the first thread, for example, if the second thread does not actually access the locked memory location while the lock is maintained by the first thread. However, this type of speculative lock may negatively impact the execution of the first thread if the first thread reads from the locked memory before the locked memory is modified by the second thread and the first thread writes to the locked memory after the locked memory is modified by the second thread.
[0029] In another example, the lock can be relaxed by not strictly enforcing atomic accesses. In such cases, the first thread will be allowed to execute out of order while maintaining the lock for a particular memory location. This can result in a violation of the barrier property in some cases. For example, if a read instruction from the first thread that is "younger" (i.e., later) than the lock instruction is executed before the speculative lock is completed, it may read out-of-date data. This may occur if a write instruction from a second thread writes to the memory location of the read instruction before the speculative lock is completed. Since the validity of the data at the locked location can be destroyed by the relaxed lock property, the validity of the data of the read instruction must be tested.
[0030] One possible test for determining whether the data is valid is to determine whether the second thread accesses the locked location while the speculative lock is maintained by the first thread. Reads by other threads do not violate the locking properties. However, there is an exposure window that exposes the speculative lock to writes by other threads. The window starts when the speculative lock reads its memory location and ends when the speculative lock is completed. When a thread is in the exposure window of the speculative lock, the thread must be aware of writes by other threads that will result in violations of the locking properties of the speculative lock. The speculatively locked memory location and all reads younger than the speculative lock that have been completed before writing to the speculatively locked memory location can be tested or monitored. If no other thread writes to the locked location, the data can be assumed to be valid.
[0031] If the data stored at the locked location is found to be valid, then normal execution can continue and the time loss associated with strict locking can be avoided. However, if it is found (or assumed) that the data stored at the locked location is invalid, then the execution pipeline (e.g., the core and / or processor executing the thread) must be flushed, and the thread maintaining the speculative lock must be re-executed in a manner that produces a valid result. Therefore, in an example where the data stored at the locked location in the processor cache is found to be invalid due to a violation of the locking properties of the speculative lock (or after the lock is released), the execution pipeline is flushed and the first thread is re-executed using strict locking (i.e., using a non-speculative lock) to avoid relaxation conditions that result in invalid data. After re-executing the thread according to the non-speculative lock, it can be assumed that the data at the locked location has not been overwritten by another thread.
[0032] Figure 3 is a flow chart illustrating an example method 300 for executing a speculative lock. Under the condition 310 that a first thread executes a lock instruction, in step 320, the thread executes a speculative lock at a particular memory location. During the speculative execution in step 320, the validity of the data at the memory location is tested, as discussed above. Under the condition 340 that the locked attribute has not been violated, the lock continues to be executed speculatively unless under the condition 330 that the speculative lock has been completed. If under the condition 340, the locked attribute is found to have been violated, then the execution pipeline is flushed in step 350, the thread is restarted in step 360, and the lock is non-speculatively executed to completion in step 370.
[0033] However, flushing the pipeline and re-executing the threads has an associated time penalty, which may offset the time gain achieved by relaxing the lock attributes. Thus, in some cases, relaxing the lock attributes may have diminishing returns. In other words, in some cases, flushing the execution pipeline and re-executing the threads due to a failed speculative lock may be more expensive in terms of time (and circuit area) than simply executing a non-speculative lock in the first place. Thus, it may be desirable to anticipate situations where relaxing the lock attributes may result in flushing memory and restarting execution in order to avoid the associated time penalty.
[0034] One way to predict situations where relaxed lock attributes may result in invalid data is to track lock address contention. Such predictions are based on the idea that if speculative locks on a particular address have caused flushes and restarts in the past, or if other threads have attempted to access the address while it was locked in the past (i.e., contended for the address), then speculative locks on the address may result in (or have a certain probability of causing) a flush and restart. Such predictions may be referred to as lock address contention predictions. For example, if a speculative lock on a particular memory address results in a flush and restart, this event may be tracked. Thus, future locks on the memory address may be forced to run non-speculatively. Variations on this strategy are possible.
[0035] In one example, a locked address contention predictor (LACP) tracks processor cache lines accessed by speculative locks resulting in flushes and restarts.
[0036] Figure 4 4 is a flow chart illustrating an example method 400 for performing a speculative lock using lock address contention prediction. Under condition 405 that a first thread executes a lock instruction, the LACP circuitry tests whether the lock attribute was violated at the target address following the speculative lock in the past, and whether the locked address is still in the local cache of the processor. Under condition 410 that the lock attribute was violated in the past and the locked address is no longer in the local cache of the processor, in step 415, the lock is performed non-speculatively. Otherwise, in step 420, the lock is performed speculatively.
[0037] During speculative execution in step 420, the LACP circuitry tests whether the locked address violates the lock property. In some implementations, if another thread has accessed the memory location during speculative execution, it is assumed that the locked property has been violated. Under the condition 425 that the lock property has not been violated, the lock continues to execute speculatively unless under the condition 427 that the speculative lock has been completed.
[0038] Under the condition 425 that the lock attribute is violated, the LACP is updated in step 430. Updating the LACP requires adding the locked address to the LACP, or if the locked address is already recorded in the LACP, updating the LACP entry age (in this implementation, the LACP includes a circuit system for tracking the "age" or length of time that the locked address has been recorded in the LACP) and clearing its hit bit. In either case, the hit bit (or other indicator) associated with the LACP entry is cleared (or otherwise configured) to prevent speculative execution of the lock on the address. The execution pipeline is flushed in step 435, and the thread is restarted and non-speculatively executed in steps 440 and 415.
[0039] It should be noted that the prohibition on speculatively locking a particular address can expire if desired. In some implementations, expiration can occur explicitly after a desired duration, a number of instructions, a number of locks, or otherwise. In some implementations, expiration can occur because an address is evicted from the LACP to make room for another address.
[0040] Figure 5 is a block diagram illustrating the functionality of an example LACP write request monitoring circuit system 500. In some implementations, the circuit system 500 may be used with Figure 4 The method 400 shown and described with respect thereto and / or other implementations discussed herein may be used together with and incorporated into Figure 6 The LACP device 600 shown and described herein may be used in or otherwise with the LACP device 600 .
[0041] The circuit system 500 is configured to monitor write requests to LACP entries. In step 510, the circuit system 500 detects whether another thread is attempting to write to an address stored in the LACP entry for any LACP entry. Under condition 520 that such a write attempt is detected, in step 530, the circuit system 500 updates the age field and hit bit (or other indicator) of the corresponding LACP entry. Otherwise, in step 510, the circuit system 500 continues to monitor write requests of other threads.
[0042] It should be noted that in contrast to other implementations discussed herein (such as Figure 4 ) in the case of a merger, Figure 5 The steps shown are performed asynchronously with those mechanisms. Thus, in this example, the LACP write request monitoring circuitry 500 updates the age field and hit bit of the LACP entry without waiting for a speculative or non-speculative lock to complete, and tests a write request to a processor cache entry without waiting for a speculative or non-speculative lock to start. It should be noted that in other implementations, Figure 5 The steps shown may be performed synchronously.
[0043] In this example implementation, the address of the LACP entry is tracked when the cache line associated with the address is in the local cache of the processor. It should be noted that in other implementations, the address of the LACP entry can always be tracked. In such implementations, LACP indicates that no contention is detected for the line. In this example implementation, the hit bit indicates whether the address tracked by LACP is still cached in the local cache of the processor.
[0044] Figure 66 is a block diagram illustrating an example LACP mechanism 600 according to various implementations discussed herein. The example LACP mechanism 600 includes a number of memory entries 610, however it should be noted that any suitable number of entries may be used. These memory entries 610 are configured to store in a processor cache 670 the addresses of memory locations that have violated locking properties in the past when speculatively locked. In some implementations, the memory entries 610 may also or instead be configured to store in the processor cache 670 the addresses of memory locations that other threads contended to access during the lock.
[0045] The number of LACP memory entries can be based on a desired replacement policy (e.g., based on a tradeoff between the amount of logic circuitry required to implement an entry and replacing an entry that may otherwise provide useful information in the future). In this example, LACP memory entries 610 are entries within a cache of the LACP. Each of entries 610 can be used to track cache lines of a processor cache 670 that violate the lock attributes of a speculative lock. Each of entries 610 includes a hit bit 650 and an age field 660.
[0046] If during execution of a thread, a lock instruction is executed for a cache entry 630 of a processor cache 670, and if the address of the cache entry 630 does not match the address stored in one of the LACP entries 610, then the lock may be executed speculatively. If the address of the cache entry 630 matches the address stored in one of the LACP entries 610, then if the cache hit bit 650 of the particular LACP entry 610 is asserted, then the lock may be executed speculatively. However, if the cache hit bit 650 of the particular LACP entry 610 is not asserted, then the lock must be executed non-speculatively. It should be noted that asserted / not asserted may be expressed in any suitable manner, such as using a bit, a flag, or a field.
[0047] The hit bit 650 is cleared when a new LACP entry 610 is created because the properties of a speculative lock are violated, where the speculatively locked processor cache address is not already stored in the LACP. The hit bit 650 of the existing LACP entry 610 is cleared when a write access from another thread (i.e., different from the thread that created the LACP entry) matches the LACP entry 610. The hit bit is asserted when a non-speculative lock is completed for the thread that created the LACP entry (a non-speculative lock completion guarantees that the cache line is in the local cache).
[0048] If a lock is executed non-speculatively, for example, for cache entry 630 of processor cache 670, and if the lock attribute of the speculative lock on cache entry 630 is violated (e.g., by a write access from a thread other than the thread maintaining the speculative lock), then the address of cache entry 630 is compared with each of entries 610 using comparator 620.
[0049] If cache entry 630 does not match an existing one of LACP entries 610, then one of LACP entries 610 is selected to track the speculatively locked cache line 630, and the address of cache entry 630 is stored in one of LACP entries 610 according to any desired replacement policy. LACP entries may be evicted and replaced using any suitable cache replacement algorithm (e.g., based on a tradeoff between the amount of logic circuitry required and / or latency incurred and replacing entries that may provide useful information in the future). For example, an empty LACP entry may be used, or if there is no empty LACP entry, the least recently used LACP entry (e.g., as determined according to age field 660) may be replaced.
[0050] If the locking property of the speculative lock is violated, the hit bit 650 of the LACP entry 610 is also cleared to indicate that the lock should be prevented from executing speculatively for this address, and the age field 660 of the LACP entry 610 is reset. After the LACP entry 610 has been created, the thread is restarted and the lock is executed non-speculatively.
[0051] If another thread's write access to processor cache entry 630 does not match an existing one of LACP entries 610 , then hit bit 650 is cleared, indicating that the lock should be prevented from speculatively executing for this address, and age field 660 of LACP entry 610 is reset.
[0052] If a non-speculative lock is asserted on processor cache entry 630, the address of entry 630 is compared to LACP entry 610 using comparator 620. If processor cache entry 630 does not match an existing LACP entry 610, then the hit bit of the entry is asserted upon or after the lock is completed, indicating that the address of the LACP entry is associated with a memory location currently residing in the processor's local cache. The asserted hit bit indicates that a subsequent lock instruction of the matching LACP entry may be speculatively executed. However, if another thread investigates entry 630 for memory access before the latter lock instruction is executed, then the address of entry 630 is compared to entry 610 using comparator 620. If cache entry 630 does not match an existing LACP entry 610, then the hit bit of the entry is cleared to indicate that a lock may not be speculatively executed for cache entry 630.
[0053] As can be seen from the foregoing, the LACP cache hit bit 650 can distinguish between two operating situations. In the first case, the LACP entry 610 is recorded for a non-speculative lock on the processor local cache 670. In this case, the LACP cache hit bit 650 is asserted to indicate that the lock can continue to be speculatively executed for the cache entry 630. In this case, the speculative lock is allowed even if the address of the cache entry 630 hits the LACP entry 610. In the second case, the access of another thread removes the cache entry 630 from the processor local cache 670. Therefore, the hit bit of the LACP entry 610 is cleared in this case to prevent the lock instruction from speculatively running for the cache entry 630. This resolves the opportunity for the second thread to violate the locked attribute on the cache entry 630.
[0054] Another method of predicting the situation that the relaxed lock attribute may lead to flushing the execution pipeline and restarting the execution with non-speculative locking is to track the time lock contention. Such prediction is based on the following concept: if a given number of speculative locks on any address have caused flushing and restarting in the past, or if a given number of other threads have contended to access the address when any address was locked in the past, then the speculative lock on any address may cause flushing and restarting. If a given number of flushing and restarting or contention events have occurred relative to any address within a given period, at a certain rate or otherwise based on time, then the speculative lock on any address may also be considered to be possible. Such prediction can be called time lock contention prediction.
[0055] In one example, a time lock contention predictor tracks the contention history of the last X cacheable lock instructions, where X can be any suitable number. For example, X can be selected based on a tradeoff between the amount of logic required and replacing entries that may provide useful information in the future. If a cacheable lock is speculative and causes a flush and restart, it is recorded as a lock contention event by the time lock contention predictor. If the number of lock contention events exceeds a desired threshold number Y, subsequent lock instructions are prevented from executing speculatively. In this example, frequent failures of speculative locking are considered predictors of future failures of speculative locking.
[0056] Figure 7700 is a flowchart illustrating an example method 700 for performing speculative locks using time lock contention prediction (TLCP). Under condition 705 that a first thread executes a lock instruction, the TLCP circuit system tests whether the lock attribute has been violated Y times or more during the speculative lock in the past X cacheable lock instructions. In this example, the TLCP circuit system includes a counter for tracking the number of lock attribute violations that have occurred in the past X cacheable lock instructions, however the TLCP circuit system is not limited to this implementation. For example, the TLCP circuit system may alternatively track the absolute number of past cacheable lock instructions (not just within the past X cacheable lock instructions). It should be noted that in various implementations, the TLCP may track the number of lock violations for a particular locked address or all lock violations for any address.
[0057] Under the condition 710 that the lock attributes have been violated Y times or more in the past X cacheable lock instructions, the lock is executed non-speculatively in step 715 and the TLCP is updated for successful lock execution in step 750. If the lock attributes have not been violated Y times or more in the past X cacheable lock instructions, then the lock is executed speculatively in step 720. During speculative execution, the TLCP circuitry tests whether the lock attributes of the speculative lock have been violated.
[0058] Under the condition 725 that the lock attribute of the speculative lock is not violated, and under the condition 727 that the lock has been completed, the TLCP is updated for the successful lock execution in step 760. Under the condition 725 that the lock attribute is found to have been violated, the data in the TLCP is updated for the unsuccessful lock execution in step 730, the execution pipeline is flushed in step 735, the thread is restarted in step 740, executed non-speculatively in step 715, and the TLCP is updated for the successful lock execution in step 750.
[0059] In another example, the TLCP circuit system also tracks the contention history of the last X cacheable lock instructions. In this example, if the cacheable lock is a speculative lock that has violated the lock attribute, the locked address is recorded by the TLCP circuit system. If the number of lock contention events exceeds the expected number Y, subsequent lock instructions are prevented from executing speculatively. This implementation is exemplary. For example, the TLCP circuit system can alternatively track the number of flushes / restarts and NAKs within a time window (such as the last X cacheable lock instructions). In this example, frequent failures of speculative locking and contention by other threads for locked (speculatively or non-speculatively) memory are considered predictors of future failures of speculative locking.
[0060] Figure 8800 for performing a speculative lock using temporal lock contention prediction (TLCP). Under condition 805 that a first thread executes a lock instruction, the TLCP circuitry tests whether a lock attribute has been violated (e.g., a thread other than the thread maintaining the lock contends for write access to a processor cache at the locked address, or a fence attribute of the lock has been violated) Y times or more in accordance with the speculative lock in the past X cacheable lock instructions. In this example, the TLCP circuitry includes a counter for tracking the number of lock attribute violations that have occurred in the past X cacheable lock instructions, however the TLCP circuitry is not limited to this implementation.
[0061] Under the condition 810 that the speculative lock on the memory (in this example, any memory entry) has been violated Y times or more in the past X cacheable lock instructions, the lock is executed non-speculatively in step 815. While the lock is executing non-speculatively in step 815, it is determined whether another thread issues a write request to write to the non-speculatively locked memory entry. In either case, the lock continues to execute non-speculatively at step 815 unless under the condition 887 that the lock has been completed.
[0062] Under the condition 850 that such a request is issued at any point during the lock, the TLCP is updated in step 855 to indicate lock contention. Under the condition 850 that such a request is not issued, the TLCP is updated in step 880 to indicate no lock contention. It should be noted that the expression update may not be required when the TLCP already reflects the appropriate state. It should also be noted that in some implementations, the TLCP update can occur at or after the lock is completed.
[0063] If the lock attribute has not been violated Y times or more in the past X cacheable lock instructions, then the lock is executed speculatively in step 820. After speculative execution, the TLCP circuitry tests whether the lock attribute of the speculative lock was violated. In some implementations, if another thread has accessed the memory location during speculative execution, the data is assumed to be invalid.
[0064] Under the condition 825 that the lock contention from another thread does not violate the lock attribute of the speculative lock, and under the condition 827 that the lock has been completed, the TLCP is updated for no lock contention in step 890. Under the condition 825 that the lock contention from another thread violates the lock attribute of the speculative lock, the TLCP is updated in step 830 to indicate that lock contention has occurred, the execution pipeline is flushed in step 835, the thread is restarted in step 840, and executed non-speculatively in step 815.
[0065] In some implementations, these concepts may be combined. For example, if a certain number of lock instructions to a certain memory location have caused a flush / restart, a certain number of lock instructions to the memory location have caused a flush / restart within a certain period of time, lock instructions to the memory location cause flushes / restarts at a certain rate or otherwise based on time, then lock instructions to the memory location may be prevented from executing speculatively.
[0066] A method for locking an entry in a memory device is disclosed herein. A lock instruction executed by a thread for a specific memory entry of a memory device is detected. If the lock instruction is detected, whether contention for the specific memory entry occurred during a previous speculative lock is detected. If contention for the specific memory entry occurred during a previous speculative lock, the lock instruction is non-speculatively executed. If contention for the specific memory entry did not occur during a previous speculative lock, the lock instruction is speculatively executed.
[0067] In some examples, under the condition of speculatively executing the lock instruction, detecting whether contention for the particular memory entry occurs from another thread during the speculative lock. In some examples, if contention for the particular memory entry occurs from another thread during the speculative lock, flushing the execution pipeline in which the thread executes, and re-executing the thread non-speculatively starting from the lock instruction.
[0068] In some examples, detecting whether contention for the particular memory entry occurred from another thread during the speculative lock includes detecting whether the particular memory entry contains invalid data. In some examples, contention includes any of: accessing, modifying, requesting access to, or requesting modification of the memory entry by another thread during a lock of the memory entry. In some examples, detecting whether contention for the particular memory entry occurred during a previous speculative lock includes detecting whether another thread requested access, accessed, requested modification to, or modified the particular memory entry during the previous speculative lock. In some examples, speculatively executing the lock includes relaxing constraints of the lock. In some examples, speculatively executing the lock includes relaxing atomic access properties or fence properties of the lock.
[0069] A method for locking an entry in a memory device is disclosed herein. A lock instruction executed by a thread for a particular memory entry of a memory device is detected. If the lock instruction is detected, then detecting whether a number of previous speculative locks of the memory that were contended for during a particular period exceeds a threshold number. If the number exceeds the threshold number, then executing the lock instruction non-speculatively. If the number does not exceed the threshold number, then executing the lock instruction speculatively.
[0070] In some examples, detecting whether the number of previous speculative locks of the memory that was contended for during the specific period exceeds the threshold number includes detecting whether the number of previous speculative locks of the specific memory entry that was contended for during the specific period exceeds the threshold number. In some examples, detecting whether the number of previous speculative locks of the memory that was contended for during the specific period exceeds the threshold number includes detecting whether the number of previous speculative locks of any memory entry in the memory device that was contended for during the specific period exceeds the threshold number.
[0071] In some examples, under the condition of speculatively executing the lock instruction, detecting whether contention for the particular memory entry occurs from another thread during the speculative lock. In some examples, if contention for the particular memory entry occurs from another thread during the speculative lock, flushing the execution pipeline in which the thread executes, and re-executing the thread non-speculatively starting from the lock instruction.
[0072] In some examples, detecting whether contention for the particular memory entry occurs from another thread during the speculative lock includes detecting whether the particular memory entry contains invalid data. In some examples, contention includes any of the following: accessing, modifying, requesting access, or requesting modification of the memory entry by a thread during a lock of the memory entry. In some examples, detecting whether the number of previous speculative locks of the memory for which contention occurred during a particular period exceeds a threshold number includes detecting whether another thread requested access, accessed, requested modification, or modified the memory during the previous speculative lock. In some examples, speculatively executing the lock includes relaxing constraints of the lock. In some examples, speculatively executing the lock includes relaxing atomic access attributes or fence attributes of the lock.
[0073] A processing device is disclosed herein, the processing device being configured for speculative locking. A processor core includes an execution pipeline. A lock instruction detection circuit system is configured to detect a lock instruction executed by a thread for a specific memory entry of a memory device. The contention detection circuit system is configured to, if the lock instruction is detected, detect whether contention occurred for the specific memory entry during a previous speculative lock. The locking circuit system is configured to non-speculatively execute the lock instruction if contention occurred for the specific memory entry during a previous speculative lock. The locking circuit system is further configured to speculatively execute the lock instruction if contention did not occur for the specific memory entry during a previous speculative lock.
[0074] In some examples, the contention detection circuitry is further configured to: detect, conditional upon speculatively executing the lock instruction, whether contention for the particular memory entry occurs from another thread during the speculative lock. Some examples include a re-execution circuitry configured to: if contention for the particular memory entry occurs from another thread during the speculative lock, flush an execution pipeline in which the thread executes, and non-speculatively re-execute the thread starting from the lock instruction.
[0075] In some examples, detecting whether contention for the particular memory entry occurred from another thread during the speculative lock includes detecting whether the particular memory entry contains invalid data. In some examples, contention includes any of: accessing, modifying, requesting access to, or requesting modification of the memory entry by another thread during a lock of the memory entry. In some examples, detecting whether contention for the particular memory entry occurred during a previous speculative lock includes detecting whether another thread requested access, accessed, requested modification to, or modified the particular memory entry during the previous speculative lock. In some examples, speculatively executing the lock includes relaxing constraints of the lock. In some examples, speculatively executing the lock includes relaxing atomic access properties or fence properties of the lock.
[0076] A processing device is disclosed herein, the processing device being configured for speculative locking. A processor core includes an execution pipeline. A lock instruction detection circuit system is configured to detect a lock instruction executed by a thread for a specific memory entry of a memory device. The contention detection circuit system is configured to detect whether the number of previous speculative locks of the memory that were contention during a specific period exceeds a threshold number if the lock instruction is detected. The locking circuit system is configured to non-speculatively execute the lock if the number exceeds the threshold number. The locking circuit system is further configured to speculatively execute the lock if the number does not exceed the threshold number.
[0077] In some examples, detecting whether the number of previous speculative locks of the memory that was contended for during the specific period exceeds the threshold number includes detecting whether the number of previous speculative locks of the specific memory entry that was contended for during the specific period exceeds the threshold number. In some examples, detecting whether the number of previous speculative locks of the memory that was contended for during the specific period exceeds the threshold number includes detecting whether the number of previous speculative locks of any memory entry in the memory device that was contended for during the specific period exceeds the threshold number. In some examples, the contention detection circuit system is further configured to: under the condition that the lock instruction is speculatively executed, detect whether contention occurs for the specific memory entry from another thread during the speculative lock.
[0078] Some examples include re-execution circuitry configured to: if contention for the particular memory entry occurs from another thread during the speculative lock, flush an execution pipeline in which the thread executes and re-execute the thread non-speculatively starting from the lock instruction. In some examples, detecting whether contention for the particular memory entry occurs from another thread during the speculative lock includes detecting whether the particular memory entry contains invalid data. In some examples, contention includes accessing, modifying, requesting access to, or requesting modification of the memory entry by a thread during a lock of the memory entry.
[0079] In some examples, detecting whether a number of previous speculative locks of the memory that were contended for during a particular period exceeds a threshold number includes any of the following: detecting whether another thread requested access, accessed, requested to modify, or modified the memory during the previous speculative lock. In some examples, speculatively executing the lock includes relaxing a constraint of the lock. In some examples, speculatively executing the lock includes relaxing an atomic access property or a fence property of the lock.
[0080] It should be understood that many variations are possible based on the disclosure herein. Although features and elements are described above in particular combinations, each feature or element may be used alone without the other features and elements, or in various combinations with or without the other features and elements.
[0081] The provided methods can be implemented in a general purpose computer, a processor, or a processor core. Suitable processors include, for example, a general purpose processor, a special purpose processor, a conventional processor, a digital signal processor (DSP), a plurality of microprocessors, one or more microprocessors associated with a DSP core, a controller, a microcontroller, an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) circuit, any other type of integrated circuit (IC), and / or a state machine. Such processors can be manufactured by configuring a manufacturing process using the results of processed hardware description language (HDL) instructions and other intermediate data including a netlist (such instructions can be stored on a computer readable medium). The result of such processing can be a mask piece, which is subsequently used in a semiconductor manufacturing process to manufacture a processor that implements various aspects of the embodiments.
[0082] The methods or flow charts provided herein may be implemented with a computer program, software or firmware incorporated into a non-transitory computer-readable storage medium for execution by a general-purpose computer or processor. Examples of non-transitory computer-readable storage media include read-only memory (ROM), random access memory (RAM), registers, cache memory, semiconductor memory devices, magnetic media such as internal hard disks and removable disks, magneto-optical media, and optical media such as CD-ROM disks and digital versatile disks (DVDs).
Claims
1. A method for locking an entry in a memory device, the method comprising: executing a lock instruction of the thread to lock a specific memory entry of the memory device; wherein the lock instruction is executed speculatively or non-speculatively based on whether the particular memory entry was written by a second thread during an exposure window of a previous speculative lock and not based on whether the particular memory entry was read by the second thread during the exposure window of a previous speculative lock; wherein non-speculatively executing the lock instruction comprises prohibiting modification of the particular memory entry by the second thread; wherein speculatively executing the lock instruction comprises allowing modification of the particular memory entry by the second thread; and Wherein the exposure window is a time interval from when the particular memory entry was read during the previous speculative lock to when the previous speculative lock completes.
2. The method of claim 1, further comprising: In response to the lock instruction being executed as a speculative lock, detecting whether another thread writes to the particular memory entry during the speculative lock.
3. The method of claim 2, further comprising: In response to another thread writing to the particular memory entry during the speculative lock, flushing the execution pipeline in which the thread executes and re-executing the thread starting from the lock instruction, wherein the lock instruction is re-executed non-speculatively. 4 . The method of claim 2 , wherein detecting whether another thread writes to the particular memory entry during the speculative lock comprises detecting whether the particular memory entry contains invalid data.
5. The method of claim 2, wherein detecting whether another thread writes to the particular memory entry comprises detecting any of: accessing, modifying, requesting access to, or requesting modification of the memory entry by another thread during a lock of the memory entry.
6. The method of claim 2, wherein detecting whether another thread wrote to the particular memory entry during a previous speculative lock comprises detecting whether another thread requested to access, accessed, requested to modify, or modified the particular memory entry during the previous speculative lock.
7. The method of claim 1, wherein speculatively executing the lock instruction comprises relaxing a constraint of the lock. 8 . The method of claim 1 , wherein speculatively executing the lock instruction comprises relaxing an atomic access attribute or a fence attribute of the lock.
9. A method for locking an entry in a memory device, the method comprising: executing a lock instruction of the thread to lock a specific memory entry of the memory device; wherein the lock instruction is executed speculatively or non-speculatively based on whether the particular memory entry was written by the second thread more than a threshold number of times during a particular period of time during an exposure window of a previous speculative lock and not based on whether the particular memory entry was read by the second thread more than a threshold number of times during a particular period of time; wherein non-speculatively executing the lock instruction comprises prohibiting modification of the particular memory entry by the second thread; wherein speculatively executing the lock instruction comprises allowing modification of the particular memory entry by the second thread; and Wherein the exposure window is a time interval from when the particular memory entry is read during one of the previous speculative locks to when one of the previous speculative locks completes.
10. The method of claim 9, wherein the lock instruction is executed speculatively or non-speculatively based on whether any memory entry in the memory device during the particular period was written by another thread more than the threshold number of times during an exposure window of a previous speculative lock.
11. The method of claim 9, further comprising: In response to speculatively executing the lock instruction, detecting whether another thread wrote to the particular memory entry during the speculative lock.
12. The method of claim 11, further comprising: In response to another thread writing to the particular memory entry during the speculative lock, the execution pipeline in which the thread is executing is flushed and the thread is re-executed starting from the lock instruction.
13. The method of claim 11, wherein detecting whether another thread writes to the particular memory during the speculative lock comprises detecting whether the particular memory entry contains invalid data.
14. The method of claim 11, wherein detecting whether another thread writes to the particular memory entry comprises detecting any of: accessing, modifying, requesting to access, or requesting to modify the memory entry by a thread during a lock of the memory entry.
15. The method of claim 11 , wherein detecting whether a number of previous speculative locks written to the particular memory entry by another thread during a particular period exceeds a threshold number comprises: Whether another thread requested to access, accessed, requested to modify, or modified the memory during the previous speculative lock is detected.
16. The method of claim 9, wherein speculatively executing the lock comprises relaxing constraints of the lock.
17. The method of claim 9, wherein speculatively executing the lock comprises relaxing an atomic access property or a fence property of the lock.
18. A processing device, the processing device being configured for speculative locking, the device comprising: a processor core, the processor core comprising an execution pipeline; The processing device is configured to: executing a lock instruction of the thread to lock a specific memory entry of the memory device, wherein the lock instruction is executed speculatively or non-speculatively based on whether the particular memory entry was written by a second thread during an exposure window of a previous speculative lock and not based on whether the particular memory entry was read by the second thread during the exposure window of a previous speculative lock; wherein non-speculatively executing the lock instruction includes inhibiting modification of the particular memory entry by the second thread; wherein speculatively executing the lock instruction comprises allowing modification of the particular memory entry by the second thread; and The exposure window is the time interval from when the particular memory entry was read during the previous speculative lock to when the previous speculative lock completes.
19. The processing device of claim 18, further configured to: in response to the lock instruction being executed as a speculative lock, detect whether another thread writes to the specific memory during the speculative lock.
20. The processing device of claim 19, further configured to: in response to another thread writing to the particular memory entry during the speculative lock, flush an execution pipeline in which the thread executes, and re-execute the thread starting from the lock instruction.
21. The processing device of claim 19, wherein detecting another thread writing to the particular memory entry during the speculative lock comprises detecting whether the particular memory entry contains invalid data.
22. The processing device of claim 19, wherein detecting whether another thread writes to the particular memory entry comprises detecting any of: accessing, modifying, requesting to access, or requesting to modify the memory entry by another thread during a lock of the memory entry.
23. The processing device of claim 19, wherein detecting whether another thread wrote to the particular memory entry during a previous speculative lock comprises detecting whether another thread requested to access, accessed, requested to modify, or modified the particular memory entry during the previous speculative lock.
24. The processing device of claim 18, wherein speculatively executing the lock instruction comprises relaxing a constraint of the lock.
25. The processing device of claim 18, wherein speculatively executing the lock instruction comprises relaxing an atomic access attribute or a fence attribute of the lock.
26. A processing device, the processing device being configured for speculative locking, the device comprising: a processor core, the processor core comprising an execution pipeline; The processing device is configured to: executing a lock instruction detection of a thread to lock a specific memory entry of a memory device; wherein the lock instruction is executed speculatively or non-speculatively based on whether the particular memory entry was written by the second thread more than a threshold number of times during a particular period of time during an exposure window of a previous speculative lock and not based on whether the particular memory entry was read by the second thread more than a threshold number of times during a particular period of time; wherein non-speculatively executing the lock instruction comprises prohibiting modification of the particular memory entry by the second thread; and wherein executing the lock instruction as a speculative lock comprises allowing the second thread to modify the particular memory entry; Wherein the exposure window is a time interval from when the particular memory entry is read during one of the previous speculative locks to when one of the previous speculative locks completes.
27. The processing device of claim 26, wherein the lock instruction is executed speculatively or non-speculatively based on whether any memory entry in the memory device during the particular period was modified by another thread more than the threshold number of times during an exposure window of a previous speculative lock.
28. The processing device of claim 26, wherein the processing device is further configured to: in response to speculatively executing the lock instruction, detect whether another thread has accessed the specific memory entry during the speculative lock.
29. The processing device of claim 26, further comprising a re-execution circuit system configured to: in response to another thread writing the particular memory entry during the speculative lock, flush an execution pipeline in which the thread executes, and re-execute the thread starting from the lock instruction.
30. The processing device of claim 28, wherein detecting whether another thread writes to the particular memory entry during the speculative lock comprises detecting whether the particular memory entry contains invalid data.
31. The processing device of claim 28, wherein detecting whether another thread writes to the particular memory entry comprises detecting any of: accessing, modifying, requesting to access, or requesting to modify the memory entry by a thread during a lock of the memory entry.
32. The processing device of claim 28, wherein detecting whether a number of previous speculative locks written to the particular memory entry by another thread during a particular period exceeds a threshold number comprises: Detecting whether another thread requested to access, accessed, requested to modify, or modified the particular memory entry during the previous speculative lock.
33. The processing device of claim 26, wherein speculatively executing the lock comprises relaxing constraints of the lock.
34. The processing device of claim 26, wherein speculatively executing the lock comprises relaxing an atomic access attribute or a fence attribute of the lock.
Citation Information
Patent Citations
Lock address contention predictor
US20180081544A1
Method and apparatus for speculative execution of uncontended lock instructions
CN1973261A
Concurrent execution of critical sections by eliding ownership of locks
US20030079094A1
Adaptive process for data sharing with selection of lock elision and locking
US20150242246A1
Method and apparatus for speculative execution of uncontended lock instructions
CN101847091A
