Skip to content

Commit

Permalink
Fixed speed issue with the heap.
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed Dec 18, 2015
1 parent 30e2ffa commit 1a2ed6b
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 136 deletions.
255 changes: 123 additions & 132 deletions Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,141 +31,132 @@ protected override void Run()
bool xTest;
string xContents;

//mDebugger.Send("START TEST: Get parent:");
//var xParent = Directory.GetParent(@"0:\test");
//Assert.IsTrue(xParent != null, "Failed to get directory parent.");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//mDebugger.Send("START TEST: Get parent:");
//xParent = Directory.GetParent(@"0:\test\");
//Assert.IsTrue(xParent != null, "Failed to get directory parent.");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//mDebugger.Send("Get files:");
//var xFiles = Directory.GetFiles(@"0:\");
//mDebugger.Send("Found " + xFiles.Length + " files.");
//if (xFiles.Length > 0)
//{
// mDebugger.Send("-- File list");
// for (int i = 0; i < xFiles.Length; i++)
// {
// mDebugger.Send("File: " + xFiles[i]);
// }
//}
//Assert.IsTrue(xFiles.Length > 0, "Failed to get files from the directory.");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//mDebugger.Send("Get directories:");
//var xDirectories = Directory.GetDirectories(@"0:\");
//mDebugger.Send("Found " + xDirectories.Length + " directories.");
//if (xDirectories.Length > 0)
//{
// mDebugger.Send("-- Directory list");
// for (int i = 0; i < xDirectories.Length; i++)
// {
// mDebugger.Send("Directory: " + xDirectories[i]);
// }
//}
//Assert.IsTrue(xDirectories.Length > 0, "Failed to get directories from the directory.");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//Assert.IsTrue(Path.GetDirectoryName(@"0:\test") == @"0:\", @"Path.GetDirectoryName(@'0:\test') == @'0:\'");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//Assert.IsTrue(Path.GetFileName(@"0:\test") == @"test", @"Path.GetFileName(@'0:\test') == @'test'");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

while (true)
mDebugger.Send("START TEST: Get parent:");
var xParent = Directory.GetParent(@"0:\test");
Assert.IsTrue(xParent != null, "Failed to get directory parent.");
mDebugger.Send("END TEST");
mDebugger.Send("");

mDebugger.Send("START TEST: Get parent:");
xParent = Directory.GetParent(@"0:\test\");
Assert.IsTrue(xParent != null, "Failed to get directory parent.");
mDebugger.Send("END TEST");
mDebugger.Send("");

mDebugger.Send("Get files:");
var xFiles = Directory.GetFiles(@"0:\");
mDebugger.Send("Found " + xFiles.Length + " files.");
if (xFiles.Length > 0)
{
mDebugger.Send("File exist check:");
xTest = File.Exists(@"0:\Kudzu.txt");
Assert.IsTrue(xTest, @"\Kudzu.txt not found!");
mDebugger.Send("END TEST");
mDebugger.Send("");
mDebugger.Send("-- File list");
for (int i = 0; i < xFiles.Length; i++)
{
mDebugger.Send("File: " + xFiles[i]);
}
}
Assert.IsTrue(xFiles.Length > 0, "Failed to get files from the directory.");
mDebugger.Send("END TEST");
mDebugger.Send("");

mDebugger.Send("Get directories:");
var xDirectories = Directory.GetDirectories(@"0:\");
mDebugger.Send("Found " + xDirectories.Length + " directories.");
if (xDirectories.Length > 0)
{
mDebugger.Send("-- Directory list");
for (int i = 0; i < xDirectories.Length; i++)
{
mDebugger.Send("Directory: " + xDirectories[i]);
}
}
Assert.IsTrue(xDirectories.Length > 0, "Failed to get directories from the directory.");
mDebugger.Send("END TEST");
mDebugger.Send("");

Assert.IsTrue(Path.GetDirectoryName(@"0:\test") == @"0:\", @"Path.GetDirectoryName(@'0:\test') == @'0:\'");
mDebugger.Send("END TEST");
mDebugger.Send("");

Assert.IsTrue(Path.GetFileName(@"0:\test") == @"test", @"Path.GetFileName(@'0:\test') == @'test'");
mDebugger.Send("END TEST");
mDebugger.Send("");

mDebugger.Send("Directory exist check:");
xTest = Directory.Exists(@"0:\test");
Assert.IsTrue(xTest, "Folder does not exist!");
mDebugger.Send("END TEST");
mDebugger.Send("");

mDebugger.Send("File contents of Kudzu.txt: ");
xContents = File.ReadAllText(@"0:\Kudzu.txt");
mDebugger.Send("Contents retrieved");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "Hello Cosmos", "Contents of Kudzu.txt was read incorrectly!");
mDebugger.Send("END TEST");
mDebugger.Send("");

using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Open))
{
xFS.SetLength(5);
}
mDebugger.Send("File made smaller");
xContents = File.ReadAllText(@"0:\Kudzu.txt");
mDebugger.Send("Contents retrieved");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!");
mDebugger.Send("END TEST");
mDebugger.Send("");

using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create))
{
xFS.SetLength(5);
}
mDebugger.Send("File made smaller");
xContents = File.ReadAllText(@"0:\Kudzu.txt");
mDebugger.Send("Contents retrieved");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!");
mDebugger.Send("END TEST");
mDebugger.Send("");

