Skip to content

Commit a545f63

Browse files
authored
Merge pull request #747 from intel-innersource/add_pci_counters_to_pcm-sensor-server_output
Add pci counters to pcm sensor server output
2 parents 3cad50f + a2449a6 commit a545f63

File tree

10 files changed

+2433
-2334
lines changed

10 files changed

+2433
-2334
lines changed

src/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ set(PROJECT_NAMES pcm pcm-numa pcm-latency pcm-power pcm-msr pcm-memory pcm-tsx
88

99
set(MINIMUM_OPENSSL_VERSION 1.1.1)
1010

11-
file(GLOB COMMON_SOURCES pcm-accel-common.cpp msr.cpp cpucounters.cpp pci.cpp mmio.cpp tpmi.cpp pmt.cpp bw.cpp utils.cpp topology.cpp debug.cpp threadpool.cpp uncore_pmu_discovery.cpp ${PCM_PUGIXML_CPP})
11+
file(GLOB COMMON_SOURCES pcm-accel-common.cpp msr.cpp cpucounters.cpp pci.cpp mmio.cpp tpmi.cpp pmt.cpp bw.cpp utils.cpp topology.cpp debug.cpp threadpool.cpp uncore_pmu_discovery.cpp pcm-iio-pmu.cpp lspci.cpp ${PCM_PUGIXML_CPP})
1212

1313
if (APPLE)
14-
file(GLOB UNUX_SOURCES dashboard.cpp)
14+
file(GLOB UNIX_SOURCES dashboard.cpp)
1515
else()
16-
file(GLOB UNUX_SOURCES dashboard.cpp resctrl.cpp)
16+
file(GLOB UNIX_SOURCES dashboard.cpp resctrl.cpp)
1717
endif()
1818

1919
if (LINUX)
@@ -49,11 +49,11 @@ if(UNIX) # LINUX, FREE_BSD, APPLE
4949
list(APPEND PROJECT_NAMES pcm-sensor)
5050

5151
# libpcm.a
52-
add_library(PCM_STATIC STATIC ${COMMON_SOURCES} ${UNUX_SOURCES})
52+
add_library(PCM_STATIC STATIC ${COMMON_SOURCES} ${UNIX_SOURCES})
5353
set_target_properties(PCM_STATIC PROPERTIES OUTPUT_NAME pcm)
5454

5555
# libpcm.a with -DPCM_SILENT for Release*
56-
add_library(PCM_STATIC_SILENT STATIC ${COMMON_SOURCES} ${UNUX_SOURCES})
56+
add_library(PCM_STATIC_SILENT STATIC ${COMMON_SOURCES} ${UNIX_SOURCES})
5757
target_compile_definitions(PCM_STATIC_SILENT PRIVATE
5858
$<$<CONFIG:Release>:PCM_SILENT>
5959
$<$<CONFIG:MinSizeRel>:PCM_SILENT>

src/cpucounters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ void PCM::initUncorePMUsDirect()
26522652
std::vector<std::pair<uint32, uint32> > socket2QATbus;
26532653
std::map<int, int> rootbusMap;
26542654

2655-
//Enumurate IDX devices by PCIe bus scan
2655+
//Enumerate IDX devices by PCIe bus scan
26562656
initSocket2Bus(socket2IAAbus, SPR_IDX_IAA_REGISTER_DEV_ADDR, SPR_IDX_IAA_REGISTER_FUNC_ADDR, IAA_DEV_IDS, (uint32)sizeof(IAA_DEV_IDS) / sizeof(IAA_DEV_IDS[0]));
26572657
initSocket2Bus(socket2DSAbus, SPR_IDX_DSA_REGISTER_DEV_ADDR, SPR_IDX_DSA_REGISTER_FUNC_ADDR, DSA_DEV_IDS, (uint32)sizeof(DSA_DEV_IDS) / sizeof(DSA_DEV_IDS[0]));
26582658
initSocket2Bus(socket2QATbus, SPR_IDX_QAT_REGISTER_DEV_ADDR, SPR_IDX_QAT_REGISTER_FUNC_ADDR, QAT_DEV_IDS, (uint32)sizeof(QAT_DEV_IDS) / sizeof(QAT_DEV_IDS[0]));

src/lspci.cpp

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#include "lspci.h"
2+
3+
namespace pcm {
4+
5+
const ccr_config ccr::skx_ccrs(44, 0xFFULL);
6+
const ccr_config ccr::icx_ccrs(48, 0xFFFULL);
7+
8+
bool operator<(const iio_stack& lh, const iio_stack& rh)
9+
{
10+
return lh.iio_unit_id < rh.iio_unit_id;
11+
}
12+
13+
bool operator<(const bdf &l, const bdf &r) {
14+
if (l.domainno < r.domainno)
15+
return true;
16+
if (l.domainno > r.domainno)
17+
return false;
18+
if (l.busno < r.busno)
19+
return true;
20+
if (l.busno > r.busno)
21+
return false;
22+
if (l.devno < r.devno)
23+
return true;
24+
if (l.devno > r.devno)
25+
return false;
26+
if (l.funcno < r.funcno)
27+
return true;
28+
if (l.funcno > r.funcno)
29+
return false;
30+
31+
return false; // bdf == bdf
32+
}
33+
34+
void probe_capability_pci_express(struct pci *p, uint32_t cap_ptr)
35+
{
36+
struct cap {
37+
union {
38+
struct {
39+
uint8_t id;
40+
union {
41+
uint8_t next;
42+
uint8_t cap_ptr;
43+
};
44+
uint16_t junk;
45+
};
46+
uint32 dw0;
47+
};
48+
} cap;
49+
uint32 value;
50+
PciHandleType h(0, p->bdf.busno, p->bdf.devno, p->bdf.funcno);
51+
h.read32(cap_ptr, &value); //Capability pointer
52+
cap.dw0 = value;
53+
if (cap.id != 0x10 && cap.next != 0x00) {
54+
probe_capability_pci_express(p, cap.cap_ptr);
55+
} else {
56+
if (cap.id == 0x10) { // We're in PCI express capability structure
57+
h.read32(cap_ptr+0x10, &value);
58+
p->link_info = value;
59+
} else { /*Finish recursive searching but cannot find PCI express capability structure*/ }
60+
}
61+
}
62+
63+
bool probe_pci(struct pci *p)
64+
{
65+
uint32 value;
66+
p->exist = false;
67+
struct bdf *bdf = &p->bdf;
68+
if (PciHandleType::exists(bdf->domainno, bdf->busno, bdf->devno, bdf->funcno)) {
69+
PciHandleType h(bdf->domainno, bdf->busno, bdf->devno, bdf->funcno);
70+
// VID:DID
71+
h.read32(0x0, &value);
72+
// Invalid VID::DID
73+
if (value != (std::numeric_limits<unsigned int>::max)()) {
74+
p->offset_0 = value;
75+
h.read32(0xc, &value);
76+
p->header_type = (value >> 16) & 0x7f;
77+
if (p->header_type == 0) {
78+
// Status register
79+
h.read32(0x4, &value);
80+
// Capability list == true
81+
if (value & 0x100000) {
82+
// Capability pointer
83+
h.read32(0x34, &value);
84+
probe_capability_pci_express(p, value);
85+
}
86+
} else if (p->header_type == 1) {
87+
h.read32(0x18, &value);
88+
p->offset_18 = value;
89+
}
90+
p->exist = true;
91+
}
92+
}
93+
94+
return p->exist;
95+
}
96+
97+
void print_pci(struct pci p, const PCIDB & pciDB)
98+
{
99+
printf("Parent bridge info:");
100+
printf("%x:%x.%d [%04x:%04x] %s %s %d P:%x S:%x S:%x ",
101+
p.bdf.busno, p.bdf.devno, p.bdf.funcno,
102+
p.vendor_id, p.device_id,
103+
(pciDB.first.count(p.vendor_id) > 0)?pciDB.first.at(p.vendor_id).c_str():"unknown vendor",
104+
(pciDB.second.count(p.vendor_id) > 0 && pciDB.second.at(p.vendor_id).count(p.device_id) > 0)?pciDB.second.at(p.vendor_id).at(p.device_id).c_str():"unknown device",
105+
p.header_type,
106+
p.primary_bus_number, p.secondary_bus_number, p.subordinate_bus_number);
107+
printf("Device info:");
108+
printf("%x:%x.%d [%04x:%04x] %s %s %d Gen%d x%d\n",
109+
p.bdf.busno, p.bdf.devno, p.bdf.funcno,
110+
p.vendor_id, p.device_id,
111+
(pciDB.first.count(p.vendor_id) > 0)?pciDB.first.at(p.vendor_id).c_str():"unknown vendor",
112+
(pciDB.second.count(p.vendor_id) > 0 && pciDB.second.at(p.vendor_id).count(p.device_id) > 0)?pciDB.second.at(p.vendor_id).at(p.device_id).c_str():"unknown device",
113+
p.header_type,
114+
p.link_speed, p.link_width);
115+
}
116+
117+
void load_PCIDB(PCIDB & pciDB)
118+
{
119+
std::ifstream in(PCI_IDS_PATH);
120+
std::string line, item;
121+
122+
if (!in.is_open())
123+
{
124+
#ifndef _MSC_VER
125+
// On Unix, try PCI_IDS_PATH2
126+
in.open(PCI_IDS_PATH2);
127+
}
128+
129+
if (!in.is_open())
130+
{
131+
// On Unix, try the current directory if the default path failed
132+
in.open("pci.ids");
133+
}
134+
135+
if (!in.is_open())
136+
{
137+
#endif
138+
std::cerr << PCI_IDS_NOT_FOUND << "\n";
139+
return;
140+
}
141+
142+
int vendorID = -1;
143+
144+
while (std::getline(in, line)) {
145+
// Ignore any line starting with #
146+
if (line.size() == 0 || line[0] == '#')
147+
continue;
148+
149+
if (line[0] == '\t' && line[1] == '\t')
150+
{
151+
// subvendor subdevice subsystem_name
152+
continue;
153+
}
154+
if (line[0] == '\t')
155+
{
156+
int deviceID = stoi(line.substr(1,4),0,16);
157+
//std::cout << vendorID << ";" << vendorName << ";" << deviceID << ";" << line.substr(7) << "\n";
158+
pciDB.second[vendorID][deviceID] = line.substr(7);
159+
continue;
160+
}
161+
// vendor
162+
vendorID = stoi(line.substr(0,4),0,16);
163+
pciDB.first[vendorID] = line.substr(6);
164+
}
165+
}
166+
167+
} // Namespace pcm

0 commit comments

Comments
 (0)