summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-05-16 15:04:25 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-05-16 15:04:25 +0000
commitf919582d8faf16aa161982aa0201c115e15365f4 (patch)
tree559439c6cff1a482d77b24fe349dab4f48ddc7f1
parent2007-05-16 Ralf Corsépius <ralf.corsepius@rtems.org> (diff)
downloadrtems-f919582d8faf16aa161982aa0201c115e15365f4.tar.bz2
2007-05-16 Joel Sherrill <joel.sherrill@oarcorp.com>
* score/Makefile.am, score/include/rtems/score/timespec.h: Add division and greater than operations for timespecs. * score/src/timespecdivide.c, score/src/timespecgreaterthan.c: New files.
-rw-r--r--cpukit/ChangeLog7
-rw-r--r--cpukit/score/Makefile.am4
-rw-r--r--cpukit/score/include/rtems/score/timespec.h33
-rw-r--r--cpukit/score/src/timespecdivide.c52
-rw-r--r--cpukit/score/src/timespecgreaterthan.c42
5 files changed, 136 insertions, 2 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 6ab4ff794d..7377476c32 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,10 @@
+2007-05-16 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * score/Makefile.am, score/include/rtems/score/timespec.h: Add division
+ and greater than operations for timespecs.
+ * score/src/timespecdivide.c, score/src/timespecgreaterthan.c:
+ New files.
+
2007-05-16 Ralf Corsépius <ralf.corsepius@rtems.org>
* score/src/objectgetnameasstring.c: Remove bogus ifdef
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 3699743ce9..2b1c25e513 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -147,8 +147,8 @@ libscore_a_SOURCES += src/threadq.c src/threadqdequeue.c \
## TIMESPEC_C_FILES
libscore_a_SOURCES += src/timespecaddto.c src/timespecfromticks.c \
- src/timespecisvalid.c src/timespeclessthan.c src/timespecsubtract.c \
- src/timespectoticks.c
+ src/timespecisvalid.c src/timespeclessthan.c src/timespecgreaterthan.c \
+ src/timespecsubtract.c src/timespectoticks.c src/timespecdivide.c
## TOD_C_FILES
libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
diff --git a/cpukit/score/include/rtems/score/timespec.h b/cpukit/score/include/rtems/score/timespec.h
index b8c4d16f24..2ffde63fc2 100644
--- a/cpukit/score/include/rtems/score/timespec.h
+++ b/cpukit/score/include/rtems/score/timespec.h
@@ -62,6 +62,21 @@ boolean _Timespec_Less_than(
const struct timespec *rhs
);
+/** @brief Timespec Greater Than Operator
+ *
+ * This method is the greater than operator for timespecs.
+ *
+ * @param[in] lhs is the left hand side timespec
+ * @param[in] rhs is the left hand side timespec
+ *
+ * @return This method returns true if @a lhs is greater than the @a rhs and
+ * false otherwise.
+ */
+boolean _Timespec_Greater_than(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+);
+
/** @brief Add to a Timespec
*
* This routine adds two timespecs. The second argument is added
@@ -120,6 +135,24 @@ void _Timespec_Subtract(
struct timespec *result
);
+/** @brief Divide Timespec
+ *
+ * This routine divides a timespec by an integer value. The expected
+ * use is to assist in benchmark calculations where you typically
+ * divide a duration by a number of iterations.
+ *
+ * @param[in] time is the total
+ * @param[in] iterations is the number of iterations
+ * @param[in] result is the average time.
+ *
+ * @return This method fills in @a result.
+ */
+void _Timespec_Divide(
+ const struct timespec *time,
+ uint32_t iterations,
+ struct timespec *result
+);
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/src/timespecdivide.c b/cpukit/score/src/timespecdivide.c
new file mode 100644
index 0000000000..0535c22e11
--- /dev/null
+++ b/cpukit/score/src/timespecdivide.c
@@ -0,0 +1,52 @@
+/**
+ * @file score/src/timespecdivide.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <sys/types.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+void _Timespec_Divide(
+ const struct timespec *time,
+ uint32_t iterations,
+ struct timespec *result
+)
+{
+ uint64_t t;
+
+ /*
+ * For math simplicity just convert the timespec to nanoseconds
+ * in a 64-bit integer.
+ */
+ t = time->tv_sec * TOD_NANOSECONDS_PER_SECOND;
+ t += time->tv_nsec;
+
+ /*
+ * Divide to get nanoseconds per iteration
+ */
+
+ t /= iterations;
+
+ /*
+ * Put it back in the timespec result
+ */
+
+ result->tv_sec = t / TOD_NANOSECONDS_PER_SECOND;
+ result->tv_nsec = t % TOD_NANOSECONDS_PER_SECOND;
+}
diff --git a/cpukit/score/src/timespecgreaterthan.c b/cpukit/score/src/timespecgreaterthan.c
new file mode 100644
index 0000000000..5541760212
--- /dev/null
+++ b/cpukit/score/src/timespecgreaterthan.c
@@ -0,0 +1,42 @@
+/**
+ * @file score/src/timespecgreaterthan.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+boolean _Timespec_Greater_than(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+)
+{
+ if ( lhs->tv_sec > rhs->tv_sec )
+ return TRUE;
+
+ if ( lhs->tv_sec < rhs->tv_sec )
+ return FALSE;
+
+ /* ASSERT: lhs->tv_sec == rhs->tv_sec */
+ if ( lhs->tv_nsec > rhs->tv_nsec )
+ return TRUE;
+
+ return FALSE;
+}