Embodiments of the invention relate to transactional memory; more particularly, embodiments of methods and systems to improve a quiescence process.
Transactional memory simplifies concurrent programming, which has been challenging but crucial in realizing the performance benefit of multi-core processors. Transactional memory allows a group of load and store instructions to execute in an atomic way. Transactional memory also alleviates those pitfalls of lock-based synchronization.
Software transactional memory (STM) provides transactional memory semantics in a software runtime library and requires minimal or no hardware support. An STM may use read and write barriers for shared memory reads and writes in transactional code sections. The read and write barriers allow the runtime system to maintain metadata that are required for data versioning and conflict detection for STM. For example, a write barrier may be a procedure inserted by programmers, a compiler, a middleware, or a runtime system to process every write operation to a shared resource. The write barrier procedure checks and records the lock state of the shared resource. Additionally, the write barrier identifies any conflict over the shared resource and resolves the conflict in accordance with a predefined protocol.
Privatization happens when a transaction (of a process/thread) removes a shared resource or a portion thereof (e.g. memory space) from public access. A transaction privatizes a shared resource so that a thread can use the shared resource in non-transactional instruction(s) later. Other active transactions may also have the reference to the same shared resource especially in a system where an optimistic read is allowed. An active transaction is a transaction in an executing phase, or is in a commit phase but has not validated its read set (rollback may happen). An active transaction may modify the value/state of a shared resource.
A transaction (of a thread) that privatizes the shared resource should wait for these other transactions which use the same shared resource to finish before the thread starts working on the privatized resource. Otherwise, if the transaction does not wait (and the thread proceeds to execute the non-transactional instructions thereafter) while other transactions are still using the same shared resource, this creates a racing condition and the results of the execution become unpredictable.
For example, a link list has element 1 to element 10 in sequence. Transaction A (of thread A) privatizes elements 2-10 (removing them from public access) by assigning the next-pointer of element 1 to null. Transaction B had read the reference to element 2 before the removal of the link. Thread A will operate on elements 2-10 in the following non-transactional section after transaction A completes. To avoid a racing condition for elements 2-10, thread A should wait for transaction B to finish before operating on the privatized resource (elements 2-10).
A quiescence algorithm can be used to guarantee proper execution of the transactions in a system that provides privatization semantics. In such an algorithm, a committing transaction waits in a quiescence phase until all other active transactions validate that their read sets do not overlap with the committing transaction's write set. After exiting the quiescence phase, the transaction safely terminates. The thread proceeds to execute the instructions following thereafter. In some cases, the waiting time for other active transactions to validate, abort, or commit is significant enough to reduce the performance of a system.
Embodiments of the present invention will be understood more fully from the detailed description given below and from the accompanying drawings of various embodiments of the invention, which, however, should not be taken to limit the invention to the specific embodiments, but are for explanation and understanding only.
Embodiments of methods and systems to improve a quiescence process of transactions are described. In one embodiment, a transaction performs validation by comparing a read signature of the transaction to published write signatures associated with committing transactions. The transaction determines, based on a result of the comparison, whether to update its local timestamp to a commit timestamp of another transaction selected from the committing transactions. Accordingly, before a transaction terminates/completes properly, the transaction enters a quiescence phase and waits until all local timestamps of other active transactions are greater than or equal to the commit timestamp of the transaction.
In the following description, numerous details are set forth to provide a more thorough explanation of embodiments of the present invention. It will be apparent, however, to one skilled in the art, that embodiments of the present invention may be practiced without these specific details. In other instances, well-known structures and devices are shown in block diagram form, rather than in detail, in order to avoid obscuring embodiments of the present invention.
Some portions of the detailed descriptions which follow are presented in terms of algorithms and symbolic representations of operations on data bits within a computer memory. These algorithmic descriptions and representations are the means used by those skilled in the data processing arts to most effectively convey the substance of their work to others skilled in the art. An algorithm is here, and generally, conceived to be a self-consistent sequence of steps leading to a desired result. The steps are those requiring physical manipulations of physical quantities. Usually, though not necessarily, these quantities take the form of electrical or magnetic signals capable of being stored, transferred, combined, compared, and otherwise manipulated. It has proven convenient at times, principally for reasons of common usage, to refer to these signals as bits, values, elements, symbols, characters, terms, numbers, or the like.
It should be borne in mind, however, that all of these and similar terms are to be associated with the appropriate physical quantities and are merely convenient labels applied to these quantities. Unless specifically stated otherwise as apparent from the following discussion, it is appreciated that throughout the description, discussions utilizing terms such as “processing” or “computing” or “calculating” or “determining” or “displaying” or the like, refer to the action and processes of a computer system, or similar electronic computing device, that manipulates and transforms data represented as physical (electronic) quantities within the computer system's registers and memories into other data similarly represented as physical quantities within the computer system memories or registers or other such information storage, transmission or display devices.
Embodiments of present invention also relate to apparatuses for performing the operations herein. Some apparatuses may be specially constructed for the required purposes, or it may comprise a general purpose computer selectively activated or reconfigured by a computer program stored in the computer. Such a computer program may be stored in a computer readable storage medium, such as, but not limited to, any type of disk including floppy disks, optical disks, CD-ROMs, DVD-ROMs, and magnetic-optical disks, read-only memories (ROMs), random access memories (RAMs), EPROMs, EEPROMs, NVRAMs, magnetic or optical cards, or any type of media suitable for storing electronic instructions, and each coupled to a computer system bus.
The algorithms and displays presented herein are not inherently related to any particular computer or other apparatus. Various general purpose systems may be used with programs in accordance with the teachings herein, or it may prove convenient to construct more specialized apparatus to perform the required method steps. The required structure for a variety of these systems will appear from the description below. In addition, embodiments of the present invention are not described with reference to any particular programming language. It will be appreciated that a variety of programming languages may be used to implement the teachings of the invention as described herein.
A machine-readable medium includes any mechanism for storing or transmitting information in a form readable by a machine (e.g., a computer). For example, a machine-readable medium includes read only memory (“ROM”); random access memory (“RAM”); magnetic disk storage media; optical storage media; flash memory devices; etc.
In one embodiment, in response to a write barrier for a memory store operation within the transaction, the processing logic tries to exclusively lock a shared resource (memory location). If the shared resource is already locked by another transaction, the runtime will try to resolve the conflict before continuing, which may abort the current transaction. If the shared resource is unlocked, the processing logic will: 1) lock the shared resource, 2) record the current value/state of the share resource in an undo log, and 3) add the shared resource to its write set, and then 4) update the shared resource.
In one embodiment, in response to a read barrier for a memory load operation within the transaction, the processing logic checks if the shared resource (memory location) is locked, but does not try to lock it. In one embodiment, the processing logic reads the value in the location if the memory location is not locked for writing by another transaction. The processing logic will 1) read the value in the location, and 2) add the shared resource to the read set.
In one embodiment, a transaction is ready to commit after the instructions therein have completed. The committing transaction enters a commit phase (processing block 120). The committing transaction validates the read set to ensure that no shared resource in the set has been updated after the transaction read them. If the validation succeeds, the committing transaction unlocks all shared resources in its write set. Otherwise, the committing transaction aborts. On the abort of a transaction, the processing logic restores the old values recorded in the undo log by writing back to the corresponding addresses (a rollback operation) and the shared resources in the write set will be unlocked.
In one embodiment, a compiler inserts a write barrier and a read barrier as system calls in response to a memory store operation and a memory load operation. The operating system loads and executes a runtime library when it encounters the system calls. In one embodiment, the programmers designate write barriers and read barriers at locations deemed suitable for maintaining the read set and the write set of the transaction.
In one embodiment, a reader transaction is a transaction that calls one or more read operations from a shared resource, such as, for example, a load operation reading from a memory location. A reader transaction therefore has a read dependency with respect to the shared resource. In one embodiment, a writer transaction is a transaction that calls one or more write/update operations to a shared resource, such as, for example, a store operation writing to a memory location. A writer transaction has a write dependency with respect to the shared resource. In one embodiment, a transaction can be a writer and a reader with respect to a shared resource. In one embodiment, a transaction is a writer, a reader, or a combination thereof with respect to multiple shared resources.
In one embodiment, read set 203 is a list of shared resources that a transaction has accessed. For example, read set 203 contains a set of shared variables or the memory locations thereof which are read during the transaction. In one embodiment, read set 203 is mapped to read signature 205 using a hash function to reduce the number of bits required to represent the shared resources. In one embodiment, read signature 205 is a bloom filter generated using a combination of hash functions. In one embodiment, read signature 205 is N-bit in length and represents a memory map of a transaction (workload of a transaction). The content of read signature 205 indicates sections of the workload that have been read or not by the transaction. In one embodiment, during a read barrier, a hash function maps a memory address to one or more bit locations of read signature 205.
In one embodiment, write set 204 is a list of shared resources to which a transaction has written. For example, write set 204 contains a set of shared variables or memory locations thereof which are speculatively stored into during the transaction. In one embodiment, a transaction removes a shared resource (during privatization) and the write set of the transaction is updated with the address of the shared resource. In one embodiment, write set 204 is mapped to write signature 206 using a hash function to reduce the number of bits required to represent the shared resources. In one embodiment, write signature 206 is a bloom filter generated with a combination of hash functions. In one embodiment, write signature 206 can be generated from write set 204 using the methods described above with respect to read signature 205. In one embodiment, performing an operation on read signature 205 and write signature 206 is faster than performing a similar operation on read set 203 and write set 204.
In one embodiment, local timestamp 202 indicates the latest timestamp value when the read signature 205 of a transaction is validated against published write signatures of other transactions that are ready to commit.
In one embodiment, when a transaction is ready to commit, the value of a global timestamp (not shown) is increased, commit timestamp 207 of the transaction is updated to the value of the global timestamp. In one embodiment, when a transaction commits or aborts, all tracking information in the data structure is cleared. In one embodiment, if a transaction aborts, information in undo log 208 is used to restore the values/states of shared resources modified by the transaction.
In one embodiment, signature 320 may show a false positive indication but may never show a false negative indication. In other words, a memory location may be indicated as ‘read’ based on the value of signature 320 due to other memory location in the same section has been read. Nevertheless, a memory location is never indicated as ‘not-read’ (indicated with a ‘0’ in the signature 320) if it has in fact been accessed by the transaction.
It will be appreciated by those skilled in the art that many hash functions can be adapted to map a read set to a read signature. In one embodiment, the input to a hash function is the first few bits of a memory address, the last few bits of a memory address, or a combination thereof. In one embodiment, a bloom filter in conjunction with a combination of hash functions can be used to map the information in a read set to a read signature. Similarly, a write signature can be generated based on a write set using the methods described above.
In one embodiment, the processing logic does not update the local timestamp of the current transaction if any intersection with one of the published write signatures is recorded. The local timestamp is updated to the global timestamp only when no intersection exists with any of the published write signatures.
In one embodiment, the processing logic updates the local timestamp of the current transaction to the highest commit timestamp of a committing transaction, and the commit timestamp is lower than commit timestamps of any other intersecting transactions (transactions with write signatures that intersect with the read signature of the current transaction).
For example, in one embodiment, assuming that 5 transactions (A, B, C, D, E) are in-flight. Transaction A is executing and triggers a validation process. Four others transactions (B, C, D, and E) are committing (or validating). Assuming the facts that:
In one embodiment, the processing logic updates the local timestamp of transaction A (after the validation process) to the commit timestamp of transaction E (i.e., 102). The commit stamp is the highest commit timestamp that is lower than any commit stamp(s) of intersecting transaction(s) (transaction D is intersecting; the commit timestamp of transaction D is 103). Transaction A cannot update it local timestamp beyond a commit timestamp that is associated with any intersecting transactions.
In one embodiment, the processing logic publishes the commit timestamp and the write signature of the committing transaction (processing block 503). In one embodiment, the processing logic publishes the information by writing the information to a shared memory space that is accessible by other transactions. In one embodiment, the processing logic notifies other transactions when new information is available. In one embodiment, the processing logic sends a message to notify other transactions about the new information.
In one embodiment, the processing logic switches the committing transaction to a quiescence phase (processing block 504). In one embodiment, the committing transaction waits in the quiescence phase until the local timestamps of all active transactions are greater than or equal to the commit timestamp of the committing transaction (processing block 510). The processing logic switches the committing transaction out from the quiescence phase (the transaction exits the quiescence phase) if the condition is met (processing block 505).
In one embodiment, the active transactions do not include the transactions which are committed or aborted. In one embodiment, a committing transaction that has privatized a shared resource only exits a quiescence phase if all other transactions either: 1) do not read the privatized shared resource at all, 2) may have read the private shared resource but are not longer using the resource (transactions have committed or aborted), or 3) may have read the private shared resource but have a greater or equal local timestamp as compared to the commit time stamp of the committing transaction.
In one embodiment, signature comparison logic 621 performs a comparison between two signatures (a read signature and a write signature) during a validation process. In one embodiment, signature comparison logic 621 comprises an intersection operator. The results from signature comparison logic 621 are sent to conflict record logic 620. In one embodiment, controller 600 in conjunction with conflict record logic 620 determines whether or not to update a local timestamp of a transaction during a validation process.
In one embodiment, when a transaction is ready to commit, controller 600 loads the write signature of the committing transaction to write signature memory 622. In one embodiment, controller 600 also loads other information associated with the committing transaction, for example, the commit time stamp, the write set, and the read set, for other validation mechanisms.
In one embodiment, controller 600 performs other operations related to management of transactions including creating of a new transaction, aborting a transaction, a rollback operation for a transaction, and safely terminating a transaction.
Although described herein as processing logic, each of the logic units can be implemented independently, separately or externally in different combinations.
Embodiments of the invention may be implemented in a variety of electronic devices and logic circuits. Furthermore, devices or circuits that include embodiments of the invention may be included within a variety of shared systems. Embodiments of the invention may also be included in other shared system topologies and architectures.
The main memory 715 may be implemented in various memory sources, such as dynamic random-access memory (DRAM), a hard disk drive (HDD) 720, a solid state disk 725 based on NVRAM technology, or a memory source located remotely from the shared system via network interface 730 or via wireless interface 740 containing various storage devices and technologies. The cache memory may be located either within the processor or in close proximity to the processor, such as on the processor's local bus 707. Furthermore, the cache memory may contain relatively fast memory cells, such as a six-transistor (6T) cell, or other memory cell of approximately equal or faster access speed.
Embodiments of the invention may be implemented within other devices within the system or distributed throughout the system in hardware, software, or some combination thereof. Other embodiments of the invention, however, may exist in other circuits, logic units, or devices within the system of
Whereas many alterations and modifications of the present invention will no doubt become apparent to a person of ordinary skill in the art after having read the foregoing description, it is to be understood that any particular embodiment shown and described by way of illustration is in no way intended to be considered limiting. Therefore, references to details of various embodiments are not intended to limit the scope of the claims which in themselves recite only those features regarded as essential to the invention.