Commit 3ff01301 authored by Sebastian Uhlík's avatar Sebastian Uhlík
Browse files

Add: tracking of all desired files.

parent a5919cbb

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29509.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "deos", "deos\deos.csproj", "{1C41DB68-8B49-4CA8-A48E-87AB080B7B3D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1C41DB68-8B49-4CA8-A48E-87AB080B7B3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C41DB68-8B49-4CA8-A48E-87AB080B7B3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C41DB68-8B49-4CA8-A48E-87AB080B7B3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C41DB68-8B49-4CA8-A48E-87AB080B7B3D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6D711733-21A4-4C63-989F-5CDE871B034A}
EndGlobalSection
EndGlobal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEOS
{
abstract class AbstractClockingDevice
{
public abstract void ClockTicks(int currentTime);
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEOS
{
class Assertion
{
static Thread[] allThreads = new Thread[4];
static int[] total_time = new int[2];
static int num_entries = 0;
public static void AddThread(Thread t)
{
//allThreads.add(t);
allThreads[num_entries] = t;
num_entries++;
}
public static bool Check()
{
total_time[0] = 0;
total_time[1] = 0;
Thread current;
for (int i = 0; i < num_entries; i++)
{
current = allThreads[i];
if (current != Scheduler.IdleThread())
{
int cp = current.itsPeriodicEvent.CurrentPeriod();
if ((current.itsLastExecution == cp) &&
(current.itsLastCompletion != cp))
{
total_time[1] += current.itsCurrentBudget.RemainingBudgetInUsec();
if (current.itsPeriodIndex == 0)
{
total_time[0] += current.itsCurrentBudget.RemainingBudgetInUsec();
}
}
else if (current.itsLastExecution != cp)
{
total_time[1] += current.itsCurrentBudget.TotalBudgetInUsec();
if (current.itsPeriodIndex == 0)
{
total_time[0] += current.itsCurrentBudget.TotalBudgetInUsec();
}
}
if (current.itsPeriodIndex == 0)
{
int tmp = (current.itsCurrentBudget.TotalBudgetInUsec()) * (StartOfPeriodEvent.EventForPeriodIndex(1).countDown - 1);
total_time[1] += tmp;
}
}
}
int period_count = StartOfPeriodEvent.EventForPeriodIndex(1).countDown - 1;
int current_period = StartOfPeriodEvent.EventForPeriodIndex(1).CurrentPeriod();
if (Scheduler.CurrentThread() != Scheduler.IdleThread())
{
int remaining = ((Registry.uSecsInFastestPeriod * period_count) +
Registry.uSecsInFastestPeriod) -
DEOS.thePeriodicClock.GetUsedTime();
if (total_time[1] > remaining)
{
DEOS.println("Ooops: Time wanted " + total_time[1] + " > " + remaining);
throw new Exception("error found");
}
else
{
}
}
total_time[0] = 0;
total_time[1] = 0;
return true;
}
public static void RemoveThread(Thread t)
{
for (int i = 0; i < num_entries; i++)
{
if (allThreads[i] == t)
{
for (int j = i + 1; j < num_entries; j++)
{
allThreads[j - 1] = allThreads[j];
}
num_entries--;
return;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEOS
{
class Budget
{
private int itsTotalBudget;
private int itsRemainingBudget;
public void SetRemainingBudgetInUsec(int b)
{
itsRemainingBudget = b;
}
public void SetTotalBudgetInUsec(int b)
{
itsTotalBudget = b;
}
public void AdjustRemainingTime(int b)
{
itsRemainingBudget += b;
}
public int RemainingBudgetInUsec()
{
return itsRemainingBudget;
}
public void Replenish()
{
itsRemainingBudget = itsTotalBudget;
}
public void ReplenishAndStartTimer()
{
itsRemainingBudget = itsTotalBudget;
StartTimer();
}
public void StartTimer()
{
DEOS.systemClock.SetTimer(itsRemainingBudget);
}
public int TotalBudgetInUsec()
{
return itsTotalBudget;
}
int StopTimer()
{
// Modified by ckong - June 25, 2001
//itsRemainingBudget = DEOS.theTimer.timeRemaining();
itsRemainingBudget = DEOS.theTimer.GetRemainingTime(
DEOS.systemClock.GetCurrentTime());
return itsRemainingBudget;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEOS
{
class CPU
{
public static int EnterCritical()
{
return 0;
}
public static void ExitCritical(int interruptState)
{
}
}
}
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System;
namespace DEOS
{
public class ChessTest
{
public static void Main(string[] args)
{
Console.WriteLine(Run());
}
public static bool Run()
{
DEOS deos = new DEOS();
return deos.Run();
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEOS
{
public class Clock
{
public static int TIME_CONSTRAINT = Registry.numPeriods * 20 * 2; // numPeriods is usually 3
public static int NOINTERRUPTS = 0;
public static int TIMEOUT = 1;
public static int SYSTEMINTERRUPT = 2;
public static int NOTIMECHANGE = 3;
int currentTime = -20;
PeriodicClock clockToNotify; // may use a list in another version
NewTimer timerToNotify; // if there are more than two clocking devices
bool eventDriven = false;
public Clock(PeriodicClock periodicIn, NewTimer timerIn)
{
if (DEOS.abstraction)
{
currentTime = -20;
}
else
{
currentTime = -1;
}
clockToNotify = periodicIn;
timerToNotify = timerIn;
}
public int GetCurrentTime()
{
return currentTime;
}
public void SetTimer(int timeIn)
{
timerToNotify.SetTimer(timeIn, currentTime);
}
public void ClearInterrupts()
{
clockToNotify.ClearInterrupt();
timerToNotify.ClearTimeOut();
}
public int Ticks()
{
ClearInterrupts();
int delta;
if (!DEOS.abstraction)
{
delta = 1;
}
else
{
int timeToEOP = (clockToNotify.GetTimeToEOP());
int timeOutTime = (timerToNotify.GetStoppingTime());
int timeToTimeOut = (timeOutTime - currentTime);
if (DEOS.RandBool())
{
delta = 0;
}
else
{
if (timeToEOP <= timeToTimeOut)
{
delta = timeToEOP;
}
else
{
delta = timeToTimeOut;
}
}
}
if (delta == 0)
{
return NOTIMECHANGE;
}
else
{
if ((currentTime + delta) > TIME_CONSTRAINT)
{
return NOTIMECHANGE;
}
currentTime = (currentTime + delta);
clockToNotify.ClockTicks(currentTime);
timerToNotify.ClockTicks(currentTime);
if (clockToNotify.IsInterrupted())
{
timerToNotify.InterruptTimer();
return SYSTEMINTERRUPT;
}
else if (timerToNotify.IsTimeOut())
{
return TIMEOUT;
}
else
{
return NOINTERRUPTS;
}
}
}
}
}
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
namespace DEOS
{
public class DEOS
{
public static NewTimer theTimer;
public static PeriodicClock thePeriodicClock;
public static Clock systemClock;
public static bool abstraction = false;
public static string indent = "";
public static string INC = " ";
public static void Inc()
{
//indent = INC + indent;
}
public bool Run()
{
Console.WriteLine("JAVA - DEOS\n");
theTimer = new NewTimer();
thePeriodicClock = new PeriodicClock(Registry.uSecsInFastestPeriod);
systemClock = new Clock(thePeriodicClock, theTimer);
DEOSKernel.ColdStartKernel();
int result = DEOSKernel.CreateThreadK("user1", 0, 21, 1);
result = DEOSKernel.CreateThreadK("user2", 0, 21, 1);
int tickResult = Clock.NOINTERRUPTS;
for (int i = 0; i < 1000; i++)
{
DEOS.println("****************************");
DEOS.println("Current time: " + DEOS.systemClock.GetCurrentTime());
DEOS.println(Scheduler.CurrentThread().ToString() + " is the current thread");
tickResult = DEOS.systemClock.Ticks();
Scheduler.CurrentThread().GetBody().Run(tickResult);
}
return true;
}
public static void println(string s)
{
Console.WriteLine(indent + s);
}
public static bool RandBool()
{
Random rand = new Random();
if (rand.NextDouble() < 0.5)
return true;
else
return false;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEOS
{
class DEOSIdleThread : DEOSThread
{
public DEOSIdleThread(Thread t): base(t)
{
}
public void Run(int tickResult)
{
GetInterrupted(tickResult);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEOS
{
class DEOSKernel
{
public const int threadSuccess = 0;
public const int threadInvalidHandle = 1;
public const int threadInvalidInterrupt = 2;
public const int threadNotDormant = 3;
public const int threadNotSchedulable = 4;
public const int threadInsufficientPrivilege = 5;
public const int threadNotDynamic = 6;
public const int threadNot = 7;
public const int threadMaximumThreadsExceeded = 8;
public const int threadInsufficientRAMForStack = 9;
public const int threadNoSuchThread = 10;
public const int threadInvalidTemplate = 11;
public const int threadNotActive = 12;
public const int threadInScheduleBefore = 13;
public const int threadInsufficientBudget = 14;
public const int threadDuplicateISR = 15;
public const int threadInvalidFromDynamicProcess = 16;
public const int threadPrimaryCannotBeISR = 17;
public static void ColdStartKernel()
{
StartOfPeriodEvent.Initialize();
Scheduler.Initialize();
}
public static int CreateThreadK (String name, int threadTemplateId, int threadBudget, int periodIndex)
{
int returnStatus;
DEOSProcess currentProcess = Scheduler.CurrentProcess();
// Allocate a thread, then initialize it
Thread threadCreated = new Thread(name);
if (threadCreated == null)
{
Console.WriteLine("Thread could not be created");
returnStatus = threadMaximumThreadsExceeded;
}
else
{
// Allocate stack and initialize the thread...
if (!threadCreated.ConceptualObjectConstructor(periodIndex))
{
threadCreated = null;
returnStatus = threadInsufficientRAMForStack;
}
else
{
int interruptState = CPU.EnterCritical();
returnStatus = LocalStartThread(threadCreated, threadBudget, periodIndex);
CPU.ExitCritical(interruptState);
if (threadSuccess == returnStatus)
{
}
else
{
threadCreated.ConceptualObjectDestructor();
threadCreated = null;
}
}
}
return returnStatus;
}
public static int DeleteThreadK(Thread theThread)
{
if (theThread != Scheduler.CurrentThread())
{
Console.WriteLine("Thread " + theThread + " no longer running delete");
return 0;
}
int result;
int interruptState = CPU.EnterCritical();
CPU.ExitCritical(interruptState);
theThread.InitiateStopAndDelete();
result = threadSuccess;
interruptState = CPU.EnterCritical();
CPU.ExitCritical(interruptState);
return result;
}
public static int LocalStartThread(Thread theThread, int requestedThreadBudget, int periodIndex)
{
// changed the following code because can't pass int (budget) by reference.
// cpuTimeInMicroseconds budget;
int budget; // budget set by following call.
budget = DEOSProcess.AllocateCPUBudgetForThread(theThread, requestedThreadBudget, periodIndex);
if (budget > -1)
{
theThread.StartThread(budget);
return threadSuccess;
}
else
{
return threadNotSchedulable;
}
}
public static int WaitUntilNextPeriodK(Thread th)
{
if (th != Scheduler.CurrentThread())
{
Console.WriteLine("Thread " + th + " no longer running");
return 0;
}
Scheduler.CurrentThread().WaitForNextPeriod();
return 0; // void really
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DEOS
{
class DEOSMainThread : DEOSThread
{
public DEOSMainThread(Thread t): base(t)
{ }
public void Run(int tickResult)
{
DEOS.Inc();
if (tickResult == Clock.NOTIMECHANGE)
{
DEOS.println("No interrupts!");
DEOS.println(thread.ToString() + " waiting until next period");
DEOSKernel.WaitUntilNextPeriodK(thread); //yieldCPU();
}
else
{
if (DEOS.RandBool())
{
DEOS.println("---Choice 0 of main---");
DEOS.println(thread.ToString() + " waiting until next period");