Skip to content

Commit 5352e7b

Browse files
committed
use reference type to prevent copying
Change-Id: I42822b6780b134c5036dc7fe43108eaef4c1b8d8
1 parent 3aefb46 commit 5352e7b

File tree

7 files changed

+46
-46
lines changed

7 files changed

+46
-46
lines changed

src/cpucounters.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ bool PCM::discoverSystemTopology()
14451445
}
14461446

14471447
// All threads are here now so we can set the refCore for a socket
1448-
for ( auto socket : systemTopology->sockets() )
1448+
for ( auto& socket : systemTopology->sockets() )
14491449
socket->setRefCore();
14501450

14511451
// use map to change apic socket id to the logical socket id
@@ -3484,7 +3484,7 @@ void PCM::enableForceRTMAbortMode(const bool silent)
34843484
{
34853485
if (isForceRTMAbortModeAvailable() && (core_gen_counter_num_max < 4))
34863486
{
3487-
for (auto m : MSR)
3487+
for (auto& m : MSR)
34883488
{
34893489
const auto res = m->write(MSR_TSX_FORCE_ABORT, 1);
34903490
if (res != sizeof(uint64))
@@ -3514,7 +3514,7 @@ void PCM::disableForceRTMAbortMode(const bool silent)
35143514
// std::cout << "disableForceRTMAbortMode(): forceRTMAbortMode=" << forceRTMAbortMode << "\n";
35153515
if (forceRTMAbortMode)
35163516
{
3517-
for (auto m : MSR)
3517+
for (auto& m : MSR)
35183518
{
35193519
const auto res = m->write(MSR_TSX_FORCE_ABORT, 0);
35203520
if (res != sizeof(uint64))
@@ -4607,7 +4607,7 @@ PCM::ErrorCode PCM::programServerUncorePowerMetrics(int mc_profile, int pcu_prof
46074607
std::cerr << "ERROR: unsupported PCU profile " << pcu_profile << "\n";
46084608
}
46094609

4610-
for (auto u : server_pcicfg_uncore)
4610+
for (auto& u : server_pcicfg_uncore)
46114611
{
46124612
u->program_power_metrics(mc_profile);
46134613
}
@@ -4710,7 +4710,7 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile
47104710
}
47114711
curPMUConfigs.erase("core");
47124712
}
4713-
for (auto pmuConfig : curPMUConfigs)
4713+
for (auto& pmuConfig : curPMUConfigs)
47144714
{
47154715
const auto & type = pmuConfig.first;
47164716
const auto & events = pmuConfig.second;
@@ -4732,28 +4732,28 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile
47324732
}
47334733
if (type == "m3upi")
47344734
{
4735-
for (auto uncore : server_pcicfg_uncore)
4735+
for (auto& uncore : server_pcicfg_uncore)
47364736
{
47374737
uncore->programM3UPI(events32);
47384738
}
47394739
}
47404740
else if (type == "xpi" || type == "upi" || type == "qpi")
47414741
{
4742-
for (auto uncore : server_pcicfg_uncore)
4742+
for (auto& uncore : server_pcicfg_uncore)
47434743
{
47444744
uncore->programXPI(events32);
47454745
}
47464746
}
47474747
else if (type == "imc")
47484748
{
4749-
for (auto uncore : server_pcicfg_uncore)
4749+
for (auto& uncore : server_pcicfg_uncore)
47504750
{
47514751
uncore->programIMC(events32);
47524752
}
47534753
}
47544754
else if (type == "m2m")
47554755
{
4756-
for (auto uncore : server_pcicfg_uncore)
4756+
for (auto& uncore : server_pcicfg_uncore)
47574757
{
47584758
uncore->programM2M(events64);
47594759
}
@@ -7344,7 +7344,7 @@ void ServerPCICFGUncore::initMemTest(ServerPCICFGUncore::MemTestParam & param)
73447344
if (result == NULL)
73457345
{
73467346
std::cerr << "ERROR: " << i << " VirtualAllocExNuma failed.\n";
7347-
for (auto b : memBuffers)
7347+
for (auto& b : memBuffers)
73487348
{
73497349
VirtualFree(b, memBufferBlockSize, MEM_RELEASE);
73507350
}
@@ -7359,7 +7359,7 @@ void ServerPCICFGUncore::initMemTest(ServerPCICFGUncore::MemTestParam & param)
73597359
#else
73607360
std::cerr << "ERROR: memory test is not implemented. QPI/UPI speed and utilization metrics may not be reliable.\n";
73617361
#endif
7362-
for (auto b : memBuffers)
7362+
for (auto& b : memBuffers)
73637363
std::fill(b, b + (memBufferBlockSize / sizeof(uint64)), 0ULL);
73647364
}
73657365

@@ -7368,7 +7368,7 @@ void ServerPCICFGUncore::doMemTest(const ServerPCICFGUncore::MemTestParam & para
73687368
const auto & memBufferBlockSize = param.first;
73697369
const auto & memBuffers = param.second;
73707370
// read and write each cache line once
7371-
for (auto b : memBuffers)
7371+
for (auto& b : memBuffers)
73727372
for (unsigned int i = 0; i < memBufferBlockSize / sizeof(uint64); i += 64 / sizeof(uint64))
73737373
{
73747374
(b[i])++;
@@ -7379,7 +7379,7 @@ void ServerPCICFGUncore::cleanupMemTest(const ServerPCICFGUncore::MemTestParam &
73797379
{
73807380
const auto & memBufferBlockSize = param.first;
73817381
const auto & memBuffers = param.second;
7382-
for (auto b : memBuffers)
7382+
for (auto& b : memBuffers)
73837383
{
73847384
#if defined(__linux__)
73857385
munmap(b, memBufferBlockSize);

src/pcm-iio.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ void print_PCIeMapping(const std::vector<struct iio_stacks_on_socket>& iios, con
10581058
for (auto & stack : it->stacks) {
10591059
printf("\t%s root bus: 0x%x", stack.stack_name.c_str(), stack.busno);
10601060
printf("\tflipped: %s\n", stack.flipped ? "true" : "false");
1061-
for (auto part : stack.parts) {
1061+
for (auto& part : stack.parts) {
10621062
vector<struct pci> pp = part.child_pci_devs;
10631063
uint8_t level = 1;
10641064
for (std::vector<struct pci>::const_iterator iunit = pp.begin(); iunit != pp.end(); ++iunit)
@@ -1078,7 +1078,7 @@ void print_PCIeMapping(const std::vector<struct iio_stacks_on_socket>& iios, con
10781078
bool check_argument_equals(const char* arg, std::initializer_list<const char*> arg_names)
10791079
{
10801080
const auto arg_len = strlen(arg);
1081-
for (const auto arg_name: arg_names) {
1081+
for (const auto& arg_name: arg_names) {
10821082
if (arg_len == strlen(arg_name) && strncmp(arg, arg_name, arg_len) == 0) {
10831083
return true;
10841084
}
@@ -1090,7 +1090,7 @@ bool check_argument_equals(const char* arg, std::initializer_list<const char*> a
10901090
bool extract_argument_value(const char* arg, std::initializer_list<const char*> arg_names, std::string& value)
10911091
{
10921092
const auto arg_len = strlen(arg);
1093-
for (const auto arg_name: arg_names) {
1093+
for (const auto& arg_name: arg_names) {
10941094
const auto arg_name_len = strlen(arg_name);
10951095
if (arg_len > arg_name_len && strncmp(arg, arg_name, arg_name_len) == 0 && arg[arg_name_len] == '=') {
10961096
value = arg + arg_name_len + 1;

src/pcm-raw.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ bool initPMUEventMap()
252252
return false;
253253
}
254254

255-
for (const auto evfile : eventFiles)
255+
for (const auto& evfile : eventFiles)
256256
{
257257
std::string path;
258258
auto printError = [&evfile]()
@@ -291,7 +291,7 @@ bool initPMUEventMap()
291291
if (EventName.empty())
292292
{
293293
cerr << "Did not find EventName in JSON object:\n";
294-
for (const auto keyValue : eventObj)
294+
for (const auto& keyValue : eventObj)
295295
{
296296
cout << "key: " << keyValue.key << " value: " << keyValue.value << "\n";
297297
}
@@ -722,7 +722,7 @@ bool addEventFromDB(PCM::RawPMUConfigs& curPMUConfigs, string fullEventStr)
722722
}
723723

724724
/*
725-
for (const auto keyValue : eventObj)
725+
for (const auto& keyValue : eventObj)
726726
{
727727
cout << keyValue.key << " : " << keyValue.value << "\n";
728728
}
@@ -932,7 +932,7 @@ void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<Cor
932932
cout << "\n";
933933
}
934934
uint32 i = 0;
935-
for (auto event : events)
935+
for (auto& event : events)
936936
{
937937
const std::string name = (event.second.empty()) ? (type + "Event" + std::to_string(i)) : event.second;
938938
printRowBegin(name, BeforeState[0], AfterState[0], m);
@@ -960,7 +960,7 @@ void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<Cor
960960
[](const CoreCounterState& before, const CoreCounterState& after) { return uint64(getBackendBound(before, after) * maxPerfMetricsValue); },
961961
[](const CoreCounterState& before, const CoreCounterState& after) { return uint64(getRetiring(before, after) * maxPerfMetricsValue); }
962962
};
963-
for (const auto event : fixedEvents)
963+
for (const auto& event : fixedEvents)
964964
{
965965
for (uint32 cnt = 0; cnt < 4; ++cnt)
966966
{
@@ -978,7 +978,7 @@ void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<Cor
978978
}
979979
}
980980
uint32 i = 0;
981-
for (const auto event : events)
981+
for (const auto& event : events)
982982
{
983983
const std::string name = (event.second.empty()) ? (type + "Event" + std::to_string(i)) : event.second;
984984
printRow(name, [&i](const CoreCounterState& before, const CoreCounterState& after) { return getNumberOfCustomEvents(i, before, after); }, BeforeState, AfterState, m);
@@ -1054,7 +1054,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
10541054
[]() { cout << "ms" << separator; },
10551055
[&]() { cout << (1000ULL * getInvariantTSC(BeforeState[0], AfterState[0])) / m->getNominalFrequency() << separator; });
10561056
}
1057-
for (auto typeEvents : curPMUConfigs)
1057+
for (auto& typeEvents : curPMUConfigs)
10581058
{
10591059
const auto & type = typeEvents.first;
10601060
const auto & events = typeEvents.second.programmable;
@@ -1078,7 +1078,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
10781078
uint64(getBackendBound(BeforeState[core], AfterState[core]) * maxPerfMetricsValue),
10791079
uint64(getRetiring(BeforeState[core], AfterState[core]) * maxPerfMetricsValue)
10801080
};
1081-
for (const auto event : fixedEvents)
1081+
for (const auto& event : fixedEvents)
10821082
{
10831083
auto print = [&](const std::string & metric, const uint64 value)
10841084
{
@@ -1103,7 +1103,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
11031103
}
11041104
}
11051105
int i = 0;
1106-
for (auto event : events)
1106+
for (auto& event : events)
11071107
{
11081108
choose(outputType,
11091109
[m, core]() { cout << "SKT" << m->getSocketId(core) << "CORE" << core << separator; },
@@ -1120,7 +1120,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
11201120
for (uint32 l = 0; l < m->getQPILinksPerSocket(); ++l)
11211121
{
11221122
int i = 0;
1123-
for (auto event : events)
1123+
for (auto& event : events)
11241124
{
11251125
choose(outputType,
11261126
[s, l]() { cout << "SKT" << s << "LINK" << l << separator; },
@@ -1138,7 +1138,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
11381138
for (uint32 l = 0; l < m->getQPILinksPerSocket(); ++l)
11391139
{
11401140
int i = 0;
1141-
for (auto event : events)
1141+
for (auto& event : events)
11421142
{
11431143
choose(outputType,
11441144
[s, l]() { cout << "SKT" << s << "LINK" << l << separator; },
@@ -1163,7 +1163,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
11631163
[&]() { cout << getDRAMClocks(ch, BeforeUncoreState[s], AfterUncoreState[s]) << separator; });
11641164
}
11651165
int i = 0;
1166-
for (auto event : events)
1166+
for (auto& event : events)
11671167
{
11681168
choose(outputType,
11691169
[s, ch]() { cout << "SKT" << s << "CHAN" << ch << separator; },
@@ -1181,7 +1181,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
11811181
for (uint32 mc = 0; mc < m->getMCPerSocket(); ++mc)
11821182
{
11831183
int i = 0;
1184-
for (auto event : events)
1184+
for (auto& event : events)
11851185
{
11861186
choose(outputType,
11871187
[s, mc]() { cout << "SKT" << s << "MC" << mc << separator; },
@@ -1197,7 +1197,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
11971197
for (uint32 s = 0; s < m->getNumSockets(); ++s)
11981198
{
11991199
int i = 0;
1200-
for (auto event : events)
1200+
for (auto& event : events)
12011201
{
12021202
choose(outputType,
12031203
[s]() { cout << "SKT" << s << separator; },
@@ -1219,7 +1219,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
12191219
[&]() { cout << getUncoreClocks(BeforeUncoreState[s], AfterUncoreState[s]) << separator; });
12201220
}
12211221
int i = 0;
1222-
for (auto event : events)
1222+
for (auto& event : events)
12231223
{
12241224
choose(outputType,
12251225
[s]() { cout << "SKT" << s << separator; },
@@ -1236,7 +1236,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
12361236
for (uint32 cbo = 0; cbo < m->getMaxNumOfCBoxes(); ++cbo)
12371237
{
12381238
int i = 0;
1239-
for (auto event : events)
1239+
for (auto& event : events)
12401240
{
12411241
choose(outputType,
12421242
[s, cbo]() { cout << "SKT" << s << "C" << cbo << separator; },
@@ -1254,7 +1254,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
12541254
for (uint32 stack = 0; stack < m->getMaxNumOfIIOStacks(); ++stack)
12551255
{
12561256
int i = 0;
1257-
for (auto event : events)
1257+
for (auto& event : events)
12581258
{
12591259
choose(outputType,
12601260
[s, stack]() { cout << "SKT" << s << "IRP" << stack << separator; },
@@ -1272,7 +1272,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, vector<CoreCounterSt
12721272
for (uint32 stack = 0; stack < m->getMaxNumOfIIOStacks(); ++stack)
12731273
{
12741274
int i = 0;
1275-
for (auto event : events)
1275+
for (auto& event : events)
12761276
{
12771277
choose(outputType,
12781278
[s, stack]() { cout << "SKT" << s << "IIO" << stack << separator; },
@@ -1502,7 +1502,7 @@ int main(int argc, char* argv[])
15021502
print_cpu_details();
15031503

15041504
size_t nGroups = 0;
1505-
for (const auto group : PMUConfigs)
1505+
for (const auto& group : PMUConfigs)
15061506
{
15071507
if (!group.empty()) ++nGroups;
15081508
}

src/pcm-sensor-server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2903,7 +2903,7 @@ enum MimeType matchSupportedWithAcceptedMimeTypes( HTTPHeader const& h ) {
29032903
// remove all whitespace from the item
29042904
copy.erase( std::remove_if( copy.begin(), copy.end(), isspace ), copy.end() );
29052905
// compare mimetype with supported ones
2906-
for ( auto mimetype : supportedOutputMimeTypes ) {
2906+
for ( auto& mimetype : supportedOutputMimeTypes ) {
29072907
auto str = mimetype.second;
29082908
str.erase( std::remove_if( str.begin(), str.end(), isspace ), str.end() );
29092909
DBG( 2, "Comparing mimetype '", copy, "' with known Mimetype '", str, "'" );

src/resctrl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ namespace pcm
109109
{
110110
auto files = fileMap[core];
111111
size_t result = 0;
112-
for (auto f : files)
112+
for (auto& f : files)
113113
{
114114
const auto data = readSysFS(f.c_str(), false);
115115
if (data.empty() == false)

src/topology.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ SocketCounterState Socket::socketCounterState( void ) const {
6262
SocketCounterState scs;
6363
// Fill the scs
6464
// by iterating the cores
65-
for( auto core : cores_ ) {
65+
for( auto& core : cores_ ) {
6666
scs.BasicCounterState::operator += ( core->coreCounterState() );
6767
}
6868
// and the uncore

0 commit comments

Comments
 (0)