Commit 874f7599 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Pedro naming scheme, clockstime->clocks_time, cpufreq->clocks_cpufreq,...

Pedro naming scheme, clockstime->clocks_time, cpufreq->clocks_cpufreq, estimate_cpufreq->clocks_estimate_cpufreq
parent fb51caf3
...@@ -70,7 +70,7 @@ int main(int argc, char *argv[]) { ...@@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
struct space s; struct space s;
struct engine e; struct engine e;
struct UnitSystem us; struct UnitSystem us;
struct clockstime tic, toc; struct clocks_time tic, toc;
char ICfileName[200] = ""; char ICfileName[200] = "";
char dumpfile[30]; char dumpfile[30];
float dt_max = 0.0f, dt_min = 0.0f; float dt_max = 0.0f, dt_min = 0.0f;
......
...@@ -37,17 +37,17 @@ ...@@ -37,17 +37,17 @@
#define SLEEPTIME 250000000 #define SLEEPTIME 250000000
/* The CPU frequency used to convert ticks to seconds. */ /* The CPU frequency used to convert ticks to seconds. */
static unsigned long long cpufreq = 0; static unsigned long long clocks_cpufreq = 0;
/* Local prototypes. */ /* Local prototypes. */
static void estimate_cpufreq(); static void clocks_estimate_cpufreq();
/** /**
* @brief Get the current time. * @brief Get the current time.
* *
* @param time the current time. * @param time the current time.
*/ */
void clocks_gettime(struct clockstime *time) { void clocks_gettime(struct clocks_time *time) {
#ifdef HAVE_CLOCK_GETTIME #ifdef HAVE_CLOCK_GETTIME
clock_gettime(CLOCK_REALTIME, &time->time); clock_gettime(CLOCK_REALTIME, &time->time);
...@@ -64,7 +64,7 @@ void clocks_gettime(struct clockstime *time) { ...@@ -64,7 +64,7 @@ void clocks_gettime(struct clockstime *time) {
* *
* @return the difference in milli-secinds. * @return the difference in milli-secinds.
*/ */
double clocks_diff(struct clockstime *start, struct clockstime *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;
...@@ -92,9 +92,9 @@ double clocks_diff(struct clockstime *start, struct clockstime *end) ...@@ -92,9 +92,9 @@ double clocks_diff(struct clockstime *start, struct clockstime *end)
*/ */
void clocks_set_cpufreq(unsigned long long freq) { void clocks_set_cpufreq(unsigned long long freq) {
if ( freq > 0 ) { if ( freq > 0 ) {
cpufreq = freq; clocks_cpufreq = freq;
} else { } else {
estimate_cpufreq(); clocks_estimate_cpufreq();
} }
} }
...@@ -105,12 +105,12 @@ void clocks_set_cpufreq(unsigned long long freq) { ...@@ -105,12 +105,12 @@ void clocks_set_cpufreq(unsigned long long freq) {
*/ */
unsigned long long clocks_get_cpufreq() { unsigned long long clocks_get_cpufreq() {
if (cpufreq > 0) if (clocks_cpufreq > 0)
return cpufreq; return clocks_cpufreq;
/* It not already set estimate it. */ /* It not already set estimate it. */
estimate_cpufreq(); clocks_estimate_cpufreq();
return cpufreq; return clocks_cpufreq;
} }
...@@ -124,12 +124,12 @@ unsigned long long clocks_get_cpufreq() { ...@@ -124,12 +124,12 @@ unsigned long long clocks_get_cpufreq() {
* file (probably a overestimate), to use the macro value CPU_TPS or * file (probably a overestimate), to use the macro value CPU_TPS or
* finally just use a value of 1. * finally just use a value of 1.
*/ */
static void estimate_cpufreq() { static void clocks_estimate_cpufreq() {
#ifdef HAVE_CLOCK_GETTIME #ifdef HAVE_CLOCK_GETTIME
/* Try to time a nanosleep() in ticks. */ /* Try to time a nanosleep() in ticks. */
struct clockstime time1; struct clocks_time time1;
struct clockstime time2; struct clocks_time time2;
struct timespec sleep; struct timespec sleep;
sleep.tv_sec = 0; sleep.tv_sec = 0;
...@@ -145,18 +145,18 @@ static void estimate_cpufreq() { ...@@ -145,18 +145,18 @@ static void estimate_cpufreq() {
ticks toc = getticks(); ticks toc = getticks();
double realsleep = clocks_diff(&time1, &time2); double realsleep = clocks_diff(&time1, &time2);
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 (cpufreq == 0) { if (clocks_cpufreq == 0) {
FILE *file = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", FILE *file = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq",
"r"); "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) {
cpufreq = maxfreq * 1000; clocks_cpufreq = maxfreq * 1000;
} }
fclose(file); fclose(file);
} }
...@@ -165,13 +165,13 @@ static void estimate_cpufreq() { ...@@ -165,13 +165,13 @@ static void estimate_cpufreq() {
/* Nearly final attempt */ /* Nearly final attempt */
#ifdef CPU_TPS #ifdef CPU_TPS
if (cpufreq == 0) if (clocks_cpufreq == 0)
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 (cpufreq == 0) if (clocks_cpufreq == 0)
cpufreq = 1; clocks_cpufreq = 1;
} }
/** /**
...@@ -188,7 +188,7 @@ static void estimate_cpufreq() { ...@@ -188,7 +188,7 @@ static void estimate_cpufreq() {
*/ */
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);
} }
/** /**
...@@ -204,5 +204,5 @@ double clocks_diff_ticks(ticks tic, ticks toc) ...@@ -204,5 +204,5 @@ double clocks_diff_ticks(ticks tic, ticks toc)
*/ */
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);
} }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "cycle.h" #include "cycle.h"
/* Struct to record a time for the clocks functions. */ /* Struct to record a time for the clocks functions. */
struct clockstime { struct clocks_time {
#ifdef HAVE_CLOCK_GETTIME #ifdef HAVE_CLOCK_GETTIME
struct timespec time; struct timespec time;
#else #else
...@@ -31,8 +31,8 @@ struct clockstime { ...@@ -31,8 +31,8 @@ struct clockstime {
#endif #endif
}; };
void clocks_gettime(struct clockstime *time); void clocks_gettime(struct clocks_time *time);
double clocks_diff(struct clockstime *start, struct clockstime *end); double clocks_diff(struct clocks_time *start, struct clocks_time *end);
void clocks_set_cpufreq(unsigned long long freq); void clocks_set_cpufreq(unsigned long long freq);
unsigned long long clocks_get_cpufreq(); unsigned long long clocks_get_cpufreq();
......
...@@ -1483,7 +1483,7 @@ void engine_step(struct engine *e) { ...@@ -1483,7 +1483,7 @@ void engine_step(struct engine *e) {
TIMER_TIC2; TIMER_TIC2;
struct clockstime time1, time2; struct clocks_time time1, time2;
clocks_gettime(&time1); clocks_gettime(&time1);
/* Collect the cell data. */ /* Collect the cell data. */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment