@@ -96,6 +96,45 @@ cpu_topology init_cpu_topology() {
9696
9797static 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+
99138std::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
126167std::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
194235std::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
198239std::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
202243std::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