Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
using ARMeilleure.Memory;
|
2019-03-15 04:37:54 +01:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-12-18 06:33:36 +01:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
2018-09-19 01:36:43 +02:00
|
|
|
using System;
|
2018-05-14 08:01:10 +02:00
|
|
|
using System.Collections.Generic;
|
2018-09-19 01:36:43 +02:00
|
|
|
using System.Linq;
|
2019-03-15 04:37:54 +01:00
|
|
|
using System.Text;
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
using System.Threading;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Threading
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-09-19 01:36:43 +02:00
|
|
|
class KThread : KSynchronizationObject, IKFutureSchedulerObject
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
private int _hostThreadRunning;
|
|
|
|
|
|
|
|
public Thread HostThread { get; private set; }
|
|
|
|
|
2019-10-31 19:09:03 +01:00
|
|
|
public ARMeilleure.State.ExecutionContext Context { get; private set; }
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
public long AffinityMask { get; set; }
|
2018-05-13 05:22:42 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
public long ThreadUid { get; private set; }
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
public long TotalTimeRunning { get; set; }
|
|
|
|
|
|
|
|
public KSynchronizationObject SignaledObj { get; set; }
|
2018-05-16 03:36:08 +02:00
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
public ulong CondVarAddress { get; set; }
|
2018-05-13 05:22:42 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private ulong _entrypoint;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
public ulong MutexAddress { get; set; }
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
public KProcess Owner { get; private set; }
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private ulong _tlsAddress;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
public ulong TlsAddress => _tlsAddress;
|
|
|
|
public ulong TlsDramAddress { get; private set; }
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
public long LastScheduledTime { get; set; }
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public LinkedListNode<KThread>[] SiblingsPerCore { get; private set; }
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
public LinkedList<KThread> Withholder { get; set; }
|
|
|
|
public LinkedListNode<KThread> WithholderNode { get; set; }
|
|
|
|
|
|
|
|
public LinkedListNode<KThread> ProcessListNode { get; set; }
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private LinkedList<KThread> _mutexWaiters;
|
|
|
|
private LinkedListNode<KThread> _mutexWaiterNode;
|
2018-02-14 03:43:08 +01:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
public KThread MutexOwner { get; private set; }
|
2018-06-26 06:09:32 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
public int ThreadHandleForUserMutex { get; set; }
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private ThreadSchedState _forcePauseFlags;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
public KernelResult ObjSyncResult { get; set; }
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
public int DynamicPriority { get; set; }
|
|
|
|
public int CurrentCore { get; set; }
|
|
|
|
public int BasePriority { get; set; }
|
|
|
|
public int PreferredCore { get; set; }
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private long _affinityMaskOverride;
|
|
|
|
private int _preferredCoreOverride;
|
|
|
|
private int _affinityOverrideCount;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
public ThreadSchedState SchedFlags { get; private set; }
|
|
|
|
|
2019-12-26 02:50:17 +01:00
|
|
|
private int _shallBeTerminated;
|
|
|
|
|
|
|
|
public bool ShallBeTerminated { get => _shallBeTerminated != 0; set => _shallBeTerminated = value ? 1 : 0; }
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
public bool SyncCancelled { get; set; }
|
|
|
|
public bool WaitingSync { get; set; }
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private bool _hasExited;
|
2019-01-18 23:26:39 +01:00
|
|
|
private bool _hasBeenInitialized;
|
|
|
|
private bool _hasBeenReleased;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
public bool WaitingInArbitration { get; set; }
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private KScheduler _scheduler;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private KSchedulingData _schedulingData;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
public long LastPc { get; set; }
|
2018-02-14 03:43:08 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public KThread(Horizon system) : base(system)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_scheduler = system.Scheduler;
|
|
|
|
_schedulingData = system.Scheduler.SchedulingData;
|
2018-05-13 05:22:42 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
SiblingsPerCore = new LinkedListNode<KThread>[KScheduler.CpuCoresCount];
|
2018-05-14 08:01:10 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_mutexWaiters = new LinkedList<KThread>();
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public KernelResult Initialize(
|
2018-12-06 12:16:24 +01:00
|
|
|
ulong entrypoint,
|
|
|
|
ulong argsPtr,
|
|
|
|
ulong stackTop,
|
|
|
|
int priority,
|
|
|
|
int defaultCpuCore,
|
|
|
|
KProcess owner,
|
2019-12-26 02:50:17 +01:00
|
|
|
ThreadType type = ThreadType.User,
|
|
|
|
ThreadStart customHostThreadStart = null)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if ((uint)type > 3)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
throw new ArgumentException($"Invalid thread type \"{type}\".");
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
PreferredCore = defaultCpuCore;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
AffinityMask |= 1L << defaultCpuCore;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
SchedFlags = type == ThreadType.Dummy
|
2018-11-28 23:18:09 +01:00
|
|
|
? ThreadSchedState.Running
|
|
|
|
: ThreadSchedState.None;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
CurrentCore = PreferredCore;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
DynamicPriority = priority;
|
|
|
|
BasePriority = priority;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
ObjSyncResult = KernelResult.ThreadNotStarted;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_entrypoint = entrypoint;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (type == ThreadType.User)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (owner.AllocateThreadLocalStorage(out _tlsAddress) != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
return KernelResult.OutOfMemory;
|
|
|
|
}
|
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
TlsDramAddress = owner.MemoryManager.GetDramAddressFromVa(_tlsAddress);
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
MemoryHelper.FillWithZeros(owner.CpuMemory, (long)_tlsAddress, KTlsPageInfo.TlsEntrySize);
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
bool is64Bits;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (owner != null)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
Owner = owner;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
owner.IncrementReferenceCount();
|
2018-12-06 12:16:24 +01:00
|
|
|
owner.IncrementThreadCount();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
is64Bits = (owner.MmuFlags & 1) != 0;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
is64Bits = true;
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2020-01-13 01:21:54 +01:00
|
|
|
HostThread = new Thread(customHostThreadStart ?? (() => ThreadStart(entrypoint)));
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2019-10-31 19:09:03 +01:00
|
|
|
Context = new ARMeilleure.State.ExecutionContext();
|
Implement some ARM32 memory instructions and CMP (#565)
* Implement ARM32 memory instructions: LDM, LDR, LDRB, LDRD, LDRH, LDRSB, LDRSH, STM, STR, STRB, STRD, STRH (immediate and register + immediate variants), implement CMP (immediate and register shifted by immediate variants)
* Rename some opcode classes and flag masks for consistency
* Fix a few suboptimal ARM32 codegen issues, only loads should be considered on decoder when checking if Rt == PC, and only NZCV flags should be considered for comparison optimizations
* Take into account Rt2 for LDRD instructions aswell when checking if the instruction changes PC
* Re-align arm32 instructions on the opcode table
2019-01-29 17:06:11 +01:00
|
|
|
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
bool isAarch32 = (Owner.MmuFlags & 1) == 0;
|
2019-01-25 02:59:53 +01:00
|
|
|
|
2019-11-14 15:28:13 +01:00
|
|
|
Context.IsAarch32 = isAarch32;
|
|
|
|
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
Context.SetX(0, argsPtr);
|
Implement some ARM32 memory instructions and CMP (#565)
* Implement ARM32 memory instructions: LDM, LDR, LDRB, LDRD, LDRH, LDRSB, LDRSH, STM, STR, STRB, STRD, STRH (immediate and register + immediate variants), implement CMP (immediate and register shifted by immediate variants)
* Rename some opcode classes and flag masks for consistency
* Fix a few suboptimal ARM32 codegen issues, only loads should be considered on decoder when checking if Rt == PC, and only NZCV flags should be considered for comparison optimizations
* Take into account Rt2 for LDRD instructions aswell when checking if the instruction changes PC
* Re-align arm32 instructions on the opcode table
2019-01-29 17:06:11 +01:00
|
|
|
|
|
|
|
if (isAarch32)
|
|
|
|
{
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
Context.SetX(13, (uint)stackTop);
|
Implement some ARM32 memory instructions and CMP (#565)
* Implement ARM32 memory instructions: LDM, LDR, LDRB, LDRD, LDRH, LDRSB, LDRSH, STM, STR, STRB, STRD, STRH (immediate and register + immediate variants), implement CMP (immediate and register shifted by immediate variants)
* Rename some opcode classes and flag masks for consistency
* Fix a few suboptimal ARM32 codegen issues, only loads should be considered on decoder when checking if Rt == PC, and only NZCV flags should be considered for comparison optimizations
* Take into account Rt2 for LDRD instructions aswell when checking if the instruction changes PC
* Re-align arm32 instructions on the opcode table
2019-01-29 17:06:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
Context.SetX(31, stackTop);
|
Implement some ARM32 memory instructions and CMP (#565)
* Implement ARM32 memory instructions: LDM, LDR, LDRB, LDRD, LDRH, LDRSB, LDRSH, STM, STR, STRB, STRD, STRH (immediate and register + immediate variants), implement CMP (immediate and register shifted by immediate variants)
* Rename some opcode classes and flag masks for consistency
* Fix a few suboptimal ARM32 codegen issues, only loads should be considered on decoder when checking if Rt == PC, and only NZCV flags should be considered for comparison optimizations
* Take into account Rt2 for LDRD instructions aswell when checking if the instruction changes PC
* Re-align arm32 instructions on the opcode table
2019-01-29 17:06:11 +01:00
|
|
|
}
|
2018-11-28 23:18:09 +01:00
|
|
|
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
Context.CntfrqEl0 = 19200000;
|
|
|
|
Context.Tpidr = (long)_tlsAddress;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
owner.SubscribeThreadEventHandlers(Context);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
ThreadUid = System.GetThreadUid();
|
|
|
|
|
2020-01-13 01:21:54 +01:00
|
|
|
HostThread.Name = $"HLE.HostThread.{ThreadUid}";
|
2019-12-26 02:50:17 +01:00
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
_hasBeenInitialized = true;
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (owner != null)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
owner.AddThread(this);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (owner.IsPaused)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
System.CriticalSection.Enter();
|
|
|
|
|
|
|
|
if (ShallBeTerminated || SchedFlags == ThreadSchedState.TerminationPending)
|
|
|
|
{
|
|
|
|
System.CriticalSection.Leave();
|
|
|
|
|
|
|
|
return KernelResult.Success;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_forcePauseFlags |= ThreadSchedState.ProcessPauseFlag;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
CombineForcePauseFlags();
|
|
|
|
|
|
|
|
System.CriticalSection.Leave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return KernelResult.Success;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
public KernelResult Start()
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
if (!System.KernelInitialized)
|
|
|
|
{
|
|
|
|
System.CriticalSection.Enter();
|
|
|
|
|
|
|
|
if (!ShallBeTerminated && SchedFlags != ThreadSchedState.TerminationPending)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_forcePauseFlags |= ThreadSchedState.KernelInitPauseFlag;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
CombineForcePauseFlags();
|
|
|
|
}
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
KernelResult result = KernelResult.ThreadTerminating;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
if (!ShallBeTerminated)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
KThread currentThread = System.Scheduler.GetCurrentThread();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
while (SchedFlags != ThreadSchedState.TerminationPending &&
|
2018-12-06 12:16:24 +01:00
|
|
|
currentThread.SchedFlags != ThreadSchedState.TerminationPending &&
|
|
|
|
!currentThread.ShallBeTerminated)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
if ((SchedFlags & ThreadSchedState.LowMask) != ThreadSchedState.None)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
result = KernelResult.InvalidState;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (currentThread._forcePauseFlags == ThreadSchedState.None)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (Owner != null && _forcePauseFlags != ThreadSchedState.None)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
CombineForcePauseFlags();
|
|
|
|
}
|
|
|
|
|
|
|
|
SetNewSchedFlags(ThreadSchedState.Running);
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
result = KernelResult.Success;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
currentThread.CombineForcePauseFlags();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (currentThread.ShallBeTerminated)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return result;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Exit()
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// TODO: Debug event.
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (Owner != null)
|
|
|
|
{
|
|
|
|
Owner.ResourceLimit?.Release(LimitableResource.Thread, 0, 1);
|
|
|
|
|
|
|
|
_hasBeenReleased = true;
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_forcePauseFlags &= ~ThreadSchedState.ForcePauseMask;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
ExitImpl();
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
DecrementReferenceCount();
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2019-12-26 02:50:17 +01:00
|
|
|
public ThreadSchedState PrepareForTermination()
|
|
|
|
{
|
|
|
|
System.CriticalSection.Enter();
|
|
|
|
|
|
|
|
ThreadSchedState result;
|
|
|
|
|
|
|
|
if (Interlocked.CompareExchange(ref _shallBeTerminated, 1, 0) == 0)
|
|
|
|
{
|
|
|
|
if ((SchedFlags & ThreadSchedState.LowMask) == ThreadSchedState.None)
|
|
|
|
{
|
|
|
|
SchedFlags = ThreadSchedState.TerminationPending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_forcePauseFlags != ThreadSchedState.None)
|
|
|
|
{
|
|
|
|
_forcePauseFlags &= ~ThreadSchedState.ThreadPauseFlag;
|
|
|
|
|
|
|
|
ThreadSchedState oldSchedFlags = SchedFlags;
|
|
|
|
|
|
|
|
SchedFlags &= ThreadSchedState.LowMask;
|
|
|
|
|
|
|
|
AdjustScheduling(oldSchedFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BasePriority >= 0x10)
|
|
|
|
{
|
|
|
|
SetPriority(0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((SchedFlags & ThreadSchedState.LowMask) == ThreadSchedState.Running)
|
|
|
|
{
|
|
|
|
// TODO: GIC distributor stuffs (sgir changes ect)
|
|
|
|
}
|
|
|
|
|
|
|
|
SignaledObj = null;
|
|
|
|
ObjSyncResult = KernelResult.ThreadTerminating;
|
|
|
|
|
|
|
|
ReleaseAndResume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = SchedFlags;
|
|
|
|
|
|
|
|
System.CriticalSection.Leave();
|
|
|
|
|
|
|
|
return result & ThreadSchedState.LowMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Terminate()
|
|
|
|
{
|
|
|
|
ThreadSchedState state = PrepareForTermination();
|
|
|
|
|
|
|
|
if (state != ThreadSchedState.TerminationPending)
|
|
|
|
{
|
|
|
|
System.Synchronization.WaitFor(new KSynchronizationObject[] { this }, -1, out _);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void HandlePostSyscall()
|
|
|
|
{
|
|
|
|
ThreadSchedState state;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (ShallBeTerminated || SchedFlags == ThreadSchedState.TerminationPending)
|
|
|
|
{
|
|
|
|
System.Scheduler.ExitThread(this);
|
|
|
|
Exit();
|
|
|
|
|
|
|
|
// As the death of the thread is handled by the CPU emulator, we differ from the official kernel and return here.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.CriticalSection.Enter();
|
|
|
|
|
|
|
|
if (ShallBeTerminated || SchedFlags == ThreadSchedState.TerminationPending)
|
|
|
|
{
|
|
|
|
state = ThreadSchedState.TerminationPending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_forcePauseFlags != ThreadSchedState.None)
|
|
|
|
{
|
|
|
|
CombineForcePauseFlags();
|
|
|
|
}
|
|
|
|
|
|
|
|
state = ThreadSchedState.Running;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.CriticalSection.Leave();
|
|
|
|
} while (state == ThreadSchedState.TerminationPending);
|
|
|
|
}
|
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
private void ExitImpl()
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
SetNewSchedFlags(ThreadSchedState.TerminationPending);
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_hasExited = true;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
Signal();
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
public KernelResult Sleep(long timeout)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
if (ShallBeTerminated || SchedFlags == ThreadSchedState.TerminationPending)
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
return KernelResult.ThreadTerminating;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SetNewSchedFlags(ThreadSchedState.Paused);
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (timeout > 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
System.TimeManager.ScheduleFutureInvocation(this, timeout);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (timeout > 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
System.TimeManager.UnscheduleFutureInvocation(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Yield()
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
if (SchedFlags != ThreadSchedState.Running)
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
System.Scheduler.ContextSwitch();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DynamicPriority < KScheduler.PrioritiesCount)
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Move current thread to the end of the queue.
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Reschedule(DynamicPriority, CurrentCore, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_scheduler.ThreadReselectionRequested = true;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
System.Scheduler.ContextSwitch();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void YieldWithLoadBalancing()
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
if (SchedFlags != ThreadSchedState.Running)
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
System.Scheduler.ContextSwitch();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
int prio = DynamicPriority;
|
|
|
|
int core = CurrentCore;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
KThread nextThreadOnCurrentQueue = null;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
if (DynamicPriority < KScheduler.PrioritiesCount)
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Move current thread to the end of the queue.
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Reschedule(prio, core, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
Func<KThread, bool> predicate = x => x.DynamicPriority == prio;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
nextThreadOnCurrentQueue = _schedulingData.ScheduledThreads(core).FirstOrDefault(predicate);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerable<KThread> SuitableCandidates()
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
foreach (KThread thread in _schedulingData.SuggestedThreads(core))
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
int srcCore = thread.CurrentCore;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (srcCore >= 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
KThread selectedSrcCore = _scheduler.CoreContexts[srcCore].SelectedThread;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (selectedSrcCore == thread || ((selectedSrcCore?.DynamicPriority ?? 2) < 2))
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// If the candidate was scheduled after the current thread, then it's not worth it,
|
|
|
|
// unless the priority is higher than the current one.
|
2018-12-06 12:16:24 +01:00
|
|
|
if (nextThreadOnCurrentQueue.LastScheduledTime >= thread.LastScheduledTime ||
|
|
|
|
nextThreadOnCurrentQueue.DynamicPriority < thread.DynamicPriority)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
yield return thread;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
KThread dst = SuitableCandidates().FirstOrDefault(x => x.DynamicPriority <= prio);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (dst != null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.TransferToCore(dst.DynamicPriority, core, dst);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_scheduler.ThreadReselectionRequested = true;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (this != nextThreadOnCurrentQueue)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_scheduler.ThreadReselectionRequested = true;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
System.Scheduler.ContextSwitch();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void YieldAndWaitForLoadBalancing()
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
if (SchedFlags != ThreadSchedState.Running)
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
System.Scheduler.ContextSwitch();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
int core = CurrentCore;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.TransferToCore(DynamicPriority, -1, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
KThread selectedThread = null;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!_schedulingData.ScheduledThreads(core).Any())
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
foreach (KThread thread in _schedulingData.SuggestedThreads(core))
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (thread.CurrentCore < 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
KThread firstCandidate = _schedulingData.ScheduledThreads(thread.CurrentCore).FirstOrDefault();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (firstCandidate == thread)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (firstCandidate == null || firstCandidate.DynamicPriority >= 2)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.TransferToCore(thread.DynamicPriority, core, thread);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
selectedThread = thread;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (selectedThread != this)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_scheduler.ThreadReselectionRequested = true;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
System.Scheduler.ContextSwitch();
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public void SetPriority(int priority)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
BasePriority = priority;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
UpdatePriorityInheritance();
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
public KernelResult SetActivity(bool pause)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-18 06:33:36 +01:00
|
|
|
KernelResult result = KernelResult.Success;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ThreadSchedState lowNibble = SchedFlags & ThreadSchedState.LowMask;
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (lowNibble != ThreadSchedState.Paused && lowNibble != ThreadSchedState.Running)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
return KernelResult.InvalidState;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
if (!ShallBeTerminated && SchedFlags != ThreadSchedState.TerminationPending)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (pause)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Pause, the force pause flag should be clear (thread is NOT paused).
|
2018-12-06 12:16:24 +01:00
|
|
|
if ((_forcePauseFlags & ThreadSchedState.ThreadPauseFlag) == 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_forcePauseFlags |= ThreadSchedState.ThreadPauseFlag;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
CombineForcePauseFlags();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-18 06:33:36 +01:00
|
|
|
result = KernelResult.InvalidState;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Unpause, the force pause flag should be set (thread is paused).
|
2018-12-06 12:16:24 +01:00
|
|
|
if ((_forcePauseFlags & ThreadSchedState.ThreadPauseFlag) != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
ThreadSchedState oldForcePauseFlags = _forcePauseFlags;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_forcePauseFlags &= ~ThreadSchedState.ThreadPauseFlag;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if ((oldForcePauseFlags & ~ThreadSchedState.ThreadPauseFlag) == ThreadSchedState.None)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
ThreadSchedState oldSchedFlags = SchedFlags;
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
SchedFlags &= ThreadSchedState.LowMask;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
AdjustScheduling(oldSchedFlags);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2018-05-13 05:22:42 +02:00
|
|
|
{
|
2018-12-18 06:33:36 +01:00
|
|
|
result = KernelResult.InvalidState;
|
2018-05-13 05:22:42 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return result;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void CancelSynchronization()
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
if ((SchedFlags & ThreadSchedState.LowMask) != ThreadSchedState.Paused || !WaitingSync)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
SyncCancelled = true;
|
|
|
|
}
|
2018-11-28 23:18:09 +01:00
|
|
|
else if (Withholder != null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
Withholder.Remove(WithholderNode);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
SetNewSchedFlags(ThreadSchedState.Running);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
Withholder = null;
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
SyncCancelled = true;
|
2018-06-22 04:05:42 +02:00
|
|
|
}
|
2018-09-19 01:36:43 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SignaledObj = null;
|
2018-12-18 06:33:36 +01:00
|
|
|
ObjSyncResult = KernelResult.Cancelled;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
SetNewSchedFlags(ThreadSchedState.Running);
|
|
|
|
|
|
|
|
SyncCancelled = false;
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public KernelResult SetCoreAndAffinityMask(int newCore, long newAffinityMask)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
bool useOverride = _affinityOverrideCount != 0;
|
2018-05-13 05:22:42 +02:00
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// The value -3 is "do not change the preferred core".
|
2018-12-06 12:16:24 +01:00
|
|
|
if (newCore == -3)
|
2018-06-22 04:05:42 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
newCore = useOverride ? _preferredCoreOverride : PreferredCore;
|
2018-05-13 05:22:42 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if ((newAffinityMask & (1 << newCore)) == 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
return KernelResult.InvalidCombination;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (useOverride)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_preferredCoreOverride = newCore;
|
|
|
|
_affinityMaskOverride = newAffinityMask;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
long oldAffinityMask = AffinityMask;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
PreferredCore = newCore;
|
|
|
|
AffinityMask = newAffinityMask;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (oldAffinityMask != newAffinityMask)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
int oldCore = CurrentCore;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
if (CurrentCore >= 0 && ((AffinityMask >> CurrentCore) & 1) == 0)
|
|
|
|
{
|
|
|
|
if (PreferredCore < 0)
|
|
|
|
{
|
|
|
|
CurrentCore = HighestSetCore(AffinityMask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentCore = PreferredCore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
AdjustSchedulingForNewAffinity(oldAffinityMask, oldCore);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
return KernelResult.Success;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private static int HighestSetCore(long mask)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
for (int core = KScheduler.CpuCoresCount - 1; core >= 0; core--)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (((mask >> core) & 1) != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
return core;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CombineForcePauseFlags()
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
ThreadSchedState oldFlags = SchedFlags;
|
|
|
|
ThreadSchedState lowNibble = SchedFlags & ThreadSchedState.LowMask;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
SchedFlags = lowNibble | _forcePauseFlags;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
AdjustScheduling(oldFlags);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private void SetNewSchedFlags(ThreadSchedState newFlags)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ThreadSchedState oldFlags = SchedFlags;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
SchedFlags = (oldFlags & ThreadSchedState.HighMask) | newFlags;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if ((oldFlags & ThreadSchedState.LowMask) != newFlags)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
AdjustScheduling(oldFlags);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ReleaseAndResume()
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
if ((SchedFlags & ThreadSchedState.LowMask) == ThreadSchedState.Paused)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
if (Withholder != null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
Withholder.Remove(WithholderNode);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
SetNewSchedFlags(ThreadSchedState.Running);
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
Withholder = null;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetNewSchedFlags(ThreadSchedState.Running);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public void Reschedule(ThreadSchedState newFlags)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Enter();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ThreadSchedState oldFlags = SchedFlags;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
SchedFlags = (oldFlags & ThreadSchedState.HighMask) |
|
|
|
|
(newFlags & ThreadSchedState.LowMask);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
AdjustScheduling(oldFlags);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public void AddMutexWaiter(KThread requester)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
AddToMutexWaitersList(requester);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
requester.MutexOwner = this;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
UpdatePriorityInheritance();
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public void RemoveMutexWaiter(KThread thread)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (thread._mutexWaiterNode?.List != null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_mutexWaiters.Remove(thread._mutexWaiterNode);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
thread.MutexOwner = null;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
UpdatePriorityInheritance();
|
|
|
|
}
|
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
public KThread RelinquishMutex(ulong mutexAddress, out int count)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
count = 0;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_mutexWaiters.First == null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
KThread newMutexOwner = null;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
LinkedListNode<KThread> currentNode = _mutexWaiters.First;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Skip all threads that are not waiting for this mutex.
|
2018-12-06 12:16:24 +01:00
|
|
|
while (currentNode != null && currentNode.Value.MutexAddress != mutexAddress)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
currentNode = currentNode.Next;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (currentNode == null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
LinkedListNode<KThread> nextNode = currentNode.Next;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_mutexWaiters.Remove(currentNode);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
currentNode.Value.MutexOwner = newMutexOwner;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (newMutexOwner != null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// New owner was already selected, re-insert on new owner list.
|
2018-12-06 12:16:24 +01:00
|
|
|
newMutexOwner.AddToMutexWaitersList(currentNode.Value);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// New owner not selected yet, use current thread.
|
2018-12-06 12:16:24 +01:00
|
|
|
newMutexOwner = currentNode.Value;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
count++;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
currentNode = nextNode;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
while (currentNode != null);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (newMutexOwner != null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
UpdatePriorityInheritance();
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
newMutexOwner.UpdatePriorityInheritance();
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return newMutexOwner;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdatePriorityInheritance()
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// If any of the threads waiting for the mutex has
|
|
|
|
// higher priority than the current thread, then
|
|
|
|
// the current thread inherits that priority.
|
2018-12-06 12:16:24 +01:00
|
|
|
int highestPriority = BasePriority;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_mutexWaiters.First != null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
int waitingDynamicPriority = _mutexWaiters.First.Value.DynamicPriority;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (waitingDynamicPriority < highestPriority)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
highestPriority = waitingDynamicPriority;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (highestPriority != DynamicPriority)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
int oldPriority = DynamicPriority;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
DynamicPriority = highestPriority;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
AdjustSchedulingForNewPriority(oldPriority);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
if (MutexOwner != null)
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Remove and re-insert to ensure proper sorting based on new priority.
|
2018-12-06 12:16:24 +01:00
|
|
|
MutexOwner._mutexWaiters.Remove(_mutexWaiterNode);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
MutexOwner.AddToMutexWaitersList(this);
|
|
|
|
|
|
|
|
MutexOwner.UpdatePriorityInheritance();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private void AddToMutexWaitersList(KThread thread)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
LinkedListNode<KThread> nextPrio = _mutexWaiters.First;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
int currentPriority = thread.DynamicPriority;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
while (nextPrio != null && nextPrio.Value.DynamicPriority <= currentPriority)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
nextPrio = nextPrio.Next;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (nextPrio != null)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
thread._mutexWaiterNode = _mutexWaiters.AddBefore(nextPrio, thread);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
thread._mutexWaiterNode = _mutexWaiters.AddLast(thread);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private void AdjustScheduling(ThreadSchedState oldFlags)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (oldFlags == SchedFlags)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (oldFlags == ThreadSchedState.Running)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Was running, now it's stopped.
|
2018-09-19 01:36:43 +02:00
|
|
|
if (CurrentCore >= 0)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Unschedule(DynamicPriority, CurrentCore, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
for (int core = 0; core < KScheduler.CpuCoresCount; core++)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (core != CurrentCore && ((AffinityMask >> core) & 1) != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Unsuggest(DynamicPriority, core, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (SchedFlags == ThreadSchedState.Running)
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Was stopped, now it's running.
|
2018-09-19 01:36:43 +02:00
|
|
|
if (CurrentCore >= 0)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Schedule(DynamicPriority, CurrentCore, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
for (int core = 0; core < KScheduler.CpuCoresCount; core++)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (core != CurrentCore && ((AffinityMask >> core) & 1) != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Suggest(DynamicPriority, core, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_scheduler.ThreadReselectionRequested = true;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private void AdjustSchedulingForNewPriority(int oldPriority)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
if (SchedFlags != ThreadSchedState.Running)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Remove thread from the old priority queues.
|
2018-09-19 01:36:43 +02:00
|
|
|
if (CurrentCore >= 0)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Unschedule(oldPriority, CurrentCore, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
for (int core = 0; core < KScheduler.CpuCoresCount; core++)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (core != CurrentCore && ((AffinityMask >> core) & 1) != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Unsuggest(oldPriority, core, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Add thread to the new priority queues.
|
2018-12-06 12:16:24 +01:00
|
|
|
KThread currentThread = _scheduler.GetCurrentThread();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
|
|
|
if (CurrentCore >= 0)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (currentThread == this)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.SchedulePrepend(DynamicPriority, CurrentCore, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Schedule(DynamicPriority, CurrentCore, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
for (int core = 0; core < KScheduler.CpuCoresCount; core++)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (core != CurrentCore && ((AffinityMask >> core) & 1) != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Suggest(DynamicPriority, core, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_scheduler.ThreadReselectionRequested = true;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private void AdjustSchedulingForNewAffinity(long oldAffinityMask, int oldCore)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
if (SchedFlags != ThreadSchedState.Running || DynamicPriority >= KScheduler.PrioritiesCount)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Remove thread from the old priority queues.
|
2018-12-06 12:16:24 +01:00
|
|
|
for (int core = 0; core < KScheduler.CpuCoresCount; core++)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (((oldAffinityMask >> core) & 1) != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (core == oldCore)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Unschedule(DynamicPriority, core, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Unsuggest(DynamicPriority, core, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Add thread to the new priority queues.
|
2018-12-06 12:16:24 +01:00
|
|
|
for (int core = 0; core < KScheduler.CpuCoresCount; core++)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (((AffinityMask >> core) & 1) != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (core == CurrentCore)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Schedule(DynamicPriority, core, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_schedulingData.Suggest(DynamicPriority, core, this);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_scheduler.ThreadReselectionRequested = true;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public void SetEntryArguments(long argsPtr, int threadHandle)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
Context.SetX(0, (ulong)argsPtr);
|
|
|
|
Context.SetX(1, (ulong)threadHandle);
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
public void TimeUp()
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
ReleaseAndResume();
|
|
|
|
}
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
public string GetGuestStackTrace()
|
|
|
|
{
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
return Owner.Debugger.GetGuestStackTrace(Context);
|
2019-03-15 04:37:54 +01:00
|
|
|
}
|
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
public void PrintGuestStackTrace()
|
|
|
|
{
|
2019-03-15 04:37:54 +01:00
|
|
|
StringBuilder trace = new StringBuilder();
|
|
|
|
|
|
|
|
trace.AppendLine("Guest stack trace:");
|
|
|
|
trace.AppendLine(GetGuestStackTrace());
|
|
|
|
|
|
|
|
Logger.PrintInfo(LogClass.Cpu, trace.ToString());
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
public void Execute()
|
|
|
|
{
|
|
|
|
if (Interlocked.CompareExchange(ref _hostThreadRunning, 1, 0) == 0)
|
|
|
|
{
|
|
|
|
HostThread.Start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ThreadStart(ulong entrypoint)
|
|
|
|
{
|
|
|
|
Owner.Translator.Execute(Context, entrypoint);
|
|
|
|
|
|
|
|
ThreadExit();
|
Use a Jump Table for direct and indirect calls/jumps, removing transitions to managed (#975)
* Implement Jump Table for Native Calls
NOTE: this slows down rejit considerably! Not recommended to be used
without codegen optimisation or AOT.
- Does not work on Linux
- A32 needs an additional commit.
* A32 Support
(WIP)
* Actually write Direct Call pointers to the table
That would help.
* Direct Calls: Rather than returning to the translator, attempt to keep within the native stack frame.
A return to the translator can still happen, but only by exceptionally
bubbling up to it.
Also:
- Always translate lowCq as a function. Faster interop with the direct
jumps, and this will be useful in future if we want to do speculative
translation.
- Tail Call Detection: after the decoding stage, detect if we do a tail
call, and avoid translating into it. Detected if a jump is made to an
address outwith the contiguous sequence of blocks surrounding the entry
point. The goal is to reduce code touched by jit and rejit.
* A32 Support
* Use smaller max function size for lowCq, fix exceptional returns
When a return has an unexpected value and there is no code block
following this one, we now return the value rather than continuing.
* CompareAndSwap (buggy)
* Ensure CompareAndSwap does not get optimized away.
* Use CompareAndSwap to make the dynamic table thread safe.
* Tail call for linux, throw on too many arguments.
* Combine CompareAndSwap 128 and 32/64.
They emit different IR instructions since their PreAllocator behaviour
is different, but now they just have one function on EmitterContext.
* Fix issues separating from optimisations.
* Use a stub to find and execute missing functions.
This allows us to skip doing many runtime comparisons and branches, and reduces the amount of code we need to emit significantly.
For the indirect call table, this stub also does the work of moving in the highCq address to the table when one is found.
* Make Jump Tables and Jit Cache dynmically resize
Reserve virtual memory, commit as needed.
* Move TailCallRemover to its own class.
* Multithreaded Translation (based on heuristic)
A poor one, at that. Need to get core count for a better one, which
means a lot of OS specific garbage.
* Better priority management for background threads.
* Bound core limit a bit more
Past a certain point the load is not paralellizable and starts stealing from the main thread. Likely due to GC, memory, heap allocation thread contention. Reduce by one core til optimisations come to improve the situation.
* Fix memory management on linux.
* Temporary solution to some sync problems.
This will make sure threads exit correctly, most of the time. There is a potential race where setting the sync counter to 0 does nothing (counter stays at what it was before, thread could take too long to exit), but we need to find a better way to do this anyways. Synchronization frequency has been tightened as we never enter blockwise segments of code. Essentially this means, check every x functions or loop iterations, before lowcq blocks existed and were worth just as much. Ideally it should be done in a better way, since functions can be anywhere from 1 to 5000 instructions. (maybe based on host timer, or an interrupt flag from a scheduler thread)
* Address feedback minus CompareAndSwap change.
* Use default ReservedRegion granularity.
* Merge CompareAndSwap with its V128 variant.
* We already got the source, no need to do it again.
* Make sure all background translation threads exit.
* Fix CompareAndSwap128
Detection criteria was a bit scuffed.
* Address Comments.
2020-03-12 04:20:55 +01:00
|
|
|
|
|
|
|
Context.Dispose();
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ThreadExit()
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
System.Scheduler.ExitThread(this);
|
2019-01-18 23:26:39 +01:00
|
|
|
System.Scheduler.RemoveThread(this);
|
|
|
|
}
|
2018-11-28 23:18:09 +01:00
|
|
|
|
Add a new JIT compiler for CPU code (#693)
* Start of the ARMeilleure project
* Refactoring around the old IRAdapter, now renamed to PreAllocator
* Optimize the LowestBitSet method
* Add CLZ support and fix CLS implementation
* Add missing Equals and GetHashCode overrides on some structs, misc small tweaks
* Implement the ByteSwap IR instruction, and some refactoring on the assembler
* Implement the DivideUI IR instruction and fix 64-bits IDIV
* Correct constant operand type on CSINC
* Move division instructions implementation to InstEmitDiv
* Fix destination type for the ConditionalSelect IR instruction
* Implement UMULH and SMULH, with new IR instructions
* Fix some issues with shift instructions
* Fix constant types for BFM instructions
* Fix up new tests using the new V128 struct
* Update tests
* Move DIV tests to a separate file
* Add support for calls, and some instructions that depends on them
* Start adding support for SIMD & FP types, along with some of the related ARM instructions
* Fix some typos and the divide instruction with FP operands
* Fix wrong method call on Clz_V
* Implement ARM FP & SIMD move instructions, Saddlv_V, and misc. fixes
* Implement SIMD logical instructions and more misc. fixes
* Fix PSRAD x86 instruction encoding, TRN, UABD and UABDL implementations
* Implement float conversion instruction, merge in LDj3SNuD fixes, and some other misc. fixes
* Implement SIMD shift instruction and fix Dup_V
* Add SCVTF and UCVTF (vector, fixed-point) variants to the opcode table
* Fix check with tolerance on tester
* Implement FP & SIMD comparison instructions, and some fixes
* Update FCVT (Scalar) encoding on the table to support the Half-float variants
* Support passing V128 structs, some cleanup on the register allocator, merge LDj3SNuD fixes
* Use old memory access methods, made a start on SIMD memory insts support, some fixes
* Fix float constant passed to functions, save and restore non-volatile XMM registers, other fixes
* Fix arguments count with struct return values, other fixes
* More instructions
* Misc. fixes and integrate LDj3SNuD fixes
* Update tests
* Add a faster linear scan allocator, unwinding support on windows, and other changes
* Update Ryujinx.HLE
* Update Ryujinx.Graphics
* Fix V128 return pointer passing, RCX is clobbered
* Update Ryujinx.Tests
* Update ITimeZoneService
* Stop using GetFunctionPointer as that can't be called from native code, misc. fixes and tweaks
* Use generic GetFunctionPointerForDelegate method and other tweaks
* Some refactoring on the code generator, assert on invalid operations and use a separate enum for intrinsics
* Remove some unused code on the assembler
* Fix REX.W prefix regression on float conversion instructions, add some sort of profiler
* Add hardware capability detection
* Fix regression on Sha1h and revert Fcm** changes
* Add SSE2-only paths on vector extract and insert, some refactoring on the pre-allocator
* Fix silly mistake introduced on last commit on CpuId
* Generate inline stack probes when the stack allocation is too large
* Initial support for the System-V ABI
* Support multiple destination operands
* Fix SSE2 VectorInsert8 path, and other fixes
* Change placement of XMM callee save and restore code to match other compilers
* Rename Dest to Destination and Inst to Instruction
* Fix a regression related to calls and the V128 type
* Add an extra space on comments to match code style
* Some refactoring
* Fix vector insert FP32 SSE2 path
* Port over the ARM32 instructions
* Avoid memory protection races on JIT Cache
* Another fix on VectorInsert FP32 (thanks to LDj3SNuD
* Float operands don't need to use the same register when VEX is supported
* Add a new register allocator, higher quality code for hot code (tier up), and other tweaks
* Some nits, small improvements on the pre allocator
* CpuThreadState is gone
* Allow changing CPU emulators with a config entry
* Add runtime identifiers on the ARMeilleure project
* Allow switching between CPUs through a config entry (pt. 2)
* Change win10-x64 to win-x64 on projects
* Update the Ryujinx project to use ARMeilleure
* Ensure that the selected register is valid on the hybrid allocator
* Allow exiting on returns to 0 (should fix test regression)
* Remove register assignments for most used variables on the hybrid allocator
* Do not use fixed registers as spill temp
* Add missing namespace and remove unneeded using
* Address PR feedback
* Fix types, etc
* Enable AssumeStrictAbiCompliance by default
* Ensure that Spill and Fill don't load or store any more than necessary
2019-08-08 20:56:22 +02:00
|
|
|
public bool IsCurrentHostThread()
|
|
|
|
{
|
|
|
|
return Thread.CurrentThread == HostThread;
|
|
|
|
}
|
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
public override bool IsSignaled()
|
|
|
|
{
|
|
|
|
return _hasExited;
|
|
|
|
}
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
protected override void Destroy()
|
|
|
|
{
|
|
|
|
if (_hasBeenInitialized)
|
|
|
|
{
|
|
|
|
FreeResources();
|
|
|
|
|
|
|
|
bool released = Owner != null || _hasBeenReleased;
|
|
|
|
|
|
|
|
if (Owner != null)
|
|
|
|
{
|
|
|
|
Owner.ResourceLimit?.Release(LimitableResource.Thread, 1, released ? 0 : 1);
|
|
|
|
|
|
|
|
Owner.DecrementReferenceCount();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.ResourceLimit.Release(LimitableResource.Thread, 1, released ? 0 : 1);
|
|
|
|
}
|
|
|
|
}
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
private void FreeResources()
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
Owner?.RemoveThread(this);
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_tlsAddress != 0 && Owner.FreeThreadLocalStorage(_tlsAddress) != KernelResult.Success)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Unexpected failure freeing thread local storage.");
|
|
|
|
}
|
|
|
|
|
|
|
|
System.CriticalSection.Enter();
|
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Wake up all threads that may be waiting for a mutex being held by this thread.
|
2018-12-06 12:16:24 +01:00
|
|
|
foreach (KThread thread in _mutexWaiters)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
thread.MutexOwner = null;
|
|
|
|
thread._preferredCoreOverride = 0;
|
2018-12-18 06:33:36 +01:00
|
|
|
thread.ObjSyncResult = KernelResult.InvalidState;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
thread.ReleaseAndResume();
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
System.CriticalSection.Leave();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
Owner?.DecrementThreadCountAndTerminateIfZero();
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|