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:
gdkchan 2018-09-19 12:16:20 -03:00 committed by GitHub
parent f07e1fa8af
commit c08479877e
3 changed files with 25 additions and 9 deletions

View file

@ -46,8 +46,6 @@ namespace ChocolArm64
return false;
}
Work.Name = "cpu_thread_" + Work.ManagedThreadId;
Work.Start();
return true;

View file

@ -2,6 +2,7 @@ using ChocolArm64.Events;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
namespace ChocolArm64.State
@ -14,6 +15,8 @@ namespace ChocolArm64.State
internal const int ErgSizeLog2 = 4;
internal const int DczSizeLog2 = 4;
private const int MinInstForCheck = 4000000;
internal AExecutionMode ExecutionMode;
//AArch32 state.
@ -45,6 +48,8 @@ namespace ChocolArm64.State
private bool Interrupted;
private int SyncCount;
public long TpidrEl0 { get; set; }
public long Tpidr { get; set; }
@ -101,13 +106,16 @@ namespace ChocolArm64.State
TickCounter.Start();
}
internal bool Synchronize()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool Synchronize(int BbWeight)
{
if (Interrupted)
{
Interrupted = false;
//Firing a interrupt frequently is expensive, so we only
//do it after a given number of instructions has executed.
SyncCount += BbWeight;
OnInterrupt();
if (SyncCount >= MinInstForCheck)
{
CheckInterrupt();
}
return Running;
@ -118,10 +126,18 @@ namespace ChocolArm64.State
Interrupted = true;
}
private void OnInterrupt()
[MethodImpl(MethodImplOptions.NoInlining)]
private void CheckInterrupt()
{
SyncCount = 0;
if (Interrupted)
{
Interrupted = false;
Interrupt?.Invoke(this, EventArgs.Empty);
}
}
internal void OnBreak(long Position, int Imm)
{

View file

@ -123,6 +123,8 @@ namespace ChocolArm64.Translation
{
EmitLdarg(ATranslatedSub.StateArgIdx);
EmitLdc_I4(CurrBlock.OpCodes.Count);
EmitPrivateCall(typeof(AThreadState), nameof(AThreadState.Synchronize));
EmitLdc_I4(0);