[task] Use ThreadType in thread pool sort key [chromium/src : main]

0 views
Skip to first unread message

Etienne Pierre-Doray (Gerrit)

unread,
Feb 5, 2026, 2:44:17 PMFeb 5
to Francois Pierre Doray, Chromium LUCI CQ, chromium...@chromium.org, fdoray...@chromium.org, gab+...@chromium.org, jessemcke...@google.com, roblia...@chromium.org, scheduler...@chromium.org
Attention needed from Francois Pierre Doray

Etienne Pierre-Doray voted and added 1 comment

Votes added by Etienne Pierre-Doray

Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 6 (Latest):
Etienne Pierre-Doray . resolved

PTAL

Open in Gerrit

Related details

Attention is currently required from:
  • Francois Pierre Doray
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I84c327b6bf5084126181a837b7e6d24648e036e5
Gerrit-Change-Number: 7545201
Gerrit-PatchSet: 6
Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
Gerrit-Reviewer: Francois Pierre Doray <fdo...@chromium.org>
Gerrit-Attention: Francois Pierre Doray <fdo...@chromium.org>
Gerrit-Comment-Date: Thu, 05 Feb 2026 19:44:13 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Francois Pierre Doray (Gerrit)

unread,
Feb 6, 2026, 10:19:24 AMFeb 6
to Etienne Pierre-Doray, Chromium LUCI CQ, chromium...@chromium.org, fdoray...@chromium.org, gab+...@chromium.org, jessemcke...@google.com, roblia...@chromium.org, scheduler...@chromium.org
Attention needed from Etienne Pierre-Doray

Francois Pierre Doray voted and added 8 comments

Votes added by Francois Pierre Doray

Code-Review+1

8 comments

Patchset-level comments
Francois Pierre Doray . resolved

LGTM with comments

File base/task/thread_pool/pooled_single_thread_task_runner_manager.cc
Line 199, Patchset 6 (Latest): if (!task_tracker_->WillPostTaskNow(task, sequence->thread_type_racy())) {
Francois Pierre Doray . unresolved

This uses a method with the name "racy" in it, but it's not actually racy because the lock is held (via `transaction`). This is misleading. It would be preferable to use `transaction.thread_type()` here (which is implemented by calling `thread_type_racy()`, but see my other comment there).

File base/task/thread_pool/priority_queue.h
Line 93, Patchset 6 (Latest):
Francois Pierre Doray . unresolved

Document what each index represents in a comment.

Or, actually, I think the code would be more self-explanatory if you simply changes this to 2 distinct variables (num_foreground_task_sources_, num_background_task_sources_), and a simple if/else in DecrementNumTaskSourcesForThreadType/IncrementNumTaskSourcesForThreadType.

File base/task/thread_pool/task_source.h
Line 148, Patchset 6 (Latest): ThreadType thread_type() const { return task_source_->thread_type_racy(); }
Francois Pierre Doray . unresolved

This method is not racy, but it calls a method with "racy" in the name. This is confusing - I have to ask myself why it's valid. I would recommend changing this to:

`return TaskPriorityToThreadType(task_source_->traits_.priority())`

Which requires exposing `TaskPriorityToThreadType`, but I think that's fine. It can be a private static method of TaskSource (I think inner classes have access to private members of outer classes?).

File base/task/thread_pool/thread_group.cc
Line 207, Patchset 6 (Latest): auto priority = priority_queue_.PeekSortKey().thread_type();
Francois Pierre Doray . unresolved

nit: thread_type

Line 231, Patchset 6 (Latest): task_source->thread_type_racy(), task_source->thread_policy());
Francois Pierre Doray . unresolved

Get non-racy thread type from the transaction (see my comment in base/task/thread_pool/task_source.h).

