< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page

  66 #include "runtime/vm_version.hpp"
  67 #include "signals_posix.hpp"
  68 #include "semaphore_posix.hpp"
  69 #include "services/memTracker.hpp"
  70 #include "services/runtimeService.hpp"
  71 #include "utilities/align.hpp"
  72 #include "utilities/decoder.hpp"
  73 #include "utilities/defaultStream.hpp"
  74 #include "utilities/events.hpp"
  75 #include "utilities/elfFile.hpp"
  76 #include "utilities/growableArray.hpp"
  77 #include "utilities/globalDefinitions.hpp"
  78 #include "utilities/macros.hpp"
  79 #include "utilities/powerOfTwo.hpp"
  80 #include "utilities/vmError.hpp"
  81 #if INCLUDE_JFR
  82 #include "jfr/jfrEvents.hpp"
  83 #endif
  84 
  85 // put OS-includes here


  86 # include <sys/types.h>
  87 # include <sys/mman.h>
  88 # include <sys/stat.h>
  89 # include <sys/select.h>
  90 # include <pthread.h>
  91 # include <signal.h>
  92 # include <endian.h>
  93 # include <errno.h>
  94 # include <dlfcn.h>
  95 # include <stdio.h>
  96 # include <unistd.h>
  97 # include <sys/resource.h>
  98 # include <pthread.h>
  99 # include <sys/stat.h>
 100 # include <sys/time.h>
 101 # include <sys/times.h>
 102 # include <sys/utsname.h>
 103 # include <sys/socket.h>
 104 # include <pwd.h>
 105 # include <poll.h>

 292       return mem_limit;
 293     }
 294   }
 295 
 296   phys_mem = Linux::physical_memory();
 297   log_trace(os)("total system memory: " JLONG_FORMAT, phys_mem);
 298   return phys_mem;
 299 }
 300 
 301 static uint64_t initial_total_ticks = 0;
 302 static uint64_t initial_steal_ticks = 0;
 303 static bool     has_initial_tick_info = false;
 304 
 305 static void next_line(FILE *f) {
 306   int c;
 307   do {
 308     c = fgetc(f);
 309   } while (c != '\n' && c != EOF);
 310 }
 311 























 312 bool os::Linux::get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu) {
 313   FILE*         fh;
 314   uint64_t      userTicks, niceTicks, systemTicks, idleTicks;
 315   // since at least kernel 2.6 : iowait: time waiting for I/O to complete
 316   // irq: time  servicing interrupts; softirq: time servicing softirqs
 317   uint64_t      iowTicks = 0, irqTicks = 0, sirqTicks= 0;
 318   // steal (since kernel 2.6.11): time spent in other OS when running in a virtualized environment
 319   uint64_t      stealTicks = 0;
 320   // guest (since kernel 2.6.24): time spent running a virtual CPU for guest OS under the
 321   // control of the Linux kernel
 322   uint64_t      guestNiceTicks = 0;
 323   int           logical_cpu = -1;
 324   const int     required_tickinfo_count = (which_logical_cpu == -1) ? 4 : 5;
 325   int           n;
 326 
 327   memset(pticks, 0, sizeof(CPUPerfTicks));
 328 
 329   if ((fh = os::fopen("/proc/stat", "r")) == nullptr) {
 330     return false;
 331   }

2128       parse_os_info(&buf[7], buflen-7, "/etc/debian_version");
2129     }
2130   } else {
2131     strncpy(buf, "Linux", buflen);
2132   }
2133 }
2134 
2135 void os::Linux::print_libversion_info(outputStream* st) {
2136   // libc, pthread
2137   st->print("libc: ");
2138   st->print("%s ", os::Linux::libc_version());
2139   st->print("%s ", os::Linux::libpthread_version());
2140   st->cr();
2141 }
2142 
2143 void os::Linux::print_proc_sys_info(outputStream* st) {
2144   _print_ascii_file_h("/proc/sys/kernel/threads-max (system-wide limit on the number of threads)",
2145                       "/proc/sys/kernel/threads-max", st);
2146   _print_ascii_file_h("/proc/sys/vm/max_map_count (maximum number of memory map areas a process may have)",
2147                       "/proc/sys/vm/max_map_count", st);


2148   _print_ascii_file_h("/proc/sys/kernel/pid_max (system-wide limit on number of process identifiers)",
2149                       "/proc/sys/kernel/pid_max", st);
2150 }
2151 
2152 void os::Linux::print_system_memory_info(outputStream* st) {
2153   _print_ascii_file_h("/proc/meminfo", "/proc/meminfo", st, false);
2154   st->cr();
2155 
2156   // some information regarding THPs; for details see
2157   // https://www.kernel.org/doc/Documentation/vm/transhuge.txt
2158   _print_ascii_file_h("/sys/kernel/mm/transparent_hugepage/enabled",
2159                       "/sys/kernel/mm/transparent_hugepage/enabled", st);
2160   _print_ascii_file_h("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size",
2161                       "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", st);
2162   _print_ascii_file_h("/sys/kernel/mm/transparent_hugepage/defrag (defrag/compaction efforts parameter)",
2163                       "/sys/kernel/mm/transparent_hugepage/defrag", st);
2164 }
2165 
2166 bool os::Linux::query_process_memory_info(os::Linux::meminfo_t* info) {
2167   FILE* f = os::fopen("/proc/self/status", "r");

  66 #include "runtime/vm_version.hpp"
  67 #include "signals_posix.hpp"
  68 #include "semaphore_posix.hpp"
  69 #include "services/memTracker.hpp"
  70 #include "services/runtimeService.hpp"
  71 #include "utilities/align.hpp"
  72 #include "utilities/decoder.hpp"
  73 #include "utilities/defaultStream.hpp"
  74 #include "utilities/events.hpp"
  75 #include "utilities/elfFile.hpp"
  76 #include "utilities/growableArray.hpp"
  77 #include "utilities/globalDefinitions.hpp"
  78 #include "utilities/macros.hpp"
  79 #include "utilities/powerOfTwo.hpp"
  80 #include "utilities/vmError.hpp"
  81 #if INCLUDE_JFR
  82 #include "jfr/jfrEvents.hpp"
  83 #endif
  84 
  85 // put OS-includes here
  86 # include <ctype.h>
  87 # include <stdlib.h>
  88 # include <sys/types.h>
  89 # include <sys/mman.h>
  90 # include <sys/stat.h>
  91 # include <sys/select.h>
  92 # include <pthread.h>
  93 # include <signal.h>
  94 # include <endian.h>
  95 # include <errno.h>
  96 # include <dlfcn.h>
  97 # include <stdio.h>
  98 # include <unistd.h>
  99 # include <sys/resource.h>
 100 # include <pthread.h>
 101 # include <sys/stat.h>
 102 # include <sys/time.h>
 103 # include <sys/times.h>
 104 # include <sys/utsname.h>
 105 # include <sys/socket.h>
 106 # include <pwd.h>
 107 # include <poll.h>

 294       return mem_limit;
 295     }
 296   }
 297 
 298   phys_mem = Linux::physical_memory();
 299   log_trace(os)("total system memory: " JLONG_FORMAT, phys_mem);
 300   return phys_mem;
 301 }
 302 
 303 static uint64_t initial_total_ticks = 0;
 304 static uint64_t initial_steal_ticks = 0;
 305 static bool     has_initial_tick_info = false;
 306 
 307 static void next_line(FILE *f) {
 308   int c;
 309   do {
 310     c = fgetc(f);
 311   } while (c != '\n' && c != EOF);
 312 }
 313 
 314 void os::Linux::kernel_version(long* major, long* minor) {
 315   *major = -1;
 316   *minor = -1;
 317 
 318   struct utsname buffer;
 319   int ret = uname(&buffer);
 320   if (ret != 0) {
 321     log_warning(os)("uname(2) failed to get kernel version: %s", os::errno_name(ret));
 322     return;
 323   }
 324 
 325   char* walker = buffer.release;
 326   long* set_v = major;
 327   while (*minor == -1 && walker != nullptr) {
 328     if (isdigit(walker[0])) {
 329       *set_v = strtol(walker, &walker, 10);
 330       set_v = minor;
 331     } else {
 332       ++walker;
 333     }
 334   }
 335 }
 336 
 337 bool os::Linux::get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu) {
 338   FILE*         fh;
 339   uint64_t      userTicks, niceTicks, systemTicks, idleTicks;
 340   // since at least kernel 2.6 : iowait: time waiting for I/O to complete
 341   // irq: time  servicing interrupts; softirq: time servicing softirqs
 342   uint64_t      iowTicks = 0, irqTicks = 0, sirqTicks= 0;
 343   // steal (since kernel 2.6.11): time spent in other OS when running in a virtualized environment
 344   uint64_t      stealTicks = 0;
 345   // guest (since kernel 2.6.24): time spent running a virtual CPU for guest OS under the
 346   // control of the Linux kernel
 347   uint64_t      guestNiceTicks = 0;
 348   int           logical_cpu = -1;
 349   const int     required_tickinfo_count = (which_logical_cpu == -1) ? 4 : 5;
 350   int           n;
 351 
 352   memset(pticks, 0, sizeof(CPUPerfTicks));
 353 
 354   if ((fh = os::fopen("/proc/stat", "r")) == nullptr) {
 355     return false;
 356   }

2153       parse_os_info(&buf[7], buflen-7, "/etc/debian_version");
2154     }
2155   } else {
2156     strncpy(buf, "Linux", buflen);
2157   }
2158 }
2159 
2160 void os::Linux::print_libversion_info(outputStream* st) {
2161   // libc, pthread
2162   st->print("libc: ");
2163   st->print("%s ", os::Linux::libc_version());
2164   st->print("%s ", os::Linux::libpthread_version());
2165   st->cr();
2166 }
2167 
2168 void os::Linux::print_proc_sys_info(outputStream* st) {
2169   _print_ascii_file_h("/proc/sys/kernel/threads-max (system-wide limit on the number of threads)",
2170                       "/proc/sys/kernel/threads-max", st);
2171   _print_ascii_file_h("/proc/sys/vm/max_map_count (maximum number of memory map areas a process may have)",
2172                       "/proc/sys/vm/max_map_count", st);
2173   _print_ascii_file_h("/proc/sys/vm/swappiness (control to define how aggressively the kernel swaps out anonymous memory)",
2174                       "/proc/sys/vm/swappiness", st);
2175   _print_ascii_file_h("/proc/sys/kernel/pid_max (system-wide limit on number of process identifiers)",
2176                       "/proc/sys/kernel/pid_max", st);
2177 }
2178 
2179 void os::Linux::print_system_memory_info(outputStream* st) {
2180   _print_ascii_file_h("/proc/meminfo", "/proc/meminfo", st, false);
2181   st->cr();
2182 
2183   // some information regarding THPs; for details see
2184   // https://www.kernel.org/doc/Documentation/vm/transhuge.txt
2185   _print_ascii_file_h("/sys/kernel/mm/transparent_hugepage/enabled",
2186                       "/sys/kernel/mm/transparent_hugepage/enabled", st);
2187   _print_ascii_file_h("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size",
2188                       "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", st);
2189   _print_ascii_file_h("/sys/kernel/mm/transparent_hugepage/defrag (defrag/compaction efforts parameter)",
2190                       "/sys/kernel/mm/transparent_hugepage/defrag", st);
2191 }
2192 
2193 bool os::Linux::query_process_memory_info(os::Linux::meminfo_t* info) {
2194   FILE* f = os::fopen("/proc/self/status", "r");
< prev index next >