All of lore.kernel.org
 help / color / mirror / Atom feed
* Bug or works as intended: signal behaviour on -RT
@ 2018-09-26 15:07 Ralf Ramsauer
  2018-10-03 15:51 ` Thomas Gleixner
  2018-10-05 11:07 ` Sebastian Andrzej Siewior
  0 siblings, 2 replies; 3+ messages in thread
From: Ralf Ramsauer @ 2018-09-26 15:07 UTC (permalink / raw)
  To: linux-rt-users

[-- Attachment #1: Type: text/plain, Size: 1043 bytes --]

Hi,

If I set the SCHED_FIFO schedular, register a SIGALRM handler, set an
alarm() and consume 100% of CPU time on an isolated CPU (IOW, never
leave running/runable), the signal will never arrive in userspace.
According to /proc/timer_list the expiration time will become a negative
value.

But if I synchronously send a SIGALRM via kill, it will immediately
arrive. Even a sched_yield() in the busy loop won't help. In order to
get the signal, I have to leave running/runable with usleep().

Now I'm not sure if this behaviour is intended for some reason or if
it's a bug. Please find a minimal example attached. Run it on an
isolated CPU with taskset.

Reproduceable with 4.14.x-rt and latest -rt. Not reproducable with
mainline Linux and PREEMPT.

Thanks
  Ralf

(How I found this: I'm currently using stress-ng as a stressor for some
cyclictest measurements. stress-ng fork()s stressors. Stressors can be
parameterised by a timeout, which is implemented as alarm(). The timeout
will never occur, as stressors never leave Running/Runable.)

[-- Attachment #2: sigalrm.c --]
[-- Type: text/x-csrc, Size: 644 bytes --]

#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sched.h>
#include <string.h>

static volatile bool stop;

static void alarm_handler(int sig)
{
	printf("Woof woof!\n");
	stop = true;
}

int main(void) {
	struct sched_param sp;
	int ret;

	memset(&sp, 0, sizeof(sp));
	sp.sched_priority = 12;
	ret = sched_setscheduler(0, SCHED_FIFO, &sp);
	if (ret != 0) {
		printf("Error setting scheduler\n");
		return -1;
	}

	if (signal(SIGALRM, alarm_handler) == SIG_ERR) {
		printf("\ncan't catch SIGINT\n");
		return -1;
	}

	alarm(5);
	while (!stop) {}

	return 0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug or works as intended: signal behaviour on -RT
  2018-09-26 15:07 Bug or works as intended: signal behaviour on -RT Ralf Ramsauer
@ 2018-10-03 15:51 ` Thomas Gleixner
  2018-10-05 11:07 ` Sebastian Andrzej Siewior
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2018-10-03 15:51 UTC (permalink / raw)
  To: Ralf Ramsauer; +Cc: linux-rt-users

On Wed, 26 Sep 2018, Ralf Ramsauer wrote:

> Hi,
> 
> If I set the SCHED_FIFO schedular, register a SIGALRM handler, set an
> alarm() and consume 100% of CPU time on an isolated CPU (IOW, never
> leave running/runable), the signal will never arrive in userspace.
> According to /proc/timer_list the expiration time will become a negative
> value.
> 
> But if I synchronously send a SIGALRM via kill, it will immediately
> arrive. Even a sched_yield() in the busy loop won't help. In order to
> get the signal, I have to leave running/runable with usleep().
> 
> Now I'm not sure if this behaviour is intended for some reason or if
> it's a bug. Please find a minimal example attached. Run it on an
> isolated CPU with taskset.
> 
> Reproduceable with 4.14.x-rt and latest -rt. Not reproducable with
> mainline Linux and PREEMPT.

The problem is that the alarm timer is delivered in softirq
context. Assuming that your task loops with higher priority than the
softirq thread it will simply starve it and the timer is never expired and
therefore no siganl delivered. Not pretty, but nothing we can do about
right now with the way signal based timers work. There are ideas to
implement that differently, but that's more complex than it seems in the
first place.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug or works as intended: signal behaviour on -RT
  2018-09-26 15:07 Bug or works as intended: signal behaviour on -RT Ralf Ramsauer
  2018-10-03 15:51 ` Thomas Gleixner
@ 2018-10-05 11:07 ` Sebastian Andrzej Siewior
  1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2018-10-05 11:07 UTC (permalink / raw)
  To: Ralf Ramsauer; +Cc: linux-rt-users

On 2018-09-26 17:07:02 [+0200], Ralf Ramsauer wrote:
> Hi,
Hi,

> But if I synchronously send a SIGALRM via kill, it will immediately
> arrive. Even a sched_yield() in the busy loop won't help. In order to
> get the signal, I have to leave running/runable with usleep().

a sched_yield() will put you at the end of the runqueue. If this is the
only task in that queue then the task will go back on the CPU.

> Thanks
>   Ralf

Sebastian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-05 18:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-26 15:07 Bug or works as intended: signal behaviour on -RT Ralf Ramsauer
2018-10-03 15:51 ` Thomas Gleixner
2018-10-05 11:07 ` Sebastian Andrzej Siewior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.