linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
       [not found] <5aZsv-3CJ-17@gated-at.bofh.it>
@ 2005-11-20 20:58 ` Bodo Eggert
  2005-11-20 21:07   ` Nish Aravamudan
  2005-11-21  8:09   ` Daniel Marjamäki
  0 siblings, 2 replies; 13+ messages in thread
From: Bodo Eggert @ 2005-11-20 20:58 UTC (permalink / raw)
  To: Daniel Marjamäki, linux-kernel

Daniel Marjamäki <daniel.marjamaki@comhem.se> wrote:

> -     aztTimeOutCount = 0;
> +     aztTimeOut = jiffies + 2;

Different timeout based on HZ seems wrong.
-- 
Ich danke GMX dafür, die Verwendung meiner Adressen mittels per SPF
verbreiteten Lügen zu sabotieren.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-20 20:58 ` I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c) Bodo Eggert
@ 2005-11-20 21:07   ` Nish Aravamudan
  2005-11-21  8:09   ` Daniel Marjamäki
  1 sibling, 0 replies; 13+ messages in thread
From: Nish Aravamudan @ 2005-11-20 21:07 UTC (permalink / raw)
  To: 7eggert; +Cc: Daniel Marjamäki, linux-kernel

On 11/20/05, Bodo Eggert <harvested.in.lkml@posting.7eggert.dyndns.org> wrote:
> Daniel Marjamäki <daniel.marjamaki@comhem.se> wrote:
>
> > -     aztTimeOutCount = 0;
> > +     aztTimeOut = jiffies + 2;
>
> Different timeout based on HZ seems wrong.

True; I'm trying to think of a good way to emulate 8000000 iterations
of loop, though. Really, this is not terrible to use 2 jiffies of
offset, as we try to sleep 1 jiffy each time. As long as we don't get
a signal *right* away, we'll sleep probably for 2 loops. Not sure,
though, may be useful to see what happens in practice and then debug
further for the right value.

May also want to use time_after_eq() not time_after().

Thanks,
Nish

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-20 20:58 ` I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c) Bodo Eggert
  2005-11-20 21:07   ` Nish Aravamudan
@ 2005-11-21  8:09   ` Daniel Marjamäki
  2005-11-21  8:19     ` Con Kolivas
  1 sibling, 1 reply; 13+ messages in thread
From: Daniel Marjamäki @ 2005-11-21  8:09 UTC (permalink / raw)
  To: linux-kernel; +Cc: 7eggert, nish.aravamudan



Bodo Eggert wrote:
> Daniel Marjamäki <daniel.marjamaki@comhem.se> wrote:
> 
> 
>>-     aztTimeOutCount = 0;
>>+     aztTimeOut = jiffies + 2;
> 
> 
> Different timeout based on HZ seems wrong.

Yes, but..

If I'd say "HZ/100", then all systems that uses my driver must have HZ>=200.

The way I do it:
All systems will give me a delay for at least a few ms.
I get the shortest timeout possible on each computer.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-21  8:09   ` Daniel Marjamäki
@ 2005-11-21  8:19     ` Con Kolivas
  2005-11-21  8:42       ` Daniel Marjamäki
  2005-11-21 16:33       ` Bodo Eggert
  0 siblings, 2 replies; 13+ messages in thread
From: Con Kolivas @ 2005-11-21  8:19 UTC (permalink / raw)
  To: Daniel Marjamäki; +Cc: linux-kernel, 7eggert, nish.aravamudan

On Mon, 21 Nov 2005 19:09, Daniel Marjamäki wrote:
> Bodo Eggert wrote:
> > Daniel Marjamäki <daniel.marjamaki@comhem.se> wrote:
> >>-     aztTimeOutCount = 0;
> >>+     aztTimeOut = jiffies + 2;
> >
> > Different timeout based on HZ seems wrong.
>
> Yes, but..
>
> If I'd say "HZ/100", then all systems that uses my driver must have
> HZ>=200.
>
> The way I do it:
> All systems will give me a delay for at least a few ms.
> I get the shortest timeout possible on each computer.

Convention in the kernel would be 
	aztTimeOut =  HZ / 100 ? : 1;
to be at least one tick (works for HZ even below 100) and is at least 10ms. If 
you wanted 2 ms then use
	aztTimeOut =  HZ / 500 ? : 1;
which would give you at least 2ms

Cheers,
Con

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-21  8:19     ` Con Kolivas
@ 2005-11-21  8:42       ` Daniel Marjamäki
  2005-11-21  9:11         ` Con Kolivas
  2005-11-21 16:33       ` Bodo Eggert
  1 sibling, 1 reply; 13+ messages in thread
From: Daniel Marjamäki @ 2005-11-21  8:42 UTC (permalink / raw)
  To: Con Kolivas; +Cc: linux-kernel



