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
ceea4cb3
Commit
ceea4cb3
authored
Jan 20, 2014
by
Eugene Zhuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[#4] A few minor changes.
parent
4ed4ff95
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
23 deletions
+26
-23
benchmark.cc
src/benchmark.cc
+25
-23
sleep.h
src/sleep.h
+1
-0
No files found.
src/benchmark.cc
View file @
ceea4cb3
...
@@ -443,15 +443,19 @@ class State::FastClock {
...
@@ -443,15 +443,19 @@ class State::FastClock {
REAL_TIME
,
REAL_TIME
,
CPU_TIME
CPU_TIME
};
};
explicit
FastClock
(
Type
type
)
:
type_
(
type
),
approx_time_
(
NowMicros
())
{
explicit
FastClock
(
Type
type
)
pthread_cond_init
(
&
bg_cond_
,
0
);
:
type_
(
type
),
pthread_mutex_init
(
&
bg_mutex_
,
0
);
approx_time_
(
NowMicros
()),
bg_done_
(
false
)
{
pthread_cond_init
(
&
bg_cond_
,
nullptr
);
pthread_mutex_init
(
&
bg_mutex_
,
nullptr
);
pthread_create
(
&
bg_
,
NULL
,
&
BGThreadWrapper
,
this
);
pthread_create
(
&
bg_
,
NULL
,
&
BGThreadWrapper
,
this
);
}
}
~
FastClock
()
{
~
FastClock
()
{
{
{
mutex_lock
l
(
&
bg_mutex_
);
mutex_lock
l
(
&
bg_mutex_
);
bg_done_
=
true
;
pthread_cond_signal
(
&
bg_cond_
);
pthread_cond_signal
(
&
bg_cond_
);
}
}
pthread_join
(
bg_
,
NULL
);
pthread_join
(
bg_
,
NULL
);
...
@@ -493,6 +497,7 @@ class State::FastClock {
...
@@ -493,6 +497,7 @@ class State::FastClock {
private
:
private
:
Type
type_
;
Type
type_
;
std
::
atomic
<
int64_t
>
approx_time_
;
// Last time measurement taken by bg_
std
::
atomic
<
int64_t
>
approx_time_
;
// Last time measurement taken by bg_
bool
bg_done_
;
// This is used to signal background thread to exit
pthread_t
bg_
;
// Background thread that updates last_time_ once every ms
pthread_t
bg_
;
// Background thread that updates last_time_ once every ms
pthread_mutex_t
bg_mutex_
;
pthread_mutex_t
bg_mutex_
;
...
@@ -504,30 +509,27 @@ class State::FastClock {
...
@@ -504,30 +509,27 @@ class State::FastClock {
}
}
void
BGThread
()
{
void
BGThread
()
{
int
done
=
0
;
do
{
do
{
SleepForMicroseconds
(
1000
);
struct
timeval
tv
;
gettimeofday
(
&
tv
,
nullptr
);
// Set timeout to 1 ms.
uint32_t
const
timeout
=
1000
;
struct
timespec
ts
;
ts
.
tv_sec
=
tv
.
tv_sec
+
(
timeout
/
kNumMicrosPerSecond
);
ts
.
tv_nsec
=
(
tv
.
tv_usec
+
(
timeout
%
kNumMicrosPerSecond
))
*
kNumNanosPerMicro
;
ts
.
tv_sec
+=
ts
.
tv_nsec
/
kNumNanosPerSecond
;
ts
.
tv_nsec
%=
kNumNanosPerSecond
;
// NOTE: this should probably be platform specific.
mutex_lock
l
(
&
bg_mutex_
);
pthread_cond_timedwait
(
&
bg_cond_
,
&
bg_mutex_
,
&
ts
);
std
::
atomic_store
(
&
approx_time_
,
NowMicros
());
std
::
atomic_store
(
&
approx_time_
,
NowMicros
());
// NOTE: same code but no memory barrier. think on it.
// NOTE: same code but no memory barrier. think on it.
// base::subtle::Release_Store(&approx_time_, NowMicros());
// base::subtle::Release_Store(&approx_time_, NowMicros());
{
}
while
(
!
bg_done_
);
struct
timeval
tv
;
gettimeofday
(
&
tv
,
0
);
// Set timeout to 100 ms.
long
const
timeout
=
100000
;
struct
timespec
ts
;
ts
.
tv_sec
=
tv
.
tv_sec
+
(
timeout
/
1000000
);
ts
.
tv_nsec
=
(
tv
.
tv_usec
+
(
timeout
%
1000000
))
*
1000
;
ts
.
tv_sec
+=
ts
.
tv_nsec
/
1000000000
;
ts
.
tv_nsec
%=
1000000000
;
// NOTE: this should probably be platform specific.
mutex_lock
l
(
&
bg_mutex_
);
if
(
0
==
pthread_cond_timedwait
(
&
bg_cond_
,
&
bg_mutex_
,
&
ts
))
done
=
1
;
}
}
while
(
done
==
0
);
}
}
DISALLOW_COPY_AND_ASSIGN
(
FastClock
)
DISALLOW_COPY_AND_ASSIGN
(
FastClock
)
...
...
src/sleep.h
View file @
ceea4cb3
...
@@ -8,6 +8,7 @@ const int64_t kNumMillisPerSecond = 1000LL;
...
@@ -8,6 +8,7 @@ const int64_t kNumMillisPerSecond = 1000LL;
const
int64_t
kNumMicrosPerMilli
=
1000LL
;
const
int64_t
kNumMicrosPerMilli
=
1000LL
;
const
int64_t
kNumMicrosPerSecond
=
kNumMillisPerSecond
*
1000LL
;
const
int64_t
kNumMicrosPerSecond
=
kNumMillisPerSecond
*
1000LL
;
const
int64_t
kNumNanosPerMicro
=
1000LL
;
const
int64_t
kNumNanosPerMicro
=
1000LL
;
const
int64_t
kNumNanosPerSecond
=
kNumNanosPerMicro
*
kNumMicrosPerSecond
;
void
SleepForMicroseconds
(
int64_t
microseconds
);
void
SleepForMicroseconds
(
int64_t
microseconds
);
void
SleepForMilliseconds
(
int
milliseconds
);
void
SleepForMilliseconds
(
int
milliseconds
);
...
...
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