Skip to content

Commit d0e8e15

Browse files
committed
resolve compile errors on OSX
1 parent c8d6cd5 commit d0e8e15

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

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/topologyentry.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#pragma once
55

66
#include "types.h"
7+
#ifndef USER_KERNEL_SHARED
78
#include "debug.h"
9+
#endif
810

911
namespace pcm
1012
{
@@ -166,7 +168,10 @@ inline bool initCoreMasks(uint32 & smtMaskWidth, uint32 & coreMaskWidth, uint32
166168
{
167169
l2CacheMaskShift++;
168170
}
171+
172+
#ifndef USER_KERNEL_SHARED
169173
DBG(1, "Number of threads sharing L2 cache = " , threadsSharingL2, " [the most significant bit = " , l2CacheMaskShift , "]");
174+
#endif
170175

171176
uint32 threadsSharingL3 = 0;
172177
uint32 l3CacheMaskWidth = 0;
@@ -178,8 +183,24 @@ inline bool initCoreMasks(uint32 & smtMaskWidth, uint32 & coreMaskWidth, uint32
178183
{
179184
l3CacheMaskShift++;
180185
}
186+
187+
#ifndef USER_KERNEL_SHARED
181188
DBG(1, "Number of threads sharing L3 cache = " , threadsSharingL3, " [the most significant bit = " , l3CacheMaskShift , "]");
189+
#endif
190+
191+
(void) threadsSharingL2; // to suppress warnings on MacOS (unused vars)
192+
(void) threadsSharingL3; // to suppress warnings on MacOS (unused vars)
193+
194+
// Validate l3CacheMaskShift and ensure the bit range is correct
195+
if (l3CacheMaskShift > 31)
196+
{
197+
#ifndef USER_KERNEL_SHARED
198+
DBG(0, "Invalid bit range for L3 cache ID extraction = ", l3CacheMaskShift);
199+
#endif
200+
return false;
201+
}
182202

203+
#ifndef USER_KERNEL_SHARED
183204
uint32 it = 0;
184205

185206
for (int i = 0; i < 100; ++i)
@@ -212,6 +233,7 @@ inline bool initCoreMasks(uint32 & smtMaskWidth, uint32 & coreMaskWidth, uint32
212233
" shift = " , CacheMaskShift);
213234
++it;
214235
}
236+
#endif
215237
}
216238
return true;
217239
}

src/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <istream>
2020
#include <sstream>
2121
#include <iomanip>
22+
#include <stdexcept>
23+
#include <string>
2224
#include <string.h>
2325
#include <assert.h>
2426
#include <limits>

0 commit comments

Comments
 (0)