Skip to content

Commit

Permalink
Merge pull request #585 from intel/push-2023-10-17
Browse files Browse the repository at this point in the history
Push 2023 10 17
  • Loading branch information
rdementi authored Oct 18, 2023
2 parents 3674dbc + ab09473 commit b1091a5
Show file tree
Hide file tree
Showing 21 changed files with 844 additions and 353 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Graphical front ends:
- **pcm-sensor** : front-end for KDE KSysGuard
- **pcm-service** : front-end for Windows perfmon

There are also utilities for reading/writing model specific registers (**pcm-msr**), PCI configuration registers (**pcm-pcicfg**) and memory mapped registers (**pcm-mmio**) supported on Linux, Windows, Mac OS X and FreeBSD.
There are also utilities for reading/writing model specific registers (**pcm-msr**), PCI configuration registers (**pcm-pcicfg**), memory mapped registers (**pcm-mmio**) and TPMI registers (**pcm-tpmi**) supported on Linux, Windows, Mac OS X and FreeBSD.

And finally a daemon that stores core, memory and QPI counters in shared memory that can be be accessed by non-root users.

Expand Down Expand Up @@ -87,7 +87,7 @@ Debug is default on Windows. Specify config to build Release:
```
cmake --build . --config Release
```
On Windows and MacOs additional drivers are required. Please find instructions here: [WINDOWS_HOWTO.md](doc/WINDOWS_HOWTO.md) and [MAC_HOWTO.txt](doc/MAC_HOWTO.txt).
On Windows and MacOs additional drivers and steps are required. Please find instructions here: [WINDOWS_HOWTO.md](doc/WINDOWS_HOWTO.md) and [MAC_HOWTO.txt](doc/MAC_HOWTO.txt).

FreeBSD/DragonFlyBSD-specific details can be found in [FREEBSD_HOWTO.txt](doc/FREEBSD_HOWTO.txt)

