1 package edu.berkeley.slipway.demos;
6 import com.atmel.fpslic.*;
7 import edu.berkeley.slipway.*;
8 import edu.berkeley.slipway.gui.*;
9 import static com.atmel.fpslic.FpslicConstants.*;
13 * This demo runs the asynchronous micropipeline fifo experiment from
16 * Output is placed in misc/data/async/ as a collection of .csv
17 * files. Each file is named sizeXXX.csv, where XXX is the capacity
18 * of the fifo. Each line of each file is of the form
19 * occupancy,tokenrate where occupancy is the proportion of the fifo
20 * which is occupied (a number between 0 and 1) and tokenrate is the
21 * number of millions of tokens per second observed at a fixed point
22 * on the ring. All files should be concatenated in order to
23 * reproduce the graphs in the paper.
25 public abstract class MicropipelineFifoDemo {
27 public SlipwayBoard slipway;
28 public FpslicDevice fpslic;
29 public FpslicDevice.Cell start;
31 // Abstract methods to implement //////////////////////////////////////////////////////////////////////////////
33 protected abstract int numDivisors();
34 protected abstract void forceMasterSuccessor(boolean high);
35 protected abstract void unForceMasterSuccessor(boolean state);
36 protected abstract void unPauseMaster();
37 protected abstract void unPauseSlaves();
38 protected abstract void pauseMaster();
39 protected abstract void pauseSlaves();
40 protected abstract void resetAll();
41 protected abstract int init(int size);
42 protected abstract int init(int size, FpslicDevice.Cell start);
44 // Constructors //////////////////////////////////////////////////////////////////////////////
46 public MicropipelineFifoDemo() throws Exception {
47 System.err.println("MicropipelineFifoDemo: initializing board...");
48 slipway = new SlipwayBoard();
49 fpslic = slipway.getFpslicDevice();
52 public void mainx(String[] s) throws Exception {
53 System.err.println("MicropipelineFifoDemo: setting up scan cell...");
55 //if (s.length > 0 && s[0].equals("-g")) {
58 Gui vis = new Gui(fpslic, slipway, fpslic.getWidth(), fpslic.getHeight());
59 Frame fr = new Frame();
60 fr.setTitle("SLIPWAY Live Fabric Debugger");
61 fr.addKeyListener(vis);
62 fr.setLayout(new BorderLayout());
63 fr.add(vis, BorderLayout.CENTER);
72 ExperimentUtils.setupScanCell(fpslic);
74 for(int i=0; i<255; i++) {
75 slipway.readInterruptCount();
76 System.err.print("\rMicropipelineFifoDemo: paranoia -- flushing interrupt count: " + i + "/254 ");
80 for(int i=1; i<402; i+=2) go(i);
81 System.err.println("MicropipelineFifoDemo: experiment is finished");
85 // Experiment Logic //////////////////////////////////////////////////////////////////////////////
88 protected void drain() {
95 slipway.readInterruptCount();
96 try { Thread.sleep(100); } catch (Exception e) { }
97 int rc = slipway.readInterruptCount();
99 System.err.println("flush() failed => " + rc);
100 try { Thread.sleep(1000); } catch (Exception e) { }
107 /** fill the fifo with "count" tokens */
108 protected void fill(int count) {
110 for(int i=0; i<count; i++) {
112 forceMasterSuccessor(yes);
117 unForceMasterSuccessor(!yes);
120 public void go(int size) throws Exception {
121 int rsize = init(size, fpslic.cell(20, 20));
123 String sizes = rsize+"";
124 while(sizes.length()<3) sizes = "0"+sizes;
125 String fname = "misc/data/async/size"+sizes+".csv";
126 if (!new File(fname).exists()) {
127 System.err.println();
128 System.err.println("MicropipelineFifoDemo: fifo size is "+rsize+"...");
129 PrintWriter outfile = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fname)));
130 for(int i=rsize; i>=0; i-=2)
131 test(i, rsize, outfile);
135 System.out.println("MicropipelineFifoDemo: file " + fname + " already exists; skipping");
139 public void test(int count, int size, PrintWriter outfile) throws Exception {
140 double[] results = new double[numtrials];
143 int clockdivisor = 64;
144 double occupancy = ((double)count)/((double)size);
145 int clockrate = 24; // (in mhz)
147 for(int i=0; i<results.length; i++) {
159 slipway.readInterruptCount();
161 int tokens = slipway.readInterruptCount();
163 double elapsed = (double)(slipway.readInterruptCountTime()/clockrate);
166 for(int j=0; j<numDivisors(); j++) multiplier *= 2;
167 multiplier /= clockdivisor;
169 double result = (tokens*multiplier)/elapsed; // in millions
174 double min = Double.MAX_VALUE;
176 for(int i=0; i<numtrials; i++) {
177 max = Math.max(max, results[i]);
178 min = Math.min(min, results[i]);
183 total /= (numtrials-2);
185 // result is transitions/sec
186 outfile.println(size + ", " + occupancy + ", " + total);
188 System.out.println("num_tokens/capacity: "+count+"/"+size+
189 " occupancy="+((int)(occupancy*100.0)) +"%"+
190 " tokenrate=" + total);
192 private static final int numtrials = 5;
194 protected FpslicDevice.Cell topLeft() { return start.north().north(); }