jdk
106 строк · 3.8 Кб
1/*
2* Copyright (c) 2020, 2021, Microsoft Corporation. All rights reserved.
3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*
5* This code is free software; you can redistribute it and/or modify it
6* under the terms of the GNU General Public License version 2 only, as
7* published by the Free Software Foundation.
8*
9* This code is distributed in the hope that it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12* version 2 for more details (a copy is included in the LICENSE file that
13* accompanied this code).
14*
15* You should have received a copy of the GNU General Public License version
16* 2 along with this work; if not, write to the Free Software Foundation,
17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18*
19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20* or visit www.oracle.com if you need additional information or have any
21* questions.
22*
23*/
24
25#include "precompiled.hpp"
26#include "logging/log.hpp"
27#include "runtime/os.hpp"
28#include "runtime/vm_version.hpp"
29
30int VM_Version::get_current_sve_vector_length() {
31assert(_features & CPU_SVE, "should not call this");
32ShouldNotReachHere();
33return 0;
34}
35
36int VM_Version::set_and_get_current_sve_vector_length(int length) {
37assert(_features & CPU_SVE, "should not call this");
38ShouldNotReachHere();
39return 0;
40}
41
42void VM_Version::get_os_cpu_info() {
43
44if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE)) _features |= CPU_CRC32;
45if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) _features |= CPU_AES | CPU_SHA1 | CPU_SHA2;
46if (IsProcessorFeaturePresent(PF_ARM_VFP_32_REGISTERS_AVAILABLE)) _features |= CPU_ASIMD;
47// No check for CPU_PMULL, CPU_SVE, CPU_SVE2
48
49__int64 dczid_el0 = _ReadStatusReg(0x5807 /* ARM64_DCZID_EL0 */);
50
51if (!(dczid_el0 & 0x10)) {
52_zva_length = 4 << (dczid_el0 & 0xf);
53}
54
55{
56PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = nullptr;
57DWORD returnLength = 0;
58
59// See https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getlogicalprocessorinformation
60GetLogicalProcessorInformation(nullptr, &returnLength);
61assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected return from GetLogicalProcessorInformation");
62
63buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)os::malloc(returnLength, mtInternal);
64BOOL rc = GetLogicalProcessorInformation(buffer, &returnLength);
65assert(rc, "Unexpected return from GetLogicalProcessorInformation");
66
67_icache_line_size = _dcache_line_size = -1;
68for (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = buffer; ptr < buffer + returnLength / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); ptr++) {
69switch (ptr->Relationship) {
70case RelationCache:
71// Cache data is in ptr->Cache, one CACHE_DESCRIPTOR structure for each cache.
72PCACHE_DESCRIPTOR Cache = &ptr->Cache;
73if (Cache->Level == 1) {
74_icache_line_size = _dcache_line_size = Cache->LineSize;
75}
76break;
77}
78}
79os::free(buffer);
80}
81
82{
83char* buf = ::getenv("PROCESSOR_IDENTIFIER");
84if (buf && strstr(buf, "Ampere(TM)") != nullptr) {
85_cpu = CPU_AMCC;
86} else if (buf && strstr(buf, "Cavium Inc.") != nullptr) {
87_cpu = CPU_CAVIUM;
88} else {
89log_info(os)("VM_Version: unknown CPU model");
90}
91
92if (_cpu) {
93SYSTEM_INFO si;
94GetSystemInfo(&si);
95_model = si.wProcessorLevel;
96_variant = si.wProcessorRevision / 0xFF;
97_revision = si.wProcessorRevision & 0xFF;
98}
99}
100}
101
102void VM_Version::get_compatible_board(char *buf, int buflen) {
103assert(buf != nullptr, "invalid argument");
104assert(buflen >= 1, "invalid argument");
105*buf = '\0';
106}
107