Skip to contentSkip to conversation

I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)

PATCH Daniel Marjamäki 4 participants 4 messages Nov 20, 2005

lore
Share & tools
lore
#0 lore raw

Hello!

I made a patch and I would like feedback.
If you can test the patch.. please let me know.

Background:
There are busy loops that time out after 8 million repetitions. I made these improvements:
* Sleep during the busy loops
* Time out is based on elapsed time

If this patch is accepted, AZT_TIMEOUT can be removed.

Best regards,
Daniel Marjamäki

diff -up a/drivers/cdrom/aztcd.c b/drivers/cdrom/aztcd.c

drivers/cdrom/aztcd.c +14 -13
@@ -179,6 +179,7 @@
 #include <linux/ioport.h>
 #include <linux/string.h>
 #include <linux/major.h>
+#include <linux/jiffies.h>
 
 #include <linux/init.h>
 
@@ -308,7 +309,7 @@ static char aztDiskChanged = 1;
 static char aztTocUpToDate = 0;
 
 static unsigned char aztIndatum;
-static unsigned long aztTimeOutCount;
+static unsigned long aztTimeOutCount, aztTimeOut;
 static int aztCmd = 0;
 
 static DEFINE_SPINLOCK(aztSpin);
@@ -361,14 +362,14 @@ static int azt_bcd2bin(unsigned char bcd
 # define OP_OK op_ok()
 static void op_ok(void)
 {
-	aztTimeOutCount = 0;
+	aztTimeOut = jiffies + 2;
 	do {
 		aztIndatum = inb(DATA_PORT);
-		aztTimeOutCount++;
-		if (aztTimeOutCount >= AZT_TIMEOUT) {
+		if (time_after(jiffies, aztTimeOut)) {
 			printk("aztcd: Error Wait OP_OK\n");
 			break;
 		}
+		schedule_timeout_interruptible(1);
 	} while (aztIndatum != AFL_OP_OK);
 }
 
@@ -377,14 +378,14 @@ static void op_ok(void)
 # define PA_OK pa_ok()
 static void pa_ok(void)
 {
-	aztTimeOutCount = 0;
+	aztTimeOut = jiffies + 2;
 	do {
 		aztIndatum = inb(DATA_PORT);
-		aztTimeOutCount++;
-		if (aztTimeOutCount >= AZT_TIMEOUT) {
+		if (time_after(jiffies, aztTimeOut)) {
 			printk("aztcd: Error Wait PA_OK\n");
 			break;
 		}
+		schedule_timeout_interruptible(1);
 	} while (aztIndatum != AFL_PA_OK);
 }
 #endif
@@ -393,17 +394,17 @@ static void pa_ok(void)
 # define STEN_LOW  sten_low()
 static void sten_low(void)
 {
-	aztTimeOutCount = 0;
+	aztTimeOut = jiffies + 2;
 	do {
 		aztIndatum = inb(STATUS_PORT);
-		aztTimeOutCount++;
-		if (aztTimeOutCount >= AZT_TIMEOUT) {
+		if (time_after(jiffies, aztTimeOut)) {
 			if (azt_init_end)
 				printk
 				    ("aztcd: Error Wait STEN_LOW commands:%x\n",
 				     aztCmd);
 			break;
 		}
+		schedule_timeout_interruptible(1);
 	} while (aztIndatum & AFL_STATUS);
 }
 
@@ -411,14 +412,14 @@ static void sten_low(void)
 # define DTEN_LOW dten_low()
 static void dten_low(void)
 {
-	aztTimeOutCount = 0;
+	aztTimeOut = jiffies + 2;
 	do {
 		aztIndatum = inb(STATUS_PORT);
-		aztTimeOutCount++;
-		if (aztTimeOutCount >= AZT_TIMEOUT) {
+		if (time_after(jiffies, aztTimeOut)) {
 			printk("aztcd: Error Wait DTEN_OK\n");
 			break;
 		}
+		schedule_timeout_interruptible(1);
 	} while (aztIndatum & AFL_DATA);
 }
 
#1 lore raw

drivers/cdrom/aztcd.c static int azt_bcd2bin(unsigned char bcd · line 372

Quoted 13 lines
  static void op_ok(void)
  {
drivers/cdrom/aztcd.c +3 -3
-	aztTimeOutCount = 0;
+	aztTimeOut = jiffies + 2;
  	do {
  		aztIndatum = inb(DATA_PORT);
-		aztTimeOutCount++;
-		if (aztTimeOutCount >= AZT_TIMEOUT) {
+		if (time_after(jiffies, aztTimeOut)) {
  			printk("aztcd: Error Wait OP_OK\n");
  			break;
  		}
+		schedule_timeout_interruptible(1);

this I think is not quite right; schedule_timeout_*() doesn't do anything unless you set current->state to something. And at that point you might as well start using msleep()!

but what you're doing is generally a good idea; busy waits as the original code did is quite wrong...

#2 lore raw

On Sun, 2005-11-20 at 16:38 +0100, Arjan van de Ven wrote: > }

Quoted 4 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		schedule_timeout_interruptible(1);

this I think is not quite right; schedule_timeout_*() doesn't do anything unless you set current->state to something.

Err, schedule_timeout_(un)interruptible sets current->state.

tglx

#3 lore raw
In reply to Arjan van de Ven
Quoted 14 lines · Arjan van de Ven

drivers/cdrom/aztcd.c static int azt_bcd2bin(unsigned char bcd · line 372

Quoted 13 lines
  static void op_ok(void)
  {
drivers/cdrom/aztcd.c +3 -3
-     aztTimeOutCount = 0;
+     aztTimeOut = jiffies + 2;
      do {
              aztIndatum = inb(DATA_PORT);
-             aztTimeOutCount++;
-             if (aztTimeOutCount >= AZT_TIMEOUT) {
+             if (time_after(jiffies, aztTimeOut)) {
                      printk("aztcd: Error Wait OP_OK\n");
                      break;
              }
+             schedule_timeout_interruptible(1);
Quoted 3 lines

this I think is not quite right; schedule_timeout_*() doesn't do anything unless you set current->state to something. And at that point you might as well start using msleep()!

Not true, as Thomas points out. You are right for schedule_timeout(), but that's why we introduced the _interruptible() and _uninterruptible(). And there are reasons to use schedule_timeout_*() instead of msleep() [not necessarily in this case, but in general], specifically the presence of wait-queues.

Quoted 2 lines

but what you're doing is generally a good idea; busy waits as the original code did is quite wrong...

I agree, and I recommend Daniel post to LKML to get some testing / see if anyone actually uses this driver :)

Thanks,
Nish