Allow JIT and CPU thread to work together#1806
Merged
Conversation
The code already supports JIT + CPU thread via cpu_thread_run_jit() which runs JIT compiled code on a separate thread while run_cpu_thread() manages cycle timing on the main thread. The JIT helper functions (do_nothing, exec_nostats, execute_normal) already skip do_cycles() when cpu_thread is enabled, and do_specialties_thread() handles SPCFLAG_END_COMPILE. Remove the artificial restrictions that prevented enabling both: - amiberry.cpp: Remove target_fixup_options() force-disable of cpu_thread when cachesize > 0 - cpu.cpp: Allow JIT checkbox when cpu_thread is enabled - cpu.cpp: Allow cpu_thread checkbox when JIT cache is enabled https://claude.ai/code/session_01V9mxWsSPRWrdiYzAfEuCng
…ocol The cross-thread indirect memory access path was using semaphores (cpu_out_sema/cpu_in_sema) for every IO request, which added significant kernel overhead per custom register/CIA access. With JIT enabled, the CPU thread runs much faster and hits these IO paths more frequently, making the synchronization cost the primary bottleneck. Changes: - Replace semaphore-based signaling with pure atomic spin-wait protocol on the hot path. The cpu_thread_indirect_mode atomic variable is now the sole synchronization mechanism for IO requests. - Extract service_cpu_indirect_request() helper that the main thread calls to poll and complete one pending request. - Main thread now checks for IO requests EVERY cycle inside the cycle loop (not just at the top of the outer loop), reducing worst-case latency from 128-256 CCKs to 1 CCK. - Flush register batch on main thread at every IO service point. - Service IO requests during frame limiter sleep instead of sleeping through them. - Add SPCFLAG_MODE_CHANGE escape from spin-wait to prevent deadlock during shutdown. Semaphores are retained only for rare operations (CPU reset, CPU stop wakeup, shutdown drain). https://claude.ai/code/session_01V9mxWsSPRWrdiYzAfEuCng
The lockless spin optimization calls cpu_thread_flush_register_batch() from run_cpu_thread(), which requires the declaration from cpu_thread.h. https://claude.ai/code/session_01V9mxWsSPRWrdiYzAfEuCng
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.
The code already supports JIT + CPU thread via cpu_thread_run_jit() which
runs JIT compiled code on a separate thread while run_cpu_thread() manages
cycle timing on the main thread. The JIT helper functions (do_nothing,
exec_nostats, execute_normal) already skip do_cycles() when cpu_thread is
enabled, and do_specialties_thread() handles SPCFLAG_END_COMPILE.
Remove the artificial restrictions that prevented enabling both:
when cachesize > 0
https://claude.ai/code/session_01V9mxWsSPRWrdiYzAfEuCng