From e160c21c6bd0acece57ecef460ea94902fc109c6 Mon Sep 17 00:00:00 2001 From: Neal Sidhwaney Date: Fri, 16 Sep 2022 16:16:04 -0700 Subject: [PATCH 1/3] Changes to DriverInterface --- src/MacMSRDriver/DriverInterface.c | 47 ++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/MacMSRDriver/DriverInterface.c b/src/MacMSRDriver/DriverInterface.c index eefd5568..8a180704 100644 --- a/src/MacMSRDriver/DriverInterface.c +++ b/src/MacMSRDriver/DriverInterface.c @@ -32,33 +32,56 @@ kern_return_t getTopologyInfo(io_connect_t connect, topologyEntry* data, size_t* kern_return_t getNumClients(io_connect_t connect, uint32_t* num_insts) { - kern_return_t kernResult; - size_t num_outputs = 1; + kern_return_t kernResult; + uint32_t output_count = 1; uint64_t knum_insts; - kernResult = IOConnectCallStructMethod(connect, kGetNumInstances, NULL, 0, &knum_insts, &num_outputs); - *num_insts = (uint32_t)knum_insts; + kernResult = IOConnectCallScalarMethod(connect, + kGetNumInstances, + NULL, 0, + &knum_insts, &output_count); + + if (kernResult == kIOReturnSuccess) + { + *num_insts = (uint32_t) knum_insts; + } + return kernResult; } kern_return_t incrementNumClients(io_connect_t connect, uint32_t* num_insts) { - kern_return_t kernResult; - size_t num_outputs = 1; + kern_return_t kernResult; + uint32_t output_count = 1; uint64_t knum_insts; - kernResult = IOConnectCallStructMethod(connect, kIncrementNumInstances, NULL, 0, &knum_insts, &num_outputs); - *num_insts = (uint32_t)knum_insts; + kernResult = IOConnectCallScalarMethod(connect, + kIncrementNumInstances, + NULL, 0, + &knum_insts, &output_count); + + if (kernResult == kIOReturnSuccess) + { + *num_insts = (uint32_t) knum_insts; + } + return kernResult; } kern_return_t decrementNumClients(io_connect_t connect, uint32_t* num_insts) { - kern_return_t kernResult; - size_t num_outputs = 1; + kern_return_t kernResult; + uint32_t output_count = 1; uint64_t knum_insts; - kernResult = IOConnectCallStructMethod(connect, kDecrementNumInstances, NULL, 0, &knum_insts, &num_outputs); - *num_insts = (uint32_t)knum_insts; + kernResult = IOConnectCallScalarMethod(connect, kDecrementNumInstances, + NULL, 0, + &knum_insts, &output_count); + + if (kernResult == kIOReturnSuccess) + { + *num_insts = (uint32_t) knum_insts; + } + return kernResult; } From 9759843920bde522c033af3501bc377d598fee09 Mon Sep 17 00:00:00 2001 From: Neal Sidhwaney Date: Sat, 17 Sep 2022 13:00:31 -0700 Subject: [PATCH 2/3] Move DriverInterface code into MSRAccessor --- src/MacMSRDriver/CMakeLists.txt | 2 +- src/MacMSRDriver/DriverInterface.c | 87 ---------------- src/MacMSRDriver/DriverInterface.h | 18 ---- src/MacMSRDriver/MSRAccessor.cpp | 156 ++++++++++++++++++++--------- src/MacMSRDriver/MSRAccessor.h | 8 +- 5 files changed, 115 insertions(+), 156 deletions(-) delete mode 100644 src/MacMSRDriver/DriverInterface.c delete mode 100644 src/MacMSRDriver/DriverInterface.h diff --git a/src/MacMSRDriver/CMakeLists.txt b/src/MacMSRDriver/CMakeLists.txt index 8f6b5cd3..4c045b4d 100644 --- a/src/MacMSRDriver/CMakeLists.txt +++ b/src/MacMSRDriver/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "-Wall") set(CMAKE_CXX_FLAGS_RELEASE "-O3") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") -file(GLOB LIB_FILES DriverInterface.c PCIDriverInterface.cpp MSRAccessor.cpp) +file(GLOB LIB_FILES PCIDriverInterface.cpp MSRAccessor.cpp) find_library(IOKIT_LIBRARY IOKit) add_library(PcmMsr SHARED ${LIB_FILES}) diff --git a/src/MacMSRDriver/DriverInterface.c b/src/MacMSRDriver/DriverInterface.c deleted file mode 100644 index 8a180704..00000000 --- a/src/MacMSRDriver/DriverInterface.c +++ /dev/null @@ -1,87 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright (c) 2012, Intel Corporation -// written by Austen Ott -// - -#include "DriverInterface.h" - -kern_return_t openMSRClient(io_connect_t connect) -{ - return IOConnectCallScalarMethod(connect, kOpenDriver, NULL, 0, NULL, NULL); -} - -kern_return_t closeMSRClient(io_connect_t connect) -{ - return IOConnectCallScalarMethod(connect, kCloseDriver, NULL, 0, NULL, NULL); -} - -kern_return_t readMSR(io_connect_t connect, pcm_msr_data_t* idata, size_t* idata_size,pcm_msr_data_t* odata, size_t* odata_size) -{ - return IOConnectCallStructMethod(connect, kReadMSR, idata, *idata_size, odata, odata_size); -} - -kern_return_t writeMSR(io_connect_t connect, pcm_msr_data_t* data, size_t* idata_size) -{ - return IOConnectCallStructMethod(connect, kWriteMSR, (void*)data, *idata_size, NULL, NULL); -} - -kern_return_t getTopologyInfo(io_connect_t connect, topologyEntry* data, size_t* data_size) -{ - return IOConnectCallStructMethod(connect, kBuildTopology, NULL, 0, data, data_size); -} - -kern_return_t getNumClients(io_connect_t connect, uint32_t* num_insts) -{ - kern_return_t kernResult; - uint32_t output_count = 1; - uint64_t knum_insts; - - kernResult = IOConnectCallScalarMethod(connect, - kGetNumInstances, - NULL, 0, - &knum_insts, &output_count); - - if (kernResult == kIOReturnSuccess) - { - *num_insts = (uint32_t) knum_insts; - } - - return kernResult; -} - -kern_return_t incrementNumClients(io_connect_t connect, uint32_t* num_insts) -{ - kern_return_t kernResult; - uint32_t output_count = 1; - uint64_t knum_insts; - - kernResult = IOConnectCallScalarMethod(connect, - kIncrementNumInstances, - NULL, 0, - &knum_insts, &output_count); - - if (kernResult == kIOReturnSuccess) - { - *num_insts = (uint32_t) knum_insts; - } - - return kernResult; -} - -kern_return_t decrementNumClients(io_connect_t connect, uint32_t* num_insts) -{ - kern_return_t kernResult; - uint32_t output_count = 1; - uint64_t knum_insts; - - kernResult = IOConnectCallScalarMethod(connect, kDecrementNumInstances, - NULL, 0, - &knum_insts, &output_count); - - if (kernResult == kIOReturnSuccess) - { - *num_insts = (uint32_t) knum_insts; - } - - return kernResult; -} diff --git a/src/MacMSRDriver/DriverInterface.h b/src/MacMSRDriver/DriverInterface.h deleted file mode 100644 index 28d06985..00000000 --- a/src/MacMSRDriver/DriverInterface.h +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright (c) 2012, Intel Corporation -// written by Austen Ott -// -#include -#include -#include -#include -#include "PcmMsr/UserKernelShared.h" - -kern_return_t openMSRClient(io_connect_t connect); -kern_return_t closeMSRClient(io_connect_t connect); -kern_return_t readMSR(io_connect_t connect, pcm_msr_data_t* idata, size_t* idata_size, pcm_msr_data_t* odata, size_t* odata_size); -kern_return_t writeMSR(io_connect_t connect, pcm_msr_data_t* data, size_t* data_size); -kern_return_t getTopologyInfo(io_connect_t connect, topologyEntry* data, size_t* data_size); -kern_return_t getNumClients(io_connect_t connect, uint32_t* num_insts); -kern_return_t incrementNumClients(io_connect_t connect, uint32_t* num_insts); -kern_return_t decrementNumClients(io_connect_t connect, uint32_t* num_insts); \ No newline at end of file diff --git a/src/MacMSRDriver/MSRAccessor.cpp b/src/MacMSRDriver/MSRAccessor.cpp index f88a31b2..a4d26133 100644 --- a/src/MacMSRDriver/MSRAccessor.cpp +++ b/src/MacMSRDriver/MSRAccessor.cpp @@ -4,99 +4,163 @@ // #include "MSRAccessor.h" #include -MSRAccessor::MSRAccessor(){ +#include +#include + +using namespace std; + +MSRAccessor::MSRAccessor() +{ service = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching(kPcmMsrDriverClassName)); openConnection(); } -int32_t MSRAccessor::buildTopology(uint32_t num_cores ,void* pTopos){ - topologyEntry *entries = (topologyEntry*)pTopos; - size_t size = sizeof(topologyEntry)*num_cores; - kern_return_t ret = getTopologyInfo(connect, entries, &size); +int32_t MSRAccessor::buildTopology(uint32_t num_cores, void* pTopos) +{ + size_t topology_struct_size = sizeof(topologyEntry)*num_cores; + + kern_return_t ret = IOConnectCallStructMethod(connect, kBuildTopology, + NULL, 0, + pTopos, &topology_struct_size); return (ret == KERN_SUCCESS) ? 0 : -1; } -int32_t MSRAccessor::read(uint32_t core_num, uint64_t msr_num, uint64_t * value){ +int32_t MSRAccessor::read(uint32_t core_num, uint64_t msr_num, uint64_t * value) +{ pcm_msr_data_t idatas, odatas; - size_t size = sizeof(pcm_msr_data_t); + + size_t struct_size = sizeof(pcm_msr_data_t); idatas.msr_num = (uint32_t)msr_num; idatas.cpu_num = core_num; - kern_return_t ret = readMSR(connect, &idatas, &size, &odatas, &size); + + kern_return_t ret = IOConnectCallStructMethod(connect, kReadMSR, + &idatas, struct_size, + &odatas, &struct_size); + if(ret == KERN_SUCCESS) { *value = odatas.value; return sizeof(uint64_t); - } - else{ + } else { return -1; } } int32_t MSRAccessor::write(uint32_t core_num, uint64_t msr_num, uint64_t value){ pcm_msr_data_t idatas; - size_t size = sizeof(pcm_msr_data_t); + idatas.value = value; idatas.msr_num = (uint32_t)msr_num; idatas.cpu_num = core_num; - kern_return_t ret = writeMSR(connect, &idatas, &size); + + kern_return_t ret = IOConnectCallStructMethod(connect, kWriteMSR, + &idatas, sizeof(pcm_msr_data_t), + NULL, NULL); + if(ret == KERN_SUCCESS) { return sizeof(uint64_t); - } - else - { + } else { return -1; } } -uint32_t MSRAccessor::getNumInstances(){ - uint32_t num_instances; - getNumClients(connect, &num_instances); - return num_instances; +uint32_t MSRAccessor::getNumInstances() +{ + kern_return_t kernResult; + uint32_t output_count = 1; + uint64_t knum_insts = 0; + + kernResult = IOConnectCallScalarMethod(connect, + kGetNumInstances, + NULL, 0, + &knum_insts, &output_count); + + if (kernResult != KERN_SUCCESS) + { + cerr << "IOConnectCallScalarMethod returned 0x" << hex << setw(8) << kernResult << endl; + } + // TODO add error handling; also, number-of-instance related + // functions may go away as they do not appear to be used. + return knum_insts; } -uint32_t MSRAccessor::incrementNumInstances(){ - uint32_t num_instances; - incrementNumClients(connect, &num_instances); - return num_instances; +uint32_t MSRAccessor::incrementNumInstances() +{ + kern_return_t kernResult; + uint32_t output_count = 1; + uint64_t knum_insts = 0; + + kernResult = IOConnectCallScalarMethod(connect, + kIncrementNumInstances, + NULL, 0, + &knum_insts, &output_count); + + if (kernResult != KERN_SUCCESS) + { + cerr << "IOConnectCallScalarMethod returned 0x" << hex << setw(8) << kernResult << endl; + } + // TODO add error handling; also, these functions may go away as + // they do not appear to be used. + return knum_insts; } -uint32_t MSRAccessor::decrementNumInstances(){ - uint32_t num_instances; - decrementNumClients(connect, &num_instances); - return num_instances; +uint32_t MSRAccessor::decrementNumInstances() +{ + kern_return_t kernResult; + uint32_t output_count = 1; + uint64_t knum_insts = 0; + + kernResult = IOConnectCallScalarMethod(connect, kDecrementNumInstances, + NULL, 0, + &knum_insts, &output_count); + + if (kernResult != KERN_SUCCESS) + { + cerr << "IOConnectCallScalarMethod returned 0x" << hex << setw(8) << kernResult << endl; + } + // TODO add error handling; also, these functions may go away as + // they do not appear to be used. + return knum_insts; } -MSRAccessor::~MSRAccessor(){ +MSRAccessor::~MSRAccessor() +{ closeConnection(); } -kern_return_t MSRAccessor::openConnection(){ +kern_return_t MSRAccessor::openConnection() +{ kern_return_t kernResult = IOServiceOpen(service, mach_task_self(), 0, &connect); - - if (kernResult != KERN_SUCCESS) { - fprintf(stderr, "IOServiceOpen returned 0x%08x\n", kernResult); - } - else { - kernResult = openMSRClient(connect); - - if (kernResult != KERN_SUCCESS) { - fprintf(stderr, "openClient returned 0x%08x.\n\n", kernResult); + + if (kernResult != KERN_SUCCESS) + { + cerr << "IOServiceOpen returned 0x" << hex << setw(8) << kernResult << endl; + } else { + kernResult = IOConnectCallScalarMethod(connect, kOpenDriver, NULL, 0, NULL, NULL); + + if (kernResult != KERN_SUCCESS) + { + cerr << "kOpenDriver returned 0x" << hex << setw(8) << kernResult << endl; } } - + return kernResult; } -void MSRAccessor::closeConnection(){ - kern_return_t kernResult = closeMSRClient(connect); - if (kernResult != KERN_SUCCESS) { - fprintf(stderr, "closeClient returned 0x%08x.\n\n", kernResult); +void MSRAccessor::closeConnection() +{ + kern_return_t kernResult = IOConnectCallScalarMethod(connect, kCloseDriver, + NULL, 0, NULL, NULL); + if (kernResult != KERN_SUCCESS) + { + cerr << "kCloseDriver returned 0x" << hex << setw(8) << kernResult << endl; } - + kernResult = IOServiceClose(connect); - if (kernResult != KERN_SUCCESS) { - fprintf(stderr, "IOServiceClose returned 0x%08x\n\n", kernResult); + if (kernResult != KERN_SUCCESS) + { + cerr << "IOServiceClose returned 0x" << hex << setw(8) << kernResult << endl; } } diff --git a/src/MacMSRDriver/MSRAccessor.h b/src/MacMSRDriver/MSRAccessor.h index e7b7558f..469420c6 100644 --- a/src/MacMSRDriver/MSRAccessor.h +++ b/src/MacMSRDriver/MSRAccessor.h @@ -2,12 +2,12 @@ // Copyright (c) 2012, Intel Corporation // written by Austen Ott // + #include -extern "C" { -#include "DriverInterface.h" -} +#include "PcmMsr/UserKernelShared.h" -class MSRAccessor{ +class MSRAccessor +{ private: io_service_t service; io_connect_t connect; From c3115468d8870094237bbd1e988ef00ffc9de734 Mon Sep 17 00:00:00 2001 From: Neal Sidhwaney Date: Sun, 18 Sep 2022 15:58:28 -0700 Subject: [PATCH 3/3] 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. --- src/MacMSRDriver/MSRAccessor.cpp | 2 +- src/MacMSRDriver/PcmMsr/PcmMsr.cpp | 10 ++--- src/MacMSRDriver/PcmMsr/PcmMsr.h | 2 +- src/MacMSRDriver/PcmMsr/PcmMsrClient.cpp | 6 +-- src/MacMSRDriver/PcmMsr/PcmMsrClient.h | 2 +- src/MacMSRDriver/PcmMsr/UserKernelShared.h | 23 +++++------ src/cpucounters.h | 33 +--------------- src/topologyentry.h | 44 ++++++++++++++++++++++ src/types.h | 12 ++++++ 9 files changed, 77 insertions(+), 57 deletions(-) create mode 100644 src/topologyentry.h diff --git a/src/MacMSRDriver/MSRAccessor.cpp b/src/MacMSRDriver/MSRAccessor.cpp index a4d26133..18cb7ddf 100644 --- a/src/MacMSRDriver/MSRAccessor.cpp +++ b/src/MacMSRDriver/MSRAccessor.cpp @@ -18,7 +18,7 @@ MSRAccessor::MSRAccessor() int32_t MSRAccessor::buildTopology(uint32_t num_cores, void* pTopos) { - size_t topology_struct_size = sizeof(topologyEntry)*num_cores; + size_t topology_struct_size = sizeof(TopologyEntry)*num_cores; kern_return_t ret = IOConnectCallStructMethod(connect, kBuildTopology, NULL, 0, diff --git a/src/MacMSRDriver/PcmMsr/PcmMsr.cpp b/src/MacMSRDriver/PcmMsr/PcmMsr.cpp index 61678add..dd008cd8 100644 --- a/src/MacMSRDriver/PcmMsr/PcmMsr.cpp +++ b/src/MacMSRDriver/PcmMsr/PcmMsr.cpp @@ -57,7 +57,7 @@ void cpuWriteMSR(void* pIDatas){ } void cpuGetTopoData(void* pTopos){ - topologyEntry* entries = (topologyEntry*)pTopos; + TopologyEntry* entries = (TopologyEntry*)pTopos; int cpu = cpu_number(); int info[4]; entries[cpu].os_id = cpu; @@ -166,18 +166,18 @@ IOReturn PcmMsrDriverClassName::writeMSR(pcm_msr_data_t* idata){ return ret; } -IOReturn PcmMsrDriverClassName::buildTopology(topologyEntry* odata, uint32_t input_num_cores) +IOReturn PcmMsrDriverClassName::buildTopology(TopologyEntry* odata, uint32_t input_num_cores) { size_t topologyBufferSize; // TODO figure out when input_num_cores is used rather than num_cores - if (os_mul_overflow(sizeof(topologyEntry), (size_t) num_cores, &topologyBufferSize)) + if (os_mul_overflow(sizeof(TopologyEntry), (size_t) num_cores, &topologyBufferSize)) { return kIOReturnBadArgument; } - topologyEntry *topologies = - (topologyEntry *)IOMallocAligned(topologyBufferSize, 32); + TopologyEntry *topologies = + (TopologyEntry *)IOMallocAligned(topologyBufferSize, 32); if (topologies == nullptr) { diff --git a/src/MacMSRDriver/PcmMsr/PcmMsr.h b/src/MacMSRDriver/PcmMsr/PcmMsr.h index 96862746..ed19c470 100644 --- a/src/MacMSRDriver/PcmMsr/PcmMsr.h +++ b/src/MacMSRDriver/PcmMsr/PcmMsr.h @@ -14,7 +14,7 @@ class PcmMsrDriverClassName : public IOService virtual IOReturn writeMSR(pcm_msr_data_t* data); virtual IOReturn readMSR(pcm_msr_data_t* idata,pcm_msr_data_t* odata); - virtual IOReturn buildTopology(topologyEntry* odata, uint32_t input_num_cores); + virtual IOReturn buildTopology(TopologyEntry* odata, uint32_t input_num_cores); virtual bool init(OSDictionary *dict) override; virtual void free(void) override; virtual bool handleOpen(IOService* forClient, IOOptionBits opts, void* args) override; diff --git a/src/MacMSRDriver/PcmMsr/PcmMsrClient.cpp b/src/MacMSRDriver/PcmMsr/PcmMsrClient.cpp index 1b49f50d..cfca0b0e 100644 --- a/src/MacMSRDriver/PcmMsr/PcmMsrClient.cpp +++ b/src/MacMSRDriver/PcmMsr/PcmMsrClient.cpp @@ -154,12 +154,12 @@ IOReturn PcmMsrClientClassName::writeMSR(pcm_msr_data_t* data) } IOReturn PcmMsrClientClassName::sBuildTopology(PcmMsrClientClassName* target, void* reference, IOExternalMethodArguments* args){ - return target -> buildTopology((topologyEntry*)args->structureOutput, args->structureOutputSize); + return target -> buildTopology((TopologyEntry*)args->structureOutput, args->structureOutputSize); } -IOReturn PcmMsrClientClassName::buildTopology(topologyEntry* data, size_t output_size) +IOReturn PcmMsrClientClassName::buildTopology(TopologyEntry* data, size_t output_size) { - uint32_t num_cores = (uint32_t) (output_size / sizeof(topologyEntry) ); + uint32_t num_cores = (uint32_t) (output_size / sizeof(TopologyEntry) ); IOReturn result = checkActiveAndOpened (__FUNCTION__); if (result == kIOReturnSuccess) diff --git a/src/MacMSRDriver/PcmMsr/PcmMsrClient.h b/src/MacMSRDriver/PcmMsr/PcmMsrClient.h index a0a84b48..54281e54 100644 --- a/src/MacMSRDriver/PcmMsr/PcmMsrClient.h +++ b/src/MacMSRDriver/PcmMsr/PcmMsrClient.h @@ -44,7 +44,7 @@ class PcmMsrClientClassName : public IOUserClient virtual IOReturn writeMSR(pcm_msr_data_t* data); static IOReturn sBuildTopology(PcmMsrClientClassName* target, void* reference, IOExternalMethodArguments* args); - virtual IOReturn buildTopology(topologyEntry* data, size_t output_size); + virtual IOReturn buildTopology(TopologyEntry* data, size_t output_size); static IOReturn sGetNumInstances(PcmMsrClientClassName* target, void* reference, IOExternalMethodArguments* args); virtual IOReturn getNumInstances(uint32_t* num_insts); diff --git a/src/MacMSRDriver/PcmMsr/UserKernelShared.h b/src/MacMSRDriver/PcmMsr/UserKernelShared.h index b10b863c..0907f1f5 100644 --- a/src/MacMSRDriver/PcmMsr/UserKernelShared.h +++ b/src/MacMSRDriver/PcmMsr/UserKernelShared.h @@ -1,12 +1,20 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2012, Intel Corporation // written by Austen Ott -// +// #define PcmMsrDriverClassName com_intel_driver_PcmMsr #define kPcmMsrDriverClassName "com_intel_driver_PcmMsr" + #ifndef USER_KERNEL_SHARED #define USER_KERNEL_SHARED + +#define PCM_API + #include +#include "../../topologyentry.h" + +using namespace pcm; + typedef struct { uint64_t value; uint32_t cpu_num; @@ -20,19 +28,6 @@ typedef struct { char padding[115]; } k_pcm_msr_data_t; -// The topologyEntry struct that is used by PCM -typedef struct -{ - int32_t os_id; - int32_t thread_id; - int32_t core_id; - int32_t tile_id; - int32_t socket; - int32_t native_cpu_model; - int32_t core_type; // This is an enum in the userland structure. - int32_t padding; -} topologyEntry; - enum { kOpenDriver, kCloseDriver, diff --git a/src/cpucounters.h b/src/cpucounters.h index 4e529b5f..25ead6e8 100644 --- a/src/cpucounters.h +++ b/src/cpucounters.h @@ -23,6 +23,7 @@ #undef PCM_UNCORE_PMON_BOX_CHECK_STATUS // debug only #include "types.h" +#include "topologyentry.h" #include "msr.h" #include "pci.h" #include "bw.h" @@ -86,38 +87,6 @@ class SystemRoot; A set of performance monitoring routines for recent Intel CPUs */ -struct PCM_API TopologyEntry // describes a core -{ - int32 os_id; - int32 thread_id; - int32 core_id; - int32 tile_id; // tile is a constalation of 1 or more cores sharing salem L2 cache. Unique for entire system - int32 socket; - int32 native_cpu_model = -1; - enum CoreType - { - Atom = 0x20, - Core = 0x40, - Invalid = -1 - }; - CoreType core_type = Invalid; - - TopologyEntry() : os_id(-1), thread_id (-1), core_id(-1), tile_id(-1), socket(-1) { } - const char* getCoreTypeStr() - { - switch (core_type) - { - case Atom: - return "Atom"; - case Core: - return "Core"; - case Invalid: - return "invalid"; - } - return "unknown"; - } -}; - class HWRegister { public: diff --git a/src/topologyentry.h b/src/topologyentry.h new file mode 100644 index 00000000..1961070b --- /dev/null +++ b/src/topologyentry.h @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2022-, Intel Corporation + +#pragma once + +#include "types.h" + +namespace pcm +{ + +struct PCM_API TopologyEntry // describes a core +{ + int32 os_id; + int32 thread_id; + int32 core_id; + int32 tile_id; // tile is a constalation of 1 or more cores sharing salem L2 cache. Unique for entire system + int32 socket; + int32 native_cpu_model = -1; + enum CoreType + { + Atom = 0x20, + Core = 0x40, + Invalid = -1 + }; + CoreType core_type = Invalid; + + TopologyEntry() : os_id(-1), thread_id (-1), core_id(-1), tile_id(-1), socket(-1) { } + const char* getCoreTypeStr() + { + switch (core_type) + { + case Atom: + return "Atom"; + case Core: + return "Core"; + case Invalid: + return "invalid"; + } + return "unknown"; + } +}; + +} + diff --git a/src/types.h b/src/types.h index c9add4a2..726b9118 100644 --- a/src/types.h +++ b/src/types.h @@ -13,6 +13,8 @@ #undef PCM_DEBUG +#ifndef KERNEL + #include #include #include @@ -23,6 +25,8 @@ #include #endif +#endif // #ifndef KERNEL + namespace pcm { typedef unsigned long long uint64; @@ -383,6 +387,8 @@ struct FixedEventControlRegister FixedEventControlRegister() : value(0) {} }; +#ifndef KERNEL + inline std::ostream & operator << (std::ostream & o, const FixedEventControlRegister & reg) { o << "os0\t\t" << reg.fields.os0 << "\n"; @@ -404,6 +410,8 @@ inline std::ostream & operator << (std::ostream & o, const FixedEventControlRegi return o; } +#endif // #ifndef KERNEL + // UNCORE COUNTER CONTROL /* \brief Uncore Event Select Register Register format @@ -1256,6 +1264,8 @@ union cvt_ds } ui32; }; +#ifndef KERNEL + struct MCFGRecord { unsigned long long baseAddress; @@ -1298,6 +1308,8 @@ struct MCFGHeader } }; +#endif // #ifndef KERNEL + } // namespace pcm #endif