linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Marco Elver <elver@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Dmitry Vyukov <dvyukov@google.com>,
	kasan-dev@googlegroups.com
Subject: Re: [PATCH v6 2/2] selftests/timers/posix_timers: Test delivery of signals across threads
Date: Sat, 6 Apr 2024 23:13:13 +0200	[thread overview]
Message-ID: <20240406211312.GD3060@redhat.com> (raw)
In-Reply-To: <46ad25c9-f63c-4bb7-9707-4bc8b21ccaca@collabora.com>

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 <dvyukov@google.com>
> > 
> > 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 <dvyukov@google.com>
> > Signed-off-by: Marco Elver <elver@google.com>
> > ---
> > 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
> 


  reply	other threads:[~2024-04-06 21:14 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16 12:30 [PATCH v6 1/2] posix-timers: Prefer delivery of signals to the current thread Marco Elver
2023-03-16 12:30 ` [PATCH v6 2/2] selftests/timers/posix_timers: Test delivery of signals across threads Marco Elver
2024-04-06 20:53   ` Muhammad Usama Anjum
2024-04-06 21:13     ` Oleg Nesterov [this message]
2024-04-06 21:32       ` Muhammad Usama Anjum
2023-03-30 10:19 ` [PATCH v6 1/2] posix-timers: Prefer delivery of signals to the current thread Marco Elver
2023-04-06 14:12 ` Marco Elver
2023-04-06 15:13   ` Frederic Weisbecker
2023-04-06 20:22 ` Peter Zijlstra
2024-04-01 20:17 ` John Stultz
2024-04-02  9:07   ` Dmitry Vyukov
2024-04-02 14:57   ` Thomas Gleixner
2024-04-02 17:23     ` John Stultz
2024-04-03 12:41       ` Thomas Gleixner
2024-04-03 15:03         ` Oleg Nesterov
2024-04-03 15:43           ` Thomas Gleixner
2024-04-03 16:32             ` Thomas Gleixner
2024-04-03 18:16               ` John Stultz
2024-04-03 19:09                 ` Thomas Gleixner
2024-04-03 19:35                   ` John Stultz
2024-04-03 22:24                     ` Thomas Gleixner
2024-04-04 14:54                       ` Oleg Nesterov
2024-04-04 18:08                         ` Thomas Gleixner
2024-04-06 15:09                           ` [PATCH] selftests/timers/posix_timers: reimplement check_timer_distribution() Oleg Nesterov
2024-04-06 15:10                             ` Oleg Nesterov
2024-04-06 22:00                               ` Thomas Gleixner
2024-04-08  8:30                               ` Dmitry Vyukov
2024-04-08 10:01                                 ` Thomas Gleixner
2024-04-08 10:26                                 ` Oleg Nesterov
2024-04-08 18:49                                   ` Oleg Nesterov
2024-04-08 22:17                                     ` Thomas Gleixner
2024-04-09 11:10                                       ` Oleg Nesterov
2024-04-09 11:45                                         ` Dmitry Vyukov
2024-04-09 12:02                                         ` Thomas Gleixner
2024-04-09 13:38                                           ` [PATCH v2] " Oleg Nesterov
2024-04-10 22:21                                             ` John Stultz
2024-04-10 22:31                                               ` Thomas Gleixner
2024-04-10 22:33                                                 ` John Stultz
2024-04-11 12:41                             ` [PATCH] " Mark Brown
2024-04-11 15:33                               ` John Stultz
2024-04-11 12:44                             ` Mark Brown
2024-04-11 14:17                               ` Thomas Gleixner
2024-04-11 15:50                                 ` Oleg Nesterov
2024-04-11 16:03                                   ` Mark Brown
2024-04-12 12:35                               ` [PATCH] selftests: fix build failure with NOLIBC Oleg Nesterov
2024-04-14  7:42                                 ` Mark Brown
2024-04-04  8:55             ` [PATCH v6 1/2] posix-timers: Prefer delivery of signals to the current thread Dmitry Vyukov
2024-04-04 13:43               ` Oleg Nesterov
2024-04-04 15:10                 ` Thomas Gleixner
2024-04-04 15:23                   ` Oleg Nesterov
2024-04-05  4:28                 ` Dmitry Vyukov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240406211312.GD3060@redhat.com \
    --to=oleg@redhat.com \
    --cc=dvyukov@google.com \
    --cc=ebiederm@xmission.com \
    --cc=elver@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=usama.anjum@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).