Upload
david-beberman
View
220
Download
0
Embed Size (px)
Citation preview
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 1/12
Aicas GmbH
RT Main example
with source
Demonstrates RTSJ release latency and jitterand execution jitter on
Linux kernel with Preempt_RT patch
02/19/13 Www.aicas.com 1/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 2/12
Source Listing/**
* Periodic Thread in JamaicaVM
*/
import javax.realtime.Clock;
import javax.realtime.HeapMemory;
import javax.realtime.PriorityScheduler;
import javax.realtime.PriorityParameters;
import javax.realtime.PeriodicParameters;
import javax.realtime.AbsoluteTime;
import javax.realtime.RelativeTime;
import javax.realtime.RealtimeThread;
/**
* @author aicas GmbH
*
*/
public class RTMain {
/**
* HELPER Class to gather RT performance statistics.
*/
public static class RTPStats {
/** Default constructor */
public RTPStats () {
}
/** Get number of overruns */
public int getNumOverruns () {
return _numOverrun;
}
/** Get average time delta (msec) */
public double getAvgTimeDelta () {
02/19/13 Www.aicas.com 2/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 3/12
return (_nSamp > 0) ? _avgTDelta / (_nSamp * 1000000.0) : 0.0;
}
/** Get minimum time delta sample (msec) */
public double getMinTimeDelta () {
return (_nSamp > 0) ? _minTDelta / 1000000.0 : 0.0;
}
/** Get maximum time delta sample (msec) */
public double getMaxTimeDelta () {
return (_nSamp > 0) ? _maxTDelta / 1000000.0 : 0.0;
}
/** For reuse of instance */
public void reset () {
_nSamp = 0;
_numOverrun = 0;
_avgTDelta = 0L;
_minTDelta = Long.MAX_VALUE;
_maxTDelta = Long.MIN_VALUE;
}
/** Accumulate time delta statistics */
public void accumTimeDelta (RelativeTime tDelta) {
accumTimeDelta(true, tDelta);
}
/** Accumulate time delta statistics */
public void accumTimeDelta (boolean onTime, RelativeTime tDelta) {
long td_ns = (tDelta.getMilliseconds() * 1000000) + tDelta.getNanoseconds();
_nSamp++;
if (!onTime) _numOverrun++;
_avgTDelta += td_ns;
_minTDelta = Math.min(_minTDelta, td_ns);
_maxTDelta = Math.max(_maxTDelta, td_ns);
}
/*
* Instance variables.
02/19/13 Www.aicas.com 3/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 4/12
*/
private int _nSamp = 0;
private int _numOverrun = 0;
private long _avgTDelta = 0L;
private long _minTDelta = Long.MAX_VALUE;
private long _maxTDelta = Long.MIN_VALUE;
}
/** Buffer used to control exact available heap size */
static byte[] _sMemBuff;
/**
* RTLatencyTest [per_ms [per_us [bufsiz_pct]]]
*
* @param args [All optional]
* tPer_ms thread period milliseconds [df: 200]
* tPer_us thread period microseconds [df: 0]
* bSiz_pct (stress GC) buffer size in percent of Heap [df: no buffer]*/
public static void main(String[] args) {
/* Defaulted command-line arguments */
int tPer_ms = (args.length > 0) ? Integer.parseInt(args[0]) : 0;
int tPer_us = (args.length > 1) ? Integer.parseInt(args[1]) : 500;
double bSiz_pct = (args.length > 2) ? Double.parseDouble(args[2]) : 50.0;
System.out.println("\nRTLatencyTest tPer(" + tPer_ms + " ms, " + tPer_us +
" us) bSiz(" + bSiz_pct + "%)\n");
final int testCount = 1000;
final Clock clock = Clock.getRealtimeClock();
AbsoluteTime currTime = clock.getTime();
long ms = currTime.getMilliseconds();
int ns = currTime.getNanoseconds();
if (ms < 0 || ns < 0 || ns > 999999) {
02/19/13 Www.aicas.com 4/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 5/12
System.out.println("Absolute time values are incorrect. Please set the system clock!");
System.out.println("Got 'ms: " + ms + "' - 'ns: " + ns + "'");
System.exit(1);
}
/* priority for new thread: mininum+10 */
int priority = PriorityScheduler.instance().getMinPriority() + 10;
PriorityParameters priortyParameters = new PriorityParameters(priority);
/* release parameters for periodic thread: */
RelativeTime period = new RelativeTime(tPer_ms, tPer_us * 1000);
PeriodicParameters periodicParameters = new PeriodicParameters(null, period,null,null,null,null);
/* SPECIAL: To "stress" the (real-time) garbage collector we create a [large] buffer
* so as to leave only a limited amount of heap memory available.
*/
long memUsed = HeapMemory.instance().memoryConsumed();
long memAvail = HeapMemory.instance().memoryRemaining();
System.out.println("HEAP Memory, used: " + memUsed + " avail: " + memAvail);
if (bSiz_pct > 0.0) {
_sMemBuff = new byte[(int)(memAvail * (bSiz_pct / 100.0))];
memUsed = HeapMemory.instance().memoryConsumed();
memAvail = HeapMemory.instance().memoryRemaining();
System.out.println("CURRENT HEAP Memory, used: " + memUsed + " avail: " +
memAvail);
}
/* create periodic thread: */
RealtimeThread realtimeThread = new RealtimeThread(priortyParameters,periodicParameters)
{
public void run() {
/* Prime period execution */
waitForNextPeriod();
/*
* Because the 1st period starts when the thread is first released (and not
02/19/13 Www.aicas.com 5/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 6/12
* when the waitForNextPeriod() method is first called), we throw away the
* very first period for more uniform statistics.
*/
waitForNextPeriod();
AbsoluteTime prevT = clock.getTime();
RTPStats pStats = new RTPStats();
RTPStats eStats = new RTPStats();
/*
* Create locals outside of performance test loop for efficiency
*/
AbsoluteTime currT = new AbsoluteTime();
RelativeTime deltaT = new RelativeTime();
boolean onTime;
for (int n=1; n <= testCount; n++)
{
onTime = waitForNextPeriod();
clock.getTime(currT);
currT.subtract(prevT, deltaT);pStats.accumTimeDelta(onTime, deltaT);
//System.out.println(n + " deltaT = " + deltaT + ((onTime) ? "" : " LATE"));
prevT.set(currT);
clock.getTime(currT);
currT.subtract(prevT, deltaT);
eStats.accumTimeDelta(deltaT);
}
/* Report results */
int nOvrun = pStats.getNumOverruns();
double avg_td = pStats.getAvgTimeDelta();
double min_td = pStats.getMinTimeDelta();
double max_td = pStats.getMaxTimeDelta();
System.out.println("AvgPeriod: " + avg_td + " msec MaxUnder: " +
(avg_td - min_td) * 1000.0 + " usec
MaxOver: " +
02/19/13 Www.aicas.com 6/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 7/12
(max_td - avg_td) * 1000.0 + " usecOverrun: " +
nOvrun + " out of " + testCount);
double avg_et = eStats.getAvgTimeDelta();
double min_et = eStats.getMinTimeDelta();
double max_et = eStats.getMaxTimeDelta();
System.out.println("AvgEXEC: " + avg_et + " msec MinExec: " +
min_et + " msec MaxExec: " + max_et + "
msec");
long memUsed = HeapMemory.instance().memoryConsumed();
long memAvail = HeapMemory.instance().memoryRemaining();
System.out.println("FINAL HEAP Memory, used: " + memUsed + " avail: " +memAvail);
}
};
/* start periodic thread: */
realtimeThread.start();
}
}
02/19/13 Www.aicas.com 7/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 8/12
Test Setup Linux (Heap: 10MB, Pre-allocated:50%)
For this test setup the Jamaica distribution was used Jamaica-6.2-1-7722-awt-linux-i686-gcc3.3-
glibc2.3. For testing a Linux with PREEMPT RT patch (kernel 2.6.33.7.2-rt30rt30) and glibc 2.12
was used. The conf
The heap and max heap size for Jamaica was set to 10MB.
Note that for the JamaicaVM interpreted a heap of 2MB is sufficient and for the built applications
800KB (see end of document for results of those test runs).
JamaicaVM interpreted example with FIFO thread schedulingPolicyCommand line:
> jamaicavm_bin -Xms10MB -Xmx10MB -cp bin/ RTMain
Output Results:
RTLatencyTest tPer(0 ms, 500 us) bSiz(50.0%)
HEAP Memory, used: 6070016 avail: 4415744
CURRENT HEAP Memory, used: 7639168 avail: 2846592
AvgPeriod: 0.499294877 msec MaxUnder: 468.053877 usec MaxOver: 2352.840123 usec
Overrun: 10 out of 1000
AvgEXEC: 0.009341545 msec MinExec: 0.00824 msec MaxExec: 0.140843 msec
FINAL HEAP Memory, used: 7675136 avail: 2810624
Comments:
• The overruns occurred at the startup for the interpreted binary due to class loading and
initialization.
JamaicaVM Builder example with default schedulingPolicy (OTHER)
Command line:
> ./RTMain_SCHED_OTHER
Output Results:
RTLatencyTest tPer(0 ms, 500 us) bSiz(50.0%)
02/19/13 Www.aicas.com 8/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 9/12
HEAP Memory, used: 947296 avail: 9538464
CURRENT HEAP Memory, used: 5548832 avail: 4936928
AvgPeriod: 0.499339388 msec MaxUnder: 483.93938799999995 usec MaxOver:
17.910611999999993 usec Overrun: 1 out of 1000
AvgEXEC: 0.001479403 msec MinExec: 0.0014 msec MaxExec: 0.00192 msec
FINAL HEAP Memory, used: 5564640 avail: 4921120
JamaicaVM Builder example with schedulingPolicy FIFO
Command line:
> ./RTMain
Output Results:
RTLatencyTest tPer(0 ms, 500 us) bSiz(50.0%)
HEAP Memory, used: 947296 avail: 9538464
CURRENT HEAP Memory, used: 5548832 avail: 4936928AvgPeriod: 0.499995358 msec MaxUnder: 6.706358000000023 usec MaxOver:
2.9346419999999873 usec Overrun: 0 out of 1000
AvgEXEC: 0.00149682 msec MinExec: 0.00144 msec MaxExec: 0.002 msec
FINAL HEAP Memory, used: 5563840 avail: 4921920
Comments:
• The total jitter on the release period is slightly under 10 usec.
• The total jitter on the execution latency is 0.6 usec.
Test runs with less Heap Memory
JamaicaVM Builder example with schedulingPolicy=FIFO
Command line:
02/19/13 Www.aicas.com 9/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 10/12
> ./RTMain_800KB
Output Results:
RTLatencyTest tPer(0 ms, 500 us) bSiz(50.0%)
HEAP Memory, used: 780032 avail: 39168
CURRENT HEAP Memory, used: 798016 avail: 21184
AvgPeriod: 0.500012676 msec MaxUnder: 28.68267599999996 usec MaxOver:
32.43732399999999 usec Overrun: 0 out of 1000
AvgEXEC: 0.001412459 msec MinExec: 0.0014 msec MaxExec: 0.00192 msec
FINAL HEAP Memory, used: 808928 avail: 10272
Comments:
• The jitter on the release period increases to 60 usec with incremental increase in garbage
collector overhead as the percentage of available memory to total memory drops below
approximately 25%.
• Average execution time and execution jitter remain constant as no memory allocation occurs
in the execution path.
JamaicaVM interpreted
Command line:
> jamaicavm_bin -Xms2MB -Xmx2MB -cp bin/ RTMain
Output results:
RTLatencyTest tPer(0 ms, 500 us) bSiz(50.0%)
HEAP Memory, used: 2021344 avail: 75808
CURRENT HEAP Memory, used: 2051776 avail: 45376
AvgPeriod: 0.499952157 msec MaxUnder: 468.472157 usec MaxOver: 1569.5648429999997 usec
Overrun: 5 out of 1000
AvgEXEC: 0.009372334 msec MinExec: 0.00832 msec MaxExec: 0.235045 msec
FINAL HEAP Memory, used: 2058112 avail: 39040
02/19/13 Www.aicas.com 10/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 11/12
Comments:
• Overruns occur at startup as with the previous interpreted test.
• Average execution time and jitter remains constant as no memory allocation occurs in the
execution path
02/19/13 Www.aicas.com 11/12
7/29/2019 Rtmain Results Published
http://slidepdf.com/reader/full/rtmain-results-published 12/12
Sources, Build Files, and Profile Location
The full project may be found in a public dropbox.
URL: https://dl.dropbox.com/u/26503273/RTMainExample.zip
02/19/13 Www.aicas.com 12/12