Repository navigation
Make the Xenoblade Chronicles: Definitive Edition profile work on Android (2/3): core_preempt lock - #641
Open
tapionallanaire wants to merge 1 commit into
Open
Make the Xenoblade Chronicles: Definitive Edition profile work on Android (2/3): core_preempt lock#641tapionallanaire wants to merge 1 commit into
tapionallanaire wants to merge 1 commit into
Conversation
On Horizon two threads of one core never run at the same moment: a running thread gives its core up only where it blocks, sleeps or yields, or when a higher-priority thread of the core preempts it. The host runs every guest thread on its own pthread, so threads of one core run side by side. Xenoblade Chronicles: Definitive Edition corrupts its heap at boot when they do: about one boot in four crashed 1-4 s into nnMain at changing sites (a memset of a size read from a resource block's footer, null and wild pointers in the heap's free-list walk), with or without a save. Not changed by core_preempt on, a barrier after file reads, DM_SPIN=0, DM_AUDIO=0 or DM_VK_WORKER=0; the whole process on one CPU with taskset made it worse (6 of 12), so it is the interleaving, not parallelism. core_preempt lock (profile) / DM_CORE_LOCK (switch): a guest thread whose affinity is one core holds that core's lock, a first-come ticket lock, while it runs guest code, and gives it up at each SVC and native HLE wait. A waiter of higher priority preempts the holder in guest code (SIGURG; in host code it is not stopped and the waiter signals again). Threads that may run on several cores, and host-owned guest threads, run free. It applies for the first DM_CORE_LOCK_SECS seconds (default 20; 0 = for good): held for good it cost Xenoblade 2-3 hitches of 70-100 ms in five minutes of play (a thread running 100 ms in guest code while the main thread waited for core 0). DM_CORE_SLICE_US adds a time slice for waiters of equal priority (default off; 4000 gave more hitches, not fewer). 0 of 60 boots crashed with it, on an AYN Thor (Snapdragon 8 Gen 2).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A new profile value
core_preempt lock(switchDM_CORE_LOCK): the guest threads of one core take turns, as on Horizon.DM_CORE_LOCK_SECSseconds (default 20; 0 = for good).DM_CORE_SLICE_USadds a time slice for waiters of equal priority (default off).Games without
core_preempt lockare unchanged:onandoffbehave exactly as before.Why
Xenoblade Chronicles: Definitive Edition corrupts its heap at boot when two threads of core 0 run at the same moment. About one boot in four crashed 1–4 s into
nnMainat changing sites:memsetof a size read from a resource block's footer;This happened with or without a save. None of these changed it:
core_preempt on;DM_SPIN=0,DM_AUDIO=0orDM_VK_WORKER=0.Running the whole process on one CPU with
tasksetmade it worse (6 of 12). So the cause is threads of one core interleaving at arbitrary points, not running in parallel.Held for the whole game, the lock cost 2–3 hitches of 70–100 ms in five minutes of play: one thread ran 100 ms in guest code while the main thread waited for core 0. The race is at boot, hence the 20 s window.
Tested
AYN Thor (Snapdragon 8 Gen 2), XCDE 1.1.2:
The native build passes on this branch.