Expand All @@ -103,7 +103,7 @@ Downloading Pre-Compiled PCM Tools
* RHEL8.5 or later: `sudo dnf install pcm`
* Fedora: `sudo yum install pcm`
* RPMs and DEBs with the *latest* PCM version for RHEL/SLE/Ubuntu/Debian/openSUSE/etc distributions (binary and source) are available [here](https://software.opensuse.org/download/package?package=pcm&project=home%3Aopcm)
- Windows: download PCM binaries as [appveyor build service](https://ci.appveyor.com/project/opcm/pcm/history) artifacts and required Visual C++ Redistributable from [www.microsoft.com](https://www.microsoft.com/en-us/download/details.aspx?id=48145). Additional drivers are needed, see [WINDOWS_HOWTO.md](doc/WINDOWS_HOWTO.md).
- Windows: download PCM binaries as [appveyor build service](https://ci.appveyor.com/project/opcm/pcm/history) artifacts and required Visual C++ Redistributable from [www.microsoft.com](https://www.microsoft.com/en-us/download/details.aspx?id=48145). Additional steps and drivers are required, see [WINDOWS_HOWTO.md](doc/WINDOWS_HOWTO.md).
- Docker: see [instructions on how to use pcm-sensor-server pre-compiled container from docker hub](doc/DOCKER_README.md).

--------------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions doc/WINDOWS_HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ _For support of systems with more than _**_64_**_ logical cores you need to comp
```
alternatively you can perform `cmake -B build`, open *PCM.sln* form *build* folder in and build required project in Visual Studio.
.exe and .dll files will be located in *build\bin\Release* folder
3. Copy the msr.sys driver and pcm.exe into a single directory
3. As Administrator create PCM directory in Windows "Program Files" directory (e.g. `C:\Program Files (x86)\PCM\`)
4. As Administrator copy the msr.sys driver and pcm.exe into the PCM directory
5. Run pcm.exe utility from the PCM directory as Administrator

4. Run pcm.exe utility from this directory

For Windows 7 and Windows Server 2008 R2 the PCM utilities need to be run as administrator:
For Windows 7+ and Windows Server 2008+ R2 the PCM utilities need to be run as administrator:

Alternatively you can achieve the same using the “Properties” Windows menu of the executable (“Privilege level” setting in the “Compatibility” tab): Right mouse click -> Properties -> Compatibility -> Privilege level -> Set “Run this program as an administrator”.

Expand All @@ -35,7 +35,7 @@ If you are getting the error `Starting MSR service failed with error 3 The syste

4. Build 'PCM-Service.exe' using Microsoft Visual Studio or cmake

5. Copy PCM-Service.exe, PCM-Service.exe.config, and pcm-lib.dll files into a single directory
5. Copy PCM-Service.exe, PCM-Service.exe.config, and pcm-lib.dll files into the PCM sub-directory in Windows "Program Files" directory (see above)

The config file enables support for legacy security policy. Without this configuration switch, you will get an exception like this:

Expand Down
22 changes: 11 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


# All pcm-* executables
set(PROJECT_NAMES pcm pcm-numa pcm-latency pcm-power pcm-msr pcm-memory pcm-tsx pcm-pcie pcm-core pcm-iio pcm-lspci pcm-pcicfg pcm-mmio pcm-raw pcm-accel)
set(PROJECT_NAMES pcm pcm-numa pcm-latency pcm-power pcm-msr pcm-memory pcm-tsx pcm-pcie pcm-core pcm-iio pcm-lspci pcm-pcicfg pcm-mmio pcm-tpmi pcm-raw pcm-accel)

file(GLOB COMMON_SOURCES msr.cpp cpucounters.cpp pci.cpp mmio.cpp bw.cpp utils.cpp topology.cpp debug.cpp threadpool.cpp uncore_pmu_discovery.cpp)

Expand Down Expand Up @@ -54,26 +54,22 @@ if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /wd4251 /wd4273 /EHa /Zi")
add_definitions(/W3)

# https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html
# windows/restrictDriverAccess.cpp is building separately
add_library(restrictDriverAccess OBJECT windows/restrictDriverAccess.cpp)
set_target_properties(restrictDriverAccess PROPERTIES COMMON_LANGUAGE_RUNTIME "")
target_compile_definitions(restrictDriverAccess PRIVATE _CONSOLE _UNICODE UNICODE)

# Rest of windows/* files + restrictDriverAccess.cpp -> PCM_STATIC
# windows/* files -> PCM_STATIC
file(GLOB WINDOWS_SOURCES winpmem/winpmem.cpp windows/stdafx.cpp freegetopt/getopt.cpp)
add_library(PCM_STATIC STATIC $<TARGET_OBJECTS:restrictDriverAccess> ${COMMON_SOURCES} ${WINDOWS_SOURCES})
add_library(PCM_STATIC STATIC ${COMMON_SOURCES} ${WINDOWS_SOURCES})
target_compile_definitions(PCM_STATIC PRIVATE UNICODE _UNICODE _CONSOLE)
target_compile_options(PCM_STATIC PRIVATE "/MT$<$<CONFIG:Debug>:d>")

# Graphical perfmon front-end: pcm-lib, pcm-service
# Files: COMMON_FILES() + pcm-lib.cpp winpmem\winpmem.cpp dllmain.cpp
file(GLOB PCM_LIB_SOURCES winpmem/winpmem.cpp dllmain.cpp pcm-lib.cpp )
add_library(pcm-lib SHARED $<TARGET_OBJECTS:restrictDriverAccess> ${COMMON_SOURCES} ${PCM_LIB_SOURCES})
add_library(pcm-lib SHARED ${COMMON_SOURCES} ${PCM_LIB_SOURCES})
target_compile_definitions(pcm-lib PRIVATE _WINDOWS _USRDLL PCM_EXPORTS _WINDLL _UNICODE UNICODE)
target_compile_options(pcm-lib PRIVATE "/MT$<$<CONFIG:Debug>:d>")

# Pcm-service files: PCM_SHARED + AssemblyInfo.cpp PCMInstaller.cpp PCMService.cpp
file(GLOB PCM_SERVICE_SOURCES windows/PCMInstaller.cpp windows/PCMService.cpp windows/AssemblyInfo.cpp winddows/utils.cpp)
add_executable(pcm-service $<TARGET_OBJECTS:restrictDriverAccess> ${PCM_SERVICE_SOURCES})
add_executable(pcm-service ${PCM_SERVICE_SOURCES})
target_compile_definitions(pcm-service PRIVATE _UNICODE UNICODE _CONSOLE)
set_target_properties(pcm-service PROPERTIES LINK_FLAGS "/INCREMENTAL:NO" COMMON_LANGUAGE_RUNTIME "")
set_property(TARGET pcm-service PROPERTY VS_DOTNET_REFERENCES "System;System.Configuration.Install;System.Data;System.Management;System.ServiceProcess;System.Xml")
Expand Down Expand Up @@ -134,6 +130,10 @@ foreach(PROJECT_NAME ${PROJECT_NAMES})

add_executable(${PROJECT_NAME} ${PROJECT_FILE})

if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE "/MT$<$<CONFIG:Debug>:d>")
endif(MSVC)

# specific file for pcm-raw project
if(${PROJECT_NAME} STREQUAL pcm-raw)
set(LIBS ${LIBS} PCM_SIMDJSON)
Expand Down
97 changes: 64 additions & 33 deletions src/cpucounters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ int convertUnknownToInt(size_t size, char* value);

#ifdef _MSC_VER

void PCM_API restrictDriverAccess(LPCTSTR path)
{
restrictDriverAccessNative(path);
}

HMODULE hOpenLibSys = NULL;

#ifndef NO_WINRING
Expand Down Expand Up @@ -1984,6 +1989,19 @@ void PCM::initUncoreObjects()
{
initUncorePMUsDirect();
}

std::cerr << "Info: " << uboxPMUs.size() << " UBOX units detected.\n";
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
{
std::cerr << "Socket " << s << ":" <<
" " << ((s < pcuPMUs.size()) ? pcuPMUs[s].size() : 0) << " PCU units detected."
" " << ((s < iioPMUs.size()) ? iioPMUs[s].size() : 0) << " IIO units detected."
" " << ((s < irpPMUs.size()) ? irpPMUs[s].size() : 0) << " IRP units detected."
" " << ((s < cboPMUs.size()) ? cboPMUs[s].size() : 0) << " CHA/CBO units detected."
" " << ((s < mdfPMUs.size()) ? mdfPMUs[s].size() : 0) << " MDF units detected."
" " << ((s < cxlPMUs.size()) ? cxlPMUs[s].size() : 0) << " CXL units detected."
"\n";
}
}

void PCM::globalFreezeUncoreCounters()
Expand Down Expand Up @@ -2026,6 +2044,7 @@ void PCM::globalFreezeUncoreCountersInternal(const unsigned long long int freeze

void PCM::initUncorePMUsDirect()
{
pcuPMUs.resize(num_sockets);
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
{
auto & handle = MSR[socketRefCore[s]];
Expand Down Expand Up @@ -2121,7 +2140,7 @@ void PCM::initUncorePMUsDirect()
{
case IVYTOWN:
case JAKETOWN:
pcuPMUs.push_back(
pcuPMUs[s].push_back(
UncorePMU(
std::make_shared<MSRRegister>(handle, JKTIVT_PCU_MSR_PMON_BOX_CTL_ADDR),
std::make_shared<MSRRegister>(handle, JKTIVT_PCU_MSR_PMON_CTL0_ADDR),
Expand All @@ -2144,7 +2163,7 @@ void PCM::initUncorePMUsDirect()
case HASWELLX:
case SKX:
case ICX:
pcuPMUs.push_back(
pcuPMUs[s].push_back(
UncorePMU(
std::make_shared<MSRRegister>(handle, HSX_PCU_MSR_PMON_BOX_CTL_ADDR),
std::make_shared<MSRRegister>(handle, HSX_PCU_MSR_PMON_CTL0_ADDR),
Expand All @@ -2162,13 +2181,14 @@ void PCM::initUncorePMUsDirect()
);
break;
case SPR:
addPMUsFromDiscovery(pcuPMUs, SPR_PCU_BOX_TYPE, 0xE);
if (pcuPMUs.empty())
addPMUsFromDiscovery(pcuPMUs[s], SPR_PCU_BOX_TYPE, 0xE);
if (pcuPMUs[s].empty())
{
std::cerr << "ERROR: PCU PMU not found\n";
}
break;
}
assert(pcuPMUs[s].size() <= ServerUncoreCounterState::maxPUnits);

// add MDF PMUs
switch (cpu_model)
Expand All @@ -2185,9 +2205,10 @@ void PCM::initUncorePMUsDirect()
}

// init IIO addresses
if (getCPUModel() == PCM::SKX)
iioPMUs.resize(num_sockets);
switch (getCPUModel())
{
iioPMUs.resize(num_sockets);
case PCM::SKX:
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
{
auto & handle = MSR[socketRefCore[s]];
Expand All @@ -2206,10 +2227,8 @@ void PCM::initUncorePMUsDirect()
);
}
}
}
else if (getCPUModel() == PCM::ICX)
{
iioPMUs.resize(num_sockets);
break;
case PCM::ICX:
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
{
auto & handle = MSR[socketRefCore[s]];
Expand All @@ -2228,10 +2247,8 @@ void PCM::initUncorePMUsDirect()
);
}
}
}
else if (getCPUModel() == PCM::SNOWRIDGE)
{
iioPMUs.resize(num_sockets);
break;
case PCM::SNOWRIDGE:
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
{
auto & handle = MSR[socketRefCore[s]];
Expand All @@ -2250,11 +2267,8 @@ void PCM::initUncorePMUsDirect()
);
}
}
}

if (getCPUModel() == PCM::SPR)
{
iioPMUs.resize(num_sockets);
break;
case PCM::SPR:
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
{
auto & handle = MSR[socketRefCore[s]];
Expand All @@ -2273,9 +2287,9 @@ void PCM::initUncorePMUsDirect()
);
}
}
break;
}


