Bug 1822393 - Consume GeckoView directly in Android Components for CI builds. r=owlis...
[gecko.git] / hal / cocoa / CocoaHeterogeneousCpuInfo.cpp
blob065a25b930f36a7653ff4eeb25df3924fc386d46
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #include "Hal.h"
8 #include "HalTypes.h"
9 #include <sys/types.h>
10 #include <sys/sysctl.h>
11 #include "mozilla/BitSet.h"
13 namespace mozilla::hal_impl {
15 mozilla::Maybe<hal::HeterogeneousCpuInfo> CreateHeterogeneousCpuInfo() {
16 #ifdef __aarch64__
17 // As of now on Apple Silicon the number of *.logicalcpu_max is the same as
18 // *.physicalcpu_max.
19 size_t len = sizeof(uint32_t);
20 uint32_t pCores = 0;
21 if (sysctlbyname("hw.perflevel0.logicalcpu_max", &pCores, &len, nullptr, 0)) {
22 return Nothing();
25 len = sizeof(uint32_t);
26 uint32_t eCores = 0;
27 if (sysctlbyname("hw.perflevel1.logicalcpu_max", &eCores, &len, nullptr, 0)) {
28 return Nothing();
31 hal::HeterogeneousCpuInfo info;
32 info.mTotalNumCpus = pCores + eCores;
34 // The API has currently a limit how many cpu cores it can tell about.
35 for (uint32_t i = 0; i < hal::HeterogeneousCpuInfo::MAX_CPUS; ++i) {
36 if (pCores) {
37 --pCores;
38 info.mBigCpus[i] = true;
39 } else if (eCores) {
40 --eCores;
41 info.mLittleCpus[i] = true;
42 } else {
43 break;
47 return Some(info);
48 #else
49 return Nothing();
50 #endif
53 const Maybe<hal::HeterogeneousCpuInfo>& GetHeterogeneousCpuInfo() {
54 static const Maybe<hal::HeterogeneousCpuInfo> cpuInfo =
55 CreateHeterogeneousCpuInfo();
56 return cpuInfo;
59 } // namespace mozilla::hal_impl