Skip to content

Commit ab8676f

Browse files
authored
Merge pull request #424 from nealsid/master
2 parents 56040dc + 64161d4 commit ab8676f

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

src/MacMSRDriver/PcmMsr/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ add_executable(
99
)
1010

1111
set_target_properties(PcmMsrDriver PROPERTIES BUNDLE_EXTENSION kext MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/PcmMsr-Info.plist)
12+
13+
1214
target_include_directories(PcmMsrDriver PRIVATE
1315
${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/Kernel.framework/PrivateHeaders
1416
${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/Kernel.framework/Headers
@@ -21,6 +23,11 @@ target_compile_definitions(PcmMsrDriver PRIVATE
2123
-DNeXT
2224
)
2325

26+
target_compile_options(PcmMsrDriver PRIVATE
27+
"-ffreestanding"
28+
"-fapple-kext"
29+
)
30+
2431
target_link_libraries(PcmMsrDriver PRIVATE ${IOKIT_LIBRARY}
2532
"-lkmodc++"
2633
"-lkmod"

src/MacMSRDriver/PcmMsr/PcmMsr.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2012, Intel Corporation
33
// written by Austen Ott
4-
//
4+
//
55
#include <IOKit/IOLib.h>
66
#include <libkern/sysctl.h>
77
#include "PcmMsr.h"
@@ -63,7 +63,7 @@ void cpuGetTopoData(void* pTopos){
6363
entries[cpu].os_id = cpu;
6464
cpuid(0xB, 1, info[0], info[1], info[2], info[3]);
6565
entries[cpu].socket = info[3] >> info[0] & 0xF;
66-
66+
6767
cpuid(0xB, 0, info[0], info[1], info[2], info[3]);
6868
entries[cpu].core_id = info[3] >> info[0] & 0xF;
6969
}
@@ -75,15 +75,15 @@ OSDefineMetaClassAndStructors(com_intel_driver_PcmMsr, IOService)
7575
bool PcmMsrDriverClassName::start(IOService* provider){
7676
bool success;
7777
success = super::start(provider);
78-
78+
7979
if (!g_pci_driver) {
8080
g_pci_driver = this;
8181
}
82-
82+
8383
if (success) {
84-
registerService();
84+
registerService();
8585
}
86-
86+
8787
return success;
8888
}
8989
uint32_t PcmMsrDriverClassName::getNumCores()
@@ -149,9 +149,9 @@ IOReturn PcmMsrDriverClassName::readMSR(pcm_msr_data_t* idatas,pcm_msr_data_t* o
149149
// All the msr_nums should be the same, so we just use the first one to pass to all cores
150150
IOReturn ret = kIOReturnBadArgument;
151151
if(idatas->cpu_num < num_cores)
152-
{
152+
{
153153
mp_rendezvous_no_intrs(cpuReadMSR, (void*)idatas);
154-
154+
155155
odatas->cpu_num = idatas->cpu_num;
156156
odatas->msr_num = idatas->msr_num;
157157
odatas->value = idatas->value;
@@ -169,14 +169,14 @@ IOReturn PcmMsrDriverClassName::writeMSR(pcm_msr_data_t* idata){
169169
if(idata->cpu_num < num_cores)
170170
{
171171
mp_rendezvous_no_intrs(cpuWriteMSR, (void*)idata);
172-
172+
173173
ret = kIOReturnSuccess;
174174
}
175175
else
176176
{
177177
IOLog("Tried to write to a core with id higher than max core id.\n");
178178
}
179-
179+
180180
return ret;
181181
}
182182

@@ -210,7 +210,7 @@ IOReturn PcmMsrDriverClassName::decrementNumInstances(uint32_t* num_insts){
210210
uint32_t PcmMsrDriverClassName::read(uint32_t pci_address)
211211
{
212212
uint32_t value = 0;
213-
213+
214214
__asm__("\t"
215215
"movw $0xCF8,%%dx\n\t"
216216
"andb $0xFC,%%al\n\t"
@@ -220,15 +220,15 @@ uint32_t PcmMsrDriverClassName::read(uint32_t pci_address)
220220
: "=a"(value)
221221
: "a"(pci_address)
222222
: "%edx");
223-
223+
224224
return value;
225225
}
226226

227227

228228
// write
229229
void PcmMsrDriverClassName::write(uint32_t pci_address, uint32_t value)
230230
{
231-
231+
232232
__asm__("\t"
233233
"movw $0xCF8,%%dx\n\t"
234234
"andb $0xFC,%%al\n\t"
@@ -246,7 +246,7 @@ void PcmMsrDriverClassName::write(uint32_t pci_address, uint32_t value)
246246
void* PcmMsrDriverClassName::mapMemory (uint32_t address, UInt8 **virtual_address)
247247
{
248248
PRINT_DEBUG("%s[%p]::%s()\n", getName(), this, __FUNCTION__);
249-
249+
250250
IOMemoryMap *memory_map = NULL;
251251
IOMemoryDescriptor *memory_descriptor = NULL;
252252
#ifndef __clang_analyzer__ // address a false-positive
@@ -278,7 +278,7 @@ void* PcmMsrDriverClassName::mapMemory (uint32_t address, UInt8 **virtual_addres
278278
} else {
279279
IOLog("%s[%p]::%s() -- IOMemoryDescriptor::withPhysicalAddress() failure\n", getName(), this, __FUNCTION__);
280280
}
281-
281+
282282
return (void*)memory_map;
283283
}
284284

@@ -287,9 +287,9 @@ void* PcmMsrDriverClassName::mapMemory (uint32_t address, UInt8 **virtual_addres
287287
void PcmMsrDriverClassName::unmapMemory (void *memory_map)
288288
{
289289
PRINT_DEBUG("%s[%p]::%s()\n", getName(), this, __FUNCTION__);
290-
290+
291291
IOMemoryMap *m_map = (IOMemoryMap*)memory_map;
292-
292+
293293
if (m_map) {
294294
m_map->getMemoryDescriptor()->complete();
295295
#ifndef __clang_analyzer__ // address a false-positive
@@ -298,6 +298,6 @@ void PcmMsrDriverClassName::unmapMemory (void *memory_map)
298298
m_map->unmap();
299299
m_map->release();
300300
}
301-
301+
302302
return;
303303
}

src/cpucounters.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,24 +1276,25 @@ bool PCM::discoverSystemTopology()
12761276
MSR.push_back(std::make_shared<SafeMsrHandle>(i));
12771277
}
12781278

1279-
TopologyEntry *entries = new TopologyEntry[num_cores];
1280-
MSR[0]->buildTopology(num_cores, entries);
1279+
TopologyEntry entries[num_cores];
1280+
if (MSR[0]->buildTopology(num_cores, entries) != 0) {
1281+
std::cerr << "Unable to build CPU topology" << std::endl;
1282+
return false;
1283+
}
12811284
for(int i = 0; i < num_cores; i++){
12821285
socketIdMap[entries[i].socket] = 0;
12831286
if(entries[i].os_id >= 0)
12841287
{
12851288
if(entries[i].core_id == 0 && entries[i].socket == 0) ++threads_per_core;
12861289
if (populateHybridEntry(entries[i], i) == false)
12871290
{
1288-
delete[] entries;
12891291
return false;
12901292
}
12911293
topology.push_back(entries[i]);
12921294
}
12931295
}
1294-
delete[] entries;
12951296
// End of OSX specific code
1296-
#endif // end of ifndef __APPLE__
1297+
#endif
12971298

12981299
#endif //end of ifdef _MSC_VER
12991300

@@ -4514,14 +4515,14 @@ PCM::ErrorCode PCM::programServerUncoreLatencyMetrics(bool enable_pmm)
45144515
if (enable_pmm == false)
45154516
{ //DDR is false
45164517
if (ICX == cpu_model)
4517-
{
4518+
{
45184519
DDRConfig[0] = MC_CH_PCI_PMON_CTL_EVENT(0x80) + MC_CH_PCI_PMON_CTL_UMASK(1); // DRAM RPQ occupancy
45194520
DDRConfig[1] = MC_CH_PCI_PMON_CTL_EVENT(0x10) + MC_CH_PCI_PMON_CTL_UMASK(1); // DRAM RPQ Insert
45204521
DDRConfig[2] = MC_CH_PCI_PMON_CTL_EVENT(0x81) + MC_CH_PCI_PMON_CTL_UMASK(0); // DRAM WPQ Occupancy
45214522
DDRConfig[3] = MC_CH_PCI_PMON_CTL_EVENT(0x20) + MC_CH_PCI_PMON_CTL_UMASK(0); // DRAM WPQ Insert
4522-
4523+
45234524
} else {
4524-
4525+
45254526
DDRConfig[0] = MC_CH_PCI_PMON_CTL_EVENT(0x80) + MC_CH_PCI_PMON_CTL_UMASK(0); // DRAM RPQ occupancy
45264527
DDRConfig[1] = MC_CH_PCI_PMON_CTL_EVENT(0x10) + MC_CH_PCI_PMON_CTL_UMASK(0); // DRAM RPQ Insert
45274528
DDRConfig[2] = MC_CH_PCI_PMON_CTL_EVENT(0x81) + MC_CH_PCI_PMON_CTL_UMASK(0); // DRAM WPQ Occupancy

0 commit comments

Comments
 (0)