* [PATCH] staging: rtl8723bs: replace yield() with usleep_range() and cond_resched()
@ 2026-10-20 4:59 sarbansah151
2026-10-20 7:08 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: sarbansah151 @ 2026-10-20 4:59 UTC (permalink / raw)
To: gregkh; +Cc: linux-staging
yield() merely reschedules the calling task and does not sleep, so
using it in hardware poll loops spins the CPU while waiting on the
device. checkpatch.pl flags this class of bug ("Using yield() is
generally wrong", see yield() kernel-doc in sched/core.c).
In the firmware download poll loops the git history shows a
commented-out mdelay(10) at these sites, which indicates a ~10ms
delay was intended; restore it with usleep_range(10000, 20000), the
correct idiom for sub-20ms sleeps. In the firmware checksum/ready
poll loops use usleep_range(1000, 2000) to rate-limit register
polling.
In the TX path there is an explicit comment that sleeping even 1ms
causes throughput loss, so use cond_resched() there instead: it
yields the CPU only when the scheduler actually wants to run
something else.
Signed-off-by: Sarban Sah <sarbansah151@gmail.com>
---
drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c | 4 ++--
drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c | 4 ++--
drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c
b/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c
--- a/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c
@@ -634,7 +634,7 @@
rtl8723b_set_FwRsvdPagePkt(padapter, 0);
DLBcnCount++;
do {
- yield();
+ usleep_range(10000, 20000);
/* check rsvd page download OK. */
rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bcn_valid));
poll++;
@@ -893,7 +893,7 @@
SetFwRsvdPagePkt_BTCoex(padapter);
DLBcnCount++;
do {
- yield();
+ usleep_range(10000, 20000);
/* check rsvd page download OK. */
rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, &bcn_valid);
poll++;
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
--- a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
@@ -192,7 +192,7 @@
if (value32 & FWDL_ChkSum_rpt || adapter->bSurpriseRemoved ||
adapter->driver_stopped)
break;
- yield();
+ usleep_range(1000, 2000);
} while (jiffies_to_msecs(jiffies-start) < timeout_ms || cnt < min_cnt);
if (!(value32 & FWDL_ChkSum_rpt))
@@ -232,7 +232,7 @@
value32 = rtw_read32(adapter, REG_MCUFWDL);
if (value32 & WINTINI_RDY || adapter->bSurpriseRemoved ||
adapter->driver_stopped)
break;
- yield();
+ usleep_range(1000, 2000);
} while (jiffies_to_msecs(jiffies - start) < timeout_ms || cnt < min_cnt);
if (!(value32 & WINTINI_RDY))
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
b/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
--- a/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
@@ -328,7 +328,7 @@
rtw_free_xmitframe(pxmitpriv, pframe);
pxmitbuf->priv_data = NULL;
enqueue_pending_xmitbuf(pxmitpriv, pxmitbuf);
- yield();
+ cond_resched();
} else
rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
pxmitbuf = NULL;
@@ -383,7 +383,7 @@
if (padapter->registrypriv.wifi_spec)
msleep(1);
else
- yield();
+ cond_resched();
goto next;
}
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] staging: rtl8723bs: replace yield() with usleep_range() and cond_resched()
2026-10-20 4:59 [PATCH] staging: rtl8723bs: replace yield() with usleep_range() and cond_resched() sarbansah151
@ 2026-10-20 7:08 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-10-20 7:08 UTC (permalink / raw)
To: sarbansah151; +Cc: gregkh, linux-staging
On Tue, Oct 20, 2026 at 12:59:47AM -0400, sarbansah151@gmail.com wrote:
> yield() merely reschedules the calling task and does not sleep, so
> using it in hardware poll loops spins the CPU while waiting on the
> device. checkpatch.pl flags this class of bug ("Using yield() is
> generally wrong", see yield() kernel-doc in sched/core.c).
>
> In the firmware download poll loops the git history shows a
> commented-out mdelay(10) at these sites, which indicates a ~10ms
> delay was intended; restore it with usleep_range(10000, 20000), the
> correct idiom for sub-20ms sleeps. In the firmware checksum/ready
> poll loops use usleep_range(1000, 2000) to rate-limit register
> polling.
>
> In the TX path there is an explicit comment that sleeping even 1ms
> causes throughput loss, so use cond_resched() there instead: it
> yields the CPU only when the scheduler actually wants to run
> something else.
>
> Signed-off-by: Sarban Sah <sarbansah151@gmail.com>
> ---
We generally wouldn't merge this without testing even without the
staging anti-AI rules, but mainly this driver has been deleted in
linux-next.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-20 7:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 4:59 [PATCH] staging: rtl8723bs: replace yield() with usleep_range() and cond_resched() sarbansah151
2026-10-20 7:08 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox