From 93c4dfb39f7e94225123594ff4864f30c884f38b Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Thu, 21 Jun 2018 07:34:53 +0200 Subject: [PATCH] Integrate cpu_features library to extend system-info output with CPU details --- external/CMakeLists.txt | 1 + src/CMakeLists.txt | 2 ++ src/anbox/cmds/system_info.cpp | 43 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index f61af7d..9c10ff3 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -2,3 +2,4 @@ add_subdirectory(process-cpp-minimal) add_subdirectory(android-emugl) add_subdirectory(xdg) add_subdirectory(backtrace-cpp) +add_subdirectory(cpu_features) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 37518d1..a2d5b70 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,6 +30,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/external/android-emugl/host/libs/renderControl_dec ${CMAKE_BINARY_DIR}/external/android-emugl/host/libs/renderControl_dec ${CMAKE_SOURCE_DIR}/external/glm + ${CMAKE_SOURCE_DIR}/external/cpu_features/include ) protobuf_generate_cpp( @@ -247,6 +248,7 @@ target_link_libraries(anbox-core ${MIRCLIENT_LIBRARIES} ${LIBSYSTEMD_LDFLAGS} ${LIBSYSTEMD_LIBRARIES} + cpu_features pthread process-cpp emugl_common diff --git a/src/anbox/cmds/system_info.cpp b/src/anbox/cmds/system_info.cpp index 9b29a7b..e97815b 100644 --- a/src/anbox/cmds/system_info.cpp +++ b/src/anbox/cmds/system_info.cpp @@ -30,6 +30,9 @@ #include "OpenGLESDispatch/EGLDispatch.h" +#include "cpu_features_macros.h" +#include "cpuinfo_x86.h" + namespace fs = boost::filesystem; namespace { @@ -44,6 +47,7 @@ constexpr const char *os_release_version{"VERSION"}; class SystemInformation { public: SystemInformation() { + collect_cpu_info(); collect_os_info(); collect_kernel_info(); collect_graphics_info(); @@ -62,6 +66,13 @@ class SystemInformation { << std::endl; } + s << "cpu:" << std::endl + << " arch: " << cpu_info_.arch << std::endl + << " brand: " << cpu_info_.brand << std::endl + << " features: " << std::endl; + for (const auto& feature : cpu_info_.features) + s << " - " << feature << std::endl; + s << "os:" << std::endl << " name: " << os_info_.name << std::endl << " version: " << os_info_.version << std::endl @@ -101,6 +112,32 @@ class SystemInformation { } private: + void collect_cpu_info() { +#if defined(CPU_FEATURES_ARCH_X86) + cpu_info_.arch = "x86"; + + const auto info = cpu_features::GetX86Info(); + if (info.features.aes) + cpu_info_.features.push_back("aes"); + if (info.features.ssse3) + cpu_info_.features.push_back("ssse3"); + if (info.features.ssse3) + cpu_info_.features.push_back("sse4_1"); + if (info.features.sse4_1) + cpu_info_.features.push_back("sse4_2"); + if (info.features.sse4_2) + cpu_info_.features.push_back("avx"); + if (info.features.avx) + cpu_info_.features.push_back("ssse3"); + if (info.features.avx2) + cpu_info_.features.push_back("avx2"); + + char brand_string[49]; + cpu_features::FillX86BrandString(brand_string); + cpu_info_.brand = brand_string; +#endif + } + void collect_os_info() { os_info_.snap_based = !anbox::utils::get_env_value("SNAP").empty(); fs::path path = os_release_path; @@ -173,6 +210,12 @@ class SystemInformation { } } + struct { + std::string arch; + std::string brand; + std::vector features; + } cpu_info_; + struct { bool snap_based = false; std::string name = "n/a";