Skip to content

Commit

Permalink
Clean up HWTopoLinux code for style.
Browse files Browse the repository at this point in the history
I was already editing it, so it seemed like a good idea.
  • Loading branch information
arthurp committed Apr 29, 2021
1 parent f76f21f commit eaa52df
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions libgalois/src/HWTopoLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ struct cpuinfo {

bool
operator<(const cpuinfo& lhs, const cpuinfo& rhs) {
if (lhs.smt != rhs.smt)
if (lhs.smt != rhs.smt) {
return lhs.smt < rhs.smt;
if (lhs.physid != rhs.physid)
}
if (lhs.physid != rhs.physid) {
return lhs.physid < rhs.physid;
if (lhs.coreid != rhs.coreid)
}
if (lhs.coreid != rhs.coreid) {
return lhs.coreid < rhs.coreid;
}
return lhs.proc < rhs.proc;
}

Expand All @@ -89,32 +92,35 @@ LoadLibNuma() {
#endif

unsigned
getNumaNode(cpuinfo& c) {
static bool warnOnce = false;
getNumaNode(const cpuinfo& c) {
static bool warn_once = false;
#ifdef KATANA_USE_NUMA
static bool numaAvail = false;
static bool numa_avail = false;

if (!warnOnce) {
warnOnce = true;
if (!warn_once) {
warn_once = true;
LoadLibNuma();
numaAvail = dynamic_numa_available && dynamic_numa_available() >= 0;
numaAvail = numaAvail && dynamic_numa_num_configured_nodes() > 0;
if (!numaAvail)
katana::gWarn(
numa_avail = dynamic_numa_available && dynamic_numa_available() >= 0;
numa_avail = numa_avail && dynamic_numa_num_configured_nodes() > 0;
if (!numa_avail) {
KATANA_LOG_WARN(
"Numa support configured but not present at runtime. "
"Assuming numa topology matches socket topology.");
}
}

if (!numaAvail)
if (!numa_avail) {
return c.physid;
}
int i = dynamic_numa_node_of_cpu(c.proc);
if (i < 0)
KATANA_SYS_DIE("failed finding numa node for ", c.proc);
if (i < 0) {
KATANA_LOG_FATAL("failed finding numa node for {}", c.proc);
}
return i;
#else
if (!warnOnce) {
warnOnce = true;
katana::gWarn(
if (!warn_once) {
warn_once = true;
KATANA_LOG_WARN(
"Numa Support Not configured (install libnuma-dev). "
"Assuming numa topology matches socket topology.");
}
Expand Down Expand Up @@ -164,35 +170,40 @@ parseCPUInfo() {
unsigned
countSockets(const std::vector<cpuinfo>& info) {
std::set<unsigned> pkgs;
for (auto& c : info)
for (auto& c : info) {
pkgs.insert(c.physid);
}
return pkgs.size();
}

unsigned
countCores(const std::vector<cpuinfo>& info) {
std::set<std::pair<int, int>> cores;
for (auto& c : info)
for (auto& c : info) {
cores.insert(std::make_pair(c.physid, c.coreid));
}
return cores.size();
}

unsigned
countNumaNodes(const std::vector<cpuinfo>& info) {
std::set<unsigned> nodes;
for (auto& c : info)
for (auto& c : info) {
nodes.insert(c.numaNode);
}
return nodes.size();
}

void
markSMT(std::vector<cpuinfo>& info) {
for (unsigned int i = 1; i < info.size(); ++i)
for (unsigned int i = 1; i < info.size(); ++i) {
if (info[i - 1].physid == info[i].physid &&
info[i - 1].coreid == info[i].coreid)
info[i - 1].coreid == info[i].coreid) {
info[i].smt = true;
else
} else {
info[i].smt = false;
}
}
}

std::vector<int>
Expand Down Expand Up @@ -233,12 +244,14 @@ void
markValid(std::vector<cpuinfo>& info) {
auto v = parseCPUSet();
if (v.empty()) {
for (auto& c : info)
for (auto& c : info) {
c.valid = true;
}
} else {
std::sort(v.begin(), v.end());
for (auto& c : info)
for (auto& c : info) {
c.valid = std::binary_search(v.begin(), v.end(), c.proc);
}
}
}

Expand Down

0 comments on commit eaa52df

Please sign in to comment.