DynaSeerImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Last Edited by: Louis Monier September 18, 1986 12:47:40 pm PDT
DIRECTORY Rope;
DynaSeerImpl:
CEDAR
PROGRAM
IMPORTS Rope
EXPORTS DynaSeer =
BEGIN OPEN DynaSeer;
CreateBusOp:
PROC [opcode: Opcode, owner:
INT, requestTime:
INT]
RETURNS [BusOp] ~ {
RETURN [NEW[BusOpRec ← [opcode: opcode, owner: owner, requestTime: requestTime]]];
};
BusOpToHistory:
PROC [busOp: BusOp]
RETURNS [h: History] ~ {
h ← NEW[HistoryRec[1]];
h[0] ← busOp;
};
ConcatHistories:
PROC [h0, h1: History]
RETURNS [h: History] ~ {
n0, n1: NAT;
IF h0=NIL THEN RETURN [h1];
IF h1=NIL THEN RETURN [h0];
h ← NEW[HistoryRec[h0.size+h1.size]];
FOR i:
NAT
IN [0..h0.size)
DO
h[i] ← h0[i];
ENDLOOP;
FOR i:
NAT
IN [0..h1.size)
DO
h[h0.size+i] ← h1[i];
ENDLOOP;
};
CreateHistory:
PROC [timeLimit:
INT]
RETURNS [history: History ←
NIL] ~ {
FOR time:
NAT
IN [0..timeLimit)
DO
history ← Arbiter[history];
ENDLOOP;
};
Arbiter:
PROC [past: History]
RETURNS [history: History] ~ {
FOR device: DeviceID
IN DeviceID
DO
Cycle[device, currentCycle];
ENDLOOP;
nextGrantee ← SelectNext[];
currentCycle ← requests[nextGrantee].intendedCycle;
history ← AppendToHistory[past, currentCycle];
};
proba: ARRAY Opcode OF INT;
thresholds: ARRAY Opcode OF INT;
proba[ProcOp] ← 2;
proba[Bubble] ← 2;
proba[NoOp] ← 2;
proba[MemOp] ← 2;
maxRandom: INT;
Processor:
PROC [n, time:
INT]
RETURNS [h: History] ~ {
random: INT ← Random.NextInt[randomSpace];
FOR op: Opcode
IN Opcode
DO
IF random<thresholds[op] THEN RETURN[opToHistory[op]];
ENDLOOP;
};
opToHistory: ARRAY Opcode OF History;
opToHistory[ProcOp] =
opToHistory[Bubble] =
opToHistory[NoOp] = NIL;
opToHistory[MemOp] =
ComputeThresholds:
PROC [proba:
ARRAY Opcode
OF
INT]
RETURNS [thresholds:
ARRAY Opcode
OF
INT, maxRandom:
INT ← 0] ~ {
FOR op: Opcode
IN Opcode
DO
maxRandom ← maxRandom+proba[op];
thresholds[op] ← current;
ENDLOOP;
};
-- Initialization
randomSpace: Random.RandomStream;
[thresholds, maxRandom] ← ComputeThresholds[proba];
randomSpace ← Random.Create[range: maxRandom];
END.