using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create))
{
mDebugger.Send("Start writing");
var xStr = "Test FAT Write.";
var xBuff = xStr.GetUtf8Bytes(0, (uint)xStr.Length);
xFS.Write(xBuff, 0, xBuff.Length);
mDebugger.Send("---- Data written");
xFS.Position = 0;
xFS.Read(xBuff, 0, xBuff.Length);
mDebugger.Send(xBuff.GetUtf8String(0, (uint)xBuff.Length));
}

//mDebugger.Send("Directory exist check:");
//xTest = Directory.Exists(@"0:\test");
//Assert.IsTrue(xTest, "Folder does not exist!");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//mDebugger.Send("File contents of Kudzu.txt: ");
//xContents = File.ReadAllText(@"0:\Kudzu.txt");
//mDebugger.Send("Contents retrieved");
//mDebugger.Send(xContents);
//Assert.IsTrue(xContents == "Hello Cosmos", "Contents of Kudzu.txt was read incorrectly!");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Open))
//{
// xFS.SetLength(5);
//}
//mDebugger.Send("File made smaller");
//xContents = File.ReadAllText(@"0:\Kudzu.txt");
//mDebugger.Send("Contents retrieved");
//mDebugger.Send(xContents);
//Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create))
//{
// xFS.SetLength(5);
//}
//mDebugger.Send("File made smaller");
//xContents = File.ReadAllText(@"0:\Kudzu.txt");
//mDebugger.Send("Contents retrieved");
//mDebugger.Send(xContents);
//Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create))
//{
// mDebugger.Send("Start writing");
// var xStr = "Test FAT Write.";
// var xBuff = xStr.GetUtf8Bytes(0, (uint)xStr.Length);
// xFS.Write(xBuff, 0, xBuff.Length);
// mDebugger.Send("---- Data written");
// xFS.Position = 0;
// xFS.Read(xBuff, 0, xBuff.Length);
// mDebugger.Send(xBuff.GetUtf8String(0, (uint)xBuff.Length));
//}

//mDebugger.Send("Write to file now");
//File.WriteAllText(@"0:\Kudzu.txt", "Test FAT write.");
//mDebugger.Send("Text written");

//xContents = File.ReadAllText(@"0:\Kudzu.txt");
//mDebugger.Send("Contents retrieved after writing");
//mDebugger.Send(xContents);
//Assert.IsTrue(xContents == "Test FAT write.", "Contents of Kudzu.txt was written incorrectly!");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//mDebugger.Send("START TEST: Create directory:");
//var xDirectory = Directory.CreateDirectory(@"0:\test2");
//Assert.IsTrue(xDirectory != null, "Failed to create a new directory.");
//bool xExists = Directory.Exists(@"0:\test2");
//Assert.IsTrue(xExists, "Failed to create a new directory.");
//mDebugger.Send("END TEST");
//mDebugger.Send("");

//mDebugger.Send("START TEST: Create file:");
//var xFile = File.Create(@"0:\test2.txt");
//Assert.IsTrue(xFile != null, "Failed to create a new file.");
//bool xFileExists = File.Exists(@"0:\test2.txt");
//Assert.IsTrue(xFileExists, "Failed to create a new file.");
//mDebugger.Send("END TEST");
//mDebugger.Send("");
mDebugger.Send("Write to file now");
File.WriteAllText(@"0:\Kudzu.txt", "Test FAT write.");
mDebugger.Send("Text written");

