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: stuefe
Backport-of: 1443f6b9191c127abdae38cadb1a44af3c652f1d
  • Loading branch information
shipilev committed Nov 8, 2022
1 parent 3a5bcf0 commit 6196d93
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 = fopen("/proc/cpuinfo", "r");

// Attempt 1 (faster): Read the microcode version off the sysfs.
FILE *fp = 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 = 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 6196d93

@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.