Skip to content

Commit b53a630

Browse files
committed
CPU Name detection on GH200, rename 'Error' to 'Unknown'
Signed-off-by: Adrien Taberner <adrien.taberner@cea.fr>
1 parent 11c08ab commit b53a630

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

archInfo/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ write_basic_package_version_file(
2626
)
2727

2828
configure_package_config_file(
29-
"${CMAKE_CURREN_SOURCE_DIR}/cmake/CexaArchInfoConfig.cmake.in"
29+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CexaArchInfoConfig.cmake.in"
3030
"${CMAKE_CURRENT_BINARY_DIR}/CexaArchInfoConfig.cmake"
3131
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CexaArchInfo"
3232
)

archInfo/src/cexa_unixArchInfo.hpp

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,45 @@ cpu_topology init_cpu_topology() {
9696

9797
static cpu_topology topology = init_cpu_topology();
9898

99+
#if defined(__aarch64__)
100+
101+
std::optional<std::string> read_cpu_model_lscpu() {
102+
static const char* model_name_key = "Model name";
103+
104+
// "lscpu --parse=MODELNAME" Not available on GH200
105+
FILE* f = popen(" lscpu | head -n 32 2>/dev/null", "r");
106+
if (!f) {
107+
return std::nullopt;
108+
}
109+
110+
// We don't expect cpu model names to be longer that 1024 characters
111+
char buffer[1024];
112+
char* pos = nullptr;
113+
114+
while (pos == nullptr) {
115+
if (!std::fgets(buffer, 1024, f)) {
116+
return std::nullopt;
117+
}
118+
pos = std::strstr(buffer, model_name_key);
119+
}
120+
121+
// Skip key and whitespace
122+
pos += std::strlen(model_name_key) + 1;
123+
while (std::isspace(*pos)) {
124+
pos++;
125+
}
126+
127+
pclose(f);
128+
129+
std::string model_name(pos);
130+
if (model_name.back() == '\n') {
131+
model_name.pop_back();
132+
}
133+
return model_name;
134+
}
135+
136+
#else // x86_64
137+
99138
std::optional<std::string> read_cpu_model_lscpu() {
100139
FILE* f = popen("lscpu --parse=MODELNAME 2>/dev/null", "r");
101140
if (!f) {
@@ -122,6 +161,8 @@ std::optional<std::string> read_cpu_model_lscpu() {
122161
return model_name;
123162
}
124163

164+
#endif
165+
125166
// Extract a value from /proc/cpuinfo
126167
std::optional<std::string> get_cpu_info_str(const char* key) {
127168
std::ifstream cpu_info("/proc/cpuinfo");
@@ -187,20 +228,20 @@ std::string get_cpu_model_name() {
187228
if (cpu_model.has_value()) {
188229
return cpu_model.value();
189230
} else {
190-
return get_cpu_info_str("model name").value_or("ERROR");
231+
return get_cpu_info_str("model name").value_or("Unknown");
191232
}
192233
}
193234

194235
std::string get_sys_name() {
195-
return get_os_release_str("PRETTY_NAME").value_or("ERROR");
236+
return get_os_release_str("PRETTY_NAME").value_or("Unknown");
196237
}
197238

198239
std::string get_sys_type() {
199-
return get_proc_sys_value("kernel/ostype").value_or("ERROR");
240+
return get_proc_sys_value("kernel/ostype").value_or("Unknown");
200241
}
201242

202243
std::string get_kernel_version() {
203-
return get_proc_sys_value("kernel/osrelease").value_or("ERROR");
244+
return get_proc_sys_value("kernel/osrelease").value_or("Unknown");
204245
}
205246

206247
} // namespace cexa::impl

0 commit comments

Comments
 (0)