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/. */
10 #include <sys/sysctl.h>
11 #include "mozilla/BitSet.h"
13 namespace mozilla::hal_impl
{
15 mozilla::Maybe
<hal::HeterogeneousCpuInfo
> CreateHeterogeneousCpuInfo() {
17 // As of now on Apple Silicon the number of *.logicalcpu_max is the same as
19 size_t len
= sizeof(uint32_t);
21 if (sysctlbyname("hw.perflevel0.logicalcpu_max", &pCores
, &len
, nullptr, 0)) {
25 len
= sizeof(uint32_t);
27 if (sysctlbyname("hw.perflevel1.logicalcpu_max", &eCores
, &len
, nullptr, 0)) {
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
) {
38 info
.mBigCpus
[i
] = true;
41 info
.mLittleCpus
[i
] = true;
53 const Maybe
<hal::HeterogeneousCpuInfo
>& GetHeterogeneousCpuInfo() {
54 static const Maybe
<hal::HeterogeneousCpuInfo
> cpuInfo
=
55 CreateHeterogeneousCpuInfo();
59 } // namespace mozilla::hal_impl