1 package edu.berkeley.slipway.demos;
6 import com.atmel.fpslic.*;
7 import edu.berkeley.slipway.*;
8 import edu.berkeley.slipway.gui.*;
9 import edu.berkeley.slipway.util.*;
10 import static com.atmel.fpslic.FpslicConstants.*;
14 * This demo runs the asynchronous micropipeline fifo experiment from
17 * Output is placed in misc/data/async/ as a collection of .csv
18 * files. Each file is named sizeXXX.csv, where XXX is the capacity
19 * of the fifo. Each line of each file is of the form
20 * occupancy,tokenrate where occupancy is the proportion of the fifo
21 * which is occupied (a number between 0 and 1) and tokenrate is the
22 * number of millions of tokens per second observed at a fixed point
23 * on the ring. All files should be concatenated in order to
24 * reproduce the graphs in the paper.
26 public abstract class MicropipelineFifoDemo {
28 public SlipwayBoard slipway;
29 public FpslicDevice fpslic;
30 public FpslicDevice.Cell start;
32 // Abstract methods to implement //////////////////////////////////////////////////////////////////////////////
34 protected abstract int numDivisors();
35 protected abstract void forceMasterSuccessor(boolean high);
36 protected abstract void unForceMasterSuccessor(boolean state);
37 protected abstract void unPauseMaster();
38 protected abstract void unPauseSlaves();
39 protected abstract void pauseMaster();
40 protected abstract void pauseSlaves();
41 protected abstract void resetAll();
42 protected abstract int init(int size);
43 protected abstract int init(int size, FpslicDevice.Cell start);
45 // Constructors //////////////////////////////////////////////////////////////////////////////
47 public MicropipelineFifoDemo() throws Exception {
48 System.err.println("MicropipelineFifoDemo: initializing board...");
49 slipway = new SlipwayBoard();
50 fpslic = slipway.getFpslicDevice();
53 public void mainx(String[] s) throws Exception {
54 System.err.println("MicropipelineFifoDemo: setting up scan cell...");
55 ExperimentUtils.setupScanCell(fpslic);
57 for(int i=0; i<255; i++) {
58 slipway.readInterruptCount();
59 System.err.print("\rMicropipelineFifoDemo: paranoia -- flushing interrupt count: " + i + "/254 ");
63 for(int i=1; i<402; i+=2) go(i);
64 System.err.println("MicropipelineFifoDemo: experiment is finished");
68 // Experiment Logic //////////////////////////////////////////////////////////////////////////////
71 protected void drain() {
78 slipway.readInterruptCount();
79 try { Thread.sleep(100); } catch (Exception e) { }
80 int rc = slipway.readInterruptCount();
82 System.err.println("flush() failed => " + rc);
83 try { Thread.sleep(1000); } catch (Exception e) { }
90 /** fill the fifo with "count" tokens */
91 protected void fill(int count) {
93 for(int i=0; i<count; i++) {
95 forceMasterSuccessor(yes);
100 unForceMasterSuccessor(!yes);
103 public void go(int size) throws Exception {
104 int rsize = init(size, fpslic.cell(20, 20));
106 String sizes = rsize+"";
107 while(sizes.length()<3) sizes = "0"+sizes;
108 String fname = "misc/data/async/size"+sizes+".csv";
109 if (!new File(fname).exists()) {
110 System.err.println();
111 System.err.println("MicropipelineFifoDemo: fifo size is "+rsize+"...");
112 PrintWriter outfile = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fname)));
113 for(int i=rsize; i>=0; i-=2)
114 test(i, rsize, outfile);
118 System.out.println("MicropipelineFifoDemo: file " + fname + " already exists; skipping");
122 public void test(int count, int size, PrintWriter outfile) throws Exception {
123 double[] results = new double[numtrials];
126 int clockdivisor = 64;
127 double occupancy = ((double)count)/((double)size);
128 int clockrate = 24; // (in mhz)
130 for(int i=0; i<results.length; i++) {
142 slipway.readInterruptCount();
144 int tokens = slipway.readInterruptCount();
146 double elapsed = (double)(slipway.readInterruptCountTime()/clockrate);
149 for(int j=0; j<numDivisors(); j++) multiplier *= 2;
150 multiplier /= clockdivisor;
152 double result = (tokens*multiplier)/elapsed; // in millions
157 double min = Double.MAX_VALUE;
159 for(int i=0; i<numtrials; i++) {
160 max = Math.max(max, results[i]);
161 min = Math.min(min, results[i]);
166 total /= (numtrials-2);
168 // result is transitions/sec
169 outfile.println(size + ", " + occupancy + ", " + total);
171 System.out.println("num_tokens/capacity: "+count+"/"+size+
172 " occupancy="+((int)(occupancy*100.0)) +"%"+
173 " tokenrate=" + total);
175 private static final int numtrials = 5;
177 protected FpslicDevice.Cell topLeft() { return start.north().north(); }