Skip to content

Commit 1443f6b

Browse files
committedMar 23, 2022
8283199: Linux os::cpu_microcode_revision() stalls cold startup
Reviewed-by: dholmes, redestad, stuefe
1 parent 82e1a1c commit 1443f6b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed
 

‎src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,26 @@ bool os::supports_sse() {
459459
}
460460

461461
juint os::cpu_microcode_revision() {
462+
// Note: this code runs on startup, and therefore should not be slow,
463+
// see JDK-8283200.
464+
462465
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");
466479
if (fp) {
480+
char data[2048] = {0}; // lines should fit in 2K buf
481+
size_t len = sizeof(data);
467482
while (!feof(fp)) {
468483
if (fgets(data, len, fp)) {
469484
if (strstr(data, "microcode") != NULL) {
@@ -475,6 +490,7 @@ juint os::cpu_microcode_revision() {
475490
}
476491
fclose(fp);
477492
}
493+
478494
return result;
479495
}
480496

0 commit comments

Comments
 (0)
Please sign in to comment.