xContents = File.ReadAllText(@"0:\Kudzu.txt");
mDebugger.Send("Contents retrieved after writing");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "Test FAT write.", "Contents of Kudzu.txt was written incorrectly!");
mDebugger.Send("END TEST");
mDebugger.Send("");

mDebugger.Send("START TEST: Create directory:");
var xDirectory = Directory.CreateDirectory(@"0:\test2");
Assert.IsTrue(xDirectory != null, "Failed to create a new directory.");
bool xExists = Directory.Exists(@"0:\test2");
Assert.IsTrue(xExists, "Failed to create a new directory.");
mDebugger.Send("END TEST");
mDebugger.Send("");

mDebugger.Send("START TEST: Create file:");
var xFile = File.Create(@"0:\test2.txt");
Assert.IsTrue(xFile != null, "Failed to create a new file.");
bool xFileExists = File.Exists(@"0:\test2.txt");
Assert.IsTrue(xFileExists, "Failed to create a new file.");
mDebugger.Send("END TEST");
mDebugger.Send("");
TestController.Completed();
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.Core/DataLookupTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal unsafe struct DataLookupTable
[FieldOffset(8)]
public DataLookupEntry FirstEntry;

public unsafe DataLookupEntry* GetEntry(int index)
public unsafe DataLookupEntry* GetEntry(uint index)
{
fixed (DataLookupEntry* xFirstEntryPtr = &FirstEntry)
{
Expand Down
15 changes: 13 additions & 2 deletions source/Cosmos.Core/Heap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ public static unsafe partial class Heap
{
private static uint mEndOfRam;

private static uint mLastTableIndex = 0u;

private static uint mLastEntryIndex = 0u;

private static void DoInitialize(uint aEndOfRam)
{
mLastTableIndex = 0u;
mLastEntryIndex = 0u;
mEndOfRam = aEndOfRam;
//
}
Expand Down Expand Up @@ -48,7 +54,7 @@ public static uint MemAlloc(uint aLength)
{
EnsureIsInitialized();

var xCurrentTableIdx = 0u;
var xCurrentTableIdx = mLastTableIndex;
DataLookupTable* xCurrentTable = GlobalSystemInfo.GlobalInformationTable->FirstDataLookupTable;
DataLookupTable* xPreviousTable = null;
uint xResult;
Expand All @@ -64,6 +70,7 @@ public static uint MemAlloc(uint aLength)
{
DebugAndHalt("Wrong handle returned!");
}
mLastTableIndex = xCurrentTableIdx;
return xResult;
}
xCurrentTableIdx ++;
Expand Down Expand Up @@ -93,6 +100,8 @@ public static uint MemAlloc(uint aLength)
}
DebugHex("Returning handle", xResult);
DebugHex("For dataobject size", aLength);
mLastTableIndex = xCurrentTableIdx;
mLastEntryIndex = 0;
return xResult;
}
finally
Expand All @@ -111,7 +120,7 @@ public static uint MemAlloc(uint aLength)
private static bool ScanDataLookupTable(uint aTableIdx, DataLookupTable* aTable, uint aSize, out uint aHandle)
{
DataLookupEntry* xPreviousEntry = null;
for (int i = 0; i < DataLookupTable.EntriesPerTable; i++)
for (uint i = mLastEntryIndex; i < DataLookupTable.EntriesPerTable; i++)
{
var xCurrentEntry = aTable->GetEntry(i);

Expand Down Expand Up @@ -165,6 +174,7 @@ private static bool ScanDataLookupTable(uint aTableIdx, DataLookupTable* aTable,
{
Debug("Last known one");
}
mLastEntryIndex = i;
return true;
}

Expand All @@ -180,6 +190,7 @@ private static bool ScanDataLookupTable(uint aTableIdx, DataLookupTable* aTable,
xCurrentEntry->Refcount = 1;
aHandle = (uint)xCurrentEntry;
DebugHex("Returning reused handle ", aHandle);
mLastEntryIndex = i;
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
<Name>Cosmos.Debug.Kernel</Name>
</ProjectReference>
<ProjectReference Include="..\Cosmos.System\Cosmos.System.csproj">
<Project>{3DEF0461-08AB-471A-8F03-A9C556652A0F}</Project>
<Project>{3def0461-08ab-471a-8f03-a9c556652a0f}</Project>
<Name>Cosmos.System</Name>
</ProjectReference>
<ProjectReference Include="..\XSharp.Nasm\XSharp.Nasm.csproj">
Expand Down

0 comments on commit 1a2ed6b

Please sign in to comment.