Lock Address Conflict Predictor

Speculative locking with LACP and TLCP optimizes lock execution in shared memory architectures, reducing delays and data corruption by predicting conflicts and contention, thus improving processing efficiency.

JP7539952B2Active Publication Date: 2024-08-26ADVANCED MICRO DEVICES INC
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
JP2022161419
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Priority Date
2016-09-22
Filing Date
2022-10-06
Publication Date
2024-08-26
Estimated Expiration
2037-09-06

AI Technical Summary

Technical Problem

In shared memory architectures, atomic access issues lead to data corruption and processing delays due to the use of locks, which can slow down threads and cause processor stalls.

Method used

Implementing speculative locking with lock address conflict prediction (LACP) and temporal lock contention prediction (TLCP) to determine when to execute locks speculatively or non-speculatively based on past conflicts and contention history, using circuits to track and predict potential data validity and contention.

Benefits of technology

Reduces processing delays and data corruption by optimizing lock execution, minimizing the need for pipeline flushes and reruns, thereby enhancing processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007539952000003
    Figure 0007539952000003
  • Figure 0007539952000008
    Figure 0007539952000008
  • Figure 0007539952000006
    Figure 0007539952000006
Patent Text Reader

Abstract

A method and processing device are provided for selectively locking entries in a memory device, either speculatively or non-speculatively, based on lock address prediction and / or temporal lock prediction. The method includes detecting a lock instruction executed by a thread for a specific memory entry in a memory device, and, if the lock instruction includes a speculative lock instruction, detecting whether contention occurred for the specific memory entry during a previous speculative lock, executing the lock non-speculatively if contention occurred for the specific memory entry during the previous speculative lock, and executing the lock speculatively if contention did not occur for the specific memory entry during the previous speculative lock.
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0001] (CROSS REFERENCE TO RELATED APPLICATIONS) This application claims the benefit of U.S. Patent Application No. 15 / 273,304, filed Sep. 22, 2016, the contents of which are incorporated by reference herein as if fully set forth. [Background technology]

[0002] A shared memory computing architecture allows multiple threads to access the same memory, such as a cache memory or other level of the memory hierarchy. For example, a single processor or processor core may execute multiple threads or processes, and each thread or process may access a shared memory, such as a cache, that is shared by the threads and / or processes. Similarly, multiple processors or multiprocessor cores may execute multiple threads or processes, and each thread and / or process may access a memory, such as a cache, that is shared by the processor or core and the threads and / or processes.

[0003] A more detailed understanding may be had from the following description, given by way of example in conjunction with the accompanying drawings, in which: [Brief description of the drawings]

[0004] [Figure 1] FIG. 1 is a block diagram of an example device capable of implementing one or more disclosed embodiments. [Diagram 2] 2 is a block diagram illustrating an example multi-core processor that can be used with the device of FIG. 1 and that can be used to implement one or more disclosed embodiments. [Diagram 3] 1 is a flowchart illustrating an example method for performing a speculative lock. [Figure 4]1 is a flowchart illustrating an example method for performing speculative locking using lock address conflict prediction. [Diagram 5] FIG. 2 is a functional block diagram of an exemplary locked address conflict predictive write request monitoring circuit. [Figure 6] FIG. 2 is a block diagram illustrating an exemplary lock address conflict prediction mechanism. [Figure 7] 5 is a flowchart illustrating an example method for enforcing speculative locking using temporal lock contention prediction. [Figure 8] 5 is a flowchart illustrating an example method for enforcing speculative locking using temporal lock contention prediction. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

[0005] Some embodiments provide a method of locking an entry in a memory device. A lock instruction executed by a thread for a particular memory entry of the memory device is detected. Whether a contention occurred for the particular memory entry during a previous speculative lock is detected, provided that the lock instruction includes a speculative lock instruction. If a contention occurred for the particular memory entry during the previous speculative lock, the lock is executed non-speculatively. If a contention did not occur for the particular memory entry during the previous speculative lock, the lock is executed speculatively.

[0006] 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 the memory device is detected. Whether a number of previous speculative locks of the memory that have encountered contention during a particular time period exceeds a threshold is detected, provided that the lock instruction includes a speculative lock instruction. If the number exceeds the threshold, the lock is executed non-speculatively. If the number does not exceed the threshold, the lock is executed speculatively.

[0007] Some embodiments provide a processing device configured for speculative locking, the device including a processor core having an execution pipeline, a lock instruction detection circuit configured to detect a lock instruction executed by a thread on a particular memory entry of a memory device, a contention detection circuit configured to detect whether a contention occurred for the particular memory entry during a previous speculative lock, provided that the lock instruction comprises a speculative lock instruction, a lock circuit configured to non-speculatively perform the lock if a contention occurred for the particular memory entry during the previous speculative lock, and a lock circuit further configured to speculatively perform the lock if a contention did not occur for the particular memory entry during the previous speculative lock.

[0008] Some embodiments provide a processing device configured for speculative locking, the device including a processor core having an execution pipeline, a lock instruction detection circuit configured to detect a lock instruction executed by a thread on a particular memory entry of a memory device, a contention detection circuit configured to detect whether a number of previous speculative locks of the memory on which contention occurred during a particular time period exceeds a threshold, provided that the lock instruction comprises a speculative lock instruction, a lock circuit configured to non-speculatively perform the lock if the number exceeds the threshold, and a lock circuit further configured to speculatively perform the lock if the number does not exceed the threshold.

