Explorar el Código

reduced offline gtt sending time

Boyoung- hace 8 años
padre
commit
e27a10f70e

+ 32 - 18
ObliVMGC/com/oblivm/backend/gc/regular/GCEva.java

@@ -1,5 +1,7 @@
 package com.oblivm.backend.gc.regular;
 
+import java.util.Arrays;
+
 import com.oblivm.backend.flexsc.Flag;
 import com.oblivm.backend.flexsc.Mode;
 import com.oblivm.backend.gc.GCEvaComp;
@@ -48,23 +50,35 @@ public class GCEva extends GCEvaComp {
 	}
 
 	private void receiveGTT() {
-		try {
-			if (timer != null)
-				timer.start(p, m);
-
-			Flag.sw.startGCIO();
-			GCSignal.receive(channel, gtt[0][1]);
-			GCSignal.receive(channel, gtt[1][0]);
-			GCSignal.receive(channel, gtt[1][1]);
-			// gtt[1][0] = GCSignal.receive(channel);
-			// gtt[1][1] = GCSignal.receive(channel);
-			Flag.sw.stopGCIO();
-
-			if (timer != null)
-				timer.stop(p, m);
-		} catch (Exception e) {
-			e.printStackTrace();
-			System.exit(1);
+		if (timer == null) {
+			try {
+				Flag.sw.startGCIO();
+				GCSignal.receive(channel, gtt[0][1]);
+				GCSignal.receive(channel, gtt[1][0]);
+				GCSignal.receive(channel, gtt[1][1]);
+				// gtt[1][0] = GCSignal.receive(channel);
+				// gtt[1][1] = GCSignal.receive(channel);
+				Flag.sw.stopGCIO();
+			} catch (Exception e) {
+				e.printStackTrace();
+				System.exit(1);
+			}
+		} else {
+			timer.start(p, m);
+			byte[] rows = channel.sender.read();
+			timer.stop(p, m);
+
+			gtt[0][1].bytes = Arrays.copyOfRange(rows, 0, GCSignal.len);
+			gtt[1][0].bytes = Arrays.copyOfRange(rows, GCSignal.len, GCSignal.len * 2);
+			gtt[1][1].bytes = Arrays.copyOfRange(rows, GCSignal.len * 2, rows.length);
+
+			/*
+			 * timer.start(p, m); GCSignal[] rows = channel.sender.readObject();
+			 * timer.stop(p, m);
+			 * 
+			 * gtt[0][1].bytes = rows[0].bytes; gtt[1][0].bytes = rows[1].bytes;
+			 * gtt[1][1].bytes = rows[2].bytes;
+			 */
 		}
 	}
 
@@ -86,7 +100,7 @@ public class GCEva extends GCEvaComp {
 				if (curr == null) {
 					curr = this;
 				} else {
-					curr.next = new GCEva(channel);
+					curr.next = new GCEva(channel, timer, p, m);
 					curr = curr.next;
 				}
 				curr.receiveGTT();

+ 28 - 15
ObliVMGC/com/oblivm/backend/gc/regular/GCGen.java

@@ -79,21 +79,34 @@ public class GCGen extends GCGenComp {
 	}
 
 	private void sendGTT() {
-		try {
-			if (timer != null)
-				timer.start(p, m);
-
-			Flag.sw.startGCIO();
-			toSend[0][1].send(channel);
-			toSend[1][0].send(channel);
-			toSend[1][1].send(channel);
-			Flag.sw.stopGCIO();
-
-			if (timer != null)
-				timer.stop(p, m);
-		} catch (Exception e) {
-			e.printStackTrace();
-			System.exit(1);
+		if (timer == null) {
+			try {
+				Flag.sw.startGCIO();
+				toSend[0][1].send(channel);
+				toSend[1][0].send(channel);
+				toSend[1][1].send(channel);
+				Flag.sw.stopGCIO();
+			} catch (Exception e) {
+				e.printStackTrace();
+				System.exit(1);
+			}
+		} else {
+			byte[] rows = new byte[GCSignal.len * 3];
+			System.arraycopy(toSend[0][1].bytes, 0, rows, 0, GCSignal.len);
+			System.arraycopy(toSend[1][0].bytes, 0, rows, GCSignal.len, GCSignal.len);
+			System.arraycopy(toSend[1][1].bytes, 0, rows, GCSignal.len * 2, GCSignal.len);
+
+			timer.start(p, m);
+			channel.receiver.write(rows);
+			timer.stop(p, m);
+
+			/*
+			 * GCSignal[] rows = new GCSignal[3]; rows[0] = toSend[0][1];
+			 * rows[1] = toSend[1][0]; rows[2] = toSend[1][1];
+			 * 
+			 * timer.start(p, m); channel.receiver.write(rows); timer.stop(p,
+			 * m);
+			 */
 		}
 	}
 

+ 16 - 0
src/exceptions/TimerException.java

@@ -0,0 +1,16 @@
+package exceptions;
+
+public class TimerException extends RuntimeException {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	public TimerException() {
+		super();
+	}
+
+	public TimerException(String message) {
+		super(message);
+	}
+}

+ 0 - 16
src/exceptions/TimingException.java

@@ -1,16 +0,0 @@
-package exceptions;
-
-public class TimingException extends RuntimeException {
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-
-	public TimingException() {
-		super();
-	}
-
-	public TimingException(String message) {
-		super(message);
-	}
-}

+ 10 - 1
src/protocols/Retrieve.java

@@ -82,6 +82,11 @@ public class Retrieve extends Protocol {
 	public void run(Party party, Metadata md, Forest forest) {
 		int records = 5;
 		int repeat = 5;
+		int cycles = records * repeat;
+		int abandRatio = 5; // 20%
+		int abandCycles = 0;
+		if (cycles > 1)
+			abandCycles = (cycles - 2) / abandRatio + 1;
 
 		int tau = md.getTau();
 		int numTrees = md.getNumTrees();
@@ -99,6 +104,9 @@ public class Retrieve extends Protocol {
 			long N = Util.nextLong(numInsert, Crypto.sr);
 
 			for (int j = 0; j < repeat; j++) {
+				if (i * records + j == abandCycles)
+					timer.reset();
+
 				System.out.println("Test: " + i + " " + j);
 				System.out.println("N=" + BigInteger.valueOf(N).toString(2));
 
@@ -188,7 +196,8 @@ public class Retrieve extends Protocol {
 			}
 		}
 
-		// timer.print();
+		System.out.println();
+		timer.divideBy(cycles - abandCycles).print();
 
 		// System.out.println();
 		// System.out.println(sw.toMS());

+ 1 - 1
src/util/M.java

@@ -1,7 +1,6 @@
 package util;
 
 public class M {
-	public static final int size = 6;
 
 	public static final int online_comp = 0;
 	public static final int online_write = 1;
@@ -12,4 +11,5 @@ public class M {
 
 	public static final String[] names = { "online_comp", "online_write", "online_read", "offline_comp",
 			"offline_write", "offline_read" };
+	public static final int size = names.length;
 }

+ 15 - 0
src/util/StopWatch.java

@@ -88,4 +88,19 @@ public class StopWatch {
 		else
 			return task + "\n" + out;
 	}
+
+	public StopWatch divideBy(int n) {
+		if (isOn) {
+			try {
+				throw new StopWatchException("StopWatch is still running");
+			} catch (StopWatchException e) {
+				e.printStackTrace();
+			}
+		}
+
+		StopWatch sw = new StopWatch(task);
+		sw.elapsedWC = elapsedWC / n;
+		sw.elapsedCPU = elapsedCPU / n;
+		return sw;
+	}
 }

+ 27 - 4
src/util/Timer.java

@@ -2,7 +2,7 @@ package util;
 
 import java.util.Stack;
 
-import exceptions.TimingException;
+import exceptions.TimerException;
 
 public class Timer {
 	StopWatch[][] watches;
@@ -16,10 +16,15 @@ public class Timer {
 		stack = new Stack<StopWatch>();
 	}
 
+	public Timer(StopWatch[][] sws) {
+		watches = sws;
+		stack = new Stack<StopWatch>();
+	}
+
 	public void start(int p, int m) {
 		if (!stack.empty()) {
 			if (stack.peek() == watches[p][m])
-				throw new TimingException("Stopwatch already added to stack");
+				throw new TimerException("Stopwatch already added to stack");
 			stack.peek().stop();
 		}
 		stack.push(watches[p][m]).start();
@@ -27,17 +32,35 @@ public class Timer {
 
 	public void stop(int p, int m) {
 		if (stack.empty())
-			throw new TimingException("No stopwatch found");
+			throw new TimerException("No stopwatch found");
 		stack.pop().stop();
 		if (!stack.empty())
 			stack.peek().start();
 	}
 
+	public void reset() {
+		if (!stack.empty())
+			throw new TimerException("Stack not empty");
+		for (int i = 0; i < watches.length; i++)
+			for (int j = 0; j < watches[i].length; j++)
+				watches[i][j].reset();
+	}
+
 	public void print() {
 		if (!stack.empty())
-			throw new TimingException("Stack not empty");
+			throw new TimerException("Stack not empty");
 		for (int i = 0; i < watches.length; i++)
 			for (int j = 0; j < watches[i].length; j++)
 				System.out.println(watches[i][j].toMS());
 	}
+
+	public Timer divideBy(int n) {
+		if (!stack.empty())
+			throw new TimerException("Stack not empty");
+		StopWatch[][] sws = new StopWatch[P.size][M.size];
+		for (int i = 0; i < watches.length; i++)
+			for (int j = 0; j < watches[i].length; j++)
+				sws[i][j] = watches[i][j].divideBy(n);
+		return new Timer(sws);
+	}
 }