Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_TASK_TASK_FEATURES_H_ |
| 6 | #define BASE_TASK_TASK_FEATURES_H_ |
| 7 | |
| 8 | #include "base/base_export.h" |
Anthony Vallee-Dubois | 9dbbbda3 | 2022-08-26 01:25:31 | [diff] [blame] | 9 | #include "base/feature_list.h" |
Etienne Pierre-Doray | d6b575b2 | 2018-11-21 19:32:29 | [diff] [blame] | 10 | #include "base/metrics/field_trial_params.h" |
Aditya Keerthi | a41eda5 | 2019-04-01 15:03:25 | [diff] [blame] | 11 | #include "build/build_config.h" |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 12 | |
| 13 | namespace base { |
| 14 | |
Edgar Arriaga | d096f40 | 2023-05-02 15:39:24 | [diff] [blame^] | 15 | // Amount of threads that will be system-wide restricted from being used |
| 16 | // by thread pools. |
| 17 | BASE_EXPORT BASE_DECLARE_FEATURE(kThreadPoolCap); |
| 18 | |
| 19 | extern const BASE_EXPORT base::FeatureParam<int> kThreadPoolCapRestrictedCount; |
| 20 | |
Zhibo Wang | f8950ab6 | 2022-12-09 05:33:42 | [diff] [blame] | 21 | // Under this feature, a utility_thread_group will be created for |
| 22 | // running USER_VISIBLE tasks. |
| 23 | BASE_EXPORT BASE_DECLARE_FEATURE(kUseUtilityThreadGroup); |
| 24 | |
Etienne Pierre-doray | b289523 | 2022-08-30 18:15:03 | [diff] [blame] | 25 | // Under this feature, worker threads are not reclaimed after a timeout. Rather, |
| 26 | // only excess workers are cleaned up immediately after finishing a task. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 27 | BASE_EXPORT BASE_DECLARE_FEATURE(kNoWorkerThreadReclaim); |
Francois Doray | a20b6df2 | 2019-06-27 15:04:19 | [diff] [blame] | 28 | |
Patrick Monette | 6497eae | 2022-08-09 17:59:58 | [diff] [blame] | 29 | // This feature controls whether wake ups are possible for canceled tasks. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 30 | BASE_EXPORT BASE_DECLARE_FEATURE(kNoWakeUpsForCanceledTasks); |
Patrick Monette | 6497eae | 2022-08-09 17:59:58 | [diff] [blame] | 31 | |
Patrick Monette | eaaa238 | 2021-12-08 17:06:59 | [diff] [blame] | 32 | // Controls whether or not canceled delayed tasks are removed from task queues. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 33 | BASE_EXPORT BASE_DECLARE_FEATURE(kRemoveCanceledTasksInTaskQueue); |
Patrick Monette | eaaa238 | 2021-12-08 17:06:59 | [diff] [blame] | 34 | |
Patrick Monette | 4efba9c | 2022-08-18 16:41:32 | [diff] [blame] | 35 | // This feature controls whether or not the scheduled task is always abandoned |
| 36 | // when a timer is stopped or reset. The re-use of the scheduled task is an |
| 37 | // optimization that ensures a timer can not leave multiple canceled tasks in |
| 38 | // the task queue. Meant to be used in conjunction with |
| 39 | // kRemoveCanceledTasksInTaskQueue. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 40 | BASE_EXPORT BASE_DECLARE_FEATURE(kAlwaysAbandonScheduledTask); |
Patrick Monette | 4efba9c | 2022-08-18 16:41:32 | [diff] [blame] | 41 | |
Gabriel Charette | dfad599 | 2022-10-28 17:57:17 | [diff] [blame] | 42 | // This feature controls whether ThreadPool WorkerThreads should hold off waking |
| 43 | // up to purge partition alloc within the first minute of their lifetime. See |
| 44 | // base::internal::GetSleepTimeBeforePurge. |
| 45 | BASE_EXPORT BASE_DECLARE_FEATURE(kDelayFirstWorkerWake); |
| 46 | |
Etienne Pierre-doray | a879273 | 2022-02-05 02:27:25 | [diff] [blame] | 47 | // Under this feature, a non-zero leeway is added to delayed tasks. Along with |
| 48 | // DelayPolicy, this affects the time at which a delayed task runs. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 49 | BASE_EXPORT BASE_DECLARE_FEATURE(kAddTaskLeewayFeature); |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 50 | constexpr TimeDelta kDefaultLeeway = Milliseconds(8); |
Etienne Pierre-doray | a879273 | 2022-02-05 02:27:25 | [diff] [blame] | 51 | extern const BASE_EXPORT base::FeatureParam<TimeDelta> kTaskLeewayParam; |
| 52 | |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 53 | // Under this feature, wake ups are aligned at a 8ms boundary when allowed per |
Etienne Pierre-doray | 048472eb | 2022-02-07 16:24:48 | [diff] [blame] | 54 | // DelayPolicy. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 55 | BASE_EXPORT BASE_DECLARE_FEATURE(kAlignWakeUps); |
Etienne Pierre-doray | 048472eb | 2022-02-07 16:24:48 | [diff] [blame] | 56 | |
Etienne Pierre-doray | ae2c15a | 2022-04-29 18:50:59 | [diff] [blame] | 57 | // Under this feature, tasks that need high resolution timer are determined |
| 58 | // based on explicit DelayPolicy rather than based on a threshold. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 59 | BASE_EXPORT BASE_DECLARE_FEATURE(kExplicitHighResolutionTimerWin); |
Etienne Pierre-doray | ae2c15a | 2022-04-29 18:50:59 | [diff] [blame] | 60 | |
Alex Attar | 9fcc01e | 2022-05-20 14:01:27 | [diff] [blame] | 61 | // Feature to run tasks by batches before pumping out messages. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 62 | BASE_EXPORT BASE_DECLARE_FEATURE(kRunTasksByBatches); |
Alex Attar | 9fcc01e | 2022-05-20 14:01:27 | [diff] [blame] | 63 | |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 64 | BASE_EXPORT void InitializeTaskLeeway(); |
Jiahe Zhang | ce46f4cb | 2022-11-22 03:12:02 | [diff] [blame] | 65 | BASE_EXPORT TimeDelta GetTaskLeewayForCurrentThread(); |
| 66 | BASE_EXPORT TimeDelta GetDefaultTaskLeeway(); |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 67 | |
Etienne Pierre-doray | e9957c9c | 2023-03-15 20:54:16 | [diff] [blame] | 68 | // Controls the max number of delayed tasks that can run before selecting an |
| 69 | // immediate task in sequence manager. |
| 70 | BASE_EXPORT BASE_DECLARE_FEATURE(kMaxDelayedStarvationTasks); |
| 71 | extern const BASE_EXPORT base::FeatureParam<int> |
| 72 | kMaxDelayedStarvationTasksParam; |
| 73 | |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 74 | } // namespace base |
| 75 | |
| 76 | #endif // BASE_TASK_TASK_FEATURES_H_ |