/* * Copyright (c) 2013, 2022, 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. *
*/
// Base loop to estimate ticks frequency for tsc counter from user mode. // Volatiles and sleep() are used to prevent compiler from applying optimizations. staticvoid do_time_measurements(volatile jlong& time_base, volatile jlong& time_fast, volatile jlong& time_base_elapsed, volatile jlong& time_fast_elapsed) { staticconstunsignedint FT_SLEEP_MILLISECS = 1; constunsignedint loopcount = 3;
// Figure out the difference between rdtsc and os provided timer. // base algorithm adopted from JRockit. for (unsignedint times = 0; times < loopcount; times++) {
start = os::elapsed_counter();
OrderAccess::fence();
fstart = os::rdtsc();
// use sleep to prevent compiler from optimizing
JavaThread::current()->sleep(FT_SLEEP_MILLISECS);
end = os::elapsed_counter();
OrderAccess::fence();
fend = os::rdtsc();
time_base += end - start;
time_fast += fend - fstart;
// basis for calculating the os tick start // to fast time tick start offset
time_base_elapsed += end;
time_fast_elapsed += (fend - _epoch);
}
// if platform supports invariant tsc, // apply higher resolution and granularity for conversion calculations if (VM_Version::supports_tscinv_ext()) { // for invariant tsc platforms, take the maximum qualified cpu frequency
tsc_freq = (double)VM_Version::maximum_qualified_cpu_frequency();
os_to_tsc_conv_factor = tsc_freq / os_freq;
} else { // use measurements to estimate // a conversion factor and the tsc frequency
// do measurements to get base data // on os timer and fast ticks tsc time relation.
do_time_measurements(time_base, time_fast, time_base_elapsed, time_fast_elapsed);
// if invalid measurements, cannot proceed if (time_fast == 0 || time_base == 0) { return 0;
}
os_to_tsc_conv_factor = (double)time_fast / (double)time_base; if (os_to_tsc_conv_factor > 1) { // estimate on tsc counter frequency
tsc_freq = os_to_tsc_conv_factor * os_freq;
}
}
if ((tsc_freq < 0) || (tsc_freq > 0 && tsc_freq <= os_freq) || (os_to_tsc_conv_factor <= 1)) { // safer to run with normal os time
tsc_freq = .0;
}
// frequency of the tsc_counter return (jlong)tsc_freq;
}
if (!ft_enabled) { if (UseFastUnorderedTimeStamps && VM_Version::supports_tsc()) {
warning("\nThe hardware does not support invariant tsc (INVTSC) register and/or cannot guarantee tsc synchronization between sockets at startup.\n"\ "Values returned via rdtsc() are not guaranteed to be accurate, esp. when comparing values from cross sockets reads. Enabling UseFastUnorderedTimeStamps on non-invariant tsc hardware should be considered experimental.\n");
ft_enabled = true;
}
}
if (!ft_enabled) { // Warn if unable to support command-line flag if (UseFastUnorderedTimeStamps && !VM_Version::supports_tsc()) {
warning("Ignoring UseFastUnorderedTimeStamps, hardware does not support normal tsc");
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.