Skip to content

Commit

Permalink
- Implements mosa#1233
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed May 15, 2024
1 parent 294893d commit da23e2a
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 74 deletions.
80 changes: 50 additions & 30 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
with:
name: windows-build-artifact
path: bin
compression-level: 9
- name: Create Package - Mosa.Tools.Package
run: nuget pack Source\Mosa.Packages\Mosa.Tools.Package.nuspec -Tool -OutputDirectory bin\nupkg -Version ${{ env.BUILD_VERSION }}
- name: Create Package - Mosa.Tools.Package.Qemu
Expand All @@ -73,7 +74,7 @@ jobs:
path: bin\nupkg

windows-build-packaging:
name: Windows Build Packaging
name: Build Windows Packaging
needs: [windows-build, linux-build, macos-build, windows-unit-testing, linux-unit-testing, macos-unit-testing, windows-demo-testing, linux-demo-testing, macos-demo-testing]
runs-on: windows-latest
timeout-minutes: 15
Expand Down Expand Up @@ -139,6 +140,7 @@ jobs:
with:
name: linux-build-artifact
path: bin
compression-level: 9

macos-build:
name: MacOS Build
Expand Down Expand Up @@ -168,6 +170,7 @@ jobs:
with:
name: macos-build-artifact
path: bin
compression-level: 9

windows-unit-testing:
strategy:
Expand All @@ -176,7 +179,7 @@ jobs:
fail-fast: false
name: Windows - Unit Test -o${{ matrix.optimization }}
runs-on: windows-latest
timeout-minutes: 15
timeout-minutes: 60
needs: windows-build
steps:
- name: Checkout
Expand All @@ -191,12 +194,13 @@ jobs:
- name: Make Artifact Folder
run: mkdir artifact
- name: Unit Test
run: bin\Mosa.Utility.UnitTests.exe -check -o${{ matrix.optimization }} -counters artifact\windows-counters-unittests-o${{ matrix.optimization }}.txt
run: bin\Mosa.Utility.UnitTests.exe -check -o${{ matrix.optimization }} -counters artifact\counters-windows-unittests-o${{ matrix.optimization }}.txt
- name: Store Counter Artifact
uses: actions/upload-artifact@v4
with:
name: windows-counters-unittests-o${{ matrix.optimization }}
name: counters-windows-unittests-o${{ matrix.optimization }}
path: artifact
retention-days: 2

linux-unit-testing:
strategy:
Expand All @@ -205,7 +209,7 @@ jobs:
fail-fast: false
name: Linux - Unit Test -o${{ matrix.optimization }}
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 60
needs: linux-build
steps:
- name: Set net8.0
Expand All @@ -228,12 +232,13 @@ jobs:
- name: Make Artifact Folder
run: mkdir artifact
- name: Perform Unit Testing
run: dotnet bin/Mosa.Utility.UnitTests.dll -check -o${{ matrix.optimization }} -counters artifact/linux-counters-unittests-o${{ matrix.optimization }}.txt
run: dotnet bin/Mosa.Utility.UnitTests.dll -check -o${{ matrix.optimization }} -counters artifact/counters-linux-unittests-o${{ matrix.optimization }}.txt
- name: Store Counter Artifact
uses: actions/upload-artifact@v4
with:
name: linux-counters-unittests-o${{ matrix.optimization }}
name: counters-linux-unittests-o${{ matrix.optimization }}
path: artifact
retention-days: 2

macos-unit-testing:
strategy:
Expand All @@ -242,7 +247,7 @@ jobs:
fail-fast: false
name: MacOS - Unit Test -o${{ matrix.optimization }}
runs-on: macos-13
timeout-minutes: 15
timeout-minutes: 60
needs: macos-build
steps:
- name: Set net8.0
Expand All @@ -263,12 +268,13 @@ jobs:
- name: Make Artifact Folder
run: mkdir artifact
- name: Unit Test
run: dotnet bin/Mosa.Utility.UnitTests.dll -check -o${{ matrix.optimization }} -counters artifact/macos-counters-unittests-o${{ matrix.optimization }}.txt
run: dotnet bin/Mosa.Utility.UnitTests.dll -check -o${{ matrix.optimization }} -counters artifact/counters-macos-unittests-o${{ matrix.optimization }}.txt
- name: Store Counter Artifact
uses: actions/upload-artifact@v4
with:
name: macos-counters-unittests-o${{ matrix.optimization }}
name: counters-macos-unittests-o${{ matrix.optimization }}
path: artifact
retention-days: 2

