From 2ec7eca01cda063eb75549f72027c3c6bcb9a73b Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Wed, 24 Jan 2018 13:22:01 +0000
Subject: [PATCH] Add function to convert millisec into ticks

---
 src/clocks.c | 19 +++++++++++++++++++
 src/clocks.h |  1 +
 2 files changed, 20 insertions(+)

diff --git a/src/clocks.c b/src/clocks.c
index d5f0e571fe..c70788e0e1 100644
--- a/src/clocks.c
+++ b/src/clocks.c
@@ -216,6 +216,25 @@ double clocks_from_ticks(ticks tics) {
   return ((double)tics / (double)clocks_get_cpufreq() * clocks_units_scale);
 }
 
+/**
+ * @brief Convert a number of milli seconds into ticks, if possible.
+ *
+ * Only an approximation as based on how well we have estimated the
+ * rtc frequency. Should be good for machines that support constant_rtc
+ * and clock_gettime(), and reasonable for most Linux machines, otherwise
+ * a guess will just be returned. See clocks_getunit() for the actual units.
+ *
+ * @param ms a number of "milliseconds" to convert to ticks
+ *
+ * @result the number of ticks, if possible.
+ */
+ticks clocks_to_ticks(double ms) {
+    return (ticks) (ms * (double)clocks_get_cpufreq() / clocks_units_scale);
+}
+
+ticks clocks_to_ticks(double interval);
+
+
 /**
  * @brief return the time units.
  *
diff --git a/src/clocks.h b/src/clocks.h
index 4c69e130d9..bdb3a6651e 100644
--- a/src/clocks.h
+++ b/src/clocks.h
@@ -39,6 +39,7 @@ const char *clocks_getunit();
 void clocks_set_cpufreq(unsigned long long freq);
 unsigned long long clocks_get_cpufreq();
 double clocks_from_ticks(ticks tics);
+ticks clocks_to_ticks(double interval);
 double clocks_diff_ticks(ticks tic, ticks toc);
 const char *clocks_get_timesincestart();
 
-- 
GitLab