Skip to contentSkip to conversation

Char: moxa, fix and optimise empty timer

PATCH In review Jiri Slaby 2 participants 3 messages Jul 25, 2007 – Jul 27, 2007 Char and misc drivers

lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/1 Char: moxa, fix and optimise empty timer

moxa, fix and optimise empty timer

don't wait and delete empty timer in empty timer function. Also fire next empty timer at rounded jiffies to save power.

---
commit da52793b6347e8b6b048526ce2422e29b20bb335
tree ad0bee78e45beef89dc740f81e0606d782296542
parent 3a69b463dcad1ff142f46e8fb74e7dc5a092eb60
author Jiri Slaby <[email protected]> Wed, 25 Jul 2007 23:42:49 +0200 committer Jiri Slaby <[email protected]> Wed, 25 Jul 2007 23:42:49 +0200

 drivers/char/moxa.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/char/moxa.c +2 -2
index ed76f0a..5000b3b 100644
@@ -1040,14 +1040,14 @@ static void check_xmit_empty(unsigned long data)
 	struct moxa_port *ch;
 
 	ch = (struct moxa_port *) data;
-	del_timer_sync(&moxa_ports[ch->port].emptyTimer);
 	if (ch->tty && (ch->statusflags & EMPTYWAIT)) {
 		if (MoxaPortTxQueue(ch->port) == 0) {
 			ch->statusflags &= ~EMPTYWAIT;
 			tty_wakeup(ch->tty);
 			return;
 		}
-		mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ);
+		mod_timer(&moxa_ports[ch->port].emptyTimer,
+				round_jiffies(jiffies + HZ));
 	} else
 		ch->statusflags &= ~EMPTYWAIT;
 }
#1 lore raw
Quoted 5 lines · On Wed, 25 Jul 2007 23:43:29 +0200 (CEST) Jiri Slaby <[email protected]>…

moxa, fix and optimise empty timer

don't wait and delete empty timer in empty timer function. Also fire next empty timer at rounded jiffies to save power.

What is actually being "fixed" here?

Quoted 22 lines

---
commit da52793b6347e8b6b048526ce2422e29b20bb335
tree ad0bee78e45beef89dc740f81e0606d782296542
parent 3a69b463dcad1ff142f46e8fb74e7dc5a092eb60
author Jiri Slaby <[email protected]> Wed, 25 Jul 2007 23:42:49 +0200 committer Jiri Slaby <[email protected]> Wed, 25 Jul 2007 23:42:49 +0200

 drivers/char/moxa.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/char/moxa.c +0 -1
index ed76f0a..5000b3b 100644
@@ -1040,14 +1040,14 @@ static void check_xmit_empty(unsigned long data)
 	struct moxa_port *ch;
 
 	ch = (struct moxa_port *) data;
-	del_timer_sync(&moxa_ports[ch->port].emptyTimer);
 	if (ch->tty && (ch->statusflags & EMPTYWAIT)) {
 		if (MoxaPortTxQueue(ch->port) == 0) {

drivers/char/moxa.c static void check_xmit_empty(unsigned long data) · line 1053

Quoted 10 lines
drivers/char/moxa.c +2 -1
 			ch->statusflags &= ~EMPTYWAIT;
 			tty_wakeup(ch->tty);
 			return;
 		}
-		mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ);
+		mod_timer(&moxa_ports[ch->port].emptyTimer,
+				round_jiffies(jiffies + HZ));
 	} else
 		ch->statusflags &= ~EMPTYWAIT;
 }

A call to check_xmit_empty() used to guarantee that the timer was no longer running (if the first `if' succeeds and the second does not), but that is no longer the case. You're sure this is correct?

author
#2 lore raw

Andrew Morton napsal(a):

Quoted 9 lines · On Wed, 25 Jul 2007 23:43:29 +0200 (CEST) Jiri Slaby <[email protected]>…
Quoted 6 lines

moxa, fix and optimise empty timer

don't wait and delete empty timer in empty timer function. Also fire next empty timer at rounded jiffies to save power.

What is actually being "fixed" here?

Lockup (see below).

Quoted 17 lines
Quoted 17 lines

---
commit da52793b6347e8b6b048526ce2422e29b20bb335
tree ad0bee78e45beef89dc740f81e0606d782296542
parent 3a69b463dcad1ff142f46e8fb74e7dc5a092eb60
author Jiri Slaby <[email protected]> Wed, 25 Jul 2007 23:42:49 +0200 committer Jiri Slaby <[email protected]> Wed, 25 Jul 2007 23:42:49 +0200

 drivers/char/moxa.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/char/moxa.c +0 -0
index ed76f0a..5000b3b 100644
@@ -1040,14 +1040,14 @@ static void check_xmit_empty(unsigned long data)
 	struct moxa_port *ch;
 
Quoted 2 lines

drivers/char/moxa.c static void check_xmit_empty(unsigned long data) · line 1043

Quoted 2 lines
drivers/char/moxa.c +0 -1
 	ch = (struct moxa_port *) data;
-	del_timer_sync(&moxa_ports[ch->port].emptyTimer);

It's "wait until the code below me is finished". At least the _sync is buggy.

Quoted 7 lines
Quoted 7 lines
drivers/char/moxa.c +0 -1
 	if (ch->tty && (ch->statusflags & EMPTYWAIT)) {
 		if (MoxaPortTxQueue(ch->port) == 0) {
 			ch->statusflags &= ~EMPTYWAIT;
 			tty_wakeup(ch->tty);
 			return;
 		}
-		mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ);
Quoted 8 lines

drivers/char/moxa.c static void check_xmit_empty(unsigned long data) · line 1053

Quoted 5 lines
drivers/char/moxa.c +2 -0
+		mod_timer(&moxa_ports[ch->port].emptyTimer,
+				round_jiffies(jiffies + HZ));
 	} else
 		ch->statusflags &= ~EMPTYWAIT;
 }

A call to check_xmit_empty() used to guarantee that the timer was no longer running (if the first `if' succeeds and the second does not), but that is

Correct me if I'm wrong, but it guaranteed nothing. When the timer function is called (note, that check_xmit_empty is timer.function), timer base lock is held and there is no window to schedule the timer again when its function is running.

Quoted 1 line

no longer the case. You're sure this is correct?

I still think so.

thanks,

Signature · 2 lines
Jiri Slaby ([email protected])
Faculty of Informatics, Masaryk University