Threads performance - allow signal handler to not call handler

Threads performance - allow signal handler to not call handler

Post by Corey Minyar » Fri, 29 Mar 2002 06:50:10



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

[ linux-nocallhndlr.patch 1K ]
--- ./arch/i386/kernel/signal.c.nocallhndlr     Wed Mar 27 10:56:29 2002

                }
        }

-       /* 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(&current->sigmask_lock);
-               sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
-               sigaddset(&current->blocked,sig);
-               recalc_sigpending(current);
-               spin_unlock_irq(&current->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(&current->sigmask_lock);
+                       sigorsets(&current->blocked,&current->blocked,
+                                 &ka->sa.sa_mask);
+                       sigaddset(&current->blocked,sig);
+                       recalc_sigpending(current);
+                       spin_unlock_irq(&current->sigmask_lock);
+               }
        }
 }

--- ./include/asm-i386/signal.h.nocallhndlr     Wed Mar 27 10:56:12 2002

 #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

 
 
 

Threads performance - allow signal handler to not call handler

Post by Jeff Dik » Fri, 29 Mar 2002 07:10:08



Quote:> 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().

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

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. Signal handlers inside signal handlers

Greetings Netters,

Unfortunately, the project I'm working on requires I mess with nested signal
handlers, and I've checked out obvious manuals and the POSIX std for clues,
but I'm having no luck.

What I'm trying to do is within a signal handler, plant another handler.
For example

#include        blah blah blah

foo2( int signo )
{
        printf("Caught the second sigalrm\n");

foo1( int signo )
{
        printf("Caught the first sigalrm\n");
        signal( SIGARLM, foo2 );
        alarm(1);

        for (;;)
                ;

main()
{
        signal( SIGALRM, foo1 );
        alarm(3);

        /* Wait for the first alarm */
        sleep(10);

The above program when run, prints the message from function foo1
but never reaches foo2.  Note that my project dictates that I can't
exit foo2, until foo1 has run.
I've tried messing with posix signals (sigaction etc), but have the
same problem.

Has anyone tried to do this sort of thing before??

Thanks in advance,
Scott Wallace

2. Thomson Speedtouch 530 router, usb port

3. Solaris 2.4 x86 Threads, Wrong signal handler called with thr_kill()

4. Help with L. on 486DLC+Mathcoop.

5. Handlers, Handlers, Handlers

6. Knetfilter work on firestarter

7. --- called from signal handler with signal -24242176 (SIG Unknown)

8. Extracting the bootimage from a bootable (El Torito) CD ?

9. Reentrant system calls (can be called from signal handler)

10. Signal handlers are not reset after signal delivery

11. Things allowed in signal handlers...

12. how to deal with thread-specific data in signal handler?

13. How to set signal handler and mask in thread other than main ?