Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp581577lqe; Sat, 6 Apr 2024 14:15:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXW/X0EFUiy7t+H9zWe/ye/imRDiLsAZ7daphC1fDSbdziu+79L0dUgJahuf5dm4US7Ole+m+NLje2DITDkrtJK3x+rrNOYay0TVbtGrQ== X-Google-Smtp-Source: AGHT+IExWf/QMheZEgjcIRabOKJJKyKiBPqMzI3YImRj8L17ycUSbGBF2jr5qIKwKxy/No+cvqf1 X-Received: by 2002:a05:6214:1cc7:b0:699:1042:dcab with SMTP id g7-20020a0562141cc700b006991042dcabmr5977920qvd.60.1712438107360; Sat, 06 Apr 2024 14:15:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712438107; cv=pass; d=google.com; s=arc-20160816; b=RwymBHfVQzw7Ucv9NAoArFiyvdqYUfCyJ++P+gqkukfQPKeO7ntHQcD4T6q8u1rvMb zlDMqcoZDWdchDSHKky8vYusXh2L3HBSe6zphF7KRBQw+vFpreI54nMIZKuMpHxq0M/x rS8grodjSqPWqPS8LsEPJuVsl6zTjt8KUrtemFuViFIH/dAj6sjdTatC6RnTpX2QdTpt rju3wxR59ZMh/m3HiZ+vT7ElumMJHliKlg3ey9id7LsLn2LxHb2IvDQ1fi8mY8QZJ5iz i9EXJnpc9VhTXxSxRtHvqkaXqMRnvOJdMzZM2yg0oHRUPfq+Nk6s+xdbxWd6bw6az6V1 qDtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=oHlEIGlMy5AeytAApxqnvbACljlKOkZKhDAKTWpoYzU=; fh=bGKKw3htlceobEgjBC75QDV5i+zKnR8IWRiRENRx0r0=; b=zEpgL3/M086f2UWbtYNwvWmzJ9o4JrgRukwneFilRCrsdhFjdXmLxj6EiYeSICitv3 JVReXJlw2TodTRT8wyPf5Z4UpSljJQaHtQFoCQL6E99gV1jvZ2nLrTmLg618FhQ639yn Snen5yRxfdDQiVpWiNPiVIJlVD8ygf4n3+L0qXtFfn4FCSbpl32zCtvmgub48oXANAVi 7ybzUZIf3XMbSHaZiR9/aXV7xah/fnDI4AuQgkLrnXKiUKVSpAqphcxhkLJ4S8LvIxux vsY5OzM+0qRKddc2b9m2aEaOLaw5Y5iNOsLW3ArhFkG7Q2p36Y8Z226POpdMh8LlkF4U +1VA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DZPRGUz3; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-134081-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134081-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x15-20020ad4458f000000b0069b143d0376si124818qvu.224.2024.04.06.14.15.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 14:15:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134081-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DZPRGUz3; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-134081-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134081-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0E5491C209D1 for ; Sat, 6 Apr 2024 21:15:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F9CA4F608; Sat, 6 Apr 2024 21:14:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DZPRGUz3" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 985804E1A0 for ; Sat, 6 Apr 2024 21:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712438093; cv=none; b=IbWy4vcmkiEWDP6viETF7T8tYMI3LBiSIpm5dO1Tf28XOXvTnnoDfDA9zYXC00H21d4vriOQ1wKwfu7jM60slo7F2Q81dDvUVs4USPmW8GRZMFVc0z2mSqtniaMLUGZLh7Eb8uY6+lSnBMlaxh2Pqi6TniG6Odqrqp/sRy18hDc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712438093; c=relaxed/simple; bh=dmNNyfbVSsVmGstlEtt+9GFUYC6Tw+gx4nXYmXDUBh0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=klhg351FOJ+/uooNAl91M8dyw0PaFTXRgkBCe353+thQ7ZnZ9lEts4Vy1r1S17UesujENKLtNstwlp/5UM6scjeigEXgvrRiVp/dVwom0k59nT6hgGN8vn74zmjEvV1nVerS/eG09/tTGfemCpPNxvpJmirkf6HsMFaxm4l/shY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DZPRGUz3; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712438089; 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: in-reply-to:in-reply-to:references:references; bh=oHlEIGlMy5AeytAApxqnvbACljlKOkZKhDAKTWpoYzU=; b=DZPRGUz3isSNzRRzBeEcix0QeuhgcVQamI58OfNBwlhqq++4O8wUZCW4BEF3nGQh/I2U1t ochdpn43Uu/aNfqNtIe58uKYPXgxD2CyMipoDNp7h0j/3X96nWxcR2W4V/1mzNYCDxH7B4 64udNuZxfdPG8uVlB2Swo5Eqat7/JAI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156-xrmUZh_FPx27M8azjuNlpg-1; Sat, 06 Apr 2024 17:14:45 -0400 X-MC-Unique: xrmUZh_FPx27M8azjuNlpg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0DBCD180A1E7; Sat, 6 Apr 2024 21:14:45 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.136]) by smtp.corp.redhat.com (Postfix) with SMTP id A5BB2100077A; Sat, 6 Apr 2024 21:14:42 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sat, 6 Apr 2024 23:13:20 +0200 (CEST) Date: Sat, 6 Apr 2024 23:13:13 +0200 From: Oleg Nesterov To: Muhammad Usama Anjum Cc: Marco Elver , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , "Eric W. Biederman" , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Dmitry Vyukov , kasan-dev@googlegroups.com Subject: Re: [PATCH v6 2/2] selftests/timers/posix_timers: Test delivery of signals across threads Message-ID: <20240406211312.GD3060@redhat.com> References: <20230316123028.2890338-1-elver@google.com> <20230316123028.2890338-2-elver@google.com> <46ad25c9-f63c-4bb7-9707-4bc8b21ccaca@collabora.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <46ad25c9-f63c-4bb7-9707-4bc8b21ccaca@collabora.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 Muhammad, I am sorry, but... are you aware that this patch was applied over a year ago, and then this code was updated to use the ksft_API? Oleg. On 04/07, Muhammad Usama Anjum wrote: > > On 3/16/23 5:30 PM, Marco Elver wrote: > > From: Dmitry Vyukov > > > > Test that POSIX timers using CLOCK_PROCESS_CPUTIME_ID eventually deliver > > a signal to all running threads. This effectively tests that the kernel > > doesn't prefer any one thread (or subset of threads) for signal delivery. > > > > Signed-off-by: Dmitry Vyukov > > Signed-off-by: Marco Elver > > --- > > v6: > > - Update wording on what the test aims to test. > > - Fix formatting per checkpatch.pl. > > --- > > tools/testing/selftests/timers/posix_timers.c | 77 +++++++++++++++++++ > > 1 file changed, 77 insertions(+) > > > > diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c > > index 0ba500056e63..8a17c0e8d82b 100644 > > --- a/tools/testing/selftests/timers/posix_timers.c > > +++ b/tools/testing/selftests/timers/posix_timers.c > > @@ -188,6 +188,80 @@ static int check_timer_create(int which) > > return 0; > > } > > > > +int remain; > > +__thread int got_signal; > > + > > +static void *distribution_thread(void *arg) > > +{ > > + while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); > > + return NULL; > > +} > > + > > +static void distribution_handler(int nr) > > +{ > > + if (!__atomic_exchange_n(&got_signal, 1, __ATOMIC_RELAXED)) > > + __atomic_fetch_sub(&remain, 1, __ATOMIC_RELAXED); > > +} > > + > > +/* > > + * Test that all running threads _eventually_ receive CLOCK_PROCESS_CPUTIME_ID > > + * timer signals. This primarily tests that the kernel does not favour any one. > > + */ > > +static int check_timer_distribution(void) > > +{ > > + int err, i; > > + timer_t id; > > + const int nthreads = 10; > > + pthread_t threads[nthreads]; > > + struct itimerspec val = { > > + .it_value.tv_sec = 0, > > + .it_value.tv_nsec = 1000 * 1000, > > + .it_interval.tv_sec = 0, > > + .it_interval.tv_nsec = 1000 * 1000, > > + }; > > + > > + printf("Check timer_create() per process signal distribution... "); > Use APIs from kselftest.h. Use ksft_print_msg() here. > > > + fflush(stdout); > > + > > + remain = nthreads + 1; /* worker threads + this thread */ > > + signal(SIGALRM, distribution_handler); > > + err = timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); > > + if (err < 0) { > > + perror("Can't create timer\n"); > ksft_perror() here > > > + return -1; > > + } > > + err = timer_settime(id, 0, &val, NULL); > > + if (err < 0) { > > + perror("Can't set timer\n"); > > + return -1; > > + } > > + > > + for (i = 0; i < nthreads; i++) { > > + if (pthread_create(&threads[i], NULL, distribution_thread, NULL)) { > > + perror("Can't create thread\n"); > > + return -1; > > + } > > + } > > + > > + /* Wait for all threads to receive the signal. */ > > + while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); > > + > > + for (i = 0; i < nthreads; i++) { > > + if (pthread_join(threads[i], NULL)) { > > + perror("Can't join thread\n"); > > + return -1; > > + } > > + } > > + > > + if (timer_delete(id)) { > > + perror("Can't delete timer\n"); > > + return -1; > > + } > > + > > + printf("[OK]\n"); > ksft_test_result or _pass variant as needed? > > > + return 0; > > +} > > + > > int main(int argc, char **argv) > > { > > printf("Testing posix timers. False negative may happen on CPU execution \n"); > > @@ -217,5 +291,8 @@ int main(int argc, char **argv) > > if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0) > > return ksft_exit_fail(); > > > > + if (check_timer_distribution() < 0) > > + return ksft_exit_fail(); > > + > > return ksft_exit_pass(); > > } > > -- > BR, > Muhammad Usama Anjum >