Skip to content

Commit b363f43

Browse files
committed
macOS: buildTopology in kernel now fills output buffer directly
Previously, buildTopology would allocate a buffer, fill it, and copy it to the output buffer. The buffer passed from userland is of the same type that the kernel needs, and it is easier to fill it directly. Also added comment clarifying need to keep types in user/kernel land in sync.
1 parent d7dd17b commit b363f43

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

src/MacMSRDriver/PcmMsr/PcmMsr.cpp

+3-23
Original file line numberDiff line numberDiff line change
@@ -168,32 +168,12 @@ IOReturn PcmMsrDriverClassName::writeMSR(pcm_msr_data_t* idata){
168168

169169
IOReturn PcmMsrDriverClassName::buildTopology(topologyEntry* odata, uint32_t input_num_cores)
170170
{
171-
size_t topologyBufferSize;
172-
173-
// TODO figure out when input_num_cores is used rather than num_cores
174-
if (os_mul_overflow(sizeof(topologyEntry), (size_t) num_cores, &topologyBufferSize))
175-
{
176-
return kIOReturnBadArgument;
177-
}
178-
179-
topologyEntry *topologies =
180-
(topologyEntry *)IOMallocAligned(topologyBufferSize, 32);
181-
182-
if (topologies == nullptr)
183-
{
184-
return kIOReturnNoMemory;
171+
if (odata == nullptr) {
172+
return kIOReturnBadArgument;
185173
}
186174

187-
mp_rendezvous_no_intrs(cpuGetTopoData, (void*)topologies);
188-
189-
for(uint32_t i = 0; i < num_cores && i < input_num_cores; i++)
190-
{
191-
odata[i].core_id = topologies[i].core_id;
192-
odata[i].os_id = topologies[i].os_id;
193-
odata[i].socket = topologies[i].socket;
194-
}
175+
mp_rendezvous_no_intrs(cpuGetTopoData, (void*)odata);
195176

196-
IOFreeAligned(topologies, topologyBufferSize);
197177
return kIOReturnSuccess;
198178
}
199179

src/MacMSRDriver/PcmMsr/UserKernelShared.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ typedef struct {
2020
char padding[115];
2121
} k_pcm_msr_data_t;
2222

23-
// The topologyEntry struct that is used by PCM
23+
// The topologyEntry struct that is used by PCM in the kernel. It
24+
// needs to be kept in sync with the one in cpucounters.h (at least,
25+
// the first 3 fields). Ideally we would just include that, but
26+
// cpucounters.h has dependencies on the platform SDK and cannot be
27+
// compiled in the kernel on macOS today.
2428
typedef struct
2529
{
2630
int32_t os_id;
@@ -30,7 +34,6 @@ typedef struct
3034
int32_t socket;
3135
int32_t native_cpu_model;
3236
int32_t core_type; // This is an enum in the userland structure.
33-
int32_t padding;
3437
} topologyEntry;
3538

3639
enum {

0 commit comments

Comments
 (0)