//init the IDX accelerator
auto createIDXPMU = [](const size_t addr, const size_t mapSize, const size_t numaNode, const size_t socketId) -> IDX_PMU
{
Expand Down Expand Up @@ -2562,9 +2576,10 @@ void PCM::initUncorePMUsPerf()
irpPMUs.resize(num_sockets);
cboPMUs.resize(num_sockets);
mdfPMUs.resize(num_sockets);
pcuPMUs.resize(num_sockets);
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
{
populatePerfPMUs(s, enumeratePerfPMUs("pcu", 100), pcuPMUs, false, true);
populatePerfPMUs(s, enumeratePerfPMUs("pcu", 100), pcuPMUs[s], false, true);
populatePerfPMUs(s, enumeratePerfPMUs("ubox", 100), uboxPMUs, true);
populatePerfPMUs(s, enumeratePerfPMUs("cbox", 100), cboPMUs[s], false, true, true);
populatePerfPMUs(s, enumeratePerfPMUs("cha", 200), cboPMUs[s], false, true, true);
Expand Down Expand Up @@ -4673,9 +4688,12 @@ void PCM::cleanupUncorePMUs(const bool silent)
pmu.cleanup();
}
}
for (auto & pmu : pcuPMUs)
for (auto& spcuPMUs : pcuPMUs)
{
pmu.cleanup();
for (auto& pmu : spcuPMUs)
{
pmu.cleanup();
}
}
for (auto& sPMUs : cxlPMUs)
{
Expand Down Expand Up @@ -5418,14 +5436,17 @@ void PCM::programPCU(uint32* PCUCntConf, const uint64 filter)
uint32 refCore = socketRefCore[i];
TemporalThreadAffinity tempThreadAffinity(refCore); // speedup trick for Linux

pcuPMUs[i].initFreeze(UNC_PMON_UNIT_CTL_FRZ_EN);

if (pcuPMUs[i].filter[0].get())
for (auto& pmu : pcuPMUs[i])
{
*pcuPMUs[i].filter[0] = filter;
}
pmu.initFreeze(UNC_PMON_UNIT_CTL_FRZ_EN);

program(pcuPMUs[i], &PCUCntConf[0], &PCUCntConf[4], UNC_PMON_UNIT_CTL_FRZ_EN);
if (pmu.filter[0].get())
{
*pmu.filter[0] = filter;
}

program(pmu, &PCUCntConf[0], &PCUCntConf[4], UNC_PMON_UNIT_CTL_FRZ_EN);
}
}
}

