From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id DB4CF8017D for ; Mon, 21 Sep 2026 20:48:13 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68LKks6V010820; Mon, 21 Sep 2026 23:46:55 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68LKks6V010820 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="SfU87SMn" Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68LKkomG010806 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 21 Sep 2026 23:46:50 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68LKkomG010806 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-495689bfcc8so25576505e9.1 for ; Mon, 21 Sep 2026 13:46:50 -0700 (PDT) X-Gm-Message-State: AFuF++lqjjH0jdqnzgOjrWIwAe/CtymB1/usNXlM3ny00cKJrvI3fera 3B6vRqj5IDXrqoTPonLenYfV2C7kZwGdqIx3IG4WkpaD6r8U17qQm9eP8SDydrcCC6xZcrZ10l9 qyBdCMLycCBaLkqEE+3chlkzP34tHQUGcK5DXaif30pi5tUgaC5De/w== X-Gm-Gg: AYBFou2FKCfvN/IRvq9GRd6iccwKnk7g8uR5ucJt9D29tFEXV7jSJmwmml1HMGWZkZK WMZpkZ31ZdT48cLYFV2jp8C7Zh4d/43PuMBTz/hI2AyRNHTpoUTs7rEJh90R7EZW8bmw+nr4E3Q x6gopxPoyh4KN9CDxi8jMM0Cdtqq4Nqf+AUXqk9JxVQV6T8uEV3UAxJC4X9QuBFfQZchVTp5o8H iB3cKWnIVN1z/mSJdJb9C4ZOVqkklhc8nU80E7FfY/HUwpmjU8o191pd/n/tVwWyPzlnmrlDQMz 0jLwPMobDEvtneg1BPfnbnccgNluVP/fjrKziuigOTAtdBcKvnTWRyXKsFXN6mrLlGmujcWcvnE VIl+izAmM7sVoM+X3bszaBAKl X-Received: by 2002:a05:600c:19c6:b0:49c:f4e1:4c2d with SMTP id 5b1f17b1804b1-49fc5741239mr180087075e9.16.1790023610160; Mon, 21 Sep 2026 13:46:50 -0700 (PDT) X-Received: by 2002:a05:600c:19c6:b0:49c:f4e1:4c2d with SMTP id 5b1f17b1804b1-49fc5741239mr180086865e9.16.1790023609649; Mon, 21 Sep 2026 13:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1790023609; cv=none; d=google.com; s=arc-20260327; b=k75iCslRplCVzIt3PvA355gYRvfRo1fYYU/9ZuHAoJFO9R29jRqMR0vGsjWxbw+4Xx t8Iq7PFsemy/Aum3/eDlPJHqOgSuT+PtY5X61APk0Izeg7r8YFhzP5VoYOZUYFDtkQGL AOXGKZTMRFtY4nWE7kmShm97Ca0J7YAw0wy5EXZRYouFUzUwTBTbuO5tc97bvMGycSuq 8zE/bOba3vzlWgoCVYoe+QEpQO8R2oVDqfwp1HHaKRQQslnGLx41JpgXCenZjL8MGQwX bPMxe+HxUCwZt7mbmmYGxKGWKhE3cwow4ghWL6IKvh2tJQ7wzxWv/fGpNQ1M0RILmSdG TAJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=BxU197/xdK+3kM7/TTKEw9WhiONZplQR4h7HBkbxoQ8=; fh=bRmlDJ6vflC8xapCpe8SIKiBemLWBr+xozKix8GBr/Q=; b=h3d6XCLHtPKacDsYklBUDeMhYL93cPlBr1AWT3zJEEBbGSHLQF5vjZb72gyXiBeX0d xr1sNQUoj+Nrdzt5qLYBrHhbzzAgIzT+fb6NUMpZLXnuafbMbY+M1bSo049YVQANT2RG QHxgIgMgHmX0vfRtXmNLc+ckS/THAd61ekfzbYuSKSX6EexTpdnhwF5yU11MDBfOPquJ BKC3YadpAB8gagGJCTDow67gOO6w26K6jxQLuQ3wHL58jK70tegyqiBml0PtgQ/nNdYW noDYakD7PF856e/JsXDXlfmumLukITbrD0vlsW8pPOC8N+QcQ1vwMNoB7veQCUPg6/F9 SFCQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=SfU87SMn; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4886225dc15si49760f8f.463.2026.09.21.13.46.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2026 13:46:49 -0700 (PDT) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=SfU87SMn; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=BxU197/xdK+3kM7/TTKEw9WhiONZplQR4h7HBkbxoQ8=; b=SfU87SMnp/44 FM/Zneuk4TuV3ubnsSydMPGWQV82/CEvtMjh9dCOUvNz742WliQ1CjooFVNWNQhC8rn5E/IxF35kf ptLmV41bMD7l425W2Yoq2Sbkjv0y/RnBS0a/T1mB1pCEohYIBuRDDiCXy7uCX+4WFcSsmaV2dMvDa hf8buFxKMxsfIMr0hJ/ql4t0jmCP74qeYWaTolw9DnbbNhxchGhGJ5n1WiTGrp7hzWFt8Lkwa/W2a 8w5fn59n1QcvAGSF0uto7C/tKZEjVdTkntpBSt4DmWv2i1U09nY/La0s855qTZSperW+KvX8WEZw2 VifBBDGcbAQEWC9LiuZ8DQ==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1x8kre-009pCP-2l; Mon, 21 Sep 2026 22:46:40 +0200 From: Eva Kurchatova To: vasileios.almpanis@virtuozzo.com Date: Mon, 21 Sep 2026 23:46:28 +0300 Message-ID: <20260921204643.2692341-2-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260921204643.2692341-1-eva.kurchatova@virtuozzo.com> References: <20260921204643.2692341-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH vz10 v2 1/3] ms/selftests/posix_timers: Use CLOCK_THREAD_CPUTIME_ID for ITIMER_PROF measurements X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: John Stultz It was reported that the posix_timers test was at times seeing failures with ITIMER_PROF timers, specifically in cases where the RCU_SOFTIRQ was taking up significant amounts of time. Analysis showed that as the time in softirq isn't included in the task stime + utime accounting used to trigger the SIGPROF so delays from softirq work could cause it to appear that the signal was incorrectly delayed. Contributing to this is that the test uses gettimeofday() to measure itimers, which also means any scheduling delay can also cause failures (as the task may not be running the entire time). To fix this, convert all the itimer measurements to use clock_gettime(), tweaking the logic to use nsecs instead of usecs. Then for ITIMER_PROF timers, utilize the CLOCK_THREAD_CPUTIME_ID clockid so that it is similarly measuring the time the task was running. Signed-off-by: John Stultz Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/20260428173957.1394265-1-jstultz@google.com The ITIMER_PROF case of it fails on the CI machines, which are two cpu guests under load: # Diff too high: 2561992..not ok 3 ITIMER_PROF 2.56 seconds of wall time for the 2 seconds of cpu time the timer counts, so the task had about four fifths of a cpu. (cherry picked from commit b00385b8d081ce74f36ea178e04e1b106505fb36) https://virtuozzo.atlassian.net/browse/VSTOR-143363 Feature: fix selftests Signed-off-by: Eva Kurchatova --- tools/testing/selftests/timers/posix_timers.c | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c index f0eceb0faf34..077a98fb1b1d 100644 --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -77,19 +77,25 @@ static void sig_handler(int nr) done = 1; } +static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2) +{ + int64_t diff; + + diff = NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec); + diff += ((int) t1.tv_nsec - (int) t2.tv_nsec); + return diff; +} + /* * Check the expected timer expiration matches the GTOD elapsed delta since * we armed the timer. Keep a 0.5 sec error margin due to various jitter. */ -static int check_diff(struct timeval start, struct timeval end) +static int check_diff(struct timespec start, struct timespec end) { - long long diff; - - diff = end.tv_usec - start.tv_usec; - diff += (end.tv_sec - start.tv_sec) * USEC_PER_SEC; + long long diff = calcdiff_ns(end, start); - if (llabs(diff - DELAY * USEC_PER_SEC) > USEC_PER_SEC / 2) { - printf("Diff too high: %lld..", diff); + if (llabs(diff - DELAY * NSEC_PER_SEC) > NSEC_PER_SEC / 2) { + printf("Diff too high: %lld ns..", diff); return -1; } @@ -98,22 +104,25 @@ static int check_diff(struct timeval start, struct timeval end) static void check_itimer(int which, const char *name) { - struct timeval start, end; + struct timespec start, end; struct itimerval val = { .it_value.tv_sec = DELAY, }; + int clock_id = CLOCK_REALTIME; done = 0; if (which == ITIMER_VIRTUAL) signal(SIGVTALRM, sig_handler); - else if (which == ITIMER_PROF) + else if (which == ITIMER_PROF) { + clock_id = CLOCK_THREAD_CPUTIME_ID; signal(SIGPROF, sig_handler); + } else if (which == ITIMER_REAL) signal(SIGALRM, sig_handler); - if (gettimeofday(&start, NULL) < 0) - fatal_error(name, "gettimeofday()"); + if (clock_gettime(clock_id, &start)) + fatal_error(name, "clock_gettime()"); if (setitimer(which, &val, NULL) < 0) fatal_error(name, "setitimer()"); @@ -125,18 +134,19 @@ static void check_itimer(int which, const char *name) else if (which == ITIMER_REAL) idle_loop(); - if (gettimeofday(&end, NULL) < 0) - fatal_error(name, "gettimeofday()"); + if (clock_gettime(clock_id, &end)) + fatal_error(name, "clock_gettime()"); ksft_test_result(check_diff(start, end) == 0, "%s\n", name); } static void check_timer_create(int which, const char *name) { - struct timeval start, end; + struct timespec start, end; struct itimerspec val = { .it_value.tv_sec = DELAY, }; + int clock_id = CLOCK_REALTIME; timer_t id; done = 0; @@ -147,16 +157,16 @@ static void check_timer_create(int which, const char *name) if (signal(SIGALRM, sig_handler) == SIG_ERR) fatal_error(name, "signal()"); - if (gettimeofday(&start, NULL) < 0) - fatal_error(name, "gettimeofday()"); + if (clock_gettime(clock_id, &start)) + fatal_error(name, "clock_gettime()"); if (timer_settime(id, 0, &val, NULL) < 0) fatal_error(name, "timer_settime()"); user_loop(); - if (gettimeofday(&end, NULL) < 0) - fatal_error(name, "gettimeofday()"); + if (clock_gettime(clock_id, &end)) + fatal_error(name, "clock_gettime()"); ksft_test_result(check_diff(start, end) == 0, "timer_create() per %s\n", name); @@ -444,15 +454,6 @@ static void check_delete(void) ksft_test_result(!tsig.signals, "check_delete\n"); } -static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2) -{ - int64_t diff; - - diff = NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec); - diff += ((int) t1.tv_nsec - (int) t2.tv_nsec); - return diff; -} - static void check_sigev_none(int which, const char *name) { struct timespec start, now; -- 2.55.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel