mirror of
https://github.com/dart-lang/sdk
synced 2024-10-03 00:29:50 +00:00
[vm/cpuid] Add trace_cpuid flag to troubleshoot cpu feature detection.
BUG=https://github.com/flutter/flutter/issues/140138 TEST=manually Change-Id: I7beaee3901d9e530aa3edf350f37b919eea01d3e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357662 Commit-Queue: Alexander Aprelev <aam@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
parent
e7a109c875
commit
70acceb4ca
|
@ -5,6 +5,8 @@
|
|||
#include "vm/globals.h"
|
||||
#if !defined(DART_HOST_OS_MACOS)
|
||||
#include "vm/cpuid.h"
|
||||
#include "vm/flags.h"
|
||||
#include "vm/os.h"
|
||||
|
||||
#if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
|
||||
// GetCpuId() on Windows, __get_cpuid() on Linux
|
||||
|
@ -17,6 +19,8 @@
|
|||
|
||||
namespace dart {
|
||||
|
||||
DEFINE_FLAG(bool, trace_cpuid, false, "Trace CPU ID discovery")
|
||||
|
||||
bool CpuId::sse2_ = false;
|
||||
bool CpuId::sse41_ = false;
|
||||
bool CpuId::popcnt_ = false;
|
||||
|
@ -41,6 +45,12 @@ void CpuId::Init() {
|
|||
uint32_t info[4] = {static_cast<uint32_t>(-1)};
|
||||
|
||||
GetCpuId(0, info);
|
||||
if (FLAG_trace_cpuid) {
|
||||
for (intptr_t i = 0; i < 3; i++) {
|
||||
OS::PrintErr("cpuid(0) info[%" Pd "]: %0x\n", i, info[i]);
|
||||
}
|
||||
}
|
||||
|
||||
char* id_string = reinterpret_cast<char*>(malloc(3 * sizeof(int32_t)));
|
||||
|
||||
// Yes, these are supposed to be out of order.
|
||||
|
@ -48,13 +58,31 @@ void CpuId::Init() {
|
|||
*reinterpret_cast<uint32_t*>(id_string + 4) = info[3];
|
||||
*reinterpret_cast<uint32_t*>(id_string + 8) = info[2];
|
||||
CpuId::id_string_ = id_string;
|
||||
if (FLAG_trace_cpuid) {
|
||||
OS::PrintErr("id_string: %s\n", id_string);
|
||||
}
|
||||
|
||||
GetCpuId(1, info);
|
||||
if (FLAG_trace_cpuid) {
|
||||
for (intptr_t i = 0; i < 3; i++) {
|
||||
OS::PrintErr("cpuid(1) info[%" Pd "]: %0x\n", i, info[i]);
|
||||
}
|
||||
}
|
||||
CpuId::sse41_ = (info[2] & (1 << 19)) != 0;
|
||||
CpuId::sse2_ = (info[3] & (1 << 26)) != 0;
|
||||
CpuId::popcnt_ = (info[2] & (1 << 23)) != 0;
|
||||
if (FLAG_trace_cpuid) {
|
||||
OS::PrintErr("sse41? %s sse2? %s popcnt? %s\n",
|
||||
CpuId::sse41_ ? "yes" : "no", CpuId::sse2_ ? "yes" : "no",
|
||||
CpuId::popcnt_ ? "yes" : "no");
|
||||
}
|
||||
|
||||
GetCpuId(0x80000001, info);
|
||||
if (FLAG_trace_cpuid) {
|
||||
for (intptr_t i = 0; i < 3; i++) {
|
||||
OS::PrintErr("cpuid(0x80000001) info[%" Pd "]: %0x\n", i, info[i]);
|
||||
}
|
||||
}
|
||||
CpuId::abm_ = (info[2] & (1 << 5)) != 0;
|
||||
|
||||
// Brand string returned by CPUID is expected to be nullptr-terminated,
|
||||
|
@ -66,9 +94,18 @@ void CpuId::Init() {
|
|||
char* brand_string = reinterpret_cast<char*>(calloc(3 * sizeof(info) + 1, 1));
|
||||
for (uint32_t i = 0; i < 2; i++) {
|
||||
GetCpuId(0x80000002U + i, info);
|
||||
if (FLAG_trace_cpuid) {
|
||||
for (intptr_t j = 0; j < 3; j++) {
|
||||
OS::PrintErr("cpuid(0x80000002U + %u) info[%" Pd "]: %0x\n", i, j,
|
||||
info[j]);
|
||||
}
|
||||
}
|
||||
memmove(&brand_string[i * sizeof(info)], &info, sizeof(info));
|
||||
}
|
||||
CpuId::brand_string_ = brand_string;
|
||||
if (FLAG_trace_cpuid) {
|
||||
OS::PrintErr("brand_string: %s\n", brand_string_);
|
||||
}
|
||||
}
|
||||
|
||||
void CpuId::Cleanup() {
|
||||
|
|
Loading…
Reference in a new issue