Commit 03e12eb9 authored by Thomas Schöpping's avatar Thomas Schöpping
Browse files

Fix: inconsistent timers where caused by numeric instabilities.

parent a49045e6
......@@ -29,7 +29,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <urtbenchmarkconf.h>
#include <amiroos.h>
#include <uRT_benchmark.h>
#include <math.h>
#include <stdlib.h>
/******************************************************************************/
......@@ -371,13 +370,13 @@ static void _urtbenchmark_triggercb_pubsubqos(void* starttime)
++_urtbenchmark_timer.counter;
// set synthetic information origin time to last trigger event
*(urt_osTime_t*)starttime = _urtbenchmark_timer.time +
ceilf(((((_urtbenchmark_timer.counter-1) * _urtbenchmark_timer.counter) / 2) *
((float)URTBENCHMARK_CFG_QOSTIME / (float)URTBENCHMARK_CFG_QOSSTEPS)));
((((_urtbenchmark_timer.counter-1) * _urtbenchmark_timer.counter) / 2) *
((URTBENCHMARK_CFG_QOSTIME + URTBENCHMARK_CFG_QOSSTEPS-1) / URTBENCHMARK_CFG_QOSSTEPS));
// restart single-shot timer
aosTimerSetAbsoluteI(&_urtbenchmark_timer.timer,
_urtbenchmark_timer.time +
ceilf(((((_urtbenchmark_timer.counter+1) * (_urtbenchmark_timer.counter+2)) / 2) *
((float)URTBENCHMARK_CFG_QOSTIME / (float)URTBENCHMARK_CFG_QOSSTEPS))),
((((_urtbenchmark_timer.counter+1) * (_urtbenchmark_timer.counter+2)) / 2) *
((URTBENCHMARK_CFG_QOSTIME + URTBENCHMARK_CFG_QOSSTEPS-1) / URTBENCHMARK_CFG_QOSSTEPS)),
_urtbenchmark_triggercb_pubsubqos,
starttime);
// fire event
......@@ -403,12 +402,12 @@ static void _urtbenchmark_triggercb_rpcqos(void* delay)
// increment counter
++_urtbenchmark_timer.counter;
// set synthetic delay
*(urt_delay_t*)delay = ceilf((float)_urtbenchmark_timer.counter * (float)URTBENCHMARK_CFG_QOSTIME / (float)URTBENCHMARK_CFG_QOSSTEPS);
*(urt_delay_t*)delay = _urtbenchmark_timer.counter * ((URTBENCHMARK_CFG_QOSTIME + URTBENCHMARK_CFG_QOSSTEPS-1) / URTBENCHMARK_CFG_QOSSTEPS);
// restart single-shot timer
aosTimerSetAbsoluteI(&_urtbenchmark_timer.timer,
_urtbenchmark_timer.time +
ceilf(((((_urtbenchmark_timer.counter+1) * (_urtbenchmark_timer.counter+2)) / 2) *
((float)URTBENCHMARK_CFG_QOSTIME / (float)URTBENCHMARK_CFG_QOSSTEPS))),
((((_urtbenchmark_timer.counter+1) * (_urtbenchmark_timer.counter+2)) / 2) *
((URTBENCHMARK_CFG_QOSTIME + URTBENCHMARK_CFG_QOSSTEPS-1) / URTBENCHMARK_CFG_QOSSTEPS)),
_urtbenchmark_triggercb_rpcqos,
delay);
// fire event
......@@ -592,7 +591,7 @@ int _urtbenchmark_nodes(BaseSequentialStream* const stream,
// arm the trigger
_urtbenchmark_timer.counter = 0;
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_REPETITIONS;
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, roundf((float)MICROSECONDS_PER_SECOND / (float)URTBENCHMARK_CFG_FREQUENCY), _urtbenchmark_triggercb, NULL);
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, MICROSECONDS_PER_SECOND / URTBENCHMARK_CFG_FREQUENCY, _urtbenchmark_triggercb, NULL);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
// stop all nodes and reset
......@@ -708,7 +707,7 @@ int _urtbenchmark_pubsub_payload(BaseSequentialStream* const stream,
// arm trigger timer
_urtbenchmark_timer.counter = 0;
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_REPETITIONS;
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, roundf((float)MICROSECONDS_PER_SECOND / (float)URTBENCHMARK_CFG_FREQUENCY), _urtbenchmark_triggercb, NULL);
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, MICROSECONDS_PER_SECOND / URTBENCHMARK_CFG_FREQUENCY, _urtbenchmark_triggercb, NULL);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
// stop all nodes and reset
......@@ -803,7 +802,7 @@ int _urtbenchmark_pubsub_messagebuffer(BaseSequentialStream* const stream,
// arm trigger timer
_urtbenchmark_timer.counter = 0;
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_REPETITIONS;
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, roundf((float)MICROSECONDS_PER_SECOND / (float)URTBENCHMARK_CFG_FREQUENCY), _urtbenchmark_triggercb, NULL);
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, MICROSECONDS_PER_SECOND / URTBENCHMARK_CFG_FREQUENCY, _urtbenchmark_triggercb, NULL);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
// stop all nodes and reset
......@@ -884,7 +883,7 @@ int _urtbenchmark_pubsub_publisher(BaseSequentialStream* const stream,
// arm trigger timer
_urtbenchmark_timer.counter = 0;
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_REPETITIONS;
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, roundf((float)MICROSECONDS_PER_SECOND / (float)URTBENCHMARK_CFG_FREQUENCY), _urtbenchmark_triggercb, NULL);
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, MICROSECONDS_PER_SECOND / URTBENCHMARK_CFG_FREQUENCY, _urtbenchmark_triggercb, NULL);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
// stop all nodes and reset
......@@ -982,7 +981,7 @@ int _urtbenchmark_pubsub_subscriber(BaseSequentialStream* const stream,
// arm trigger timer
_urtbenchmark_timer.counter = 0;
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_REPETITIONS;
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, roundf((float)MICROSECONDS_PER_SECOND / (float)URTBENCHMARK_CFG_FREQUENCY), _urtbenchmark_triggercb, NULL);
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, MICROSECONDS_PER_SECOND / URTBENCHMARK_CFG_FREQUENCY, _urtbenchmark_triggercb, NULL);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
// stop all nodes and reset
......@@ -1062,7 +1061,7 @@ int _urtbenchmark_pubsub_topic(BaseSequentialStream* const stream,
// arm trigger timer
_urtbenchmark_timer.counter = 0;
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_REPETITIONS;
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, roundf((float)MICROSECONDS_PER_SECOND / (float)URTBENCHMARK_CFG_FREQUENCY), _urtbenchmark_triggercb, NULL);
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, MICROSECONDS_PER_SECOND / URTBENCHMARK_CFG_FREQUENCY, _urtbenchmark_triggercb, NULL);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
// stop all nodes and reset
......@@ -1143,7 +1142,7 @@ int _urtbenchmark_pubsub_deadline(BaseSequentialStream* const stream,
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_QOSSTEPS;
aosSysGetUptime(&_urtbenchmark_timer.time);
aosTimerSetAbsolute(&_urtbenchmark_timer.timer,
_urtbenchmark_timer.time + ceilf((float)URTBENCHMARK_CFG_QOSTIME / (float)URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_timer.time + ((URTBENCHMARK_CFG_QOSTIME + URTBENCHMARK_CFG_QOSSTEPS-1) / URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_triggercb_pubsubqos,
&_urtbenchmark_data.pubsub.deadline.origintime);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
......@@ -1233,7 +1232,7 @@ int _urtbenchmark_pubsub_jitter(BaseSequentialStream* const stream,
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_QOSSTEPS + 1;
aosSysGetUptime(&_urtbenchmark_timer.time);
aosTimerSetAbsolute(&_urtbenchmark_timer.timer,
_urtbenchmark_timer.time + ceilf((float)URTBENCHMARK_CFG_QOSTIME / (float)URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_timer.time + ((URTBENCHMARK_CFG_QOSTIME + URTBENCHMARK_CFG_QOSSTEPS-1) / URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_triggercb_pubsubqos,
&_urtbenchmark_data.pubsub.jitter.origintime);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
......@@ -1323,7 +1322,7 @@ int _urtbenchmark_pubsub_rate(BaseSequentialStream* const stream,
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_QOSSTEPS;
aosSysGetUptime(&_urtbenchmark_timer.time);
aosTimerSetAbsolute(&_urtbenchmark_timer.timer,
_urtbenchmark_timer.time + ceilf((float)URTBENCHMARK_CFG_QOSTIME / (float)URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_timer.time + ((URTBENCHMARK_CFG_QOSTIME + URTBENCHMARK_CFG_QOSSTEPS-1) / URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_triggercb_pubsubqos,
&_urtbenchmark_data.pubsub.rate.origintime);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
......@@ -1627,7 +1626,7 @@ int _urtbenchmark_rpc_payload(BaseSequentialStream* const stream,
// arm trigger timer
_urtbenchmark_timer.counter = 0;
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_REPETITIONS;
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, roundf((float)MICROSECONDS_PER_SECOND / (float)URTBENCHMARK_CFG_FREQUENCY), _urtbenchmark_triggercb, NULL);
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, MICROSECONDS_PER_SECOND / URTBENCHMARK_CFG_FREQUENCY, _urtbenchmark_triggercb, NULL);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
// stop all nodes and reset
......@@ -1721,7 +1720,7 @@ int _urtbenchmark_rpc_request(BaseSequentialStream* const stream,
// arm trigger timer
_urtbenchmark_timer.counter = 0;
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_REPETITIONS;
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, roundf((float)MICROSECONDS_PER_SECOND / (float)URTBENCHMARK_CFG_FREQUENCY), _urtbenchmark_triggercb, NULL);
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, MICROSECONDS_PER_SECOND / URTBENCHMARK_CFG_FREQUENCY, _urtbenchmark_triggercb, NULL);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
// stop all nodes and reset
......@@ -1799,7 +1798,7 @@ int _urtbenchmark_rpc_service(BaseSequentialStream* const stream,
// arm trigger timer
_urtbenchmark_timer.counter = 0;
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_REPETITIONS;
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, roundf((float)MICROSECONDS_PER_SECOND / (float)URTBENCHMARK_CFG_FREQUENCY), _urtbenchmark_triggercb, NULL);
aosTimerPeriodicInterval(&_urtbenchmark_timer.timer, MICROSECONDS_PER_SECOND / URTBENCHMARK_CFG_FREQUENCY, _urtbenchmark_triggercb, NULL);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
// stop all nodes and reset
......@@ -1878,7 +1877,7 @@ int _urtbenchmark_rpc_deadline(BaseSequentialStream* const stream,
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_QOSSTEPS;
aosSysGetUptime(&_urtbenchmark_timer.time);
aosTimerSetAbsolute(&_urtbenchmark_timer.timer,
_urtbenchmark_timer.time + ceilf((float)URTBENCHMARK_CFG_QOSTIME / (float)URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_timer.time + ((URTBENCHMARK_CFG_QOSTIME + URTBENCHMARK_CFG_QOSSTEPS-1) / URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_triggercb_rpcqos,
&_urtbenchmark_data.rpc.deadline.delaybuffer);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
......@@ -1965,7 +1964,7 @@ int _urtbenchmark_rpc_jitter(BaseSequentialStream* const stream,
_urtbenchmark_timer.iterations = URTBENCHMARK_CFG_QOSSTEPS + 1;
aosSysGetUptime(&_urtbenchmark_timer.time);
aosTimerSetAbsolute(&_urtbenchmark_timer.timer,
_urtbenchmark_timer.time + ceilf((float)URTBENCHMARK_CFG_QOSTIME / (float)URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_timer.time + ((URTBENCHMARK_CFG_QOSTIME + URTBENCHMARK_CFG_QOSSTEPS-1) / URTBENCHMARK_CFG_QOSSTEPS),
_urtbenchmark_triggercb_rpcqos,
&_urtbenchmark_data.rpc.jitter.delaybuffer);
urtEventWait(terminationevent, URT_EVENT_WAIT_ANY, URT_DELAY_INFINITE);
......
Markdown is supported
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