Skip to contentSkip to conversation

staging: rtl8723bs: replace msleep with usleep_range

PATCH In review Ofek Almog 4 participants 5 messages Feb 14 – Feb 15 Staging

lore
Share & tools
lore

Ofek Almog

author
#0 lore raw

PATCH 1/1 staging: rtl8723bs: replace msleep with usleep_range

This patch replaces msleep(10) with usleep_range(10000, 11000) to provide more precise delay handling while allowing the timer subsystem to coalesce timers efficiently.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +1 -1
index b2e7f479f72b..3f5b3ca2066d 100644
@@ -214,7 +214,7 @@ void _rtw_free_evt_priv(struct	evt_priv *pevtpriv)
 {
 	_cancel_workitem_sync(&pevtpriv->c2h_wk);
 	while (pevtpriv->c2h_wk_alive)
-		msleep(10);
+		usleep_range(10000, 11000);
 
 	while (!rtw_cbuf_empty(pevtpriv->c2h_queue)) {
 		void *c2h = rtw_cbuf_pop(pevtpriv->c2h_queue);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 14 lines · Ofek Almog

This patch replaces msleep(10) with usleep_range(10000, 11000) to provide more precise delay handling while allowing the timer subsystem to coalesce timers efficiently.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +0 -0
index b2e7f479f72b..3f5b3ca2066d 100644

drivers/staging/rtl8723bs/core/rtw_cmd.c void _rtw_free_evt_priv(struct evt_priv *pevtpriv) · line 220

Quoted 8 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +1 -1
@@ -214,7 +214,7 @@ void _rtw_free_evt_priv(struct	evt_priv *pevtpriv)
 {
 	_cancel_workitem_sync(&pevtpriv->c2h_wk);
 	while (pevtpriv->c2h_wk_alive)
-		msleep(10);
+		usleep_range(10000, 11000);
 
 	while (!rtw_cbuf_empty(pevtpriv->c2h_queue)) {
 		void *c2h = rtw_cbuf_pop(pevtpriv->c2h_queue);

Shouldn't we be using fsleep() now instead of replacing msleep() with usleep_range() when the time is sub 20ms?

I feel like I read Andy Shevchenko mention this elsewhere.

Thanks,

ET

#2 lore raw
Quoted 4 lines · Ethan Tidmore
Quoted 3 lines · Ofek Almog

This patch replaces msleep(10) with usleep_range(10000, 11000) to provide more precise delay handling while allowing the timer subsystem to coalesce timers efficiently.

...

Quoted 3 lines

drivers/staging/rtl8723bs/core/rtw_cmd.c void _rtw_free_evt_priv(struct evt_priv *pevtpriv) · line 217

Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +1 -1
 	while (pevtpriv->c2h_wk_alive)
-		msleep(10);
+		usleep_range(10000, 11000);

The whole approach here seems to be fragile. It should rather use completion mechanism instead of infinite loop.

Quoted 7 lines

drivers/staging/rtl8723bs/core/rtw_cmd.c void _rtw_free_evt_priv(struct evt_priv *pevtpriv) · line 220

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +0 -0
 	while (!rtw_cbuf_empty(pevtpriv->c2h_queue)) {
 		void *c2h = rtw_cbuf_pop(pevtpriv->c2h_queue);

Shouldn't we be using fsleep() now instead of replacing msleep() with usleep_range() when the time is sub 20ms?

I feel like I read Andy Shevchenko mention this elsewhere.

Yep.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#3 lore raw

(Resending as plain text, apologies if you received a previous HTML version)

Hi Andy, Ethan,

Thank you both for the review.

Regarding the fsleep() suggestion - understood, that clearly seems like the right helper to use here.

Regarding the completion mechanism logic - I completely agree that the current infinite loop polling is fragile. However, as this is my very first contribution and I do not have the hardware to verify logic changes, I am hesitant to refactor the synchronization mechanism blindly.

Would you prefer I send a v2 that strictly switches to fsleep() as an incremental improvement over msleep(), or should I drop this patch altogether until someone with the hardware can refactor the logic properly?

Best regards,
Ofek

‫בתאריך שבת, 14 בפבר׳ 2026 ב-20:24 מאת ‪Andy Shevchenko‬‏ <‪[email protected]‬‏>:‬

Quoted 31 lines · Ethan Tidmore
Quoted 4 lines · Ofek Almog
Quoted 3 lines

This patch replaces msleep(10) with usleep_range(10000, 11000) to provide more precise delay handling while allowing the timer subsystem to coalesce timers efficiently.

...

Quoted 3 lines

drivers/staging/rtl8723bs/core/rtw_cmd.c void _rtw_free_evt_priv(struct evt_priv *pevtpriv) · line 217

Quoted 3 lines
    while (pevtpriv->c2h_wk_alive)
drivers/staging/rtl8723bs/core/rtw_cmd.c +1 -1
-           msleep(10);
+           usleep_range(10000, 11000);

The whole approach here seems to be fragile. It should rather use completion mechanism instead of infinite loop.

Quoted 7 lines
Quoted 2 lines
    while (!rtw_cbuf_empty(pevtpriv->c2h_queue)) {
            void *c2h = rtw_cbuf_pop(pevtpriv->c2h_queue);

Shouldn't we be using fsleep() now instead of replacing msleep() with usleep_range() when the time is sub 20ms?

I feel like I read Andy Shevchenko mention this elsewhere.

Yep.

--
With Best Regards,
Andy Shevchenko

maintainer
#4 lore raw
Quoted 15 lines · Ofek Almog

(Resending as plain text, apologies if you received a previous HTML version)

Hi Andy, Ethan,

Thank you both for the review.

Regarding the fsleep() suggestion - understood, that clearly seems like the right helper to use here.

Regarding the completion mechanism logic - I completely agree that the current infinite loop polling is fragile. However, as this is my very first contribution and I do not have the hardware to verify logic changes, I am hesitant to refactor the synchronization mechanism blindly.

Quoted 4 lines

Would you prefer I send a v2 that strictly switches to fsleep() as an incremental improvement over msleep(), or should I drop this patch altogether until someone with the hardware can refactor the logic properly?

Please drop it, see the archives for why (you need someone with the hardare and specs to figure out what needs to be done.)

thanks,

greg k-h