Skip to content

Commit c311546

Browse files
committed
Move TopologyEntry into its own header file
It is needed in the kernel and this consolidates versions of the structure. This change also wraps types in types.h that cannot be used in the kernel in an #ifdef that removes them from compilation during the kext build.
1 parent 9759843 commit c311546

File tree

9 files changed

+77
-57
lines changed

9 files changed

+77
-57
lines changed

src/MacMSRDriver/MSRAccessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ MSRAccessor::MSRAccessor()
1818

1919
int32_t MSRAccessor::buildTopology(uint32_t num_cores, void* pTopos)
2020
{
21-
size_t topology_struct_size = sizeof(topologyEntry)*num_cores;
21+
size_t topology_struct_size = sizeof(TopologyEntry)*num_cores;
2222

2323
kern_return_t ret = IOConnectCallStructMethod(connect, kBuildTopology,
2424
NULL, 0,

src/MacMSRDriver/PcmMsr/PcmMsr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void cpuWriteMSR(void* pIDatas){
5757
}
5858

5959
void cpuGetTopoData(void* pTopos){
60-
topologyEntry* entries = (topologyEntry*)pTopos;
60+
TopologyEntry* entries = (TopologyEntry*)pTopos;
6161
int cpu = cpu_number();
6262
int info[4];
6363
entries[cpu].os_id = cpu;
@@ -166,18 +166,18 @@ IOReturn PcmMsrDriverClassName::writeMSR(pcm_msr_data_t* idata){
166166
return ret;
167167
}
168168

169-
IOReturn PcmMsrDriverClassName::buildTopology(topologyEntry* odata, uint32_t input_num_cores)
169+
IOReturn PcmMsrDriverClassName::buildTopology(TopologyEntry* odata, uint32_t input_num_cores)
170170
{
171171
size_t topologyBufferSize;
172172

173173
// 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))
174+
if (os_mul_overflow(sizeof(TopologyEntry), (size_t) num_cores, &topologyBufferSize))
175175
{
176176
return kIOReturnBadArgument;
177177
}
178178

179-
topologyEntry *topologies =
180-
(topologyEntry *)IOMallocAligned(topologyBufferSize, 32);
179+
TopologyEntry *topologies =
180+
(TopologyEntry *)IOMallocAligned(topologyBufferSize, 32);
181181

182182
if (topologies == nullptr)
183183
{

src/MacMSRDriver/PcmMsr/PcmMsr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class PcmMsrDriverClassName : public IOService
1414

1515
virtual IOReturn writeMSR(pcm_msr_data_t* data);
1616
virtual IOReturn readMSR(pcm_msr_data_t* idata,pcm_msr_data_t* odata);
17-
virtual IOReturn buildTopology(topologyEntry* odata, uint32_t input_num_cores);
17+
virtual IOReturn buildTopology(TopologyEntry* odata, uint32_t input_num_cores);
1818
virtual bool init(OSDictionary *dict) override;
1919
virtual void free(void) override;
2020
virtual bool handleOpen(IOService* forClient, IOOptionBits opts, void* args) override;

src/MacMSRDriver/PcmMsr/PcmMsrClient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ IOReturn PcmMsrClientClassName::writeMSR(pcm_msr_data_t* data)
154154
}
155155

156156
IOReturn PcmMsrClientClassName::sBuildTopology(PcmMsrClientClassName* target, void* reference, IOExternalMethodArguments* args){
157-
return target -> buildTopology((topologyEntry*)args->structureOutput, args->structureOutputSize);
157+
return target -> buildTopology((TopologyEntry*)args->structureOutput, args->structureOutputSize);
158158
}
159159

160-
IOReturn PcmMsrClientClassName::buildTopology(topologyEntry* data, size_t output_size)
160+
IOReturn PcmMsrClientClassName::buildTopology(TopologyEntry* data, size_t output_size)
161161
{
162-
uint32_t num_cores = (uint32_t) (output_size / sizeof(topologyEntry) );
162+
uint32_t num_cores = (uint32_t) (output_size / sizeof(TopologyEntry) );
163163
IOReturn result = checkActiveAndOpened (__FUNCTION__);
164164

165165
if (result == kIOReturnSuccess)

src/MacMSRDriver/PcmMsr/PcmMsrClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class PcmMsrClientClassName : public IOUserClient
4444
virtual IOReturn writeMSR(pcm_msr_data_t* data);
4545

4646
static IOReturn sBuildTopology(PcmMsrClientClassName* target, void* reference, IOExternalMethodArguments* args);
47-
virtual IOReturn buildTopology(topologyEntry* data, size_t output_size);
47+
virtual IOReturn buildTopology(TopologyEntry* data, size_t output_size);
4848

4949
static IOReturn sGetNumInstances(PcmMsrClientClassName* target, void* reference, IOExternalMethodArguments* args);
5050
virtual IOReturn getNumInstances(uint32_t* num_insts);

src/MacMSRDriver/PcmMsr/UserKernelShared.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2012, Intel Corporation
33
// written by Austen Ott
4-
//
4+
//
55
#define PcmMsrDriverClassName com_intel_driver_PcmMsr
66
#define kPcmMsrDriverClassName "com_intel_driver_PcmMsr"
7+
78
#ifndef USER_KERNEL_SHARED
89
#define USER_KERNEL_SHARED
10+
11+
#define PCM_API
12+
913
#include <stdint.h>
14+
#include "../../topologyentry.h"
15+
16+
using namespace pcm;
17+
1018
typedef struct {
1119
uint64_t value;
1220
uint32_t cpu_num;
@@ -20,19 +28,6 @@ typedef struct {
2028
char padding[115];
2129
} k_pcm_msr_data_t;
2230

23-
// The topologyEntry struct that is used by PCM
24-
typedef struct
25-
{
26-
int32_t os_id;
27-
int32_t thread_id;
28-
int32_t core_id;
29-
int32_t tile_id;
30-
int32_t socket;
31-
int32_t native_cpu_model;
32-
int32_t core_type; // This is an enum in the userland structure.
33-
int32_t padding;
34-
} topologyEntry;
35-
3631
enum {
3732
kOpenDriver,
3833
kCloseDriver,

src/cpucounters.h

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#undef PCM_UNCORE_PMON_BOX_CHECK_STATUS // debug only
2424

2525
#include "types.h"
26+
#include "topologyentry.h"
2627
#include "msr.h"
2728
#include "pci.h"
2829
#include "bw.h"
@@ -86,38 +87,6 @@ class SystemRoot;
8687
A set of performance monitoring routines for recent Intel CPUs
8788
*/
8889

89-
struct PCM_API TopologyEntry // describes a core
90-
{
91-
int32 os_id;
92-
int32 thread_id;
93-
int32 core_id;
94-
int32 tile_id; // tile is a constalation of 1 or more cores sharing salem L2 cache. Unique for entire system
95-
int32 socket;
96-
int32 native_cpu_model = -1;
97-
enum CoreType
98-
{
99-
Atom = 0x20,
100-
Core = 0x40,
101-
Invalid = -1
102-
};
103-
CoreType core_type = Invalid;
104-
105-
TopologyEntry() : os_id(-1), thread_id (-1), core_id(-1), tile_id(-1), socket(-1) { }
106-
const char* getCoreTypeStr()
107-
{
108-
switch (core_type)
109-
{
110-
case Atom:
111-
return "Atom";
112-
case Core:
113-
return "Core";
114-
case Invalid:
115-
return "invalid";
116-
}
117-
return "unknown";
118-
}
119-
};
120-
12190
class HWRegister
12291
{
12392
public:

src/topologyentry.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2022-, Intel Corporation
3+
4+
#pragma once
5+
6+
#include "types.h"
7+
8+
namespace pcm
9+
{
10+
11+
struct PCM_API TopologyEntry // describes a core
12+
{
13+
int32 os_id;
14+
int32 thread_id;
15+
int32 core_id;
16+
int32 tile_id; // tile is a constalation of 1 or more cores sharing salem L2 cache. Unique for entire system
17+
int32 socket;
18+
int32 native_cpu_model = -1;
19+
enum CoreType
20+
{
21+
Atom = 0x20,
22+
Core = 0x40,
23+
Invalid = -1
24+
};
25+
CoreType core_type = Invalid;
26+
27+
TopologyEntry() : os_id(-1), thread_id (-1), core_id(-1), tile_id(-1), socket(-1) { }
28+
const char* getCoreTypeStr()
29+
{
30+
switch (core_type)
31+
{
32+
case Atom:
33+
return "Atom";
34+
case Core:
35+
return "Core";
36+
case Invalid:
37+
return "invalid";
38+
}
39+
return "unknown";
40+
}
41+
};
42+
43+
}
44+

src/types.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#undef PCM_DEBUG
1515

16+
#ifndef KERNEL
17+
1618
#include <iostream>
1719
#include <istream>
1820
#include <sstream>
@@ -23,6 +25,8 @@
2325
#include <windows.h>
2426
#endif
2527

28+
#endif // #ifndef KERNEL
29+
2630
namespace pcm {
2731

2832
typedef unsigned long long uint64;
@@ -383,6 +387,8 @@ struct FixedEventControlRegister
383387
FixedEventControlRegister() : value(0) {}
384388
};
385389

390+
#ifndef KERNEL
391+
386392
inline std::ostream & operator << (std::ostream & o, const FixedEventControlRegister & reg)
387393
{
388394
o << "os0\t\t" << reg.fields.os0 << "\n";
@@ -404,6 +410,8 @@ inline std::ostream & operator << (std::ostream & o, const FixedEventControlRegi
404410
return o;
405411
}
406412

413+
#endif // #ifndef KERNEL
414+
407415
// UNCORE COUNTER CONTROL
408416

409417
/* \brief Uncore Event Select Register Register format
@@ -1256,6 +1264,8 @@ union cvt_ds
12561264
} ui32;
12571265
};
12581266

1267+
#ifndef KERNEL
1268+
12591269
struct MCFGRecord
12601270
{
12611271
unsigned long long baseAddress;
@@ -1298,6 +1308,8 @@ struct MCFGHeader
12981308
}
12991309
};
13001310

1311+
#endif // #ifndef KERNEL
1312+
13011313
} // namespace pcm
13021314

13031315
#endif

0 commit comments

Comments
 (0)