Skip to content

Commit

Permalink
- WIP (Threading)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Oct 22, 2023
1 parent 63741bb commit 8046bb5
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Demos/Run-BareMetal.TestWorld.x86.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd %~dp0
cd ..\bin
Mosa.Tool.Launcher -autostart -oMax -output-asm -output-debug -output-hash Mosa.BareMetal.TestWorld.x86.dll
3 changes: 0 additions & 3 deletions Source/Mosa.BareMetal.HelloWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Kernel.BareMetal;
using Mosa.UnitTests.Optimization;

namespace Mosa.BareMetal.HelloWorld.x86;

Expand All @@ -12,8 +11,6 @@ public static void Main()
Debug.WriteLine("Boot::Main()");
Debug.WriteLine("MOSA x86 Kernel");

Division.DivisionBy7(254u);

Program.EntryPoint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<ItemGroup>
<ProjectReference Include="..\Mosa.BareMetal.HelloWorld\Mosa.BareMetal.HelloWorld.csproj" />
<ProjectReference Include="..\Mosa.Kernel.BareMetal.x86\Mosa.Kernel.BareMetal.x86.csproj" />
<ProjectReference Include="..\Mosa.UnitTests\Mosa.UnitTests.csproj" />
</ItemGroup>

</Project>
96 changes: 95 additions & 1 deletion Source/Mosa.BareMetal.TestWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using System.Runtime.CompilerServices;
using Mosa.Kernel.BareMetal;
using Mosa.UnitTests.Optimization;

Expand All @@ -10,10 +12,102 @@ public static class Boot
public static void Main()
{
Debug.WriteLine("Boot::Main()");
Debug.WriteLine("MOSA x86 Kernel");

Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.White;
Console.Clear();
Console.WriteLine("Mosa.BareMetal.TextWold.x86");
Console.WriteLine();

Division.DivisionBy7(254u);

StartThreadTest();

Program.EntryPoint();
}

private static void StartThreadTest()
{
Scheduler.CreateThread(Thread1, Page.Size);
Scheduler.CreateThread(Thread2, Page.Size);
Scheduler.CreateThread(Thread3, Page.Size);
Scheduler.CreateThread(Thread4, Page.Size);
Scheduler.CreateThread(Thread5, Page.Size);

Scheduler.Start();
}

private static readonly object spinlock = new();
private static uint totalticks = 0;

private static void UpdateThreadTicks(int thread, uint ticks)
{
++totalticks;

if (totalticks % 10000 == 0)
{
lock (spinlock)
{
Console.SetCursorPosition(18 + thread, 0);
Console.Write("Thread #" + thread + ": " + ticks);
}

//Native.Hlt();
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void Thread1()
{
var ticks = 0u;

while (true)
{
UpdateThreadTicks(1, ++ticks);
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void Thread2()
{
var ticks = 0u;

while (true)
{
UpdateThreadTicks(2, ++ticks);
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void Thread3()
{
var ticks = 0u;

while (true)
{
UpdateThreadTicks(3, ++ticks);
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void Thread4()
{
var ticks = 0u;

while (true)
{
UpdateThreadTicks(4, ++ticks);
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void Thread5()
{
var ticks = 0u;

while (true)
{
UpdateThreadTicks(5, ++ticks);
}
}
}
4 changes: 0 additions & 4 deletions Source/Mosa.BareMetal.TestWorld/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public static void EntryPoint()
Debug.WriteLine("Program::Main()");
Debug.WriteLine("##PASS##");

Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
Console.Clear();

for (; ; )
HAL.Yield();
}
Expand Down

0 comments on commit 8046bb5

Please sign in to comment.