Commit 467157ed authored by Paul Schütze's avatar Paul Schütze
Browse files

Merge branch 'backport_cpuinfo' into 'v2.2-stable'

[v2.2-stable] allpix exec: add CPU id info

See merge request allpix-squared/allpix-squared!708
parents 09ddf966 a0bc472e
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
 */

#include <atomic>
#include <cpuid.h>
#include <csignal>
#include <cstdlib>
#include <fstream>
@@ -121,8 +122,28 @@ int main(int argc, const char* argv[]) {
                      << std::endl;
            std::cout << "                     ROOT " << ROOT_RELEASE << std::endl;
#ifdef ALLPIX_GEANT4_AVAILABLE
            std::cout << "                     Geant4 " << G4VERSION_NUMBER << std::endl;
            std::cout << "                     Geant4 " << G4VERSION_NUMBER / 100 << "." << G4VERSION_NUMBER / 10 % 10 << "."
                      << G4VERSION_NUMBER % 10 << std::endl;
#endif

            std::array<char, 0x40> cpu_string;
            std::array<unsigned int, 4> cpu_info = {0, 0, 0, 0};
            __cpuid(0x80000000, cpu_info[0], cpu_info[1], cpu_info[2], cpu_info[3]);
            unsigned int n_ex_ids = cpu_info[0];
            memset(cpu_string.data(), 0, sizeof(cpu_string));
            for(unsigned int j = 0x80000000; j <= n_ex_ids; ++j) {
                __cpuid(j, cpu_info[0], cpu_info[1], cpu_info[2], cpu_info[3]);
                if(j == 0x80000002) {
                    memcpy(cpu_string.data(), cpu_info.data(), sizeof(cpu_info));
                } else if(j == 0x80000003) {
                    memcpy(cpu_string.data() + 16, cpu_info.data(), sizeof(cpu_info));
                } else if(j == 0x80000004) {
                    memcpy(cpu_string.data() + 32, cpu_info.data(), sizeof(cpu_info));
                }
            }
            std::cout << "               running on " << std::thread::hardware_concurrency() << "x " << cpu_string.data()
                      << std::endl;

            std::cout << std::endl;
            std::cout << "Copyright (c) 2017-2021 CERN and the Allpix Squared authors." << std::endl << std::endl;
            std::cout << "This software is distributed under the terms of the MIT License." << std::endl;