OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
To: vasileios.almpanis@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH vz10 v2 3/3] selftests: timers: measure each timer on the clock it is armed with
Date: Mon, 21 Sep 2026 23:46:30 +0300	[thread overview]
Message-ID: <20260921204643.2692341-4-eva.kurchatova@virtuozzo.com> (raw)
In-Reply-To: <20260921204643.2692341-1-eva.kurchatova@virtuozzo.com>

Commit b00385b8d081 ("selftests/posix_timers: Use CLOCK_THREAD_CPUTIME_ID
for ITIMER_PROF measurements") gave ITIMER_PROF the clock it counts, as
measuring a cpu timer against the wall says nothing on a machine where
the task does not have a cpu to itself.  The other timers are still
measured against CLOCK_REALTIME and fail the same way.  With four busy
loops on the two cpus of a test machine:

  not ok 2 ITIMER_VIRTUAL
  not ok 5 timer_create() per CLOCK_THREAD_CPUTIME_ID
  not ok 6 timer_create() per CLOCK_PROCESS_CPUTIME_ID

ITIMER_VIRTUAL counts the time the task spends in userspace, so take
CLOCK_THREAD_CPUTIME_ID for it as well; the loop it runs stays in
userspace, so what that clock adds for system time is far inside the
half a second the check allows.  check_timer_create() arms its timer on
the clock it is given, so measure on that one.

ITIMER_REAL is armed with CLOCK_MONOTONIC, in fork.c:

  hrtimer_setup(&sig->real_timer, it_real_fn, CLOCK_MONOTONIC,
                HRTIMER_MODE_REL);

so measure it on that rather than on CLOCK_REALTIME, which a step of the
wall clock would carry away from the timer it is timing.  All three arms
now choose a clock, so they read better as a switch, which also gives
the unknown case somewhere to go.

The test passes whole on that machine, 19 of 19, busy or idle.

https://virtuozzo.atlassian.net/browse/VSTOR-143363
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
 tools/testing/selftests/timers/posix_timers.c | 21 +++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index 077a98fb1b1d..f5a92ede3a6d 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -108,18 +108,27 @@ static void check_itimer(int which, const char *name)
 	struct itimerval val = {
 		.it_value.tv_sec = DELAY,
 	};
-	int clock_id = CLOCK_REALTIME;
+	int clock_id;
 
 	done = 0;
 
-	if (which == ITIMER_VIRTUAL)
+	/* Measure each timer on the clock the kernel arms it with. */
+	switch (which) {
+	case ITIMER_VIRTUAL:
+		clock_id = CLOCK_THREAD_CPUTIME_ID;
 		signal(SIGVTALRM, sig_handler);
-	else if (which == ITIMER_PROF) {
+		break;
+	case ITIMER_PROF:
 		clock_id = CLOCK_THREAD_CPUTIME_ID;
 		signal(SIGPROF, sig_handler);
-	}
-	else if (which == ITIMER_REAL)
+		break;
+	case ITIMER_REAL:
+		clock_id = CLOCK_MONOTONIC;
 		signal(SIGALRM, sig_handler);
+		break;
+	default:
+		fatal_error(name, "unknown itimer");
+	}
 
 	if (clock_gettime(clock_id, &start))
 		fatal_error(name, "clock_gettime()");
@@ -146,7 +155,7 @@ static void check_timer_create(int which, const char *name)
 	struct itimerspec val = {
 		.it_value.tv_sec = DELAY,
 	};
-	int clock_id = CLOCK_REALTIME;
+	int clock_id = which;
 	timer_t id;
 
 	done = 0;
-- 
2.55.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-09-21 20:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 20:46 [Devel] [PATCH vz10 v2 0/3] selftests: timers: raw_skew fixes Eva Kurchatova
2026-09-21 20:46 ` [Devel] [PATCH vz10 v2 1/3] ms/selftests/posix_timers: Use CLOCK_THREAD_CPUTIME_ID for ITIMER_PROF measurements Eva Kurchatova
2026-09-21 20:46 ` [Devel] [PATCH vz10 v2 2/3] selftests: timers: count what tick is worth in the drift estimate Eva Kurchatova
2026-09-21 20:46 ` Eva Kurchatova [this message]
2026-09-23 17:49 ` [Devel] [PATCH vz10 v2 0/3] selftests: timers: raw_skew fixes Konstantin Khorenko
2026-09-23 17:53 ` Konstantin Khorenko

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=20260921204643.2692341-4-eva.kurchatova@virtuozzo.com \
    --to=eva.kurchatova@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=vasileios.almpanis@virtuozzo.com \
    /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