Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
b87545bc
Commit
b87545bc
authored
9 years ago
by
Peter W. Draper
Browse files
Options
Downloads
Patches
Plain Diff
Use standard formatting
parent
874f7599
No related branches found
No related tags found
2 merge requests
!136
Master
,
!105
Show time in real milli seconds
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/clocks.c
+15
-22
15 additions, 22 deletions
src/clocks.c
src/clocks.h
+2
-2
2 additions, 2 deletions
src/clocks.h
with
17 additions
and
24 deletions
src/clocks.c
+
15
−
22
View file @
b87545bc
...
@@ -64,8 +64,7 @@ void clocks_gettime(struct clocks_time *time) {
...
@@ -64,8 +64,7 @@ void clocks_gettime(struct clocks_time *time) {
*
*
* @return the difference in milli-secinds.
* @return the difference in milli-secinds.
*/
*/
double
clocks_diff
(
struct
clocks_time
*
start
,
struct
clocks_time
*
end
)
double
clocks_diff
(
struct
clocks_time
*
start
,
struct
clocks_time
*
end
)
{
{
#ifdef HAVE_CLOCK_GETTIME
#ifdef HAVE_CLOCK_GETTIME
struct
timespec
temp
;
struct
timespec
temp
;
if
((
end
->
time
.
tv_nsec
-
start
->
time
.
tv_nsec
)
<
0
)
{
if
((
end
->
time
.
tv_nsec
-
start
->
time
.
tv_nsec
)
<
0
)
{
...
@@ -77,9 +76,8 @@ double clocks_diff(struct clocks_time *start, struct clocks_time *end)
...
@@ -77,9 +76,8 @@ double clocks_diff(struct clocks_time *start, struct clocks_time *end)
}
}
return
(
double
)
temp
.
tv_sec
*
1000
.
0
+
(
double
)
temp
.
tv_nsec
*
1.0E-6
;
return
(
double
)
temp
.
tv_sec
*
1000
.
0
+
(
double
)
temp
.
tv_nsec
*
1.0E-6
;
#else
#else
return
elapsed
(
end
->
time
,
start
-
time
)
/
clocks_get_cpufreq
()
*
1000
;
return
elapsed
(
end
->
time
,
start
-
>
time
)
/
clocks_get_cpufreq
()
*
1000
;
#endif
#endif
}
}
/**
/**
...
@@ -91,10 +89,10 @@ double clocks_diff(struct clocks_time *start, struct clocks_time *end)
...
@@ -91,10 +89,10 @@ double clocks_diff(struct clocks_time *start, struct clocks_time *end)
* @param freq the CPU frequency in Hz or 0 to estimate one.
* @param freq the CPU frequency in Hz or 0 to estimate one.
*/
*/
void
clocks_set_cpufreq
(
unsigned
long
long
freq
)
{
void
clocks_set_cpufreq
(
unsigned
long
long
freq
)
{
if
(
freq
>
0
)
{
if
(
freq
>
0
)
{
clocks_cpufreq
=
freq
;
clocks_cpufreq
=
freq
;
}
else
{
}
else
{
clocks_estimate_cpufreq
();
clocks_estimate_cpufreq
();
}
}
}
}
...
@@ -105,13 +103,11 @@ void clocks_set_cpufreq(unsigned long long freq) {
...
@@ -105,13 +103,11 @@ void clocks_set_cpufreq(unsigned long long freq) {
*/
*/
unsigned
long
long
clocks_get_cpufreq
()
{
unsigned
long
long
clocks_get_cpufreq
()
{
if
(
clocks_cpufreq
>
0
)
if
(
clocks_cpufreq
>
0
)
return
clocks_cpufreq
;
return
clocks_cpufreq
;
/* It not already set estimate it. */
/* It not already set estimate it. */
clocks_estimate_cpufreq
();
clocks_estimate_cpufreq
();
return
clocks_cpufreq
;
return
clocks_cpufreq
;
}
}
/**
/**
...
@@ -145,14 +141,15 @@ static void clocks_estimate_cpufreq() {
...
@@ -145,14 +141,15 @@ static void clocks_estimate_cpufreq() {
ticks
toc
=
getticks
();
ticks
toc
=
getticks
();
double
realsleep
=
clocks_diff
(
&
time1
,
&
time2
);
double
realsleep
=
clocks_diff
(
&
time1
,
&
time2
);
clocks_cpufreq
=
(
signed
long
long
)
(
double
)(
toc
-
tic
)
*
1
.
0
/
realsleep
*
1000
.
0
;
clocks_cpufreq
=
(
signed
long
long
)(
double
)(
toc
-
tic
)
*
1
.
0
/
realsleep
*
1000
.
0
;
#endif
#endif
/* Look for the system value, if available. Tends to be too large. */
/* Look for the system value, if available. Tends to be too large. */
#ifdef __linux__
#ifdef __linux__
if
(
clocks_cpufreq
==
0
)
{
if
(
clocks_cpufreq
==
0
)
{
FILE
*
file
=
fopen
(
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
,
FILE
*
file
=
"r"
);
fopen
(
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
,
"r"
);
if
(
file
!=
NULL
)
{
if
(
file
!=
NULL
)
{
unsigned
long
long
maxfreq
;
unsigned
long
long
maxfreq
;
if
(
fscanf
(
file
,
"%llu"
,
&
maxfreq
)
==
1
)
{
if
(
fscanf
(
file
,
"%llu"
,
&
maxfreq
)
==
1
)
{
...
@@ -163,15 +160,13 @@ static void clocks_estimate_cpufreq() {
...
@@ -163,15 +160,13 @@ static void clocks_estimate_cpufreq() {
}
}
#endif
#endif
/* Nearly final attempt */
/* Nearly final attempt */
#ifdef CPU_TPS
#ifdef CPU_TPS
if
(
clocks_cpufreq
==
0
)
if
(
clocks_cpufreq
==
0
)
clocks_cpufreq
=
CPU_TPS
;
clocks_cpufreq
=
CPU_TPS
;
#endif
#endif
/* If all fails just report ticks in any times. */
/* If all fails just report ticks in any times. */
if
(
clocks_cpufreq
==
0
)
if
(
clocks_cpufreq
==
0
)
clocks_cpufreq
=
1
;
clocks_cpufreq
=
1
;
}
}
/**
/**
...
@@ -186,8 +181,7 @@ static void clocks_estimate_cpufreq() {
...
@@ -186,8 +181,7 @@ static void clocks_estimate_cpufreq() {
*
*
* @result the absolute difference in approximated seconds.
* @result the absolute difference in approximated seconds.
*/
*/
double
clocks_diff_ticks
(
ticks
tic
,
ticks
toc
)
double
clocks_diff_ticks
(
ticks
tic
,
ticks
toc
)
{
{
return
clocks_from_ticks
(
tic
-
toc
);
return
clocks_from_ticks
(
tic
-
toc
);
}
}
...
@@ -202,7 +196,6 @@ double clocks_diff_ticks(ticks tic, ticks toc)
...
@@ -202,7 +196,6 @@ double clocks_diff_ticks(ticks tic, ticks toc)
*
*
* @result the approximated seconds.
* @result the approximated seconds.
*/
*/
double
clocks_from_ticks
(
ticks
tics
)
double
clocks_from_ticks
(
ticks
tics
)
{
{
return
((
double
)
tics
/
(
double
)
clocks_get_cpufreq
()
*
1000
.
0
);
return
((
double
)
tics
/
(
double
)
clocks_get_cpufreq
()
*
1000
.
0
);
}
}
This diff is collapsed.
Click to expand it.
src/clocks.h
+
2
−
2
View file @
b87545bc
...
@@ -25,9 +25,9 @@
...
@@ -25,9 +25,9 @@
/* Struct to record a time for the clocks functions. */
/* Struct to record a time for the clocks functions. */
struct
clocks_time
{
struct
clocks_time
{
#ifdef HAVE_CLOCK_GETTIME
#ifdef HAVE_CLOCK_GETTIME
struct
timespec
time
;
struct
timespec
time
;
#else
#else
ticks
time
;
ticks
time
;
#endif
#endif
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment