From: Petr Vorel <pvorel@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH] clock_settime: use POSIX runtime detection for CLOCK_MONOTONIC
Date: Fri, 17 Apr 2026 14:53:22 +0200 [thread overview]
Message-ID: <20260417125322.GA419619@pevik> (raw)
In-Reply-To: <20260416-fix_clock_settime_helper-v1-1-2874202291bf@suse.com>
> From: Andrea Cervesato <andrea.cervesato@suse.com>
> The clock_settime helpers.h used a compile-time #ifdef on
> _POSIX_MONOTONIC_CLOCK to select between real and stub
> implementations of pts_mono_time_start()/pts_mono_time_check().
> On Linux/glibc, _POSIX_MONOTONIC_CLOCK is defined as 0, meaning
> support is optional and must be verified at runtime via
> sysconf(_SC_MONOTONIC_CLOCK). The #ifdef treated 0 the same as
> >0 (always available), which is not POSIX-correct.
> Replace the compile-time #ifdef/#else split with a runtime
> pts_mono_available() helper that performs proper POSIX detection
> via sysconf(). Also add a missing #ifndef include guard and
> #include <unistd.h> so _POSIX_MONOTONIC_CLOCK is always defined.
> Fixes: 9ecb4a004b18 ("clock_settime: Detect external clock adjustments via CLOCK_MONOTONIC")
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> .../conformance/interfaces/clock_settime/helpers.h | 76 +++++++++++++---------
> 1 file changed, 46 insertions(+), 30 deletions(-)
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/helpers.h b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/helpers.h
> index 37bf30926f039553e9e370751b7938ca5ea1d00a..b568ec8122d3bba8246b09a5b694f1263084a408 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/helpers.h
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/helpers.h
> @@ -13,7 +13,11 @@
> * by those tests.
> */
> +#ifndef CLOCK_SETTIME_HELPERS_H
> +#define CLOCK_SETTIME_HELPERS_H
> +
> #include <stdlib.h>
> +#include <unistd.h>
> static int getBeforeTime(struct timespec *tpget)
> {
> @@ -37,53 +41,65 @@ static int setBackTime(struct timespec tpset)
> #define PTS_MONO_MAX_RETRIES 3
> +static struct timespec pts_mono_start;
> +
> +static inline int pts_mono_available(void)
> +{
> #ifdef _POSIX_MONOTONIC_CLOCK
> -static struct timespec _pts_mono_start;
> + if (_POSIX_MONOTONIC_CLOCK > 0)
> + return 1;
> +
> + if (!_POSIX_MONOTONIC_CLOCK && sysconf(_SC_MONOTONIC_CLOCK) > 0)
This and the previous condition is the same as in patch for nanosleep.
It's a simple code, but because it's still a bit specific, wouldn't it make
sense to move the function from nanosleep/helpers.h [1]
to newly created file in testcases/open_posix_testsuite/include/clock.h?
And both tests would use it?
Kind regards,
Petr
[1] https://patchwork.ozlabs.org/project/ltp/patch/20260416-fix_nanosleep_include-v2-1-b3147763acb8@suse.com/
> + return 1;
> +#endif
> + return 0;
> +}
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2026-04-17 12:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 13:01 [LTP] [PATCH] clock_settime: use POSIX runtime detection for CLOCK_MONOTONIC Andrea Cervesato
2026-04-16 13:35 ` [LTP] " linuxtestproject.agent
2026-04-17 12:53 ` Petr Vorel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260417125322.GA419619@pevik \
--to=pvorel@suse.cz \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox