diff mbox series

[09/10] staging: wfx: ensure HIF request has been sent before polling

Message ID 20220225112405.355599-10-Jerome.Pouiller@silabs.com (mailing list archive)
State Not Applicable
Delegated to: Johannes Berg
Headers show
Series staging: wfx: usual maintenance | expand

Commit Message

Jérôme Pouiller Feb. 25, 2022, 11:24 a.m. UTC
From: Jérôme Pouiller <jerome.pouiller@silabs.com>

wfx_bh_request_tx() send HIF request asynchronously through bh_work().
Then the caller will run wfx_bh_poll_irq() to poll the answer.

However it useless to burn CPU cycles for the polling while the request
has yet been sent. Worse, wfx_bh_poll_irq() may get the CPU and prevent
wfx_bh_request_tx() to run. This problem has been observed on mono core
architecture.

This first exchange is correct:
    kworker/u2:1-24    [000] ....    : io_read32: CONTROL: 00003000
    kworker/u2:1-24    [000] ....    : io_read32: CONTROL: 00003000
    kworker/u2:1-24    [000] ....    : io_read32: CONTROL: 00003004
    kworker/u2:1-24    [000] ....    : io_read32: CONTROL: 00003004
    kworker/0:1H-40    [000] ....    : io_read: QUEUE: 08 00 09 0c 00 00 00 00 3a 7b 00 30 (12 bytes)
    kworker/0:1H-40    [000] ....    : piggyback: CONTROL: 00003000
    kworker/0:1H-40    [000] ....    : hif_recv: 0:2:CNF_CONFIGURATION: 00 00 00 00 (8 bytes)
    kworker/0:1H-40    [000] ....    : io_read32: CONFIG: 03010200
    kworker/0:1H-40    [000] ....    : bh_stats: IND/REQ/CNF:  0/  0/  1, REQ in progress:  0, WUP: release

... while the following is not:
    kworker/u2:1-24    [000] ....    : io_read32: CONTROL: 00003000
    kworker/u2:1-24    [000] ....    : io_read32: CONTROL: 00003000
    kworker/u2:1-24    [000] ....    : io_read32: CONTROL: 00003000
    [...loop until timeout...]
    wfx-sdio mmc0:0001:1: time out while polling control register

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
---
 drivers/staging/wfx/bh.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Tetsuo Handa April 12, 2022, 1:11 p.m. UTC | #1
Hello.

I found that commit c86176d51340d5ee ("staging: wfx: ensure HIF request has
been sent before polling") started using flush_workqueue(system_highpri_wq).

But please avoid flushing system-wide workqueues, for
flushing system-wide workqueues is dangerous and will be forbidden.

Link: https://lkml.kernel.org/r/49925af7-78a8-a3dd-bce6-cfc02e1a9236@I-love.SAKURA.ne.jp
Jérôme Pouiller April 13, 2022, 3:18 p.m. UTC | #2
On Tuesday 12 April 2022 15:11:53 CEST Tetsuo Handa wrote:
> Hello.
> 
> I found that commit c86176d51340d5ee ("staging: wfx: ensure HIF request has
> been sent before polling") started using flush_workqueue(system_highpri_wq).
> 
> But please avoid flushing system-wide workqueues, for
> flushing system-wide workqueues is dangerous and will be forbidden.
> 
> Link: https://lkml.kernel.org/r/49925af7-78a8-a3dd-bce6-cfc02e1a9236@I-love.SAKURA.ne.jp
> 
> 

There is a workqueue provided by mac80211. But I am not sure it can 
replace the system-wide workqueue.

I guess I need to declare a new workqueue. Give me a couple of weeks to
prepare a patch.
diff mbox series

Patch

diff --git a/drivers/staging/wfx/bh.c b/drivers/staging/wfx/bh.c
index 4c6ba9c342a6..bcea9d5b119c 100644
--- a/drivers/staging/wfx/bh.c
+++ b/drivers/staging/wfx/bh.c
@@ -295,6 +295,7 @@  void wfx_bh_poll_irq(struct wfx_dev *wdev)
 	u32 reg;
 
 	WARN(!wdev->poll_irq, "unexpected IRQ polling can mask IRQ");
+	flush_workqueue(system_highpri_wq);
 	start = ktime_get();
 	for (;;) {
 		wfx_control_reg_read(wdev, &reg);