Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ finalization crashed with a Python fatal error if a daemon thread was still
running.
(Contributed by Victor Stinner in :issue:`37266`.)

time
----

On AIX, :func:`~time.thread_time` is now implemented with ``thread_cputime()``
which has nanosecond resolution, rather than
``clock_gettime(CLOCK_THREAD_CPUTIME_ID)`` which has a resolution of 10 ms.
(Contributed by Batuhan Taskaya in :issue:`40192`)

sys
---

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
On AIX, :func:`~time.thread_time` is now implemented with ``thread_cputime()``
which has nanosecond resolution, rather than
``clock_gettime(CLOCK_THREAD_CPUTIME_ID)`` which has a resolution of 10 ms.
Patch by Batuhan Taskaya.
28 changes: 28 additions & 0 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
# include <pthread.h>
#endif

#if defined(_AIX)
# include <sys/thread.h>
#endif

#if defined(__WATCOMC__) && !defined(__QNX__)
#include <i86.h>
#else
Expand Down Expand Up @@ -1344,6 +1348,30 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
return 0;
}
Comment thread
isidentical marked this conversation as resolved.

#elif defined(_AIX)
#define HAVE_THREAD_TIME
static int
_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
{
/* bpo-40192: On AIX, thread_cputime() is preferred: it has nanosecond
resolution, whereas clock_gettime(CLOCK_THREAD_CPUTIME_ID)
has a resolution of 10 ms. */
thread_cputime_t tc;
Comment thread
isidentical marked this conversation as resolved.
if (thread_cputime(-1, &tc) != 0) {
PyErr_SetFromErrno(PyExc_OSError);
return -1;
}

if (info) {
info->implementation = "thread_cputime()";
info->monotonic = 1;
info->adjustable = 0;
info->resolution = 1e-9;
}
*tp = _PyTime_FromNanoseconds(tc.stime + tc.utime);
return 0;
}

#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
#define HAVE_THREAD_TIME
static int
Expand Down