[0009] 1 is a block diagram of an example device 100 capable of implementing one or more disclosed embodiments. 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 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 additional components not shown in FIG. 1.

[0010] Processor 102 may include a central processing unit (CPU), a graphics processing unit (GPU), a CPU and a GPU located on the same die, or one or more processors, where each processor core may be a CPU or a GPU. Memory 104 may be located on the same die as processor 102 or may be located separately from processor 102. Memory 104 may include, for example, volatile or non-volatile memory, such as random access memory (RAM), dynamic RAM, or cache.

[0011] Storage 106 may include, for example, a fixed or removable storage device such as a hard disk drive, a solid state drive, an optical disk, or a flash drive. 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 local area network card for transmitting and / or receiving wireless IEEE 802 signals). Output device 110 may include a display, a speaker, a printer, a haptic feedback device, one or more lights, an antenna, or a network connection (e.g., a wireless local area network card for transmitting and / or receiving wireless IEEE 802 signals).

[0012] The input driver 112 communicates with the processor 102 and the input device 108, allowing 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, allowing 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 the device 100 would operate similarly even if the input driver 112 and the output driver 114 were not present.

[0013] FIG. 2 is a schematic diagram illustrating an exemplary multi-core processor 200 including two processing cores 210, 220. The processor 200 may be used with the device 100, for example as the processor 102. The cores 210, 220 may be any suitable computing cores, such as a CPU core, a GPU core, or one CPU core and one GPU core. The cores 210, 220 share access to a cache memory 230. Each of the cores 210, 220 may execute a thread that may access at least some of the same cache entries 240 in the cache 230. In some implementations, either or both of the cores 210, 220 may execute multiple threads that access at least some of the same cache entries 240 in the cache memory 230. Although the examples described herein relate to a cache memory, the principles described herein may be applied to any suitable memory or portion of a memory hierarchy, such as another cache layer (not shown) or memory 104 shown and described with respect to FIG. 1. Processor 200 is exemplary and the principles described herein are applicable to single core processors or processors having three or more cores.

[0014] One problem that can arise in shared memory architectures relates to atomic accesses: for example, if a first thread is operating on (e.g., reading or writing) data in a particular memory location (e.g., cache entry 250 in FIG. 2) in the shared memory, and a second thread is operating simultaneously on the same memory location, the data may become corrupted.

[0015] This problem can be solved using a lock, which is a mutual exclusion (mutex) mechanism that allows only one thread to access a particular memory location until the lock is released. A thread that has acquired a lock is typically guaranteed atomic access to the locked memory location until it releases the lock.

[0016] A thread may acquire a lock on a particular memory location by executing a lock instruction before executing other instructions that affect data stored in the memory location, such as, for example, a store instruction. For purposes of illustration herein, a lock is acquired by a lock instruction executed by the thread and released by an instruction executed by the thread. However, in some embodiments, a lock may be acquired and / or released by a prefix to an instruction executed by the thread, by a particular type or version of an instruction, or in any other suitable manner. Any of these may be referred to as a lock instruction, regardless of whether they include a separate lock instruction or whether a lock instruction is combined with another instruction or operation, for example, as a flag, bit, or prefix. In general, when a particular memory location is locked by a thread or process, a different thread or process that attempts to access that memory location is not permitted to access that memory location and typically receives a not acknowledged (NAK) signal or other appropriate signal. However, the various techniques and devices described herein are not limited to a particular implementation of a lock.

[0017] Locks can delay the thread or process that holds the lock, which can be costly in terms of processing time. Lock instructions that ensure atomicity by locking a memory location in a processor cache require the lock instruction to wait for all old instructions in a thread to complete before locking the line in that cache. While the lock instruction waits for old instructions to complete, buffers in the processor can back up (i.e., become full or approach full), stalling the processor.

[0018] One way to mitigate or avoid these possible disadvantages is to relax one or more properties of the lock, such as atomicity or fencing. For example, a lock can be relaxed by not enforcing or strictly enforcing atomic access. In such a case, a second thread is permitted to access a memory location locked by a first thread. However, for relaxed atomic access to work, it must be established that either the second thread did not access the memory location while the lock was held by the first thread, or that the access by the second thread did not adversely affect the execution of the first thread during the lock (e.g., a computation performed by the second thread under the relaxed lock produces the same result as if it had been performed under a strict lock). Because it is not necessarily known in advance whether relaxing a lock property will produce valid data in the locked memory location, a thread holding a relaxed lock is said to be executing speculatively, or under a speculative lock.

[0019] In a simple example of a speculative lock with relaxed atomicity, a second thread is only allowed read access to a locked memory location that does not modify the data: in this case, the lock is relaxed with respect to reads, allowing the second thread to perform such reads instead of waiting for the first thread to release the lock.

[0020] In a more complex example of a speculative lock with relaxed atomicity, a second thread is permitted to write to or modify a locked memory location. This does not adversely affect the execution of the first thread, for example, if the second thread does not actually access the locked memory location while the lock is held by the first thread. However, this type of speculative lock can adversely affect the execution of the first thread if the first thread reads from the locked memory before it is modified by the second thread and writes to the locked memory after it is modified by the second thread.

[0021] In another example, locking can be relaxed by not strictly enforcing the fencing property. In such a case, a first thread is allowed to execute out of order while holding a lock on a particular memory location. This can lead to a violation of the fencing property in some circumstances. For example, if a read instruction from a first thread that is "younger" (i.e., later) than the lock instruction executes before the speculative lock completes, the read instruction may read stale data. This can occur if a write instruction from a second thread writes to the memory location of the read instruction before the speculative lock completes. The validity of the data in the locked location may be compromised by the relaxed locking property, so the validity of the data in the read instruction needs to be checked.

