comparison src/os/linux/vm/os_linux.cpp @ 12997:e4f478e7781b

8027294: Prepare hotspot for non TOD based uptime counter Summary: Use HR timer when available for os::elapsed_counter() on linux/bsd. Add a new counter for the JVM uptime. Reviewed-by: dholmes, sla
author jbachorik
date Fri, 25 Oct 2013 09:07:58 +0200
parents aa6f2ea19d8f
children 096c224171c4 c250880a6673 2b8e28fdf503 5656140324ed
comparison
equal deleted inserted replaced
12996:d70a665e25d7 12997:e4f478e7781b
1331 1331
1332 // Time since start-up in seconds to a fine granularity. 1332 // Time since start-up in seconds to a fine granularity.
1333 // Used by VMSelfDestructTimer and the MemProfiler. 1333 // Used by VMSelfDestructTimer and the MemProfiler.
1334 double os::elapsedTime() { 1334 double os::elapsedTime() {
1335 1335
1336 return (double)(os::elapsed_counter()) * 0.000001; 1336 return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
1337 } 1337 }
1338 1338
1339 jlong os::elapsed_counter() { 1339 jlong os::elapsed_counter() {
1340 timeval time; 1340 return javaTimeNanos() - initial_time_count;
1341 int status = gettimeofday(&time, NULL);
1342 return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
1343 } 1341 }
1344 1342
1345 jlong os::elapsed_frequency() { 1343 jlong os::elapsed_frequency() {
1346 return (1000 * 1000); 1344 return NANOSECS_PER_SEC; // nanosecond resolution
1347 } 1345 }
1348 1346
1349 bool os::supports_vtime() { return true; } 1347 bool os::supports_vtime() { return true; }
1350 bool os::enable_vtime() { return false; } 1348 bool os::enable_vtime() { return false; }
1351 bool os::vtime_enabled() { return false; } 1349 bool os::vtime_enabled() { return false; }
4748 4746
4749 // main_thread points to the aboriginal thread 4747 // main_thread points to the aboriginal thread
4750 Linux::_main_thread = pthread_self(); 4748 Linux::_main_thread = pthread_self();
4751 4749
4752 Linux::clock_init(); 4750 Linux::clock_init();
4753 initial_time_count = os::elapsed_counter(); 4751 initial_time_count = javaTimeNanos();
4754 4752
4755 // pthread_condattr initialization for monotonic clock 4753 // pthread_condattr initialization for monotonic clock
4756 int status; 4754 int status;
4757 pthread_condattr_t* _condattr = os::Linux::condAttr(); 4755 pthread_condattr_t* _condattr = os::Linux::condAttr();
4758 if ((status = pthread_condattr_init(_condattr)) != 0) { 4756 if ((status = pthread_condattr_init(_condattr)) != 0) {