summaryrefslogtreecommitdiffstats
path: root/hal/cocoa/CocoaHeterogeneousCpuInfo.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /hal/cocoa/CocoaHeterogeneousCpuInfo.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'hal/cocoa/CocoaHeterogeneousCpuInfo.cpp')
-rw-r--r--hal/cocoa/CocoaHeterogeneousCpuInfo.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/hal/cocoa/CocoaHeterogeneousCpuInfo.cpp b/hal/cocoa/CocoaHeterogeneousCpuInfo.cpp
new file mode 100644
index 0000000000..065a25b930
--- /dev/null
+++ b/hal/cocoa/CocoaHeterogeneousCpuInfo.cpp
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+#include "Hal.h"
+#include "HalTypes.h"
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include "mozilla/BitSet.h"
+
+namespace mozilla::hal_impl {
+
+mozilla::Maybe<hal::HeterogeneousCpuInfo> CreateHeterogeneousCpuInfo() {
+#ifdef __aarch64__
+ // As of now on Apple Silicon the number of *.logicalcpu_max is the same as
+ // *.physicalcpu_max.
+ size_t len = sizeof(uint32_t);
+ uint32_t pCores = 0;
+ if (sysctlbyname("hw.perflevel0.logicalcpu_max", &pCores, &len, nullptr, 0)) {
+ return Nothing();
+ }
+
+ len = sizeof(uint32_t);
+ uint32_t eCores = 0;
+ if (sysctlbyname("hw.perflevel1.logicalcpu_max", &eCores, &len, nullptr, 0)) {
+ return Nothing();
+ }
+
+ hal::HeterogeneousCpuInfo info;
+ info.mTotalNumCpus = pCores + eCores;
+
+ // The API has currently a limit how many cpu cores it can tell about.
+ for (uint32_t i = 0; i < hal::HeterogeneousCpuInfo::MAX_CPUS; ++i) {
+ if (pCores) {
+ --pCores;
+ info.mBigCpus[i] = true;
+ } else if (eCores) {
+ --eCores;
+ info.mLittleCpus[i] = true;
+ } else {
+ break;
+ }
+ }
+
+ return Some(info);
+#else
+ return Nothing();
+#endif
+}
+
+const Maybe<hal::HeterogeneousCpuInfo>& GetHeterogeneousCpuInfo() {
+ static const Maybe<hal::HeterogeneousCpuInfo> cpuInfo =
+ CreateHeterogeneousCpuInfo();
+ return cpuInfo;
+}
+
+} // namespace mozilla::hal_impl