Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
721c9224
Commit
721c9224
authored
Oct 08, 2016
by
Eric Fiselier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix getting the CPU frequency on OS X
parent
f67ee4ad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
21 deletions
+16
-21
sysinfo.cc
src/sysinfo.cc
+16
-21
No files found.
src/sysinfo.cc
View file @
721c9224
...
@@ -280,29 +280,24 @@ void InitializeSystemInfo() {
...
@@ -280,29 +280,24 @@ void InitializeSystemInfo() {
// group
// group
#elif defined BENCHMARK_OS_MACOSX
#elif defined BENCHMARK_OS_MACOSX
// returning "mach time units" per second. the current number of elapsed
int32_t
num_cpus
=
0
;
// mach time units can be found by calling uint64 mach_absolute_time();
// while not as precise as actual CPU cycles, it is accurate in the face
// of CPU frequency scaling and multi-cpu/core machines.
// Our mac users have these types of machines, and accuracy
// (i.e. correctness) trumps precision.
// See cycleclock.h: CycleClock::Now(), which returns number of mach time
// units on Mac OS X.
mach_timebase_info_data_t
timebase_info
;
mach_timebase_info
(
&
timebase_info
);
double
mach_time_units_per_nanosecond
=
static_cast
<
double
>
(
timebase_info
.
denom
)
/
static_cast
<
double
>
(
timebase_info
.
numer
);
cpuinfo_cycles_per_second
=
mach_time_units_per_nanosecond
*
1e9
;
int
num_cpus
=
0
;
size_t
size
=
sizeof
(
num_cpus
);
size_t
size
=
sizeof
(
num_cpus
);
int
numcpus_name
[]
=
{
CTL_HW
,
HW_NCPU
};
if
(
::
sysctlbyname
(
"hw.ncpu"
,
&
num_cpus
,
&
size
,
nullptr
,
0
)
==
0
&&
if
(
::
sysctl
(
numcpus_name
,
arraysize
(
numcpus_name
),
&
num_cpus
,
&
size
,
nullptr
,
(
size
==
sizeof
(
num_cpus
)))
{
0
)
==
0
&&
(
size
==
sizeof
(
num_cpus
)))
cpuinfo_num_cpus
=
num_cpus
;
cpuinfo_num_cpus
=
num_cpus
;
}
else
{
fprintf
(
stderr
,
"%s
\n
"
,
strerror
(
errno
));
std
::
exit
(
EXIT_FAILURE
);
}
int64_t
cpu_freq
=
0
;
size
=
sizeof
(
cpu_freq
);
if
(
::
sysctlbyname
(
"hw.cpufrequency"
,
&
cpu_freq
,
&
size
,
nullptr
,
0
)
==
0
&&
(
size
==
sizeof
(
cpu_freq
)))
{
cpuinfo_cycles_per_second
=
cpu_freq
;
}
else
{
fprintf
(
stderr
,
"%s
\n
"
,
strerror
(
errno
));
std
::
exit
(
EXIT_FAILURE
);
}
#else
#else
// Generic cycles per second counter
// Generic cycles per second counter
cpuinfo_cycles_per_second
=
static_cast
<
double
>
(
EstimateCyclesPerSecond
());
cpuinfo_cycles_per_second
=
static_cast
<
double
>
(
EstimateCyclesPerSecond
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment