Skip to content

Commit eec62c8

Browse files
committed
rename extract_bits_ui into extract_bits_32
to reduce risk of cutting bits of wider input integers Change-Id: Iaac12ef1147c9d292cf7f6a5d7a32a20e81b40b5
1 parent 66cb2b2 commit eec62c8

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

src/cpucounters.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ void PCM::readCoreCounterConfig(const bool complainAboutMSR)
253253
// get counter related info
254254
PCM_CPUID_INFO cpuinfo;
255255
pcm_cpuid(0xa, cpuinfo);
256-
perfmon_version = extract_bits_ui(cpuinfo.array[0], 0, 7);
257-
core_gen_counter_num_max = extract_bits_ui(cpuinfo.array[0], 8, 15);
258-
core_gen_counter_width = extract_bits_ui(cpuinfo.array[0], 16, 23);
256+
perfmon_version = extract_bits_32(cpuinfo.array[0], 0, 7);
257+
core_gen_counter_num_max = extract_bits_32(cpuinfo.array[0], 8, 15);
258+
core_gen_counter_width = extract_bits_32(cpuinfo.array[0], 16, 23);
259259
if (perfmon_version > 1)
260260
{
261-
core_fixed_counter_num_max = extract_bits_ui(cpuinfo.array[3], 0, 4);
262-
core_fixed_counter_width = extract_bits_ui(cpuinfo.array[3], 5, 12);
261+
core_fixed_counter_num_max = extract_bits_32(cpuinfo.array[3], 0, 4);
262+
core_fixed_counter_width = extract_bits_32(cpuinfo.array[3], 5, 12);
263263
}
264264
else if (1 == perfmon_version)
265265
{
@@ -321,7 +321,7 @@ bool PCM::isFixedCounterSupported(unsigned c)
321321
{
322322
PCM_CPUID_INFO cpuinfo;
323323
pcm_cpuid(0xa, cpuinfo);
324-
return extract_bits_ui(cpuinfo.reg.ecx, c, c) || (extract_bits_ui(cpuinfo.reg.edx, 4, 0) > c);
324+
return extract_bits_32(cpuinfo.reg.ecx, c, c) || (extract_bits_32(cpuinfo.reg.edx, 4, 0) > c);
325325
}
326326
return false;
327327
}
@@ -340,7 +340,7 @@ bool PCM::isHWTMAL1Supported() const
340340
supported = 0;
341341
PCM_CPUID_INFO cpuinfo;
342342
pcm_cpuid(1, cpuinfo);
343-
if (extract_bits_ui(cpuinfo.reg.ecx, 15, 15) && MSR.size())
343+
if (extract_bits_32(cpuinfo.reg.ecx, 15, 15) && MSR.size())
344344
{
345345
uint64 perf_cap;
346346
if (MSR[0]->read(MSR_PERF_CAPABILITIES, &perf_cap) == sizeof(uint64))
@@ -1125,12 +1125,12 @@ bool PCM::discoverSystemTopology()
11251125
{
11261126
pcm_cpuid(0x1F, subleaf, cpuid_args);
11271127
domain d;
1128-
d.type = (TopologyEntry::DomainTypeID)extract_bits_ui(cpuid_args.reg.ecx, 8, 15);
1128+
d.type = (TopologyEntry::DomainTypeID)extract_bits_32(cpuid_args.reg.ecx, 8, 15);
11291129
if (d.type == TopologyEntry::DomainTypeID::InvalidDomainTypeID)
11301130
{
11311131
break;
11321132
}
1133-
d.nextLevelShift = extract_bits_ui(cpuid_args.reg.eax, 0, 4);
1133+
d.nextLevelShift = extract_bits_32(cpuid_args.reg.eax, 0, 4);
11341134
d.levelShift = topologyDomains.empty() ? 0 : topologyDomains.back().nextLevelShift;
11351135
d.width = d.nextLevelShift - d.levelShift;
11361136
topologyDomains.push_back(d);
@@ -1182,11 +1182,11 @@ bool PCM::discoverSystemTopology()
11821182
if (di != topologyDomainMap.end())
11831183
{
11841184
const auto & d = di->second;
1185-
return extract_bits_ui(apic_id, d.levelShift, d.nextLevelShift - 1);
1185+
return extract_bits_32(apic_id, d.levelShift, d.nextLevelShift - 1);
11861186
}
11871187
return 0U;
11881188
};
1189-
entry.tile_id = extract_bits_ui(getAPICID(0xb), l2CacheMaskShift, 31);
1189+
entry.tile_id = extract_bits_32(getAPICID(0xb), l2CacheMaskShift, 31);
11901190
const int apic_id = getAPICID(0x1F);
11911191
entry.thread_id = getID(apic_id, TopologyEntry::DomainTypeID::LogicalProcessorDomain);
11921192
entry.core_id = getID(apic_id, TopologyEntry::DomainTypeID::CoreDomain);
@@ -1210,7 +1210,7 @@ bool PCM::discoverSystemTopology()
12101210
};
12111211
domain d1 = getDomain( TopologyEntry::DomainTypeID::CoreDomain );
12121212
domain d2 = getDomain( TopologyEntry::DomainTypeID::SocketPackageDomain );
1213-
entry.socket_unique_core_id = extract_bits_ui( apic_id, d1.levelShift, d2.levelShift - 1 );
1213+
entry.socket_unique_core_id = extract_bits_32( apic_id, d1.levelShift, d2.levelShift - 1 );
12141214
}
12151215
else
12161216
{
@@ -1233,8 +1233,8 @@ bool PCM::discoverSystemTopology()
12331233
(void)core;
12341234
return false;
12351235
#endif
1236-
entry.native_cpu_model = extract_bits_ui(cpuid_args.reg.eax, 0, 23);
1237-
entry.core_type = (TopologyEntry::CoreType) extract_bits_ui(cpuid_args.reg.eax, 24, 31);
1236+
entry.native_cpu_model = extract_bits_32(cpuid_args.reg.eax, 0, 23);
1237+
entry.core_type = (TopologyEntry::CoreType) extract_bits_32(cpuid_args.reg.eax, 24, 31);
12381238
return true;
12391239
};
12401240

