[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 4 Apr 2024 16:54:08 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: John Stultz <jstultz@...gle.com>, Marco Elver <elver@...gle.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
Dmitry Vyukov <dvyukov@...gle.com>, kasan-dev@...glegroups.com,
Edward Liaw <edliaw@...gle.com>,
Carlos Llamas <cmllamas@...gle.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [PATCH v6 1/2] posix-timers: Prefer delivery of signals to the
current thread
On 04/04, Thomas Gleixner wrote:
>
> IOW, we cannot test this reliably at all with the current approach.
Agreed!
So how about a REALLY SIMPLE test-case below?
Lacks error checking, should be updated to match tools/testing/selftests.
Without commit bcb7ee79029dca assert(sig_cnt > SIG_CNT) fails, the very
1st tick wakes the leader up.
With that commit it doesn't fail.
Oleg.
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <time.h>
#include <assert.h>
#define SIG_CNT 100
static volatile int sig_cnt;
static void alarm_func(int sig)
{
++sig_cnt;
}
static void *thread_func(void *arg)
{
// one second before the 1st tick to ensure the leader sleeps
struct itimerspec val = {
.it_value.tv_sec = 1,
.it_value.tv_nsec = 0,
.it_interval.tv_sec = 0,
.it_interval.tv_nsec = 1000 * 1000,
};
timer_t id;
timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id);
timer_settime(id, 0, &val, NULL);
while (sig_cnt < SIG_CNT)
;
// wake up the leader
kill(getpid(), SIGALRM);
return NULL;
}
int main(void)
{
pthread_t thread;
signal(SIGALRM, alarm_func);
pthread_create(&thread, NULL, thread_func, NULL);
pause();
assert(sig_cnt > SIG_CNT); // likely SIG_CNT + 1
return 0;
}
Powered by blists - more mailing lists