Ver código fonte

revert to version where eviction is pipelined but reshuffle, ppt, permutetarget, permuteindex are still sequential

Boyoung- 9 anos atrás
pai
commit
caafb59fac

+ 4 - 58
src/protocols/Eviction.java

@@ -9,7 +9,6 @@ import communication.Communication;
 import gc.GCUtil;
 import oram.Bucket;
 import oram.Forest;
-import oram.Global;
 import oram.Metadata;
 import oram.Tree;
 import oram.Tuple;
@@ -24,17 +23,10 @@ public class Eviction extends Protocol {
 
 	private int pid = P.EVI;
 
-	private Communication[] cons;
-
 	public Eviction(Communication con1, Communication con2) {
 		super(con1, con2);
 	}
 
-	public Eviction(Communication[] cons) {
-		super(cons[0], cons[1]);
-		this.cons = cons;
-	}
-
 	private int[] prepareEviction(int target[], int[] ti, int W) {
 		int d = ti.length;
 		int[] evict = new int[W * d];
@@ -163,33 +155,12 @@ public class Eviction extends Protocol {
 					(logW + 7) / 8);
 		}
 
-		PermuteTarget permutetarget = null;
-		int[] target_pp = null;
-		Timer t = null;
-		Thread thread = null;
-		if (!Global.pipeline) {
-			permutetarget = new PermuteTarget(con1, con2);
-			target_pp = permutetarget.runD(predata, firstTree, outKeys[0], timer);
-		} else {
-			permutetarget = new PermuteTarget(cons[2], cons[3]);
-			t = new Timer();
-			permutetarget.setArgs(Party.Debbie, predata, firstTree, outKeys[0], t);
-			thread = new Thread(permutetarget);
-			thread.start();
-		}
+		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
+		int[] target_pp = permutetarget.runD(predata, firstTree, outKeys[0], timer);
 
 		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
 		int[] ti_pp = permuteindex.runD(predata, firstTree, ti_p, w, timer);
 
-		if (Global.pipeline) {
-			try {
-				thread.join();
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-			target_pp = permutetarget.getReturn();
-		}
-
 		int W = (int) Math.pow(2, logW);
 		int[] evict = prepareEviction(target_pp, ti_pp, W);
 
@@ -203,9 +174,6 @@ public class Eviction extends Protocol {
 		OTi.setBucketsOnPath(new BigInteger(1, Li).longValue(), pathBuckets);
 
 		timer.stop(pid, M.online_comp);
-
-		if (Global.pipeline)
-			timer.add(t);
 	}
 
 	public void runC(PreData predata, boolean firstTree, Tuple[] originalPath, int d, int sw, int w, Timer timer) {
@@ -236,31 +204,12 @@ public class Eviction extends Protocol {
 		con2.write(pid, C_labelInputKeys);
 		timer.stop(pid, M.online_write);
 
-		PermuteTarget permutetarget = null;
-		Timer t = null;
-		Thread thread = null;
-		if (!Global.pipeline) {
-			permutetarget = new PermuteTarget(con1, con2);
-			permutetarget.runC(predata, firstTree, timer);
-		} else {
-			permutetarget = new PermuteTarget(cons[2], cons[3]);
-			t = new Timer();
-			permutetarget.setArgs(Party.Charlie, predata, firstTree, null, t);
-			thread = new Thread(permutetarget);
-			thread.start();
-		}
+		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
+		permutetarget.runC(predata, firstTree, timer);
 
 		PermuteIndex permuteindex = new PermuteIndex(con1, con2);
 		permuteindex.runC(predata, firstTree, timer);
 
-		if (Global.pipeline) {
-			try {
-				thread.join();
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-		}
-
 		int logW = (int) Math.ceil(Math.log(w + 1) / Math.log(2));
 		int W = (int) Math.pow(2, logW);
 		for (int i = 0; i < d; i++) {
@@ -296,9 +245,6 @@ public class Eviction extends Protocol {
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);
-
-		if (Global.pipeline)
-			timer.add(t);
 	}
 
 	// for testing correctness

+ 1 - 36
src/protocols/PermuteTarget.java

@@ -18,33 +18,14 @@ import util.P;
 import util.Timer;
 import util.Util;
 
-public class PermuteTarget extends Protocol implements Runnable {
+public class PermuteTarget extends Protocol {
 
 	private int pid = P.PT;
 
-	private Party party;
-	private PreData predata;
-	private boolean firstTree;
-	private GCSignal[][] targetOutKeys;
-	private Timer timer;
-	private int[] target;
-
 	public PermuteTarget(Communication con1, Communication con2) {
 		super(con1, con2);
 	}
 
-	public void setArgs(Party party, PreData predata, boolean firstTree, GCSignal[][] targetOutKeys, Timer timer) {
-		this.party = party;
-		this.predata = predata;
-		this.firstTree = firstTree;
-		this.targetOutKeys = targetOutKeys;
-		this.timer = timer;
-	}
-
-	public int[] getReturn() {
-		return target;
-	}
-
 	public void runE() {
 	}
 
@@ -119,22 +100,6 @@ public class PermuteTarget extends Protocol implements Runnable {
 		timer.stop(pid, M.online_comp);
 	}
 
-	@Override
-	public void run() {
-		if (party == Party.Eddie) {
-			runE();
-
-		} else if (party == Party.Debbie) {
-			target = runD(predata, firstTree, targetOutKeys, timer);
-
-		} else if (party == Party.Charlie) {
-			runC(predata, firstTree, timer);
-
-		} else {
-			throw new NoSuchPartyException(party + "");
-		}
-	}
-
 	// for testing correctness
 	@Override
 	public void run(Party party, Metadata md, Forest forest) {

+ 26 - 49
src/protocols/Pipeline.java

@@ -16,7 +16,8 @@ import util.Util;
 
 public class Pipeline extends Thread {
 
-	private Communication[] cons;
+	private Communication con1;
+	private Communication con2;
 	private Party party;
 	private PreData[] predata;
 	private Tree OTi;
@@ -27,9 +28,10 @@ public class Pipeline extends Thread {
 	private byte[] Li;
 	private OutAccess outaccess;
 
-	public Pipeline(Communication[] cons, Party party, PreData[] predata, Tree OTi, int h, Timer timer, Metadata md,
-			int treeIndex, byte[] Li, OutAccess outaccess) {
-		this.cons = cons;
+	public Pipeline(Communication con1, Communication con2, Party party, PreData[] predata, Tree OTi, int h,
+			Timer timer, Metadata md, int treeIndex, byte[] Li, OutAccess outaccess) {
+		this.con1 = con1;
+		this.con2 = con2;
 		this.party = party;
 		this.predata = predata;
 		this.OTi = OTi;
@@ -43,25 +45,14 @@ public class Pipeline extends Thread {
 
 	public void runE(PreData[] predata, Tree OTi, int h, Timer timer) {
 		// 1st eviction
-		Access access = new Access(cons[0], cons[1]);
-		Reshuffle reshuffle = new Reshuffle(cons[2], cons[3]);
-		PostProcessT postprocesst = new PostProcessT(cons[0], cons[1]);
-		UpdateRoot updateroot = new UpdateRoot(cons[0], cons[1]);
-		Eviction eviction = new Eviction(cons);
-
-		Timer t = new Timer();
-		reshuffle.setArgs(Party.Eddie, predata[0], outaccess.E_P, OTi.getTreeIndex() == 0, t);
-		Thread thread = new Thread(reshuffle);
-		thread.start();
-		Tuple Ti = postprocesst.runE(predata[0], outaccess.E_Ti, OTi.getTreeIndex() == h - 1, timer);
-		try {
-			thread.join();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		Tuple[] path = reshuffle.getReturn();
-		timer.add(t);
+		Access access = new Access(con1, con2);
+		Reshuffle reshuffle = new Reshuffle(con1, con2);
+		PostProcessT postprocesst = new PostProcessT(con1, con2);
+		UpdateRoot updateroot = new UpdateRoot(con1, con2);
+		Eviction eviction = new Eviction(con1, con2);
 
+		Tuple[] path = reshuffle.runE(predata[0], outaccess.E_P, OTi.getTreeIndex() == 0, timer);
+		Tuple Ti = postprocesst.runE(predata[0], outaccess.E_Ti, OTi.getTreeIndex() == h - 1, timer);
 		Tuple[] root = Arrays.copyOfRange(path, 0, OTi.getStashSize());
 		root = updateroot.runE(predata[0], OTi.getTreeIndex() == 0, outaccess.Li, root, Ti, timer);
 		System.arraycopy(root, 0, path, 0, root.length);
@@ -81,17 +72,14 @@ public class Pipeline extends Thread {
 
 	public void runD(PreData predata[], Tree OTi, Timer timer) {
 		// 1st eviction
-		Access access = new Access(cons[0], cons[1]);
-		Reshuffle reshuffle = new Reshuffle(cons[2], cons[3]);
-		PostProcessT postprocesst = new PostProcessT(cons[0], cons[1]);
-		UpdateRoot updateroot = new UpdateRoot(cons[0], cons[1]);
-		Eviction eviction = new Eviction(cons);
-
-		// no extra thread for D's reshuffle and postprocesst
-		// because D does nothing online in these two protocols
+		Access access = new Access(con1, con2);
+		Reshuffle reshuffle = new Reshuffle(con1, con2);
+		PostProcessT postprocesst = new PostProcessT(con1, con2);
+		UpdateRoot updateroot = new UpdateRoot(con1, con2);
+		Eviction eviction = new Eviction(con1, con2);
+
 		reshuffle.runD();
 		postprocesst.runD();
-
 		updateroot.runD(predata[0], OTi.getTreeIndex() == 0, Li, OTi.getW(), timer);
 		eviction.runD(predata[0], OTi.getTreeIndex() == 0, Li, OTi, timer);
 
@@ -103,26 +91,15 @@ public class Pipeline extends Thread {
 
 	public OutAccess runC(PreData[] predata, Metadata md, int ti, byte[] Li, Timer timer) {
 		// 1st eviction
-		Access access = new Access(cons[0], cons[1]);
-		Reshuffle reshuffle = new Reshuffle(cons[2], cons[3]);
-		PostProcessT postprocesst = new PostProcessT(cons[0], cons[1]);
-		UpdateRoot updateroot = new UpdateRoot(cons[0], cons[1]);
-		Eviction eviction = new Eviction(cons);
-
-		Timer t = new Timer();
-		reshuffle.setArgs(Party.Charlie, predata[0], outaccess.C_P, ti == 0, t);
-		Thread thread = new Thread(reshuffle);
-		thread.start();
+		Access access = new Access(con1, con2);
+		Reshuffle reshuffle = new Reshuffle(con1, con2);
+		PostProcessT postprocesst = new PostProcessT(con1, con2);
+		UpdateRoot updateroot = new UpdateRoot(con1, con2);
+		Eviction eviction = new Eviction(con1, con2);
+
+		Tuple[] path = reshuffle.runC(predata[0], outaccess.C_P, ti == 0, timer);
 		Tuple Ti = postprocesst.runC(predata[0], outaccess.C_Ti, Li, outaccess.C_Lip1, outaccess.C_j2,
 				ti == md.getNumTrees() - 1, timer);
-		try {
-			thread.join();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		Tuple[] path = reshuffle.getReturn();
-		timer.add(t);
-
 		Tuple[] root = Arrays.copyOfRange(path, 0, md.getStashSizeOfTree(ti));
 		root = updateroot.runC(predata[0], ti == 0, root, Ti, timer);
 		System.arraycopy(root, 0, path, 0, root.length);

+ 1 - 35
src/protocols/Reshuffle.java

@@ -21,32 +21,14 @@ import util.P;
 import util.Timer;
 import util.Util;
 
-public class Reshuffle extends Protocol implements Runnable {
+public class Reshuffle extends Protocol {
 
 	private int pid = P.RSF;
 
-	private Party party;
-	private PreData predata;
-	private Tuple[] path;
-	private boolean firstTree;
-	private Timer timer;
-
 	public Reshuffle(Communication con1, Communication con2) {
 		super(con1, con2);
 	}
 
-	public void setArgs(Party party, PreData predata, Tuple[] path, boolean firstTree, Timer timer) {
-		this.party = party;
-		this.predata = predata;
-		this.path = path;
-		this.firstTree = firstTree;
-		this.timer = timer;
-	}
-
-	public Tuple[] getReturn() {
-		return path;
-	}
-
 	public Tuple[] runE(PreData predata, Tuple[] path, boolean firstTree, Timer timer) {
 		if (firstTree)
 			return path;
@@ -90,22 +72,6 @@ public class Reshuffle extends Protocol implements Runnable {
 		return predata.reshuffle_a_prime;
 	}
 
-	@Override
-	public void run() {
-		if (party == Party.Eddie) {
-			path = runE(predata, path, firstTree, timer);
-
-		} else if (party == Party.Debbie) {
-			runD();
-
-		} else if (party == Party.Charlie) {
-			path = runC(predata, path, firstTree, timer);
-
-		} else {
-			throw new NoSuchPartyException(party + "");
-		}
-	}
-
 	// for testing correctness
 	@Override
 	public void run(Party party, Metadata md, Forest forest) {

+ 13 - 21
src/protocols/Retrieve.java

@@ -122,23 +122,20 @@ public class Retrieve extends Protocol {
 		OutAccess outaccess = access.runE(predata[0], OTi, Ni, Nip1_pr, timer[0]);
 
 		int ti = OTi.getTreeIndex();
-		Communication[] cons = new Communication[] { cons1[ti + 1], cons2[ti + 1], cons1[ti + h + 1],
-				cons2[ti + h + 1] };
-		Pipeline pipeline = new Pipeline(cons, Party.Eddie, predata, OTi, h, timer[ti + 1], null, ti, outaccess.Li,
-				outaccess);
+		Pipeline pipeline = new Pipeline(cons1[ti + 1], cons2[ti + 1], Party.Eddie, predata, OTi, h, timer[ti + 1],
+				null, ti, outaccess.Li, outaccess);
 		pipeline.start();
 
 		return pipeline;
 	}
 
-	public Pipeline pipelineD(PreData predata[], Tree OTi, byte[] Ni, byte[] Nip1_pr, int h, Timer[] timer) {
+	public Pipeline pipelineD(PreData predata[], Tree OTi, byte[] Ni, byte[] Nip1_pr, Timer[] timer) {
 		Access access = new Access(con1, con2);
 		byte[] Li = access.runD(predata[0], OTi, Ni, Nip1_pr, timer[0]);
 
 		int ti = OTi.getTreeIndex();
-		Communication[] cons = new Communication[] { cons1[ti + 1], cons2[ti + 1], cons1[ti + h + 1],
-				cons2[ti + h + 1] };
-		Pipeline pipeline = new Pipeline(cons, Party.Debbie, predata, OTi, h, timer[ti + 1], null, ti, Li, null);
+		Pipeline pipeline = new Pipeline(cons1[ti + 1], cons2[ti + 1], Party.Debbie, predata, OTi, 0, timer[ti + 1],
+				null, ti, Li, null);
 		pipeline.start();
 
 		return pipeline;
@@ -148,10 +145,8 @@ public class Retrieve extends Protocol {
 		Access access = new Access(con1, con2);
 		OutAccess outaccess = access.runC(md, ti, Li, timer[0]);
 
-		int h = md.getNumTrees();
-		Communication[] cons = new Communication[] { cons1[ti + 1], cons2[ti + 1], cons1[ti + h + 1],
-				cons2[ti + h + 1] };
-		Pipeline pipeline = new Pipeline(cons, Party.Charlie, predata, null, 0, timer[ti + 1], md, ti, Li, outaccess);
+		Pipeline pipeline = new Pipeline(cons1[ti + 1], cons2[ti + 1], Party.Charlie, predata, null, 0, timer[ti + 1],
+				md, ti, Li, outaccess);
 		pipeline.start();
 
 		return new OutRetrieve(outaccess, pipeline);
@@ -184,9 +179,6 @@ public class Retrieve extends Protocol {
 
 		long[] gates = new long[2];
 
-		PreData[][] predata = new PreData[numTrees][2];
-		PreRetrieve preretrieve = new PreRetrieve(con1, con2);
-
 		Pipeline[] threads = new Pipeline[numTrees];
 
 		sanityCheck();
@@ -214,6 +206,8 @@ public class Retrieve extends Protocol {
 				System.out.println("N=" + BigInteger.valueOf(N).toString(2));
 
 				System.out.print("Precomputation... ");
+				PreData[][] predata = new PreData[numTrees][2];
+				PreRetrieve preretrieve = new PreRetrieve(con1, con2);
 				for (int ti = 0; ti < numTrees; ti++) {
 					predata[ti][0] = new PreData();
 					predata[ti][1] = new PreData();
@@ -292,7 +286,7 @@ public class Retrieve extends Protocol {
 						} else {
 							if (ti == 0)
 								ete_on.start();
-							threads[ti] = pipelineD(predata[ti], OTi, sD_Ni, sD_Nip1_pr, numTrees, timer);
+							threads[ti] = pipelineD(predata[ti], OTi, sD_Ni, sD_Nip1_pr, timer);
 						}
 
 					} else if (party == Party.Charlie) {
@@ -347,7 +341,7 @@ public class Retrieve extends Protocol {
 
 		Timer sum = new Timer();
 		for (int i = 0; i < timer.length; i++)
-			sum.add(timer[i]);
+			sum = sum.add(timer[i]);
 		sum.noPrePrint();
 		System.out.println();
 
@@ -360,10 +354,8 @@ public class Retrieve extends Protocol {
 		Bandwidth[] bandwidth = new Bandwidth[P.size];
 		for (int i = 0; i < P.size; i++) {
 			bandwidth[i] = new Bandwidth(P.names[i]);
-			for (int j = 0; j < cons1.length; j++) {
-				bandwidth[i].add(cons1[j].bandwidth[i]);
-				bandwidth[i].add(cons2[j].bandwidth[i]);
-			}
+			for (int j = 0; j < cons1.length; j++)
+				bandwidth[i] = bandwidth[i].add(cons1[j].bandwidth[i].add(cons2[j].bandwidth[i]));
 			System.out.println(bandwidth[i].noPreToString());
 		}
 		System.out.println();

+ 1 - 1
src/ui/CLI.java

@@ -108,7 +108,7 @@ public class CLI {
 		System.out.println("Starting " + party + "...");
 
 		Metadata md = new Metadata(configFile);
-		int numComs = Global.pipeline ? md.getNumTrees() * 2 + 1 : 1;
+		int numComs = Global.pipeline ? md.getNumTrees() + 1 : 1;
 		Communication[] con1 = new Communication[numComs];
 		Communication[] con2 = new Communication[numComs];
 

+ 4 - 3
src/util/Bandwidth.java

@@ -25,11 +25,12 @@ public class Bandwidth {
 		bandwidth += n;
 	}
 
-	public void add(Bandwidth b) {
+	public Bandwidth add(Bandwidth b) {
 		if (!task.equals(b.task))
 			throw new BandwidthException("Task: " + task + " != " + b.task);
-
-		bandwidth = bandwidth + b.bandwidth;
+		Bandwidth total = new Bandwidth(task);
+		total.bandwidth = bandwidth + b.bandwidth;
+		return total;
 	}
 
 	public String noPreToString() {

+ 5 - 3
src/util/StopWatch.java

@@ -108,7 +108,7 @@ public class StopWatch {
 		return sw;
 	}
 
-	public void add(StopWatch s) {
+	public StopWatch add(StopWatch s) {
 		if (isOn || s.isOn) {
 			try {
 				throw new StopWatchException("StopWatch is still running");
@@ -125,7 +125,9 @@ public class StopWatch {
 			}
 		}
 
-		elapsedWC = elapsedWC + s.elapsedWC;
-		elapsedCPU = elapsedCPU + s.elapsedCPU;
+		StopWatch sw = new StopWatch(task);
+		sw.elapsedWC = elapsedWC + s.elapsedWC;
+		sw.elapsedCPU = elapsedCPU + s.elapsedCPU;
+		return sw;
 	}
 }

+ 4 - 2
src/util/Timer.java

@@ -74,12 +74,14 @@ public class Timer {
 		return new Timer(sws);
 	}
 
-	public void add(Timer t) {
+	public Timer add(Timer t) {
 		if (!stack.empty() || !t.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++)
-				watches[i][j].add(t.watches[i][j]);
+				sws[i][j] = watches[i][j].add(t.watches[i][j]);
+		return new Timer(sws);
 	}
 }