IP Library Granted Patent US 6,862,664
Granted Patent B2
US 6,862,664 · App. 10/439,911 · Granted Mar 1, 2005

Method and apparatus for avoiding locks by speculatively executing critical sections

View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 6,862,664
App. No.
10/439,911
Granted
Mar 1, 2005
Kind
B2
Abstract

One embodiment of the present invention provides a system that facilitates avoiding locks by speculatively executing critical sections of code. During operation, the system allows a process to speculatively execute a critical section of code within a program without first acquiring a lock associated with the critical section. If the process subsequently completes the critical section without encountering an interfering data access from another process, the system commits changes made during the speculative execution, and resumes normal non-speculative execution of the program past the critical section. Otherwise, if an interfering data access from another process is encountered during execution of the critical section, the system discards changes made during the speculative execution, and attempts to re-execute the critical section.

Claims (83)

1. A method for avoiding locks by speculatively executing critical sections of code, comprising:

allowing a process to speculatively execute a critical section of code within a program without first acquiring a lock associated with the critical section;

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 speculative execution, and

resuming normal non-speculative execution of the program past the critical section; and

wherein if an interfering data access from another process is encountered during execution of the critical section, the method further comprises:

discarding changes made during the speculative execution, and

attempting to re-execute the critical section zero or more times;

wherein attemping to re-execute the critical section involves speculatively re-executing the critical section, wherein if the critical section is not successfully completed after a number of attempts at speculative execution, the method further comprises:

acquiring a lock associated with the critical section,

non-speculatively executing the critical section, and

releasing the lock associated with the critical section.

2. The method of claim 1 , wherein data accesses from other processes are allowed to proceed during the speculative execution of he critical section.

3. The method of claim 1 , wherein prior to allowing the process to speculatively execute the critical section, the method further comprises performing a checkpointing operation to checkpoint register values and other state information associated with the process.

4. The method of claim 1 , wherein upon executing a load operation during speculative execution of the critical section, the method further comprises load marking a corresponding cache line.

5. The method of claim 4 , wherein the corresponding cache line is load marked in level 1 (L1) cache.

6. The method of claim 1 , wherein upon executing a store operation during speculative execution of the critical section, the method further comprises:

prefetching the corresponding cache line for exclusive use; and

store marking the corresponding cache line.

7. The method of claim 6 , wherein the corresponding cache line is store marked in the cache level closest to the processor where cache lines are coherent.

8. The method of claim 1 , wherein the interfering data access can include:

a store by another process to a cache line that has been load marked by the process; and

a load or a store by another process to a cache line that has been store marked by the process.

9. The method of claim 1 , wherein prior to executing the critical section, the process performs a checkpointing operation that:

checkpoints an existing processor register file; and

causes a store buffer for the process to become gated, so that the store buffer does not send out stores generated during the speculative execution.

10. The method of claim 1 , wherein committing changes made during speculative execution involves:

treating store-marked cache lines as locked, thereby causing other processes to wait to access the store-marked cache lines;

clearing load marks from cache lines;

committing store buffer entries generated during the execution to memory, wherein committing each store buffer entry involves unmarking, and thereby unlocking, a corresponding cache line; and

committing register file changes made during speculative execution.

11. The method of claim 1 , wherein discarding changes made during the speculative execution involves:

discarding register file changes made during the speculative execution;

clearing load marks from cache lines;

draining store buffer entries generated during the speculative execution; and

clearing store marks from cache lines.

12. An apparatus that avoids locks by speculatively executing critical sections of code, comprising:

a speculative execution mechanism configured to allow a process to speculatively execute a critical section of code within a program without first acquiring a lock associated with the critical section;

a commit mechanism, wherein if the process completes the critical section without encountering an interfering data access from another process, the commit mechanism is configured to:

commit changes made during the speculative execution, and to

resume normal non-speculative execution of the program past the critical section; and

a re-execution mechanism, wherein if an interfering data access from another process is encountered during execution of the critical section, the re-execution mechanism is configured to:

