Skip to contentSkip to conversation

do_sigaction: don't worry about signal_pending()

PATCH In review Oleg Nesterov 3 participants 5 messages Aug 20, 2007 – Aug 22, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 do_sigaction: don't worry about signal_pending()

do_sigaction() returns -ERESTARTNOINTR if signal_pending(). The comment says:

* If there might be a fatal signal pending on multiple
* threads, make sure we take it before changing the action.

I think this is not needed. We should only worry about SIGNAL_GROUP_EXIT case, bit it implies a pending SIGKILL which can't be cleared by do_sigaction.

Kill this special case.

kernel/signal.c renamed from kernel/signal.c~SA_NOPEND +0 -9
@@ -2300,15 +2300,6 @@ int do_sigaction(int sig, struct k_sigac
 	k = &current->sighand->action[sig-1];
 
 	spin_lock_irq(&current->sighand->siglock);
-	if (signal_pending(current)) {
-		/*
-		 * If there might be a fatal signal pending on multiple
-		 * threads, make sure we take it before changing the action.
-		 */
-		spin_unlock_irq(&current->sighand->siglock);
-		return -ERESTARTNOINTR;
-	}
-
 	if (oact)
 		*oact = *k;
 
#1 lore raw

I agree, I don't think this check is buying us anything now.

Thanks,
Roland

#2 lore raw
In reply to Oleg Nesterov
Quoted 7 lines · Oleg Nesterov

do_sigaction() returns -ERESTARTNOINTR if signal_pending(). The comment says:

* If there might be a fatal signal pending on multiple
* threads, make sure we take it before changing the action.

I think this is not needed. We should only worry about SIGNAL_GROUP_EXIT case, bit it implies a pending SIGKILL which can't be cleared by do_sigaction.

Isn't it for optimization e.g., to skip this 'do while' loop below for such multiple threads, which would get SIGKILL or SIGSTOP anyway?

Regards,
Jarek P.

#3 lore raw
Quoted 4 lines · Jarek Poplawski
Quoted 2 lines · Oleg Nesterov

do_sigaction() returns -ERESTARTNOINTR if signal_pending(). The comment says:

Quoted 8 lines
Quoted 5 lines

* If there might be a fatal signal pending on multiple
* threads, make sure we take it before changing the action.

I think this is not needed. We should only worry about SIGNAL_GROUP_EXIT case, bit it implies a pending SIGKILL which can't be cleared by do_sigaction.

Isn't it for optimization e.g., to skip this 'do while' loop below for such multiple threads, which would get SIGKILL or SIGSTOP anyway?

Yes, in that case this 'do while' doesn't make sense. But this is very unlikely, sigaction() shouldn't be called too much often, better to save a couple of bytes from icache.

Also, please note that sigaction() is not special, almost any system call could be started with

	if (current->signal->flags & SIGNAL_GROUP_EXIT)
		return ANYVALUE;

to "optimize" for the case when the task is dying.

Oleg.

#4 lore raw
Quoted 18 lines · Oleg Nesterov
Quoted 4 lines · Jarek Poplawski
Quoted 2 lines · Oleg Nesterov

do_sigaction() returns -ERESTARTNOINTR if signal_pending(). The comment says:

Quoted 8 lines
Quoted 5 lines

* If there might be a fatal signal pending on multiple
* threads, make sure we take it before changing the action.

I think this is not needed. We should only worry about SIGNAL_GROUP_EXIT case, bit it implies a pending SIGKILL which can't be cleared by do_sigaction.

Isn't it for optimization e.g., to skip this 'do while' loop below for such multiple threads, which would get SIGKILL or SIGSTOP anyway?

Yes, in that case this 'do while' doesn't make sense. But this is very unlikely, sigaction() shouldn't be called too much often, better to save a couple of bytes from icache.

Quoted 7 lines

Also, please note that sigaction() is not special, almost any system call could be started with

	if (current->signal->flags & SIGNAL_GROUP_EXIT)
		return ANYVALUE;

to "optimize" for the case when the task is dying.

OK, I only wasn't sure this was considered before getting this "not needed" verdict.

BTW, sometimes, even if something is very unlikely, but very time-consuming, and skipping this isn't so costly, there could be a gain at the end. So, maybe it's about individual cases and some testing too? (At least, it seems, somebody found this so usable, she/he bothered with such a long comment, and we know it's a last thing any decent kernel hacker would care to do...)

Jarek P.