head	1.2;
access;
symbols
	bg2_23:1.2
	bg2_22:1.2
	bg2_21:1.2
	bg2_20:1.2
	bg2_16:1.2
	bg2_15:1.2;
locks; strict;
comment	@# @;


1.2
date	2008.06.16.08.17.29;	author martin;	state Exp;
branches;
next	1.1;
commitid	336a485621944567;

1.1
date	2008.06.14.16.44.19;	author martin;	state Exp;
branches;
next	;
commitid	4104853f5604567;


desc
@@


1.2
log
@no message
@
text
@/*
  This file is part of JOP, the Java Optimized Processor
    see <http://www.jopdesign.com/>

  Copyright (C) 2001-2008, Martin Schoeberl (martin@@jopdesign.com)

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package gcinc;

import java.util.Vector;

import util.Dbg;

import com.jopdesign.sys.Const;
import com.jopdesign.sys.GC;
import com.jopdesign.sys.Native;

import joprt.RtThread;

public class LatencyBigArray {

	final static int ARRAY_LENGTH = 256*1024/4;
	final static int ARRAY_SIZE = ARRAY_LENGTH*4;
	final static int HEAP_SIZE = 300*1024;
	
	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() {
			// nothing for the HF thread
		}
		
		void result() {
			Dbg.wr("max=", max);
			Dbg.wr("max=", min);
			for (;;);
		}
	}
	
//	static Vector v;
	static SimpleList sl;
	
	
	static class GCThread extends RtThread {

		public GCThread() {
			super(1, PERIOD_GC);
			GC.setConcurrent();
		}
		
		public void run() {
			for (;;) {
				Dbg.wr('G');
				GC.gc();
				waitForNextPeriod();
			}
		}
	}
	
	/**
	 * Use Dbg instead 
	 * @@author martin
	 *
	 */
	static class LogThread extends RtThread {
	
		public LogThread(int prio, int us) {
			super(prio, us);
		}

		public void run() {
			for (;;) {
				waitForNextPeriod();
				if (hft!=null) {
					Dbg.wr("hft max=", hft.max);
					Dbg.wr("hft min=", hft.min);
				}
			}
		}

	}
	
	static HFThread hft;

	// Changes in the scheduler to get low latency values:
	//		TIM_OFF to 2
	//		omit time adjustments on a missed deadline in
	//		waitForNextPeriod()
	// Results for 100 MHz:
	// 		107 is without jitter when running it alone
	public static final int PERIOD_HIGH = 107;
	public static final int PERIOD_GC = 1000; 
	
	
	/**
	 * @@param args
	 */
	public static void main(String[] args) {

		Dbg.initSerWait();
//		v = new Vector(20);
		sl = new SimpleList();
		
		System.out.print("Number of arrays: ");
		System.out.println(HEAP_SIZE/ARRAY_SIZE);
		for (int i=0; i<HEAP_SIZE/ARRAY_SIZE; ++i) {
			sl.append(new int[ARRAY_LENGTH]);
		}
		
		
		hft = new HFThread(5, PERIOD_HIGH);
		new LogThread (2, 1000*1000);
		
		new GCThread();
		
		RtThread.startMission();
		
		// that one is mandatory to get low latency!
		// check RtThreadImpl why.
		for (;;);
	}

}
@


1.1
log
@new latency test with big arrays
@
text
@d35 1
a35 1
	final static int ARRAY_LENGTH = 1*1024/4;
d148 2
@