discard changes made during the speculative execution, and to attemp to re-execute the critical section zero or more times;

wherein the re-execution mechanism is configured to speculatively re-execute the critical section, wherein if the critical section is not successfully completed after a number of attempts at speculative execution, the re-execution mechanism is configured to:

acquire a lock associated with the critical section,

non-speculatively execute the critical section, and to

release the lock associated with the critical section.

13. The apparatus of claim 12 , wherein the speculative execution mechanism is configured to allow data accesses from other processes to proceed during the speculative execution of the critical section.

14. The apparatus of claim 12 , further comprising a checkpointing mechanism configured to checkpoint register values and other state information associated with the process prior to allowing the process to speculatively execute the critical section.

15. The apparatus of claim 12 , wherein upon executing a load operation during speculative execution of the critical section, the speculative execution mechanism is configured to load mark a corresponding cache line.

16. The apparatus of claim 15 , wherein the corresponding cache line is load marked in level 1 (L1) cache.

17. The apparatus of claim 12 , wherein upon executing a store operation during speculative execution of the critical section, speculative execution mechanism is configured to:

prefetch the corresponding cache line for exclusive use; and to store mark the corresponding cache line.

18. The apparatus of claim 17 , wherein the corresponding cache line is store marked in the cache level closest to the processor where cache lines are coherent.

19. The apparatus of claim 12 , wherein the interfering data access can include:

a store by another process to a cache line that has been load marked by the process; and

a load or a store by another process to a cache line that has been store marked by the process.

20. The apparatus of claim 12 , further comprising a checkpointing mechanism, wherein prior execution of the critical section, the checkpointing mechanism is configured to:

checkpoint an existing processor register file; and to

configure a store buffer for the process to become gated, so that the store buffer does not send out stores generated during the speculative execution.

21. The apparatus of claim 12 , wherein while committing changes made during speculative execution, the commit mechanism is configured to:

treat store-marked cache lines as locked, thereby causing processes to wait to access the store-marked cache lines;

clear load marks from cache lines;

commit store buffer entries generated during the speculative execution, wherein committing each store buffer entry involves unmarking, and thereby unlocking, a corresponding cache line; and to

commit register file changes made during speculative execution.

22. The apparatus of claim 12 , wherein while discarding changes made during the speculative execution, the commit mechanism is configured to:

discard register file changes made during the speculative execution;

clear load marks from cache lines;

drain store buffer entries generated during the speculative execution; and to

clear store marks from cache lines.

23. A computer system that facilitates avoiding locks by speculatively executing critical sections of code, comprising:

a processor;

a speculative execution mechanism within the processor configured to allow a process to speculatively execute a critical section of code within a program without first acquiring a lock associated with the critical section;

a commit mechanism within the processor, wherein if the process completes the critical section without encountering an interfering data access from another process, the commit mechanism is configured to:

commit changes made during the speculative execution, and to

resume normal non-speculative execution of the program past the critical section; and

a re-execution mechanism within the processor, wherein if an interfering data access from another process is encountered during execution of the critical section, the re-execution mechanism is configured to:

discard changes made during the speculative execution, and to

attempt to re-execute the critical section zero or more times;

wherein the re-execution mechanism is configured to speculatively re-execute the critical section, wherein if the critical section is not successfully completed after a number of attempts at speculative execution, the re-execution mechanism is configured to:

acquire a lock associated with the critical section,

non-speculatively execute the critical section, and to

release the lock associated with the critical section.

Assignments (2)
MERGER AND CHANGE OF NAME Recorded Dec 12, 2015
From: ORACLE USA, INC.; SUN MICROSYSTEMS, INC.; ORACLE AMERICA, INC.
To: ORACLE AMERICA, INC.
Reel/Frame 037278/0877 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded May 16, 2003
From: TREMBLAY, MARC; CHAUDHRY, SHAILENDER; JACOBSON, QUINN A.
To: SUN MICROSYSTEMS, INC.
Reel/Frame 014089/0495 →