Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Cycle detection optimizations #224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Source/SchedulingStrategies/ISchedulingStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public interface ISchedulingStrategy
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState">Used for liveness checking, cache only at sends</param>
/// <returns>Boolean</returns>
bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current);
bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true);

/// <summary>
/// Returns the next boolean choice.
Expand Down
3 changes: 2 additions & 1 deletion Source/SchedulingStrategies/Strategies/DFS/DFSStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public DFSStrategy(int maxSteps, ILogger logger)
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
var enabledChoices = choices.Where(choice => choice.IsEnabled).ToList();
if (enabledChoices.Count == 0)
Expand Down
3 changes: 2 additions & 1 deletion Source/SchedulingStrategies/Strategies/DPOR/DPORStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ private void AbdandonReplay(bool clearNonDet)
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
next = null;
return GetNextHelper(ref next, choices, current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ public DelayBoundingStrategy(int maxSteps, int maxDelays, ILogger logger, IRando
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public virtual bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public virtual bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
var currentMachineIdx = choices.IndexOf(current);
var orderedMachines = choices.GetRange(currentMachineIdx, choices.Count - currentMachineIdx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public PCTStrategy(int maxSteps, int maxPrioritySwitchPoints, ILogger logger, IR
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
next = null;
return GetNextHelper(ref next, choices, current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public ProbabilisticRandomStrategy(int maxSteps, int numberOfCoinFlips, IRandomN
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public override bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public override bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
var enabledChoices = choices.Where(choice => choice.IsEnabled).ToList();
if (enabledChoices.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ public RandomStrategy(int maxSteps, IRandomNumberGenerator random)
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public virtual bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public virtual bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
var enabledChoices = choices.Where(choice => choice.IsEnabled).ToList();
if (enabledChoices.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ public BasicReductionStrategy(
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
next = null;
return GetNextHelper(ref next, choices, current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public ComboStrategy(ISchedulingStrategy prefixStrategy, ISchedulingStrategy suf
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
if (this.PrefixStrategy.HasReachedMaxSchedulingSteps())
{
Expand Down
2 changes: 1 addition & 1 deletion Source/TestingServices/Runtime/BugFindingRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using Microsoft.PSharp.TestingServices.Tracing.Error;
using Microsoft.PSharp.TestingServices.Tracing.Machines;
using Microsoft.PSharp.TestingServices.Tracing.Schedule;
using Microsoft.PSharp.IO;

namespace Microsoft.PSharp.TestingServices
{
Expand Down Expand Up @@ -1562,7 +1563,6 @@ internal Fingerprint GetProgramState()

fingerprint = new Fingerprint(hash);
}

return fingerprint;
}

Expand Down
6 changes: 5 additions & 1 deletion Source/TestingServices/Scheduling/BugFindingScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ internal void Schedule(OperationType operationType, OperationTargetType targetTy
var choices = this.SchedulableInfoMap.Values.OrderBy(choice => choice.Id).Select(choice => choice as ISchedulable).ToList();

ISchedulable next = null;
if (!this.Strategy.GetNext(out next, choices, current))
bool CheckCycle = false;
if (operationType.Equals(OperationType.Send)/* && !operationType.Equals(OperationType.Create)*/
/*&& !operationType.Equals(OperationType.Receive)*/)
CheckCycle = true;
if (!this.Strategy.GetNext(out next, choices, current, CheckCycle))
{
// Checks if the program has livelocked.
this.CheckIfProgramHasLivelocked(choices.Select(choice => choice as SchedulableInfo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ internal CycleDetectionStrategy(Configuration configuration, StateCache cache, S
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CheckCycle">CacheState</param>
/// <returns>Boolean</returns>
public override bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public override bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CheckCycle = false)
{
CaptureAndCheckProgramState();
CaptureAndCheckProgramState(CheckCycle);

if (IsReplayingCycle)
{
Expand Down Expand Up @@ -333,7 +334,7 @@ public override bool IsFair()
/// <summary>
/// Captures the program state and checks for liveness violations.
/// </summary>
private void CaptureAndCheckProgramState()
private void CaptureAndCheckProgramState(bool CheckCycle = false)
{
if (this.ScheduleTrace.Count == 0)
{
Expand All @@ -346,7 +347,7 @@ private void CaptureAndCheckProgramState()
Fingerprint fingerprint;
bool stateExists = StateCache.CaptureState(out capturedState, out fingerprint,
FingerprintIndexMap, ScheduleTrace.Peek(), Monitors);
if (stateExists)
if (stateExists && CheckCycle)
{
Debug.WriteLine("<LivenessDebug> Detected potential infinite execution.");
CheckLivenessAtTraceCycle(FingerprintIndexMap[fingerprint]);
Expand Down Expand Up @@ -449,20 +450,21 @@ private void CheckLivenessAtTraceCycle(List<int> indices)
var scheduleStep = ScheduleTrace[i];
PotentialCycle.Add(scheduleStep);
PotentialCycleFingerprints.Add(scheduleStep.State.Fingerprint);
Debug.WriteLine("<LivenessDebug> Cycle contains {0} with {1}.",
scheduleStep.Type, scheduleStep.State.Fingerprint.ToString());
}

DebugPrintScheduleTrace();
//DebugPrintScheduleTrace();
DebugPrintPotentialCycle();

if (!IsSchedulingFair(PotentialCycle))
bool CheckFairness = true;
if (GetHotMonitors(PotentialCycle).Count == 0)
CheckFairness = false;
if (CheckFairness && !IsSchedulingFair(PotentialCycle))
{
Debug.WriteLine("<LivenessDebug> Scheduling in cycle is unfair.");
PotentialCycle.Clear();
PotentialCycleFingerprints.Clear();
}
else if (!IsNondeterminismFair(PotentialCycle))
else if (CheckFairness && !IsNondeterminismFair(PotentialCycle))
{
Debug.WriteLine("<LivenessDebug> Nondeterminism in cycle is unfair.");
PotentialCycle.Clear();
Expand All @@ -488,7 +490,8 @@ private void CheckLivenessAtTraceCycle(List<int> indices)
scheduleStep.Type, scheduleStep.State.Fingerprint.ToString());
}

if (IsSchedulingFair(PotentialCycle) && IsNondeterminismFair(PotentialCycle))
if (GetHotMonitors(PotentialCycle).Count > 0 &&
IsSchedulingFair(PotentialCycle) && IsNondeterminismFair(PotentialCycle))
{
isFairCycleFound = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ internal LivenessCheckingStrategy(Configuration configuration, List<Monitor> mon
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public abstract bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current);
public abstract bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true);

/// <summary>
/// Returns the next boolean choice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ internal TemperatureCheckingStrategy(Configuration configuration, List<Monitor>
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public override bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public override bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
CheckLivenessTemperature();
return SchedulingStrategy.GetNext(out next, choices, current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public InteractiveStrategy(Configuration configuration, IO.ILogger logger)
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
next = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public ReplayStrategy(Configuration configuration, ScheduleTrace trace, bool isF
/// <param name="next">Next</param>
/// <param name="choices">Choices</param>
/// <param name="current">Curent</param>
/// <param name="CacheState"></param>
/// <returns>Boolean</returns>
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current)
public bool GetNext(out ISchedulable next, List<ISchedulable> choices, ISchedulable current, bool CacheState = true)
{
var enabledChoices = choices.Where(choice => choice.IsEnabled).ToList();
if (enabledChoices.Count == 0)
Expand Down