|
Message
From: cvs at opencores.org<cvs@o...>
Date: Tue Dec 18 01:30:21 CET 2007
Subject: [cvs-checkins] MODIFIED: jop ...
Date: 00/07/12 18:01:30 Added: jop/java/target/src/common/com/jopdesign/io/examples IHwithGC.java MeasureIH.java ScheduledIH.java Log: more IH examples Revision Changes Path 1.1 jop/java/target/src/common/com/jopdesign/io/examples/IHwithGC.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/common/com/jopdesign/io/examples/IHwithGC.java?rev=1.1&content-type=text/x-cvsweb-markup Index: IHwithGC.java =================================================================== package com.jopdesign.io.examples; import com.jopdesign.io.IOFactory; import com.jopdesign.io.SerialPort; import com.jopdesign.io.SysDevice; import com.jopdesign.sys.Const; import com.jopdesign.sys.GC; import com.jopdesign.sys.Native; import joprt.RtThread; import joprt.SwEvent; /** * Work in progress to play with GC and IH. * * @author martin * */ public class IHwithGC { static class HFThread extends RtThread { public HFThread(int prio, int us) { super(prio, us); period = us; } int period; int expected; int max, min; int cnt; boolean notFirst; public void run() { for (;;) { waitForNextPeriod(); int t = Native.rdMem(Const.IO_US_CNT); if (!notFirst) { expected = t+period; notFirst = true; } else { int diff = t-expected; if (diff>max) max = diff; if (diff<min) min = diff; // if (++cnt==1000000) { // result(); // } expected += period; } work(); } } void work() { ts = Native.rdMem(Const.IO_CNT); sw.fire(); } void result() { System.out.println("max="+max); System.out.println("min="+min); for (;;); } } static class EH extends SwEvent { public EH(int priority, int minTime) { super(priority, minTime); } int max; public void handle() { te = Native.rdMem(Const.IO_CNT); int diff = te-ts-to; // System.out.print(diff); // System.out.print(" IH max="); if (diff>max) max = diff; // System.out.println(max); // System.out.print(JVMHelp.ts-ts-to); // System.out.print(" "); } } // static Vector v; static SimpleList sl;
static class MFThread extends HFThread {
int nr;
public MFThread(int prio, int us) {
super(prio, us);
}
void work() {
sl.append(new Integer(nr));
++nr;
}
}
static class LFThread extends HFThread {
int expNr;
public LFThread(int prio, int us) {
super(prio, us);
}
void work() {
Object o;
while ((o = sl.remove())!=null) {
if (((Integer) o).intValue()!=expNr) {
System.out.println("List problem");
}
++expNr;
}
}
}
static class GCThread extends RtThread {
public GCThread() {
super(1, PERIOD_GC);
GC.setConcurrent();
}
public void run() {
for (;;) {
System.out.print("G");
GC.gc();
waitForNextPeriod();
}
}
}
static class LogThread extends RtThread {
public LogThread(int prio, int us) {
super(prio, us);
}
public void run() {
for (;;) {
waitForNextPeriod();
System.out.println();
if (hft!=null) {
System.out.print("hft max=");
System.out.println(hft.max);
System.out.print("hft min=");
System.out.println(hft.min);
}
if (mft!=null) {
System.out.print("mft max=");
System.out.println(mft.max);
System.out.print("mft min=");
System.out.println(mft.min);
}
if (sw!=null) {
System.out.print("sw max=");
System.out.println(sw.max);
}
}
}
}
static HFThread hft;
static MFThread mft;
// 200 is without jitter when running it alone
// 500 without jitter when a second dummy thread runs
// change to 200us on the 100 MHz version
// at 100 MHz, RtThreadImp TIM_OFF at 2:
// 200 us without jitter when run alone
// with output thread 10 us
// with prod/cons threads (no GC) 16 us
// with GC 72 us (77 us)
// public static final int PERIOD_HIGH = 100;
// public static final int PERIOD_MEDIUM = 1000;
// public static final int PERIOD_LOW = 10000;
// public static final int PERIOD_GC = 200000;
// public static final int PERIOD_HIGH = 107; // 211; // 107;
// public static final int PERIOD_MEDIUM = 1009;
// public static final int PERIOD_LOW = 10853;
// public static final int PERIOD_GC = 200183;
// for slower JOP versions (<100MHz)
public static final int PERIOD_HIGH = 2000; // 211; // 107;
public static final int PERIOD_MEDIUM = 4000;
public static final int PERIOD_LOW = 40000;
public static final int PERIOD_GC = 400000;
static int ts, te, to;
static EH sw;
static SysDevice sys;
/**
* @param args
*/
public static void main(String[] args) {
IOFactory fact = IOFactory.getFactory();
SerialPort sp = fact.getSerialPort();
sys = fact.getSysDevice();
ScheduledIH ih = new ScheduledIH();
fact.registerInterruptHandler(1, ih);
sw = new EH(6, 1000);
sl = new SimpleList();
hft = new HFThread(5, PERIOD_HIGH);
mft = new MFThread(4, PERIOD_MEDIUM);
new LFThread(3, PERIOD_LOW);
new GCThread();
new LogThread (2, 1000*1000);
RtThread.startMission();
for (;;);
}
}
class SimpleList {
class Element {
Object element;
Element next;
}
Element first, last;
public void append(Object o) {
Element e = new Element();
e.element = o;
synchronized (this) {
if (last!=null) {
last.next = e;
} else {
first = e;
}
last = e;
}
}
public Object remove() {
Object o = null;
synchronized (this) {
if (first!=null) {
Element e = first;
o = e.element;
first = e.next;
if (first==null) {
last = null;
}
}
}
return o;
}
}
1.1 jop/java/target/src/common/com/jopdesign/io/examples/MeasureIH.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/common/com/jopdesign/io/examples/MeasureIH.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: MeasureIH.java
===================================================================
package com.jopdesign.io.examples;
import util.Timer;
import com.jopdesign.io.*;
import com.jopdesign.sys.*;
public class MeasureIH implements Runnable {
static int ts, te, to;
public static void main(String[] args) {
IOFactory fact = IOFactory.getFactory();
SerialPort sp = fact.getSerialPort();
SysDevice sys = fact.getSysDevice();
MeasureIH ih = new MeasureIH();
fact.registerInterruptHandler(1, ih);
System.out.println("Measure IH respons time");
// enable software interrupt 1
fact.enableInterrupt(1);
// measure overhead
ts = Native.rdMem(Const.IO_CNT);
sys.swInterrupt = 2;
te = Native.rdMem(Const.IO_CNT);
to = te-ts;
ts = Native.rdMem(Const.IO_CNT);
for (int i=0; i<200; ++i) {
// Timer.wd();
// int t = Timer.getTimeoutMs(200);
// while (!Timer.timeout(t));
ts = Native.rdMem(Const.IO_CNT);
// trigger a SW interrupt via the system HW object
sys.swInterrupt = 1;
}
}
public void run() {
te = Native.rdMem(Const.IO_CNT);
System.out.print(te-ts-to);
System.out.print(" ");
System.out.print(JVMHelp.ts-ts-to);
System.out.print(" ");
}
}
1.1 jop/java/target/src/common/com/jopdesign/io/examples/ScheduledIH.java
http://www.opencores.org/cvsweb.shtml/jop/java/target/src/common/com/jopdesign/io/examples/ScheduledIH.java?rev=1.1&content-type=text/x-cvsweb-markup
Index: ScheduledIH.java
===================================================================
package com.jopdesign.io.examples;
import joprt.*;
import util.Timer;
import com.jopdesign.io.*;
import com.jopdesign.sys.*;
public class ScheduledIH implements Runnable {
static int ts, te, to;
static SwEvent sw;
static SysDevice sys;
public static void main(String[] args) {
IOFactory fact = IOFactory.getFactory();
SerialPort sp = fact.getSerialPort();
sys = fact.getSysDevice();
ScheduledIH ih = new ScheduledIH();
fact.registerInterruptHandler(1, ih);
sw = new SwEvent(10, 1000) {
public void handle() {
te = Native.rdMem(Const.IO_CNT);
System.out.print(te-ts-to);
System.out.print(" ");
// System.out.print(JVMHelp.ts-ts-to);
// System.out.print(" ");
}
};
new RtThread(9, 100000) {
public void run() {
for (;;) {
ts = Native.rdMem(Const.IO_CNT);
// trigger a SW interrupt via the system HW object
// sw.fire();
sys.swInterrupt = 1;
waitForNextPeriod();
}
}
};
System.out.println("Measure IH respons time with RT scheduling");
// enable all interrupts
fact.enableInterrupt(-1);
// measure overhead
ts = Native.rdMem(Const.IO_CNT);
sys.swInterrupt = 2;
te = Native.rdMem(Const.IO_CNT);
to = te-ts;
RtThread.startMission();
for (int i=0; i<20; ++i) {
Timer.wd();
// RtThread.sleepMs(200);
int t = Timer.getTimeoutMs(200);
while (!Timer.timeout(t));
}
}
public void run() {
// do we have to enable interrupts for the
// timer interrupt fire? I don't think so
// Native.wr(1, Const.IO_INT_ENA);
sw.fire();
}
}
|
 |