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.
This commit is contained in:
Joel Sherrill
2007-05-16 15:04:25 +00:00
parent 717adfb3e8
commit f919582d8f
5 changed files with 136 additions and 2 deletions

View File

@@ -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

View File

@@ -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 \

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
}