Skip to content

Commit

Permalink
8283199: Linux os::cpu_microcode_revision() stalls cold startup
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, redestad, stuefe
  • Loading branch information
shipilev committed Mar 23, 2022
1 parent 82e1a1c commit 1443f6b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp
Expand Up @@ -459,11 +459,26 @@ bool os::supports_sse() {
}

juint os::cpu_microcode_revision() {
// Note: this code runs on startup, and therefore should not be slow,
// see JDK-8283200.

juint result = 0;
char data[2048] = {0}; // lines should fit in 2K buf
size_t len = sizeof(data);
FILE *fp = os::fopen("/proc/cpuinfo", "r");

// Attempt 1 (faster): Read the microcode version off the sysfs.
FILE *fp = os::fopen("/sys/devices/system/cpu/cpu0/microcode/version", "r");
if (fp) {
int read = fscanf(fp, "%x", &result);
fclose(fp);
if (read > 0) {
return result;
}
}

// Attempt 2 (slower): Read the microcode version off the procfs.
fp = os::fopen("/proc/cpuinfo", "r");
if (fp) {
char data[2048] = {0}; // lines should fit in 2K buf
size_t len = sizeof(data);
while (!feof(fp)) {
if (fgets(data, len, fp)) {
if (strstr(data, "microcode") != NULL) {
Expand All @@ -475,6 +490,7 @@ juint os::cpu_microcode_revision() {
}
fclose(fp);
}

return result;
}

Expand Down

1 comment on commit 1443f6b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.