[0022] One possible check to determine if the data is valid is to determine if a second thread accessed the locked location while the speculative lock was held by the first thread. Reads by other threads do not violate the locking properties. However, there is a window of exposure of the speculative lock during which other threads may write. This window begins when the speculative lock reads the memory location and ends when the speculative lock completes. While the thread is in the window of exposure of the speculative lock, it must monitor writes by other threads, which would cause a violation of the locking properties of the speculative lock. The speculatively locked memory location and all reads younger than the speculative lock that completed before the speculatively locked memory location was written can be inspected or monitored. If no other threads are writing to the locked location, the data can be presumed to be valid.

[0023] If it is determined that the data stored in the locked location is valid, execution can continue normally, avoiding the time penalty associated with strict locking. However, if it is determined (or presumed) that the data stored in the locked location is invalid, the execution pipeline (e.g., the core and / or processor executing the thread) must be flushed and the thread that held the speculative lock must be re-executed to ensure valid results. Thus, in an example where it is determined that the data stored in the locked location in the processor cache (or after the lock is released) is invalid due to a violation of the locking properties of the speculative lock, the execution pipeline is flushed and the first thread is re-executed using strict locking (i.e., using a non-speculative lock) to avoid a mitigating situation that results in invalid data. After re-executing the thread under a non-speculative lock, it can be presumed that the data in the locked location has not been overwritten by another thread.

[0024] 3 is a flow chart illustrating an example method 300 for executing a speculative lock. Conditional on a first thread executing a lock instruction (310), the thread executes a speculative lock on a particular memory location at step 320. During the execution of the speculative lock at step 320, the data at the memory location is checked for validity as described above. Conditional on the lock property not being violated (340), the lock continues to be executed speculatively as long as the speculative lock is not completed at condition 330. If it is determined that the lock property is violated at condition 340, the execution pipeline is flushed at step 350, the thread resumes at step 360, and the lock is executed non-speculatively to complete at step 370.

[0025] However, flushing the execution pipeline and re-executing threads has an associated time penalty that may offset the time gain realized by relaxing the locking characteristics. Thus, relaxing the locking characteristics may provide diminishing returns in certain circumstances. In other words, under certain circumstances, flushing the execution pipeline and re-executing threads due to a failed speculative lock may be more costly in terms of time (and circuit area) than simply executing a non-speculative lock in the first place. Thus, to avoid the associated time penalty, it may be desirable to anticipate circumstances where relaxed locking characteristics may result in flushing memory and resuming execution.

[0026] One approach to predicting situations where relaxed locking characteristics may result in invalid data is to track lock address contention. Such a prediction is based on the idea that a speculative lock on a particular address may (or will occur with some probability) result in a flush and resume if a speculative lock on that address has previously resulted in a flush and resume, or if another thread was trying to access that address (i.e., contending for that address) while that address was previously locked. Such a prediction may be called a lock address contention prediction. For example, if a speculative lock on a particular memory address causes a flush and resume, this occurrence may be tracked. As a result, future locks on this memory address may be forced to be performed non-speculatively. This strategy can be modified.

[0027] In one example, a lock address contention predictor (LACP) tracks processor cache lines accessed by a speculative lock that caused a flush and resume.

[0028] 4 is a flow chart illustrating an example method 400 for performing a speculative lock using lock address contention prediction. The LACP circuit checks 405 if a first thread executes a lock instruction, whether a lock property has been violated in the past at the target address after a speculative lock, and whether the locked address is not present in the processor's local cache. If a lock property has been violated in the past and the locked address is present in the processor's local cache 410, the lock is executed non-speculatively in step 415. If not, the lock is executed speculatively in step 420.

[0029] During speculative execution in step 420, the LACP circuitry checks whether the locking properties have been violated for the locked address. In some embodiments, if another thread accesses the memory location during speculative execution, the locking properties are presumed to have been violated. Provided that the locking properties have not been violated (425), the lock continues to be speculatively executed unless the speculative lock is completed at condition 427.

