* [PATCH 0/2] i2c: i801: Replace waitqueue with completion API
@ 2021-05-21 21:59 Heiner Kallweit
2021-05-21 22:00 ` [PATCH 1/2] i2c: i801: Remove unneeded warning after wait_event_timeout timeout Heiner Kallweit
2021-05-21 22:02 ` [PATCH 2/2] i2c: i801: Replace waitqueue with completion API Heiner Kallweit
0 siblings, 2 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-05-21 21:59 UTC (permalink / raw
To: Jean Delvare; +Cc: linux-i2c@vger.kernel.org
Using the completion API is more intuitive and it allows to simplify
the code.
Heiner Kallweit (2):
i2c: i801: Remove unneeded warning after wait_event_timeout timeout
i2c: i801: Replace waitqueue with completion API
drivers/i2c/busses/i2c-i801.c | 52 +++++++++++++----------------------
1 file changed, 19 insertions(+), 33 deletions(-)
--
2.31.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] i2c: i801: Remove unneeded warning after wait_event_timeout timeout
2021-05-21 21:59 [PATCH 0/2] i2c: i801: Replace waitqueue with completion API Heiner Kallweit
@ 2021-05-21 22:00 ` Heiner Kallweit
2021-05-25 10:00 ` Jean Delvare
2021-05-21 22:02 ` [PATCH 2/2] i2c: i801: Replace waitqueue with completion API Heiner Kallweit
1 sibling, 1 reply; 9+ messages in thread
From: Heiner Kallweit @ 2021-05-21 22:00 UTC (permalink / raw
To: Jean Delvare; +Cc: linux-i2c@vger.kernel.org
When passing -ETIMEDOUT to i801_check_post() it will emit a timeout
error message. I don't see much benefit in an additional warning
stating more or less the same.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/i2c/busses/i2c-i801.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 99d446763..bfea94d02 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -509,11 +509,9 @@ static int i801_transaction(struct i801_priv *priv, int xact)
result = wait_event_timeout(priv->waitq,
(status = priv->status),
adap->timeout);
- if (!result) {
+ if (!result)
status = -ETIMEDOUT;
- dev_warn(&priv->pci_dev->dev,
- "Timeout waiting for interrupt!\n");
- }
+
priv->status = 0;
return i801_check_post(priv, status);
}
@@ -732,11 +730,9 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
result = wait_event_timeout(priv->waitq,
(status = priv->status),
adap->timeout);
- if (!result) {
+ if (!result)
status = -ETIMEDOUT;
- dev_warn(&priv->pci_dev->dev,
- "Timeout waiting for interrupt!\n");
- }
+
priv->status = 0;
return i801_check_post(priv, status);
}
--
2.31.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] i2c: i801: Replace waitqueue with completion API
2021-05-21 21:59 [PATCH 0/2] i2c: i801: Replace waitqueue with completion API Heiner Kallweit
2021-05-21 22:00 ` [PATCH 1/2] i2c: i801: Remove unneeded warning after wait_event_timeout timeout Heiner Kallweit
@ 2021-05-21 22:02 ` Heiner Kallweit
2021-05-25 12:12 ` Jean Delvare
2021-05-27 20:09 ` Wolfram Sang
1 sibling, 2 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-05-21 22:02 UTC (permalink / raw
To: Jean Delvare; +Cc: linux-i2c@vger.kernel.org
Using the completion API is more intuitive and it allows to simplify
the code. Note that we don't have to set priv->status = 0 any longer
with the completion API.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/i2c/busses/i2c-i801.c | 48 ++++++++++++++---------------------
1 file changed, 19 insertions(+), 29 deletions(-)
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index bfea94d02..738204d77 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -103,7 +103,7 @@
#include <linux/dmi.h>
#include <linux/slab.h>
#include <linux/string.h>
-#include <linux/wait.h>
+#include <linux/completion.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/platform_data/itco_wdt.h>
@@ -270,7 +270,7 @@ struct i801_priv {
unsigned int features;
/* isr processing */
- wait_queue_head_t waitq;
+ struct completion done;
u8 status;
/* Command state used by isr for byte-by-byte block transactions */
@@ -496,24 +496,19 @@ static int i801_wait_byte_done(struct i801_priv *priv)
static int i801_transaction(struct i801_priv *priv, int xact)
{
int status;
- int result;
+ unsigned long result;
const struct i2c_adapter *adap = &priv->adapter;
- result = i801_check_pre(priv);
- if (result < 0)
- return result;
+ status = i801_check_pre(priv);
+ if (status < 0)
+ return status;
if (priv->features & FEATURE_IRQ) {
+ reinit_completion(&priv->done);
outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
SMBHSTCNT(priv));
- result = wait_event_timeout(priv->waitq,
- (status = priv->status),
- adap->timeout);
- if (!result)
- status = -ETIMEDOUT;
-
- priv->status = 0;
- return i801_check_post(priv, status);
+ result = wait_for_completion_timeout(&priv->done, adap->timeout);
+ return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
}
/* the current contents of SMBHSTCNT can be overwritten, since PEC,
@@ -638,7 +633,7 @@ static irqreturn_t i801_host_notify_isr(struct i801_priv *priv)
* DEV_ERR - Invalid command, NAK or communication timeout
* BUS_ERR - SMI# transaction collision
* FAILED - transaction was canceled due to a KILL request
- * When any of these occur, update ->status and wake up the waitq.
+ * When any of these occur, update ->status and signal completion.
* ->status must be cleared before kicking off the next transaction.
*
* 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
@@ -675,7 +670,7 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
if (status) {
outb_p(status, SMBHSTSTS(priv));
priv->status = status;
- wake_up(&priv->waitq);
+ complete(&priv->done);
}
return IRQ_HANDLED;
@@ -694,15 +689,15 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
int i, len;
int smbcmd;
int status;
- int result;
+ unsigned long result;
const struct i2c_adapter *adap = &priv->adapter;
if (command == I2C_SMBUS_BLOCK_PROC_CALL)
return -EOPNOTSUPP;
- result = i801_check_pre(priv);
- if (result < 0)
- return result;
+ status = i801_check_pre(priv);
+ if (status < 0)
+ return status;
len = data->block[0];
@@ -726,15 +721,10 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
priv->count = 0;
priv->data = &data->block[1];
+ reinit_completion(&priv->done);
outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
- result = wait_event_timeout(priv->waitq,
- (status = priv->status),
- adap->timeout);
- if (!result)
- status = -ETIMEDOUT;
-
- priv->status = 0;
- return i801_check_post(priv, status);
+ result = wait_for_completion_timeout(&priv->done, adap->timeout);
+ return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
}
for (i = 1; i <= len; i++) {
@@ -1889,7 +1879,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
}
if (priv->features & FEATURE_IRQ) {
- init_waitqueue_head(&priv->waitq);
+ init_completion(&priv->done);
err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
IRQF_SHARED,
--
2.31.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] i2c: i801: Remove unneeded warning after wait_event_timeout timeout
2021-05-21 22:00 ` [PATCH 1/2] i2c: i801: Remove unneeded warning after wait_event_timeout timeout Heiner Kallweit
@ 2021-05-25 10:00 ` Jean Delvare
2021-05-27 20:09 ` Wolfram Sang
0 siblings, 1 reply; 9+ messages in thread
From: Jean Delvare @ 2021-05-25 10:00 UTC (permalink / raw
To: Heiner Kallweit; +Cc: linux-i2c
On Sat, 22 May 2021 00:00:28 +0200, Heiner Kallweit wrote:
> When passing -ETIMEDOUT to i801_check_post() it will emit a timeout
> error message. I don't see much benefit in an additional warning
> stating more or less the same.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> drivers/i2c/busses/i2c-i801.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> index 99d446763..bfea94d02 100644
> --- a/drivers/i2c/busses/i2c-i801.c
> +++ b/drivers/i2c/busses/i2c-i801.c
> @@ -509,11 +509,9 @@ static int i801_transaction(struct i801_priv *priv, int xact)
> result = wait_event_timeout(priv->waitq,
> (status = priv->status),
> adap->timeout);
> - if (!result) {
> + if (!result)
> status = -ETIMEDOUT;
> - dev_warn(&priv->pci_dev->dev,
> - "Timeout waiting for interrupt!\n");
> - }
> +
> priv->status = 0;
> return i801_check_post(priv, status);
> }
> @@ -732,11 +730,9 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
> result = wait_event_timeout(priv->waitq,
> (status = priv->status),
> adap->timeout);
> - if (!result) {
> + if (!result)
> status = -ETIMEDOUT;
> - dev_warn(&priv->pci_dev->dev,
> - "Timeout waiting for interrupt!\n");
> - }
> +
> priv->status = 0;
> return i801_check_post(priv, status);
> }
I have to agree.
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Tested-by: Jean Delvare <jdelvare@suse.de>
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] i2c: i801: Replace waitqueue with completion API
2021-05-21 22:02 ` [PATCH 2/2] i2c: i801: Replace waitqueue with completion API Heiner Kallweit
@ 2021-05-25 12:12 ` Jean Delvare
2021-05-25 13:01 ` Heiner Kallweit
2021-05-27 20:09 ` Wolfram Sang
1 sibling, 1 reply; 9+ messages in thread
From: Jean Delvare @ 2021-05-25 12:12 UTC (permalink / raw
To: Heiner Kallweit; +Cc: Daniel Kurtz, linux-i2c
Hi Heiner,
Adding Daniel Kurtz, who wrote the original wait queue-based code, to
Cc. I'm not sure if Daniel is still into kernel code though.
On Sat, 22 May 2021 00:02:43 +0200, Heiner Kallweit wrote:
> Using the completion API is more intuitive and it allows to simplify
> the code. Note that we don't have to set priv->status = 0 any longer
> with the completion API.
OK, but you need to call reinit_completion() instead, which has the
same cost. So that's not a good argument ;-)
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> drivers/i2c/busses/i2c-i801.c | 48 ++++++++++++++---------------------
> 1 file changed, 19 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> index bfea94d02..738204d77 100644
> --- a/drivers/i2c/busses/i2c-i801.c
> +++ b/drivers/i2c/busses/i2c-i801.c
> @@ -103,7 +103,7 @@
> #include <linux/dmi.h>
> #include <linux/slab.h>
> #include <linux/string.h>
> -#include <linux/wait.h>
> +#include <linux/completion.h>
> #include <linux/err.h>
> #include <linux/platform_device.h>
> #include <linux/platform_data/itco_wdt.h>
> @@ -270,7 +270,7 @@ struct i801_priv {
> unsigned int features;
>
> /* isr processing */
> - wait_queue_head_t waitq;
> + struct completion done;
> u8 status;
>
> /* Command state used by isr for byte-by-byte block transactions */
> @@ -496,24 +496,19 @@ static int i801_wait_byte_done(struct i801_priv *priv)
> static int i801_transaction(struct i801_priv *priv, int xact)
> {
> int status;
> - int result;
> + unsigned long result;
> const struct i2c_adapter *adap = &priv->adapter;
>
> - result = i801_check_pre(priv);
> - if (result < 0)
> - return result;
> + status = i801_check_pre(priv);
> + if (status < 0)
> + return status;
>
> if (priv->features & FEATURE_IRQ) {
> + reinit_completion(&priv->done);
> outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
> SMBHSTCNT(priv));
> - result = wait_event_timeout(priv->waitq,
> - (status = priv->status),
> - adap->timeout);
> - if (!result)
> - status = -ETIMEDOUT;
> -
> - priv->status = 0;
> - return i801_check_post(priv, status);
> + result = wait_for_completion_timeout(&priv->done, adap->timeout);
> + return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
> }
>
> /* the current contents of SMBHSTCNT can be overwritten, since PEC,
> @@ -638,7 +633,7 @@ static irqreturn_t i801_host_notify_isr(struct i801_priv *priv)
> * DEV_ERR - Invalid command, NAK or communication timeout
> * BUS_ERR - SMI# transaction collision
> * FAILED - transaction was canceled due to a KILL request
> - * When any of these occur, update ->status and wake up the waitq.
> + * When any of these occur, update ->status and signal completion.
> * ->status must be cleared before kicking off the next transaction.
> *
> * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
> @@ -675,7 +670,7 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
> if (status) {
> outb_p(status, SMBHSTSTS(priv));
> priv->status = status;
> - wake_up(&priv->waitq);
> + complete(&priv->done);
> }
>
> return IRQ_HANDLED;
> @@ -694,15 +689,15 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
> int i, len;
> int smbcmd;
> int status;
> - int result;
> + unsigned long result;
> const struct i2c_adapter *adap = &priv->adapter;
>
> if (command == I2C_SMBUS_BLOCK_PROC_CALL)
> return -EOPNOTSUPP;
>
> - result = i801_check_pre(priv);
> - if (result < 0)
> - return result;
> + status = i801_check_pre(priv);
> + if (status < 0)
> + return status;
>
> len = data->block[0];
>
> @@ -726,15 +721,10 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
> priv->count = 0;
> priv->data = &data->block[1];
>
> + reinit_completion(&priv->done);
> outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
> - result = wait_event_timeout(priv->waitq,
> - (status = priv->status),
> - adap->timeout);
> - if (!result)
> - status = -ETIMEDOUT;
> -
> - priv->status = 0;
> - return i801_check_post(priv, status);
> + result = wait_for_completion_timeout(&priv->done, adap->timeout);
> + return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
> }
>
> for (i = 1; i <= len; i++) {
> @@ -1889,7 +1879,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
> }
>
> if (priv->features & FEATURE_IRQ) {
> - init_waitqueue_head(&priv->waitq);
> + init_completion(&priv->done);
>
> err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
> IRQF_SHARED,
The clean-up isn't massive but I agree the code is a bit more pleasant
to read after the change, and I also see the binary size shrink a bit,
so I vote for it.
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Tested-by: Jean Delvare <jdelvare@suse.de>
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] i2c: i801: Replace waitqueue with completion API
2021-05-25 12:12 ` Jean Delvare
@ 2021-05-25 13:01 ` Heiner Kallweit
2021-05-27 7:13 ` Daniel Kurtz
0 siblings, 1 reply; 9+ messages in thread
From: Heiner Kallweit @ 2021-05-25 13:01 UTC (permalink / raw
To: Jean Delvare; +Cc: Daniel Kurtz, linux-i2c
On 25.05.2021 14:12, Jean Delvare wrote:
> Hi Heiner,
>
> Adding Daniel Kurtz, who wrote the original wait queue-based code, to
> Cc. I'm not sure if Daniel is still into kernel code though.
>
> On Sat, 22 May 2021 00:02:43 +0200, Heiner Kallweit wrote:
>> Using the completion API is more intuitive and it allows to simplify
>> the code. Note that we don't have to set priv->status = 0 any longer
>> with the completion API.
>
> OK, but you need to call reinit_completion() instead, which has the
> same cost. So that's not a good argument ;-)
>
Maybe my comment wasn't clear enough. I didn't want to say that we
save something but that it's safe from a functional point of view
to remove clearing priv->status.
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>> drivers/i2c/busses/i2c-i801.c | 48 ++++++++++++++---------------------
>> 1 file changed, 19 insertions(+), 29 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
>> index bfea94d02..738204d77 100644
>> --- a/drivers/i2c/busses/i2c-i801.c
>> +++ b/drivers/i2c/busses/i2c-i801.c
>> @@ -103,7 +103,7 @@
>> #include <linux/dmi.h>
>> #include <linux/slab.h>
>> #include <linux/string.h>
>> -#include <linux/wait.h>
>> +#include <linux/completion.h>
>> #include <linux/err.h>
>> #include <linux/platform_device.h>
>> #include <linux/platform_data/itco_wdt.h>
>> @@ -270,7 +270,7 @@ struct i801_priv {
>> unsigned int features;
>>
>> /* isr processing */
>> - wait_queue_head_t waitq;
>> + struct completion done;
>> u8 status;
>>
>> /* Command state used by isr for byte-by-byte block transactions */
>> @@ -496,24 +496,19 @@ static int i801_wait_byte_done(struct i801_priv *priv)
>> static int i801_transaction(struct i801_priv *priv, int xact)
>> {
>> int status;
>> - int result;
>> + unsigned long result;
>> const struct i2c_adapter *adap = &priv->adapter;
>>
>> - result = i801_check_pre(priv);
>> - if (result < 0)
>> - return result;
>> + status = i801_check_pre(priv);
>> + if (status < 0)
>> + return status;
>>
>> if (priv->features & FEATURE_IRQ) {
>> + reinit_completion(&priv->done);
>> outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
>> SMBHSTCNT(priv));
>> - result = wait_event_timeout(priv->waitq,
>> - (status = priv->status),
>> - adap->timeout);
>> - if (!result)
>> - status = -ETIMEDOUT;
>> -
>> - priv->status = 0;
>> - return i801_check_post(priv, status);
>> + result = wait_for_completion_timeout(&priv->done, adap->timeout);
>> + return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
>> }
>>
>> /* the current contents of SMBHSTCNT can be overwritten, since PEC,
>> @@ -638,7 +633,7 @@ static irqreturn_t i801_host_notify_isr(struct i801_priv *priv)
>> * DEV_ERR - Invalid command, NAK or communication timeout
>> * BUS_ERR - SMI# transaction collision
>> * FAILED - transaction was canceled due to a KILL request
>> - * When any of these occur, update ->status and wake up the waitq.
>> + * When any of these occur, update ->status and signal completion.
>> * ->status must be cleared before kicking off the next transaction.
>> *
>> * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
>> @@ -675,7 +670,7 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
>> if (status) {
>> outb_p(status, SMBHSTSTS(priv));
>> priv->status = status;
>> - wake_up(&priv->waitq);
>> + complete(&priv->done);
>> }
>>
>> return IRQ_HANDLED;
>> @@ -694,15 +689,15 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
>> int i, len;
>> int smbcmd;
>> int status;
>> - int result;
>> + unsigned long result;
>> const struct i2c_adapter *adap = &priv->adapter;
>>
>> if (command == I2C_SMBUS_BLOCK_PROC_CALL)
>> return -EOPNOTSUPP;
>>
>> - result = i801_check_pre(priv);
>> - if (result < 0)
>> - return result;
>> + status = i801_check_pre(priv);
>> + if (status < 0)
>> + return status;
>>
>> len = data->block[0];
>>
>> @@ -726,15 +721,10 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
>> priv->count = 0;
>> priv->data = &data->block[1];
>>
>> + reinit_completion(&priv->done);
>> outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
>> - result = wait_event_timeout(priv->waitq,
>> - (status = priv->status),
>> - adap->timeout);
>> - if (!result)
>> - status = -ETIMEDOUT;
>> -
>> - priv->status = 0;
>> - return i801_check_post(priv, status);
>> + result = wait_for_completion_timeout(&priv->done, adap->timeout);
>> + return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
>> }
>>
>> for (i = 1; i <= len; i++) {
>> @@ -1889,7 +1879,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
>> }
>>
>> if (priv->features & FEATURE_IRQ) {
>> - init_waitqueue_head(&priv->waitq);
>> + init_completion(&priv->done);
>>
>> err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
>> IRQF_SHARED,
>
> The clean-up isn't massive but I agree the code is a bit more pleasant
> to read after the change, and I also see the binary size shrink a bit,
> so I vote for it.
>
> Reviewed-by: Jean Delvare <jdelvare@suse.de>
> Tested-by: Jean Delvare <jdelvare@suse.de>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] i2c: i801: Replace waitqueue with completion API
2021-05-25 13:01 ` Heiner Kallweit
@ 2021-05-27 7:13 ` Daniel Kurtz
0 siblings, 0 replies; 9+ messages in thread
From: Daniel Kurtz @ 2021-05-27 7:13 UTC (permalink / raw
To: Heiner Kallweit; +Cc: Jean Delvare, Linux I2C
Hi Jean, Heiner,
On Tue, May 25, 2021 at 11:01 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
>
> On 25.05.2021 14:12, Jean Delvare wrote:
> > Hi Heiner,
> >
> > Adding Daniel Kurtz, who wrote the original wait queue-based code, to
> > Cc. I'm not sure if Daniel is still into kernel code though.
Thanks for thinking of me! I'm still into kernel code, but I do a lot
more reading than writing these days.
> >
> > On Sat, 22 May 2021 00:02:43 +0200, Heiner Kallweit wrote:
> >> Using the completion API is more intuitive and it allows to simplify
> >> the code. Note that we don't have to set priv->status = 0 any longer
> >> with the completion API.
> >
> > OK, but you need to call reinit_completion() instead, which has the
> > same cost. So that's not a good argument ;-)
> >
> Maybe my comment wasn't clear enough. I didn't want to say that we
> save something but that it's safe from a functional point of view
> to remove clearing priv->status.
>
> >> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> >> ---
> >> drivers/i2c/busses/i2c-i801.c | 48 ++++++++++++++---------------------
> >> 1 file changed, 19 insertions(+), 29 deletions(-)
> >>
> >> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> >> index bfea94d02..738204d77 100644
> >> --- a/drivers/i2c/busses/i2c-i801.c
> >> +++ b/drivers/i2c/busses/i2c-i801.c
> >> @@ -103,7 +103,7 @@
> >> #include <linux/dmi.h>
> >> #include <linux/slab.h>
> >> #include <linux/string.h>
> >> -#include <linux/wait.h>
> >> +#include <linux/completion.h>
> >> #include <linux/err.h>
> >> #include <linux/platform_device.h>
> >> #include <linux/platform_data/itco_wdt.h>
> >> @@ -270,7 +270,7 @@ struct i801_priv {
> >> unsigned int features;
> >>
> >> /* isr processing */
> >> - wait_queue_head_t waitq;
> >> + struct completion done;
> >> u8 status;
> >>
> >> /* Command state used by isr for byte-by-byte block transactions */
> >> @@ -496,24 +496,19 @@ static int i801_wait_byte_done(struct i801_priv *priv)
> >> static int i801_transaction(struct i801_priv *priv, int xact)
> >> {
> >> int status;
> >> - int result;
> >> + unsigned long result;
> >> const struct i2c_adapter *adap = &priv->adapter;
> >>
> >> - result = i801_check_pre(priv);
> >> - if (result < 0)
> >> - return result;
> >> + status = i801_check_pre(priv);
> >> + if (status < 0)
> >> + return status;
> >>
> >> if (priv->features & FEATURE_IRQ) {
> >> + reinit_completion(&priv->done);
> >> outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
> >> SMBHSTCNT(priv));
> >> - result = wait_event_timeout(priv->waitq,
> >> - (status = priv->status),
> >> - adap->timeout);
> >> - if (!result)
> >> - status = -ETIMEDOUT;
> >> -
> >> - priv->status = 0;
> >> - return i801_check_post(priv, status);
> >> + result = wait_for_completion_timeout(&priv->done, adap->timeout);
> >> + return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
> >> }
> >>
> >> /* the current contents of SMBHSTCNT can be overwritten, since PEC,
> >> @@ -638,7 +633,7 @@ static irqreturn_t i801_host_notify_isr(struct i801_priv *priv)
> >> * DEV_ERR - Invalid command, NAK or communication timeout
> >> * BUS_ERR - SMI# transaction collision
> >> * FAILED - transaction was canceled due to a KILL request
> >> - * When any of these occur, update ->status and wake up the waitq.
> >> + * When any of these occur, update ->status and signal completion.
> >> * ->status must be cleared before kicking off the next transaction.
> >> *
> >> * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
> >> @@ -675,7 +670,7 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
> >> if (status) {
> >> outb_p(status, SMBHSTSTS(priv));
> >> priv->status = status;
> >> - wake_up(&priv->waitq);
> >> + complete(&priv->done);
> >> }
> >>
> >> return IRQ_HANDLED;
> >> @@ -694,15 +689,15 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
> >> int i, len;
> >> int smbcmd;
> >> int status;
> >> - int result;
> >> + unsigned long result;
> >> const struct i2c_adapter *adap = &priv->adapter;
> >>
> >> if (command == I2C_SMBUS_BLOCK_PROC_CALL)
> >> return -EOPNOTSUPP;
> >>
> >> - result = i801_check_pre(priv);
> >> - if (result < 0)
> >> - return result;
> >> + status = i801_check_pre(priv);
> >> + if (status < 0)
> >> + return status;
> >>
> >> len = data->block[0];
> >>
> >> @@ -726,15 +721,10 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
> >> priv->count = 0;
> >> priv->data = &data->block[1];
> >>
> >> + reinit_completion(&priv->done);
> >> outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
> >> - result = wait_event_timeout(priv->waitq,
> >> - (status = priv->status),
> >> - adap->timeout);
> >> - if (!result)
> >> - status = -ETIMEDOUT;
> >> -
> >> - priv->status = 0;
> >> - return i801_check_post(priv, status);
> >> + result = wait_for_completion_timeout(&priv->done, adap->timeout);
> >> + return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
> >> }
> >>
> >> for (i = 1; i <= len; i++) {
> >> @@ -1889,7 +1879,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
> >> }
> >>
> >> if (priv->features & FEATURE_IRQ) {
> >> - init_waitqueue_head(&priv->waitq);
> >> + init_completion(&priv->done);
> >>
> >> err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
> >> IRQF_SHARED,
> >
> > The clean-up isn't massive but I agree the code is a bit more pleasant
> > to read after the change, and I also see the binary size shrink a bit,
> > so I vote for it.
> >
> > Reviewed-by: Jean Delvare <jdelvare@suse.de>
> > Tested-by: Jean Delvare <jdelvare@suse.de>
> >
>
I agree, shorter and sweeter. Thanks for cleaning this up!
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] i2c: i801: Remove unneeded warning after wait_event_timeout timeout
2021-05-25 10:00 ` Jean Delvare
@ 2021-05-27 20:09 ` Wolfram Sang
0 siblings, 0 replies; 9+ messages in thread
From: Wolfram Sang @ 2021-05-27 20:09 UTC (permalink / raw
To: Jean Delvare; +Cc: Heiner Kallweit, linux-i2c
[-- Attachment #1: Type: text/plain, Size: 403 bytes --]
On Tue, May 25, 2021 at 12:00:12PM +0200, Jean Delvare wrote:
> On Sat, 22 May 2021 00:00:28 +0200, Heiner Kallweit wrote:
> > When passing -ETIMEDOUT to i801_check_post() it will emit a timeout
> > error message. I don't see much benefit in an additional warning
> > stating more or less the same.
> >
> > Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] i2c: i801: Replace waitqueue with completion API
2021-05-21 22:02 ` [PATCH 2/2] i2c: i801: Replace waitqueue with completion API Heiner Kallweit
2021-05-25 12:12 ` Jean Delvare
@ 2021-05-27 20:09 ` Wolfram Sang
1 sibling, 0 replies; 9+ messages in thread
From: Wolfram Sang @ 2021-05-27 20:09 UTC (permalink / raw
To: Heiner Kallweit; +Cc: Jean Delvare, linux-i2c@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 333 bytes --]
On Sat, May 22, 2021 at 12:02:43AM +0200, Heiner Kallweit wrote:
> Using the completion API is more intuitive and it allows to simplify
> the code. Note that we don't have to set priv->status = 0 any longer
> with the completion API.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-05-27 20:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-21 21:59 [PATCH 0/2] i2c: i801: Replace waitqueue with completion API Heiner Kallweit
2021-05-21 22:00 ` [PATCH 1/2] i2c: i801: Remove unneeded warning after wait_event_timeout timeout Heiner Kallweit
2021-05-25 10:00 ` Jean Delvare
2021-05-27 20:09 ` Wolfram Sang
2021-05-21 22:02 ` [PATCH 2/2] i2c: i801: Replace waitqueue with completion API Heiner Kallweit
2021-05-25 12:12 ` Jean Delvare
2021-05-25 13:01 ` Heiner Kallweit
2021-05-27 7:13 ` Daniel Kurtz
2021-05-27 20:09 ` Wolfram Sang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.