Bug 1869092 - Fix timeouts in browser_PanelMultiView.js. r=twisniewski,test-only
[gecko.git] / hal / HalTypes.h
blob912e4c12bb5b5cd012dae3b07009e704ee50951a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_hal_Types_h
7 #define mozilla_hal_Types_h
9 #include "ipc/EnumSerializer.h"
10 #include "mozilla/BitSet.h"
11 #include "mozilla/Observer.h"
12 #include "mozilla/TimeStamp.h"
13 #include "mozilla/UniquePtr.h"
15 namespace mozilla {
16 namespace hal {
18 /**
19 * These constants specify special values for content process IDs. You can get
20 * a content process ID by calling ContentChild::GetID() or
21 * ContentParent::GetChildID().
23 const uint64_t CONTENT_PROCESS_ID_UNKNOWN = uint64_t(-1);
24 const uint64_t CONTENT_PROCESS_ID_MAIN = 0;
26 // Note that we rely on the order of this enum's entries. Higher priorities
27 // should have larger int values.
28 enum ProcessPriority {
29 PROCESS_PRIORITY_UNKNOWN = -1,
30 PROCESS_PRIORITY_BACKGROUND,
31 PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE,
32 PROCESS_PRIORITY_FOREGROUND_KEYBOARD,
33 // The special class for the preallocated process, high memory priority but
34 // low CPU priority.
35 PROCESS_PRIORITY_PREALLOC,
36 // Any priority greater than or equal to FOREGROUND is considered
37 // "foreground" for the purposes of priority testing, for example
38 // CurrentProcessIsForeground().
39 PROCESS_PRIORITY_FOREGROUND,
40 PROCESS_PRIORITY_FOREGROUND_HIGH,
41 PROCESS_PRIORITY_PARENT_PROCESS,
42 NUM_PROCESS_PRIORITY
45 /**
46 * Convert a ProcessPriority enum value to a string. The strings returned by
47 * this function are statically allocated; do not attempt to free one!
49 * If you pass an unknown process priority, we fatally assert in debug
50 * builds and otherwise return "???".
52 const char* ProcessPriorityToString(ProcessPriority aPriority);
54 /**
55 * Used by ModifyWakeLock
57 enum WakeLockControl {
58 WAKE_LOCK_REMOVE_ONE = -1,
59 WAKE_LOCK_NO_CHANGE = 0,
60 WAKE_LOCK_ADD_ONE = 1,
61 NUM_WAKE_LOCK
64 /**
65 * Represents a workload shared by a group of threads that should be completed
66 * in a target duration each cycle.
68 * This is created using hal::CreatePerformanceHintSession(). Each cycle, the
69 * actual work duration should be reported using ReportActualWorkDuration(). The
70 * system can then adjust the scheduling accordingly in order to achieve the
71 * target.
73 class PerformanceHintSession {
74 public:
75 virtual ~PerformanceHintSession() = default;
77 // Updates the session's target work duration for each cycle.
78 virtual void UpdateTargetWorkDuration(TimeDuration aDuration) = 0;
80 // Reports the session's actual work duration for a cycle.
81 virtual void ReportActualWorkDuration(TimeDuration aDuration) = 0;
84 /**
85 * Categorizes the CPUs on the system in to big, medium, and little classes.
87 * A set bit in each bitset indicates that the CPU of that index belongs to that
88 * class. If the CPUs are fully homogeneous they are all categorized as big. If
89 * there are only 2 classes, they are categorized as either big or little.
90 * Finally, if there are >= 3 classes, the remainder will be categorized as
91 * medium.
93 * If there are more than MAX_CPUS present we are unable to represent this
94 * information.
96 struct HeterogeneousCpuInfo {
97 // We use a max of 32 because currently this is only implemented for Android
98 // where we are unlikely to need more CPUs than that, and it simplifies
99 // dealing with cpu_set_t as CPU_SETSIZE is 32 on 32-bit Android.
100 static const size_t MAX_CPUS = 32;
101 size_t mTotalNumCpus;
102 mozilla::BitSet<MAX_CPUS> mLittleCpus;
103 mozilla::BitSet<MAX_CPUS> mMediumCpus;
104 mozilla::BitSet<MAX_CPUS> mBigCpus;
107 } // namespace hal
108 } // namespace mozilla
110 namespace IPC {
113 * WakeLockControl serializer.
115 template <>
116 struct ParamTraits<mozilla::hal::WakeLockControl>
117 : public ContiguousEnumSerializer<mozilla::hal::WakeLockControl,
118 mozilla::hal::WAKE_LOCK_REMOVE_ONE,
119 mozilla::hal::NUM_WAKE_LOCK> {};
121 template <>
122 struct ParamTraits<mozilla::hal::ProcessPriority>
123 : public ContiguousEnumSerializer<mozilla::hal::ProcessPriority,
124 mozilla::hal::PROCESS_PRIORITY_UNKNOWN,
125 mozilla::hal::NUM_PROCESS_PRIORITY> {};
127 } // namespace IPC
129 #endif // mozilla_hal_Types_h