linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: adt7470: Allow faster removal
@ 2016-09-01  5:17 Joshua Scott
  2016-09-01  8:17 ` Jean Delvare
  2016-09-01 12:10 ` Guenter Roeck
  0 siblings, 2 replies; 7+ messages in thread
From: Joshua Scott @ 2016-09-01  5:17 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, linux-hwmon; +Cc: Joshua Scott, Chris Packham

adt7470_remove will wait for the update thread to complete before
returning. This has a worst-case time of up to the user-configurable
auto_update_interval.

Break this delay into smaller slices to allow the thread to exit quickly
when adt7470_remove is called.

Signed-off-by: Joshua Scott <joshua.scott@alliedtelesis.co.nz>
---
 drivers/hwmon/adt7470.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 7d185a9..ba97392 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -268,14 +268,21 @@ static int adt7470_update_thread(void *p)
 {
 	struct i2c_client *client = p;
 	struct adt7470_data *data = i2c_get_clientdata(client);
+	unsigned long next_read = jiffies - 1;
 
 	while (!kthread_should_stop()) {
-		mutex_lock(&data->lock);
-		adt7470_read_temperatures(client, data);
-		mutex_unlock(&data->lock);
+
+		if (time_after_eq(jiffies, next_read)) {
+			next_read = jiffies + data->auto_update_interval * HZ / 1000;
+			mutex_lock(&data->lock);
+			adt7470_read_temperatures(client, data);
+			mutex_unlock(&data->lock);
+		}
+
+		msleep_interruptible(1);
+
 		if (kthread_should_stop())
 			break;
-		msleep_interruptible(data->auto_update_interval);
 	}
 
 	complete_all(&data->auto_update_stop);
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH] hwmon: adt7470: Allow faster removal
@ 2016-09-06 22:49 Joshua Scott
  2016-09-09  4:17 ` Guenter Roeck
  0 siblings, 1 reply; 7+ messages in thread
From: Joshua Scott @ 2016-09-06 22:49 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, linux-hwmon; +Cc: Joshua Scott, Chris Packham

adt7470_remove will wait for the update thread to complete before
returning. This had a worst-case time of up to the user-configurable
auto_update_interval.

Replace msleep_interruptible with set_current_state and schedule_timeout
so that kthread_stop will interrupt the sleep.

Signed-off-by: Joshua Scott <joshua.scott@alliedtelesis.co.nz>
---
 drivers/hwmon/adt7470.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 7d185a9..e93c528 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -273,9 +273,12 @@ static int adt7470_update_thread(void *p)
 		mutex_lock(&data->lock);
 		adt7470_read_temperatures(client, data);
 		mutex_unlock(&data->lock);
+
+		set_current_state(TASK_INTERRUPTIBLE);
 		if (kthread_should_stop())
 			break;
-		msleep_interruptible(data->auto_update_interval);
+
+		schedule_timeout(data->auto_update_interval * HZ / 1000);
 	}
 
 	complete_all(&data->auto_update_stop);
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-09-09  4:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-01  5:17 [PATCH] hwmon: adt7470: Allow faster removal Joshua Scott
2016-09-01  8:17 ` Jean Delvare
2016-09-01 12:10 ` Guenter Roeck
2016-09-01 21:08   ` Chris Packham
2016-09-02 14:55     ` Jean Delvare
  -- strict thread matches above, loose matches on Subject: below --
2016-09-06 22:49 Joshua Scott
2016-09-09  4:17 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).