mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 13:39:58 -04:00
Give a thread on a folded virtual core the number of its own core, so that fewer than six cores no longer crash the game.
With fewer than six virtual cores a thread pinned to a core at or above the count runs on core (c mod count), and GetCurrentProcessorNumber told it that virtual core's number. The game keys per-core data by the number without locks, so with four cores a thread pinned to core 5 used core 1's data in turn with core 1's own threads, and the game died within seconds of the first frame in play. The Steam Deck profile sets four cores, so this was every start under that profile (issue #445). The call now answers with one of the thread's own cores that fold onto the virtual core it holds, its ideal core first; with all six cores the answer is as before. The kernel probe gets a test with two threads pinned to each of the six cores: with 6, 4, 3 and 1 virtual cores no thread sees another core's number and no two see the same at once. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -364,7 +364,7 @@ void kern_free_cores_note(void) {
|
||||
|
||||
// NX2NAVI_CORES = 1..NCORE: how many virtual cores run threads (default all NCORE). A core at or above the count is
|
||||
// folded onto core (c mod count): a thread pinned to core 5 with NX2NAVI_CORES=3 runs on core 2, one thread per core
|
||||
// at a time as always (diagnosis of races that more parallel cores expose).
|
||||
// at a time as always (diagnosis of races that more parallel cores expose; the Steam Deck profile's four).
|
||||
static int core_allowed(const RtThread *t, int c) {
|
||||
if (c >= g_active_cores) return 0;
|
||||
for (int j = c; j < NCORE; j += g_active_cores)
|
||||
@@ -372,6 +372,21 @@ static int core_allowed(const RtThread *t, int c) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The core number a thread sees (GetCurrentProcessorNumber) while it holds virtual core c. With all NCORE cores that
|
||||
// is c. With fewer it is one of the thread's own cores that fold onto c, its ideal core first: the game keys per-core
|
||||
// data by this number without locks, so a thread pinned to core 5 must go on using core 5's data when it takes
|
||||
// turns with core 1's threads on one virtual core. Seeing 1 there, it used core 1's data in turn with core 1's own
|
||||
// threads, and the game died in its draw set-up within seconds of the first frame in play (issue #445; with
|
||||
// NX2NAVI_CORES=4 on any machine). No two threads that run guest code see the same number: they hold different
|
||||
// virtual cores, and the numbers that fold onto different virtual cores differ.
|
||||
static int core_seen(const RtThread *t, int c) {
|
||||
if (g_active_cores >= NCORE) return c;
|
||||
if (t->core >= 0 && t->core < NCORE && t->core % g_active_cores == c && ((t->mask >> t->core) & 1)) return t->core;
|
||||
for (int j = c; j < NCORE; j += g_active_cores)
|
||||
if ((t->mask >> j) & 1) return j;
|
||||
return c;
|
||||
}
|
||||
|
||||
// ---- asynchronous preemption (NX2NAVI_ASYNC_PREEMPT, on unless 0)
|
||||
// Contains code Copyright (c) 2026 MacNativeGames contributors (MIT; see THIRD_PARTY_NOTICES.md).
|
||||
// Horizon gives a core to a strictly better thread the moment that thread is ready.
|
||||
@@ -1707,9 +1722,9 @@ static int kern_svc_inner(Cpu *c, uint32_t imm) {
|
||||
unlock();
|
||||
return 1;
|
||||
}
|
||||
case 0x10: { // GetCurrentProcessorNumber: the virtual core held
|
||||
case 0x10: { // GetCurrentProcessorNumber: the core seen on the virtual core held (core_seen)
|
||||
RtThread *t = cur(imm);
|
||||
x[0] = (uint64_t)(uint32_t)(t->cur_core >= 0 ? t->cur_core : t->core);
|
||||
x[0] = (uint64_t)(uint32_t)(t->cur_core >= 0 ? core_seen(t, t->cur_core) : t->core);
|
||||
return 1;
|
||||
}
|
||||
case 0x36: { // SynchronizePreemptionState: the SDK's spin locks call it after clearing TLR+0x100 (disable_count)
|
||||
|
||||
Reference in New Issue
Block a user