24
24
*/
25
25
26
26
#include " precompiled.hpp"
27
- #include " asm/macroAssembler.hpp"
28
- #include " asm/macroAssembler.inline.hpp"
29
- #include " memory/resourceArea.hpp"
30
27
#include " runtime/arguments.hpp"
31
28
#include " runtime/globals_extension.hpp"
32
29
#include " runtime/java.hpp"
33
30
#include " runtime/os.hpp"
34
- #include " runtime/stubCodeGenerator.hpp"
35
31
#include " runtime/vm_version.hpp"
36
32
#include " utilities/formatBuffer.hpp"
37
33
#include " utilities/macros.hpp"
38
34
39
35
#include OS_HEADER_INLINE(os)
40
36
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
-
87
37
int VM_Version::_cpu;
88
38
int VM_Version::_model;
89
39
int VM_Version::_model2;
90
40
int VM_Version::_variant;
91
41
int VM_Version::_revision;
92
42
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:
108
43
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;
136
48
137
- void VM_Version::get_processor_features () {
49
+ void VM_Version::initialize () {
138
50
_supports_cx8 = true ;
139
51
_supports_atomic_getset4 = true ;
140
52
_supports_atomic_getadd4 = true ;
141
53
_supports_atomic_getset8 = true ;
142
54
_supports_atomic_getadd8 = true ;
143
55
144
- getPsrInfo_stub (&_psr_info );
56
+ get_os_cpu_info ( );
145
57
146
58
int dcache_line = VM_Version::dcache_line_size ();
147
59
@@ -183,45 +95,12 @@ void VM_Version::get_processor_features() {
183
95
SoftwarePrefetchHintDistance &= ~7 ;
184
96
}
185
97
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
- }
219
98
220
99
if (os::supports_map_sync ()) {
221
100
// if dcpop is available publish data cache line flush size via
222
101
// generic field, otherwise let if default to zero thereby
223
102
// disabling writeback
224
- if (_dcpop ) {
103
+ if (_features & CPU_DCPOP ) {
225
104
_data_cache_line_flush_size = dcache_line;
226
105
}
227
106
}
@@ -302,30 +181,31 @@ void VM_Version::get_processor_features() {
302
181
}
303
182
304
183
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)
306
185
// we assume the worst and assume we could be on a big little system and have
307
186
// 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;
309
188
189
+ char buf[512 ];
310
190
sprintf (buf, " 0x%02x:0x%x:0x%03x:%d" , _cpu, _variant, _model, _revision);
311
191
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" );
321
201
322
202
_features_string = os::strdup (buf);
323
203
324
204
if (FLAG_IS_DEFAULT (UseCRC32)) {
325
- UseCRC32 = (auxv & HWCAP_CRC32 ) != 0 ;
205
+ UseCRC32 = (_features & CPU_CRC32 ) != 0 ;
326
206
}
327
207
328
- if (UseCRC32 && (auxv & HWCAP_CRC32 ) == 0 ) {
208
+ if (UseCRC32 && (_features & CPU_CRC32 ) == 0 ) {
329
209
warning (" UseCRC32 specified, but not supported on this CPU" );
330
210
FLAG_SET_DEFAULT (UseCRC32, false );
331
211
}
@@ -339,7 +219,7 @@ void VM_Version::get_processor_features() {
339
219
FLAG_SET_DEFAULT (UseVectorizedMismatchIntrinsic, false );
340
220
}
341
221
342
- if (auxv & HWCAP_ATOMICS ) {
222
+ if (_features & CPU_LSE ) {
343
223
if (FLAG_IS_DEFAULT (UseLSE))
344
224
FLAG_SET_DEFAULT (UseLSE, true );
345
225
} else {
@@ -349,7 +229,7 @@ void VM_Version::get_processor_features() {
349
229
}
350
230
}
351
231
352
- if (auxv & HWCAP_AES ) {
232
+ if (_features & CPU_AES ) {
353
233
UseAES = UseAES || FLAG_IS_DEFAULT (UseAES);
354
234
UseAESIntrinsics =
355
235
UseAESIntrinsics || (UseAES && FLAG_IS_DEFAULT (UseAESIntrinsics));
@@ -377,7 +257,7 @@ void VM_Version::get_processor_features() {
377
257
UseCRC32Intrinsics = true ;
378
258
}
379
259
380
- if (auxv & HWCAP_CRC32 ) {
260
+ if (_features & CPU_CRC32 ) {
381
261
if (FLAG_IS_DEFAULT (UseCRC32CIntrinsics)) {
382
262
FLAG_SET_DEFAULT (UseCRC32CIntrinsics, true );
383
263
}
@@ -395,7 +275,7 @@ void VM_Version::get_processor_features() {
395
275
FLAG_SET_DEFAULT (UseMD5Intrinsics, false );
396
276
}
397
277
398
- if (auxv & (HWCAP_SHA1 | HWCAP_SHA2 )) {
278
+ if (_features & (CPU_SHA1 | CPU_SHA2 )) {
399
279
if (FLAG_IS_DEFAULT (UseSHA)) {
400
280
FLAG_SET_DEFAULT (UseSHA, true );
401
281
}
@@ -404,7 +284,7 @@ void VM_Version::get_processor_features() {
404
284
FLAG_SET_DEFAULT (UseSHA, false );
405
285
}
406
286
407
- if (UseSHA && (auxv & HWCAP_SHA1 )) {
287
+ if (UseSHA && (_features & CPU_SHA1 )) {
408
288
if (FLAG_IS_DEFAULT (UseSHA1Intrinsics)) {
409
289
FLAG_SET_DEFAULT (UseSHA1Intrinsics, true );
410
290
}
@@ -413,7 +293,7 @@ void VM_Version::get_processor_features() {
413
293
FLAG_SET_DEFAULT (UseSHA1Intrinsics, false );
414
294
}
415
295
416
- if (UseSHA && (auxv & HWCAP_SHA2 )) {
296
+ if (UseSHA && (_features & CPU_SHA2 )) {
417
297
if (FLAG_IS_DEFAULT (UseSHA256Intrinsics)) {
418
298
FLAG_SET_DEFAULT (UseSHA256Intrinsics, true );
419
299
}
@@ -422,7 +302,7 @@ void VM_Version::get_processor_features() {
422
302
FLAG_SET_DEFAULT (UseSHA256Intrinsics, false );
423
303
}
424
304
425
- if (UseSHA && (auxv & HWCAP_SHA512 )) {
305
+ if (UseSHA && (_features & CPU_SHA512 )) {
426
306
// Do not auto-enable UseSHA512Intrinsics until it has been fully tested on hardware
427
307
// if (FLAG_IS_DEFAULT(UseSHA512Intrinsics)) {
428
308
// FLAG_SET_DEFAULT(UseSHA512Intrinsics, true);
@@ -436,7 +316,7 @@ void VM_Version::get_processor_features() {
436
316
FLAG_SET_DEFAULT (UseSHA, false );
437
317
}
438
318
439
- if (auxv & HWCAP_PMULL ) {
319
+ if (_features & CPU_PMULL ) {
440
320
if (FLAG_IS_DEFAULT (UseGHASHIntrinsics)) {
441
321
FLAG_SET_DEFAULT (UseGHASHIntrinsics, true );
442
322
}
@@ -457,12 +337,12 @@ void VM_Version::get_processor_features() {
457
337
FLAG_SET_DEFAULT (UseBlockZeroing, false );
458
338
}
459
339
460
- if (auxv & HWCAP_SVE ) {
340
+ if (_features & CPU_SVE ) {
461
341
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 );
463
343
}
464
344
if (UseSVE > 0 ) {
465
- _initial_sve_vector_length = prctl (PR_SVE_GET_VL );
345
+ _initial_sve_vector_length = get_current_sve_vector_length ( );
466
346
}
467
347
} else if (UseSVE > 0 ) {
468
348
warning (" UseSVE specified, but not supported on current CPU. Disabling SVE." );
@@ -510,11 +390,9 @@ void VM_Version::get_processor_features() {
510
390
warning (" SVE does not support vector length less than 16 bytes. Disabling SVE." );
511
391
UseSVE = 0 ;
512
392
} 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);
514
394
_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.
518
396
if (new_vl < 0 ) {
519
397
vm_exit_during_initialization (
520
398
err_msg (" Current system does not support SVE vector length for MaxVectorSize: %d" ,
@@ -555,22 +433,6 @@ void VM_Version::get_processor_features() {
555
433
AlignVector = AvoidUnalignedAccesses;
556
434
}
557
435
#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 ();
574
436
575
437
UNSUPPORTED_OPTION (CriticalJNINatives);
576
438
}
0 commit comments