tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HalTypes.h (4531B)


      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/. */
      5 
      6 #ifndef mozilla_hal_Types_h
      7 #define mozilla_hal_Types_h
      8 
      9 #include "ipc/EnumSerializer.h"
     10 #include "mozilla/BitSet.h"
     11 #include "mozilla/Observer.h"
     12 #include "mozilla/TimeStamp.h"
     13 
     14 namespace mozilla {
     15 namespace hal {
     16 
     17 /**
     18 * These constants specify special values for content process IDs.  You can get
     19 * a content process ID by calling ContentChild::GetID() or
     20 * ContentParent::GetChildID().
     21 */
     22 const uint64_t CONTENT_PROCESS_ID_UNKNOWN = uint64_t(-1);
     23 const uint64_t CONTENT_PROCESS_ID_MAIN = 0;
     24 
     25 // Note that we rely on the order of this enum's entries.  Higher priorities
     26 // should have larger int values.
     27 enum ProcessPriority {
     28  PROCESS_PRIORITY_UNKNOWN = -1,
     29  PROCESS_PRIORITY_BACKGROUND,
     30  PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE,
     31  PROCESS_PRIORITY_FOREGROUND_KEYBOARD,
     32  // The special class for the preallocated process, high memory priority but
     33  // low CPU priority.
     34  PROCESS_PRIORITY_PREALLOC,
     35  // Any priority greater than or equal to FOREGROUND is considered
     36  // "foreground" for the purposes of priority testing, for example
     37  // CurrentProcessIsForeground().
     38  PROCESS_PRIORITY_FOREGROUND,
     39  PROCESS_PRIORITY_FOREGROUND_HIGH,
     40  PROCESS_PRIORITY_PARENT_PROCESS,
     41  NUM_PROCESS_PRIORITY
     42 };
     43 
     44 /**
     45 * Convert a ProcessPriority enum value to a string.  The strings returned by
     46 * this function are statically allocated; do not attempt to free one!
     47 *
     48 * If you pass an unknown process priority, we fatally assert in debug
     49 * builds and otherwise return "???".
     50 */
     51 const char* ProcessPriorityToString(ProcessPriority aPriority);
     52 
     53 /**
     54 * Used by ModifyWakeLock
     55 */
     56 enum WakeLockControl {
     57  WAKE_LOCK_REMOVE_ONE = -1,
     58  WAKE_LOCK_NO_CHANGE = 0,
     59  WAKE_LOCK_ADD_ONE = 1,
     60  NUM_WAKE_LOCK
     61 };
     62 
     63 /**
     64 * Represents a workload shared by a group of threads that should be completed
     65 * in a target duration each cycle.
     66 *
     67 * This is created using hal::CreatePerformanceHintSession(). Each cycle, the
     68 * actual work duration should be reported using ReportActualWorkDuration(). The
     69 * system can then adjust the scheduling accordingly in order to achieve the
     70 * target.
     71 */
     72 class PerformanceHintSession {
     73 public:
     74  virtual ~PerformanceHintSession() = default;
     75 
     76  // Updates the session's target work duration for each cycle.
     77  virtual void UpdateTargetWorkDuration(TimeDuration aDuration) = 0;
     78 
     79  // Reports the session's actual work duration for a cycle.
     80  virtual void ReportActualWorkDuration(TimeDuration aDuration) = 0;
     81 };
     82 
     83 /**
     84 * Categorizes the CPUs on the system in to big, medium, and little classes.
     85 *
     86 * A set bit in each bitset indicates that the CPU of that index belongs to that
     87 * class. If the CPUs are fully homogeneous they are all categorized as big. If
     88 * there are only 2 classes, they are categorized as either big or little.
     89 * Finally, if there are >= 3 classes, the remainder will be categorized as
     90 * medium.
     91 *
     92 * If there are more than MAX_CPUS present we are unable to represent this
     93 * information.
     94 */
     95 struct HeterogeneousCpuInfo {
     96  // We use a max of 32 because this was initially implemented only for Android
     97  // where we are unlikely to need more CPUs than that, and it simplifies
     98  // dealing with cpu_set_t as CPU_SETSIZE is 32 on 32-bit Android.
     99  // If there are more than 32 CPU cores, the implementation should try to fill
    100  // first mBigCpus before adding anything to mMediumCpus or mLittleCpus.
    101  static const size_t MAX_CPUS = 32;
    102  size_t mTotalNumCpus;
    103  mozilla::BitSet<MAX_CPUS> mLittleCpus;
    104  mozilla::BitSet<MAX_CPUS> mMediumCpus;
    105  mozilla::BitSet<MAX_CPUS> mBigCpus;
    106 };
    107 
    108 }  // namespace hal
    109 }  // namespace mozilla
    110 
    111 namespace IPC {
    112 
    113 /**
    114 * WakeLockControl serializer.
    115 */
    116 template <>
    117 struct ParamTraits<mozilla::hal::WakeLockControl>
    118    : public ContiguousEnumSerializer<mozilla::hal::WakeLockControl,
    119                                      mozilla::hal::WAKE_LOCK_REMOVE_ONE,
    120                                      mozilla::hal::NUM_WAKE_LOCK> {};
    121 
    122 template <>
    123 struct ParamTraits<mozilla::hal::ProcessPriority>
    124    : public ContiguousEnumSerializer<mozilla::hal::ProcessPriority,
    125                                      mozilla::hal::PROCESS_PRIORITY_UNKNOWN,
    126                                      mozilla::hal::NUM_PROCESS_PRIORITY> {};
    127 
    128 }  // namespace IPC
    129 
    130 #endif  // mozilla_hal_Types_h