[0030] Upon a violation of the locking property (425), the LACP is updated in step 430. Updating the LACP involves either adding the locked address to the LACP, or, if the locked address is already recorded in the LACP, updating the LACP entry age (the LACP in this embodiment includes circuitry to track the "duration" 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 inhibit speculative execution of the lock at that address. In step 435, the execution pipeline is flushed, and in steps 440 and 415, the thread is resumed and executed non-speculatively.

[0031] Note that the prohibition on speculatively locking a particular address may expire, if desired. In some embodiments, the expiration may occur explicitly after a desired period of time, a number of instructions, a number of locks, or otherwise. In some embodiments, the expiration may occur by the address being evicted from the LACP to make room for another address.

[0032] Figure 5 is a functional block diagram of an example LACP write request monitoring circuit 500. In some embodiments, the circuit 500 may be used with the method 400 shown and described with respect to Figure 4 and / or other embodiments discussed herein, and may be incorporated into or used with an LACP device 600, as shown and described with respect to Figure 6.

[0033] Circuit 500 is configured to monitor write requests to LACP entries. At step 510, circuit 500 detects, for any LACP entry, whether another thread is attempting to write to the address stored in the LACP entry. If such an attempt to write is detected (520), circuit 500 updates the age field and hit bit (or other indicator) of the corresponding LACP entry at step 530. Otherwise, circuit 500 continues to monitor at step 510 for write requests by other threads.

[0034] It should be noted that the steps shown in Figure 5, when combined with other embodiments discussed herein (such as Figure 4), are performed asynchronously with those mechanisms. Thus, in this example, the LACP write request monitoring circuit 500 does not wait for a speculative or non-speculative lock to complete before updating the age field and hit bit of the LACP entry, and does not wait for a speculative or non-speculative lock to begin before checking the write request to the processor cache entry. It should be noted that in other embodiments, the steps shown in Figure 5 can be performed synchronously.

[0035] In this exemplary embodiment, the address of an LACP entry is tracked while the cache line associated with that address is in the processor's local cache. Note that in other embodiments, the address of an LACP entry may be tracked at all times. In such an embodiment, LACP indicates that the line has not encountered a conflict. In this embodiment, the hit bit indicates whether the address tracked by LACP is still cached in the processor's local cache.

[0036] 6 is a block diagram illustrating an example LACP mechanism 600 in accordance with various embodiments described herein. The example LACP mechanism 600 includes a number of memory entries 610, although it should be noted that any suitable number of entries may be used. These memory entries 610 are configured to store addresses of memory locations in the processor cache 670 that have previously violated lock properties while speculatively locked. In some embodiments, the memory entries 610 may also or instead be configured to store addresses of memory locations in the processor cache 670 that other threads are competing for access to while locked.

[0037] The number of LACP memory entries can be based on a desired replacement strategy (e.g., based on a tradeoff between the amount of logic required to implement the entry and replacing entries that may later provide useful information). In this example, the LACP memory entries 610 are entries in the LACP cache. Each entry 610 can be used to track cache lines in the processor cache 670 that have violated the locking properties of the speculative lock. Each entry 610 includes a hit bit 650 and an age field 660.

[0038] If during execution of a thread, a lock instruction is executed on a cache entry 630 in a processor cache 670, and 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 performed speculatively. If the address of the cache entry 630 matches the address stored in one of the LACP entries 610, then the lock may be performed speculatively if a cache hit bit 650 for the particular LACP entry 610 is asserted. However, if the cache hit bit 650 for the particular LACP entry 610 is not asserted, then the lock must be performed non-speculatively. It should be noted that assertion / deassertion may be represented in any suitable manner, such as a bit, a flag, or a field.

[0039] When a new LACP entry 610 is created due to a violation of the locking properties of the speculative lock, the hit bit 650 is cleared and the speculatively locked processor cache address has not yet been stored in the LACP. The hit bit 650 of an existing LACP entry 610 is cleared when a write access from another thread (i.e., a thread other than the one that created the LACP entry) matches the LACP entry 610. The hit bit is asserted when the non-speculative lock of the thread that created the LACP entry completes (completion of the non-speculative lock guarantees that the cache line is in the local cache).

[0040] For example, if a lock is speculatively executed on cache entry 630 in processor cache 670, and if the locking properties of the speculative lock on cache entry 630 are violated (e.g., by a write access from a thread other than the thread holding the speculative lock), the address of cache entry 630 is compared with each entry 610 using comparator 620.

[0041] If the cache entry 630 does not match an existing LACP entry 610, then one LACP entry 610 is selected to track the cache line 630 of the speculative lock, and the address of the cache entry 630 is stored in the one LACP entry 610 according to a desired replacement strategy. LACP entries may be evicted and replaced using any suitable cache replacement algorithm (e.g., based on a tradeoff between the amount of logic required and / or the amount of delay incurred versus replacing an entry that may later provide useful information). For example, an empty LACP entry may be used, or if no empty LACP entry exists, the most recently used LACP entry (e.g., as determined according to the age field 660) may be replaced.

[0042] If the locking properties of the speculative lock are violated, the hit bit 650 of the LACP entry 610 is cleared to indicate that the lock should not be speculatively executed for this address, and the age field 660 of the LACP entry 610 is reset. After the LACP entry 610 is created, the thread is resumed and the lock is executed non-speculatively.

[0043] If another thread's write access to processor cache entry 630 matches an existing LACP entry 610, the hit bit 650 is cleared to indicate that the lock should not be speculatively executed for this address, and the age field 660 of the LACP entry 610 is reset.

[0044] When 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 matches an existing LACP entry 610, the entry's hit bit is asserted when or after the lock is completed to indicate that the address of the LACP entry is associated with a memory location that is currently present in the processor's local cache. The asserted hit bit indicates that a subsequent lock instruction that matches the LACP entry may be executed speculatively. However, if another thread probes entry 630 for a memory access before the subsequent lock instruction is executed, the address of entry 630 is compared to entry 610 using comparator 620. If cache entry 630 matches an existing LACP entry 610, the entry's hit bit is cleared to indicate that a lock may not be executed speculatively for cache entry 630.

[0045] As can be seen from the above, the LACP cache hit bit 650 can distinguish two cases of operation. In the first case, the LACP entry 610 is recorded for a non-speculative lock of the processor local cache 670. In this case, the LACP cache hit bit 650 is asserted to indicate that the lock may continue to be speculatively executed for the cache entry 630. In this case, the speculative lock is permitted even if the address of the cache entry 630 hits the LACP entry 610. In the second case, an access by another thread removes the cache entry 630 from the processor local cache 670. Thus, in this case, the hit bit of the LACP entry 610 is cleared to inhibit the speculative execution of a lock instruction for the cache entry 630. This addresses an opportunity for the second thread to violate the lock property of the cache entry 630.

[0046] Another approach to predicting situations where relaxed locking characteristics may result in flushing the execution pipeline and resuming execution using a non-speculative lock is to track temporal lock contention. Such a prediction is based on the idea that a speculative lock on any address may result in flushing and resuming if a certain number of speculative locks on that address have previously resulted in flushing and resuming, or if a certain number of other threads have contended for access to that address while it was previously locked. If a certain number of flushing and resuming or contention events have occurred on any address within a certain period of time, at a certain rate, or based on time, then a speculative lock on any address is considered likely. Such a prediction may be referred to as a temporal lock contention prediction.

[0047] In one example, the temporal lock contention predictor tracks the contention history of the last X cacheable lock instructions, where X may be any suitable number. For example, X may be selected based on a tradeoff between the amount of logic required and replacing entries that may provide useful information later. If a cacheable lock is speculative and causes a flush and resume, it is recorded as a lock contention event by the temporal lock contention predictor. If the number of lock contention events exceeds a desired threshold Y, subsequent lock instructions are inhibited from being speculatively executed. In this example, frequent speculative lock failures are considered a predictor of future speculative lock failures.

[0048] FIG. 7 is a flow chart illustrating an example method 700 of performing speculative locking using temporal lock contention prediction (TLCP). Conditional on a first thread executing a lock instruction (705), the TLCP circuit checks whether a lock characteristic has been violated Y or more times during speculative locking in the past X cacheable lock instructions. In this example, the TLCP circuit includes a counter that tracks the number of violations of the lock characteristic that have occurred in the past X cacheable lock instructions, although the TLCP circuit is not limited to this embodiment. For example, the TLCP circuit may instead track an absolute number of past cacheable lock instructions (not just within the past X cacheable lock instructions). Note that in various embodiments, the TLCP may track the number of violations of a lock for a particular locked address, or the number of violations of all locks for any address.

[0049] Provided that the lock characteristics have been violated Y or more times in the past X cacheable locked instructions (710), the lock is executed non-speculatively in step 715 and the TLCP is updated for successful execution of the lock in step 750. If the lock characteristics have not been violated Y or more times in the past X cacheable locked instructions, the lock is executed speculatively in step 720. During speculative execution, the TLCP circuitry checks whether the lock characteristics of the speculative lock have been violated.

[0050] Provided that the locking properties of the speculative lock are not violated (725) and that the lock is completed (727), the TLCP is updated for a successful lock execution in step 760. Provided that the locking properties are determined to be violated (725), the data in the TLCP is updated for a failed lock execution in step 730, the execution pipeline is flushed in step 735, the thread is resumed in step 740 and executed non-speculatively in step 715, and the TLCP is updated for a successful lock execution in step 750.

[0051] In another example, the TLCP circuit 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 its locking characteristics, the locked address is recorded by the TLCP circuit. If the number of lock contention events exceeds a desired number Y, subsequent locked instructions are inhibited from being speculatively executed. This embodiment is exemplary. For example, the TLCP circuit may instead track the number of flush / resumes and NAKs within a particular time window, such as the last X cacheable lock instructions. In this example, frequent failures of the speculative lock and contention by other threads for locked memory (speculatively or non-speculatively) are considered predictors of subsequent speculative lock failures.

[0052] 8 is a flow chart illustrating an example method 800 for performing speculative locking using temporal lock contention prediction (TLCP). Conditional on a first thread executing a lock instruction (805), the TLCP circuit checks whether a lock property has been violated Y or more times after the speculative lock in the past X cacheable lock instructions (e.g., a thread other than the thread holding the lock has contended for write access to a processor cache at the locked address or a fencing property of the lock has been violated). In this example, the TLCP circuit includes a counter that tracks the number of violations of the lock property that have occurred in the past X cacheable lock instructions, although the TLCP circuit is not limited to this embodiment.

[0053] Provided that the locking characteristics of the speculative lock on memory (in this example, any memory entry) have been violated Y or more times in the past X cacheable locked instructions (810), the lock is executed non-speculatively in step 815. While the lock is being executed non-speculatively in step 815, it is determined whether a write request has been made by another thread to write to the non-speculatively locked memory entry. In either case, the lock continues to be executed non-speculatively in step 815 as long as the lock is not completed in condition 887.

[0054] Provided that such a request was made at any time during the lock (850), the TLCP is updated to indicate a lock contention in step 855. Provided that no such request was made (850), the TLCP is updated to indicate no lock contention in step 880. Note that if the TLCP already reflects the proper state, an explicit update may not be required. Note that in some embodiments, the TLCP update may occur when or after the lock is completed.

[0055] If the lock property has not been violated Y or more times in the past X cacheable lock instructions, the lock is speculatively executed in step 820. After speculative execution, the TLCP circuit checks whether the lock property of the speculative lock has been violated. In some embodiments, if another thread accesses the memory location during speculative execution, the data is presumed to be invalid.

[0056] Provided that the locking properties of the speculative lock have not been violated due to lock contention from another thread (825), and that the lock has been completed (827), the TLCP is updated to no lock contention in step 890. Provided that the locking properties of the speculative lock have been violated due to lock contention from another thread (825), the TLCP is updated to indicate that a lock contention has occurred in step 830, the execution pipeline is flushed in step 835, and the thread is resumed in step 840 and executed non-speculatively in step 815.

[0057] In some embodiments, these concepts may be combined, for example, speculative execution of a lock instruction to a particular memory location may be inhibited if a certain number of lock instructions to that memory location result in a flush / resume, if a certain number of lock instructions to that memory location within a certain time period result in a flush / resume, if a certain number of lock instructions to that memory location result in a flush / resume at a certain rate or based on time.

[0058] 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 the memory device is detected. If the lock instruction is detected, it is detected whether a contention occurred for the particular memory entry during a previous speculative lock. If a contention occurred for the particular memory entry during a previous speculative lock, the lock instruction is executed non-speculatively. If a contention did not occur for the particular memory entry during a previous speculative lock, the lock instruction is executed speculatively.

[0059] In some examples, whether contention from another thread occurs for a particular memory entry while speculatively locked is detected on the condition that the lock instruction was speculatively executed. In some examples, if contention from another thread occurs for a particular memory entry while speculatively locked, the execution pipeline in which the thread is executing is flushed and the thread is re-executed non-speculatively starting from the lock instruction.

[0060] In some examples, detecting whether a contention from another thread occurred for the particular memory entry during the speculative lock includes detecting whether the particular memory entry contains invalid data. In some examples, the contention includes any of the following: access to the memory entry, modification of the memory entry, request to access the memory entry, or request to modify the memory entry by another thread during the locking of the memory entry. In some examples, detecting whether a contention occurred for the particular memory entry during a previous speculative lock includes detecting whether another thread requested access to, accessed, requested to modify, or modified the particular memory entry 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 the atomic accessibility or fencing property of the lock.

[0061] 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 the memory device is detected. If the lock instruction is detected, it is detected whether the number of previous speculative locks of the memory where contention occurred during a particular time period exceeds a threshold. If the number exceeds the threshold, the lock instruction is executed non-speculatively. If the number does not exceed the threshold, the lock instruction is executed speculatively.

[0062] In some examples, detecting whether the number of previous speculative locks of the memory where the contention occurred during the particular time period exceeds a threshold includes detecting whether the number of previous speculative locks of a particular memory entry where the contention occurred during the particular time period exceeds a threshold. In some examples, detecting whether the number of previous speculative locks of the memory where the contention occurred during the particular time period exceeds a threshold includes detecting whether the number of previous speculative locks of any memory entry in the memory device where the contention occurred during the particular time period exceeds a threshold.

[0063] In some examples, whether contention from another thread occurs for a particular memory entry while speculatively locked is detected on the condition that the lock instruction is executed speculatively. In some examples, if contention from another thread occurs for a particular memory entry while speculatively locked, the execution pipeline in which the thread is executing is flushed and the thread is re-executed non-speculatively starting from the lock instruction.

[0064] In some examples, detecting whether a contention has occurred for a particular memory entry during a speculative lock includes detecting whether the particular memory entry contains invalid data. In some examples, the contention includes any of the following: access to the memory entry, modification of the memory entry, request to access the memory entry, or request to modify the memory entry by the thread during the lock of the memory entry. In some examples, detecting whether the number of previous speculative locks of the memory during which contention occurred exceeds a threshold value during a particular period of time includes detecting whether another thread requested access to, accessed, requested to modify, or modified the memory during a 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 the atomic accessibility or fencing nature of the lock.

[0065] Disclosed herein is a processing device configured for speculative locking. A processor core includes an execution pipeline. A lock instruction detection circuit is configured to detect a lock instruction executed by a thread for a particular memory entry of a memory device. A conflict detection circuit is configured to detect if a conflict occurred for the particular memory entry during a previous speculative lock if the lock instruction is detected. The lock circuit is configured to non-speculatively execute the lock instruction if a conflict occurred for the particular memory entry during a previous speculative lock. The lock circuit is configured to speculatively execute the lock instruction if a conflict did not occur for the particular memory entry during a previous speculative lock.

[0066] In some examples, the contention detection circuitry is configured to detect whether a contention from another thread occurs for the particular memory entry while speculatively locked, subject to the lock instruction being speculatively executed. In some examples, the circuitry includes a re-execution circuitry configured to flush an execution pipeline in which the thread is executing and re-execute the thread non-speculatively starting from the lock instruction if a contention occurs for the particular memory entry while speculatively locked.

[0067] In some examples, detecting whether a contention occurred for a particular memory entry during a speculative lock includes detecting whether the particular memory entry contains invalid data. In some examples, the contention includes any of the following: access to the memory entry, modification of the memory entry, request to access the memory entry, or request to modify the memory entry by another thread during the locking of the memory entry. In some examples, detecting whether a contention occurred for a particular memory entry during a previous speculative lock includes detecting whether another thread requested access to, accessed, requested to modify, or modified the particular memory entry during the previous speculative lock. In some examples, speculatively executing a lock includes relaxing a constraint of the lock. In some examples, speculatively executing a lock includes relaxing the atomic accessibility or fencing nature of the lock.

[0068] Disclosed herein is a processing device configured for speculative locking. The processor core includes an execution pipeline. The lock instruction detection circuit is configured to detect a lock instruction executed by a thread for a particular memory entry of a memory device. The contention detection circuit is configured to detect, if the lock instruction is detected, whether a number of previous speculative locks of the memory where contention occurred during a particular time period exceeds a threshold. The lock circuit is configured to non-speculatively execute the lock if the number exceeds the threshold. The lock circuit is configured to speculatively execute the lock if the number does not exceed the threshold.

[0069] In some examples, detecting whether the number of previous speculative locks of the memory during a particular time period where contention occurred exceeds a threshold includes detecting whether the number of previous speculative locks of a particular memory entry during a particular time period where contention occurred exceeds a threshold. In some examples, detecting whether the number of previous speculative locks of the memory during a particular time period where contention occurred exceeds a threshold includes detecting whether the number of previous speculative locks of any memory entry in the memory device during which contention occurred exceeds a threshold. In some examples, the contention detection circuitry is configured to detect whether contention from another thread occurred for the particular memory entry during the speculative lock, provided that the lock instruction was executed speculatively.

[0070] In some examples, the re-execution circuit is configured to flush an execution pipeline in which the thread is executing and non-speculatively re-execute the thread starting from the lock instruction if a contention occurs from another thread for the particular memory entry while speculatively locked. In some examples, detecting whether a contention occurs from another thread for the particular memory entry while speculatively locked includes detecting whether the particular memory entry contains invalid data. In some examples, the contention includes an access to the memory entry, a modification of the memory entry, a request to access the memory entry, or a request to modify the memory entry by the thread while the memory entry is locked.

[0071] In some examples, detecting whether the number of previous speculative locks of the memory that encountered contention during a particular time period exceeds a threshold includes detecting whether another thread either requested access to, accessed, requested modification of, or modified the memory during a previous speculative lock. In some examples, speculatively executing a lock includes relaxing a constraint of the lock. In some examples, speculatively executing a lock includes relaxing the atomic accessibility or fencing properties of the lock.

[0072] It should be understood that many variations are possible based on the disclosure herein. Although features and elements have been described above in specific 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.

[0073] The provided methods may be implemented in a general purpose computer, processor, or processor core. Suitable processors include, by way of example, general purpose processors, special purpose processors, conventional processors, digital signal processors (DSPs), multiple microprocessors, one or more microprocessors associated with a DSP core, controllers, microcontrollers, application specific integrated circuits (ASICs), field programmable gate array (FPGA) circuits, other types of integrated circuits (ICs), and / or state machines. Such processors may be manufactured by configuring a manufacturing process with the results of processed hardware description language (HDL) instructions (such instructions may be stored on a computer readable medium) and other intermediate data including a netlist. The results of such processes may be maskwork used in a semiconductor manufacturing process to manufacture a processor implementing aspects of the embodiments.

[0074] The methods or flow charts provided herein may be implemented in a computer program, software, or firmware embodied in 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, for example, read-only memory (ROM), random access memory (RAM), registers, cache memory, semiconductor memory devices, magnetic media such as internal hard disks, removable disks, and optical media such as magneto-optical storage media, e.g., CD-ROM disks and digital versatile disks (DVDs).

Claims

1. 1. A method of locking an entry in a memory device, comprising: executing a lock instruction of a thread to lock a particular memory entry of the memory device; the lock instruction is executed speculatively or non-speculatively based on whether the particular memory entry was written by a second thread during a window of exposure of a previous speculative lock and is non-speculatively executed based on whether the particular memory entry was read by the second thread during the window of exposure; non-speculatively executing the lock instruction includes not allowing the second thread to modify the particular memory entry; speculatively executing the lock instruction includes allowing the second thread to modify the particular memory entry; the window of exposure is the period of time from when the particular memory entry was read during the previous speculative lock to when the previous speculative lock completes. method.

2. and in response to the lock instruction being executed as a speculative lock, detecting whether another thread wrote to the particular memory entry during the speculative lock.

2. The method of claim 1.

3. and, in response to another thread writing to the particular memory entry during the speculative lock, flushing a pipeline in which the thread is executing and re-executing the thread starting at the lock instruction, where the lock instruction is re-executed non-speculatively. The method of claim 2.

4. Detecting whether another thread has written to the particular memory entry during the speculative lock includes detecting whether the particular memory entry contains invalid data. The method of claim 2.

5. Detecting whether another thread has written to the particular memory entry includes detecting any of an access, modification, access request, or modification request to the memory entry by the other thread while the memory entry is locked. The method of claim 2.

6. Whether or not another thread has written to the particular memory entry during the previous speculative lock includes whether or not another thread has requested access to, accessed, requested modification to, or modified the particular memory entry during the previous speculative lock.

2. The method of claim 1.

7. speculatively executing the lock instruction includes relaxing a constraint of the lock.

2. The method of claim 1.

8. speculatively executing the lock instruction includes relaxing the atomic accessibility or fencing nature of the lock.

2. The method of claim 1.

9. 1. A method of locking an entry in a memory device, comprising: executing a lock instruction of a thread to lock a particular memory entry of the memory device; the lock instruction is executed speculatively or non-speculatively during a particular time period based on whether the particular memory entry was written to by a second thread during a window of exposure of a previous speculative lock exceeds a threshold value, and is non-speculatively executed based on whether the particular memory entry was read by the second thread during the window of exposure; non-speculatively executing the lock instruction includes not allowing the second thread to modify the particular memory entry; speculatively executing the lock instruction includes allowing the second thread to modify the particular memory entry; the window of exposure is the time period from when the particular memory entry was read during one of the previous speculative locks to when the previous speculative lock completes; method.

10. the lock instruction is executed speculatively or non-speculatively based on whether, during the specified time period, the number of times any memory entry in the memory device has been written to by other threads during a window of exposure of a previous speculative lock exceeds a threshold value.

10. The method of claim 9.

11. and detecting, in response to the lock instruction being speculatively executed, whether another thread has written to the particular memory entry during the speculative lock.

10. The method of claim 9.

12. and, in response to another thread writing to the particular memory entry during the speculative lock, flushing a pipeline in which the thread is executing and re-executing the thread starting from the lock instruction.

12. The method of claim 11.

13. Detecting whether another thread has written to the particular memory entry during the speculative lock includes detecting whether the particular memory entry contains invalid data.

12. The method of claim 11.

14. Detecting whether another thread has written to the particular memory entry includes detecting any of an access, modification, access request, or modification request by a thread to the memory entry while the memory entry is locked.

12. The method of claim 11.

15. Whether the number of previous speculative locks in which other threads have written to the particular memory entry during a particular period of time exceeds a threshold value includes whether other threads have requested access to, accessed, requested modification to, or modified the particular memory entry during the previous speculative lock.

10. The method of claim 9.

16. speculatively executing the lock instruction includes relaxing a constraint of the lock.

10. The method of claim 9.

17. speculatively executing the lock instruction includes relaxing the atomic accessibility or fencing nature of the lock.

10. The method of claim 9.

18. 1. A processing device configured for speculative locking, comprising: a processor core including an execution pipeline; The processing device comprises: configured to execute a lock instruction of the thread to lock a particular memory entry of the memory device; the lock instruction is executed speculatively or non-speculatively based on whether the particular memory entry was written by a second thread during a window of exposure of a previous speculative lock and is non-speculatively executed based on whether the particular memory entry was read by the second thread during the window of exposure; non-speculatively executing the lock instruction includes not allowing the second thread to modify the particular memory entry; speculatively executing the lock instruction includes allowing the second thread to modify the particular memory entry; the window of exposure is the period of time from when the particular memory entry was read during the previous speculative lock to when the previous speculative lock completes. Processing device.

19. The processing device is further configured, in response to the lock instruction being executed as a speculative lock, to detect whether another thread wrote to the particular memory entry during the speculative lock.

20. The processing device of claim 18.

20. The processing device is further configured, in response to another thread writing to the particular memory entry during the speculative lock, to flush a pipeline in which the thread is executing and to re-execute the thread starting at the lock instruction.

20. The processing device of claim 19.

21. Detecting whether another thread has written to the particular memory entry during the speculative lock includes detecting whether the particular memory entry contains invalid data.

20. The processing device of claim 19.

22. Detecting whether another thread has written to the particular memory entry includes detecting any of an access, modification, access request, or modification request to the memory entry by the other thread while the memory entry is locked.

20. The processing device of claim 19.

23. Whether or not another thread has written to the particular memory entry during the previous speculative lock includes whether or not another thread has requested access to, accessed, requested modification to, or modified the particular memory entry during the previous speculative lock.

20. The processing device of claim 18.

24. speculatively executing the lock instruction includes relaxing a constraint of the lock.

20. The processing device of claim 18.

25. speculatively executing the lock instruction includes relaxing the atomic accessibility or fencing nature of the lock.

20. The processing device of claim 18.

26. 1. A processing device configured for speculative locking, comprising: a processor core including an execution pipeline; The processing device comprises: configured to execute a lock instruction of the thread to lock a particular memory entry of the memory device; the lock instruction is executed speculatively or non-speculatively during a particular time period based on whether the particular memory entry was written to by a second thread during a window of exposure of a previous speculative lock exceeds a threshold value, and is non-speculatively executed based on whether the particular memory entry was read by the second thread during the window of exposure; non-speculatively executing the lock instruction includes not allowing the second thread to modify the particular memory entry; speculatively executing the lock instruction includes allowing the second thread to modify the particular memory entry; the window of exposure is the time period from when the particular memory entry was read during one of the previous speculative locks to when the previous speculative lock completes; Processing device.

27. the lock instruction is executed speculatively or non-speculatively during the specified time period based on whether the number of times any memory entry in the memory device was modified by other threads during a window of exposure of a previous speculative lock exceeds a threshold value.

27. The processing device of claim 26.

28. The processing device is further configured, in response to the lock instruction being speculatively executed, to detect whether other threads have written to the particular memory entry during the speculative lock.

27. The processing device of claim 26.

29. The processing device is further configured, in response to another thread writing to the particular memory entry during the speculative lock, to flush a pipeline in which the thread is executing and to re-execute the thread starting at the lock instruction.

27. The processing device of claim 26.

30. Detecting whether another thread has written to the particular memory entry during the speculative lock includes detecting whether the particular memory entry contains invalid data.

30. The processing device of claim 28.

31. Whether another thread has written to the particular memory entry includes any of the following: access, modification, and request to access or modify the memory entry by the thread while the memory entry is locked; 27. The processing device of claim 26.

32. Whether the number of previous speculative locks in which other threads have written to the particular memory entry during a particular period of time exceeds a threshold value includes whether other threads have requested access to, accessed, requested modification to, or modified the particular memory entry during the previous speculative lock.

27. The processing device of claim 26.

33. speculatively executing the lock instruction includes relaxing a constraint of the lock.

27. The processing device of claim 26.

34. speculatively executing the lock instruction includes relaxing the atomic accessibility or fencing nature of the lock.

27. The processing device of claim 26.

Citation Information

Patent Citations

  • Method and apparatus for speculative execution of non-conflicting lock instructions

    JP2008504603A

  • Transaction-based shared data operations in multiprocessor environments

    JP2008525923A

  • Concurrent execution of critical sections by eliding ownership of locks

    US20030079094A1

  • Adaptive process for data sharing with selection of lock elision and locking

    WO2015055083A1

  • An apparatus and method to generate trace data in response to transactional execution

    WO2016139446A1