< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page

        

@@ -61,11 +61,10 @@
 #include "runtime/stubRoutines.hpp"
 #include "runtime/thread.inline.hpp"
 #include "runtime/threadCritical.hpp"
 #include "runtime/threadSMR.hpp"
 #include "runtime/timer.hpp"
-#include "runtime/vm_version.hpp"
 #include "semaphore_posix.hpp"
 #include "services/attachListener.hpp"
 #include "services/memTracker.hpp"
 #include "services/runtimeService.hpp"
 #include "utilities/align.hpp"

@@ -226,86 +225,10 @@
   phys_mem = Linux::physical_memory();
   log_trace(os)("total system memory: " JLONG_FORMAT, phys_mem);
   return phys_mem;
 }
 
-static uint64_t initial_total_ticks = 0;
-static uint64_t initial_steal_ticks = 0;
-static bool     has_initial_tick_info = false;
-
-static void next_line(FILE *f) {
-  int c;
-  do {
-    c = fgetc(f);
-  } while (c != '\n' && c != EOF);
-}
-
-bool os::Linux::get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu) {
-  FILE*         fh;
-  uint64_t      userTicks, niceTicks, systemTicks, idleTicks;
-  // since at least kernel 2.6 : iowait: time waiting for I/O to complete
-  // irq: time  servicing interrupts; softirq: time servicing softirqs
-  uint64_t      iowTicks = 0, irqTicks = 0, sirqTicks= 0;
-  // steal (since kernel 2.6.11): time spent in other OS when running in a virtualized environment
-  uint64_t      stealTicks = 0;
-  // guest (since kernel 2.6.24): time spent running a virtual CPU for guest OS under the
-  // control of the Linux kernel
-  uint64_t      guestNiceTicks = 0;
-  int           logical_cpu = -1;
-  const int     required_tickinfo_count = (which_logical_cpu == -1) ? 4 : 5;
-  int           n;
-
-  memset(pticks, 0, sizeof(CPUPerfTicks));
-
-  if ((fh = fopen("/proc/stat", "r")) == NULL) {
-    return false;
-  }
-
-  if (which_logical_cpu == -1) {
-    n = fscanf(fh, "cpu " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
-            UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
-            UINT64_FORMAT " " UINT64_FORMAT " ",
-            &userTicks, &niceTicks, &systemTicks, &idleTicks,
-            &iowTicks, &irqTicks, &sirqTicks,
-            &stealTicks, &guestNiceTicks);
-  } else {
-    // Move to next line
-    next_line(fh);
-
-    // find the line for requested cpu faster to just iterate linefeeds?
-    for (int i = 0; i < which_logical_cpu; i++) {
-      next_line(fh);
-    }
-
-    n = fscanf(fh, "cpu%u " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
-               UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
-               UINT64_FORMAT " " UINT64_FORMAT " ",
-               &logical_cpu, &userTicks, &niceTicks,
-               &systemTicks, &idleTicks, &iowTicks, &irqTicks, &sirqTicks,
-               &stealTicks, &guestNiceTicks);
-  }
-
-  fclose(fh);
-  if (n < required_tickinfo_count || logical_cpu != which_logical_cpu) {
-    return false;
-  }
-  pticks->used       = userTicks + niceTicks;
-  pticks->usedKernel = systemTicks + irqTicks + sirqTicks;
-  pticks->total      = userTicks + niceTicks + systemTicks + idleTicks +
-                       iowTicks + irqTicks + sirqTicks + stealTicks + guestNiceTicks;
-
-  if (n > required_tickinfo_count + 3) {
-    pticks->steal = stealTicks;
-    pticks->has_steal_ticks = true;
-  } else {
-    pticks->steal = 0;
-    pticks->has_steal_ticks = false;
-  }
-
-  return true;
-}
-
 // Return true if user is running as root.
 
 bool os::have_special_privileges() {
   static bool init = false;
   static bool privileges = false;

@@ -771,19 +694,19 @@
   // initialize floating point control register
   os::Linux::init_thread_fpu_state();
 
   // handshaking with parent thread
   {
-    MutexLocker ml(sync, Mutex::_no_safepoint_check_flag);
+    MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
 
     // notify parent thread
     osthread->set_state(INITIALIZED);
     sync->notify_all();
 
     // wait until os::start_thread()
     while (osthread->get_state() == INITIALIZED) {
-      sync->wait_without_safepoint_check();
+      sync->wait(Mutex::_no_safepoint_check_flag);
     }
   }
 
   assert(osthread->pthread_id() != 0, "pthread_id was not set as expected");
 

@@ -879,13 +802,13 @@
     osthread->set_pthread_id(tid);
 
     // Wait until child thread is either initialized or aborted
     {
       Monitor* sync_with_child = osthread->startThread_lock();
-      MutexLocker ml(sync_with_child, Mutex::_no_safepoint_check_flag);
+      MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
       while ((state = osthread->get_state()) == ALLOCATED) {
-        sync_with_child->wait_without_safepoint_check();
+        sync_with_child->wait(Mutex::_no_safepoint_check_flag);
       }
     }
   }
 
   // Aborted due to thread limit being reached

