File: background_thread_pool_field_trial.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (91 lines) | stat: -rw-r--r-- 3,070 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_ANDROID_BACKGROUND_THREAD_POOL_FIELD_TRIAL_H_
#define BASE_ANDROID_BACKGROUND_THREAD_POOL_FIELD_TRIAL_H_

#include <optional>
#include <string_view>

#include "base/auto_reset.h"
#include "base/base_export.h"
#include "base/synchronization/synchronization_buildflags.h"

namespace base::android {

class BASE_EXPORT BackgroundThreadPoolFieldTrial {
 public:
  static void Initialize();

  // Returns true if the background thread pool field trial is active and has
  // requested the use of priority-inheritance locks.
  static bool ShouldUsePriorityInheritanceLocks();

  // Returns true if the background thread pool field trial is active and has
  // requested the use of background thread pool.
  static bool ShouldUseBackgroundThreadPool();

  struct BASE_EXPORT TrialInfo {
    std::string trial_name;
    std::string group_name;
  };

  // Returns a non-null TrialInfo struct if the trial is active.
  static std::optional<TrialInfo> GetTrialInfo();

 protected:
  // The configuration value dictates the trial and group currently active. It
  // is
  // set by the server-side config and applied on the next browser launch.
  enum class Configuration : int {
    // |kDisabled|: No trial is currently active.
    kDisabled = 0,

    // The PI supported trial groups requires the kernel to support priority
    // inheritance futexes. It is intended
    // to measure the effect of PI-locks along with the background thread pool.
    kPISupportedTrialControl = 1,
    kPISupportedTrialEnabledPILocksOnly = 2,
    kPISupportedTrialEnabledBGThreadPoolOnly = 3,
    kPISupportedTrialEnabledBoth = 4,

    // The general trial does not require any special kernel support and is
    // meant
    // to measure the effect of
    // using a background thread pool unconditionally.
    kGeneralTrialControl = 5,
    kGeneralTrialEnabledBGThreadPool = 6,

    // |kConfigurationMax|: The maximum integer value of the configuration.
    kConfigurationMax = kGeneralTrialEnabledBGThreadPool,
  };

  friend class ScopedUsePriorityInheritanceLocksForTesting;

  static std::optional<Configuration> s_configuration_;

 private:
  static Configuration ReadConfigurationFromCommandLine();
  static Configuration GetConfiguration();
  static TrialInfo GetGeneralTrialInfo();
#if BUILDFLAG(ENABLE_MUTEX_PRIORITY_INHERITANCE)
  static TrialInfo GetPISupportedTrialInfo();
#endif  // BUILDFLAG(ENABLE_MUTEX_PRIORITY_INHERITANCE)
};

#if BUILDFLAG(ENABLE_MUTEX_PRIORITY_INHERITANCE)
class BASE_EXPORT ScopedUsePriorityInheritanceLocksForTesting {
 public:
  ScopedUsePriorityInheritanceLocksForTesting();
  ~ScopedUsePriorityInheritanceLocksForTesting();

 private:
  base::AutoReset<std::optional<BackgroundThreadPoolFieldTrial::Configuration>>
      reset_config_value_;
};
#endif  // BUILDFLAG(ENABLE_MUTEX_PRIORITY_INHERITANCE)

}  // namespace base::android

#endif  // BASE_ANDROID_BACKGROUND_THREAD_POOL_FIELD_TRIAL_H_