All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v4] clock_settime: use POSIX runtime detection for CLOCK_MONOTONIC
Date: Mon, 4 May 2026 11:54:41 +0200	[thread overview]
Message-ID: <afhs4WvcNbp1msPY@yuki.lan> (raw)
In-Reply-To: <20260504-fix_clock_settime_helper-v4-1-403149f43d30@suse.com>

Hi!
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <time.h>
> +#include <unistd.h>
> +
> +static inline int pts_mono_available(void)
> +{
> +#ifdef CLOCK_MONOTONIC

This one should have stayed _POSIX_MONOTONIC_CLOCK since we are doing a
presence checks and the -1 is correctly handled here (we get to return 0
case in this case).

> +	if (_POSIX_MONOTONIC_CLOCK > 0)
> +		return 1;
> +
> +	if (!_POSIX_MONOTONIC_CLOCK && sysconf(_SC_MONOTONIC_CLOCK) > 0)
> +		return 1;
> +#endif
> +	return 0;
> +}
> +
> +#define PTS_MONO_MAX_RETRIES 3
> +
> +static struct timespec pts_mono_start;
> +
> +static inline int pts_mono_time_start(void)
> +{
> +	if (!pts_mono_available()) {
> +		static int warned;
> +
> +		if (!warned) {
> +			printf("CLOCK_MONOTONIC unavailable, test may fail due to clock adjustment\n");
> +			warned = 1;
> +		}
> +		return 0;
> +	}
> +
> +#ifdef CLOCK_MONOTONIC
> +	if (clock_gettime(CLOCK_MONOTONIC, &pts_mono_start) != 0) {
> +		perror("clock_gettime(CLOCK_MONOTONIC) failed");
> +		return -1;
> +	}
> +#endif

These are guarding againts compilation failures and looks fine to me
now.

> +	return 0;
> +}
> +
> +static inline int pts_mono_time_check(unsigned int expected_secs)
> +{
> +#ifdef CLOCK_MONOTONIC
> +	if (pts_mono_available()) {
> +		struct timespec now;
> +		long elapsed;
> +
> +		if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) {
> +			perror("clock_gettime(CLOCK_MONOTONIC) failed");
> +			return -1;
> +		}
> +
> +		elapsed = now.tv_sec - pts_mono_start.tv_sec;
> +
> +		if (labs(elapsed - (long)expected_secs) > 1) {
> +			printf("Clock adjustment detected (elapsed %lds, expected ~%us)\n",
> +			       elapsed, expected_secs);
> +			return 1;
> +		}
> +		return 0;
> +	}
> +#endif
> +	(void)expected_secs;
> +	return 0;
> +}
> +
> +#endif /* PTS_CLOCK_H */
> 
> ---
> base-commit: 73cfad509db014e5a631bd2298f4e9d8ea3ee1c1
> change-id: 20260429-fix_clock_settime_helper-7670708ed94f
> 
> Best regards,
> -- 
> Andrea Cervesato <andrea.cervesato@suse.com>
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2026-05-04  9:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-04  9:39 [LTP] [PATCH v4] clock_settime: use POSIX runtime detection for CLOCK_MONOTONIC Andrea Cervesato
2026-05-04  9:54 ` Cyril Hrubis [this message]
2026-05-04 10:22   ` Andrea Cervesato via ltp
2026-05-04 10:24     ` Cyril Hrubis
2026-05-04 10:31       ` Andrea Cervesato via ltp

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=afhs4WvcNbp1msPY@yuki.lan \
    --to=chrubis@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.