Threads performance - allow signal handler to not call handler
PATCH 1/1 Threads performance - allow signal handler to not call handler
This patch modfies i386 to add a flag to sa_flags in sigaction that will cause the signal handler to not be called (but all other side effects to occur). This may seem unusual, but signals are often used between threads to wake each other up, the signal handler is just a dummy and is pure overhead. With this patch, if the flag is set, the signal handler won't get called (thus saving the overhead of going in and out of userland for the handler), but it will still wake up sigsuspend() and select(). The beauty of this is the flag will be ignored on kernels without it, so it will still work, with just lower performance.
-Corey
arch/i386/kernel/signal.c renamed from arch/i386/kernel/signal.c.nocallhndlr +15 -12
@@ -558,21 +558,24 @@ } } -/* Set up the stack frame */ -if (ka->sa.sa_flags &SA_SIGINFO ) -setup_rt_frame (sig, ka, info, oldset, regs); -else -setup_frame (sig, ka, oldset, regs); -if (ka->sa.sa_flags &SA_ONESHOT ) ka->sa.sa_handler =SIG_DFL ; -if (!(ka->sa.sa_flags &SA_NODEFER )) { -spin_lock_irq (¤t->sigmask_lock); -sigorsets (¤t->blocked,¤t->blocked,&ka->sa.sa_mask); -sigaddset (¤t->blocked,sig); -recalc_sigpending (current); -spin_unlock_irq (¤t->sigmask_lock); +/* Set up the stack frame */ +if (! (ka->sa.sa_flags &SA_NOCALLHNDLR )) { +if (ka->sa.sa_flags &SA_SIGINFO ) +setup_rt_frame (sig, ka, info, oldset, regs); +else +setup_frame (sig, ka, oldset, regs); + +if (!(ka->sa.sa_flags &SA_NODEFER )) { +spin_lock_irq (¤t->sigmask_lock); +sigorsets (¤t->blocked,¤t->blocked, + &ka->sa.sa_mask); +sigaddset (¤t->blocked,sig); +recalc_sigpending (current); +spin_unlock_irq (¤t->sigmask_lock); + } } }
include/asm-i386/signal.h renamed from include/asm-i386/signal.h.nocallhndlr +1 -0
@@ -91,6 +91,7 @@#define SA_RESTART 0x10000000#define SA_NODEFER 0x40000000#define SA_RESETHAND 0x80000000 +#define SA_NOCALLHNDLR 0x00800000/* Don't really call the handler. */ #define SA_NOMASK SA_NODEFER#define SA_ONESHOT SA_RESETHAND
Quoted 3 lines · [email protected] said:
With this patch, if the flag is set, the signal handler won't get called (thus saving the overhead of going in and out of userland for the handler), but it will still wake up
sigsuspend()andselect().
I've wanted this for UML as well. I have some empty signal handlers which exist for no reason other than to wake up pause/sigsuspend/et al.
Jeff