Skip to content

Commit ec9bee6

Browse files
AntonKozlovAndrew Haley
authored andcommitted
8253015: Aarch64: Move linux code out from generic CPU feature detection
Reviewed-by: aph
1 parent 16b8c39 commit ec9bee6

File tree

7 files changed

+220
-209
lines changed

7 files changed

+220
-209
lines changed

src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5266,7 +5266,7 @@ void MacroAssembler::cache_wb(Address line) {
52665266
assert(line.offset() == 0, "offset should be 0");
52675267
// would like to assert this
52685268
// assert(line._ext.shift == 0, "shift should be zero");
5269-
if (VM_Version::supports_dcpop()) {
5269+
if (VM_Version::features() & VM_Version::CPU_DCPOP) {
52705270
// writeback using clear virtual address to point of persistence
52715271
dc(Assembler::CVAP, line.base());
52725272
} else {

src/hotspot/cpu/aarch64/vm_version_aarch64.cpp

Lines changed: 34 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -24,124 +24,36 @@
2424
*/
2525

2626
#include "precompiled.hpp"
27-
#include "asm/macroAssembler.hpp"
28-
#include "asm/macroAssembler.inline.hpp"
29-
#include "memory/resourceArea.hpp"
3027
#include "runtime/arguments.hpp"
3128
#include "runtime/globals_extension.hpp"
3229
#include "runtime/java.hpp"
3330
#include "runtime/os.hpp"
34-
#include "runtime/stubCodeGenerator.hpp"
3531
#include "runtime/vm_version.hpp"
3632
#include "utilities/formatBuffer.hpp"
3733
#include "utilities/macros.hpp"
3834

3935
#include OS_HEADER_INLINE(os)
4036

41-
#include <asm/hwcap.h>
42-
#include <sys/auxv.h>
43-
#include <sys/prctl.h>
44-
45-
#ifndef HWCAP_AES
46-
#define HWCAP_AES (1<<3)
47-
#endif
48-
49-
#ifndef HWCAP_PMULL
50-
#define HWCAP_PMULL (1<<4)
51-
#endif
52-
53-
#ifndef HWCAP_SHA1
54-
#define HWCAP_SHA1 (1<<5)
55-
#endif
56-
57-
#ifndef HWCAP_SHA2
58-
#define HWCAP_SHA2 (1<<6)
59-
#endif
60-
61-
#ifndef HWCAP_CRC32
62-
#define HWCAP_CRC32 (1<<7)
63-
#endif
64-
65-
#ifndef HWCAP_ATOMICS
66-
#define HWCAP_ATOMICS (1<<8)
67-
#endif
68-
69-
#ifndef HWCAP_SHA512
70-
#define HWCAP_SHA512 (1 << 21)
71-
#endif
72-
73-
#ifndef HWCAP_SVE
74-
#define HWCAP_SVE (1 << 22)
75-
#endif
76-
77-
#ifndef HWCAP2_SVE2
78-
#define HWCAP2_SVE2 (1 << 1)
79-
#endif
80-
81-
#ifndef PR_SVE_GET_VL
82-
// For old toolchains which do not have SVE related macros defined.
83-
#define PR_SVE_SET_VL 50
84-
#define PR_SVE_GET_VL 51
85-
#endif
86-
8737
int VM_Version::_cpu;
8838
int VM_Version::_model;
8939
int VM_Version::_model2;
9040
int VM_Version::_variant;
9141
int VM_Version::_revision;
9242
int VM_Version::_stepping;
93-
bool VM_Version::_dcpop;
94-
int VM_Version::_initial_sve_vector_length;
95-
VM_Version::PsrInfo VM_Version::_psr_info = { 0, };
96-
97-
static BufferBlob* stub_blob;
98-
static const int stub_size = 550;
99-
100-
extern "C" {
101-
typedef void (*getPsrInfo_stub_t)(void*);
102-
}
103-
static getPsrInfo_stub_t getPsrInfo_stub = NULL;
104-
105-
106-
class VM_Version_StubGenerator: public StubCodeGenerator {
107-
public:
10843

109-
VM_Version_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
110-
111-
address generate_getPsrInfo() {
112-
StubCodeMark mark(this, "VM_Version", "getPsrInfo_stub");
113-
# define __ _masm->
114-
address start = __ pc();
115-
116-
// void getPsrInfo(VM_Version::PsrInfo* psr_info);
117-
118-
address entry = __ pc();
119-
120-
__ enter();
121-
122-
__ get_dczid_el0(rscratch1);
123-
__ strw(rscratch1, Address(c_rarg0, in_bytes(VM_Version::dczid_el0_offset())));
124-
125-
__ get_ctr_el0(rscratch1);
126-
__ strw(rscratch1, Address(c_rarg0, in_bytes(VM_Version::ctr_el0_offset())));
127-
128-
__ leave();
129-
__ ret(lr);
130-
131-
# undef __
132-
133-
return start;
134-
}
135-
};
44+
int VM_Version::_zva_length;
45+
int VM_Version::_dcache_line_size;
46+
int VM_Version::_icache_line_size;
47+
int VM_Version::_initial_sve_vector_length;
13648

137-
void VM_Version::get_processor_features() {
49+
void VM_Version::initialize() {
13850
_supports_cx8 = true;
13951
_supports_atomic_getset4 = true;
14052
_supports_atomic_getadd4 = true;
14153
_supports_atomic_getset8 = true;
14254
_supports_atomic_getadd8 = true;
14355

144-
getPsrInfo_stub(&_psr_info);
56+
get_os_cpu_info();
14557

14658
int dcache_line = VM_Version::dcache_line_size();
14759

@@ -183,45 +95,12 @@ void VM_Version::get_processor_features() {
18395
SoftwarePrefetchHintDistance &= ~7;
18496
}
18597

186-
uint64_t auxv = getauxval(AT_HWCAP);
187-
uint64_t auxv2 = getauxval(AT_HWCAP2);
188-
189-
char buf[512];
190-
191-
_features = auxv;
192-
193-
int cpu_lines = 0;
194-
if (FILE *f = fopen("/proc/cpuinfo", "r")) {
195-
// need a large buffer as the flags line may include lots of text
196-
char buf[1024], *p;
197-
while (fgets(buf, sizeof (buf), f) != NULL) {
198-
if ((p = strchr(buf, ':')) != NULL) {
199-
long v = strtol(p+1, NULL, 0);
200-
if (strncmp(buf, "CPU implementer", sizeof "CPU implementer" - 1) == 0) {
201-
_cpu = v;
202-
cpu_lines++;
203-
} else if (strncmp(buf, "CPU variant", sizeof "CPU variant" - 1) == 0) {
204-
_variant = v;
205-
} else if (strncmp(buf, "CPU part", sizeof "CPU part" - 1) == 0) {
206-
if (_model != v) _model2 = _model;
207-
_model = v;
208-
} else if (strncmp(buf, "CPU revision", sizeof "CPU revision" - 1) == 0) {
209-
_revision = v;
210-
} else if (strncmp(buf, "flags", sizeof("flags") - 1) == 0) {
211-
if (strstr(p+1, "dcpop")) {
212-
_dcpop = true;
213-
}
214-
}
215-
}
216-
}
217-
fclose(f);
218-
}
21998

22099
if (os::supports_map_sync()) {
221100
// if dcpop is available publish data cache line flush size via
222101
// generic field, otherwise let if default to zero thereby
223102
// disabling writeback
224-
if (_dcpop) {
103+
if (_features & CPU_DCPOP) {
225104
_data_cache_line_flush_size = dcache_line;
226105
}
227106
}
@@ -302,30 +181,31 @@ void VM_Version::get_processor_features() {
302181
}
303182

304183
if (_cpu == CPU_ARM && (_model == 0xd07 || _model2 == 0xd07)) _features |= CPU_STXR_PREFETCH;
305-
// If an olde style /proc/cpuinfo (cpu_lines == 1) then if _model is an A57 (0xd07)
184+
// If an olde style /proc/cpuinfo (cores == 1) then if _model is an A57 (0xd07)
306185
// we assume the worst and assume we could be on a big little system and have
307186
// undisclosed A53 cores which we could be swapped to at any stage
308-
if (_cpu == CPU_ARM && cpu_lines == 1 && _model == 0xd07) _features |= CPU_A53MAC;
187+
if (_cpu == CPU_ARM && os::processor_count() == 1 && _model == 0xd07) _features |= CPU_A53MAC;
309188

189+
char buf[512];
310190
sprintf(buf, "0x%02x:0x%x:0x%03x:%d", _cpu, _variant, _model, _revision);
311191
if (_model2) sprintf(buf+strlen(buf), "(0x%03x)", _model2);
312-
if (auxv & HWCAP_ASIMD) strcat(buf, ", simd");
313-
if (auxv & HWCAP_CRC32) strcat(buf, ", crc");
314-
if (auxv & HWCAP_AES) strcat(buf, ", aes");
315-
if (auxv & HWCAP_SHA1) strcat(buf, ", sha1");
316-
if (auxv & HWCAP_SHA2) strcat(buf, ", sha256");
317-
if (auxv & HWCAP_SHA512) strcat(buf, ", sha512");
318-
if (auxv & HWCAP_ATOMICS) strcat(buf, ", lse");
319-
if (auxv & HWCAP_SVE) strcat(buf, ", sve");
320-
if (auxv2 & HWCAP2_SVE2) strcat(buf, ", sve2");
192+
if (_features & CPU_ASIMD) strcat(buf, ", simd");
193+
if (_features & CPU_CRC32) strcat(buf, ", crc");
194+
if (_features & CPU_AES) strcat(buf, ", aes");
195+
if (_features & CPU_SHA1) strcat(buf, ", sha1");
196+
if (_features & CPU_SHA2) strcat(buf, ", sha256");
197+
if (_features & CPU_SHA512) strcat(buf, ", sha512");
198+
if (_features & CPU_LSE) strcat(buf, ", lse");
199+
if (_features & CPU_SVE) strcat(buf, ", sve");
200+
if (_features & CPU_SVE2) strcat(buf, ", sve2");
321201

322202
_features_string = os::strdup(buf);
323203

324204
if (FLAG_IS_DEFAULT(UseCRC32)) {
325-
UseCRC32 = (auxv & HWCAP_CRC32) != 0;
205+
UseCRC32 = (_features & CPU_CRC32) != 0;
326206
}
327207

328-
if (UseCRC32 && (auxv & HWCAP_CRC32) == 0) {
208+
if (UseCRC32 && (_features & CPU_CRC32) == 0) {
329209
warning("UseCRC32 specified, but not supported on this CPU");
330210
FLAG_SET_DEFAULT(UseCRC32, false);
331211
}
@@ -339,7 +219,7 @@ void VM_Version::get_processor_features() {
339219
FLAG_SET_DEFAULT(UseVectorizedMismatchIntrinsic, false);
340220
}
341221

342-
if (auxv & HWCAP_ATOMICS) {
222+
if (_features & CPU_LSE) {
343223
if (FLAG_IS_DEFAULT(UseLSE))
344224
FLAG_SET_DEFAULT(UseLSE, true);
345225
} else {
@@ -349,7 +229,7 @@ void VM_Version::get_processor_features() {
349229
}
350230
}
351231

352-
if (auxv & HWCAP_AES) {
232+
if (_features & CPU_AES) {
353233
UseAES = UseAES || FLAG_IS_DEFAULT(UseAES);
354234
UseAESIntrinsics =
355235
UseAESIntrinsics || (UseAES && FLAG_IS_DEFAULT(UseAESIntrinsics));
@@ -377,7 +257,7 @@ void VM_Version::get_processor_features() {
377257
UseCRC32Intrinsics = true;
378258
}
379259

380-
if (auxv & HWCAP_CRC32) {
260+
if (_features & CPU_CRC32) {
381261
if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) {
382262
FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true);
383263
}
@@ -395,7 +275,7 @@ void VM_Version::get_processor_features() {
395275
FLAG_SET_DEFAULT(UseMD5Intrinsics, false);
396276
}
397277

398-
if (auxv & (HWCAP_SHA1 | HWCAP_SHA2)) {
278+
if (_features & (CPU_SHA1 | CPU_SHA2)) {
399279
if (FLAG_IS_DEFAULT(UseSHA)) {
400280
FLAG_SET_DEFAULT(UseSHA, true);
401281
}
@@ -404,7 +284,7 @@ void VM_Version::get_processor_features() {
404284
FLAG_SET_DEFAULT(UseSHA, false);
405285
}
406286

407-
if (UseSHA && (auxv & HWCAP_SHA1)) {
287+
if (UseSHA && (_features & CPU_SHA1)) {
408288
if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) {
409289
FLAG_SET_DEFAULT(UseSHA1Intrinsics, true);
410290
}
@@ -413,7 +293,7 @@ void VM_Version::get_processor_features() {
413293
FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
414294
}
415295

416-
if (UseSHA && (auxv & HWCAP_SHA2)) {
296+
if (UseSHA && (_features & CPU_SHA2)) {
417297
if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) {
418298
FLAG_SET_DEFAULT(UseSHA256Intrinsics, true);
419299
}
@@ -422,7 +302,7 @@ void VM_Version::get_processor_features() {
422302
FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
423303
}
424304

425-
if (UseSHA && (auxv & HWCAP_SHA512)) {
305+
if (UseSHA && (_features & CPU_SHA512)) {
426306
// Do not auto-enable UseSHA512Intrinsics until it has been fully tested on hardware
427307
// if (FLAG_IS_DEFAULT(UseSHA512Intrinsics)) {
428308
// FLAG_SET_DEFAULT(UseSHA512Intrinsics, true);
@@ -436,7 +316,7 @@ void VM_Version::get_processor_features() {
436316
FLAG_SET_DEFAULT(UseSHA, false);
437317
}
438318

439-
if (auxv & HWCAP_PMULL) {
319+
if (_features & CPU_PMULL) {
440320
if (FLAG_IS_DEFAULT(UseGHASHIntrinsics)) {
441321
FLAG_SET_DEFAULT(UseGHASHIntrinsics, true);
442322
}
@@ -457,12 +337,12 @@ void VM_Version::get_processor_features() {
457337
FLAG_SET_DEFAULT(UseBlockZeroing, false);
458338
}
459339

460-
if (auxv & HWCAP_SVE) {
340+
if (_features & CPU_SVE) {
461341
if (FLAG_IS_DEFAULT(UseSVE)) {
462-
FLAG_SET_DEFAULT(UseSVE, (auxv2 & HWCAP2_SVE2) ? 2 : 1);
342+
FLAG_SET_DEFAULT(UseSVE, (_features & CPU_SVE2) ? 2 : 1);
463343
}
464344
if (UseSVE > 0) {
465-
_initial_sve_vector_length = prctl(PR_SVE_GET_VL);
345+
_initial_sve_vector_length = get_current_sve_vector_length();
466346
}
467347
} else if (UseSVE > 0) {
468348
warning("UseSVE specified, but not supported on current CPU. Disabling SVE.");
@@ -510,11 +390,9 @@ void VM_Version::get_processor_features() {
510390
warning("SVE does not support vector length less than 16 bytes. Disabling SVE.");
511391
UseSVE = 0;
512392
} else if ((MaxVectorSize % 16) == 0 && is_power_of_2(MaxVectorSize)) {
513-
int new_vl = prctl(PR_SVE_SET_VL, MaxVectorSize);
393+
int new_vl = set_and_get_current_sve_vector_lenght(MaxVectorSize);
514394
_initial_sve_vector_length = new_vl;
515-
// If MaxVectorSize is larger than system largest supported SVE vector length, above prctl()
516-
// call will set task vector length to the system largest supported value. So, we also update
517-
// MaxVectorSize to that largest supported value.
395+
// Update MaxVectorSize to the largest supported value.
518396
if (new_vl < 0) {
519397
vm_exit_during_initialization(
520398
err_msg("Current system does not support SVE vector length for MaxVectorSize: %d",
@@ -555,22 +433,6 @@ void VM_Version::get_processor_features() {
555433
AlignVector = AvoidUnalignedAccesses;
556434
}
557435
#endif
558-
}
559-
560-
void VM_Version::initialize() {
561-
ResourceMark rm;
562-
563-
stub_blob = BufferBlob::create("getPsrInfo_stub", stub_size);
564-
if (stub_blob == NULL) {
565-
vm_exit_during_initialization("Unable to allocate getPsrInfo_stub");
566-
}
567-
568-
CodeBuffer c(stub_blob);
569-
VM_Version_StubGenerator g(&c);
570-
getPsrInfo_stub = CAST_TO_FN_PTR(getPsrInfo_stub_t,
571-
g.generate_getPsrInfo());
572-
573-
get_processor_features();
574436

575437
UNSUPPORTED_OPTION(CriticalJNINatives);
576438
}

0 commit comments

Comments
 (0)