Exclude cpuid.h from Mac non x86 arch (#7166)

* add ifdef to exclude inclusion from non x86 arch

* exclude calling of __cpuid_count

Co-authored-by: Randy Shuai <rashuai@microsoft.com>
This commit is contained in:
RandySheriffH 2021-03-30 11:50:42 -07:00 committed by GitHub
parent 0ccfe6c86a
commit d880578537
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,7 +27,9 @@ limitations under the License.
#include <codecvt>
#include <locale>
#elif defined(__APPLE__)
#if defined(__x86_64__) || defined(__i386__)
#include <cpuid.h>
#endif
#else
#include <sched.h>
#endif
@ -122,11 +124,13 @@ void ThreadPoolProfiler::MainThreadStat::LogCore() {
#ifdef _WIN32
core_ = GetCurrentProcessorNumber();
#elif defined(__APPLE__)
#if defined(__x86_64__) || defined(__i386__)
uint32_t CPUInfo[4];
__cpuid_count(1, 0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
if ((CPUInfo[3] & (1 << 9)) != 0) {
core_ = (unsigned)CPUInfo[1] >> 24;
}
#endif
#else
core_ = sched_getcpu();
#endif
@ -200,11 +204,13 @@ void ThreadPoolProfiler::LogRun(int thread_idx) {
#ifdef _WIN32
child_thread_stats_[thread_idx].core_ = GetCurrentProcessorNumber();
#elif defined(__APPLE__)
#if defined(__x86_64__) || defined(__i386__)
uint32_t CPUInfo[4];
__cpuid_count(1, 0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
if ((CPUInfo[3] & (1 << 9)) != 0) {
child_thread_stats_[thread_idx].core_ = (unsigned)CPUInfo[1] >> 24;
}
#endif
#else
child_thread_stats_[thread_idx].core_ = sched_getcpu();
#endif