@@ -973,11 +896,11 @@
 
 void os::pd_start_thread(Thread* thread) {
   OSThread * osthread = thread->osthread();
   assert(osthread->get_state() != INITIALIZED, "just checking");
   Monitor* sync_with_child = osthread->startThread_lock();
-  MutexLocker ml(sync_with_child, Mutex::_no_safepoint_check_flag);
+  MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
   sync_with_child->notify();
 }
 
 // Free Linux resources related to the OSThread
 void os::free_thread(OSThread* osthread) {

@@ -1938,10 +1861,39 @@
   ::close(fd);
 
   return true;
 }
 
+#if defined(S390) || defined(PPC64)
+// keywords_to_match - NULL terminated array of keywords
+static bool print_matching_lines_from_file(const char* filename, outputStream* st, const char* keywords_to_match[]) {
+  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;
+}
+#endif
+
 void os::print_dll_info(outputStream *st) {
   st->print_cr("Dynamic libraries:");
 
   char fname[32];
   pid_t pid = os::Linux::gettid();

@@ -2022,13 +1974,11 @@
 
   os::Linux::print_ld_preload_file(st);
 
   os::Linux::print_container_info(st);
 
-  VM_Version::print_platform_virtualization_info(st);
-
-  os::Linux::print_steal_info(st);
+  os::Linux::print_virtualization_info(st);
 }
 
 // Try to identify popular distros.
 // Most Linux distributions have a /etc/XXX-release file, which contains
 // the OS version string. Newer Linux distributions have a /etc/lsb-release

@@ -2279,26 +2229,42 @@
     st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited");
   }
   st->cr();
 }
 
-void os::Linux::print_steal_info(outputStream* st) {
-  if (has_initial_tick_info) {
-    CPUPerfTicks pticks;
-    bool res = os::Linux::get_tick_information(&pticks, -1);
-
-    if (res && pticks.has_steal_ticks) {
-      uint64_t steal_ticks_difference = pticks.steal - initial_steal_ticks;
-      uint64_t total_ticks_difference = pticks.total - initial_total_ticks;
-      double steal_ticks_perc = 0.0;
-      if (total_ticks_difference != 0) {
-        steal_ticks_perc = (double) steal_ticks_difference / total_ticks_difference;
-      }
-      st->print_cr("Steal ticks since vm start: " UINT64_FORMAT, steal_ticks_difference);
-      st->print_cr("Steal ticks percentage since vm start:%7.3f", steal_ticks_perc);
-    }
+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 };
+  const char* info_file = "/proc/sysinfo";
+
+  if (!print_matching_lines_from_file(info_file, st, kw)) {
+    st->print_cr("  <%s Not Available>", info_file);
   }
+#elif defined(PPC64)
+  const char* info_file = "/proc/ppc64/lparcfg";
+  const char* kw[] = { "system_type=", // qemu indicates PowerKVM
+                       "partition_entitled_capacity=", // entitled processor capacity percentage
+                       "partition_max_entitled_capacity=",
+                       "capacity_weight=", // partition CPU weight
+                       "partition_active_processors=",
+                       "partition_potential_processors=",
+                       "entitled_proc_capacity_available=",
+                       "capped=", // 0 - uncapped, 1 - vcpus capped at entitled processor capacity percentage
+                       "shared_processor_mode=", // (non)dedicated partition
+                       "system_potential_processors=",
+                       "pool=", // CPU-pool number
+                       "pool_capacity=",
+                       "NumLpars=", // on non-KVM machines, NumLpars is not found for full partition mode machines
+                       NULL };
+  if (!print_matching_lines_from_file(info_file, st, kw)) {
+    st->print_cr("  <%s Not Available>", info_file);
+  }
+#endif
 }
 
 void os::print_memory_info(outputStream* st) {
 
   st->print("Memory:");

@@ -5021,19 +4987,10 @@
 
   Linux::initialize_system_info();
 
   Linux::initialize_os_info();
 
-  os::Linux::CPUPerfTicks pticks;
-  bool res = os::Linux::get_tick_information(&pticks, -1);
-
-  if (res && pticks.has_steal_ticks) {
-    has_initial_tick_info = true;
-    initial_total_ticks = pticks.total;
-    initial_steal_ticks = pticks.steal;
-  }
-
   // _main_thread points to the thread that created/loaded the JVM.
   Linux::_main_thread = pthread_self();
 
   // retrieve entry point for pthread_setname_np
   Linux::_pthread_setname_np =

@@ -5156,20 +5113,17 @@
   // Check and sets minimum stack sizes against command line options
   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
     return JNI_ERR;
   }
 
-#if defined(IA32)
-  // Need to ensure we've determined the process's initial stack to
-  // perform the workaround
-  Linux::capture_initial_stack(JavaThread::stack_size_at_create());
-  workaround_expand_exec_shield_cs_limit();
-#else
   suppress_primordial_thread_resolution = Arguments::created_by_java_launcher();
   if (!suppress_primordial_thread_resolution) {
     Linux::capture_initial_stack(JavaThread::stack_size_at_create());
   }
+
+#if defined(IA32)
+  workaround_expand_exec_shield_cs_limit();
 #endif
 
   Linux::libpthread_init();
   Linux::sched_getcpu_init();
   log_info(os)("HotSpot is running with %s, %s",
< prev index next >