Line 358, Patchset 6 (Latest):void ThreadGroup::HandoffNonUserBlockingTaskSourcesToOtherThreadGroup(
Francois Pierre Doray . unresolved

Update method name.

Line 363, Patchset 6 (Latest): // This works because all USER_BLOCKING tasks are at the front of the queue.
Francois Pierre Doray . unresolved

Update comment.

Open in Gerrit

Related details

Attention is currently required from:
  • Etienne Pierre-Doray
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I84c327b6bf5084126181a837b7e6d24648e036e5
    Gerrit-Change-Number: 7545201
    Gerrit-PatchSet: 6
    Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
    Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
    Gerrit-Reviewer: Francois Pierre Doray <fdo...@chromium.org>
    Gerrit-Attention: Etienne Pierre-Doray <etie...@chromium.org>
    Gerrit-Comment-Date: Fri, 06 Feb 2026 15:19:19 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Etienne Pierre-Doray (Gerrit)

    unread,
    Feb 6, 2026, 12:18:20 PMFeb 6
    to Francois Pierre Doray, Chromium LUCI CQ, chromium...@chromium.org, fdoray...@chromium.org, gab+...@chromium.org, jessemcke...@google.com, roblia...@chromium.org, scheduler...@chromium.org

    Etienne Pierre-Doray voted and added 7 comments

    Votes added by Etienne Pierre-Doray

    Commit-Queue+2

    7 comments

    File base/task/thread_pool/pooled_single_thread_task_runner_manager.cc
    Line 199, Patchset 6: if (!task_tracker_->WillPostTaskNow(task, sequence->thread_type_racy())) {
    Francois Pierre Doray . resolved

    This uses a method with the name "racy" in it, but it's not actually racy because the lock is held (via `transaction`). This is misleading. It would be preferable to use `transaction.thread_type()` here (which is implemented by calling `thread_type_racy()`, but see my other comment there).

    Etienne Pierre-Doray

    Done

    File base/task/thread_pool/priority_queue.h
    Francois Pierre Doray . resolved

    Document what each index represents in a comment.

    Or, actually, I think the code would be more self-explanatory if you simply changes this to 2 distinct variables (num_foreground_task_sources_, num_background_task_sources_), and a simple if/else in DecrementNumTaskSourcesForThreadType/IncrementNumTaskSourcesForThreadType.

    Etienne Pierre-Doray

    Done

    File base/task/thread_pool/task_source.h
    Line 148, Patchset 6: ThreadType thread_type() const { return task_source_->thread_type_racy(); }
    Francois Pierre Doray . resolved

    This method is not racy, but it calls a method with "racy" in the name. This is confusing - I have to ask myself why it's valid. I would recommend changing this to:

    `return TaskPriorityToThreadType(task_source_->traits_.priority())`

    Which requires exposing `TaskPriorityToThreadType`, but I think that's fine. It can be a private static method of TaskSource (I think inner classes have access to private members of outer classes?).

    Etienne Pierre-Doray

    Done here, but in follow-up this will become a bit more complicated:
    thread_type becomes a function of multiple traits and originating thread_type.

    File base/task/thread_pool/thread_group.cc
    Line 207, Patchset 6: auto priority = priority_queue_.PeekSortKey().thread_type();
    Francois Pierre Doray . resolved

    nit: thread_type

    Etienne Pierre-Doray

    Done

    Line 231, Patchset 6: task_source->thread_type_racy(), task_source->thread_policy());
    Francois Pierre Doray . resolved

    Get non-racy thread type from the transaction (see my comment in base/task/thread_pool/task_source.h).

    Etienne Pierre-Doray

    Done

    Line 358, Patchset 6:void ThreadGroup::HandoffNonUserBlockingTaskSourcesToOtherThreadGroup(
    Francois Pierre Doray . resolved

    Update method name.

    Etienne Pierre-Doray

    Done

    Line 363, Patchset 6: // This works because all USER_BLOCKING tasks are at the front of the queue.
    Francois Pierre Doray . resolved

    Update comment.

    Etienne Pierre-Doray

    Done

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I84c327b6bf5084126181a837b7e6d24648e036e5
      Gerrit-Change-Number: 7545201
      Gerrit-PatchSet: 8
      Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
      Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
      Gerrit-Reviewer: Francois Pierre Doray <fdo...@chromium.org>
      Gerrit-Comment-Date: Fri, 06 Feb 2026 17:18:11 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Francois Pierre Doray <fdo...@chromium.org>
      satisfied_requirement
      open
      diffy

      Chromium LUCI CQ (Gerrit)

      unread,
      Feb 6, 2026, 1:21:00 PMFeb 6
      to Etienne Pierre-Doray, Francois Pierre Doray, chromium...@chromium.org, fdoray...@chromium.org, gab+...@chromium.org, jessemcke...@google.com, roblia...@chromium.org, scheduler...@chromium.org

      Chromium LUCI CQ submitted the change with unreviewed changes

      Unreviewed changes

      6 is the latest approved patch-set.
      The change was submitted with unreviewed changes in the following files:

      ```
      The name of the file: base/task/thread_pool/priority_queue.h
      Insertions: 6, Deletions: 8.

      The diff is too large to show. Please review the diff.
      ```
      ```
      The name of the file: base/task/thread_pool/task_source.h
      Insertions: 1, Deletions: 1.

      The diff is too large to show. Please review the diff.
      ```
      ```
      The name of the file: base/task/thread_pool/priority_queue.cc
      Insertions: 14, Deletions: 4.

      The diff is too large to show. Please review the diff.
      ```
      ```
      The name of the file: base/task/thread_pool/thread_group.h
      Insertions: 1, Deletions: 1.

      The diff is too large to show. Please review the diff.
      ```
      ```
      The name of the file: base/task/thread_pool/thread_pool_impl.cc
      Insertions: 2, Deletions: 3.

      The diff is too large to show. Please review the diff.
      ```
      ```
      The name of the file: base/task/thread_pool/task_source.cc
      Insertions: 4, Deletions: 0.

      The diff is too large to show. Please review the diff.
      ```
      ```
      The name of the file: base/task/thread_pool/pooled_single_thread_task_runner_manager.cc
      Insertions: 1, Deletions: 1.

      The diff is too large to show. Please review the diff.
      ```
      ```
      The name of the file: base/task/thread_pool/thread_group.cc
      Insertions: 12, Deletions: 16.

      The diff is too large to show. Please review the diff.
      ```

      Change information

      Commit message:
      [task] Use ThreadType in thread pool sort key

      This CL uses ThreadType to represent task source importance instead of
      task priority.
      In follow-up, this is necessary to represent importance of sequence
      that are posted with ThreadType inheritance, and to create ThreadGroup
      whose importance can't be described by the current TaskPriority.
      Luckily, all existing TaskPriority can be mapped to ThreadType
      so the conversion is not lossy.
      Bug: 470337728
      Change-Id: I84c327b6bf5084126181a837b7e6d24648e036e5
      Commit-Queue: Etienne Pierre-Doray <etie...@chromium.org>
      Reviewed-by: Francois Pierre Doray <fdo...@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#1580950}
      Files:
      • M base/task/post_job.cc
      • M base/task/thread_pool/job_task_source.cc
      • M base/task/thread_pool/pooled_single_thread_task_runner_manager.cc
      • M base/task/thread_pool/priority_queue.cc
      • M base/task/thread_pool/priority_queue.h
      • M base/task/thread_pool/priority_queue_unittest.cc
      • M base/task/thread_pool/sequence.cc
      • M base/task/thread_pool/sequence_unittest.cc
      • M base/task/thread_pool/task_source.cc
      • M base/task/thread_pool/task_source.h
      • M base/task/thread_pool/task_source_sort_key.cc
      • M base/task/thread_pool/task_source_sort_key.h
      • M base/task/thread_pool/task_source_sort_key_unittest.cc
      • M base/task/thread_pool/task_tracker.cc
      • M base/task/thread_pool/task_tracker.h
      • M base/task/thread_pool/thread_group.cc
      • M base/task/thread_pool/thread_group.h
      • M base/task/thread_pool/thread_group_impl.cc
      • M base/task/thread_pool/thread_group_impl_unittest.cc
      • M base/task/thread_pool/thread_group_unittest.cc
      • M base/task/thread_pool/thread_pool_impl.cc
      • M base/task/thread_pool/thread_pool_impl.h
      Change size: L
      Delta: 22 files changed, 243 insertions(+), 234 deletions(-)
      Branch: refs/heads/main
      Submit Requirements:
      • requirement satisfiedCode-Review: +1 by Francois Pierre Doray
      Open in Gerrit
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: merged
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I84c327b6bf5084126181a837b7e6d24648e036e5
      Gerrit-Change-Number: 7545201
      Gerrit-PatchSet: 9
      Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
      Gerrit-Reviewer: Chromium LUCI CQ <chromiu...@luci-project-accounts.iam.gserviceaccount.com>
      Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
      Gerrit-Reviewer: Francois Pierre Doray <fdo...@chromium.org>
      open
      diffy
      satisfied_requirement
      Reply all
      Reply to author
      Forward
      0 new messages