Skip to content

Commit d4c0972

Browse files
committed
Merge tag '2023-12-13' into push-2023-12-13
Change-Id: I23620a4480dd24300f10aad5402448aad1a697c9
2 parents f7be22a + 10f854c commit d4c0972

File tree

7 files changed

+237
-229
lines changed

7 files changed

+237
-229
lines changed

src/MacMSRDriver/MSRKernel.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,4 @@ typedef struct {
1313
uint32_t msr_num;
1414
} pcm_msr_data_t;
1515

16-
/*
17-
// The topologyEntry struct that is used by PCM
18-
typedef struct{
19-
uint32_t os_id;
20-
uint32_t socket;
21-
uint32_t core_id;
22-
} topologyEntry;
23-
24-
// A kernel version of the topology entry structure. It has
25-
// an extra unused int to explicitly align the struct on a 64bit
26-
// boundary, preventing the compiler from adding extra padding.
27-
enum {
28-
kOpenDriver,
29-
kCloseDriver,
30-
kReadMSR,
31-
kWriteMSR,
32-
kBuildTopology,
33-
kGetNumInstances,
34-
kIncrementNumInstances,
35-
kDecrementNumInstances,
36-
kNumberOfMethods
37-
};
38-
*/
3916
#endif

src/MacMSRDriver/PcmMsr/PcmMsr.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ PcmMsrDriverClassName *g_pci_driver = NULL;
1212
asm volatile ("wrmsr" : : "c" (msr), "a" (lo), "d" (hi))
1313
#define rdmsr(msr,lo,hi) \
1414
asm volatile ("\trdmsr\n" : "=a" (lo), "=d" (hi) : "c" (msr))
15-
#define cpuid(func1, func2, a, b, c, d) \
16-
asm volatile ("cpuid" : "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (func1), "c" (func2));
1715

1816
extern "C" {
1917
extern void mp_rendezvous_no_intrs(void (*func)(void *),
@@ -58,14 +56,18 @@ void cpuWriteMSR(void* pIDatas){
5856

5957
void cpuGetTopoData(void* pTopos){
6058
TopologyEntry* entries = (TopologyEntry*)pTopos;
61-
int cpu = cpu_number();
62-
int info[4];
63-
entries[cpu].os_id = cpu;
64-
cpuid(0xB, 1, info[0], info[1], info[2], info[3]);
65-
entries[cpu].socket = info[3] >> info[0] & 0xF;
66-
67-
cpuid(0xB, 0, info[0], info[1], info[2], info[3]);
68-
entries[cpu].core_id = info[3] >> info[0] & 0xF;
59+
const int cpu = cpu_number();
60+
61+
TopologyEntry & entry = entries[cpu];
62+
entry.os_id = cpu;
63+
64+
uint32 smtMaskWidth = 0;
65+
uint32 coreMaskWidth = 0;
66+
uint32 l2CacheMaskShift = 0;
67+
initCoreMasks(smtMaskWidth, coreMaskWidth, l2CacheMaskShift);
68+
PCM_CPUID_INFO cpuid_args;
69+
pcm_cpuid(0xb, 0x0, cpuid_args);
70+
fillEntry(entry, smtMaskWidth, coreMaskWidth, l2CacheMaskShift, cpuid_args.array[3]);
6971
}
7072

7173
OSDefineMetaClassAndStructors(com_intel_driver_PcmMsr, IOService)
@@ -188,8 +190,10 @@ IOReturn PcmMsrDriverClassName::buildTopology(TopologyEntry* odata, uint32_t inp
188190

189191
for(uint32_t i = 0; i < num_cores && i < input_num_cores; i++)
190192
{
191-
odata[i].core_id = topologies[i].core_id;
192193
odata[i].os_id = topologies[i].os_id;
194+
odata[i].thread_id = topologies[i].thread_id;
195+
odata[i].core_id = topologies[i].core_id;
196+
odata[i].tile_id = topologies[i].tile_id;
193197
odata[i].socket = topologies[i].socket;
194198
}
195199

src/cpucounters.cpp

Lines changed: 9 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,6 @@ void pcm_cpuid_bsd(int leaf, PCM_CPUID_INFO& info, int core)
339339
}
340340
#endif
341341

342-
/* Adding the new version of cpuid with leaf and subleaf as an input */
343-
void pcm_cpuid(const unsigned leaf, const unsigned subleaf, PCM_CPUID_INFO & info)
344-
{
345-
#ifdef _MSC_VER
346-
__cpuidex(info.array, leaf, subleaf);
347-
#else
348-
__asm__ __volatile__ ("cpuid" : \
349-
"=a" (info.reg.eax), "=b" (info.reg.ebx), "=c" (info.reg.ecx), "=d" (info.reg.edx) : "a" (leaf), "c" (subleaf));
350-
#endif
351-
}
352-
353342
#ifdef __linux__
354343
bool isNMIWatchdogEnabled(const bool silent);
355344
bool keepNMIWatchdogEnabled();
@@ -1121,16 +1110,9 @@ bool PCM::discoverSystemTopology()
11211110
socketIdMap_type socketIdMap;
11221111

11231112
PCM_CPUID_INFO cpuid_args;
1124-
// init constants for CPU topology leaf 0xB
1125-
// adapted from Topology Enumeration Reference code for Intel 64 Architecture
1126-
// https://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration
1127-
int wasCoreReported = 0, wasThreadReported = 0;
1128-
int subleaf = 0, levelType, levelShift;
1129-
//uint32 coreSelectMask = 0, smtSelectMask = 0;
11301113
uint32 smtMaskWidth = 0;
1131-
//uint32 pkgSelectMask = (-1), pkgSelectMaskShift = 0;
1132-
uint32 corePlusSMTMaskWidth = 0;
11331114
uint32 coreMaskWidth = 0;
1115+
uint32 l2CacheMaskShift = 0;
11341116

11351117
struct domain
11361118
{
@@ -1140,30 +1122,14 @@ bool PCM::discoverSystemTopology()
11401122
std::unordered_map<int, domain> topologyDomainMap;
11411123
{
11421124
TemporalThreadAffinity aff0(0);
1143-
do
1125+
1126+
if (initCoreMasks(smtMaskWidth, coreMaskWidth, l2CacheMaskShift) == false)
11441127
{
1145-
pcm_cpuid(0xb, subleaf, cpuid_args);
1146-
if (cpuid_args.array[1] == 0)
1147-
{ // if EBX ==0 then this subleaf is not valid, we can exit the loop
1148-
break;
1149-
}
1150-
levelType = extract_bits_ui(cpuid_args.array[2], 8, 15);
1151-
levelShift = extract_bits_ui(cpuid_args.array[0], 0, 4);
1152-
switch (levelType)
1153-
{
1154-
case 1: //level type is SMT, so levelShift is the SMT_Mask_Width
1155-
smtMaskWidth = levelShift;
1156-
wasThreadReported = 1;
1157-
break;
1158-
case 2: //level type is Core, so levelShift is the CorePlusSMT_Mask_Width
1159-
corePlusSMTMaskWidth = levelShift;
1160-
wasCoreReported = 1;
1161-
break;
1162-
default:
1163-
break;
1164-
}
1165-
subleaf++;
1166-
} while (1);
1128+
std::cerr << "ERROR: Major problem? No leaf 0 under cpuid function 11.\n";
1129+
return false;
1130+
}
1131+
1132+
int subleaf = 0;
11671133

11681134
std::vector<domain> topologyDomains;
11691135
if (max_cpuid >= 0x1F)
@@ -1209,42 +1175,6 @@ bool PCM::discoverSystemTopology()
12091175
}
12101176
}
12111177

1212-
if (wasThreadReported && wasCoreReported)
1213-
{
1214-
coreMaskWidth = corePlusSMTMaskWidth - smtMaskWidth;
1215-
}
1216-
else if (!wasCoreReported && wasThreadReported)
1217-
{
1218-
coreMaskWidth = smtMaskWidth;
1219-
}
1220-
else
1221-
{
1222-
std::cerr << "ERROR: Major problem? No leaf 0 under cpuid function 11.\n";
1223-
return false;
1224-
}
1225-
1226-
(void) coreMaskWidth; // to suppress warnings on MacOS (unused vars)
1227-
1228-
uint32 l2CacheMaskShift = 0;
1229-
#ifdef PCM_DEBUG_TOPOLOGY
1230-
uint32 threadsSharingL2;
1231-
#endif
1232-
uint32 l2CacheMaskWidth;
1233-
1234-
pcm_cpuid(0x4, 2, cpuid_args); // get ID for L2 cache
1235-
l2CacheMaskWidth = 1 + extract_bits_ui(cpuid_args.array[0],14,25); // number of APIC IDs sharing L2 cache
1236-
#ifdef PCM_DEBUG_TOPOLOGY
1237-
threadsSharingL2 = l2CacheMaskWidth;
1238-
#endif
1239-
for( ; l2CacheMaskWidth > 1; l2CacheMaskWidth >>= 1)
1240-
{
1241-
l2CacheMaskShift++;
1242-
}
1243-
#ifdef PCM_DEBUG_TOPOLOGY
1244-
std::cerr << "DEBUG: Number of threads sharing L2 cache = " << threadsSharingL2
1245-
<< " [the most significant bit = " << l2CacheMaskShift << "]\n";
1246-
#endif
1247-
12481178
#ifndef __APPLE__
12491179
auto populateEntry = [&topologyDomainMap,&smtMaskWidth, &coreMaskWidth, &l2CacheMaskShift](TopologyEntry& entry)
12501180
{
@@ -1285,11 +1215,7 @@ bool PCM::discoverSystemTopology()
12851215
}
12861216
else
12871217
{
1288-
const int apic_id = getAPICID(0xb);
1289-
entry.thread_id = smtMaskWidth ? extract_bits_ui(apic_id, 0, smtMaskWidth - 1) : 0;
1290-
entry.core_id = (smtMaskWidth + coreMaskWidth) ? extract_bits_ui(apic_id, smtMaskWidth, smtMaskWidth + coreMaskWidth - 1) : 0;
1291-
entry.socket = extract_bits_ui(apic_id, smtMaskWidth + coreMaskWidth, 31);
1292-
entry.tile_id = extract_bits_ui(apic_id, l2CacheMaskShift, 31);
1218+
fillEntry(entry, smtMaskWidth, coreMaskWidth, l2CacheMaskShift, getAPICID(0xb));
12931219
}
12941220
};
12951221
#endif

src/pcm-iio.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ using namespace pcm;
4646
#define SKX_UNC_SOCKETID_UBOX_LNID_OFFSET 0xC0
4747
#define SKX_UNC_SOCKETID_UBOX_GID_OFFSET 0xD4
4848

49-
const uint8_t max_sockets = 4;
5049
static const std::string iio_stack_names[6] = {
5150
"IIO Stack 0 - CBDMA/DMI ",
5251
"IIO Stack 1 - PCIe0 ",
@@ -239,8 +238,7 @@ struct iio_counter : public counter {
239238
std::vector<result_content> data;
240239
};
241240

242-
//TODO: remove binding to stacks amount
243-
result_content results(max_sockets, stack_content(12, ctr_data()));
241+
result_content results;
244242

245243
typedef struct
246244
{
@@ -1444,6 +1442,7 @@ void print_usage(const string& progname)
14441442
cout << " -csv-delimiter=<value> | /csv-delimiter=<value> => set custom csv delimiter\n";
14451443
cout << " -human-readable | /human-readable => use human readable format for output (for csv only)\n";
14461444
cout << " -root-port | /root-port => add root port devices to output (for csv only)\n";
1445+
cout << " -list | --list => provide platform topology info\n";
14471446
cout << " -i[=number] | /i[=number] => allow to determine number of iterations\n";
14481447
cout << " Examples:\n";
14491448
cout << " " << progname << " 1.0 -i=10 => print counters every second 10 times and exit\n";
@@ -1456,22 +1455,18 @@ PCM_MAIN_NOTHROW;
14561455

14571456
int mainThrows(int argc, char * argv[])
14581457
{
1459-
if(print_version(argc, argv))
1458+
if (print_version(argc, argv))
14601459
exit(EXIT_SUCCESS);
14611460

14621461
null_stream nullStream;
14631462
check_and_set_silent(argc, argv, nullStream);
14641463

1465-
set_signal_handlers();
1466-
14671464
std::cout << "\n Intel(r) Performance Counter Monitor " << PCM_VERSION << "\n";
14681465
std::cout << "\n This utility measures IIO information\n\n";
14691466

14701467
string program = string(argv[0]);
14711468

14721469
vector<struct iio_counter> counters;
1473-
PCIDB pciDB;
1474-
load_PCIDB(pciDB);
14751470
bool csv = false;
14761471
bool human_readable = false;
14771472
bool show_root_port = false;
@@ -1480,11 +1475,9 @@ int mainThrows(int argc, char * argv[])
14801475
double delay = PCM_DELAY_DEFAULT;
14811476
bool list = false;
14821477
MainLoop mainLoop;
1483-
PCM * m = PCM::getInstance();
14841478
iio_evt_parse_context evt_ctx;
14851479
// Map with metrics names.
14861480
map<string,std::pair<h_id,std::map<string,v_id>>> nameMap;
1487-
map<string,uint32_t> opcodeFieldMap;
14881481

14891482
while (argc > 1) {
14901483
argv++;
@@ -1511,7 +1504,7 @@ int mainThrows(int argc, char * argv[])
15111504
else if (check_argument_equals(*argv, {"-human-readable", "/human-readable"})) {
15121505
human_readable = true;
15131506
}
1514-
else if (check_argument_equals(*argv, {"--list"})) {
1507+
else if (check_argument_equals(*argv, {"-list", "--list"})) {
15151508
list = true;
15161509
}
15171510
else if (check_argument_equals(*argv, {"-root-port", "/root-port"})) {
@@ -1526,13 +1519,14 @@ int mainThrows(int argc, char * argv[])
15261519
}
15271520
}
15281521

1522+
set_signal_handlers();
1523+
15291524
print_cpu_details();
15301525

1531-
//TODO: remove binding to max sockets count.
1532-
if (m->getNumSockets() > max_sockets) {
1533-
cerr << "Only systems with up to " << max_sockets << " sockets are supported! Program aborted\n";
1534-
exit(EXIT_FAILURE);
1535-
}
1526+
PCM * m = PCM::getInstance();
1527+
1528+
PCIDB pciDB;
1529+
load_PCIDB(pciDB);
15361530

15371531
auto mapping = IPlatformMapping::getPlatformMapping(m->getCPUModel(), m->getNumSockets());
15381532
if (!mapping) {
@@ -1568,6 +1562,7 @@ int mainThrows(int argc, char * argv[])
15681562
exit(EXIT_FAILURE);
15691563
}
15701564

1565+
map<string,uint32_t> opcodeFieldMap;
15711566
opcodeFieldMap["opcode"] = PCM::OPCODE;
15721567
opcodeFieldMap["ev_sel"] = PCM::EVENT_SELECT;
15731568
opcodeFieldMap["umask"] = PCM::UMASK;
@@ -1600,8 +1595,11 @@ int mainThrows(int argc, char * argv[])
16001595
exit(EXIT_FAILURE);
16011596
}
16021597

1603-
//print_nameMap(nameMap);
1604-
//TODO: Taking from cli
1598+
#ifdef PCM_DEBUG
1599+
print_nameMap(nameMap);
1600+
#endif
1601+
1602+
results.resize(m->getNumSockets(), stack_content(m->getMaxNumOfIIOStacks(), ctr_data()));
16051603

16061604
mainLoop([&]()
16071605
{

0 commit comments

Comments
 (0)