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
dc5b533a
Commit
dc5b533a
authored
Jan 08, 2014
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove tunable estimate for cycles per second
parent
9d230ffb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
13 deletions
+10
-13
sysinfo.cc
src/sysinfo.cc
+10
-13
No files found.
src/sysinfo.cc
View file @
dc5b533a
...
@@ -20,21 +20,18 @@
...
@@ -20,21 +20,18 @@
namespace
benchmark
{
namespace
benchmark
{
namespace
{
namespace
{
const
int64_t
estimate_time_ms
=
1000
;
pthread_once_t
cpuinfo_init
=
PTHREAD_ONCE_INIT
;
pthread_once_t
cpuinfo_init
=
PTHREAD_ONCE_INIT
;
double
cpuinfo_cycles_per_second
=
1.0
;
double
cpuinfo_cycles_per_second
=
1.0
;
int
cpuinfo_num_cpus
=
1
;
// Conservative guess
int
cpuinfo_num_cpus
=
1
;
// Conservative guess
static
pthread_mutex_t
cputimens_mutex
;
pthread_mutex_t
cputimens_mutex
;
// Helper function estimates cycles/sec by observing cycles elapsed during
// Helper function estimates cycles/sec by observing cycles elapsed during
// sleep(). Using small sleep time decreases accuracy significantly.
// sleep(). Using small sleep time decreases accuracy significantly.
int64_t
EstimateCyclesPerSecond
(
const
int
estimate_time_ms
)
{
int64_t
EstimateCyclesPerSecond
()
{
CHECK
(
estimate_time_ms
>
0
);
double
multiplier
=
1000.0
/
(
double
)
estimate_time_ms
;
// scale by this much
const
int64_t
start_ticks
=
cycleclock
::
Now
();
const
int64_t
start_ticks
=
cycleclock
::
Now
();
SleepForMilliseconds
(
estimate_time_ms
);
SleepForMilliseconds
(
estimate_time_ms
);
const
int64_t
guess
=
int64_t
(
multiplier
*
(
cycleclock
::
Now
()
-
start_ticks
));
return
cycleclock
::
Now
()
-
start_ticks
;
return
guess
;
}
}
// Helper function for reading an int from a file. Returns true if successful
// Helper function for reading an int from a file. Returns true if successful
...
@@ -99,9 +96,9 @@ void InitializeSystemInfo() {
...
@@ -99,9 +96,9 @@ void InitializeSystemInfo() {
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
perror
(
pname
);
perror
(
pname
);
if
(
!
saw_mhz
)
{
if
(
!
saw_mhz
)
{
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
(
1000
);
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
();
}
}
return
;
// TODO: use generic tester instead?
return
;
}
}
double
bogo_clock
=
1.0
;
double
bogo_clock
=
1.0
;
...
@@ -166,7 +163,7 @@ void InitializeSystemInfo() {
...
@@ -166,7 +163,7 @@ void InitializeSystemInfo() {
cpuinfo_cycles_per_second
=
bogo_clock
;
cpuinfo_cycles_per_second
=
bogo_clock
;
}
else
{
}
else
{
// If we don't even have bogomips, we'll use the slow estimation.
// If we don't even have bogomips, we'll use the slow estimation.
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
(
1000
);
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
();
}
}
}
}
if
(
num_cpus
==
0
)
{
if
(
num_cpus
==
0
)
{
...
@@ -202,7 +199,7 @@ void InitializeSystemInfo() {
...
@@ -202,7 +199,7 @@ void InitializeSystemInfo() {
if
(
sysctlbyname
(
sysctl_path
,
&
hz
,
&
sz
,
NULL
,
0
)
!=
0
)
{
if
(
sysctlbyname
(
sysctl_path
,
&
hz
,
&
sz
,
NULL
,
0
)
!=
0
)
{
fprintf
(
stderr
,
"Unable to determine clock rate from sysctl: %s: %s
\n
"
,
fprintf
(
stderr
,
"Unable to determine clock rate from sysctl: %s: %s
\n
"
,
sysctl_path
,
strerror
(
errno
));
sysctl_path
,
strerror
(
errno
));
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
(
1000
);
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
();
}
else
{
}
else
{
cpuinfo_cycles_per_second
=
hz
;
cpuinfo_cycles_per_second
=
hz
;
}
}
...
@@ -222,7 +219,7 @@ void InitializeSystemInfo() {
...
@@ -222,7 +219,7 @@ void InitializeSystemInfo() {
"~MHz"
,
NULL
,
&
data
,
&
data_size
)))
"~MHz"
,
NULL
,
&
data
,
&
data_size
)))
cpuinfo_cycles_per_second
=
(
int64
)
data
*
(
int64
)(
1000
*
1000
);
// was mhz
cpuinfo_cycles_per_second
=
(
int64
)
data
*
(
int64
)(
1000
*
1000
);
// was mhz
else
else
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
(
500
);
// TODO <500?
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
(
);
// TODO: also figure out cpuinfo_num_cpus
// TODO: also figure out cpuinfo_num_cpus
#elif defined OS_MACOSX
#elif defined OS_MACOSX
...
@@ -251,7 +248,7 @@ void InitializeSystemInfo() {
...
@@ -251,7 +248,7 @@ void InitializeSystemInfo() {
#else
#else
// Generic cycles per second counter
// Generic cycles per second counter
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
(
1000
);
cpuinfo_cycles_per_second
=
EstimateCyclesPerSecond
();
#endif
#endif
}
}
}
// end namespace
}
// end namespace
...
...
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