Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp482635lqp; Mon, 10 Jun 2024 09:43:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9I3WLz7W9Zq/XlzHkVsTIhspNF8/6rPXZk/SaNfa9HfWHbqk0Z/+h/BK9aipJ01fyNKPCYjgSlQl49JLr9G6FVpruk7chU2h0TpmpqQ== X-Google-Smtp-Source: AGHT+IGFZijELMVBb90J9C4B6V9qz9dcT7jEgPGHOqOjvHsyGg1DSA73Vpsp9CSMRRLpACsYTl4t X-Received: by 2002:a05:6a21:33a8:b0:1b5:69cd:87c with SMTP id adf61e73a8af0-1b569cd093emr8241410637.27.1718037803370; Mon, 10 Jun 2024 09:43:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718037803; cv=pass; d=google.com; s=arc-20160816; b=ysLR9Y99AK3ffIkUMx0ejGOie5CgbHGvpFyT2prCDKh+s/NNxZYEgIUbSHnTzPbWY+ 45uAHSBOIPiTFGujLysbrZc+ucUBYbTHZKpoPRRsRKwUSzc+lY2eSo1vI7PJF5LVv2io +L39Ud+T+U4QBsJgLw0PJH7miI8FOlAOH43gr+0NegVMj3ikzY5n18JkWt3UAZtKKKbK BclnX4WYVl7etI/yDwHmBkCK1hbiM02dKHGSCbS6JjsZMpvPmBW3JWtqyh4xVJgQBYsP be44yTeZGw6lp0wun7/JnTL+l+OZTZ/jh1YhaFsvev+0+2OBat7GF0IrrxfnMqBmE4bz X1EQ== 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=oS7SrzV2Wd9Ag3yMmGtoq7FlROh6d1Si5LvLo/AXQAY=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=u8e7lq4XmGcX8qDK1SwBPFmrdYUbJAaFtajSQKspU4JSieBJXKJcr+8fRsEjeabHzL 5/GPuDk1vnucfhTkZZsgPsNCPMxCNye/iQvoMygCmLpKN3Lx5qodeBKi7YR7RY6JH8Ra P37nGNAgMtxC00n2qcOG2IU9ef9DmyRoEAOclF8y3cl97L2Aiv8BAnLtLZ71L+ol/ONl +hg40K2sAMGVpC7VABjcEil9X+jKtp1lQ1Gj3qOOvkY8DH4rZvEg7cd1ORlpv0RGEoL1 dc9pVVpl4ewQ5T2tMTuIEmbrrNDuTwtPNtmxO0rsdQwFQqeECWgonuqPvOVmhGki2lkp C5vg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SLboMHul; 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-208566-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208566-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. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-70435079291si2940517b3a.34.2024.06.10.09.43.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 09:43:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208566-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SLboMHul; 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-208566-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208566-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 EEEDE2845C9 for ; Mon, 10 Jun 2024 16:42:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC98F14900C; Mon, 10 Jun 2024 16:42:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SLboMHul"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="lZ99rRfz" 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 59F371459E3 for ; Mon, 10 Jun 2024 16:42:17 +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=1718037738; cv=none; b=LYcmu4JnorW7cIwIw4CzeBFMlYIWXJxuZbkrxkuV5wYj2Qreev/cJLPEftGgvgFY7gwUkMJ5yTpJU2olI7bNAURH+X312TyQTu9e369/50MqY8e5/Oo0RHdFG9qXXeL4s1SqbmFS5bkICTvJPLCZKer4vJBGiA0Ciu4bwFJ8Jj8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037738; c=relaxed/simple; bh=Jz7RJXZF/wpnmhSKslp2B8lopo6bOLwGJ9GuQe5xSbw=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=ujLs5UudrZs+jb1cOIFnqefvMzxnVOSMuwC6Vm2yta8ZT/+XJeGdG/JcoKhpuEZhOVArnDuKPTnfz9wNuCrXU3IW4Oohcqqzrs14KXyl1mhj+UnysQ97mQYu1XpGw9eiTNt6qYE+ZZe68M4Ocdy7xSKbo3PPZInjf6CJgdLLj2g= 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=SLboMHul; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=lZ99rRfz; 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.833739199@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718037733; 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=oS7SrzV2Wd9Ag3yMmGtoq7FlROh6d1Si5LvLo/AXQAY=; b=SLboMHulqbAU78PDwvYlC230/wjCP2JGpchgUKhRDuA/m3MKMfrkT2hOA6sG0M6xcAdACp 5BVGhJFhGt5jfV4CzArspK8Xm5ucUFcHyQo5xCs66oVYpHPUsM+WY6IQaivVBTet5xKD0D vfemF24gHqyz4OC0fiJ33VQ0i13b3UZrBRf+ACusWzR184Ez4wy3Bvn6+X5EL6IKfFjMur Yf75OqYbF1yg/eCTUYZwW4P3PFssK4jwlR9izFuTcyOBqeTisuzJTTjuUAJnVQ1waA7i/x jYENJ3xUyQbiDb7Y6orD3hOVb7anqF3v+eCDcE/hwQsGFXD7NuF5Cr8fTI1TeQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718037733; 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=oS7SrzV2Wd9Ag3yMmGtoq7FlROh6d1Si5LvLo/AXQAY=; b=lZ99rRfzJK1+g1S5HZtI3ARgZ0iPRWDgHoy+IjBeWdkwqbJbWB2DGGCx2L3rytgUpkB6WB ENMMZM7iW/aXlPBA== 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 06/51] selftests/timers/posix-timers: Validate overrun after unblock 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:12 +0200 (CEST) When a timer signal is blocked and later unblocked then one signal should be delivered with the correct number of overruns since the timer was queued. Validate that behaviour. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 61 +++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -540,10 +540,66 @@ static void check_gettime(int which, con ksft_test_result(wraps > 1, "check_gettime %s\n", name); } +static void check_overrun(int which, const char *name) +{ + struct timespec start, now; + struct tmrsig tsig = { }; + struct itimerspec its; + struct sigaction sa; + struct sigevent sev; + timer_t timerid; + sigset_t set; + + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = siginfo_handler; + sigemptyset(&sa.sa_mask); + if (sigaction(SIGUSR1, &sa, NULL)) + fatal_error(name, "sigaction()"); + + /* 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; + sev.sigev_value.sival_ptr = &tsig; + 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 (clock_gettime(which, &start)) + fatal_error(name, "clock_gettime()"); + + do { + if (clock_gettime(which, &now)) + fatal_error(name, "clock_gettime()"); + } while (calcdiff_ns(now, start) < NSECS_PER_SEC); + + /* Unblock it, which should deliver a signal */ + if (sigprocmask(SIG_UNBLOCK, &set, NULL)) + fatal_error(name, "sigprocmask(SIG_UNBLOCK)"); + + if (timer_delete(timerid)) + fatal_error(name, "timer_delete()"); + + ksft_test_result(tsig.signals == 1 && tsig.overruns == 9, + "check_overrun %s\n", name); +} + int main(int argc, char **argv) { ksft_print_header(); - ksft_set_plan(15); + ksft_set_plan(18); 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"); @@ -574,6 +630,9 @@ int main(int argc, char **argv) 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"); + check_overrun(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); + check_overrun(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID"); + check_overrun(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID"); ksft_finished(); }