diff options
author | David Fries <david@fries.net> | 2008-10-16 01:04:41 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-16 14:21:49 -0400 |
commit | 3c52e4e627896b42152cc6ff98216c302932227e (patch) | |
tree | 811992a651418cfcd8a606317e2abae26447b9f9 | |
parent | 01e14d6db9654be005a0a5384090aea2cde39976 (diff) |
W1: w1_process, block or sleep
The w1_process thread's sleeping and termination has been modified.
msleep_interruptible was replaced by schedule_timeout and schedule to
allow for kthread_stop and wake_up_process to interrupt the sleep and the
unbounded sleeping when a bus search is disabled. The W1_MASTER_NEED_EXIT
and flags variable were removed as they were redundant with
kthread_should_stop and kthread_stop. If w1_process is sleeping,
requesting a search will immediately wake it up rather than waiting for
the end of msleep_interruptible previously.
Signed-off-by: David Fries <david@fries.net>
Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/w1/w1.c | 20 | ||||
-rw-r--r-- | drivers/w1/w1.h | 4 | ||||
-rw-r--r-- | drivers/w1/w1_int.c | 2 |
3 files changed, 17 insertions, 9 deletions
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 730faa49d8dc..9b5c11701c37 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c | |||
@@ -251,6 +251,7 @@ static ssize_t w1_master_attribute_store_search(struct device * dev, | |||
251 | mutex_lock(&md->mutex); | 251 | mutex_lock(&md->mutex); |
252 | md->search_count = simple_strtol(buf, NULL, 0); | 252 | md->search_count = simple_strtol(buf, NULL, 0); |
253 | mutex_unlock(&md->mutex); | 253 | mutex_unlock(&md->mutex); |
254 | wake_up_process(md->thread); | ||
254 | 255 | ||
255 | return count; | 256 | return count; |
256 | } | 257 | } |
@@ -773,7 +774,7 @@ void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb | |||
773 | tmp64 = (triplet_ret >> 2); | 774 | tmp64 = (triplet_ret >> 2); |
774 | rn |= (tmp64 << i); | 775 | rn |= (tmp64 << i); |
775 | 776 | ||
776 | if (test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) { | 777 | if (kthread_should_stop()) { |
777 | printk(KERN_INFO "Abort w1_search (exiting)\n"); | 778 | printk(KERN_INFO "Abort w1_search (exiting)\n"); |
778 | return; | 779 | return; |
779 | } | 780 | } |
@@ -811,8 +812,12 @@ void w1_search_process(struct w1_master *dev, u8 search_type) | |||
811 | int w1_process(void *data) | 812 | int w1_process(void *data) |
812 | { | 813 | { |
813 | struct w1_master *dev = (struct w1_master *) data; | 814 | struct w1_master *dev = (struct w1_master *) data; |
815 | /* As long as w1_timeout is only set by a module parameter the sleep | ||
816 | * time can be calculated in jiffies once. | ||
817 | */ | ||
818 | const unsigned long jtime = msecs_to_jiffies(w1_timeout * 1000); | ||
814 | 819 | ||
815 | while (!kthread_should_stop() && !test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) { | 820 | while (!kthread_should_stop()) { |
816 | if (dev->search_count) { | 821 | if (dev->search_count) { |
817 | mutex_lock(&dev->mutex); | 822 | mutex_lock(&dev->mutex); |
818 | w1_search_process(dev, W1_SEARCH); | 823 | w1_search_process(dev, W1_SEARCH); |
@@ -820,7 +825,16 @@ int w1_process(void *data) | |||
820 | } | 825 | } |
821 | 826 | ||
822 | try_to_freeze(); | 827 | try_to_freeze(); |
823 | msleep_interruptible(w1_timeout * 1000); | 828 | __set_current_state(TASK_INTERRUPTIBLE); |
829 | |||
830 | if (kthread_should_stop()) | ||
831 | break; | ||
832 | |||
833 | /* Only sleep when the search is active. */ | ||
834 | if (dev->search_count) | ||
835 | schedule_timeout(jtime); | ||
836 | else | ||
837 | schedule(); | ||
824 | } | 838 | } |
825 | 839 | ||
826 | atomic_dec(&dev->refcnt); | 840 | atomic_dec(&dev->refcnt); |
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index 13e0ea880bf8..34ee01e008ad 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h | |||
@@ -149,8 +149,6 @@ struct w1_bus_master | |||
149 | u8, w1_slave_found_callback); | 149 | u8, w1_slave_found_callback); |
150 | }; | 150 | }; |
151 | 151 | ||
152 | #define W1_MASTER_NEED_EXIT 0 | ||
153 | |||
154 | struct w1_master | 152 | struct w1_master |
155 | { | 153 | { |
156 | struct list_head w1_master_entry; | 154 | struct list_head w1_master_entry; |
@@ -169,8 +167,6 @@ struct w1_master | |||
169 | void *priv; | 167 | void *priv; |
170 | int priv_size; | 168 | int priv_size; |
171 | 169 | ||
172 | long flags; | ||
173 | |||
174 | struct task_struct *thread; | 170 | struct task_struct *thread; |
175 | struct mutex mutex; | 171 | struct mutex mutex; |
176 | 172 | ||
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c index 36ff40250b61..bd877b24ce42 100644 --- a/drivers/w1/w1_int.c +++ b/drivers/w1/w1_int.c | |||
@@ -142,7 +142,6 @@ int w1_add_master_device(struct w1_bus_master *master) | |||
142 | 142 | ||
143 | #if 0 /* Thread cleanup code, not required currently. */ | 143 | #if 0 /* Thread cleanup code, not required currently. */ |
144 | err_out_kill_thread: | 144 | err_out_kill_thread: |
145 | set_bit(W1_MASTER_NEED_EXIT, &dev->flags); | ||
146 | kthread_stop(dev->thread); | 145 | kthread_stop(dev->thread); |
147 | #endif | 146 | #endif |
148 | err_out_rm_attr: | 147 | err_out_rm_attr: |
@@ -158,7 +157,6 @@ void __w1_remove_master_device(struct w1_master *dev) | |||
158 | struct w1_netlink_msg msg; | 157 | struct w1_netlink_msg msg; |
159 | struct w1_slave *sl, *sln; | 158 | struct w1_slave *sl, *sln; |
160 | 159 | ||
161 | set_bit(W1_MASTER_NEED_EXIT, &dev->flags); | ||
162 | kthread_stop(dev->thread); | 160 | kthread_stop(dev->thread); |
163 | 161 | ||
164 | mutex_lock(&w1_mlock); | 162 | mutex_lock(&w1_mlock); |