Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp482759lqp; Mon, 10 Jun 2024 09:43:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpPJ9GXENKpqlw4HIUGbJzFGxH0Pkwh20VybYEmcs2jBT0E41qlo3AnIRlKwAGEHdPHBpn6m6CXSjw3rHO04XEiI5nVCIFQ9odMgTVjw== X-Google-Smtp-Source: AGHT+IEehwfxt5082d1fXPQedAdHCqfWXA7d3DPPJUmIpy7xOXwmKX+hUD4hKg8ylXA2XMBEiRWp X-Received: by 2002:a17:902:c94c:b0:1f3:453f:1372 with SMTP id d9443c01a7336-1f6d02fe4camr115987675ad.30.1718037818245; Mon, 10 Jun 2024 09:43:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718037818; cv=pass; d=google.com; s=arc-20160816; b=cxq/uGseFiwhntSqX1uwj6yZV2qwh37pbHJvfhOrcsIiOMl45tX4Hgh3RX4hZKW1K/ VumOnB3gZfu8W8AZee6iQ3iFMrMqjUWVdCtuzqUUB7XlI3IMsWfu6EjTGFqbofSCsrPm RvJTOsNWSkpRJxNIoQjmitqV51Ybik2/fQrHQxkfzwynbn0IvTyns8cVnMgzEUR6gVPu L5QHR4su3sGq8dwhcVGeyT9GRTdU8Ef/jf7CpwZTUGR/HXZ7dulAGC61lUryTJrqjpS8 Koq7cGlB+fY2pU6/hsomeaZzhpbBequlqQyaM8qqdJVtODFdys9PkdL+OeP2U+dVECbJ 98mQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=7n8Tw6w2v5Y162ZsOpKlDwSopUc0/cD/VnEumBQN9lE=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=lGImD0cnU5fNQ3QzISTHJOrlXZiXZRyfxlTevmkERHpUukgFHUZHlCLyJO514owcL6 nl/QzbzcAz2P2rKtxX+CNnTPDV4ZsAv6ik4VfJd5b3mCGtEqX+nuXpR5o34WiqflEkz+ A6718w7V3Mip06Rr9lCrw+7PebVI2TOuY7Y9+W2mENCqhfcaODNM30IyiFL5iILacXgM sGMe9oluKH0bGdOkFSEVG6wnk/98MUmppq03NANK5XFOQi6+xycAf1CU4IYo0n5yKyDi 7Pbhl/dsBCUt2BZiBHSoM7fJgYR8nsv22h+/ecNYK7yS76yR8umXuMgGP95noDPux35Q ETJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bvhOmmGk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f71b503f16si13271565ad.490.2024.06.10.09.43.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 09:43:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bvhOmmGk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 47C982862B2 for ; Mon, 10 Jun 2024 16:43:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E6A414D422; Mon, 10 Jun 2024 16:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bvhOmmGk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="54xHgEiE" 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 92B581474B9 for ; Mon, 10 Jun 2024 16:42:18 +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=1718037740; cv=none; b=awrs9MijhTrQW/Vbbc6OtMZEm+kFiwU+R3m+KT0APLoFWlUdmTWr/K5BLhLkyHMziOhc55DhSHtcd01NjYgrJor1/NGOGl9oLPfKObl+ZdQPUrlzgEofLELV6GdWU76y85rfpIePpFlDg8OmFz9XfYNNYmMpNRlJZ2uF2O5L2yk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037740; c=relaxed/simple; bh=Qw6a6vr3job2BPNhi3+9A2NeMwWriv1M9zdK8XeX/E8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=hiZQJvA0lV7aXgJCEWZMCoK8s3xVXk8YYEgL49GWwUNlmbf02bcD9lzZrm6M2sU3Xa++BAKnnSgEzfl9jXUvabhmMVYinbawZ7fTP1jrImBRfsay/5ntPIzWNqaz2pRzUyqj2QjLd7DJQLRPWJKHqTUhpdZjJLL1pvjrQ8R/g58= 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=bvhOmmGk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=54xHgEiE; 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 Message-ID: <20240610164025.770458477@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718037731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=7n8Tw6w2v5Y162ZsOpKlDwSopUc0/cD/VnEumBQN9lE=; b=bvhOmmGkK5yGsZZv+PH4sh94JC14KGR+imMTHgyuHuNvk/GI8R5d3X734tdrTOvUsAs8RH 5FH4dxdMRdo1VIVSXoUImREQCti9+rYHlTKJeYaHnnVbUIN1iPcJqFPJMePZ7iGphkRtPO yElJGm7TMRmyVTdQp30R1TDARAqMXhaRP2WptHSd6UMzKMlVN9mqmfIHx9u8S6gaysEiDV YfsSYzXLaiBp7A7IpyZfmlI4ehGaGEthPclcAJZEG0PZoGK3JPRXwBMLgP0ZFlNML3gZQS 7ynGXXl+/70NMnoDviFFevsMXdJfiSEMwhT+XEiJFxb8zHO+iRu03YpBdjL2Ug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718037731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=7n8Tw6w2v5Y162ZsOpKlDwSopUc0/cD/VnEumBQN9lE=; b=54xHgEiEfEPgGVu+cv242Ke+UqUqvtMChDKDI8HmYZQOcy2xIiOaFI8MbnRVc7ekb5/U7a IrTCdoiHv4D3fcAA== From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch V3 05/51] selftests/timers/posix-timers: Validate timer_gettime() References: <20240610163452.591699700@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 10 Jun 2024 18:42:11 +0200 (CEST) timer_gettime() must return the correct expiry time for interval timers even when the timer is not armed, which is the case when a signal is pending but blocked. Works correctly for regular posix timers, but not for posix CPU timers. Add a selftest to validate the fixes. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 58 +++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -487,10 +487,63 @@ static void check_sigev_none(int which, "check_sigev_none %s\n", name); } +static void check_gettime(int which, const char *name) +{ + struct itimerspec its, prev; + struct timespec start, now; + struct sigevent sev; + timer_t timerid; + int wraps = 0; + sigset_t set; + + /* Block the signal */ + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + if (sigprocmask(SIG_BLOCK, &set, NULL)) + fatal_error(name, "sigprocmask(SIG_BLOCK)"); + + memset(&sev, 0, sizeof(sev)); + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGUSR1; + + if (timer_create(which, &sev, &timerid)) + fatal_error(name, "timer_create()"); + + /* Start the timer to expire in 100ms and 100ms intervals */ + its.it_value.tv_sec = 0; + its.it_value.tv_nsec = 100000000; + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 100000000; + if (timer_settime(timerid, 0, &its, NULL)) + fatal_error(name, "timer_settime()"); + + if (timer_gettime(timerid, &prev)) + fatal_error(name, "timer_gettime()"); + + if (clock_gettime(which, &start)) + fatal_error(name, "clock_gettime()"); + + do { + if (clock_gettime(which, &now)) + fatal_error(name, "clock_gettime()"); + if (timer_gettime(timerid, &its)) + fatal_error(name, "timer_gettime()"); + if (its.it_value.tv_nsec > prev.it_value.tv_nsec) + wraps++; + prev = its; + + } while (calcdiff_ns(now, start) < NSECS_PER_SEC); + + if (timer_delete(timerid)) + fatal_error(name, "timer_delete()"); + + ksft_test_result(wraps > 1, "check_gettime %s\n", name); +} + int main(int argc, char **argv) { ksft_print_header(); - ksft_set_plan(12); + ksft_set_plan(15); ksft_print_msg("Testing posix timers. False negative may happen on CPU execution \n"); ksft_print_msg("based timers if other threads run on the CPU...\n"); @@ -518,6 +571,9 @@ int main(int argc, char **argv) check_delete(); check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); + check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); + check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); + check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID"); ksft_finished(); }