Speculative execution explained

Speculative execution is an optimization technique where a computer system performs some task that may not be needed. Work is done before it is known whether it is actually needed, so as to prevent a delay that would have to be incurred by doing the work after it is known that it is needed. If it turns out the work was not needed after all, most changes made by the work are reverted and the results are ignored.

The objective is to provide more concurrency if extra resources are available. This approach is employed in a variety of areas, including branch prediction in pipelined processors, value prediction for exploiting value locality, prefetching memory and files, and optimistic concurrency control in database systems.[1] [2] [3]

Speculative multithreading is a special case of speculative execution.

Overview

Modern pipelined microprocessors use speculative execution to reduce the cost of conditional branch instructions using schemes that predict the execution path of a program based on the history of branch executions.[2] In order to improve performance and utilization of computer resources, instructions can be scheduled at a time when it has not yet been determined that the instructions will need to be executed, ahead of a branch.[4]

Variants

Speculative computation was a related earlier concept.[5]

Eager execution

Eager execution is a form of speculative execution where both sides of the conditional branch are executed; however, the results are committed only if the predicate is true. With unlimited resources, eager execution (also known as oracle execution) would in theory provide the same performance as perfect branch prediction. With limited resources, eager execution should be employed carefully, since the number of resources needed grows exponentially with each level of branch executed eagerly.[6]

Predictive execution

See also: Pipeline (computing).

See main article: Branch predictor.

Predictive execution is a form of speculative execution where some outcome is predicted and execution proceeds along the predicted path until the actual result is known. If the prediction is true, the predicted execution is allowed to commit; however, if there is a misprediction, execution has to be unrolled and re-executed. Common forms of this include branch predictors and memory dependence prediction. A generalized form is sometimes referred to as value prediction.[7]

Runahead

Related concepts

Lazy execution

See main article: Lazy evaluation.

Lazy execution is the opposite of eager execution, and does not involve speculation. The incorporation of speculative execution into implementations of the Haskell programming language, a lazy language, is a current research topic. Eager Haskell, a variant of the language, is designed around the idea of speculative execution. A 2003 PhD thesis made GHC support a kind of speculative execution with an abortion mechanism to back out in case of a bad choice called optimistic execution.[8] It was deemed too complicated.[9]

Security vulnerabilities

See also: Transient execution CPU vulnerability.

Starting in 2017, a series of security vulnerabilities were found in the implementations of speculative execution on common processor architectures which effectively enabled an elevation of privileges.

These include:

See also

Notes and References

  1. Lampson . Butler . Butler Lampson . 2006 . Momenzadeh . Mariam . Shvartsman . Alexander A. . Lazy and Speculative Execution in Computer Systems . Principles of Distributed Systems . Lecture Notes in Computer Science . 10th International Conference on Principles of Distributed Systems . en . Bordeaux, France . Springer . 4305 . 1–2 . 10.1007/11945529_1 . 978-3-540-49991-6.
  2. Raghavan. Prabhakar. Shachnai. Hadas. Yaniv. Mira. Dynamic schemes for speculative execution of code. 1998. 10.1109/MASCOT.1998.693711. Proceedings of the Sixth International Symposium on Modeling, Analysis and Simulation of Computer and Telecommunication Systems. IEEE. 309–314. 18 January 2011.
  3. H. T. Kung. H. T. . Kung. John T. Robinson. On optimistic methods for concurrency control. ACM Trans. Database Syst.. 6. 2. June 1981. https://web.archive.org/web/20190831230313/https://apps.dtic.mil/dtic/tr/fulltext/u2/a081452.pdf. live. August 31, 2019.
  4. Book: Bernd Krieg-Brückner. ESOP '92: 4th European Symposium on Programming, Rennes, France, February 26-28, 1992: proceedings. 18 January 2011. 1992. Springer. 978-3-540-55253-6. 56–57.
  5. Book: http://www.hpl.hp.com/techreports/Compaq-DEC/CRL-90-1.html . Speculative Computation in Multilisp . Randy B. Osborne . Parallel Lisp: Languages and Systems . 441 . 103–137 . 1990-03-21 . . . 10.1007/BFb0024152 . 2018-01-26 . Lecture Notes in Computer Science . 3-540-52782-6 . 2017-02-07 . https://web.archive.org/web/20170207033142/http://www.hpl.hp.com/techreports/Compaq-DEC/CRL-90-1.html . dead .
  6. Book: Jurij Šilc. Borut Robič. Theo Ungerer. Processor architecture: from dataflow to superscalar and beyond. registration. 21 January 2011. 1999. Springer. 978-3-540-64798-0. 148–150.
  7. Book: Mark D.. Hill. Norman Jouppi. Norman P.. Jouppi. Gourindar S.. Sohi. Readings in Computer Architecture. 2000. Morgan Kaufman. 5 January 2018. 9781558605398.
  8. Optimistic Evaluation: a fast evaluation strategy for non-strict programs. Simon Peyton. Jones. Robert. Ennals. 1 August 2003. 15 May 2019. www.microsoft.com.
  9. Web site: [Haskell] Optimistic Evaluation? . 31 August 2006 .