public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: davem@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: recalc_sigpending() / recalc_sigpending_tsk() ?
Date: Fri, 01 Mar 2002 17:05:06 +0000	[thread overview]
Message-ID: <792.1015002306@redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0203010838360.3798-100000@home.transmeta.com>
In-Reply-To: <Pine.LNX.4.33.0203010838360.3798-100000@home.transmeta.com>


torvalds@transmeta.com said:
>  So the basic rule should be: drivers etc should not ever have to
> touch "sigmask_lock", because they simply should never even _know_
> about things like that. Agreed? 

Absolutely.

>  So I would suggest solving this problem by just adding something like
> 	/* Block all signals except for mask */
> 	void sigallow(unsigned long mask)
> 	{
> 		spin_lock_irq(&current->sigmask_lock);
> 		siginitsetinv(current->blocked, mask);
> 		recalc_sigpending();
> 		spin_unlock_irq(&current->sigmask_lock);
> 	} 

Now that I like. Especially if coupled with the equivalent for dequeuing a
signal with implicit locking too, so I really can drop all references to 
current->sigmask_lock -- the JFFS2 garbage collection thread dequeues 
signals and deals as you might expect with SIGSTOP/SIGKILL:

	for (;;) {
		spin_lock_irq(&current->sigmask_lock);
		siginitsetinv (&current->blocked, sigmask(SIGHUP) | sigmask(SIGKILL) | sigmask(SIGSTOP) | sigmask(SIGCONT));
		recalc_sigpending();
		spin_unlock_irq(&current->sigmask_lock);

		if (!thread_should_wake(c)) {
                        set_current_state (TASK_INTERRUPTIBLE);
			D1(printk(KERN_DEBUG "jffs2_garbage_collect_thread sleeping...\n"));
			/* Yes, there's a race here; we checked thread_should_wake() before
			   setting current->state to TASK_INTERRUPTIBLE. But it doesn't
			   matter - We don't care if we miss a wakeup, because the GC thread
			   is only an optimisation anyway. */
			schedule();
		}
                
		cond_resched();

                /* Put_super will send a SIGKILL and then wait on the sem. 
                 */
                while (signal_pending(current)) {
                        siginfo_t info;
                        unsigned long signr;

                        spin_lock_irq(&current->sigmask_lock);
                        signr = dequeue_signal(&current->blocked, &info);
                        spin_unlock_irq(&current->sigmask_lock);

                        switch(signr) {
                        case SIGSTOP:
                                D1(printk(KERN_DEBUG "jffs2_garbage_collect_thread(): SIGSTOP received.\n"));
                                set_current_state(TASK_STOPPED);
                                schedule();
                                break;

                        case SIGKILL:
                                D1(printk(KERN_DEBUG "jffs2_garbage_collect_thread(): SIGKILL received.\n"));
				spin_lock_bh(&c->erase_completion_lock);
                                c->gc_task = NULL;
				spin_unlock_bh(&c->erase_completion_lock);
				complete_and_exit(&c->gc_thread_exit, 0);

			case SIGHUP:
				D1(printk(KERN_DEBUG "jffs2_garbage_collect_thread(): SIGHUP received.\n"));
				break;
			default:
				D1(printk(KERN_DEBUG "jffs2_garbage_collect_thread(): signal %ld received\n", signr));

                        }
                }
		/* We don't want SIGHUP to interrupt us. STOP and KILL are OK though. */
		spin_lock_irq(&current->sigmask_lock);
		siginitsetinv (&current->blocked, sigmask(SIGKILL) | sigmask(SIGSTOP) | sigmask(SIGCONT));
		recalc_sigpending();
		spin_unlock_irq(&current->sigmask_lock);

		D1(printk(KERN_DEBUG "jffs2_garbage_collect_thread(): pass\n"));
		jffs2_garbage_collect_pass(c);
	}

--
dwmw2



  reply	other threads:[~2002-03-01 17:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-28 16:31 recalc_sigpending() / recalc_sigpending_tsk() ? David Woodhouse
2002-02-28 16:59 ` Linus Torvalds
2002-02-28 18:26   ` David Woodhouse
2002-03-01 15:33   ` David Woodhouse
2002-03-01 15:33     ` David S. Miller
2002-03-01 15:37     ` David Woodhouse
2002-03-01 15:49       ` David S. Miller
2002-03-01 16:28       ` David Woodhouse
2002-03-01 16:49     ` Linus Torvalds
2002-03-01 17:05       ` David Woodhouse [this message]
2002-03-01 17:40       ` David Howells
2002-03-01 17:43         ` David Woodhouse
2002-03-01 19:01       ` [PATCH] small proposal Martin Dalecki

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=792.1015002306@redhat.com \
    --to=dwmw2@infradead.org \
    --cc=davem@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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