mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@us.ibm.com>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org, mingo@elte.hu,
	dipankar@in.ibm.com, hch@infradead.org
Subject: Re: [PATCH] Remove duplicate code in signal.c
Date: Sun, 23 Oct 2005 08:09:33 -0700	[thread overview]
Message-ID: <20051023150933.GB7961@us.ibm.com> (raw)
In-Reply-To: <435B6C4E.F9215E82@tv-sign.ru>

On Sun, Oct 23, 2005 at 02:56:14PM +0400, Oleg Nesterov wrote:
> "Paul E. McKenney" wrote:
> > 
> > Hello!
> > 
> > The following patch combines a bit of redundant code between
> > force_sig_info() and force_sig_specific().  Tested on x86 and ppc64.
> 
> Some minor nitpicks ...
> 
> > +++ linux-2.6.14-rc2-rt7-force_sig/kernel/signal.c      2005-09-29 18:41:07.000000000 -0700
> > @@ -920,8 +920,8 @@ force_sig_info(int sig, struct siginfo *
> >         if (sigismember(&t->blocked, sig) || t->sighand->action[sig-1].sa.sa_handler == SIG_IGN) {
> >                 t->sighand->action[sig-1].sa.sa_handler = SIG_DFL;
> >                 sigdelset(&t->blocked, sig);
> 
> May be it would be more readable to do:
> 
> 	if (handler == SIG_IGN)
> 		handler = SIG_DFL;
> 
> 	if (sigismember(->blocked, sig)) // probably unneeded at all
> 		sigdelset(->blocked, sig);

Seems reasonable to me.

> > -               recalc_sigpending_tsk(t);
> >         }
> > +       recalc_sigpending_tsk(t);
> 
> I never understood why can't we just do:
> 
> 	set_tsk_thread_flag(TIF_SIGPENDING);
> 
> If this signal is not pending yet specific_send_siginfo() will
> set this flag anyway.

My guess is that putting the general logic into recalc_sigpending_tsk()
prevents some bugs that might otherwise show up if someone forgets one
of the conditions that can result in a signal being asserted.  But in
this case, it seems pretty safe.  We really do want to force a signal.
But it is a minor optimization, so I left it as is for now.

> > -       specific_send_sig_info(sig, (void *)2, t);
> > -       spin_unlock_irqrestore(&t->sighand->siglock, flags);
> > +       force_sig_info(sig, (void *)2, t);
> 
> Paul, if you think this patch should go into the -mm tree first,
> could you rediff this patch against -mm ?
> 
> - 	specific_send_sig_info(sig, SEND_SIG_FORCED, t);
> +	force_sig_info(sig, SEND_SIG_FORCED, t);

Some time in -mm would certainly not hurt.  The patch below is against
2.6.14-rc4-mm1, though Andrew asks that they be against a recent Linus
tree (see 5c in http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt).
In any case, "SEND_SIG_FORCED" seems much nicer than "(void *)2".  ;-)

						Thanx, Paul

diff -urpNa -X dontdiff linux-2.6.14-rc4-mm1/kernel/signal.c linux-2.6.14-rc4-mm1-force-sig/kernel/signal.c
--- linux-2.6.14-rc4-mm1/kernel/signal.c	2005-10-23 07:47:05.000000000 -0700
+++ linux-2.6.14-rc4-mm1-force-sig/kernel/signal.c	2005-10-23 08:01:16.000000000 -0700
@@ -889,11 +889,13 @@ force_sig_info(int sig, struct siginfo *
 	int ret;
 
 	spin_lock_irqsave(&t->sighand->siglock, flags);
-	if (sigismember(&t->blocked, sig) || t->sighand->action[sig-1].sa.sa_handler == SIG_IGN) {
+	if (t->sighand->action[sig-1].sa.sa_handler == SIG_IGN) {
 		t->sighand->action[sig-1].sa.sa_handler = SIG_DFL;
+	}
+	if (sigismember(&t->blocked, sig)) {
 		sigdelset(&t->blocked, sig);
-		recalc_sigpending_tsk(t);
 	}
+	recalc_sigpending_tsk(t);
 	ret = specific_send_sig_info(sig, info, t);
 	spin_unlock_irqrestore(&t->sighand->siglock, flags);
 
@@ -903,15 +905,7 @@ force_sig_info(int sig, struct siginfo *
 void
 force_sig_specific(int sig, struct task_struct *t)
 {
-	unsigned long int flags;
-
-	spin_lock_irqsave(&t->sighand->siglock, flags);
-	if (t->sighand->action[sig-1].sa.sa_handler == SIG_IGN)
-		t->sighand->action[sig-1].sa.sa_handler = SIG_DFL;
-	sigdelset(&t->blocked, sig);
-	recalc_sigpending_tsk(t);
-	specific_send_sig_info(sig, SEND_SIG_FORCED, t);
-	spin_unlock_irqrestore(&t->sighand->siglock, flags);
+	force_sig_info(sig, SEND_SIG_FORCED, t);
 }
 
 /*

      reply	other threads:[~2005-10-23 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-23  3:22 Paul E. McKenney
2005-10-23 10:56 ` Oleg Nesterov
2005-10-23 15:09   ` Paul E. McKenney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051023150933.GB7961@us.ibm.com \
    --to=paulmck@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=dipankar@in.ibm.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@tv-sign.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®