mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Ben Collins <bcollins@ubuntu.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	Stefan Richter <stefanr@s5r6.in-berlin.de>,
	"Serge E. Hallyn" <serue@us.ibm.com>,
	weihs@ict.tuwien.ac.at, linux1394-devel@lists.sourceforge.net,
	bcollins@debian.org, "Eric W. Biederman" <ebiederm@xmission.com>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kthread conversion: convert ieee1394 from kernel_thread
Date: Sat, 10 Jun 2006 19:37:03 +0100	[thread overview]
Message-ID: <20060610183703.GA1497@infradead.org> (raw)
In-Reply-To: <1149962931.4448.557.camel@grayson>

On Sat, Jun 10, 2006 at 02:08:50PM -0400, Ben Collins wrote:
> Most rescans are initiated by a bus reset (usually caused by a
> connect/disconnect of a device) that is detected in interrupt.
> Obviously, we cannot initiate these rescans in interrupt, so a tasklet
> or kthread is the only option.
> 
> The reason for handling user-initiated rescans (through some sysfs
> interface?) and hardware-initiated rescans in the same place is code
> simplicity, and synchronization.
> 
> I'm not sure what your implying about user-initiated rescans. The only
> thing I can think of is device/driver binding, which isn't handled in
> our kernel thread anyway (except where it's a new device being detected,
> as opposed to a new driver being loaded).

Sorry, I was confused when looking at the code.  There are two calls
to kernel_thread in drivers/ieee1394/nodemgr.c.  The first one is from
fw_set_rescan, which handles a writeable sysfs attribute.  For that all
my comments in this thread stand, and I think it should not start a
thread.

The second one is the actual, real daemon you talked about most of the
time.  That one should of course stay a kernel thread!

Below is a draft patch to convert it to the kthread API and replace the
reset_sem with a simple wake_up_process scheme.  I removed the down_trylock
loop there which I think should be fine because we get the wakeup again
ASAP, but please double-check.


Index: linux-2.6/drivers/ieee1394/nodemgr.c
===================================================================
--- linux-2.6.orig/drivers/ieee1394/nodemgr.c	2006-06-10 20:25:14.000000000 +0200
+++ linux-2.6/drivers/ieee1394/nodemgr.c	2006-06-10 20:33:01.000000000 +0200
@@ -19,6 +19,7 @@
 #include <linux/delay.h>
 #include <linux/pci.h>
 #include <linux/moduleparam.h>
+#include <linux/kthread.h>
 #include <asm/atomic.h>
 
 #include "ieee1394_types.h"
@@ -113,11 +114,7 @@
 struct host_info {
 	struct hpsb_host *host;
 	struct list_head list;
-	struct completion exited;
-	struct semaphore reset_sem;
-	int pid;
-	char daemon_name[15];
-	int kill_me;
+	struct task_struct *thread;
 };
 
 static int nodemgr_bus_match(struct device * dev, struct device_driver * drv);
@@ -1567,9 +1564,6 @@
 	struct hpsb_host *host = hi->host;
 	int reset_cycles = 0;
 
-	/* No userlevel access needed */
-	daemonize(hi->daemon_name);
-
 	/* Setup our device-model entries */
 	nodemgr_create_host_dev_files(host);
 
@@ -1579,15 +1573,14 @@
 		unsigned int generation = 0;
 		int i;
 
-		if (down_interruptible(&hi->reset_sem) ||
-		    down_interruptible(&nodemgr_serialize)) {
+		if (down_interruptible(&nodemgr_serialize)) {
 			if (try_to_freeze())
 				continue;
 			printk("NodeMgr: received unexpected signal?!\n" );
 			break;
 		}
 
-		if (hi->kill_me) {
+		if (kthread_should_stop()) {
 			up(&nodemgr_serialize);
 			break;
 		}
@@ -1608,13 +1601,8 @@
 			 * returning bogus data. */
 			generation = get_hpsb_generation(host);
 
-			/* If we get a reset before we are done waiting, then
-			 * start the the waiting over again */
-			while (!down_trylock(&hi->reset_sem))
-				i = 0;
-
-			/* Check the kill_me again */
-			if (hi->kill_me) {
+			/* Check the whether we should stop again */
+			if (kthread_should_stop()) {
 				up(&nodemgr_serialize);
 				goto caught_signal;
 			}
@@ -1647,7 +1635,7 @@
 caught_signal:
 	HPSB_VERBOSE("NodeMgr: Exiting thread");
 
-	complete_and_exit(&hi->exited, 0);
+	return 0;
 }
 
 int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *))
