Commit 1443f6b 1 parent 82e1a1c commit 1443f6b Copy full SHA for 1443f6b
File tree 1 file changed +19
-3
lines changed
src/hotspot/os_cpu/linux_x86
1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -459,11 +459,26 @@ bool os::supports_sse() {
459
459
}
460
460
461
461
juint os::cpu_microcode_revision () {
462
+ // Note: this code runs on startup, and therefore should not be slow,
463
+ // see JDK-8283200.
464
+
462
465
juint result = 0 ;
463
- char data[2048 ] = {0 }; // lines should fit in 2K buf
464
- size_t len = sizeof (data);
465
- FILE *fp = os::fopen (" /proc/cpuinfo" , " r" );
466
+
467
+ // Attempt 1 (faster): Read the microcode version off the sysfs.
468
+ FILE *fp = os::fopen (" /sys/devices/system/cpu/cpu0/microcode/version" , " r" );
469
+ if (fp) {
470
+ int read = fscanf (fp, " %x" , &result);
471
+ fclose (fp);
472
+ if (read > 0 ) {
473
+ return result;
474
+ }
475
+ }
476
+
477
+ // Attempt 2 (slower): Read the microcode version off the procfs.
478
+ fp = os::fopen (" /proc/cpuinfo" , " r" );
466
479
if (fp) {
480
+ char data[2048 ] = {0 }; // lines should fit in 2K buf
481
+ size_t len = sizeof (data);
467
482
while (!feof (fp)) {
468
483
if (fgets (data, len, fp)) {
469
484
if (strstr (data, " microcode" ) != NULL ) {
@@ -475,6 +490,7 @@ juint os::cpu_microcode_revision() {
475
490
}
476
491
fclose (fp);
477
492
}
493
+
478
494
return result;
479
495
}
480
496
You can’t perform that action at this time.
0 commit comments