Commit 4ec63703 authored by uahhx's avatar uahhx

sync

TODO: buffer behaviour check.
WHAT. WHY. WHAT IS HAPPENING. HALP.
check why globaltimestamp w/o wait is getting these ridiculous buffer usages/number of live packets
parent 6a3a2564
......@@ -9,6 +9,7 @@ public class DataPacket {
private int latencyCounter = 0;
private int lastCounter = 1;
private int timeStamp; //for beeva, but also used by global timestamp strategy
private int finalAge = -1;
//private boolean isControlPacket; //might want to implement just unsing a bool later on, for info it might be better to use the enum though
......@@ -82,4 +83,12 @@ public class DataPacket {
public int getTimeStamp() {
return timeStamp;
}
public int getFinalAge() {
return finalAge;
}
public void setFinalAge(int currentCycle) {
this.finalAge = currentCycle-timeStamp;
}
}
......@@ -17,17 +17,21 @@ public class FunnelNet {
//public static final int dataWidth = 64/8; //dataWidth in number of segments per transmission. this should be a round number even if it wasn't forced by type.
public static final int bufferSize = 3; //max # of packets per buffer
public static final int bufferSize = 24; //max # of packets per buffer
//public static final int bufferSize = 4 + packetLatency*2; //max # of packets per buffer
public final int realTimeConstraint = 10000; //RTC in ns
public final int nodeClock = 125; //node Clockspeed in MHz
public final int rtcCycles = 12;//(realTimeConstraint*nodeClock)/1000; //warning: put this back
public final int rtcCycles = (realTimeConstraint*nodeClock)/1000; //warning: put this back
private int numDownConnections = 1;//7; //total number of connections is this+1
private int numSlaves = 1; //7*7*7*7;
private int numDownConnections;//7; //total number of connections is this+1
private int numSlaves; //7*7*7*7;
private int numLayers; //0 based!
private int minNetLayers = 5;
private int minNetLayers;
public int minRT = Integer.MAX_VALUE;
public int maxRT = 0;
public long cumulativeRT = 0;
public MasterNode master = null;
public HashSet<NetNode> netNodes = new HashSet<NetNode>();
......@@ -47,7 +51,7 @@ public class FunnelNet {
}
public FunnelNet(Strategy strategy) { //for now no numUpConnections
initFunnelNet(strategy, numSlaves, numDownConnections, minNetLayers);
initFunnelNet(strategy, 1, 1, 0);
}
private void initFunnelNet(Strategy strategy, int numSlaves, int numDownConnections, int minNetLayers) {
......@@ -125,7 +129,7 @@ public class FunnelNet {
//for (int i = 0; i < newSlaveNodes.length - homogeneousReduction - (inhomogeneousReduction > 0 ? 1 : 0); i++) {
SlaveNode[] newSlaveNodes = new SlaveNode[numNewNodes - homogeneousReduction - (inhomogeneousReduction > 0 ? 1 : 0)];
for (int j = 0; j < newSlaveNodes.length; j++) {
SlaveNode curNewNode = new SlaveNode(layerNumber, curNode.getNodeNumber()*numNewNodes+j, this);
SlaveNode curNewNode = new SlaveNode(layerNumber, curNode.getNodeNumber()*numNewNodes+j, this, 1f/numSlaves);
curNewNode.setSuperNeighbor(curNode);
curNewNode.setSubNeighbors(new Node[0]);
newSlaveNodes[j] = curNewNode;
......@@ -164,4 +168,8 @@ public class FunnelNet {
public Strategy getStrategy() {
return this.strategy;
}
public void printMe(String printMe) {
System.out.println(cycleCounter + ": " + printMe);
}
}
\ No newline at end of file
......@@ -2,9 +2,13 @@ package FunnelNetSim.Nodes;
import FunnelNetSim.DataPacket;
import FunnelNetSim.FunnelNet;
import FunnelNetSim.SimHost;
public class MasterNode extends Node {
private int topAge = 0;
public int noOOOEx = 0;
public MasterNode(int layerNumber, int nodeNumber, FunnelNet parentNet) {
super(layerNumber, nodeNumber, parentNet);
}
......@@ -19,11 +23,24 @@ public class MasterNode extends Node {
super.tick();
//select receive element
if (superIncoming != null)
System.out.println("WHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAT");
superIncoming = selectFromFrontRow(); //uses the superIncoming variable because downwardCom refers to it. /should/ run smoothly. TODO: make sure this actually does run smoothly
if (superIncoming == null) {
//parentNet.printMe("MASTER IDLE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
if (superIncoming != null) {
System.out.println("Master processing " + superIncoming.toString());
if (SimHost.verbose)
System.out.println("Master processing " + superIncoming.toString());
superIncoming.setMState(DataPacket.messageState.PROCESSED);
if (superIncoming.getTimeStamp() < topAge) {
//parentNet.printMe("!!!!!!!!!!!! out of order execution");
noOOOEx++;
}
else
topAge = superIncoming.getTimeStamp();
}
downwardCom();
//send element back
}
......
......@@ -162,11 +162,11 @@ public abstract class Node {
* Warning: Evaluate if it is possible for the super buffers to run over due to start/stop messages' priority
*/
protected void downwardCom() {
//get new super DataPacket destination
int superIncDest = superIncoming != null ? getLocalOrigin(superIncoming.getOrigin()) : -1;
SlinkyBuffer<DataPacket> curSubBuf;
SlinkyBuffer<DataPacket> curSuperBuf;
DataPacket selectedMessage;
DataPacket superPrev = superIncoming;
int superIncDest = superIncoming == null ? -1 : getLocalOrigin(superIncoming.getOrigin());
for (int i = 0; i < subNeighbors.length; i++) {
selectedMessage = null;
curSubBuf = subBuffers.get(i);
......@@ -187,15 +187,15 @@ public abstract class Node {
if (curSubBuf.limitReached() == subSendEnableM[i]) { //if the limit is reached and the sub is currently allowed to send (or vice versa), send control packet
subSendEnableM[i] = !curSubBuf.limitReached();
selectedMessage = new DataPacket(-1, parentNet.packetLatency, parentNet.getCycleCounter(), DataPacket.messageType.STOPSTART); //send StartStop K-Flagged segment.
if(SimHost.verbose || true) {
if(SimHost.verbose) {
System.out.println(nodeID() + " SubBuffer no." + i + (subSendEnableM[i] ? " free again" : " reached limit"));
if (superIncDest == i)
System.out.println("!!!!! This blocked message " + (curSuperBuf.isEmpty() ? superIncoming.getPacketID() : curSuperBuf.lookAtBuffer().getPacketID()));
parentNet.printMe("!!!!! This blocked message " + (curSuperBuf.isEmpty() ? superIncoming.getPacketID() : curSuperBuf.lookAtBuffer().getPacketID()));
}
}
else if (!curSuperBuf.isEmpty() || superIncDest == i) {
selectedMessage = curSuperBuf.isEmpty() ? superIncoming : curSuperBuf.takeFromBuffer();
if (curSuperBuf.isEmpty())
if (superIncDest == i)
superIncoming = null;
}
}
......@@ -203,7 +203,7 @@ public abstract class Node {
curSuperBuf.add(superIncoming);
superIncoming = null;
if (curSuperBuf.limitReached())
System.out.println("a superbuffer hit limit! this should not be happening!"); //NOTE: use this <PLACE> to check super buffer fill state later (implement buffer.size())
parentNet.printMe("a superbuffer hit limit! this should not be happening!"); //NOTE: use this <PLACE> to check super buffer fill state later (implement buffer.size())
}
if (selectedMessage != null)
send(selectedMessage, subNeighbors[i]);
......
......@@ -4,10 +4,40 @@ import FunnelNetSim.DataPacket;
import FunnelNetSim.FunnelNet;
import FunnelNetSim.SimHost;
import java.util.Random;
public class SlaveNode extends Node {
public SlaveNode(int layerNumber, int nodeNumber, FunnelNet parentNet) {
private static Random rnd = new Random();
private float fireChance; //can be set individually to create scenarios that result in unbalanced load
private boolean packetSent = false;
private boolean waitForAnswer = false;// = true;
private boolean resendOnReject = false;
private boolean rejected = false;
private int deadTimeCounter = 0;
private int deadTime = 0; //deadTime == 0 effectively disables it
public SlaveNode(int layerNumber, int nodeNumber, FunnelNet parentNet, float fireChance, boolean waitForAnswer, int deadTime, boolean resendOnReject) {
super(layerNumber, nodeNumber, parentNet);
initSlaveNode(fireChance, waitForAnswer, deadTime, resendOnReject);
}
public SlaveNode(int layerNumber, int nodeNumber, FunnelNet parentNet, float fireChance) {
super(layerNumber, nodeNumber, parentNet);
initSlaveNode(fireChance, waitForAnswer, deadTime, resendOnReject);
}
// public SlaveNode(int layerNumber, int nodeNumber, FunnelNet parentNet) {
// super(layerNumber, nodeNumber, parentNet);
// initSlaveNode(0f, true);
// }
private void initSlaveNode(float fireChance, boolean waitForAnswer, int deadTime, boolean resendOnReject) {
this.fireChance = fireChance;
this.waitForAnswer = waitForAnswer;
this.deadTime = deadTime;
this.resendOnReject = resendOnReject;
}
@Override
......@@ -19,28 +49,40 @@ public class SlaveNode extends Node {
public void tick() {
super.tick();
if (superIncoming != null) {
superIncoming.setFinalAge(parentNet.getCycleCounter());
int age = superIncoming.getFinalAge();
if (SimHost.verbose)
System.out.println("--------- Message no. " + superIncoming.getPacketID() + " from " + superIncoming.getOrigin() +
" returned to " + getNodeNumber() + " after " + (parentNet.getCycleCounter() - superIncoming.getTimeStamp()) + " cycles");
" returned to " + getNodeNumber() + " after " + (age) + " cycles");
parentNet.livePackets.remove(superIncoming);
if (superIncoming.getMState() == DataPacket.messageState.REJECTED)
parentNet.rejectedPackets.add(superIncoming);
else if (superIncoming.getMState() == DataPacket.messageState.PROCESSED)
else if (superIncoming.getMState() == DataPacket.messageState.PROCESSED) {
parentNet.successfulPackets.add(superIncoming);
if (age < parentNet.minRT)
parentNet.minRT = age;
if (age > parentNet.maxRT)
parentNet.maxRT = age;
parentNet.cumulativeRT += age;
}
else
System.out.println("Returned packet was of unexpected mState " + superIncoming.getMState().toString());
packetSent = false;
}
if (deadTimeCounter > 0)
deadTimeCounter--;
if (!(waitForAnswer && packetSent) && deadTimeCounter <= 0 && ((resendOnReject && rejected) || rnd.nextFloat() < fireChance)) {
rejected = false; //must be before createPacket() because that one can set it right back to true
packetSent = createPacket();
deadTimeCounter = deadTime;
}
}
public void tick(boolean spawnPacket) {
tick();
if(spawnPacket && !createPacket())
System.out.println("couldn't spawn packet");
}
public boolean createPacket() {
DataPacket newPacket = new DataPacket(this.getNodeNumber(), parentNet.packetLatency, parentNet.getCycleCounter(), DataPacket.messageType.REGULAR);
if (superBuffers.isEmpty() && superSendEnableS) {
DataPacket newPacket = new DataPacket(this.getNodeNumber(), parentNet.packetLatency, parentNet.getCycleCounter(), DataPacket.messageType.REGULAR);
parentNet.livePackets.add(newPacket);
send(newPacket, superNeighbor);
if (SimHost.verbose)
......@@ -49,6 +91,10 @@ public class SlaveNode extends Node {
}
//if (SimHost.verbose)
System.out.println("!!!!!!!!! could not create new Packet!");
newPacket.setFinalAge(0);
rejected = true;
parentNet.rejectedPackets.add(newPacket);
return false;
}
......
package FunnelNetSim;
import FunnelNetSim.Nodes.Node;
import FunnelNetSim.Nodes.SlaveNode;
import FunnelNetSim.Strategies.GlobalTimeStamp;
import FunnelNetSim.Strategies.TestStrategy;
import FunnelNetSim.Strategies.GlobalTimeStampPlus;
import FunnelNetSim.Strategies.RoundRobin;
import FunnelNetSim.Visualizers.PseudoGraphics;
import java.io.IOException;
public class SimHost {
public static final boolean verbose = false;//true;
......@@ -21,10 +19,15 @@ public class SimHost {
// }
// System.out.println(i);
// }
run();
// test1();
test2();
// for (int i = 0; i < 15; i++) {
// System.out.println("-");
// }
// System.out.println();
}
private static void run() {
private static void test1() {
//FunnelNet net = new FunnelNet(new TestStrategy());
//FunnelNet net = new FunnelNet(new TestStrategy(), 8, 2, 1);
FunnelNet net = new FunnelNet(new GlobalTimeStamp(), 9, 2, 1);
......@@ -60,4 +63,24 @@ public class SimHost {
System.out.println("no of dropped packets: " + net.droppedPackets.size());
}
private static void test2() {
FunnelNet net = new FunnelNet(new GlobalTimeStamp(), 27*3*3*3, 3, 0);
for (int i = 0; i < 1000000; i++) {
int cycleNo = net.tickNet();
if (cycleNo % 1000 == 0) {
System.out.println(cycleNo +": Average RT: " + net.cumulativeRT / (float) net.successfulPackets.size() + ", # LivePackets: " + net.livePackets.size());
}
}
System.out.println("no of live packets: " + net.livePackets.size());
System.out.println("no of successful packets: " + net.successfulPackets.size());
System.out.println("no of rejected packets: " + net.rejectedPackets.size());
System.out.println("no of dropped packets: " + net.droppedPackets.size());
System.out.println("Min RT: " + net.minRT);
System.out.println("Max RT: " + net.maxRT);
System.out.println("Average RT: " + net.cumulativeRT/(float)net.successfulPackets.size());
System.out.println("Number of OOOEx: " + net.master.noOOOEx);
}
}
package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
import FunnelNetSim.SimHost;
public class GlobalTimeStamp extends Strategy {
@Override
public int selectForwardingSub(DataPacket[] frontRow) {
boolean visited = false;
int oldest = -1;
int oldestStamp = Integer.MAX_VALUE;
for (int i = 0; i < frontRow.length; i++) {
DataPacket curPacket = frontRow[i];
if (curPacket != null)
visited = true;
if (curPacket != null && !shouldReject(curPacket)) {
if (curPacket.getTimeStamp() < oldestStamp) {
......@@ -20,6 +23,8 @@ public class GlobalTimeStamp extends Strategy {
}
//return i;
}
if (visited && oldest <= -1) //TODO: removeme
System.out.println("NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
return oldest;
}
......
package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
public class GlobalTimeStampPlus extends Strategy {
int curRRPointer = 0;
@Override
public int selectForwardingSub(DataPacket[] frontRow) {
int oldest = -1;
int oldestStamp = Integer.MAX_VALUE;
for (int i = 0; i < frontRow.length; i++) {
int pointer = (i + curRRPointer) % frontRow.length;
DataPacket curPacket = frontRow[pointer];
if (curPacket != null && !shouldReject(curPacket)) {
if (curPacket.getTimeStamp() < oldestStamp) {
oldest = pointer;
oldestStamp = curPacket.getTimeStamp();
}
}
//return i;
}
curRRPointer = (oldest + 1) % frontRow.length;
return oldest;
}
@Override
protected boolean shouldReject(DataPacket packet) {
//TODO: implement a predictive rejection (reject if it can't make the trip, based on optimal layer latency
if (parentNode.parentNet.getCycleCounter() - packet.getTimeStamp() > parentNode.parentNet.rtcCycles) {
packet.setMState(dropPackets ? DataPacket.messageState.DROP : DataPacket.messageState.REJECTED);
return true;
}
return false;
}
@Override
public Strategy makeNew() {
return new GlobalTimeStampPlus();
}
}
package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
public class RoundRobin extends Strategy {
int curRRPointer = 0;
@Override
public int selectForwardingSub(DataPacket[] frontRow) {
for (int i = 0; i < frontRow.length; i++) {
int pointer = (i + curRRPointer) % frontRow.length;
if (frontRow[pointer] != null) {
curRRPointer = (pointer + 1) % frontRow.length;
return pointer;
}
}
return 0;
}
@Override
protected boolean shouldReject(DataPacket packet) {
return false; //RR can not reject
}
@Override
public Strategy makeNew() {
return new RoundRobin();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment