summaryrefslogtreecommitdiffstats
path: root/Modules/timemodule.c
diff options
context:
space:
mode:
authorBatuhan Taskaya <isidentical@gmail.com>2020-05-16 09:39:09 (GMT)
committerGitHub <noreply@github.com>2020-05-16 09:39:09 (GMT)
commit45410862321ae509e8753f239b0ea28fdcef5bad (patch)
tree030a36663d2dc03cf7ce87b528ab316f948ec4e1 /Modules/timemodule.c
parent62972d9d73e83d6eea157617cc69500ffec9e3f0 (diff)
downloadcpython-45410862321ae509e8753f239b0ea28fdcef5bad.zip
cpython-45410862321ae509e8753f239b0ea28fdcef5bad.tar.gz
cpython-45410862321ae509e8753f239b0ea28fdcef5bad.tar.bz2
bpo-40192: Use thread_cputime for time.thread_time to improve resolution (GH-19381)
On AIX, 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.
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r--Modules/timemodule.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index a0e66ac..8a4d149 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -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
@@ -1343,6 +1347,30 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
return 0;
}
+#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;
+ 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