Skip to contentSkip to conversation

net: core: fix msleep() is not accurate

PATCH In review Yejune Deng 2 participants 3 messages Dec 10, 2020 – Dec 11, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: core: fix msleep() is not accurate

See Documentation/timers/timers-howto.rst, msleep() is not for (1ms - 20ms), There is a more advanced API is used.

---
 net/core/dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/dev.c +2 -2
index d33099f..6e83ee03 100644
@@ -6726,9 +6726,9 @@ void napi_disable(struct napi_struct *n)
 	set_bit(NAPI_STATE_DISABLE, &n->state);
 
 	while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
-		msleep(1);
+		fsleep(1000);
 	while (test_and_set_bit(NAPI_STATE_NPSVC, &n->state))
-		msleep(1);
+		fsleep(1000);
 
 	hrtimer_cancel(&n->timer);
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 14 lines · Yejune Deng

See Documentation/timers/timers-howto.rst, msleep() is not for (1ms - 20ms), There is a more advanced API is used.

---
 net/core/dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/dev.c +0 -0
index d33099f..6e83ee03 100644

net/core/dev.c void napi_disable(struct napi_struct *n) · line 6732

Quoted 9 lines
net/core/dev.c +2 -2
@@ -6726,9 +6726,9 @@ void napi_disable(struct napi_struct *n)
        set_bit(NAPI_STATE_DISABLE, &n->state);
 
        while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
-               msleep(1);
+               fsleep(1000);
        while (test_and_set_bit(NAPI_STATE_NPSVC, &n->state))
-               msleep(1);
+               fsleep(1000);
 

I would prefer explicit usleep_range().

fsleep() is not common in the kernel, I had to go to its definition.

I would argue that we should use usleep_range(10, 200) to have an opportunity to spend less time in napi_disable() in some cases.

#2 lore raw

Does anyone else have a different opinion? If not,I will adopt it and resubmit.

Quoted 32 lines · Eric Dumazet
Quoted 14 lines · Yejune Deng

See Documentation/timers/timers-howto.rst, msleep() is not for (1ms - 20ms), There is a more advanced API is used.

---
 net/core/dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/dev.c +0 -0
index d33099f..6e83ee03 100644

net/core/dev.c void napi_disable(struct napi_struct *n) · line 6732

Quoted 9 lines
net/core/dev.c +2 -2
@@ -6726,9 +6726,9 @@ void napi_disable(struct napi_struct *n)
        set_bit(NAPI_STATE_DISABLE, &n->state);
 
        while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
-               msleep(1);
+               fsleep(1000);
        while (test_and_set_bit(NAPI_STATE_NPSVC, &n->state))
-               msleep(1);
+               fsleep(1000);
 

I would prefer explicit usleep_range().

fsleep() is not common in the kernel, I had to go to its definition.

I would argue that we should use usleep_range(10, 200) to have an opportunity to spend less time in napi_disable() in some cases.