From nobody Sat Jun 13 17:08:19 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A138936EAB0; Wed, 6 May 2026 07:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778051500; cv=none; b=RATbtDcQ62c5rTmtV7nbAfK89dXHkHplMeFO6ExIXOHVHqixNb1PYb6GwmEQFryiZVTvaZwd82gjVixKRGq6G9oPUKcFzK1QZ8Mwqov1u6GHZif29kTF9HUfGLwPzwCq0R1SqBDtaMOFAjxjPb53u5YrSLlfL4BSHkP9ZNOf6Fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778051500; c=relaxed/simple; bh=yy2lerGFrz4idHhR6osiAI9dx9yofU0rsLjifJyDK+0=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=hMaxGoh4/KB9go5idb6BNAkgXc3I5lUp/Zjxkv2FFkJiprh8WDtt6o/xxo+Gl9YwdN2klikR3qke1tqm7yA9o/F40ND5JfBWz9EYLAZrndx9pMCFf5/PTu6O2bdEzUe9KaNR97dQuQxAuyHQPV4dLIfwwquYn33mnovebQCUOtQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cN29xvI+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=r7vt0l4g; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cN29xvI+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="r7vt0l4g" Date: Wed, 06 May 2026 07:11:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1778051497; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wpcz9m2vlU2kwCIOxCYJLaCI4TRHSQPZTEQCB+csLR0=; b=cN29xvI+tOvuLvTf+V0epm4P2VG04SSH9OeNm4yzlHNff44JSrAowvGlEaVpm1VZ2MTQr+ 20j9W1qpVCDfEwnrFco5l5VzYsV/5VsUA7EygDFzYzWOZsxMNlCXxJSZu5S260f82Grg81 2t10XsKT7efKsh4preobp2GBwGadwl26j5UG2g2bIQp65r6B5aa5mUZ7GuyCcIh42lVP2p 8ZMOKVOg2ZWhNu1Bbt/gTys2L2m1sNNUh/ImWDvrMNtoKgLKgffigh9nfW4frgUK5Exh+t mzoBhev5uNB44/RHNB+t/jhr4N1kPMUdxAyPI8c2TpEQg09cx6r9MG1CQKm8Kw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1778051497; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wpcz9m2vlU2kwCIOxCYJLaCI4TRHSQPZTEQCB+csLR0=; b=r7vt0l4geb7CUtJcl5mDTpg1+WPW+dbY2QqQBmVNk5QDFd/cq1uVBjZIszhM7joIQHNC4p Yf1N2FDZ/YZcZgAA== From: "tip-bot2 for John Stultz" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] selftests/posix_timers: Use CLOCK_THREAD_CPUTIME_ID for ITIMER_PROF measurements Cc: John Stultz , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260428173957.1394265-1-jstultz@google.com> References: <20260428173957.1394265-1-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177805149584.424702.13715833280881299991.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the timers/core branch of tip: Commit-ID: b00385b8d081ce74f36ea178e04e1b106505fb36 Gitweb: https://git.kernel.org/tip/b00385b8d081ce74f36ea178e04e1b106= 505fb36 Author: John Stultz AuthorDate: Tue, 28 Apr 2026 17:39:46=20 Committer: Thomas Gleixner CommitterDate: Wed, 06 May 2026 08:33:08 +02:00 selftests/posix_timers: Use CLOCK_THREAD_CPUTIME_ID for ITIMER_PROF measure= ments 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 --- 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 3851262..2f3bac9 100644 --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -78,19 +78,25 @@ static void sig_handler(int nr) done =3D 1; } =20 +static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2) +{ + int64_t diff; + + diff =3D NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec); + diff +=3D ((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 =3D end.tv_usec - start.tv_usec; - diff +=3D (end.tv_sec - start.tv_sec) * USEC_PER_SEC; + long long diff =3D calcdiff_ns(end, start); =20 - 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; } =20 @@ -99,22 +105,25 @@ static int check_diff(struct timeval start, struct tim= eval end) =20 static void check_itimer(int which, const char *name) { - struct timeval start, end; + struct timespec start, end; struct itimerval val =3D { .it_value.tv_sec =3D DELAY, }; + int clock_id =3D CLOCK_REALTIME; =20 done =3D 0; =20 if (which =3D=3D ITIMER_VIRTUAL) signal(SIGVTALRM, sig_handler); - else if (which =3D=3D ITIMER_PROF) + else if (which =3D=3D ITIMER_PROF) { + clock_id =3D CLOCK_THREAD_CPUTIME_ID; signal(SIGPROF, sig_handler); + } else if (which =3D=3D ITIMER_REAL) signal(SIGALRM, sig_handler); =20 - if (gettimeofday(&start, NULL) < 0) - fatal_error(name, "gettimeofday()"); + if (clock_gettime(clock_id, &start)) + fatal_error(name, "clock_gettime()"); =20 if (setitimer(which, &val, NULL) < 0) fatal_error(name, "setitimer()"); @@ -126,18 +135,19 @@ static void check_itimer(int which, const char *name) else if (which =3D=3D ITIMER_REAL) idle_loop(); =20 - if (gettimeofday(&end, NULL) < 0) - fatal_error(name, "gettimeofday()"); + if (clock_gettime(clock_id, &end)) + fatal_error(name, "clock_gettime()"); =20 ksft_test_result(check_diff(start, end) =3D=3D 0, "%s\n", name); } =20 static void check_timer_create(int which, const char *name) { - struct timeval start, end; + struct timespec start, end; struct itimerspec val =3D { .it_value.tv_sec =3D DELAY, }; + int clock_id =3D CLOCK_REALTIME; timer_t id; =20 done =3D 0; @@ -148,16 +158,16 @@ static void check_timer_create(int which, const char = *name) if (signal(SIGALRM, sig_handler) =3D=3D SIG_ERR) fatal_error(name, "signal()"); =20 - if (gettimeofday(&start, NULL) < 0) - fatal_error(name, "gettimeofday()"); + if (clock_gettime(clock_id, &start)) + fatal_error(name, "clock_gettime()"); =20 if (timer_settime(id, 0, &val, NULL) < 0) fatal_error(name, "timer_settime()"); =20 user_loop(); =20 - if (gettimeofday(&end, NULL) < 0) - fatal_error(name, "gettimeofday()"); + if (clock_gettime(clock_id, &end)) + fatal_error(name, "clock_gettime()"); =20 ksft_test_result(check_diff(start, end) =3D=3D 0, "timer_create() per %s\n", name); @@ -445,15 +455,6 @@ static void check_delete(void) ksft_test_result(!tsig.signals, "check_delete\n"); } =20 -static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2) -{ - int64_t diff; - - diff =3D NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec); - diff +=3D ((int) t1.tv_nsec - (int) t2.tv_nsec); - return diff; -} - static void check_sigev_none(int which, const char *name) { struct timespec start, now;