AffinityLock.acquireCore should lock/unlock all cpus ie 2 when hypert… #180
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.
This change makes
AffinityLock.acquireCore()
correctly reserve all logicalCPUs that share the same physical core (e.g. both SMT / Hyper-Threads).
It touches the lock inventory, PID-file handling and CPU-layout APIs, plus adds
new verification tests.
✨ Behavioural changes
AffinityLock.acquireCore()
now locks both hyper-threads on the target core, preventing other threads or JVMs from binding to the sibling logical CPU.cpuId2
to track the paired logical CPU.• Hex mask parsing uses
Long.parseUnsignedLong
(fixes > 64-bit masks).•
acquireLock(int)
returns noLock (not exception) when CPU id is out-of-range.•
acquireLock(int[])
silently skips invalid ids with a log warning.int pair(int cpuId)
returns the hyper-thread twin (0 if not HT). Implemented inVanillaCpuLayout
; stubbed inNoCpuLayout
.LockChecker
&FileLockBasedLockChecker
upgraded soobtainLock()
can atomically grab two lock files (cpu
,cpuId2
). PID logging & replace logic updated accordingly.cpuId
and itspair()
. Whole-core acquisition path passes both ids toLockCheck
.🛠️ API surface changes
CpuLayout
– +pair(int cpuId)
LockChecker.obtainLock(int cpu1, int cpu2, String meta)
– supersedes old 2-arg variant (now removed).Internal interfaces only – no public-API break for typical callers.
🧪 Tests
VanillaCpuLayoutPairTest
pair()
mapping on sample i7 & i3 cpuinfo.AffinityLockTest
acquireCore()
reserves all logical CPUs of a core and updates existing expectations to dual-id locks.FileLockLockCheckTest
,LockCheckTest
updateCpu
/replacePid
signatures.Total diff +170 / -47 (mostly tests & lock-plumbing).
✅ Compatibility & Migration
LockChecker.obtainLock()
directly must adopt thenew 3-arg form (very rare outside this repo).