Con Kolivas wrote:
> 
> Convention in the kernel would be 
> 	aztTimeOut =  HZ / 100 ? : 1;
> to be at least one tick (works for HZ even below 100) and is at least 10ms. If 
> you wanted 2 ms then use
> 	aztTimeOut =  HZ / 500 ? : 1;
> which would give you at least 2ms
> 

Thank you Con for the feedback.

Hmm.. The minimum value should be 2, right?
Otherwise the loop could time out after only a few nanoseconds.. since the loop will then timeout immediately on a clock tick.
Or am I wrong?

Best regards,
Daniel Marjamäki




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-21  8:42       ` Daniel Marjamäki
@ 2005-11-21  9:11         ` Con Kolivas
  2005-11-21 10:47           ` Nick Piggin
  0 siblings, 1 reply; 13+ messages in thread
From: Con Kolivas @ 2005-11-21  9:11 UTC (permalink / raw)
  To: Daniel Marjamäki; +Cc: linux-kernel

On Mon, 21 Nov 2005 19:42, Daniel Marjamäki wrote:
> Con Kolivas wrote:
> > Convention in the kernel would be
> > 	aztTimeOut =  HZ / 100 ? : 1;
> > to be at least one tick (works for HZ even below 100) and is at least
> > 10ms. If you wanted 2 ms then use
> > 	aztTimeOut =  HZ / 500 ? : 1;
> > which would give you at least 2ms
>
> Thank you Con for the feedback.
>
> Hmm.. The minimum value should be 2, right?
> Otherwise the loop could time out after only a few nanoseconds.. since the
> loop will then timeout immediately on a clock tick. Or am I wrong?

 	aztTimeOut =  HZ / 500 ? : 1;
Would give you a 2ms timeout on 1000Hz and 500Hz
It would give you 5ms on 250Hz and 10ms on 100Hz

ie the absolute minimum it would be would be 2ms, but it would always be at 
least one timer tick which is longer than 2ms at low HZ values.

Cheers,
Con

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-21  9:11         ` Con Kolivas
@ 2005-11-21 10:47           ` Nick Piggin
  2005-11-21 15:08             ` Nish Aravamudan
  0 siblings, 1 reply; 13+ messages in thread
From: Nick Piggin @ 2005-11-21 10:47 UTC (permalink / raw)
  To: Con Kolivas; +Cc: Daniel Marjamäki, linux-kernel

Con Kolivas wrote:
> On Mon, 21 Nov 2005 19:42, Daniel Marjamäki wrote:

>>Hmm.. The minimum value should be 2, right?
>>Otherwise the loop could time out after only a few nanoseconds.. since the
>>loop will then timeout immediately on a clock tick. Or am I wrong?
> 
> 
>  	aztTimeOut =  HZ / 500 ? : 1;
> Would give you a 2ms timeout on 1000Hz and 500Hz
> It would give you 5ms on 250Hz and 10ms on 100Hz
> 
> ie the absolute minimum it would be would be 2ms, but it would always be at 
> least one timer tick which is longer than 2ms at low HZ values.
> 

Not true. From 'now', the next timer interrupt is somewhere
between epsilon and 1/HZ seconds away.

Luckily, time_after is < rather than <=, so your aztTimeOut would
actually make Daniel's code wait until a minimum of *two* timer
ticks have elapsed since reading jiffies. So it would manage to
scrape by the values of HZ you quoted.

OTOH, if HZ were between 500 and 1000, it would again be too short
due to truncation.

Better I think would be to use the proper interfaces for converting
msecs to jiffies:

   aztTimeOut = jiffies + msecs_to_jiffies(2);

Nick

-- 
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-21 10:47           ` Nick Piggin
@ 2005-11-21 15:08             ` Nish Aravamudan
  0 siblings, 0 replies; 13+ messages in thread
From: Nish Aravamudan @ 2005-11-21 15:08 UTC (permalink / raw)
  To: Nick Piggin; +Cc: Con Kolivas, Daniel Marjamäki, linux-kernel

On 11/21/05, Nick Piggin <nickpiggin@yahoo.com.au> wrote:
> Con Kolivas wrote:
> > On Mon, 21 Nov 2005 19:42, Daniel Marjamäki wrote:
>
> >>Hmm.. The minimum value should be 2, right?
> >>Otherwise the loop could time out after only a few nanoseconds.. since the
> >>loop will then timeout immediately on a clock tick. Or am I wrong?
> >
> >
> >       aztTimeOut =  HZ / 500 ? : 1;
> > Would give you a 2ms timeout on 1000Hz and 500Hz
> > It would give you 5ms on 250Hz and 10ms on 100Hz
> >
> > ie the absolute minimum it would be would be 2ms, but it would always be at
> > least one timer tick which is longer than 2ms at low HZ values.
> >
>
> Not true. From 'now', the next timer interrupt is somewhere
> between epsilon and 1/HZ seconds away.
>
> Luckily, time_after is < rather than <=, so your aztTimeOut would
> actually make Daniel's code wait until a minimum of *two* timer
> ticks have elapsed since reading jiffies. So it would manage to
> scrape by the values of HZ you quoted.
>
> OTOH, if HZ were between 500 and 1000, it would again be too short
> due to truncation.
>
> Better I think would be to use the proper interfaces for converting
> msecs to jiffies:
>
>    aztTimeOut = jiffies + msecs_to_jiffies(2);

