blob: 8e943e18825360db48861d131d75e85e46e257b2 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2018 The Chromium Authors
Leszek Swirski2987cc82018-11-05 15:19:282// 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-Dubois9dbbbda32022-08-26 01:25:319#include "base/feature_list.h"
Etienne Pierre-Dorayd6b575b22018-11-21 19:32:2910#include "base/metrics/field_trial_params.h"
Aditya Keerthia41eda52019-04-01 15:03:2511#include "build/build_config.h"
Leszek Swirski2987cc82018-11-05 15:19:2812
13namespace base {
14
Edgar Arriaga453bcb12023-09-12 23:09:0115// Fixed amount of threads that will be used as a cap for thread pools.
16BASE_EXPORT BASE_DECLARE_FEATURE(kThreadPoolCap2);
Edgar Arriagad096f402023-05-02 15:39:2417
18extern const BASE_EXPORT base::FeatureParam<int> kThreadPoolCapRestrictedCount;
19
Zhibo Wangf8950ab62022-12-09 05:33:4220// Under this feature, a utility_thread_group will be created for
21// running USER_VISIBLE tasks.
22BASE_EXPORT BASE_DECLARE_FEATURE(kUseUtilityThreadGroup);
23
Etienne Pierre-dorayb2895232022-08-30 18:15:0324// Under this feature, worker threads are not reclaimed after a timeout. Rather,
25// only excess workers are cleaned up immediately after finishing a task.
Daniel Cheng0fff5c232022-09-21 17:43:3426BASE_EXPORT BASE_DECLARE_FEATURE(kNoWorkerThreadReclaim);
Francois Doraya20b6df22019-06-27 15:04:1927
Gabriel Charettedfad5992022-10-28 17:57:1728// This feature controls whether ThreadPool WorkerThreads should hold off waking
Kalvin Leec5684a8e2024-03-12 10:45:2429// up to purge PartitionAlloc within the first minute of their lifetime. See
Olivier Li0c5572d2024-02-28 18:52:1030// base::internal::GetSleepDurationBeforePurge.
Gabriel Charettedfad5992022-10-28 17:57:1731BASE_EXPORT BASE_DECLARE_FEATURE(kDelayFirstWorkerWake);
32
Etienne Pierre-doraya8792732022-02-05 02:27:2533// Under this feature, a non-zero leeway is added to delayed tasks. Along with
34// DelayPolicy, this affects the time at which a delayed task runs.
Daniel Cheng0fff5c232022-09-21 17:43:3435BASE_EXPORT BASE_DECLARE_FEATURE(kAddTaskLeewayFeature);
Etienne Pierre-dorayd5cdda492023-07-05 18:20:1436#if BUILDFLAG(IS_WIN)
37constexpr TimeDelta kDefaultLeeway = Milliseconds(16);
38#else
Jiahe Zhang07cf33132022-08-09 09:42:4939constexpr TimeDelta kDefaultLeeway = Milliseconds(8);
Etienne Pierre-dorayd5cdda492023-07-05 18:20:1440#endif // #if !BUILDFLAG(IS_WIN)
Etienne Pierre-doraya8792732022-02-05 02:27:2541extern const BASE_EXPORT base::FeatureParam<TimeDelta> kTaskLeewayParam;
42
Etienne Pierre-doray77474c902023-09-27 20:23:0943// We consider that delayed tasks above |kMaxPreciseDelay| never need
44// DelayPolicy::kPrecise. The default value is slightly above 30Hz timer.
45constexpr TimeDelta kDefaultMaxPreciseDelay = Milliseconds(36);
46extern const BASE_EXPORT base::FeatureParam<TimeDelta> kMaxPreciseDelay;
47
Jiahe Zhang07cf33132022-08-09 09:42:4948// Under this feature, wake ups are aligned at a 8ms boundary when allowed per
Etienne Pierre-doray048472eb2022-02-07 16:24:4849// DelayPolicy.
Daniel Cheng0fff5c232022-09-21 17:43:3450BASE_EXPORT BASE_DECLARE_FEATURE(kAlignWakeUps);
Etienne Pierre-doray048472eb2022-02-07 16:24:4851
Etienne Pierre-doray1f2b04e2023-09-05 20:23:5652// Under this feature, slack is added on mac message pumps that support it when
53// allowed per DelayPolicy.
54BASE_EXPORT BASE_DECLARE_FEATURE(kTimerSlackMac);
55
Etienne Pierre-dorayae2c15a2022-04-29 18:50:5956// Under this feature, tasks that need high resolution timer are determined
57// based on explicit DelayPolicy rather than based on a threshold.
Daniel Cheng0fff5c232022-09-21 17:43:3458BASE_EXPORT BASE_DECLARE_FEATURE(kExplicitHighResolutionTimerWin);
Etienne Pierre-dorayae2c15a2022-04-29 18:50:5959
Sean Maherbff1adc2024-04-10 20:33:4360// Under this feature, the Windows UI pump uses a WaitableEvent to wake itself
61// up when not in a native nested loop. It also uses different control flow,
62// calling Win32 MessagePump functions less often.
63BASE_EXPORT BASE_DECLARE_FEATURE(kUIPumpImprovementsWin);
64
Alex Attar9fcc01e2022-05-20 14:01:2765// Feature to run tasks by batches before pumping out messages.
Daniel Cheng0fff5c232022-09-21 17:43:3466BASE_EXPORT BASE_DECLARE_FEATURE(kRunTasksByBatches);
Alex Attar9fcc01e2022-05-20 14:01:2767
Etienne Pierre-doraye9957c9c2023-03-15 20:54:1668// Controls the max number of delayed tasks that can run before selecting an
69// immediate task in sequence manager.
70BASE_EXPORT BASE_DECLARE_FEATURE(kMaxDelayedStarvationTasks);
71extern const BASE_EXPORT base::FeatureParam<int>
72 kMaxDelayedStarvationTasksParam;
73
Sean Mahereabe41ee2024-01-30 21:43:2374// Feature to use ThreadGroupSemaphore instead of ThreadGroupImpl.
75BASE_EXPORT BASE_DECLARE_FEATURE(kThreadGroupSemaphore);
76extern const BASE_EXPORT base::FeatureParam<int> kMaxNumWorkersCreated;
77
Leszek Swirski2987cc82018-11-05 15:19:2878} // namespace base
79
80#endif // BASE_TASK_TASK_FEATURES_H_