windows-demo-testing:
strategy:
Expand Down Expand Up @@ -388,25 +394,25 @@ jobs:
name: linux-build-artifact
path: bin
- name: x64 Compile Test - BareMetal HelloWorld - o0
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o0 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o0 -check -launch-off -output-counters
- name: x64 Compile Test - BareMetal HelloWorld - o1
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o1 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o1 -check -launch-off -output-counters
- name: x64 Compile Test - BareMetal HelloWorld - o2
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o2 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o2 -check -launch-off -output-counters
- name: x64 Compile Test - BareMetal HelloWorld - o3
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o3 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o3 -check -launch-off -output-counters
- name: x64 Compile Test - BareMetal HelloWorld - o4
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o4 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o4 -check -launch-off -output-counters
- name: x64 Compile Test - BareMetal HelloWorld - o5
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o5 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o5 -check -launch-off -output-counters
- name: x64 Compile Test - BareMetal HelloWorld - o6
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o6 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o6 -check -launch-off -output-counters
- name: x64 Compile Test - BareMetal HelloWorld - o7
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o7 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o7 -check -launch-off -output-counters
- name: x64 Compile Test - BareMetal HelloWorld - o8
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o8 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o8 -check -launch-off -output-counters
- name: x64 Compile Test - BareMetal HelloWorld - o9
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o9 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.x64.dll -x64 -o9 -check -launch-off -output-counters

linux-arm32-compile-test:
name: Linux - ARM32 Compile Tests
Expand All @@ -428,22 +434,36 @@ jobs:
name: linux-build-artifact
path: bin
- name: ARM32 Compile Test - BareMetal HelloWorld - o0
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o0 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o0 -check -launch-off -output-counters
- name: ARM32 Compile Test - BareMetal HelloWorld - o1
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o1 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o1 -check -launch-off -output-counters
- name: ARM32 Compile Test - BareMetal HelloWorld - o2
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o2 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o2 -check -launch-off -output-counters
- name: ARM32 Compile Test - BareMetal HelloWorld - o3
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o3 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o3 -check -launch-off -output-counters
- name: ARM32 Compile Test - BareMetal HelloWorld - o4
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o4 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o4 -check -launch-off -output-counters
- name: ARM32 Compile Test - BareMetal HelloWorld - o5
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o5 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o5 -check -launch-off -output-counters
- name: ARM32 Compile Test - BareMetal HelloWorld - o6
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o6 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o6 -check -launch-off -output-counters
- name: ARM32 Compile Test - BareMetal HelloWorld - o7
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o7 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o7 -check -launch-off -output-counters
- name: ARM32 Compile Test - BareMetal HelloWorld - o8
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o8 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o8 -check -launch-off -output-counters
- name: ARM32 Compile Test - BareMetal HelloWorld - o9
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o9 -check -autolaunch-off -output-counters
run: dotnet bin/Mosa.Tool.Launcher.Console.dll bin/Mosa.BareMetal.HelloWorld.ARM32.dll -arm32 -o9 -check -launch-off -output-counters

merge-artifacts:
name: Merge Artifacts
runs-on: ubuntu-latest
needs: [windows-unit-testing, linux-unit-testing, macos-unit-testing]
timeout-minutes: 15
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: counters-unit-tests
pattern: counters-*
compression-level: 9

4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
contents: write

env:
BUILD_VERSION: 2.5.1.${{ github.run_number }}
BUILD_VERSION: 2.6.0.${{ github.run_number }}

jobs:

Expand All @@ -26,7 +26,7 @@ jobs:
with:
python-version: '3.11'
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive
- name: Update package repository
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![License][source-image]][source-target] [![License][github-license]][github-license-link] [![Discord Chat][discord-image]][discord-chat]

[![Build status][build-status-image]][build-status] [![Test status][test-status-image]][test-status] [![Issues][github-issues]][github-issues-link] [![Stars][github-stars]][github-stars-link] [![Forks][github-forks]][github-forks-link]
[![Build status][build-status-image]][build-status] [![Issues][github-issues]][github-issues-link] [![Stars][github-stars]][github-stars-link] [![Forks][github-forks]][github-forks-link]

[build-status-image]: https://github.com/mosa/MOSA-Project/workflows/Builds/badge.svg?branch=master
[build-status]: https://github.com/mosa/MOSA-Project/actions
Expand Down
22 changes: 21 additions & 1 deletion Source/Mosa.Compiler.Framework/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public sealed class Compiler

public bool HasError { get; private set; }

public Stopwatch CompileTime { get; } = new Stopwatch();

public Stopwatch TotalCompileTime { get; } = new Stopwatch();

public Stopwatch LinkerTime { get; } = new Stopwatch();

#endregion Properties

