Context preservation during thread level speculative execution
OwnerJack Masoninventor
Life of this patent
Estimating the term…
Abstract
A microarchitecture can be configured to allow a thread's speculative state to be stored when the thread is preempted. The stored speculative state can then be loaded back into the microarchitecture when the thread is resumed to thereby enable the thread to resume execution at the speculative state that existed when the thread was preempted. By maintaining the speculative state of threads, a greater amount of parallel processing is achieved.
Claims20
A method for storing a speculative state of a thread that is being executed by a processor in accordance with a thread level speculative execution technique, the method comprising:
- during execution of a thread, executing a first instruction that indicates that the thread is entering into speculative execution, the first instruction including an address of a synchronization variable as an argument of the first function, the synchronization variable representing a first range of shared memory addresses that includes at least one memory address that the thread intends to access during speculative execution, executing the first instruction comprising,
- storing, within the processor, a current state of the thread that exists prior to executing the first instruction;
- creating or updating a first SVT entry in a synchronization variable table, the first SVT entry comprising the address of the synchronization variable, an in-use count, and an SVT handle representing the first SVT entry;
- and
- returning the SVT handle;
- during speculative execution of the thread, maintaining, within the processor, a speculative state of the thread, the speculative state of the thread including a speculative write buffer that includes an entry for each memory address that the thread accesses during speculative execution, the speculative write buffer including a first buffer entry comprising the SVT handle, a particular memory address within the first range of shared memory addresses that was accessed by the first thread, and a value for the particular memory address;
- detecting that the thread will be preempted during speculative execution;
- and
- storing the speculative state to allow the speculative state to be recreated within the processor when execution of the thread is resumed.
A processor comprising:
- an execution unit;
- a plurality of registers for storing values generated by the execution unit;
- a synchronization variable table;
- and
- one or more buffers for storing a speculative state of a thread while the thread is being executed in accordance with a thread level speculative execution technique;
- wherein the processor is configured to perform the following:
- during execution of a thread, executing the first instruction that indicates that the thread is entering into speculative execution, the first instruction including an address of a synchronization variable as an argument of the first function, the synchronization variable representing a first range of shared memory addresses that includes at least one memory address that the thread intends to access during speculative execution, executing the first instruction comprising:
- storing, within the processor, a current state of the thread that exists prior to executing the first instruction;
- creating or updating a first SVT entry in the synchronization variable table, the first SVT entry comprising the address of the synchronization variable, an in-use count, and an SVT handle representing the first SVT entry;
- and
- returning the SVT handle;
- during speculative execution of the thread, maintaining, within the one or more buffers, a speculative state of the thread, the speculative state of the thread including a speculative write buffer that includes an entry for each memory address that the thread accesses during speculative execution, the speculative write buffer including a first buffer entry comprising the SVT handle, a particular memory address within the first range of shared memory addresses that was accessed by the first thread, and a value for the particular memory address;
- detecting that the thread will be preempted during speculative execution;
- and
- writing the speculative state to memory to allow the speculative state to be recreated within the processor when execution of the thread is resumed.
A method for storing a speculative write buffer of a thread when the thread is preempted, the method comprising:
- during execution of a thread, executing a first instruction that indicates that the thread is entering into speculative execution, the first instruction including an address of a synchronization variable as an argument of the first function, the synchronization variable representing a first range of shared memory addresses that includes at least one memory address that the thread intends to access during speculative execution, executing the first instruction comprising:
- storing, within the processor, a current state of the thread that exists prior to executing the first instruction;
- creating or updating a first SVT entry in a synchronization variable table, the first SVT entry comprising the address of the synchronization variable, an in-use count, and
- an SVT handle representing the first SVT entry;
- and
- returning the SVT handle;
- during speculative execution of the thread, maintaining within the processor, a speculative state of the thread, the speculative state of the thread including a speculative write buffer that includes an entry for each memory address that the thread accesses during speculative execution, the speculative write buffer including a first buffer entry comprising the SVT handle, a particular memory address within the first range of shared memory addresses that was accessed by the first thread, and a value for the particular memory address;
- detecting that the thread will be preempted during speculative execution;
- storing the speculative state to allow the speculative state to be recreated within the processor when execution of the thread is resumed;
- resuming execution of the thread by restoring the speculative state;
- executing a second instruction that indicates that the thread is exiting speculative execution, the second instruction including the SVT handle;
- using the SVT handle to access the first SVT entry in the synchronization variable table, the access including decrementing the in-use count;
- after decrementing the in-use count, returning the in-use count;
- determining that the in-use count returned from the execution of the second command indicates that no other threads are still accessing the first range of shared addresses;
- determining whether any data collisions occurred during the speculative execution;
- upon determining that no data collisions occurred, accessing the speculative write buffer to identify any entries which define a value written by the thread to the corresponding memory address during the speculative execution;
- and
- for each identified entry, writing the value in the entry to the corresponding memory address.
Dependencies are inferred from the claim text.