WO2007015925A1 - Avoiding locks by transactionally executing critical sections - Google Patents
Avoiding locks by transactionally executing critical sections Download PDFInfo
- Publication number
- WO2007015925A1 WO2007015925A1 PCT/US2006/028152 US2006028152W WO2007015925A1 WO 2007015925 A1 WO2007015925 A1 WO 2007015925A1 US 2006028152 W US2006028152 W US 2006028152W WO 2007015925 A1 WO2007015925 A1 WO 2007015925A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- critical section
- transactional execution
- program
- critical
- transactionally
- Prior art date
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/52—Program synchronisation; Mutual exclusion, e.g. by means of semaphores
- G06F9/526—Mutual exclusion algorithms
- G06F9/528—Mutual exclusion algorithms by using speculative mechanisms
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30003—Arrangements for executing specific machine instructions
- G06F9/3004—Arrangements for executing specific machine instructions to perform operations on memory
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30003—Arrangements for executing specific machine instructions
- G06F9/30076—Arrangements for executing specific machine instructions to perform miscellaneous control operations, e.g. NOP
- G06F9/30087—Synchronisation or serialisation instructions
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/38—Concurrent instruction execution, e.g. pipeline or look ahead
- G06F9/3824—Operand accessing
- G06F9/3834—Maintaining memory consistency
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/38—Concurrent instruction execution, e.g. pipeline or look ahead
- G06F9/3854—Instruction completion, e.g. retiring, committing or graduating
- G06F9/3858—Result writeback, i.e. updating the architectural state or memory
- G06F9/38585—Result writeback, i.e. updating the architectural state or memory with result invalidation, e.g. nullification
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/466—Transaction processing
- G06F9/467—Transactional memory
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/52—Binary to binary
Definitions
- attempting to re-execute the critical section involves attempting to transactionally re-execute the critical section.
- the program is modified so that if the critical section is not successfully completed after one or more attempts at transactional execution, the program: acquires a lock associated with the critical section; non- transactionally executes the critical section; and releases the lock associated with the critical section.
- FIG. 2A illustrates how a critical section is executed in accordance with an embodiment of the present invention. ⁇ .
- Processor 101 additionally includes a level one (Ll) data cache 115, which stores data items that are likely to be used by processor 101.
- Ll data cache 115 includes load-marking bits 116, which indicate that a data value from the line has been loaded during transactional execution. These load-marking bits 116 are used to determine whether any interfering memory references take place during transactional execution as is described below with reference to FIGs. 3-8.
- Processor 101 also includes an Ll instruction cache (not shown).
- Ll instruction cache in processor 101, and with Ll data cache 117 (and a corresponding Ll instruction cache) in processor 102.
- L2 cache 120 is associated with a coherency mechanism 122, such as the reverse directory structure described in U.S. Patent Application No. 10/186,118, entitled, "Method and Apparatus for Facilitating Speculative Loads in a Multiprocessor System," filed on June 26, 2002, by inventors Shailender Chaudhry and Marc Tremblay (Publication No. US-2002-0199066-A1).
- This coherency mechanism 122 maintains "copyback inforavation" 121 for each cache line.
- FIG. 6 presents a flow chart illustrating how store-marking is performed during transactional execution in accordance with an embodiment of the present invention.
- the system performs a store operation. If this store operation has been identified as a store operation that needs to be store-marked, the system first prefetches a corresponding cache line for exclusive use (step 602). Note that this prefetch operation will do nothing if the line is already located in cache and is already in an exclusive use state.
- Ll data cache 115 is a write-through cache
- the store operation propagates through Ll data cache 115 to L2 cache 120. The system then attempts to lock the cache line corresponding to the store operation in L2 data cache 115 (step 604).
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Advance Control (AREA)
Abstract
A system that avoids locks by transactionally executing critical sections. The system receives a program which includes critical sections which are protected by locks. The system modifies the program so that the critical sections are executed transactionally without acquiring locks. The program is modified so that: (1) during transactional execution of a critical section, the program first determines if a lock associated with the critical section is held by another process and if so aborts the transactional execution; (2) if the transactional execution completes without encountering an interfering data access from another process, the program commits changes made during the transactional execution and optionally resumes normal non-transactional execution of the program past the critical section; and (3) if an interfering data access from another process is encountered during transactional execution, the program discards changes made during the transactional execution, and attempts to re-execute the critical section.
Description
AVOIDING LOCKS BY TRANSACTIONALLY EXECUTING CRITICAL SECTIONS
Inventors: Mark S. Moir, Marc Tremblay and Shailender Chaudhry
BACKGROUND
Field of the Invention [0001] The present invention relates to techniques for improving performance within computer systems. More specifically, the present invention relates to a method and an apparatus for avoiding the overhead involved in using locks by transactionally executing critical sections of code.
Related Art
[0002] Computer system designers are presently developing mechanisms to support multi-threading within the latest generation of Chip-Multiprocessors (CMPs) as well as more traditional Shared Memory Multiprocessors (SMPs). With proper hardware support, multithreading can dramatically increase the performance of numerous applications. However, as microprocessor performance continues to increase, the time spent synchronizing between threads (processes) is becoming a large fraction of overall execution time. In fact, as multithreaded applications begin to use even more threads, this synchronization overhead becomes the dominant factor in limiting application performance.
[0003] From a programmer's perspective, synchronization is generally accomplished through the use of locks. A lock is typically acquired before a thread enters a critical section of code, and is released after the thread exits the critical section. If another thread wants to enter a critical section protected by the same lock, it must acquire the same lock. If it is unable to acquire the lock, because a preceding thread has grabbed the lock, the thread must wait until the preceding thread releases the lock. (Note that a lock can be implemented in a number of ways, such as through atomic operations or semaphores.)
[0004] Unfortunately, the process of acquiring a lock and the process of releasing a lock are very time-consuming in modern microprocessors. They involve atomic operations, which typically flush the load buffer and store buffer, and can consequently require hundreds, if not thousands, of processor cycles to complete. [0005] Moreover, as multi-threaded applications use more threads, more locks are required. For example, if multiple threads need to access a shared data structure, it is impractical for performance reasons to use a single lock for the entire data structure. Instead, it is preferable to use multiple fine-grained locks to lock small portions of the data structure.
This allows multiple threads to operate on different portions of the data structure in parallel. However, it also requires a single thread to acquire and release multiple locks in order to access different portions of the data structure. It also introduces significant software engineering concerns, such as avoiding deadlock.
[0006] In some cases, locks are used when they are not required. For example, many applications make use of "thread-safe" library routines that use locks to ensure that they are "thread-safe" for multi-threaded applications. Unfortunately, the overhead involved in acquiring and releasing these locks is still incurred, even when the thread-safe library routines are called by a single-threaded application.
[0007] Applications typically use locks to ensure mutual exclusion within critical sections of code. However, in many cases threads will not interfere with each other, even if they are allowed to execute a critical section simultaneously. In these cases, mutual exclusion is used to prevent the unlikely case in which threads actually interfere with each other.
Consequently, in these cases, the overhead involved in acquiring and releasing locks is largely wasted.
[0008] Hence, what is needed is a method and an apparatus that reduces the overhead involved in manipulating locks when accessing critical sections.
SUMMARY
[0009] One embodiment of the present invention provides a system that avoids locks by transactionally executing critical sections. During operation, the system receives a program which includes one or more critical sections which are protected by locks. Next, the
system modifies the program so that the critical sections which are protected by locks are executed transactionally without acquiring locks associated with the critical sections.
[0010] More specifically, the program is modified so that: (1) during transactional execution of a critical section, the program first determines if a lock associated with the critical section is held by another process and if so aborts the transactional execution; (2) if the transactional execution of the critical section completes without encountering an interfering data access from another process, the program commits changes made during the transactional execution and (optionally) resumes normal non-transactional execution of the program past the critical section (note that a system can possibly coalesce a number of smaller transactions into a larger one, in which case the system may not immediately resume non- transactional execution past a critical section which is associated with a smaller transaction); and (3) if an interfering data access from another process is encountered during transactional execution of the critical section, the program discards changes made during the transactional execution, and attempts to re-execute the critical section zero or more times. [0011] Note that checking the lock status within the transaction (as in step (1) above) allows the transaction to work correctly with other processes that actually acquire the lock before executing the critical section non-transactionally. This is an advantage because it allows the technique to be selectively applied where it is likely to be useful, rather than applying it across-the-board, which could potentially degrade performance in some cases. [0012] Also note that the code modification process can possibly be performed manually. For example, a programmer can identify critical sections that are frequently used, and can manually replace corresponding lock acquire and lock release calls with special calls that cause the critical section to be executed transactionally, without acquiring the lock.
[0013] In a variation on this embodiment, modifying the program can involve: using a compiler to modify the program; using a binary modification tool to modify the program; or replacing libraries accessed by the program;
[0014] In a variation on this embodiment, data accesses from other processes are allowed to proceed during the transactional execution of the critical section.
[0015] hi a variation on this embodiment, attempting to re-execute the critical section involves attempting to transactionally re-execute the critical section.
[0016] In a variation on this embodiment, the program is modified so that if the critical section is not successfully completed after one or more attempts at transactional execution, the program: acquires a lock associated with the critical section; non- transactionally executes the critical section; and releases the lock associated with the critical section.
[0017] hi a variation on this embodiment, the interfering data access can include: a store by another process to location which was loaded from during transactional execution; a load by another process to a location which was stored to during transactional execution; or a store by another process to a location which was stored to during transactional execution. [0018] In a variation on this embodiment, commencing transactional execution of a critical section involves performing a checkpointing operation to checkpoint register values and other state information.
BRIEF DESCRIPTION OF THE FIGURES [0019] FIG. 1 illustrates a computer system in accordance with an embodiment of the present invention.
[0020] FIG. 2A illustrates how a critical section is executed in accordance with an embodiment of the present invention. ■ .
[0021] FIG. 2B illustrates another example of how a critical section is executed in accordance with an embodiment of the present invention.
[0022] FIG. 3 presents a flow chart illustrating the transactional execution process in accordance with an embodiment of the present invention.
[0023] FIG. 4 presents a flow chart illustrating a start transactional execution (STE) operation in accordance with an embodiment of the present invention. [0024] FIG. 5 presents a flow chart illustrating how load-marking is performed during transactional execution in accordance with an embodiment of the present invention.
[0025] FIG. 6 presents a flow chart illustrating how store-marking is performed during transactional execution in accordance with an embodiment of the present invention.
[0026] FIG. 7 presents a flow chart illustrating how a commit operation is performed in accordance with an embodiment of the present invention.
[0027] FIG. 8 presents a flow chart illustrating how changes are discarded after transactional execution completes unsuccessfully in accordance with an embodiment of the present invention.
DETAILED DESCRIPTION
[0028] The following description is presented to enable any person skilled in the art to make and use the invention, and is provided in the context of a particular application and its requirements. Various modifications to the disclosed embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other embodiments and applications without departing from the spirit and scope of the present invention. Thus, the present invention is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed herein.
[0029] The data structures and code described in this detailed description are typically stored on a computer readable storage medium, which may be any device or medium that can store code and/or data for use by a computer system. This includes, but is not limited to, magnetic and optical storage devices such as disk drives, magnetic tape, CDs (compact discs) and DVDs (digital versatile discs or digital video discs), and computer instruction signals embodied in a transmission medium (with or without a carrier wave upon which the signals are modulated). For example, the transmission medium may include a communications network, such as the Internet.
Computer System
[0030] FIG. 1 illustrates a computer system 100 in accordance with an embodiment of the present invention. Computer system 100 can generally include any type of computer system, including, but not limited to, a computer system based on a microprocessor, a mainframe computer, a digital signal processor, a portable computing device, a personal organizer, a device controller, and a computational engine within an appliance. As is illustrated in FIG. 1, computer system 100 includes processors 101 and level 2 (L2) cache
120, which is coupled to main memory (not shown). Processor 102 is similar in structure to processor 101, so only processor 101 is described below.
[0031] Processor 101 has two register files 103 and 104, one of which is an "active register file" and the other of which is a backup "shadow register file." In one embodiment of the present invention, processor 101 provides a flash copy operation that instantly copies all of the values from register file 103 into register file 104. This facilitates a rapid register checkpointing operation to support transactional execution.
[0032] Processor 101 also includes one or more functional units, such as adder 107 and multiplier 108. These functional units are used in performing computational operations involving operands retrieved from register files 103 or 104. As in a conventional processor, load and store operations pass through load buffer 111 and store buffer 112.
[0033] Processor 101 additionally includes a level one (Ll) data cache 115, which stores data items that are likely to be used by processor 101. Note that lines in Ll data cache 115 include load-marking bits 116, which indicate that a data value from the line has been loaded during transactional execution. These load-marking bits 116 are used to determine whether any interfering memory references take place during transactional execution as is described below with reference to FIGs. 3-8. Processor 101 also includes an Ll instruction cache (not shown).
[0034] Note that load-marking does not necessarily have to take place in Ll data cache 115. In general load-marking can take place at any level cache, such as L2 cache 120, or even in an independent structure. However, for performance reasons, the load-marking will likely take place at the cache level that is as close to the processor as possible, which in this case is Ll data cache 115. Otherwise, loads would have to go to L2 cache 120 even on an Ll hit. [0035] L2 cache 120 operates in concert with Ll data cache 115 (and a corresponding
Ll instruction cache) in processor 101, and with Ll data cache 117 (and a corresponding Ll instruction cache) in processor 102. Note that L2 cache 120 is associated with a coherency mechanism 122, such as the reverse directory structure described in U.S. Patent Application No. 10/186,118, entitled, "Method and Apparatus for Facilitating Speculative Loads in a Multiprocessor System," filed on June 26, 2002, by inventors Shailender Chaudhry and Marc
Tremblay (Publication No. US-2002-0199066-A1). This coherency mechanism 122 maintains "copyback inforavation" 121 for each cache line. This copyback information 121 facilitates sending a cache line from L2 cache 120 to a requesting processor in cases where a cache line must be sent to another processor. [0036] Each line in L2 cache 120 includes a "store-marking bit," which indicates that a data value has been stored to the line during transactional execution. This store-marking bit is used to determine whether any interfering memory references take place during transactional execution as is described below with reference to FIGs. 3-8. Note that store- marking does not necessarily have to take place in L2 cache 120. [0037] Ideally, the store-marking takes place in the cache level closest to the processor where cache lines are coherent. For write-through Ll data caches, writes are automatically propagated to L2 cache 120. However, if an Ll data cache is a write-back cache, we perform store-marking in the Ll data cache. (Note that the cache coherence protocol ensures that any other processor that subsequently modifies the same cache line will retrieve the cache line from the Ll cache, and will hence become aware of the store-mark.)
Executing a Critical Section .
[0038] FIG. 2A illustrates how a critical section is executed in accordance with an embodiment of the present invention. As is illustrated in the left-hand side of FIG. 2 A, a thread that executes a critical section typically acquires a lock associated with the critical section before entering the critical section. If the lock has been acquired by another thread, the thread may have to wait until the other thread releases the lock. Upon leaving the critical section, the thread releases the lock. (Note that the terms "thread" and "process" are used interchangeably throughout this specification.) [0039] A lock can be associated with a shared data structure. For example, before accessing a shared data structure, a thread can acquire a lock on the shared data structure.
The thread can then execute a critical section of code that accesses the shared data structure.
After the thread is finished accessing the shared data structure, the thread releases the lock. [0040] In contrast, in the present invention, the thread does not acquire a lock, but instead executes a start transactional execution (STE) instruction before entering the critical
section. If the critical section is successfully completed without interference from other threads, the thread performs a commit operation, to commit changes made during transactional execution. This sequence of events is described in more detail below with reference to FIGs. 3-8. [0041] Note that in one embodiment of the present invention a compiler replaces lock-acquiring instructions with STE instructions, and also replaces corresponding lock releasing instructions with commit instructions. Note that there may not be a one-to-one correspondence between replaced instructions. For example, a single lock acquisition operation comprised of multiple instructions may be replaced by a single STE instruction. [0042] Note that in many cases we will want to maintain the ability to fall back on the lock in case we cannot make progress for some reason. Also, from a software engineering standpoint, it will often be desirable to transform the code only in common paths, and leave locking code intact in uncommon paths. To facilitate this, in transforming a critical section to execute transactionally, we can replace the lock-acquire with an STE instruction followed by code that reads the lock state transactionally and checks that the lock is not held (see FIG. 2B).
[0043] The above discussion presumes that the processor's instruction set has been augmented to include an STE instruction and a commit instruction. These instructions are described in more detail below with reference to FIGs. 3-9. .
Transactional Execution Process
[0044] FIG. 3 presents a flow chart illustrating how transactional execution takes place in accordance with an embodiment of the present invention. A thread first executes an STE instruction prior to entering of a critical section of code (step 302). Next, the system transactionally executes code within the critical section, without committing results of the transactional execution (step 304).
[0045] At the start of transactional execution of the critical section, the program transactionally reads the lock state associated with the critical section and checks that the lock is not held. If the lock is held, the system aborts transactional execution (step 303). Note that if another process acquires the lock during transactional execution of the critical section, the
transactional execution of the critical section will be aborted because the initial transactional read of the lock state will be "interfered with" by the lock acquisition operation.
[0046] During this transactional execution, the system continually monitors data references made by other threads, and determines if an interfering data access (or other type of failure) takes place during transactional execution. If not, the system atomically commits all changes made during transactional execution (step 308) and then optionally resumes normal non-transactional execution of the program past the critical section (step 310).
[0047] On the other hand, if an interfering data access is detected, the system discards changes made during the transactional execution (step 312), and attempts to re-execute the critical section (step 314).
[0048] In one embodiment of the present invention, the system attempts to transactionally re-execute the critical section zero, one, two or more times. If these attempts are not successful, the system executes an alternative block of code in normal execution mode. This alternative code may additionally attempt to perform the transaction and will likely have the ability to revert back to the conventional technique of acquiring a lock on the critical section before entering the critical section, and then releasing the lock after leaving the critical section.
[0049] Note that an interfering data access can include a store by another thread to a cache line that has been load-marked by the thread. It can also include a load or a store by another thread to a cache line that has been store-marked by the thread.
[0050] Also note that circuitry to detect interfering data accesses can be easily implemented by making minor modifications to conventional cache coherence circuitry. This conventional cache coherence circuitry presently generates signals indicating whether a given cache line has been accessed by another processor. Hence, these signals can be used to determine whether an interfering data access has taken place.
Starting Transactional Execution
[0051] FIG. 4 presents a flow chart illustrating a start transactional execution (STE) operation in accordance with an embodiment of the present invention. This flow chart illustrates what takes place during step 302 of the flow chart in FIG. 3. The system starts by
checkpointing the register file (step 402). This can involve performing a flash copy operation from register file 103 to register file 104 (see FIG. 1). In addition to checkpointing register values, this flash copy can also checkpoint various state registers associated with the currently executing thread. In general, the flash copy operation checkpoints enough state to be able to restart the corresponding thread.
[0052] At the same time the register file is checkpointed, the STE operation also causes store buffer 112 to become "gated" (step 404). This allows existing entries in store buffer to propagate to the memory sub-system (and to thereby become committed to the architectural state of the processor), but prevents new store buffer entries generated during transactional execution from doing so.
[0053] The system then starts transactional execution (step 406), which involves load- marking and store-marking cache lines, if necessary, as well as monitoring data references in order to detect interfering references.
Load-Marking Process
[0054] FIG. 5 presents a flow chart illustrating how load-marking is performed during transactional execution in accordance with an embodiment of the present invention. During transactional execution of a critical section, the system performs a load operation. In performing this load operation if the load operation has been identified as a load operation that needs to be load-marked, the system first attempts to load a data item from Ll data cache 115 (step 502). If the load causes a cache hit, the system "load-marks" the corresponding cache line in Ll data cache 115 (step 506). This involves setting the load-marking bit for the cache line. Otherwise, if the load causes a cache miss, the system retrieves the cache line from further levels of the memory hierarchy (step 508), and proceeds to step 506 to load-mark the cache line in Ll data cache 115.
Store-Marking Process
[0055] FIG. 6 presents a flow chart illustrating how store-marking is performed during transactional execution in accordance with an embodiment of the present invention. During transactional execution of a critical section, the system performs a store operation. If
this store operation has been identified as a store operation that needs to be store-marked, the system first prefetches a corresponding cache line for exclusive use (step 602). Note that this prefetch operation will do nothing if the line is already located in cache and is already in an exclusive use state. [0056] Since in this example Ll data cache 115 is a write-through cache, the store operation propagates through Ll data cache 115 to L2 cache 120. The system then attempts to lock the cache line corresponding to the store operation in L2 data cache 115 (step 604). If the corresponding line is in L2 cache 120 (cache hit), the system "store-marks" the corresponding cache line in L2 cache 120 (step 610). This involves setting the store-marking bit for the cache line. Otherwise, if the corresponding line is not in L2 cache 120 (cache miss), the system retrieves the cache line from further levels of the memory hierarchy (step 608) and then proceeds to step 610 to store-mark the cache line in L2 cache 120.
[0057] Next, after the cache line is store-marked in step 610, the system enters the store data into an entry of the store buffer 112 (step 612). Note that this store data will remain in store buffer 112 until a subsequent commit operation takes place, or until changes made during the transactional execution are discarded.
[0058] Note that a cache line that is store marked by a given thread can be read by other threads. Note that this may cause the given thread to fail while the other threads continue.
Commit Operation . .
[0059] FIG. 7 presents a flow chart illustrating how a commit operation is performed after transactional execution completes successfully in accordance with an embodiment of the present invention. This flow chart illustrates what takes place during step 308 of the flow chart in FIG. 3.
[0060] The system starts by treating store-marked cache lines as though they are locked (step 702). This means other threads that request a store-marked line must wait until the line is no longer locked before they can access the line. This is similar to how lines are locked in conventional caches. [0061] Next, the system clears load-marks from Ll data cache 115 (step 704).
[0062] The system then commits entries from store buffer 112 for stores that are identified as needing to be marked, which were generated during the transactional execution, into the memory hierarchy (step 706).. As each entry is committed, a corresponding line in L2 cache 120 is unlocked. [0063] The system also commits register file changes (step 708). For example, this can involve functionally performing a flash copy between register file 103 and register file 104 in the system illustrated in FIG. 1.
Discarding Changes [0064] FIG. 8 presents a flow chart illustrating how changes are discarded after transactional execution completes unsuccessfully in accordance with an embodiment of the present invention. This flow chart illustrates what takes place during step 312 of the flow chart in FIG. 3. The system first discards register file changes made during the transactional execution (step 802). This can involve either clearing or simply ignoring register file changes made during transactional execution. This is easy to accomplish because the old register values were checkpointed prior to commencing transactional execution. The system also clears load-marks from cache lines in Ll data cache 115 (step 804), and drains store buffer entries generated during transactional execution without committing them to the memory hierarchy (step 806). At the same time, the system unmarks corresponding L2 cache lines. Finally, in one embodiment of the present invention, the system branches to a target location specified by the STE instruction (step 808). The code at this target location optionally attempts to re-execute the critical section (as is described above with reference to step 314 of FIG. 1) or takes other action in response to the failure, for example backing off to reduce contention. [0065] The foregoing descriptions of embodiments of the present invention have been presented for purposes of illustration and description only. They are not intended to be exhaustive or to limit the present invention to the forms disclosed. Accordingly, many modifications and variations will be apparent to practitioners skilled in the art. Additionally, the above disclosure is not intended to limit the present invention. The scope of the present invention is defined by the appended claims.
Claims
1. A method for modifying a program to avoid locks by transactionally executing critical sections, comprising: receiving a program which includes one or more critical sections which are protected by locks; modifying the program so that the critical sections which are protected by locks are executed transactionally without acquiring locks associated with the critical sections; wherein the program is modified so that, during transactional execution of a critical section, the program first determines if a lock associated with the critical section is held by another process and if so aborts the transactional execution; if the transactional execution of the critical section completes without encountering an interfering data access from another process, the program commits changes made during the transactional execution and optionally resumes normal non-transactional execution of the program past the critical section; and if an interfering data access from another process is encountered during transactional execution of the critical section, the program discards changes made during the transactional execution, and attempts to re-execute the critical section zero or more times.
2. The method of claim 1, wherein modifying the program involves: using a compiler to modify the program; using a binary modification tool to modify the program; or replacing libraries accessed by the program;
3. The method of claim 1, wherein data accesses from other processes are allowed to proceed during the transactional execution of the critical section.
4. The method of claim 1 , wherein attempting to re-execute the critical section involves attempting to transactionally re-execute the critical section.
5. The method of claim 4, wherein the program is modified so that if the critical section is not successfully completed after one or more attempts at transactional execution, the program: acquires a lock associated with the critical section; non-transactionally executes the critical section; and releases the lock associated with the critical section.
6. The method of claim 1, wherein the interfering data access can include: a store by another process to location which was loaded from during transactional execution; a load by another process to a location which was stored to during transactional execution; and a store by another process to a location which was stored to during transactional execution.
7. The method of claim 1 , wherein commencing transactional execution of a critical section involves performing a checkpointing operation to checkpoint register values and other state information.
8. A method for avoiding locks by transactionally executing critical sections of code, comprising: allowing a process to transactionally execute a critical section of code within a program without acquiring a lock associated with the critical section; wherein transactionally executing the critical section involves first determining if the lock associated with the critical section is held by another process and if so aborting the transactional execution; wherein if the process completes the critical section without encountering an interfering data access from another process, the method further comprises, committing changes made during the transactional execution, and optionally resuming normal non-transactional execution of the program past the critical section; and wherein if an interfering data access from another process is encountered during transactional execution of the critical section, the method further comprises, discarding changes made during the transactional execution, and attempting to re-execute the critical section zero or more times.
9. The method of claim 8, wherein before executing the program, the method further comprises modifying the program so that critical sections which are protected by locks are executed transactionally.
10. The method of claim 9, wherein modifying the program involves : using a compiler to modify the program; using a binary modification tool to modify the program; or replacing libraries accessed by the program;
11. The method of claim 8, wherein data accesses from other processes are allowed to proceed during the transactional execution of the critical section.
12. The method of claim 8, wherein attempting to re-execute the critical section involves attempting to transactionally re-execute the critical section.
13. The method of claim 12, wherein if the critical section is not successfully completed after one or more attempts at transactional execution, the method further comprises: acquiring a lock associated with the critical section; non-transactionally executing the critical section; and releasing the lock associated with the critical section.
14. The method of claim 8, wherein commencing transactional execution of a critical section involves performing a checkpointing operation to checkpoint register values and other state information.
15. The method of claim 8, wherein the interfering data access can include: a store by another process to location that the process has loaded from during transactional execution; a load by another process to a location that the process has stored to during transactional execution; and a store by another process to a location that the process has stored to during transactional execution. .
16. An apparatus that modifies a program to avoid locks by transactionally executing critical sections, comprising: a modification mechanism configured to modify the program so that critical sections which are protected by locks are executed transactionally without acquiring locks associated with the critical sections; * .. . . ... wherein the modification mechanism is configured to modify the program so that, during transactional execution of a critical section, the program first determines if a lock associated with the critical section is held by another process and if so aborts the transactional execution; if the transactional execution of the critical section completes without encountering an interfering data access from another process, the program commits changes made during the transactional execution and optionally resumes normal non-transactional execution of the program past the critical section; and if an interfering data access from another process is encountered during transactional execution of the critical section, the program discards changes made during the transactional execution, and attempts to re-execute the critical section zero or more times.
17. The apparatus of claim 16, wherein the modification mechanism is: a compiler; a binary modification tool; or a mechanism that replaces libraries accessed by the program.
18. The apparatus of claim 16, wherein data accesses from other processes are allowed to proceed during the transactional execution of the critical section.
19. The apparatus of claim 16, wherein attempting to re-execute the critical section involves attempting to transactionally re-execute the critical section.
20. The apparatus of claim 19, wherein the program is modified so that if the critical section is not successfully completed after one or more attempts at transactional execution, the program: . . acquires a lock associated with the critical section; non-transactionally executes the critical section; and releases the lock associated with the critical section.
Priority Applications (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2008524994A JP2009508187A (en) | 2005-08-01 | 2006-07-21 | Avoiding locks by executing critical sections transactionally |
EP06787947A EP1913473A1 (en) | 2005-08-01 | 2006-07-21 | Avoiding locks by transactionally executing critical sections |
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
US11/195,093 | 2005-08-01 | ||
US11/195,093 US7398355B1 (en) | 2003-02-13 | 2005-08-01 | Avoiding locks by transactionally executing critical sections |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2007015925A1 true WO2007015925A1 (en) | 2007-02-08 |
Family
ID=37309335
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/US2006/028152 WO2007015925A1 (en) | 2005-08-01 | 2006-07-21 | Avoiding locks by transactionally executing critical sections |
Country Status (3)
Country | Link |
---|---|
EP (1) | EP1913473A1 (en) |
JP (1) | JP2009508187A (en) |
WO (1) | WO2007015925A1 (en) |
Cited By (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2012514254A (en) * | 2008-12-30 | 2012-06-21 | インテル・コーポレーション | Memory model of hardware attributes in a transactional memory system |
US9740549B2 (en) | 2012-06-15 | 2017-08-22 | International Business Machines Corporation | Facilitating transaction completion subsequent to repeated aborts of the transaction |
US9740521B2 (en) | 2012-06-15 | 2017-08-22 | International Business Machines Corporation | Constrained transaction execution |
US9766925B2 (en) | 2012-06-15 | 2017-09-19 | International Business Machines Corporation | Transactional processing |
US9772854B2 (en) | 2012-06-15 | 2017-09-26 | International Business Machines Corporation | Selectively controlling instruction execution in transactional processing |
CN107239415A (en) * | 2016-03-28 | 2017-10-10 | 华为技术有限公司 | A kind of method and device for performing critical section operation |
US9792125B2 (en) | 2012-06-15 | 2017-10-17 | International Business Machines Corporation | Saving/restoring selected registers in transactional processing |
US9851978B2 (en) | 2012-06-15 | 2017-12-26 | International Business Machines Corporation | Restricted instructions in transactional execution |
US9940138B2 (en) | 2009-04-08 | 2018-04-10 | Intel Corporation | Utilization of register checkpointing mechanism with pointer swapping to resolve multithreading mis-speculations |
US9983883B2 (en) | 2012-06-15 | 2018-05-29 | International Business Machines Corporation | Transaction abort instruction specifying a reason for abort |
US10185588B2 (en) | 2012-06-15 | 2019-01-22 | International Business Machines Corporation | Transaction begin/end instructions |
US10223214B2 (en) | 2012-06-15 | 2019-03-05 | International Business Machines Corporation | Randomized testing within transactional execution |
US10430199B2 (en) | 2012-06-15 | 2019-10-01 | International Business Machines Corporation | Program interruption filtering in transactional execution |
US10599435B2 (en) | 2012-06-15 | 2020-03-24 | International Business Machines Corporation | Nontransactional store instruction |
CN114706691A (en) * | 2022-04-15 | 2022-07-05 | 郑州信大捷安信息技术股份有限公司 | Multitask mutual exclusion method and system based on file lock |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP5088754B2 (en) | 2009-12-18 | 2012-12-05 | インターナショナル・ビジネス・マシーンズ・コーポレーション | System, method, program, and code generation apparatus |
US20120079245A1 (en) * | 2010-09-25 | 2012-03-29 | Cheng Wang | Dynamic optimization for conditional commit |
US20150277914A1 (en) * | 2014-03-27 | 2015-10-01 | John H. Kelm | Lock elision with binary translation based processors |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20040162967A1 (en) * | 2003-02-13 | 2004-08-19 | Marc Tremblay | Start transactional execution (STE) instruction to support transactional program execution |
US20040187123A1 (en) * | 2003-02-13 | 2004-09-23 | Marc Tremblay | Selectively unmarking load-marked cache lines during transactional program execution |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7418577B2 (en) * | 2003-02-13 | 2008-08-26 | Sun Microsystems, Inc. | Fail instruction to support transactional program execution |
-
2006
- 2006-07-21 EP EP06787947A patent/EP1913473A1/en not_active Withdrawn
- 2006-07-21 WO PCT/US2006/028152 patent/WO2007015925A1/en active Application Filing
- 2006-07-21 JP JP2008524994A patent/JP2009508187A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20040162967A1 (en) * | 2003-02-13 | 2004-08-19 | Marc Tremblay | Start transactional execution (STE) instruction to support transactional program execution |
US20040187123A1 (en) * | 2003-02-13 | 2004-09-23 | Marc Tremblay | Selectively unmarking load-marked cache lines during transactional program execution |
Non-Patent Citations (3)
Title |
---|
MOIR M: "Hybrid Hardware / Software Transactional Memory", SLIDES PRESENTED AT THE WORKSHOP ON TRANSACTIONAL SYSTEMS, 8 April 2005 (2005-04-08), CHICAGO, IL, USA, XP002407376, Retrieved from the Internet <URL:http://www.cs.wisc.edu/~rajwar/tm-workshop/TALKS/moir.pdf> [retrieved on 20061114] * |
MOIR M: "Hybrid Transactional Memory", SUN MICROSYSTEMS LABORATORIES PAPER, July 2005 (2005-07-01), XP002407375, Retrieved from the Internet <URL:http://research.sun.com/scalable/pubs/Moir-Hybrid-2005.pdf> [retrieved on 20061114] * |
RAJWAR R ET AL: "Speculative lock elision: enabling highly concurrent multithreaded execution", MICROARCHITECTURE, 2001. MICRO-34. PROCEEDINGS. 34TH ACM/IEEE INTERNATIONAL SYMPOSIUM ON DEC. 1-5, 2001, PISCATAWAY, NJ, USA,IEEE, 1 December 2001 (2001-12-01), pages 294 - 305, XP010583693, ISBN: 0-7965-1369-7 * |
Cited By (28)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2012514254A (en) * | 2008-12-30 | 2012-06-21 | インテル・コーポレーション | Memory model of hardware attributes in a transactional memory system |
US9940138B2 (en) | 2009-04-08 | 2018-04-10 | Intel Corporation | Utilization of register checkpointing mechanism with pointer swapping to resolve multithreading mis-speculations |
US9996360B2 (en) | 2012-06-15 | 2018-06-12 | International Business Machines Corporation | Transaction abort instruction specifying a reason for abort |
US10684863B2 (en) | 2012-06-15 | 2020-06-16 | International Business Machines Corporation | Restricted instructions in transactional execution |
US9772854B2 (en) | 2012-06-15 | 2017-09-26 | International Business Machines Corporation | Selectively controlling instruction execution in transactional processing |
US11080087B2 (en) | 2012-06-15 | 2021-08-03 | International Business Machines Corporation | Transaction begin/end instructions |
US9792125B2 (en) | 2012-06-15 | 2017-10-17 | International Business Machines Corporation | Saving/restoring selected registers in transactional processing |
US9851978B2 (en) | 2012-06-15 | 2017-12-26 | International Business Machines Corporation | Restricted instructions in transactional execution |
US9858082B2 (en) | 2012-06-15 | 2018-01-02 | International Business Machines Corporation | Restricted instructions in transactional execution |
US9740521B2 (en) | 2012-06-15 | 2017-08-22 | International Business Machines Corporation | Constrained transaction execution |
US9983883B2 (en) | 2012-06-15 | 2018-05-29 | International Business Machines Corporation | Transaction abort instruction specifying a reason for abort |
US9983882B2 (en) | 2012-06-15 | 2018-05-29 | International Business Machines Corporation | Selectively controlling instruction execution in transactional processing |
US9983915B2 (en) | 2012-06-15 | 2018-05-29 | International Business Machines Corporation | Facilitating transaction completion subsequent to repeated aborts of the transaction |
US9983881B2 (en) | 2012-06-15 | 2018-05-29 | International Business Machines Corporation | Selectively controlling instruction execution in transactional processing |
US9766925B2 (en) | 2012-06-15 | 2017-09-19 | International Business Machines Corporation | Transactional processing |
US9740549B2 (en) | 2012-06-15 | 2017-08-22 | International Business Machines Corporation | Facilitating transaction completion subsequent to repeated aborts of the transaction |
US10558465B2 (en) | 2012-06-15 | 2020-02-11 | International Business Machines Corporation | Restricted instructions in transactional execution |
US10353759B2 (en) | 2012-06-15 | 2019-07-16 | International Business Machines Corporation | Facilitating transaction completion subsequent to repeated aborts of the transaction |
US10430199B2 (en) | 2012-06-15 | 2019-10-01 | International Business Machines Corporation | Program interruption filtering in transactional execution |
US10437602B2 (en) | 2012-06-15 | 2019-10-08 | International Business Machines Corporation | Program interruption filtering in transactional execution |
US10223214B2 (en) | 2012-06-15 | 2019-03-05 | International Business Machines Corporation | Randomized testing within transactional execution |
US10719415B2 (en) | 2012-06-15 | 2020-07-21 | International Business Machines Corporation | Randomized testing within transactional execution |
US10599435B2 (en) | 2012-06-15 | 2020-03-24 | International Business Machines Corporation | Nontransactional store instruction |
US10606597B2 (en) | 2012-06-15 | 2020-03-31 | International Business Machines Corporation | Nontransactional store instruction |
US10185588B2 (en) | 2012-06-15 | 2019-01-22 | International Business Machines Corporation | Transaction begin/end instructions |
CN107239415B (en) * | 2016-03-28 | 2020-02-14 | 华为技术有限公司 | Method and device for executing critical section operation |
CN107239415A (en) * | 2016-03-28 | 2017-10-10 | 华为技术有限公司 | A kind of method and device for performing critical section operation |
CN114706691A (en) * | 2022-04-15 | 2022-07-05 | 郑州信大捷安信息技术股份有限公司 | Multitask mutual exclusion method and system based on file lock |
Also Published As
Publication number | Publication date |
---|---|
JP2009508187A (en) | 2009-02-26 |
EP1913473A1 (en) | 2008-04-23 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US7389383B2 (en) | Selectively unmarking load-marked cache lines during transactional program execution | |
US7398355B1 (en) | Avoiding locks by transactionally executing critical sections | |
US7818510B2 (en) | Selectively monitoring stores to support transactional program execution | |
US7904664B2 (en) | Selectively monitoring loads to support transactional program execution | |
US6938130B2 (en) | Method and apparatus for delaying interfering accesses from other threads during transactional program execution | |
US7206903B1 (en) | Method and apparatus for releasing memory locations during transactional execution | |
US7500086B2 (en) | Start transactional execution (STE) instruction to support transactional program execution | |
US6862664B2 (en) | Method and apparatus for avoiding locks by speculatively executing critical sections | |
US7930695B2 (en) | Method and apparatus for synchronizing threads on a processor that supports transactional memory | |
WO2007015925A1 (en) | Avoiding locks by transactionally executing critical sections | |
US7617421B2 (en) | Method and apparatus for reporting failure conditions during transactional execution | |
US20040163082A1 (en) | Commit instruction to support transactional program execution | |
US7418577B2 (en) | Fail instruction to support transactional program execution | |
US8065670B2 (en) | Method and apparatus for enabling optimistic program execution |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application | ||
WWE | Wipo information: entry into national phase |
Ref document number: 2006787947 Country of ref document: EP |
|
WWE | Wipo information: entry into national phase |
Ref document number: 2008524994 Country of ref document: JP |
|
NENP | Non-entry into the national phase |
Ref country code: DE |