Expand Down Expand Up @@ -5731,7 +5752,10 @@ void PCM::freezeServerUncoreCounters()
const auto refCore = socketRefCore[i];
TemporalThreadAffinity tempThreadAffinity(refCore); // speedup trick for Linux

pcuPMUs[i].freeze(UNC_PMON_UNIT_CTL_FRZ_EN);
for (auto& pmu : pcuPMUs[i])
{
pmu.freeze(UNC_PMON_UNIT_CTL_FRZ_EN);
}

if (IIOEventsAvailable())
{
Expand Down Expand Up @@ -5783,7 +5807,10 @@ void PCM::unfreezeServerUncoreCounters()
const auto refCore = socketRefCore[i];
TemporalThreadAffinity tempThreadAffinity(refCore); // speedup trick for Linux

pcuPMUs[i].unfreeze(UNC_PMON_UNIT_CTL_FRZ_EN);
for (auto& pmu : pcuPMUs[i])
{
pmu.unfreeze(UNC_PMON_UNIT_CTL_FRZ_EN);
}

if (IIOEventsAvailable())
{
Expand Down Expand Up @@ -6588,9 +6615,13 @@ ServerUncoreCounterState PCM::getServerUncoreCounterState(uint32 socket)
result.UBOXCounter[i] = *(uboxPMUs[socket].counterValue[i]);
result.UncClocks = getUncoreClocks(socket);
}
for (int i = 0; i < ServerUncoreCounterState::maxCounters && socket < pcuPMUs.size() && size_t(i) < pcuPMUs[socket].size(); ++i)
for (size_t u = 0; socket < pcuPMUs.size() && u < pcuPMUs[socket].size(); ++u)
{
result.PCUCounter[i] = *pcuPMUs[socket].counterValue[i];
for (int i = 0; i < ServerUncoreCounterState::maxCounters && size_t(i) < pcuPMUs[socket][u].size(); ++i)
{
assert(u < ServerUncoreCounterState::maxPUnits);
result.PCUCounter[u][i] = *pcuPMUs[socket][u].counterValue[i];
}
}
for (size_t p = 0; p < getNumCXLPorts(socket); ++p)
{
Expand Down
Loading

0 comments on commit b1091a5

Please sign in to comment.