From eae579be0d8980b48c43856711cbb11e56011b6f Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Mon, 5 Sep 2022 11:31:45 +0100 Subject: [PATCH] Delay producing a warning until a lock is actually used --- .../main/java/net/openhft/affinity/AffinityLock.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java index fc2eae07c..67642daf5 100644 --- a/affinity/src/main/java/net/openhft/affinity/AffinityLock.java +++ b/affinity/src/main/java/net/openhft/affinity/AffinityLock.java @@ -121,7 +121,6 @@ private static BitSet getReservedAffinity0() { reserverable.set(1, PROCESSORS, true); reserverable.andNot(BASE_AFFINITY); if (reserverable.isEmpty() && PROCESSORS > 1) { - LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1)); // make all but first CPUs available reserverable.set(1, PROCESSORS); return reserverable; @@ -149,6 +148,14 @@ public static AffinityLock acquireLock() { return acquireLock(true); } + static class Warnings { + static void warmNoReservedCPUs() { + if (RESERVED_AFFINITY.isEmpty() && PROCESSORS > 1) { + LoggerFactory.getLogger(AffinityLock.class).info("No isolated CPUs found, so assuming CPUs 1 to {} available.", (PROCESSORS - 1)); + } + } + } + /** * Assign any free core to this thread.

In reality, only one cpu is assigned, the rest of * the threads for that core are reservable so they are not used. @@ -294,6 +301,7 @@ public static AffinityLock acquireCore(boolean bind) { } private static AffinityLock acquireLock(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { + Warnings.warmNoReservedCPUs(); return LOCK_INVENTORY.acquireLock(bind, cpuId, strategies); } @@ -310,6 +318,7 @@ private static AffinityLock tryAcquireLock(boolean bind, int cpuId) { } private static AffinityLock acquireCore(boolean bind, int cpuId, @NotNull AffinityStrategy... strategies) { + Warnings.warmNoReservedCPUs(); return LOCK_INVENTORY.acquireCore(bind, cpuId, strategies); }