SequenceManager: Introduce TaskOrder as on ordering on ready tasks

This CL fixes an ordering issue where ready delayed tasks with the same
priority might not be ordered by delayed run time across tasks queues.
This could happen as a result how we assign EnqueueOrders during
wake-ups. We previously fixed this by sorting ready delayed tasks by
delayed run time across task queues prior to assigning their
EnqueueOrder (crrev.com/c/3213629), but reverted the change due TaskOrder
performance overhead. This CL attempts to achieve the same result more
efficiently.

To achieve the desired ordering for delayed tasks, this CL introduces a
new abstraction, TaskOrder, which replaces EnqueueOrder as the key in
in WorkQueueSets. TaskOrder is a 3-tuple of (enqueue order, delayed run
time, and sequence number (posting order)), which can be obtained from
a task via `task.task_order()`. TaskOrder has the following properties:

 1. task1.enqueue_order() < task2.enqueue_order() =>
    task1.task_order() < task2.task_order().

 2. If task1.enqueue_order() == task2.enqueue_order(), then
    task1.task_order() < task2.task_order() iff task1 < task2 (i.e.
    by comparing delayed_run_time and sequence_num in the same way
    we do for PendingTasks).

All ready delayed tasks enqueued during a wake-up are assigned the same
EnqueueOrder, so ordering between then is decided by their delayed run
times and sequence numbers.

This CL also changes fences to use TaskOrder instead of EnqueueOrder.
For delayed fences activated during wake-ups, we previously would use a
unique enqueue order within the range of enqueue orders assigned to
ready delayed tasks during a wake-up. But since all such tasks now use
the same enqueue order, this is no longer possible. Instead, we use the
TaskOrder corresponding to first delayed task past the delayed fence.
We also create a Fence subclass of TaskOrder with functionality for
blocking fences to separate it from TaskOrder.

This also adds unit tests for TaskOrder as well as new test cases for
WorkQueueSets and WorkQueue.

Bug: 1249857
Change-Id: I1a0d57e3bbf75c7d371d67509710bcd19d7df306
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3290327
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Reviewed-by: Alexander Timin <altimin@chromium.org>
Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/main@{#948220}
22 files changed
tree: 437be34e12d2284aa837d92cb6370028706f3462
  1. android_webview/
  2. apps/
  3. ash/
  4. base/
  5. build/
  6. build_overrides/
  7. buildtools/
  8. cc/
  9. chrome/
  10. chromecast/
  11. chromeos/
  12. cloud_print/
  13. codelabs/
  14. components/
  15. content/
  16. courgette/
  17. crypto/
  18. dbus/
  19. device/
  20. docs/
  21. extensions/
  22. fuchsia/
  23. gin/
  24. google_apis/
  25. google_update/
  26. gpu/
  27. headless/
  28. infra/
  29. ios/
  30. ipc/
  31. jingle/
  32. media/
  33. mojo/
  34. native_client_sdk/
  35. net/
  36. pdf/
  37. ppapi/
  38. printing/
  39. remoting/
  40. rlz/
  41. sandbox/
  42. services/
  43. skia/
  44. sql/
  45. storage/
  46. styleguide/
  47. testing/
  48. third_party/
  49. tools/
  50. ui/
  51. url/
  52. weblayer/
  53. .clang-format
  54. .clang-tidy
  55. .eslintrc.js
  56. .git-blame-ignore-revs
  57. .gitattributes
  58. .gitignore
  59. .gn
  60. .mailmap
  61. .rustfmt.toml
  62. .vpython
  63. .vpython3
  64. .yapfignore
  65. AUTHORS
  66. BUILD.gn
  67. CODE_OF_CONDUCT.md
  68. codereview.settings
  69. DEPS
  70. DIR_METADATA
  71. ENG_REVIEW_OWNERS
  72. LICENSE
  73. LICENSE.chromium_os
  74. OWNERS
  75. PRESUBMIT.py
  76. PRESUBMIT_test.py
  77. PRESUBMIT_test_mocks.py
  78. README.md
  79. WATCHLISTS
README.md

Logo Chromium

Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all users to experience the web.

The project's web site is https://www.chromium.org.

To check out the source code locally, don't use git clone! Instead, follow the instructions on how to get the code.

Documentation in the source is rooted in docs/README.md.

Learn how to Get Around the Chromium Source Code Directory Structure .

For historical reasons, there are some small top level directories. Now the guidance is that new top level directories are for product (e.g. Chrome, Android WebView, Ash). Even if these products have multiple executables, the code should be in subdirectories of the product.

If you found a bug, please file it at https://crbug.com/new.