8217843: Performance regression related to os::supports_monotonic_clock() on linux

Reviewed-by: redestad, stuefe
This commit is contained in:
David Holmes 2019-02-05 20:18:00 -05:00
parent 076d2267b6
commit 07664f43d4
4 changed files with 59 additions and 19 deletions

View file

@ -26,6 +26,7 @@
#define OS_LINUX_OS_LINUX_INLINE_HPP
#include "runtime/os.hpp"
#include "os_posix.inline.hpp"
// System includes

View file

@ -25,10 +25,10 @@
#include "jvm.h"
#include "logging/log.hpp"
#include "memory/allocation.inline.hpp"
#include "os_posix.inline.hpp"
#include "utilities/globalDefinitions.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/interfaceSupport.inline.hpp"
#include "runtime/os.hpp"
#include "services/memTracker.hpp"
#include "utilities/align.hpp"
#include "utilities/formatBuffer.hpp"
@ -1659,26 +1659,13 @@ static void pthread_init_common(void) {
// This means we have clockid_t, clock_gettime et al and CLOCK_MONOTONIC
static int (*_clock_gettime)(clockid_t, struct timespec *) = NULL;
static int (*_clock_getres)(clockid_t, struct timespec *) = NULL;
int (*os::Posix::_clock_gettime)(clockid_t, struct timespec *) = NULL;
int (*os::Posix::_clock_getres)(clockid_t, struct timespec *) = NULL;
static int (*_pthread_condattr_setclock)(pthread_condattr_t *, clockid_t) = NULL;
static bool _use_clock_monotonic_condattr = false;
// Exported clock functionality
int os::Posix::clock_gettime(clockid_t clock_id, struct timespec *tp) {
return _clock_gettime != NULL ? _clock_gettime(clock_id, tp) : -1;
}
int os::Posix::clock_getres(clockid_t clock_id, struct timespec *tp) {
return _clock_getres != NULL ? _clock_getres(clock_id, tp) : -1;
}
bool os::Posix::supports_monotonic_clock() {
return _clock_gettime != NULL;
}
// Determine what POSIX API's are present and do appropriate
// configuration.
void os::Posix::init(void) {
@ -1879,12 +1866,12 @@ static void to_abstime(timespec* abstime, jlong timeout,
clockid_t clock = CLOCK_MONOTONIC;
// need to ensure we have a runtime check for clock_gettime support
if (!isAbsolute && _clock_gettime != NULL) {
if (!isAbsolute && os::Posix::supports_monotonic_clock()) {
if (!_use_clock_monotonic_condattr || isRealtime) {
clock = CLOCK_REALTIME;
}
struct timespec now;
int status = _clock_gettime(clock, &now);
int status = os::Posix::clock_gettime(clock, &now);
assert_status(status == 0, status, "clock_gettime");
calc_rel_time(abstime, timeout, now.tv_sec, now.tv_nsec, NANOUNITS);
DEBUG_ONLY(max_secs += now.tv_sec;)

View file

@ -123,6 +123,11 @@ public:
#ifdef SUPPORTS_CLOCK_MONOTONIC
private:
// These need to be members so we can access them from inline functions
static int (*_clock_gettime)(clockid_t, struct timespec *);
static int (*_clock_getres)(clockid_t, struct timespec *);
public:
static bool supports_monotonic_clock();
static int clock_gettime(clockid_t clock_id, struct timespec *tp);
static int clock_getres(clockid_t clock_id, struct timespec *tp);

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef OS_POSIX_OS_POSIX_INLINE_HPP
#define OS_POSIX_OS_POSIX_INLINE_HPP
#include "runtime/os.hpp"
#ifdef SUPPORTS_CLOCK_MONOTONIC
// Exported clock functionality
inline bool os::Posix::supports_monotonic_clock() {
return _clock_gettime != NULL;
}
inline int os::Posix::clock_gettime(clockid_t clock_id, struct timespec *tp) {
return _clock_gettime != NULL ? _clock_gettime(clock_id, tp) : -1;
}
inline int os::Posix::clock_getres(clockid_t clock_id, struct timespec *tp) {
return _clock_getres != NULL ? _clock_getres(clock_id, tp) : -1;
}
#endif // SUPPORTS_CLOCK_MONOTONIC
#endif // OS_POSIX_OS_POSIX_INLINE_HPP