@@ -1714,16 +1702,11 @@
 	}
 
 	hi->host = host;
-	init_completion(&hi->exited);
-        sema_init(&hi->reset_sem, 0);
+	hi->thread = kthread_create(nodemgr_host_thread, hi, "knodemgrd_%d", host->id);
 
-	sprintf(hi->daemon_name, "knodemgrd_%d", host->id);
-
-	hi->pid = kernel_thread(nodemgr_host_thread, hi, CLONE_KERNEL);
-
-	if (hi->pid < 0) {
-		HPSB_ERR ("NodeMgr: failed to start %s thread for %s",
-			  hi->daemon_name, host->driver->name);
+	if (IS_ERR(hi->thread)) {
+		HPSB_ERR ("NodeMgr: failed to start thread for %s",
+			  host->driver->name);
 		hpsb_destroy_hostinfo(&nodemgr_highlevel, host);
 		return;
 	}
@@ -1736,8 +1719,7 @@
 	struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
 
 	if (hi != NULL) {
-		HPSB_VERBOSE("NodeMgr: Processing host reset for %s", hi->daemon_name);
-		up(&hi->reset_sem);
+		wake_up_process(hi->thread);
 	} else
 		HPSB_ERR ("NodeMgr: could not process reset of unused host");
 
@@ -1749,13 +1731,8 @@
 	struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host);
 
 	if (hi) {
-		if (hi->pid >= 0) {
-			hi->kill_me = 1;
-			mb();
-			up(&hi->reset_sem);
-			wait_for_completion(&hi->exited);
-			nodemgr_remove_host_dev(&host->device);
-		}
+		kthread_stop(hi->thread);
+		nodemgr_remove_host_dev(&host->device);
 	} else
 		HPSB_ERR("NodeMgr: host %s does not exist, cannot remove",
 			 host->driver->name);

  reply	other threads:[~2006-06-10 18:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-10 14:31 Serge E. Hallyn
2006-06-10 14:42 ` Christoph Hellwig
2006-06-10 15:11   ` Stefan Richter
2006-06-10 15:42     ` Christoph Hellwig
2006-06-10 16:34       ` Ben Collins
2006-06-10 16:38         ` Christoph Hellwig
2006-06-10 18:08           ` Ben Collins
2006-06-10 18:37             ` Christoph Hellwig [this message]
2006-06-17 18:44               ` Stefan Richter
2006-06-18 10:29                 ` Stefan Richter
2006-06-18 16:57                 ` [PATCH 2.6.17-rc6-mm2 0/6] ieee1394: nodemgr: misc API conversions Stefan Richter
2006-06-18 16:57                   ` [PATCH 2.6.17-rc6-mm2 1/6] ieee1394: nodemgr: remove unnecessary includes Stefan Richter
2006-06-18 16:59                     ` [PATCH 2.6.17-rc6-mm2 2/6] ieee1394: do not spawn a kernel_thread for user-initiated bus rescan Stefan Richter
2006-06-18 17:00                       ` [PATCH 2.6.17-rc6-mm2 3/6] ieee1394: make module parameter ignore_drivers writable Stefan Richter
2006-06-18 17:02                         ` [PATCH 2.6.17-rc6-mm2 4/6] ieee1394: nodemgr: switch to kthread API Stefan Richter
2006-06-18 17:03                           ` [PATCH 2.6.17-rc6-mm2 5/6] ieee1394: nodemgr: replace reset semaphore Stefan Richter
2006-06-18 17:05                             ` [PATCH 2.6.17-rc6-mm2 6/6] ieee1394: convert nodemgr_serialize semaphore to mutex Stefan Richter
2006-06-10 18:12           ` [PATCH] kthread conversion: convert ieee1394 from kernel_thread Stefan Richter

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=20060610183703.GA1497@infradead.org \
    --to=hch@infradead.org \
    --cc=bcollins@debian.org \
    --cc=bcollins@ubuntu.com \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=serue@us.ibm.com \
    --cc=stefanr@s5r6.in-berlin.de \
    --cc=weihs@ict.tuwien.ac.at \
    /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®