#region Static Methods
Expand All @@ -131,8 +137,8 @@ public sealed class Compiler
!string.IsNullOrEmpty(mosaSettings.PreLinkHashFile) ? new PreLinkHashFileStage() : null,
new LinkerLayoutStage(),
!string.IsNullOrEmpty(mosaSettings.PostLinkHashFile) ? new PostLinkHashFileStage() : null,
!string.IsNullOrEmpty(mosaSettings.CompileTimeFile) ? new MethodCompileTimeStage() : null,
!string.IsNullOrEmpty(mosaSettings.OutputFile) && mosaSettings.EmitBinary ? new LinkerEmitStage() : null,
!string.IsNullOrEmpty(mosaSettings.CompileTimeFile) ? new MethodCompileTimeStage() : null,
!string.IsNullOrEmpty(mosaSettings.MapFile) ? new MapFileStage() : null,
!string.IsNullOrEmpty(mosaSettings.CounterFile) ? new CounterFileStage() : null,
!string.IsNullOrEmpty(mosaSettings.DebugFile) ? new DebugFileStage() : null,
Expand Down Expand Up @@ -448,8 +454,13 @@ private MosaMethod CompileMethod(MosaMethod method, int threadID)

public void ExecuteCompile(int maxThreads)
{
GlobalCounters.Set("Compiler.MaxThreads", maxThreads);

PostEvent(CompilerEvent.CompilingMethodsStart);

CompileTime.Start();
TotalCompileTime.Start();

if (maxThreads > 0)
{
var threads = Enumerable
Expand All @@ -461,7 +472,9 @@ public void ExecuteCompile(int maxThreads)
threads.ForEach(x => x.Join());
}
else
{
CompilePass();
}

PostEvent(CompilerEvent.CompilingMethodsCompleted);
}
Expand Down Expand Up @@ -490,6 +503,9 @@ private void CompilePass()
/// </remarks>
internal void Finalization()
{
CompileTime.Stop();
GlobalCounters.Set("Elapsed.Total.Milliseconds", (int)CompileTime.ElapsedMilliseconds);

PostEvent(CompilerEvent.FinalizationStart);

// Sum up the counters
Expand Down Expand Up @@ -520,6 +536,10 @@ internal void Finalization()
PostEvent(CompilerEvent.FinalizationStageEnd, stage.Name);
}

TotalCompileTime.Stop();
GlobalCounters.Set("Elapsed.TotalCompile.Milliseconds", (int)TotalCompileTime.ElapsedMilliseconds);
GlobalCounters.Set("Compiler.TotalMethods", MethodScheduler.TotalMethods);

MethodScanner.Complete();

EmitCounters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ protected override void Finalization()
if (string.IsNullOrEmpty(MosaSettings.OutputFile))
return;

Compiler.PostEvent(CompilerEvent.LinkingStart);

File.Delete(MosaSettings.OutputFile);

Compiler.PostEvent(CompilerEvent.LinkingStart);

using (var file = new FileStream(MosaSettings.OutputFile, FileMode.Create))
{
Linker.Emit(file);
}

Compiler.LinkerTime.Stop();

Compiler.PostEvent(CompilerEvent.LinkingEnd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ protected override void Finalization()

Linker.FinalizeLayout();

Compiler.GlobalCounters.Update("Linker.Text", (int)Linker.Sections[(int)SectionKind.Text].Size);
Compiler.GlobalCounters.Update("Linker.Data", (int)Linker.Sections[(int)SectionKind.Data].Size);
Compiler.GlobalCounters.Update("Linker.ROData", (int)Linker.Sections[(int)SectionKind.ROData].Size);
Compiler.GlobalCounters.Update("Linker.BSS", (int)Linker.Sections[(int)SectionKind.BSS].Size);
Compiler.LinkerTime.Reset();

Compiler.GlobalCounters.Set("Linker.Text", (int)Linker.Sections[(int)SectionKind.Text].Size);
Compiler.GlobalCounters.Set("Linker.Data", (int)Linker.Sections[(int)SectionKind.Data].Size);
Compiler.GlobalCounters.Set("Linker.ROData", (int)Linker.Sections[(int)SectionKind.ROData].Size);
Compiler.GlobalCounters.Set("Linker.BSS", (int)Linker.Sections[(int)SectionKind.BSS].Size);
}
}
22 changes: 17 additions & 5 deletions Source/Mosa.Compiler.Framework/Counters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,41 @@ public void Reset()

public void Update(string name, int count)
{
UpdateCounter(name, count);
UpdateCounter(name, count, false);
}

public void Set(string name, int count)
{
UpdateCounter(name, count, true);
}

public void Update(Counter counter)
{
UpdateCounter(counter.Name, counter.Count);
UpdateCounter(counter.Name, counter.Count, false);
}

public void Update(Counters counters)
{
foreach (var counter in counters.Entries.Values)
{
UpdateCounter(counter.Name, counter.Count);
UpdateCounter(counter.Name, counter.Count, false);
}
}

private void UpdateCounter(string name, int count)
private void UpdateCounter(string name, int count, bool reset = false)
{
lock (_lock)
{
if (Entries.TryGetValue(name, out var counter))
{
counter.Increment(count);
if (reset)
{
counter.Set(count);
}
else
{
counter.Increment(count);
}
}
else
{
Expand Down
Loading

0 comments on commit da23e2a

Please sign in to comment.