Fix performance regression caused by the new scheduler changes (#422)
* Call interrupt less often, remove some leftovers from the old scheduler code * Remove unneeded attribute
This commit is contained in:
parent
f07e1fa8af
commit
c08479877e
3 changed files with 25 additions and 9 deletions
|
@ -46,8 +46,6 @@ namespace ChocolArm64
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Work.Name = "cpu_thread_" + Work.ManagedThreadId;
|
|
||||||
|
|
||||||
Work.Start();
|
Work.Start();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -2,6 +2,7 @@ using ChocolArm64.Events;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.Intrinsics;
|
using System.Runtime.Intrinsics;
|
||||||
|
|
||||||
namespace ChocolArm64.State
|
namespace ChocolArm64.State
|
||||||
|
@ -14,6 +15,8 @@ namespace ChocolArm64.State
|
||||||
internal const int ErgSizeLog2 = 4;
|
internal const int ErgSizeLog2 = 4;
|
||||||
internal const int DczSizeLog2 = 4;
|
internal const int DczSizeLog2 = 4;
|
||||||
|
|
||||||
|
private const int MinInstForCheck = 4000000;
|
||||||
|
|
||||||
internal AExecutionMode ExecutionMode;
|
internal AExecutionMode ExecutionMode;
|
||||||
|
|
||||||
//AArch32 state.
|
//AArch32 state.
|
||||||
|
@ -45,6 +48,8 @@ namespace ChocolArm64.State
|
||||||
|
|
||||||
private bool Interrupted;
|
private bool Interrupted;
|
||||||
|
|
||||||
|
private int SyncCount;
|
||||||
|
|
||||||
public long TpidrEl0 { get; set; }
|
public long TpidrEl0 { get; set; }
|
||||||
public long Tpidr { get; set; }
|
public long Tpidr { get; set; }
|
||||||
|
|
||||||
|
@ -101,13 +106,16 @@ namespace ChocolArm64.State
|
||||||
TickCounter.Start();
|
TickCounter.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool Synchronize()
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal bool Synchronize(int BbWeight)
|
||||||
{
|
{
|
||||||
if (Interrupted)
|
//Firing a interrupt frequently is expensive, so we only
|
||||||
{
|
//do it after a given number of instructions has executed.
|
||||||
Interrupted = false;
|
SyncCount += BbWeight;
|
||||||
|
|
||||||
OnInterrupt();
|
if (SyncCount >= MinInstForCheck)
|
||||||
|
{
|
||||||
|
CheckInterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Running;
|
return Running;
|
||||||
|
@ -118,9 +126,17 @@ namespace ChocolArm64.State
|
||||||
Interrupted = true;
|
Interrupted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInterrupt()
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
private void CheckInterrupt()
|
||||||
{
|
{
|
||||||
Interrupt?.Invoke(this, EventArgs.Empty);
|
SyncCount = 0;
|
||||||
|
|
||||||
|
if (Interrupted)
|
||||||
|
{
|
||||||
|
Interrupted = false;
|
||||||
|
|
||||||
|
Interrupt?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void OnBreak(long Position, int Imm)
|
internal void OnBreak(long Position, int Imm)
|
||||||
|
|
|
@ -123,6 +123,8 @@ namespace ChocolArm64.Translation
|
||||||
{
|
{
|
||||||
EmitLdarg(ATranslatedSub.StateArgIdx);
|
EmitLdarg(ATranslatedSub.StateArgIdx);
|
||||||
|
|
||||||
|
EmitLdc_I4(CurrBlock.OpCodes.Count);
|
||||||
|
|
||||||
EmitPrivateCall(typeof(AThreadState), nameof(AThreadState.Synchronize));
|
EmitPrivateCall(typeof(AThreadState), nameof(AThreadState.Synchronize));
|
||||||
|
|
||||||
EmitLdc_I4(0);
|
EmitLdc_I4(0);
|
||||||
|
|
Loading…
Reference in a new issue