Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:45

0001 #include <string>
0002 #include <boost/predef/os.h>
0003 
0004 #if BOOST_OS_LINUX
0005 // Linux
0006 #include <fstream>
0007 #include <regex>
0008 #endif  // BOOST_OS_LINUX
0009 
0010 #if BOOST_OS_BSD || BOOST_OS_MACOS
0011 // OSX or BSD
0012 #include <sys/types.h>
0013 #include <sys/sysctl.h>
0014 #endif  // BOOST_OS_BSD || BOOST_OS_MACOS
0015 
0016 #include "HLTrigger/Timer/interface/processor_model.h"
0017 
0018 std::string read_processor_model() {
0019   std::string result = "unknown";
0020 
0021 #if BOOST_OS_LINUX
0022   // on Linux, read the processor model from /proc/cpuinfo,
0023   // and check the status of SMT from /sys/devices/system/cpu/smt/active
0024   static const std::regex pattern("^model name\\s*:\\s*(.*)", std::regex::optimize);
0025   std::smatch match;
0026 
0027   std::ifstream cpuinfo("/proc/cpuinfo", std::ios::in);
0028   std::string line;
0029   while (cpuinfo.good()) {
0030     std::getline(cpuinfo, line);
0031     if (std::regex_match(line, match, pattern)) {
0032       result = match[1];
0033       break;
0034     }
0035   }
0036 
0037   std::ifstream smtinfo("/sys/devices/system/cpu/smt/active", std::ios::in);
0038   if (smtinfo) {
0039     int status;
0040     smtinfo >> status;
0041     result += status ? " with SMT enabled" : " with SMT disabled";
0042   }
0043 #endif  // BOOST_OS_LINUX
0044 
0045 #if BOOST_OS_BSD || BOOST_OS_MACOS
0046   // on BSD and OS X, read the processor  model via sysctlbyname("machdep.cpu.brand_string", ...)
0047   std::string result;
0048   size_t len;
0049   sysctlbyname("machdep.cpu.brand_string", nullptr, &len, NULL, 0);
0050   result.resize(len);
0051   sysctlbyname("machdep.cpu.brand_string", result.data(), &len, NULL, 0);
0052 #endif  // BOOST_OS_BSD || BOOST_OS_MACOS
0053 
0054   return result;
0055 }
0056 
0057 const std::string processor_model = read_processor_model();