/// <summary> /// This function is called in response to invoke-scheduler function in the zing model. /// </summary> /// <param name="Params"></param> public void Invoke(ZingerSchedulerState ZSchedulerState, params object[] Params) { var param1_operation = (string)Params[0]; if (param1_operation == "map") { var Param2_PprocessId = (int)Params[1]; ZSchedulerState.Map(Param2_PprocessId); } else if (param1_operation == "enabled") { var param2_target = (int)Params[1]; var param3_source = (int)Params[2]; OnEnabled(ZSchedulerState, param2_target, param3_source); } else if (param1_operation == "blocked") { var param2_source = (int)Params[1]; OnBlocked(ZSchedulerState, param2_source); } else if (param1_operation == "zingerop") { ZingerOperation(ZSchedulerState, Params); } else { OtherOperations(ZSchedulerState, Params); } }
/// <summary> /// Returns the first element in the list. /// </summary> /// <param name="zSchedState"></param> /// <returns>The next process to be executed</returns> public override int Next(ZingerSchedulerState zSchedState) { var SchedState = zSchedState as RoundRobinDBSchedulerState; if (SchedState.enabledProcesses.Count == 0) return -1; else return SchedState.enabledProcesses.ElementAt(0); }
/// <summary> /// Perform the delay operation. Move process at the start of the list to the end. /// </summary> /// <param name="zSchedState"></param> public override void Delay(ZingerSchedulerState zSchedState) { //Console.WriteLine("Delayed"); var SchedState = zSchedState as RoundRobinDBSchedulerState; if (SchedState.enabledProcesses.Count == 0) return; //remove the current process and push it at the back of the queue. var delayProcess = SchedState.enabledProcesses.ElementAt(0); SchedState.enabledProcesses.RemoveAt(0); SchedState.enabledProcesses.Add(delayProcess); //one delay operation performed zSchedState.numOfTimesCurrStateDelayed++; }
public FrontierNode(TraversalInfo ti) { this.Bounds = new ZingerBounds(ti.zBounds.ExecutionCost, ti.zBounds.ChoiceCost); if (ZingerConfiguration.DoDelayBounding) { schedulerState = ti.ZingDBSchedState.Clone(true); } else if (ZingerConfiguration.DoPreemptionBounding) { preemptionBounding = ti.preemptionBounding.Clone(); } ti.IsFingerPrinted = true; TheTrace = ti.GenerateTrace(); }
public void Deserialize(Stream inputStream) { BinaryReader bReader = new BinaryReader(inputStream); this.Bounds = new ZingerBounds(); this.Bounds.ExecutionCost = bReader.ReadInt32(); this.Bounds.ChoiceCost = bReader.ReadInt32(); if (ZingerConfiguration.DoDelayBounding) { BinaryFormatter bFormat = new BinaryFormatter(); bFormat.Binder = new AllowAllAssemblyVersionsDeserializationBinder(); this.schedulerState = (ZingerSchedulerState)bFormat.Deserialize(inputStream); } Int32 traceCount = bReader.ReadInt32(); UInt32[] steps = new UInt32[traceCount]; for (int i = 0; i < traceCount; i++) { steps[i] = bReader.ReadUInt32(); } this.TheTrace = new Trace(steps); }
/// <summary> /// The Delay operation drops the last scheduled process such that it is never scheduled again /// for that state. /// </summary> /// <param name="zSchedState"></param> public override void Delay(ZingerSchedulerState zSchedState) { var SchedState = zSchedState as RandomDBSchedulerState; // Drop the element SchedState.setOfProcesses.Remove(SchedState.scheculedProcess); zSchedState.numOfTimesCurrStateDelayed++; return; }
/// <summary> /// This function is called by Zinger whenever a new process is created. /// Add the new created process at the end of RR list. /// </summary> /// <param name="processId"> process Id of the newly created process</param> public override void Start(ZingerSchedulerState ZSchedulerState, int processId) { var SchedState = ZSchedulerState as RoundRobinDBSchedulerState; ZSchedulerState.Start(processId); //add the process to the enabled processes list SchedState.enabledProcesses.Add(processId); }
/// <summary> /// This function is called when an enqueue is performed on a process, hence it has a pending event to be serviced. /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="targetSM"> targetSM is the target process in which the event was enqueued. /// This process is pushed on top of the stack to follow event enqueue order.</param> /// <param name="sourceSM">This parameter is passed for debugging purposes</param> public override void OnEnabled(ZingerSchedulerState ZSchedulerState, int targetSM, int sourceSM) { var SchedState = ZSchedulerState as RTCDBSchedulerState; var procId = SchedState.GetZingProcessId(targetSM); if (!SchedState.DBStack.Contains(procId)) SchedState.DBStack.Push(procId); }
/// <summary> /// This function is provided for extending or customizing the delayingExplorer. /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="Params"></param> public override void ZingerOperation(ZingerSchedulerState ZSchedulerState, params object[] Params) { //do nothing }
/// <summary> /// Remove the completed process from Stack so that it is never scheduled again. /// </summary> /// <param name="processId">Process id to be removed from the stack</param> public override void Finish(ZingerSchedulerState zSchedState, int processId) { var SchedState = zSchedState as RTCDBSchedulerState; Stack<int> tempStack = new Stack<int>(); while (SchedState.DBStack.Count != 0) { int topStack; if ((topStack = SchedState.DBStack.Pop()) == processId) { break; } else { tempStack.Push(topStack); } } while (tempStack.Count != 0) { SchedState.DBStack.Push(tempStack.Pop()); } }
/// <summary> /// Return process at the top of stack. /// This process is executed next and follows the deterministic schedule. /// </summary> /// <returns>next process to be scheduled</returns> public override int Next(ZingerSchedulerState zSchedState) { var SchedState = zSchedState as RTCDBSchedulerState; if (SchedState.DBStack.Count == 0) return -1; return SchedState.DBStack.Peek(); }
/// <summary> /// This function is called by Zinger whenever a process has finished execution. /// Remove the process from list of enabled processes. /// </summary> /// <param name="processId"> process Id of the completed process</param> public override void Finish(ZingerSchedulerState ZSchedulerState, int processId) { var schedState = ZSchedulerState as RoundRobinDBSchedulerState; schedState.enabledProcesses.Remove(processId); }
/// <summary> /// This function is called by Zinger to obtain next process to be scheduled. /// </summary> /// <returns>process Id of next process to be scheduled</returns> public abstract int Next(ZingerSchedulerState ZSchedulerState);
protected TraversalInfo(StateImpl s, StateType st, TraversalInfo pred, Via bt) { stateType = st; Via = bt; NumProcesses = s.NumProcesses; ProcessInfo = s.GetProcessInfo(); events = s.GetEvents(); exception = s.Exception; IsAcceptingState = s.IsAcceptingState; //initialize the plugin information. if (pred != null) { Predecessor = pred; CurrentDepth = pred.CurrentDepth + 1; zBounds = new ZingerBounds(pred.zBounds.ExecutionCost, pred.zBounds.ChoiceCost); zBounds.IncrementDepthCost(); doDelay = false; if (ZingerConfiguration.DoDelayBounding) { ZingDBSchedState = s.ZingDBSchedState; ZingDBScheduler = s.ZingDBScheduler; } else if (ZingerConfiguration.DoPreemptionBounding) { preemptionBounding = new ZingPreemptionBounding(ProcessInfo, NumProcesses, Predecessor.preemptionBounding.currentProcess); } if (ZingerConfiguration.DronacharyaEnabled || ZingerConfiguration.IsPluginEnabled) { ZingerPlugin = s.ZingerPlugin; ZingerPluginState = s.ZingerPluginState; } pred.Successor = this; MagicBit = pred.MagicBit; } else { zBounds = new ZingerBounds(); MagicBit = false; CurrentDepth = 0; if (ZingerConfiguration.DoDelayBounding) { ZingDBSchedState = s.ZingDBSchedState.Clone(false); ZingDBScheduler = s.ZingDBScheduler; } else if (ZingerConfiguration.DoPreemptionBounding) { preemptionBounding = new ZingPreemptionBounding(ProcessInfo, NumProcesses, 0); } if (ZingerConfiguration.DronacharyaEnabled || ZingerConfiguration.IsPluginEnabled) { ZingerPlugin = s.ZingerPlugin; ZingerPluginState = s.ZingerPluginState.Clone(); } } }
/// <summary> /// This function is called by Zinger whenever a new process is created. /// </summary> /// <param name="processId"> process Id of the newly created process</param> public abstract void Start(ZingerSchedulerState ZSchedulerState, int processId);
/// <summary> /// Unhandled operation or a special operation. /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="Params"></param> public virtual void OtherOperations(ZingerSchedulerState ZSchedulerState, params object[] Params) { throw new Exception("This operation is not supported by the delaying scheduler"); }
/// <summary> /// This function is called when a P process is enabled. /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="targetSM"></param> /// <param name="sourceSM"></param> public abstract void OnEnabled(ZingerSchedulerState ZSchedulerState, int targetSM, int sourceSM);
/// <summary> /// This function is called when a P process is blocked on a dequeue /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="sourceSM"></param> public abstract void OnBlocked(ZingerSchedulerState ZSchedulerState, int sourceSM);
/// <summary> /// This function is used internally by the ZING explorer. /// It checks if we have applied the maximum number of delays in the current state. /// Applying any more delay operations will not lead to new transitions/states being explored. /// Maximum delay operations for a state is always (totalEnabledProcesses - 1). /// </summary> /// <param name="zSchedState"></param> /// <returns>If max bound for the given state has reached</returns> public override bool MaxDelayReached(ZingerSchedulerState zSchedState) { var SchedState = zSchedState as RoundRobinDBSchedulerState; return zSchedState.numOfTimesCurrStateDelayed >= (SchedState.enabledProcesses.Count - 1); }
/// <summary> /// This function is called by Zinger whenever a process has finished execution (terminated). /// </summary> /// <param name="processId"> process Id of the completed process</param> public override void Finish(ZingerSchedulerState ZSchedulerState, int processId) { var schedState = (ZSchedulerState as RandomDBSchedulerState); schedState.EnabledProcesses.Remove(processId); schedState.setOfProcesses.Remove(processId); }
/// <summary> /// This function is called when a process is blocked on dequeue. /// There are no more events to be serviced and the queue is empty. /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="sourceSM">Process that is blocked</param> public override void OnBlocked(ZingerSchedulerState ZSchedulerState, int sourceSM) { var SchedState = (ZSchedulerState as RoundRobinDBSchedulerState); var procId = SchedState.GetZingProcessId(sourceSM); SchedState.enabledProcesses.Remove(procId); }
/// <summary> /// Randomly return a process from the set of processes SetOfProcesses not yet delayed. /// </summary> /// <param name="zSchedState"></param> /// <returns></returns> public override int Next(ZingerSchedulerState zSchedState) { var SchedState = zSchedState as RandomDBSchedulerState; if (SchedState.setOfProcesses.Count() == 0) return -1; var index = SchedState.randGen.Next(0, SchedState.setOfProcesses.Count); var procId = SchedState.setOfProcesses.ElementAt(index); SchedState.scheculedProcess = procId; return procId; }
/// <summary> /// This function is used internally by the ZING explorer. /// It checks if we have applied the maximum number of delays in the current state. /// Applying any more delay operations will not lead to new transitions/states being explored. /// Maximum delay operations for a state is always (totalEnabledProcesses - 1). /// </summary> /// <param name="zSchedState"></param> /// <returns>If max bound for the given state has reached</returns> public override bool MaxDelayReached(ZingerSchedulerState zSchedState) { var SchedState = zSchedState as RTCDBSchedulerState; return zSchedState.numOfTimesCurrStateDelayed >= (SchedState.DBStack.Count - 1); }
/// <summary> /// This function is called when a process is blocked on dequeue. /// There are no more events to be serviced and the queue is empty. /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="sourceSM">Process that is blocked</param> public override void OnBlocked(ZingerSchedulerState ZSchedulerState, int sourceSM) { var SchedState = ZSchedulerState as RandomDBSchedulerState; var procId = SchedState.GetZingProcessId(sourceSM); // Console.WriteLine(SchedState.ToString()); SchedState.setOfProcesses.Remove(procId); SchedState.EnabledProcesses.Remove(procId); }
/// <summary> /// This function is called when a process is blocked. In the context of asynchronous message /// passing programs, a process is blocked when its queue is empty and the process is waiting for an event. /// The process that gets blocked is poped off the stack. /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="sourceSM">This parameter is passed for debugging purposes</param> public override void OnBlocked(ZingerSchedulerState ZSchedulerState, int sourceSM) { var SchedState = ZSchedulerState as RTCDBSchedulerState; if (SchedState.DBStack.Count > 0) { SchedState.DBStack.Pop(); } }
/// <summary> /// This function is called on a enqueue operation. A process is enabled /// if it has messages in its queue to be serviced /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="targetSM">process is added to the set of enabled processes</param> /// <param name="sourceSM"></param> public override void OnEnabled(ZingerSchedulerState ZSchedulerState, int targetSM, int sourceSM) { var SchedState = ZSchedulerState as RandomDBSchedulerState; var procId = SchedState.GetZingProcessId(targetSM); if (!SchedState.EnabledProcesses.Contains(procId)) { SchedState.EnabledProcesses.Add(procId); SchedState.setOfProcesses.Add(procId); } }
/// <summary> /// Push newly created process on top of Stack /// </summary> /// <param name="processId"> process Id of the newly created process</param> public override void Start(ZingerSchedulerState zSchedState, int processId) { var SchedState = zSchedState as RTCDBSchedulerState; SchedState.DBStack.Push(processId); SchedState.Start(processId); }
/// <summary> /// This function is called by Zinger whenever a new process is created. /// </summary> /// <param name="processId"> process Id of the newly created process</param> public override void Start(ZingerSchedulerState ZSchedulerState, int processId) { var schedState = (ZSchedulerState as RandomDBSchedulerState); ZSchedulerState.Start(processId); schedState.EnabledProcesses.Add(processId); schedState.setOfProcesses.Add(processId); }
/// <summary> /// Move the process on top of stack to the bottom of the stack. Moving the process to the bottom of the stack deviates /// the scheduler from following the casual order of events (RTC strategy). /// </summary> public override void Delay(ZingerSchedulerState zSchedState) { var SchedState = zSchedState as RTCDBSchedulerState; if (SchedState.DBStack.Count == 0) return; var topOfStack = SchedState.DBStack.Pop(); var tempStack = new Stack<int>(); while (SchedState.DBStack.Count != 0) { tempStack.Push(SchedState.DBStack.Pop()); } SchedState.DBStack.Push(topOfStack); while (tempStack.Count != 0) { SchedState.DBStack.Push(tempStack.Pop()); } zSchedState.numOfTimesCurrStateDelayed++; }
/// <summary> /// This function is called on a enqueue operation. A process is enabled /// if it has messages in its queue to be serviced /// </summary> /// <param name="ZSchedulerState"></param> /// <param name="targetSM">The process that is enabled because of an enqueue</param> /// <param name="sourceSM">This parameter is passed for debugging purposes</param> public override void OnEnabled(ZingerSchedulerState ZSchedulerState, int targetSM, int sourceSM) { var SchedState = (ZSchedulerState as RoundRobinDBSchedulerState); var procId = SchedState.GetZingProcessId(targetSM); if (!SchedState.enabledProcesses.Contains(procId)) SchedState.enabledProcesses.Add(procId); }