From ed1a6c7893d4b8e41399878fee854bc3acb9486e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 16 Sep 2024 12:17:32 +0300 Subject: [PATCH 1/4] Revert "gh-123974: Fix time.get_clock_info() on NetBSD (#123975)" This reverts commit b1d6f8a2ee04215c64aa8752cc515b7e98a08d28. --- Modules/timemodule.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index cfbb26b0259504..46f85bc9c30f9c 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1509,19 +1509,15 @@ _PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info) return -1; } if (info) { + struct timespec res; info->implementation = function; info->monotonic = 1; info->adjustable = 0; - #if defined(__NetBSD__) - info->resolution = 1e-9; - #else - struct timespec res; if (clock_getres(clk_id, &res)) { PyErr_SetFromErrno(PyExc_OSError); return -1; } info->resolution = res.tv_sec + res.tv_nsec * 1e-9; - #endif } if (_PyTime_FromTimespec(tp, &ts) < 0) { From 86fd156167dacb5dbefbb5c009af953514eb92a7 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 16 Sep 2024 12:29:34 +0300 Subject: [PATCH 2/4] gh-123978: Remove broken time.thread_time() on NetBSD --- .../Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst | 1 + Modules/timemodule.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst diff --git a/Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst b/Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst new file mode 100644 index 00000000000000..105aa7eaed9fd4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst @@ -0,0 +1 @@ +Remove broken :func:`time.thread_time` on NetBSD. diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 46f85bc9c30f9c..c124fe5cb2bc7c 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1485,7 +1485,8 @@ _PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info) #elif defined(HAVE_CLOCK_GETTIME) && \ defined(CLOCK_PROCESS_CPUTIME_ID) && \ - !defined(__EMSCRIPTEN__) && !defined(__wasi__) + !defined(__EMSCRIPTEN__) && !defined(__wasi__) && \ + !defined(__NetBSD__) #define HAVE_THREAD_TIME #if defined(__APPLE__) && _Py__has_attribute(availability) From 9473b4e823e782714e7de3aed2447bb3f0778d4e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 18 Sep 2024 08:38:45 +0300 Subject: [PATCH 3/4] Update Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst Co-authored-by: Furkan Onder --- .../next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst b/Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst index 105aa7eaed9fd4..e5b3229122b509 100644 --- a/Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst +++ b/Misc/NEWS.d/next/Library/2024-09-16-12-31-48.gh-issue-123978.z3smEu.rst @@ -1 +1 @@ -Remove broken :func:`time.thread_time` on NetBSD. +Remove broken :func:`time.thread_time` and :func:`time.thread_time_ns` on NetBSD. From 98a52362f40080241cba94a6df0a9f438c4d2bd0 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 18 Sep 2024 09:14:48 +0300 Subject: [PATCH 4/4] Add comments and fix some conditions. --- Modules/timemodule.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index c124fe5cb2bc7c..ee59fb73ac1e31 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1288,9 +1288,14 @@ py_process_time(time_module_state *state, PyTime_t *tp, /* clock_gettime */ // gh-115714: Don't use CLOCK_PROCESS_CPUTIME_ID on WASI. +/* CLOCK_PROF is defined on NetBSD, but not supported. + * CLOCK_PROCESS_CPUTIME_ID is broken on NetBSD for the same reason as + * CLOCK_THREAD_CPUTIME_ID (see comment below). + */ #if defined(HAVE_CLOCK_GETTIME) \ && (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF)) \ - && !defined(__wasi__) + && !defined(__wasi__) \ + && !defined(__NetBSD__) struct timespec ts; if (HAVE_CLOCK_GETTIME_RUNTIME) { @@ -1483,8 +1488,14 @@ _PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info) return 0; } +/* CLOCK_THREAD_CPUTIME_ID is broken on NetBSD: the result of clock_gettime() + * includes the sleeping time, that defeats the purpose of the clock. + * Also, clock_getres() does not support it. + * https://github.com/python/cpython/issues/123978 + * https://gnats.netbsd.org/57512 + */ #elif defined(HAVE_CLOCK_GETTIME) && \ - defined(CLOCK_PROCESS_CPUTIME_ID) && \ + defined(CLOCK_THREAD_CPUTIME_ID) && \ !defined(__EMSCRIPTEN__) && !defined(__wasi__) && \ !defined(__NetBSD__) #define HAVE_THREAD_TIME