Skip to content

Commit 21fb054

Browse files
committed
adjust the check and fix OSX code
l3CacheMaskShift < 0 is never true Change-Id: I4c3b30912a4c9896dad7e0f164c731037d4b5337
1 parent 44dee11 commit 21fb054

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/MacMSRDriver/PcmMsr/PcmMsr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ void cpuGetTopoData(void* pTopos){
6464
uint32 smtMaskWidth = 0;
6565
uint32 coreMaskWidth = 0;
6666
uint32 l2CacheMaskShift = 0;
67-
initCoreMasks(smtMaskWidth, coreMaskWidth, l2CacheMaskShift);
67+
uint32 l3CacheMaskShift = 0;
68+
initCoreMasks(smtMaskWidth, coreMaskWidth, l2CacheMaskShift, l3CacheMaskShift);
6869
PCM_CPUID_INFO cpuid_args;
6970
pcm_cpuid(0xb, 0x0, cpuid_args);
70-
fillEntry(entry, smtMaskWidth, coreMaskWidth, l2CacheMaskShift, cpuid_args.array[3]);
71+
const auto apic_id = cpuid_args.array[3];
72+
fillEntry(entry, smtMaskWidth, coreMaskWidth, l2CacheMaskShift, apic_id);
73+
entry.l3_cache_id = extract_bits_32(apic_id, l3CacheMaskShift, 31);
7174
}
7275

7376
OSDefineMetaClassAndStructors(com_intel_driver_PcmMsr, IOService)

src/cpucounters.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,15 +1217,6 @@ bool PCM::discoverSystemTopology()
12171217
{
12181218
fillEntry(entry, smtMaskWidth, coreMaskWidth, l2CacheMaskShift, getAPICID(0xb));
12191219
}
1220-
// Validate l3CacheMaskShift and ensure the bit range is correct
1221-
if (l3CacheMaskShift < 0 || l3CacheMaskShift > 31)
1222-
{
1223-
throw std::runtime_error("Invalid l3CacheMaskShift: must be between 0 and 31");
1224-
}
1225-
if (l3CacheMaskShift > 31)
1226-
{
1227-
throw std::runtime_error("Invalid bit range for L3 cache ID extraction");
1228-
}
12291220
entry.l3_cache_id = extract_bits_32(getAPICID(0xb), l3CacheMaskShift, 31);
12301221
};
12311222
#endif

src/topologyentry.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ inline bool initCoreMasks(uint32 & smtMaskWidth, uint32 & coreMaskWidth, uint32
183183
l3CacheMaskShift++;
184184
}
185185
DBG(1, "Number of threads sharing L3 cache = " , threadsSharingL3, " [the most significant bit = " , l3CacheMaskShift , "]");
186+
// Validate l3CacheMaskShift and ensure the bit range is correct
187+
if (l3CacheMaskShift > 31)
188+
{
189+
throw std::runtime_error("Invalid bit range for L3 cache ID extraction");
190+
}
186191

187192
uint32 it = 0;
188193

0 commit comments

Comments
 (0)