2005-04-16 18:20:36 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 PathScale, Inc
|
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <signal.h>
|
2006-01-08 04:01:29 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include "user_util.h"
|
|
|
|
#include "user.h"
|
|
|
|
#include "signal_kern.h"
|
|
|
|
#include "sysdep/sigcontext.h"
|
|
|
|
#include "sigcontext.h"
|
2005-04-16 18:20:36 -04:00
|
|
|
#include "mode.h"
|
2006-01-18 20:42:42 -05:00
|
|
|
#include "os.h"
|
2005-04-16 18:20:36 -04:00
|
|
|
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
/* These are the asynchronous signals. SIGVTALRM and SIGARLM are handled
|
|
|
|
* together under SIGVTALRM_BIT. SIGPROF is excluded because we want to
|
|
|
|
* be able to profile all of UML, not just the non-critical sections. If
|
|
|
|
* profiling is not thread-safe, then that is not my problem. We can disable
|
|
|
|
* profiling when SMP is enabled in that case.
|
|
|
|
*/
|
|
|
|
#define SIGIO_BIT 0
|
|
|
|
#define SIGIO_MASK (1 << SIGIO_BIT)
|
|
|
|
|
|
|
|
#define SIGVTALRM_BIT 1
|
|
|
|
#define SIGVTALRM_MASK (1 << SIGVTALRM_BIT)
|
|
|
|
|
|
|
|
#define SIGALRM_BIT 2
|
|
|
|
#define SIGALRM_MASK (1 << SIGALRM_BIT)
|
|
|
|
|
|
|
|
static int signals_enabled = 1;
|
|
|
|
static int pending = 0;
|
|
|
|
|
2006-09-26 02:33:04 -04:00
|
|
|
void sig_handler(int sig, struct sigcontext *sc)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
int enabled;
|
|
|
|
|
|
|
|
enabled = signals_enabled;
|
|
|
|
if(!enabled && (sig == SIGIO)){
|
|
|
|
pending |= SIGIO_MASK;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
block_signals();
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
CHOOSE_MODE_PROC(sig_handler_common_tt, sig_handler_common_skas,
|
|
|
|
sig, sc);
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
|
|
|
|
set_signals(enabled);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
static void real_alarm_handler(int sig, struct sigcontext *sc)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
if(sig == SIGALRM)
|
|
|
|
switch_timers(0);
|
|
|
|
|
|
|
|
CHOOSE_MODE_PROC(sig_handler_common_tt, sig_handler_common_skas,
|
|
|
|
sig, sc);
|
|
|
|
|
|
|
|
if(sig == SIGALRM)
|
|
|
|
switch_timers(1);
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-09-26 02:33:04 -04:00
|
|
|
void alarm_handler(int sig, struct sigcontext *sc)
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
{
|
|
|
|
int enabled;
|
|
|
|
|
|
|
|
enabled = signals_enabled;
|
|
|
|
if(!signals_enabled){
|
|
|
|
if(sig == SIGVTALRM)
|
|
|
|
pending |= SIGVTALRM_MASK;
|
|
|
|
else pending |= SIGALRM_MASK;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
block_signals();
|
|
|
|
|
|
|
|
real_alarm_handler(sig, sc);
|
|
|
|
set_signals(enabled);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2006-01-08 04:01:29 -05:00
|
|
|
void set_sigstack(void *sig_stack, int size)
|
|
|
|
{
|
|
|
|
stack_t stack = ((stack_t) { .ss_flags = 0,
|
|
|
|
.ss_sp = (__ptr_t) sig_stack,
|
|
|
|
.ss_size = size - sizeof(void *) });
|
|
|
|
|
|
|
|
if(sigaltstack(&stack, NULL) != 0)
|
|
|
|
panic("enabling signal stack failed, errno = %d\n", errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove_sigstack(void)
|
|
|
|
{
|
|
|
|
stack_t stack = ((stack_t) { .ss_flags = SS_DISABLE,
|
|
|
|
.ss_sp = NULL,
|
|
|
|
.ss_size = 0 });
|
|
|
|
|
|
|
|
if(sigaltstack(&stack, NULL) != 0)
|
|
|
|
panic("disabling signal stack failed, errno = %d\n", errno);
|
|
|
|
}
|
|
|
|
|
2006-09-26 02:33:04 -04:00
|
|
|
void (*handlers[_NSIG])(int sig, struct sigcontext *sc);
|
|
|
|
|
|
|
|
extern void hard_handler(int sig);
|
|
|
|
|
2006-01-08 04:01:29 -05:00
|
|
|
void set_handler(int sig, void (*handler)(int), int flags, ...)
|
|
|
|
{
|
|
|
|
struct sigaction action;
|
|
|
|
va_list ap;
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
sigset_t sig_mask;
|
2006-01-08 04:01:29 -05:00
|
|
|
int mask;
|
|
|
|
|
2006-09-26 02:33:04 -04:00
|
|
|
handlers[sig] = (void (*)(int, struct sigcontext *)) handler;
|
|
|
|
action.sa_handler = hard_handler;
|
|
|
|
|
2006-01-08 04:01:29 -05:00
|
|
|
sigemptyset(&action.sa_mask);
|
2006-09-26 02:33:04 -04:00
|
|
|
|
|
|
|
va_start(ap, flags);
|
|
|
|
while((mask = va_arg(ap, int)) != -1)
|
2006-01-08 04:01:29 -05:00
|
|
|
sigaddset(&action.sa_mask, mask);
|
|
|
|
va_end(ap);
|
2006-09-26 02:33:04 -04:00
|
|
|
|
2006-01-08 04:01:29 -05:00
|
|
|
action.sa_flags = flags;
|
|
|
|
action.sa_restorer = NULL;
|
|
|
|
if(sigaction(sig, &action, NULL) < 0)
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
panic("sigaction failed - errno = %d\n", errno);
|
|
|
|
|
|
|
|
sigemptyset(&sig_mask);
|
|
|
|
sigaddset(&sig_mask, sig);
|
|
|
|
if(sigprocmask(SIG_UNBLOCK, &sig_mask, NULL) < 0)
|
|
|
|
panic("sigprocmask failed - errno = %d\n", errno);
|
2006-01-08 04:01:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int change_sig(int signal, int on)
|
|
|
|
{
|
|
|
|
sigset_t sigset, old;
|
|
|
|
|
|
|
|
sigemptyset(&sigset);
|
|
|
|
sigaddset(&sigset, signal);
|
|
|
|
sigprocmask(on ? SIG_UNBLOCK : SIG_BLOCK, &sigset, &old);
|
|
|
|
return(!sigismember(&old, signal));
|
|
|
|
}
|
|
|
|
|
|
|
|
void block_signals(void)
|
|
|
|
{
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
signals_enabled = 0;
|
2006-01-08 04:01:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void unblock_signals(void)
|
|
|
|
{
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
int save_pending;
|
2006-01-08 04:01:29 -05:00
|
|
|
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
if(signals_enabled == 1)
|
|
|
|
return;
|
2006-01-08 04:01:29 -05:00
|
|
|
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
/* We loop because the IRQ handler returns with interrupts off. So,
|
|
|
|
* interrupts may have arrived and we need to re-enable them and
|
|
|
|
* recheck pending.
|
|
|
|
*/
|
|
|
|
while(1){
|
|
|
|
/* Save and reset save_pending after enabling signals. This
|
|
|
|
* way, pending won't be changed while we're reading it.
|
|
|
|
*/
|
|
|
|
signals_enabled = 1;
|
|
|
|
|
|
|
|
save_pending = pending;
|
|
|
|
if(save_pending == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pending = 0;
|
|
|
|
|
|
|
|
/* We have pending interrupts, so disable signals, as the
|
|
|
|
* handlers expect them off when they are called. They will
|
|
|
|
* be enabled again above.
|
|
|
|
*/
|
|
|
|
|
|
|
|
signals_enabled = 0;
|
|
|
|
|
|
|
|
/* Deal with SIGIO first because the alarm handler might
|
|
|
|
* schedule, leaving the pending SIGIO stranded until we come
|
|
|
|
* back here.
|
|
|
|
*/
|
|
|
|
if(save_pending & SIGIO_MASK)
|
|
|
|
CHOOSE_MODE_PROC(sig_handler_common_tt,
|
|
|
|
sig_handler_common_skas, SIGIO, NULL);
|
|
|
|
|
|
|
|
if(save_pending & SIGALRM_MASK)
|
|
|
|
real_alarm_handler(SIGALRM, NULL);
|
|
|
|
|
|
|
|
if(save_pending & SIGVTALRM_MASK)
|
|
|
|
real_alarm_handler(SIGVTALRM, NULL);
|
|
|
|
}
|
2006-01-08 04:01:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_signals(void)
|
|
|
|
{
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
return signals_enabled;
|
2006-01-08 04:01:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int set_signals(int enable)
|
|
|
|
{
|
|
|
|
int ret;
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
if(signals_enabled == enable)
|
|
|
|
return enable;
|
2006-01-08 04:01:29 -05:00
|
|
|
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
ret = signals_enabled;
|
|
|
|
if(enable)
|
|
|
|
unblock_signals();
|
|
|
|
else block_signals();
|
2006-01-08 04:01:29 -05:00
|
|
|
|
[PATCH] uml: implement soft interrupts
This patch implements soft interrupts. Interrupt enabling and disabling no
longer map to sigprocmask. Rather, a flag is set indicating whether
interrupts may be handled. If a signal comes in and interrupts are marked as
OK, then it is handled normally. If interrupts are marked as off, then the
signal handler simply returns after noting that a signal needs handling. When
interrupts are enabled later on, this pending signals flag is checked, and the
IRQ handlers are called at that point.
The point of this is to reduce the cost of local_irq_save et al, since they
are very much more common than the signals that they are enabling and
disabling. Soft interrupts produce a speed-up of ~25% on a kernel build.
Subtleties -
UML uses sigsetjmp/siglongjmp to switch contexts. sigsetjmp has been
wrapped in a save_flags-like macro which remembers the interrupt state at
setjmp time, and restores it when it is longjmp-ed back to.
The enable_signals function has to loop because the IRQ handler
disables interrupts before returning. enable_signals has to return with
signals enabled, and signals may come in between the disabling and the
return to enable_signals. So, it loops for as long as there are pending
signals, ensuring that signals are enabled when it finally returns, and
that there are no pending signals that need to be dealt with.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-18 20:42:49 -05:00
|
|
|
return ret;
|
2006-01-08 04:01:29 -05:00
|
|
|
}
|
2006-01-18 20:42:46 -05:00
|
|
|
|
|
|
|
void os_usr1_signal(int on)
|
|
|
|
{
|
|
|
|
change_sig(SIGUSR1, on);
|
|
|
|
}
|