double resolution;
} _Py_clock_info_t;
-// Similar to PyTime_Time() but silently ignore the error and return 0 if the
-// internal clock fails.
-//
-// Use _PyTime_TimeWithInfo() or the public PyTime_Time() to check
-// for failure.
-// Export for '_random' shared extension.
-PyAPI_FUNC(PyTime_t) _PyTime_TimeUnchecked(void);
-
// Get the current time from the system clock.
// On success, set *t and *info (if not NULL), and return 0.
// On error, raise an exception and return -1.
PyTime_t *t,
_Py_clock_info_t *info);
-// Similar to PyTime_Monotonic() but silently ignore the error and return 0 if
-// the internal clock fails.
-//
-// Use _PyTime_MonotonicWithInfo() or the public PyTime_Monotonic()
-// to check for failure.
-// Export for '_random' shared extension.
-PyAPI_FUNC(PyTime_t) _PyTime_MonotonicUnchecked(void);
-
// Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
// The clock is not affected by system clock updates. The reference point of
// the returned value is undefined, so that only the difference between the
// Export for '_datetime' shared extension.
PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm);
-// Similar to PyTime_PerfCounter() but silently ignore the error and return 0
-// if the internal clock fails.
-//
-// Use _PyTime_PerfCounterWithInfo() or the public PyTime_PerfCounter() to
-// check for failure.
-// Export for '_lsprof' shared extension.
-PyAPI_FUNC(PyTime_t) _PyTime_PerfCounterUnchecked(void);
-
// Get the performance counter: clock with the highest available resolution to
// measure a short duration.
// --- _PyDeadline -----------------------------------------------------------
// Create a deadline.
-// Pseudo code: _PyTime_MonotonicUnchecked() + timeout.
+// Pseudo code: return PyTime_MonotonicRaw() + timeout
// Export for '_ssl' shared extension.
PyAPI_FUNC(PyTime_t) _PyDeadline_Init(PyTime_t timeout);
// Get remaining time from a deadline.
-// Pseudo code: deadline - _PyTime_MonotonicUnchecked().
+// Pseudo code: return deadline - PyTime_MonotonicRaw()
// Export for '_ssl' shared extension.
PyAPI_FUNC(PyTime_t) _PyDeadline_Get(PyTime_t deadline);
return CallExternalTimer(pObj);
}
else {
- return _PyTime_PerfCounterUnchecked();
+ PyTime_t t;
+ (void)PyTime_PerfCounterRaw(&t);
+ return t;
}
}
#include "parts.h"
#include "pycore_lock.h"
-#include "pycore_time.h" // _PyTime_MonotonicUnchecked()
#include "clinic/test_lock.c.h"
goto exit;
}
- PyTime_t start = _PyTime_MonotonicUnchecked();
+ PyTime_t start, end;
+ if (PyTime_PerfCounter(&start) < 0) {
+ goto exit;
+ }
for (Py_ssize_t i = 0; i < num_threads; i++) {
thread_data[i].bench_data = &bench_data;
}
Py_ssize_t total_iters = bench_data.total_iters;
- PyTime_t end = _PyTime_MonotonicUnchecked();
+ if (PyTime_PerfCounter(&end) < 0) {
+ goto exit;
+ }
// Return the total number of acquisitions and the number of acquisitions
// for each thread.
PyList_SET_ITEM(thread_iters, i, iter);
}
- double rate = total_iters * 1000000000.0 / (end - start);
+ assert(end != start);
+ double rate = total_iters * 1e9 / (end - start);
res = Py_BuildValue("(dO)", rate, thread_iters);
exit:
#include "pycore_object_alloc.h" // _PyObject_MallocWithType()
#include "pycore_pyerrors.h"
#include "pycore_pystate.h" // _PyThreadState_GET()
-#include "pycore_time.h" // _PyTime_PerfCounterUnchecked()
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
#include "pydtrace.h"
#include "pycore_object_stack.h"
#include "pycore_pyerrors.h"
#include "pycore_pystate.h" // _PyThreadState_GET()
-#include "pycore_time.h" // _PyTime_GetPerfCounter()
#include "pycore_tstate.h" // _PyThreadStateImpl
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
#include "pydtrace.h"
if (gcstate->debug & _PyGC_DEBUG_STATS) {
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
show_stats_each_generations(gcstate);
- t1 = _PyTime_PerfCounterUnchecked();
+ // ignore error: don't interrupt the GC if reading the clock fails
+ (void)PyTime_PerfCounterRaw(&t1);
}
if (PyDTrace_GC_START_ENABLED()) {
n = state.uncollectable;
if (gcstate->debug & _PyGC_DEBUG_STATS) {
- double d = PyTime_AsSecondsDouble(_PyTime_PerfCounterUnchecked() - t1);
+ PyTime_t t2;
+ (void)PyTime_PerfCounterRaw(&t2);
+ double d = PyTime_AsSecondsDouble(t2 - t1);
PySys_WriteStderr(
"gc: done, %zd unreachable, %zd uncollectable, %.4fs elapsed\n",
n+m, n, d);
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_sysmodule.h" // _PySys_Audit()
-#include "pycore_time.h" // _PyTime_PerfCounterUnchecked()
+#include "pycore_time.h" // _PyTime_AsMicroseconds()
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
#include "marshal.h" // PyMarshal_ReadObjectFromString()
#undef header
import_level++;
- t1 = _PyTime_PerfCounterUnchecked();
+ // ignore error: don't block import if reading the clock fails
+ (void)PyTime_PerfCounterRaw(&t1);
accumulated = 0;
}
mod != NULL);
if (import_time) {
- PyTime_t cum = _PyTime_PerfCounterUnchecked() - t1;
+ PyTime_t t2;
+ (void)PyTime_PerfCounterRaw(&t2);
+ PyTime_t cum = t2 - t1;
import_level--;
fprintf(stderr, "import time: %9ld | %10ld | %*s%s\n",
#include "pycore_lock.h"
#include "pycore_parking_lot.h"
#include "pycore_semaphore.h"
-#include "pycore_time.h" // _PyTime_MonotonicUnchecked()
+#include "pycore_time.h" // _PyTime_Add()
#ifdef MS_WINDOWS
# define WIN32_LEAN_AND_MEAN
-# include <windows.h> // SwitchToThread()
+# include <windows.h> // SwitchToThread()
#elif defined(HAVE_SCHED_H)
-# include <sched.h> // sched_yield()
+# include <sched.h> // sched_yield()
#endif
// If a thread waits on a lock for longer than TIME_TO_BE_FAIR_NS (1 ms), then
return PY_LOCK_FAILURE;
}
- PyTime_t now = _PyTime_MonotonicUnchecked();
+ PyTime_t now;
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_MonotonicRaw(&now);
PyTime_t endtime = 0;
if (timeout > 0) {
endtime = _PyTime_Add(now, timeout);
{
uint8_t v = 0;
if (entry) {
- PyTime_t now = _PyTime_MonotonicUnchecked();
+ PyTime_t now;
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_MonotonicRaw(&now);
int should_be_fair = now > entry->time_to_be_fair;
entry->handed_off = should_be_fair;
#include "pycore_pyerrors.h" // _Py_FatalErrorFormat
#include "pycore_pystate.h" // _PyThreadState_GET
#include "pycore_semaphore.h" // _PySemaphore
-#include "pycore_time.h" //_PyTime_MonotonicUnchecked()
+#include "pycore_time.h" // _PyTime_Add()
#include <stdbool.h>
struct timespec ts;
#if defined(CLOCK_MONOTONIC) && defined(HAVE_SEM_CLOCKWAIT)
- PyTime_t deadline = _PyTime_Add(_PyTime_MonotonicUnchecked(), timeout);
-
+ PyTime_t now;
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_MonotonicRaw(&now);
+ PyTime_t deadline = _PyTime_Add(now, timeout);
_PyTime_AsTimespec_clamp(deadline, &ts);
err = sem_clockwait(&sema->platform_sem, CLOCK_MONOTONIC, &ts);
#else
- PyTime_t deadline = _PyTime_Add(_PyTime_TimeUnchecked(), timeout);
+ PyTime_t now;
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_TimeRaw(&now);
+ PyTime_t deadline = _PyTime_Add(now, timeout);
_PyTime_AsTimespec_clamp(deadline, &ts);
_PyTime_AsTimespec_clamp(timeout, &ts);
err = pthread_cond_timedwait_relative_np(&sema->cond, &sema->mutex, &ts);
#else
- PyTime_t deadline = _PyTime_Add(_PyTime_TimeUnchecked(), timeout);
+ PyTime_t now;
+ (void)PyTime_TimeRaw(&now);
+ PyTime_t deadline = _PyTime_Add(now, timeout);
_PyTime_AsTimespec_clamp(deadline, &ts);
err = pthread_cond_timedwait(&sema->cond, &sema->mutex, &ts);
}
-PyTime_t
-_PyTime_TimeUnchecked(void)
-{
- PyTime_t t;
-#ifdef Py_DEBUG
- int result = PyTime_TimeRaw(&t);
- if (result != 0) {
- Py_FatalError("unable to read the system clock");
- }
-#else
- (void)PyTime_TimeRaw(&t);
-#endif
- return t;
-}
-
-
int
_PyTime_TimeWithInfo(PyTime_t *t, _Py_clock_info_t *info)
{
}
-PyTime_t
-_PyTime_MonotonicUnchecked(void)
-{
- PyTime_t t;
-#ifdef Py_DEBUG
- int result = PyTime_MonotonicRaw(&t);
- if (result != 0) {
- Py_FatalError("unable to read the monotonic clock");
- }
-#else
- (void)PyTime_MonotonicRaw(&t);
-#endif
- return t;
-}
-
-
int
_PyTime_MonotonicWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
{
}
-PyTime_t
-_PyTime_PerfCounterUnchecked(void)
-{
- return _PyTime_MonotonicUnchecked();
-}
-
-
int
_PyTime_localtime(time_t t, struct tm *tm)
{
PyTime_t
_PyDeadline_Init(PyTime_t timeout)
{
- PyTime_t now = _PyTime_MonotonicUnchecked();
+ PyTime_t now;
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_MonotonicRaw(&now);
return _PyTime_Add(now, timeout);
}
PyTime_t
_PyDeadline_Get(PyTime_t deadline)
{
- PyTime_t now = _PyTime_MonotonicUnchecked();
+ PyTime_t now;
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_MonotonicRaw(&now);
return deadline - now;
}
PyTime_t t;
#ifdef CONDATTR_MONOTONIC
if (condattr_monotonic) {
- t = _PyTime_MonotonicUnchecked();
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_MonotonicRaw(&t);
}
else
#endif
{
- t = _PyTime_TimeUnchecked();
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_TimeRaw(&t);
}
t = _PyTime_Add(t, timeout);
_PyTime_AsTimespec_clamp(t, abs);
struct timespec abs_timeout;
// Local scope for deadline
{
- PyTime_t deadline = _PyTime_Add(_PyTime_MonotonicUnchecked(), timeout);
+ PyTime_t now;
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_MonotonicRaw(&now);
+ PyTime_t deadline = _PyTime_Add(now, timeout);
_PyTime_AsTimespec_clamp(deadline, &abs_timeout);
}
#else
status = fix_status(sem_clockwait(thelock, CLOCK_MONOTONIC,
&abs_timeout));
#else
- PyTime_t abs_time = _PyTime_Add(_PyTime_TimeUnchecked(),
- timeout);
+ PyTime_t now;
+ // silently ignore error: cannot report error to the caller
+ (void)PyTime_TimeRaw(&now);
+ PyTime_t abs_time = _PyTime_Add(now, timeout);
+
struct timespec ts;
_PyTime_AsTimespec_clamp(abs_time, &ts);
status = fix_status(sem_timedwait(thelock, &ts));