That's what I get for sleeping. Yes, Nick is right, don't do this
conversion yourself, please, use the interfaces designed exactly to
avoid any confusion / HZ-issues (and if those interfaces have
limitations, as Willy discovered earlier, please fix them).

Thanks,
Nish

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-21  8:19     ` Con Kolivas
  2005-11-21  8:42       ` Daniel Marjamäki
@ 2005-11-21 16:33       ` Bodo Eggert
  1 sibling, 0 replies; 13+ messages in thread
From: Bodo Eggert @ 2005-11-21 16:33 UTC (permalink / raw)
  To: Con Kolivas; +Cc: Daniel Marjamäki, linux-kernel, 7eggert, nish.aravamudan

On Mon, 21 Nov 2005, Con Kolivas wrote:
> On Mon, 21 Nov 2005 19:09, Daniel Marjamäki wrote:

> > The way I do it:
> > All systems will give me a delay for at least a few ms.
> > I get the shortest timeout possible on each computer.
> 
> Convention in the kernel would be 
> 	aztTimeOut =  HZ / 100 ? : 1;
> to be at least one tick (works for HZ even below 100) and is at least 10ms.

You have to add one to the timeout, since you might be just before the end 
of the timeslice when the delay starts. aztTimeOut = (HZ / 100 ? : 1) + 1;

-- 
Top 100 things you don't want the sysadmin to say:
11. Can you get VMS for this Sparc thingy?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-20 15:38 ` Arjan van de Ven
  2005-11-20 17:15   ` Thomas Gleixner
@ 2005-11-20 21:04   ` Nish Aravamudan
  1 sibling, 0 replies; 13+ messages in thread
From: Nish Aravamudan @ 2005-11-20 21:04 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Daniel Marjamäki, linux-kernel

On 11/20/05, Arjan van de Ven <arjan@infradead.org> wrote:
> >   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);
>
> 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.

> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-20 15:38 ` Arjan van de Ven
@ 2005-11-20 17:15   ` Thomas Gleixner
  2005-11-20 21:04   ` Nish Aravamudan
  1 sibling, 0 replies; 13+ messages in thread
From: Thomas Gleixner @ 2005-11-20 17:15 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Daniel Marjamäki, linux-kernel

On Sun, 2005-11-20 at 16:38 +0100, Arjan van de Ven wrote:	>   		}
> > +		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



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
  2005-11-20 15:29 Daniel Marjamäki
@ 2005-11-20 15:38 ` Arjan van de Ven
  2005-11-20 17:15   ` Thomas Gleixner
  2005-11-20 21:04   ` Nish Aravamudan
  0 siblings, 2 replies; 13+ messages in thread
From: Arjan van de Ven @ 2005-11-20 15:38 UTC (permalink / raw)
  To: Daniel Marjamäki; +Cc: linux-kernel

>   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);

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...



^ permalink raw reply	[flat|nested] 13+ messages in thread

* I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c)
@ 2005-11-20 15:29 Daniel Marjamäki
  2005-11-20 15:38 ` Arjan van de Ven
  0 siblings, 1 reply; 13+ messages in thread
From: Daniel Marjamäki @ 2005-11-20 15:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: Daniel Marjamäki


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

--- a/drivers/cdrom/aztcd.c	2005-11-17 11:39:53.000000000 +0100
+++ b/drivers/cdrom/aztcd.c	2005-11-19 17:14:58.000000000 +0100
@@ -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);
  }




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2005-11-21 16:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5aZsv-3CJ-17@gated-at.bofh.it>
2005-11-20 20:58 ` I made a patch and would like feedback/testers (drivers/cdrom/aztcd.c) Bodo Eggert
2005-11-20 21:07   ` Nish Aravamudan
2005-11-21  8:09   ` Daniel Marjamäki
2005-11-21  8:19     ` Con Kolivas
2005-11-21  8:42       ` Daniel Marjamäki
2005-11-21  9:11         ` Con Kolivas
2005-11-21 10:47           ` Nick Piggin
2005-11-21 15:08             ` Nish Aravamudan
2005-11-21 16:33       ` Bodo Eggert
2005-11-20 15:29 Daniel Marjamäki
2005-11-20 15:38 ` Arjan van de Ven
2005-11-20 17:15   ` Thomas Gleixner
2005-11-20 21:04   ` Nish Aravamudan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).