Skip to content

Commit

Permalink
Include information about SMT in the processor model
Browse files Browse the repository at this point in the history
Include whether Simultaneous Multi Threading (SMT) is enabled or
disabled after the processor model name.
  • Loading branch information
fwyzard committed Nov 14, 2022
1 parent 9c0c506 commit 7f53327
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions HLTrigger/Timer/src/processor_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#include "HLTrigger/Timer/interface/processor_model.h"

std::string read_processor_model() {
std::string result = "unknown";

#if BOOST_OS_LINUX
// on Linux, read the processor model from /proc/cpuinfo
// on Linux, read the processor model from /proc/cpuinfo,
// and check the status of SMT from /sys/devices/system/cpu/smt/active
static const std::regex pattern("^model name\\s*:\\s*(.*)", std::regex::optimize);
std::smatch match;

Expand All @@ -26,9 +29,17 @@ std::string read_processor_model() {
while (cpuinfo.good()) {
std::getline(cpuinfo, line);
if (std::regex_match(line, match, pattern)) {
return match[1];
result = match[1];
break;
}
}

std::ifstream smtinfo("/sys/devices/system/cpu/smt/active", std::ios::in);
if (smtinfo) {
int status;
smtinfo >> status;
result += status ? " with SMT enabled" : " with SMT disabled";
}
#endif // BOOST_OS_LINUX

#if BOOST_OS_BSD || BOOST_OS_MACOS
Expand All @@ -38,10 +49,9 @@ std::string read_processor_model() {
sysctlbyname("machdep.cpu.brand_string", nullptr, &len, NULL, 0);
result.resize(len);
sysctlbyname("machdep.cpu.brand_string", result.data(), &len, NULL, 0);
return result;
#endif // BOOST_OS_BSD || BOOST_OS_MACOS

return "unknown";
return result;
}

const std::string processor_model = read_processor_model();

0 comments on commit 7f53327

Please sign in to comment.