150
|
1 //===-------- `Benchmark` function ----------------------------------------===//
|
|
2 //
|
|
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
4 // See https://llvm.org/LICENSE.txt for license information.
|
|
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
6 //
|
|
7 //===----------------------------------------------------------------------===//
|
|
8
|
|
9 #include "LibcBenchmark.h"
|
|
10 #include "llvm/Support/Host.h"
|
|
11
|
|
12 namespace llvm {
|
|
13 namespace libc_benchmarks {
|
|
14
|
|
15 void checkRequirements() {
|
|
16 const auto &CpuInfo = benchmark::CPUInfo::Get();
|
|
17 if (CpuInfo.scaling_enabled)
|
|
18 report_fatal_error(
|
|
19 "CPU scaling is enabled, the benchmark real time measurements may be "
|
|
20 "noisy and will incur extra overhead.");
|
|
21 }
|
|
22
|
|
23 HostState HostState::get() {
|
|
24 const auto &CpuInfo = benchmark::CPUInfo::Get();
|
|
25 HostState H;
|
|
26 H.CpuFrequency = CpuInfo.cycles_per_second;
|
|
27 H.CpuName = llvm::sys::getHostCPUName().str();
|
|
28 for (const auto &BenchmarkCacheInfo : CpuInfo.caches) {
|
|
29 CacheInfo CI;
|
|
30 CI.Type = BenchmarkCacheInfo.type;
|
|
31 CI.Level = BenchmarkCacheInfo.level;
|
|
32 CI.Size = BenchmarkCacheInfo.size;
|
|
33 CI.NumSharing = BenchmarkCacheInfo.num_sharing;
|
|
34 H.Caches.push_back(std::move(CI));
|
|
35 }
|
|
36 return H;
|
|
37 }
|
|
38
|
|
39 } // namespace libc_benchmarks
|
|
40 } // namespace llvm
|