US 20050216673 A1
A method and device for determining an attribute associated with a locked load instruction and selecting a lock protocol based upon the attribute of the locked load instruction. Also disclosed is a method for concurrently executing the respective lock sequences associated with multiple threads of a processing device.
16. A method comprising:
in response to a determination that a locked μOP is an oldest μOP in a replay loop, draining stores in a buffer memory and, in parallel therewith, checking for a special event; and
in response to a verification that the special event is clear and a verification that the stores in the buffer memory are drained, providing a lock ready signal.
17. The method of
18. The method of
19. A method comprising:
in response to a determination that a locked μOP is an oldest μOP in a replay loop, checking for a special event; and
in response to a verification that the special event is clear, providing a lock ready signal.
20. The method of
21. The method of
22. A method comprising:
executing a lock protocol for a cache lock associated with a first thread of a processing device;
executing the lock protocol for a cache lock associated with a second thread of the processing device; and
performing a lock sequence for the cache lock associated with the first thread while performing a lock sequence for the cache lock associated with the second thread.
23. The method of
acquiring ownership of a memory location associated with the cache lock;
performing an atomic operation on data stored at the memory location; and
releasing ownership of the memory location.
24. The method of
performing a load operation to access the data stored at the memory location;
performing a modify operation on the data; and
performing a store instruction to write modified data to the memory location.
Embodiments of the invention relate generally to microprocessors and other processing devices and, more particularly, to a method and apparatus for handling locks.
Microelectronic manufacturers are continually striving to improve the speed and performance of microprocessors and other processing devices, the performance of such devices being dependent upon many factors. One factor affecting the performance of a processing device is the scheduling and execution of instructions associated with a piece of code executing on that processor. To increase the speed at which a set of instructions can be executed—and, hence, to improve efficiency and performance—multi-threaded processors and multi-processor systems have been devised. Performance may also be enhanced using speculative and/or out-of-order execution of instructions. In out-of-order processing, a piece of code is not necessarily executed in the same sequence as its underlying source code and, in speculative processing, instructions are prefetched and branch prediction is performed to “guess” whether a branch condition will, or will not, be taken.
Typically, a processor includes an instruction decoder that decodes an instruction to create one or more micro-instructions, or micro-operations, that can be understood and executed by the processor. A micro-operation will also be referred to herein as a “μOP.” A series of μOPs associated with a piece of code may be scheduled for execution on a processor (or on a specific thread thereof), this scheduling potentially being speculative or out-of-order, as noted above. If a μOP properly executes, that μOP is retired. However, if a μOP does not, for any reason, properly execute, the μOP is again scheduled and replayed for execution. Although the set of μOPs associated with the piece of code may be executed out of order, the μOPs must generally be retired in order.
For systems incorporating multi-threaded processors and/or multiple processing devices, the multiple threads and/or multiple processors may often times need to share data stored within the system. Care must be taken to insure that a thread or processor accesses the most recent and up-to-date data and also to insure that a thread or processor does not access and modify data currently associated with another thread or processor. Further complicating this sharing of data, most modern-day processing devices include one or more on-chip cache memories. Within a multi-processor system, the multiple on-chip caches will often—and, in practice, generally do—contain multiple copies of a data item. Accordingly, when a thread or processor accesses a copy of a data item, it must be insured that an updated or valid data value is read.
Thus, in multi-threaded processors and/or multi-processor systems, “cache coherency” must be maintained. Cache coherency refers to the synchronization of data written from, or read into, cache memory, such that any data item stored in a cache that is accessed by a thread or processor is the most recent copy of that data item. Further, any data value written from cache back into main memory should be the most current data. The accuracy and performance of speculative and out-of-order processing is highly dependent upon the consistency and synchronization of data.
One method of maintaining cache coherency and insuring that, when a data item is needed by a thread or processor, the most up-to-date value for that data item is accessed is to implement a “lock.” A lock comprises a process that is performed in response to a load instruction—i.e., a μOP issued by a processor or thread requesting a specific data item from memory—to insure synchronization between processors and/or threads. A lock is an attribute of a load instruction, and the lock is typically indicated by a tag associated with the lock. A load instruction that has been tagged for lock will be referred to herein as a “locked μOP.”
Generally, a lock is associated with a set of instructions, including the load instruction, an instruction to modify the data item, and a store instruction (i.e., a μOP issued by a processor to write the modified data item to memory). The lock—also referred to herein as a “lock sequence” or “lock operation”—may, for example, include acquiring ownership of a memory location that stores data (that is the subject of a tagged load instruction), performing an atomic operation on the data while preventing other processes from operating on that data, and releasing ownership of the memory location after the atomic operation is performed. An atomic operation is one that is performed sequentially and in an uninterrupted manner and, further, that is guaranteed to be completed or not completed at all (i.e., the operation is indivisible). Because execution of the set of μOPs (i.e., the load, modify, and store instructions) is atomic, the entire lock sequence is sometimes viewed as a single μOP (e.g., it appears like a single operation).
While use of locks can insure cache coherency and data integrity, this mechanism is not without its disadvantages. Specifically, the processing of a lock can introduce significant latency into the execution of a piece of code.
Each of the processing devices 200 may have an external or off-chip cache 130 coupled therewith, respectively. For example, the processor 200 a may have an external cache 130 a coupled therewith whereas an external cache 130 b may be coupled with the processor 200 b, each of the external caches 130 a, 130 b also being coupled with the system bus 110. It should be understood that, although illustrated as separate memories, the external caches 130 a-b may comprise a single, integrated memory. The computer system 100 includes a main memory 120 coupled—via system bus 110—with the processing devices 200, the main memory 120 comprising, for example, any suitable type of random access memory (RAM). The computer system 100 may further include a read-only memory (ROM) 140 coupled with the system bus 110. The processing devices 200 may also have a data storage device 150 coupled therewith by system bus 110. The data storage device 150 comprises any suitable non-volatile memory, such as, for example, a hard disk drive.
The computer system 100 may include one or more input devices 160 coupled with the system bus 110. Common input devices 160 include keyboards, pointing devices such as a mouse, and scanners or other data entry devices. One or more output devices 170 may also be coupled with the system bus 110. Common output devices 170 include video monitors, printing devices, and audio output devices (e.g., a sound card and speakers). The computer system 100 may further include a removable storage media 180, such as a floppy disk drive or CD ROM drive.
It should be understood that the computer system 100 illustrated in
The processor 200 includes an instruction decoder 220 and a scheduler 230, both coupled with the local bus 205. The instruction decoder 220 receives an instruction (or instructions) associated with a program or piece of code executing on processor 200 and breaks the instruction down into one or more μOPs. The scheduler 230 receives μOPs from the instruction decoder 220 and schedules the μOPs for execution. The μOPs scheduled for execution by scheduler 230 may be associated with a single thread or, alternatively, multiple threads. Also, the μOPs may be scheduled in a speculative and/or out-of-order manner, as described above. Further, it should be understood that the processor 200 may receive one or more instructions associated with a program, whereas another processor 200 of computer system 100 may receive one or more instructions associated with the same program. Accordingly, a program may be executing on multiple processors 200.
The scheduler 230 outputs scheduled μOPs to a reservation station 240 and a re-order buffer (ROB) 250. The reservation station 240 stores instructions that have not been executed and then dispatches the instructions to a CPU core 270 for execution and/or to a memory cluster 260. The CPU core 270 comprises one or more execution units, such as, for example, an arithmetic and logic unit. If a μOP corresponds to, for example, an arithmetic operation, that μOP is dispatched to the CPU core 270, which then performs the arithmetic operation. If a μOP corresponds to a memory-referencing instruction—e.g., a load or a store—that μOP is dispatched to the memory cluster 260 and, more specifically, to a memory-ordering buffer (MOB) 265, as will be explained below.
The ROB 250 stores the results (which, again, may be speculative) of μOPs dispatched by the reservation station 240 and executed in CPU core 270. Due to unresolved conditions or antecedents resulting from the speculative execution of instructions, a μOP may not have properly executed in CPU core 270 and/or the results associated with the μOP may be speculative. Such a speculative μOP is sent into a replay loop (shown schematically at reference numeral 290) where the μOP is replayed until the μOP is no longer speculative—i.e., the μOP is non-speculative or “replay safe”—at which time any previously unresolved conditions and antecedents have been verified and, if necessary, the μOP is executed.
As noted above, although a series of μOPs associated with a piece of code may be executed out-of-order, these μOPs must generally be retired in order. Accordingly, the ROB 250 reorders the retirement of μOPs to achieve a sequence of events specified by a piece of code, wherein each μOP is retired when it has become replay safe. An “at-retire” pointer 292 identifies the “oldest” μOP in the replay loop 290 and, generally, it is this oldest μOP that is next in line to retire. When a μOP is ready to be retired, as identified by the at-retire pointer 292, resolution of all previously unresolved conditions or antecedents is verified and/or the μOP is executed, as noted above.
The memory cluster 260 includes one or more levels of cache memory, including, for example, an L0 cache 261 and an L1 cache 262. Each of the L0 cache 261 and L1 cache 262 can store data recently accessed, or expected to be accessed, by the CPU core 270. If an item of data requested by CPU core 270 is resident in one of the cache memories 261, 262, a cache “hit” has occurred; however, if the requested data is not present in cache, then a cache “miss” has occurred. One or more of the cache memories (e.g., L0 cache 261) may be coupled with a data access control unit (DAC) 263. The DAC 263 controls all transactions that resulted in a cache miss, as well as other transactions that require special handling. A lock, as described above, is one type of transaction that requires special handling by the DAC 263 and by other components of the memory cluster 260.
The DAC 263 may include a write-combining buffer (WCB) 264. The WCB 264 is, in essence, a cache memory for holding stores that may be combined and written to memory (e.g., a cache) in a single store operation, thereby reducing the number of memory accesses and improving bus bandwidth. For instance, a series of data stores may be combined and written to the same cache line within the WCB 264 and, when the cache line is full, the entire cache line is committed to memory. Generally, data stores of any memory type may be subjected to write-combining in the WCB 264, including cacheable and, in some instances, uncacheable stores.
The memory cluster 260 also includes the memory ordering buffer (MOB) 265, as noted above. Load and store instructions are dispatched from the reservation station 240 to the MOB 265. The MOB 265 ensures the proper ordering of load and store instructions and, further, provides for the proper sequencing of these transactions within the memory hierarchy (i.e., the various levels of memory within computer system 100, including L0 cache 261, L1 cache 262, external cache 130, main memory 120, and data storage device 150).
The memory cluster 260 further includes a page miss handler (PMH) 266 and a segmentation and address translation unit (SAAT) 267, the SAAT 267 including a translation lookaside buffer (TLB) 268 that provides a cache for virtual-to-physical address translations. The PMH 266 may handle certain events, such as page misses, cache misses, TLB misses, page splits, and cache splits, that can occur in response to a load instruction. In response to one of the aforementioned events, the PMH 266 will generate one or more μOPs to process the event. The SAAT 267 interfaces directly with the PMH 266, and the SAAT 267 detects the occurrence of any of the above-described events and issues a request to the PMH 266 to process the detected event. By way of example, if the SAAT 267 detects a TLB miss, the SAAT 267 will issue a request to the PMH 266 directing the PMH to execute a page walk in order to load the appropriate physical address translation from main memory 120 and into the TLB 268. In response, the PMH 266 will generate one or more μOPs to handle the page walk.
It should be understood that the processor 200 illustrated in
Any one or more of the μOPs scheduled for execution by scheduler 220 may comprise a load instruction that has been tagged for a lock—i.e., a locked μOP. The lock, as noted above, corresponds to a sequence of instructions (e.g., load, modify, and store) that are performed in a manner (e.g., acquiring ownership of a memory location, performing an atomic operation, and releasing ownership of the memory location) that insures synchronization between processors and/or threads. The tag for lock is generally provided by a program executing on the processing device 200 that requires atomic operation. However, it should be understood that a tag for lock may be issued by, or derived from, any other source.
Referring now to
Referring to block 325, the lock protocol is now performed. During execution of the lock protocol, synchronization is performed to ensure that there are no operations older than the locked μOP that are pending to the “lock address” (i.e., the memory address associated with the locked load instructions). Further, required resources are reserved to ensure that all necessary resources are available to complete the lock operation. When the lock protocol is complete, the DAC 263 will accept the locked μOP, as illustrated at block 330, and assume responsibility for conducting the lock sequence.
Referring to block 335, the lock sequence may then be performed. Generally, the first step in the lock sequence is for the DAC 263 to obtain “ownership” of the lock address. To obtain such ownership, the DAC 263 issues a read-for-ownership (RFO) instruction to read the data from the lock address (i.e., the data that is the subject of the locked load instruction), and this data is written to a buffer that has been allocated to the lock. The allocated buffer is typically protected, such that other transactions cannot access the lock address during the lock sequence. After the RFO completes—the locked μOP having been replayed until completion of the RFO—the locked μOP has been executed and is, therefore, considered to be “replay safe.” Once the locked μOP is replay safe, the modify operation of the lock sequence can be performed on the data contained in the allocated buffer. Subsequently, a Store Unlock instruction is executed to store the modified data at the lock address and, further, to unlock the allocated buffer and the locked memory location (i.e., the lock address).
Referring to block 405, the MOB 265 drains all pending stores to on-chip cache (e.g., L0 cache 261 or L1 cache 262) or other suitable memory. When all stores are drained—see time 490 b—a check for any events or conditions that may require special processing is performed, as shown at block 410. Events requiring special processing include, for example, page misses, cache misses, TLB misses, page splits, cache splits, SAAT faults, as well as others (these events being referred to herein as “special events”). If such a special event is found—such events typically being detected by the SAAT 267—the special event is processed, this processing usually being performed by the PMH 266 and/or SAAT 267. Upon clearing of these special events or conditions, as depicted at time 490 c, the DAC 263 verifies that all pending stores have been drained and that the memory cluster 260 is indeed ready to handle the lock—see block 415—and, at some later point in time 490 d, the DAC 263 signals a lock request to the MOB 265, PMH 266, and SAAT 267.
In response to receipt of the lock request from the DAC 263, each of the MOB 265 and PMH 266 will complete any pending transactions and then send a lock ready signal to the SAAT 267, as shown at block 420. The SAAT 267 will also clear and/or complete any pending transactions and, upon receipt of the lock ready signals from the MOB 265 and PMH 266, respectively, the SAAT 267 will transmit a lock ready signal to the DAC 263—also as shown at block 420—to indicate to the DAC 263 that the necessary resources of the MOB 265, PMH 266, and SAAT 267 are free. Thus, at a further point in time 490 e, the DAC 263 receives the lock ready signal.
In response to receipt of the lock ready signal at DAC 263, the WCB 264 will dump all pending stores to cache (e.g., L0 cache 261 or L1 cache 262) or other suitable memory—see block 425—such that the resources of the WCB 264 are available for handling the lock. When the WCB 264 has been evicted, as depicted at time 490 f, the DAC 263 will verify eviction of the WCB 264, as illustrated in block 430. After verifying all stores have been dumped from the WCB 264, the DAC 263 will accept the lock, which is shown on the timeline 490 at time 490 g.
Although the method 300 of handling locks treats all locked μOPs the same—i.e., it applies the same lock protocol to all locks—locked μOPs and their respective lock sequences are not, in practice, identical. Locks may have differing characteristics depending upon, for example, the type of memory associated with the lock address. More specific, the requirements for handling a lock directed to a lock address that is cacheable in an on-chip cache memory (e.g., L0 cache 261 or L1 cache 262) may be significantly different than the requirements for handling a lock directed to a lock address that is not amenable to on-chip cache storage—i.e., a store or write operation to external memory (e.g., main memory 120 or external cache 130) is necessary. A lock directed to a lock address that is cacheable will be referred to herein as a “cache lock,” whereas a lock directed to a lock address that is not cacheable will be referred to herein as a “bus lock.” Because a bus lock is directed to a memory address that is off-chip—e.g., it requires a transaction across bus interface unit 210 and/or system bus 110—the requirements for processing, as well as the resources required, are much more burdensome than the requirements and resources needed to handle a cache lock, which is directed to an on-chip memory address.
Because the method 300 for handling locks does not distinguish among cache and bus locks, the lock protocol 400 must be adapted to handle both bus locks and cache locks. Accordingly, the lock protocol 400 must meet the more demanding requirements and resource needs of bus locks, but this same lock protocol 400 is also being used for cache locks, which results in significant and unnecessary overhead for processing cache locks. Therefore, applying the lock protocol 400 to all locks, irrespective of whether the lock is a bus or cache lock, adds significant latency to the processing of cache locks, a situation that is especially troublesome because, in practice, the majority of locks are cache locks.
Referring to block 305 in
Referring to block 505, a lock protocol is selected. As will be described in greater detail below, the lock protocol is selected based upon the type or characteristics of the lock. The selected lock protocol is then performed, as illustrated at block 510. Again, execution of the lock protocol provides synchronization and insures the availability of required resources for performing the lock sequence. Because selection of the lock protocol is determined in response to the specific type or characteristics of the pending lock, the lock protocol that is executed will be optimized for the particular lock being processed and, therefore, the overhead associated with lock handling is reduced and latency minimized.
When the lock protocol is complete, the DAC 263 will accept the locked μOP and assume responsibility for conducting the lock sequence, as shown at block 330. Referring to block 335, the lock sequence may then be performed. Generally, as noted above, the first step in the lock sequence is for the DAC 263 to obtain “ownership” of the lock address by issuing a RFO instruction to read the data from the lock address, which is written to a protected buffer that has been allocated to the lock. After the RFO completes and the locked μOP has been executed, the modify operation of the lock sequence can be performed on the data contained in the protected buffer. A Store Unlock instruction is then executed to store the modified data at the lock address and, further, to unlock the protected buffer and the locked memory location.
Referring to reference numeral 710, if the locked μOP is associated with a lock address that is cacheable, the locked μOP is tagged as a cache lock, as shown at 715. As shown at block 720, the cache lock protocol is then applied to the lock during lock handling (see block 510 in
Referring again to reference numeral 710, if the locked μOP is associated with a lock address that is uncacheable, the locked μOP is tagged as a bus lock, as shown at block 725. As illustrated at block 730, a bus lock protocol is applied to the locked μOP during lock handling (see block 510 in
In another embodiment, if the locked μOP is associated with a lock address that is cacheable (see reference numeral 710), the locked μOP is tagged as a cache lock (see block 715), and the cache lock protocol is then applied to the lock during lock handling (see block 720), as described above. However, if the locked μOP is associated with a lock address that is not cacheable (see reference numeral 710), the bus lock protocol is simply applied to handle the lock (see block 730) and a tag (identifying the lock as a bus lock) is not applied to the uncacheable lock. In other words, the element illustrated at block 725 may be omitted. In a further embodiment, if the locked μOP is associated with a lock address that is not cacheable (see reference numeral 710), the locked μOP is tagged as a bus lock (see block 725), and the bus lock protocol is then applied to the lock during lock handling (see block 730). If the locked μOP is, however, associated with a lock address that is cacheable (see reference numeral 710), the cache lock protocol is simply applied to handle the lock (see block 720) and a tag (identifying the lock as a cache lock) is not applied to the cacheable lock. Thus, the element illustrated at block 715 may be omitted in this embodiment.
An embodiment of a cache lock protocol 800 is illustrated in
Referring now to
When the stores have been drained and all special events or conditions cleared, as shown at point 890 b on timeline 890, the SAAT 267 verifies that the special events are clear and also verifies the drainage of stores, and then the SAAT 267 provides a lock ready signal to the DAC 263, as illustrated at block 810. For the above-described alternative embodiment, wherein the stores are not drained, the SAAT 267 does not verify the drainage of stores prior to issuing a lock ready signal to the DAC 263. Rather, in response to verification that the special events are clear, the SAAT 267 provides the lock ready signal to DAC 263. Referring to point 890 c on timeline 890, the DAC 263 accepts the lock in response to receipt of the lock ready signal provided by SAAT 267.
Generally, during handling of a bus lock, the bus will be reserved (e.g., as by assertion of a lock pin on the bus) for execution of the lock sequence. Thus, bus locks cannot be processed in parallel but, rather, must be executed sequentially. However, processing of a cache lock does not require obtaining ownership of the bus and, because cache locks are now processed using a unique protocol, cache locks associated with different threads can be handled concurrently. Illustrated in
As set forth above, the method 700 of selecting a lock protocol, as well as the method 500 of handling locks, are not limited to distinguishing among cache and bus locks. Rather, the disclosed embodiments may be used to process any suitable number of lock types that are distinguished according to any suitable characteristic or set of characteristics. For example, locks may be classified based upon whether the locked μOP necessitates accessing an address split across two cache lines (i.e., a cache split). The more general applicability of the disclosed embodiments may be better understood with reference to the method 1000 of selecting a lock protocol illustrated in
Referring to block 1005 in
In another embodiment, if the locked μOP exhibits the one or more specified attributes (see reference numeral 1010) the locked μOP is tagged as a first lock type (see block 1015), and the first cache lock protocol is then applied to the lock during lock handling (see block 1020), as described above. However, if the locked μOP does not exhibit the specified attribute or attributes (see reference numeral 1010), the second lock protocol is simply applied to handle the lock (see block 1030) and a tag (identifying the lock as the second lock type) is not applied to the lock. In other words, the element illustrated at block 1025 may be omitted. Of course, the element illustrated at block 1015 (i.e., tagging the locked μOP as the first lock type) may be omitted rather than the element illustrated at block 1025. Stated another way, if a locked μOP exhibits one or more specified attributes, the locked μOP is tagged and a lock protocol applied to handle this tagged lock, whereas if the locked μOP does not exhibit the one or more specified attributes (or exhibits some other attribute or set of attributes), a different lock protocol is applied to handle this untagged lock.
For the method 1000 of selecting a lock protocol, any suitable attribute or attributes may be utilized to distinguish between locks. Further, any suitable number of lock protocols (and, hence, lock types) may be employed. For example, a certain set of attributes may correspond to yet a third lock type that requires a third lock protocol. Stated another way, if a locked μOP exhibits a first attribute or set of attributes, a first lock protocol is applied, and if the locked μOP exhibits a second attribute(s), a second lock protocol is applied, whereas if the locked μOP exhibits a third attribute(s), a third lock protocol is applied, and so on.
From a comparison of the cache lock protocol 800 with the lock protocol 400 of
In other instances, where there is a tradeoff between performance and complexity, increased complexity may be acceptable for cache locks, whereas the increased complexity would not be acceptable for bus locks because the gain in performance does not outweigh the added complexity. For example, for the cache lock protocol 800, a two-way handshake between the DAC 263 and SAAT 267 was eliminated (as compared to the bus lock protocol 400). This two-way handshake hurts performance, but such a two-way handshake is desirable for the bus lock protocol 400 because it reduces complexity. However, for the cache lock protocol 800 that eliminates this two-way handshake, the added complexity is acceptable for the gain in performance. There may, of course, be other situations where the performance-complexity balance may tilt the other direction, and reduced complexity taken advantage of to increase performance.
By distinguishing between lock types and applying a unique protocol to each type of lock, microelectronic designers can now tailor a protocol for the specific type of lock that protocol is intended to process. Unnecessary steps can be eliminated. Further, any cost-benefit analysis (e.g., complexity vs. performance) can be directed to one type of lock, and any performance-enhancing feature may be advantageously realized, irrespective of that feature's affect on other types of locks. In sum, the worst-case scenario no longer governs the lock handling process for all types of locks, and a lock protocol may be optimized for a single type of lock that the protocol is intended to process, thereby improving performance and minimizing latency.
The foregoing detailed description and accompanying drawings are only illustrative and not restrictive. They have been provided primarily for a clear and comprehensive understanding of the disclosed embodiments and no unnecessary limitations are to be understood therefrom. Numerous additions, deletions, and modifications to the embodiments described herein, as well as alternative arrangements, may be devised by those skilled in the art without departing from the spirit of the disclosed embodiments and the scope of the appended claims.