8217786: Provide virtualization related info in the hs_error file on linux s390x
authormbaesken
Wed, 30 Jan 2019 09:57:59 +0100
changeset 53565 55ba2125ba24
parent 53564 754bcf6ca637
child 53566 acb1571b1df8
8217786: Provide virtualization related info in the hs_error file on linux s390x Reviewed-by: dholmes, stuefe
src/hotspot/os/linux/os_linux.cpp
src/hotspot/os/linux/os_linux.hpp
--- a/src/hotspot/os/linux/os_linux.cpp	Wed Jan 30 12:04:59 2019 +0000
+++ b/src/hotspot/os/linux/os_linux.cpp	Wed Jan 30 09:57:59 2019 +0100
@@ -1856,6 +1856,34 @@
   return true;
 }
 
+// keywords_to_match - NULL terminated array of keywords
+static bool print_matching_lines_from_sysinfo_file(outputStream* st, const char* keywords_to_match[]) {
+  const char* filename = "/proc/sysinfo";
+  char* line = NULL;
+  size_t length = 0;
+  FILE* fp = fopen(filename, "r");
+  if (fp == NULL) {
+    return false;
+  }
+
+  st->print_cr("Virtualization information:");
+  while (getline(&line, &length, fp) != -1) {
+    int i = 0;
+    while (keywords_to_match[i] != NULL) {
+      if (strncmp(line, keywords_to_match[i], strlen(keywords_to_match[i])) == 0) {
+        st->print("%s", line);
+        break;
+      }
+      i++;
+    }
+  }
+
+  free(line);
+  fclose(fp);
+
+  return true;
+}
+
 void os::print_dll_info(outputStream *st) {
   st->print_cr("Dynamic libraries:");
 
@@ -1939,6 +1967,8 @@
   os::Linux::print_ld_preload_file(st);
 
   os::Linux::print_container_info(st);
+
+  os::Linux::print_virtualization_info(st);
 }
 
 // Try to identify popular distros.
@@ -2152,6 +2182,20 @@
   st->cr();
 }
 
+void os::Linux::print_virtualization_info(outputStream* st) {
+#if defined(S390)
+  // /proc/sysinfo contains interesting information about
+  // - LPAR
+  // - whole "Box" (CPUs )
+  // - z/VM / KVM (VM<nn>); this is not available in an LPAR-only setup
+  const char* kw[] = { "LPAR", "CPUs", "VM", NULL };
+
+  if (! print_matching_lines_from_sysinfo_file(st, kw)) {
+    st->print_cr("  </proc/sysinfo Not Available>");
+  }
+#endif
+}
+
 void os::print_memory_info(outputStream* st) {
 
   st->print("Memory:");
--- a/src/hotspot/os/linux/os_linux.hpp	Wed Jan 30 12:04:59 2019 +0000
+++ b/src/hotspot/os/linux/os_linux.hpp	Wed Jan 30 09:57:59 2019 +0100
@@ -110,6 +110,7 @@
 
   static void print_full_memory_info(outputStream* st);
   static void print_container_info(outputStream* st);
+  static void print_virtualization_info(outputStream* st);
   static void print_distro_info(outputStream* st);
   static void print_libversion_info(outputStream* st);
   static void print_proc_sys_info(outputStream* st);