@@ -1654,7 +1654,7 @@ bool PCM::detectNominalFrequency()
16541654
{
16551655
PCM_CPUID_INFO cpuinfo;
16561656
pcm_cpuid(0x16, cpuinfo);
1657-
nominal_frequency = uint64(extract_bits_ui(cpuinfo.reg.eax, 0, 15)) * 1000000ULL;;
1657+
nominal_frequency = uint64(extract_bits_32(cpuinfo.reg.eax, 0, 15)) * 1000000ULL;;
16581658
}
16591659
if (!nominal_frequency)
16601660
{
@@ -6224,7 +6224,7 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile
62246224
const auto pcicfgOffset = extract_bits(membarBits, 0, 15);
62256225
uint32 memBarOffset = 0;
62266226
pciHandle.read32(pcicfgOffset, &memBarOffset);
6227-
return size_t(extract_bits_ui(memBarOffset, srcPos, srcPos + numBits - 1)) << destPos;
6227+
return size_t(extract_bits_32(memBarOffset, srcPos, srcPos + numBits - 1)) << destPos;
62286228
}
62296229
return 0;
62306230
};
@@ -6686,7 +6686,7 @@ void PCM::readPCICFGRegisters(SystemCounterState& systemState)
66866686
{
66876687
case 16:
66886688
h->read32(offset, &value32);
6689-
value = (uint64)extract_bits_ui(value32, 0, 15);
6689+
value = (uint64)extract_bits_32(value32, 0, 15);
66906690
break;
66916691
case 32:
66926692
h->read32(offset, &value32);
@@ -6756,7 +6756,7 @@ void PCM::readMMIORegisters(SystemCounterState& systemState)
67566756
{
67576757
case 16:
67586758
value32 = h->read32(offset);
6759-
value = (uint64)extract_bits_ui(value32, 0, 15);
6759+
value = (uint64)extract_bits_32(value32, 0, 15);
67606760
break;
67616761
case 32:
67626762
value32 = h->read32(offset);
@@ -9867,7 +9867,7 @@ uint64 ServerUncorePMUs::computeQPISpeed(const uint32 core_nr, const int cpufami
98679867
uint32 value = 0;
98689868
if (reg.read32(UPI_SPEED_REGISTER_OFFSET, &value) == sizeof(uint32))
98699869
{
9870-
const size_t speedMT = UPISpeedMap[extract_bits_ui(value, regBits.first, regBits.second)];
9870+
const size_t speedMT = UPISpeedMap[extract_bits_32(value, regBits.first, regBits.second)];
98719871
if (false)
98729872
{
98739873
std::cerr << "speedMT: " << speedMT << "\n";
@@ -10575,11 +10575,11 @@ void PCM::programIDXAccelCounters(uint32 accel, std::vector<uint64_t> &events, s
1057510575
*ctrl_reg = 0x0;
1057610576
}
1057710577

10578-
*filter_wq_reg = extract_bits_ui(filters_wq.at(i), 0, 15);
10579-
*filter_eng_reg = extract_bits_ui(filters_eng.at(i), 0, 15);
10580-
*filter_tc_reg = extract_bits_ui(filters_tc.at(i), 0, 7);
10581-
*filter_pgsz_reg = extract_bits_ui(filters_pgsz.at(i), 0, 7);
10582-
*filter_xfersz_reg = extract_bits_ui(filters_xfersz.at(i), 0, 7);
10578+
*filter_wq_reg = extract_bits_32(filters_wq.at(i), 0, 15);
10579+
*filter_eng_reg = extract_bits_32(filters_eng.at(i), 0, 15);
10580+
*filter_tc_reg = extract_bits_32(filters_tc.at(i), 0, 7);
10581+
*filter_pgsz_reg = extract_bits_32(filters_pgsz.at(i), 0, 7);
10582+
*filter_xfersz_reg = extract_bits_32(filters_xfersz.at(i), 0, 7);
1058310583

1058410584
if (pmu.getPERFMode() == false)
1058510585
{

src/pcm-lspci.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ int mainThrows(int /*argc*/, char * /*argv*/[])
124124
PciHandleType h(0, bus, device, function);
125125
uint32 value = 0;
126126
h.read32(0, &value);
127-
const uint32 vendor = extract_bits_ui(value, 0, 15);
128-
const uint32 deviceID = extract_bits_ui(value, 16, 31);
127+
const uint32 vendor = extract_bits_32(value, 0, 15);
128+
const uint32 deviceID = extract_bits_32(value, 16, 31);
129129
std::cout << "0:" << bus << ":" << device << ":" << function << " vendor 0x" << std::hex << vendor << " device 0x" << deviceID << std::dec << "\n";
130130
}
131131
}

src/topologyentry.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ struct PCM_API TopologyEntry // describes a core
9696

9797
inline void fillEntry(TopologyEntry & entry, const uint32 & smtMaskWidth, const uint32 & coreMaskWidth, const uint32 & l2CacheMaskShift, const int apic_id)
9898
{
99-
entry.thread_id = smtMaskWidth ? extract_bits_ui(apic_id, 0, smtMaskWidth - 1) : 0;
100-
entry.core_id = (smtMaskWidth + coreMaskWidth) ? extract_bits_ui(apic_id, smtMaskWidth, smtMaskWidth + coreMaskWidth - 1) : 0;
101-
entry.socket_id = extract_bits_ui(apic_id, smtMaskWidth + coreMaskWidth, 31);
102-
entry.tile_id = extract_bits_ui(apic_id, l2CacheMaskShift, 31);
99+
entry.thread_id = smtMaskWidth ? extract_bits_32(apic_id, 0, smtMaskWidth - 1) : 0;
100+
entry.core_id = (smtMaskWidth + coreMaskWidth) ? extract_bits_32(apic_id, smtMaskWidth, smtMaskWidth + coreMaskWidth - 1) : 0;
101+
entry.socket_id = extract_bits_32(apic_id, smtMaskWidth + coreMaskWidth, 31);
102+
entry.tile_id = extract_bits_32(apic_id, l2CacheMaskShift, 31);
103103
entry.socket_unique_core_id = entry.core_id;
104104
}
105105

@@ -121,8 +121,8 @@ inline bool initCoreMasks(uint32 & smtMaskWidth, uint32 & coreMaskWidth, uint32
121121
{ // if EBX ==0 then this subleaf is not valid, we can exit the loop
122122
break;
123123
}
124-
levelType = extract_bits_ui(cpuid_args.array[2], 8, 15);
125-
levelShift = extract_bits_ui(cpuid_args.array[0], 0, 4);
124+
levelType = extract_bits_32(cpuid_args.array[2], 8, 15);
125+
levelShift = extract_bits_32(cpuid_args.array[0], 0, 4);
126126
switch (levelType)
127127
{
128128
case 1: //level type is SMT, so levelShift is the SMT_Mask_Width
@@ -160,7 +160,7 @@ inline bool initCoreMasks(uint32 & smtMaskWidth, uint32 & coreMaskWidth, uint32
160160
uint32 l2CacheMaskWidth;
161161

162162
pcm_cpuid(0x4, 2, cpuid_args); // get ID for L2 cache
163-
l2CacheMaskWidth = 1 + extract_bits_ui(cpuid_args.array[0],14,25); // number of APIC IDs sharing L2 cache
163+
l2CacheMaskWidth = 1 + extract_bits_32(cpuid_args.array[0],14,25); // number of APIC IDs sharing L2 cache
164164
#ifdef PCM_DEBUG_TOPOLOGY
165165
threadsSharingL2 = l2CacheMaskWidth;
166166
#endif

src/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ inline uint32 build_bit_ui(uint32 beg, uint32 end)
15811581
return myll;
15821582
}
15831583

1584-
inline uint32 extract_bits_ui(uint32 myin, uint32 beg, uint32 end)
1584+
inline uint32 extract_bits_32(uint32 myin, uint32 beg, uint32 end)
15851585
{
15861586
uint32 myll = 0;
15871587
uint32 beg1, end1;

0 commit comments

Comments
 (0)