sound/cs4231_lib: replace schedule_timeout() with
Subsystems (2)
PATCH 1/1 sound/cs4231_lib: replace schedule_timeout() with
Quoted 31 lines · Clemens Ladisch
Quoted 18 lines · Nishanth Aravamudan
sound/isa/cs423x/cs4231_lib.cwhich contains the following code:
timeout = HZ / 4 / 2; time = 2; while (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) { set_current_state(TASK_INTERRUPTIBLE); time = schedule_timeout(time); if (time > 0) continue; time = 2; if (--timeout < 0) { snd_printk("mce_down - auto calibration time out (2)\n"); return; } }Quoted 4 lines
This code seems pretty strange, as the delay is in terms of time, which seems to mean the loop (as long as the condition is true, of course) sleeps for 2 jiffies, then sleeps for another 2, about HZ / 4 / 2 (HZ /
8) times. This results in a maximal delay of HZ / 4 jiffies...This code was introduced in revision 1.29:
http://cvs.sourceforge.net/viewcvs.py/alsa/alsa-kernel/isa/cs423x/cs4231_lib.c?rev=HEAD&view=log#rev1.29Originally, there was a single timeout of 250 ms, but it had to be split up into several waits to be able to check the chip status more frequently.
Quoted 5 lines
There is no reason to use 2 jiffies -- the code was written assuming HZ=100 (for 20ms waits), but now this isn't the case anyway.
BTW: Using
TASK_INTERRUPTIBLEisn't quite correct because we don't check for signals here.
Ok, great! Thanks for the information! How about the following patch? I tried to follow the information you gave me as well as what I saw as the original intent of the code. Of course, I am open to changes... Also, there is similar code in sound/sparc/cs4231.c. Can similar changes be made there? It seems like it should be possible, as long as I keep the irq_* functions in place.
Finally, I used TASK_UNINTERRUPTIBLE (i.e. msleep()). This, though, will guarantee that the task sleeps *at least* the requested time (20 ms per iteration). This may lead to a longer delay than desired, for instance, if perhaps the condition should be checked after each signal. I can make this change, of course, and use msleep_interruptible() instead, which to me makes a little more sense...
-Nish
Description: Uses msleep() instead of schedule_timeout() to guarantee the task delays as expected. This lead to several related changes, as the current code assumes the value of HZ is 100. Use timeout as an iteration variable to count out how many 20ms delays should be used.
sound/isa/cs423x/cs4231_lib.c +6 -14
@@ -390,34 +390,26 @@ void snd_cs4231_mce_down(cs4231_t *chip)#if 0 printk ("(2) timeout = %i, jiffies = %li\n" , timeout, jiffies);#endif - timeout =HZ /4 /2 ; - time =2 ; +/* in 20 ms increments, check condition, up to 260 ms */ + timeout =8 ;while (snd_cs4231_in (chip,CS4231_TEST_INIT ) &CS4231_CALIB_IN_PROGRESS ) { -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); -if (time >0 ) -continue ; - time =2 ;if (--timeout <0 ) {snd_printk ("mce_down - auto calibration time out (2)\n" );return ; } +msleep (20 ); }#if 0 printk ("(3) jiffies = %li\n" , jiffies);#endif - timeout =HZ /10 /2 ; - time =2 ; +/* in 20 ms increments, check condition, up to 100 ms */ + timeout =5 ;while (cs4231_inb (chip,CS4231P (REGSEL )) &CS4231_INIT ) { -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); -if (time >0 ) -continue ; - time =2 ;if (--timeout <0 ) {snd_printk (KERN_ERR "mce_down - auto calibration time out (3)\n" );return ; } +msleep (20 ); }#if 0 printk ("(4) jiffies = %li\n" , jiffies);
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
Clemens Ladisch
AppliedRe: [PATCH] sound/cs4231_lib: replace schedule_timeout() with msleep()
Quoted 2 lines · Nishanth Aravamudan
[...]
How about the following patch?
Applied, with some changes (see below).
Quoted 5 lines
I used
TASK_UNINTERRUPTIBLE(i.e.msleep()). This, though, will guarantee that the task sleeps *at least* the requested time (20 ms per iteration). This may lead to a longer delay than desired, for instance, if perhaps the condition should be checked after each signal.
This code was never intended to handle signals; using TASK_INTERRUPTIBLE was a bug.
20 ms happens to be the usual calibration time of the original CS4231 chip (so it was expected to stop after the first iteration), but there are many clones that might need a slightly different time, so I changed it to 10 ms. However, this doesn't really matter. :)
Finally, I removed the time variable because it wasn't used anymore.
Clemens
Index: alsa-kernel/isa/cs423x/cs4231_lib.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/isa/cs423x/cs4231_lib.c,v retrieving revision 1.43
retrieving revision 1.44
isa/cs423x/cs4231_lib.c +6 -15
@@ -356,7 +356,6 @@ {unsigned long flags;int timeout; -signed long time;snd_cs4231_busy_wait (chip);#if 0
@@ -390,34 +389,26 @@#if 0 printk ("(2) timeout = %i, jiffies = %li\n" , timeout, jiffies);#endif - timeout =HZ /4 /2 ; - time =2 ; +/* in 10 ms increments, check condition, up to 250 ms */ + timeout =25 ;while (snd_cs4231_in (chip,CS4231_TEST_INIT ) &CS4231_CALIB_IN_PROGRESS ) { -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); -if (time >0 ) -continue ; - time =2 ;if (--timeout <0 ) {snd_printk ("mce_down - auto calibration time out (2)\n" );return ; } +msleep (10 ); }#if 0 printk ("(3) jiffies = %li\n" , jiffies);#endif - timeout =HZ /10 /2 ; - time =2 ; +/* in 10 ms increments, check condition, up to 100 ms */ + timeout =10 ;while (cs4231_inb (chip,CS4231P (REGSEL )) &CS4231_INIT ) { -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); -if (time >0 ) -continue ; - time =2 ;if (--timeout <0 ) {snd_printk (KERN_ERR "mce_down - auto calibration time out (3)\n" );return ; } +msleep (10 ); }#if 0 printk ("(4) jiffies = %li\n" , jiffies);
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
PATCH 1/1 sound/cs4231: replace schedule_timeout() with
Description: Uses msleep_interruptible() instead of schedule_timeout() to guarantee the task delays as expected. Changes the type of time to match the return value of msleep_interruptible().
sound/sparc/cs4231.c +5 -7
@@ -560,7 +560,7 @@ static void snd_cs4231_mce_down(cs4231_t {unsigned long flags;int timeout; -signed long time; +unsigned long time;spin_lock_irqsave (&chip->lock, flags);snd_cs4231_busy_wait (chip);
@@ -594,29 +594,27 @@ static void snd_cs4231_mce_down(cs4231_t#if 0 printk ("(2) timeout = %i, jiffies = %li\n" , timeout, jiffies);#endif - time =HZ /4 ; + time =250 ;while (snd_cs4231_in (chip,CS4231_TEST_INIT ) &CS4231_CALIB_IN_PROGRESS ) {spin_unlock_irqrestore (&chip->lock, flags);if (time <=0 ) {snd_printk ("mce_down - auto calibration time out (2)\n" );return ; } -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); + time =msleep_interruptible (time);spin_lock_irqsave (&chip->lock, flags); }#if 0 printk ("(3) jiffies = %li\n" , jiffies);#endif - time =HZ /10 ; + time =100 ;while (__cs4231_readb (chip,CS4231P (chip,REGSEL )) &CS4231_INIT ) {spin_unlock_irqrestore (&chip->lock, flags);if (time <=0 ) {snd_printk ("mce_down - auto calibration time out (3)\n" );return ; } -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); + time =msleep_interruptible (time);spin_lock_irqsave (&chip->lock, flags); }spin_unlock_irqrestore (&chip->lock, flags);
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
Re: [PATCH] sound/cs4231: replace schedule_timeout() with msleep_interruptible()
Quoted 13 lines · Nishanth Aravamudan
sound/sparc/cs4231.c +2
-2+ time =250 ;while (snd_cs4231_in (chip,CS4231_TEST_INIT ) &CS4231_CALIB_IN_PROGRESS ) {spin_unlock_irqrestore (&chip->lock, flags);if (time <=0 ) {snd_printk ("mce_down - auto calibration time out (2)\n" );return ; } -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); + time =msleep_interruptible (time);spin_lock_irqsave (&chip->lock, flags); }
Quoted 2 lines
Description: Uses
msleep_interruptible()instead ofschedule_timeout()to guarantee the task delays as expected.
The SPARC driver originated as a copy of the ISA driver and still has the problem that was fixed there, i.e., it uses a single 250 ms wait (which results in a delay of several seconds if OSS programs try to enumerate sample rates).
Like the ISA driver, this driver should check the hardware status more often so that the wait can be aborted as soon as the calibration has finished.
And this driver doesn't expect do receive signals; using msleep() would be just fine.
Clemens
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
Clemens Ladisch
Applied[KJ] Re: [Alsa-devel] [PATCH] sound/cs4231_lib: replace
Quoted 2 lines · Nishanth Aravamudan
[...]
How about the following patch?
Applied, with some changes (see below).
Quoted 5 lines
I used
TASK_UNINTERRUPTIBLE(i.e.msleep()). This, though, will guarantee that the task sleeps *at least* the requested time (20 ms per iteration). This may lead to a longer delay than desired, for instance, if perhaps the condition should be checked after each signal.
This code was never intended to handle signals; using TASK_INTERRUPTIBLE was a bug.
20 ms happens to be the usual calibration time of the original CS4231 chip (so it was expected to stop after the first iteration), but there are many clones that might need a slightly different time, so I changed it to 10 ms. However, this doesn't really matter. :)
Finally, I removed the time variable because it wasn't used anymore.
Clemens
Index: alsa-kernel/isa/cs423x/cs4231_lib.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/isa/cs423x/cs4231_lib.c,v retrieving revision 1.43
retrieving revision 1.44
isa/cs423x/cs4231_lib.c +6 -15
@@ -356,7 +356,6 @@ {unsigned long flags;int timeout; -signed long time;snd_cs4231_busy_wait (chip);#if 0
@@ -390,34 +389,26 @@#if 0 printk ("(2) timeout = %i, jiffies = %li\n" , timeout, jiffies);#endif - timeout =HZ /4 /2 ; - time =2 ; +/* in 10 ms increments, check condition, up to 250 ms */ + timeout =25 ;while (snd_cs4231_in (chip,CS4231_TEST_INIT ) &CS4231_CALIB_IN_PROGRESS ) { -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); -if (time >0 ) -continue ; - time =2 ;if (--timeout <0 ) {snd_printk ("mce_down - auto calibration time out (2)\n" );return ; } +msleep (10 ); }#if 0 printk ("(3) jiffies = %li\n" , jiffies);#endif - timeout =HZ /10 /2 ; - time =2 ; +/* in 10 ms increments, check condition, up to 100 ms */ + timeout =10 ;while (cs4231_inb (chip,CS4231P (REGSEL )) &CS4231_INIT ) { -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); -if (time >0 ) -continue ; - time =2 ;if (--timeout <0 ) {snd_printk (KERN_ERR "mce_down - auto calibration time out (3)\n" );return ; } +msleep (10 ); }#if 0 printk ("(4) jiffies = %li\n" , jiffies);
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
[KJ] Re: [Alsa-devel] [PATCH] sound/cs4231: replace
Quoted 13 lines · Nishanth Aravamudan
isa/cs423x/cs4231_lib.c +2
-2+ time =250 ;while (snd_cs4231_in (chip,CS4231_TEST_INIT ) &CS4231_CALIB_IN_PROGRESS ) {spin_unlock_irqrestore (&chip->lock, flags);if (time <=0 ) {snd_printk ("mce_down - auto calibration time out (2)\n" );return ; } -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); + time =msleep_interruptible (time);spin_lock_irqsave (&chip->lock, flags); }
Quoted 2 lines
Description: Uses
msleep_interruptible()instead ofschedule_timeout()to guarantee the task delays as expected.
The SPARC driver originated as a copy of the ISA driver and still has the problem that was fixed there, i.e., it uses a single 250 ms wait (which results in a delay of several seconds if OSS programs try to enumerate sample rates).
Like the ISA driver, this driver should check the hardware status more often so that the wait can be aborted as soon as the calibration has finished.
And this driver doesn't expect do receive signals; using msleep() would be just fine.
Clemens
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
Re: [PATCH] sound/cs4231: replace schedule_timeout() with msleep_interruptible()
Quoted 22 lines · Clemens Ladisch
Quoted 13 lines · Nishanth Aravamudan
(quoted diff) +2
-2+ time = 250; while (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) { spin_unlock_irqrestore(&chip->lock, flags); if (time <= 0) { snd_printk("mce_down - auto calibration time out (2)\n"); return; } - set_current_state(TASK_INTERRUPTIBLE); - time = schedule_timeout(time); + time = msleep_interruptible(time); spin_lock_irqsave(&chip->lock, flags); }Quoted 2 lines
Description: Uses
msleep_interruptible()instead ofschedule_timeout()to guarantee the task delays as expected.The SPARC driver originated as a copy of the ISA driver and still has the problem that was fixed there, i.e., it uses a single 250 ms wait (which results in a delay of several seconds if OSS programs try to enumerate sample rates).
Quoted 6 lines
Like the ISA driver, this driver should check the hardware status more often so that the wait can be aborted as soon as the calibration has finished.
And this driver doesn't expect do receive signals; using
msleep()would be just fine.
These changes have been made in the following patch. Does it look better now?
-Nish
Description: Uses msleep_interruptible() instead of schedule_timeout() to guarantee the task delays as expected. Changes the type of time to match the return value of msleep_interruptible().
sound/sparc/cs4231.c +8 -9
@@ -560,7 +560,6 @@ static void snd_cs4231_mce_down(cs4231_t {unsigned long flags;int timeout; -signed long time;spin_lock_irqsave (&chip->lock, flags);snd_cs4231_busy_wait (chip);
@@ -594,29 +593,29 @@ static void snd_cs4231_mce_down(cs4231_t#if 0 printk ("(2) timeout = %i, jiffies = %li\n" , timeout, jiffies);#endif - time =HZ /4 ; +/* in 10ms increments, check condition, up to 250ms */ + timeout =25 ;while (snd_cs4231_in (chip,CS4231_TEST_INIT ) &CS4231_CALIB_IN_PROGRESS ) {spin_unlock_irqrestore (&chip->lock, flags); -if (time <=0 ) { +if (--timeout <0 ) {snd_printk ("mce_down - auto calibration time out (2)\n" );return ; } -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); +msleep (10 );spin_lock_irqsave (&chip->lock, flags); }#if 0 printk ("(3) jiffies = %li\n" , jiffies);#endif - time =HZ /10 ; +/* in 10ms increments, check condition, up to 100ms */ + timeout =10 ;while (__cs4231_readb (chip,CS4231P (chip,REGSEL )) &CS4231_INIT ) {spin_unlock_irqrestore (&chip->lock, flags); -if (time <=0 ) { +if (--timeout <0 ) {snd_printk ("mce_down - auto calibration time out (3)\n" );return ; } -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); +msleep (10 );spin_lock_irqsave (&chip->lock, flags); }spin_unlock_irqrestore (&chip->lock, flags);
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
Nishanth Aravamudan
Acked-by[KJ] Re: [Alsa-devel] [PATCH] sound/cs4231_lib: replace
In reply to Clemens LadischQuoted 15 lines · Clemens Ladisch
Quoted 2 lines · Nishanth Aravamudan
[...]
How about the following patch?Applied, with some changes (see below).
Quoted 5 lines
I used
TASK_UNINTERRUPTIBLE(i.e.msleep()). This, though, will guarantee that the task sleeps *at least* the requested time (20 ms per iteration). This may lead to a longer delay than desired, for instance, if perhaps the condition should be checked after each signal.This code was never intended to handle signals; using
TASK_INTERRUPTIBLEwas a bug.
Quoted 6 lines
20 ms happens to be the usual calibration time of the original CS4231 chip (so it was expected to stop after the first iteration), but there are many clones that might need a slightly different time, so I changed it to 10 ms. However, this doesn't really matter. :)
Finally, I removed the time variable because it wasn't used anymore.
Great,i
I will resend the sparc patch now.
-Nish
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
Nishanth Aravamudan
Acked-byRe: [PATCH] sound/cs4231_lib: replace schedule_timeout() with msleep()
In reply to Clemens LadischQuoted 15 lines · Clemens Ladisch
Quoted 2 lines · Nishanth Aravamudan
[...]
How about the following patch?Applied, with some changes (see below).
Quoted 5 lines
I used
TASK_UNINTERRUPTIBLE(i.e.msleep()). This, though, will guarantee that the task sleeps *at least* the requested time (20 ms per iteration). This may lead to a longer delay than desired, for instance, if perhaps the condition should be checked after each signal.This code was never intended to handle signals; using
TASK_INTERRUPTIBLEwas a bug.
Quoted 6 lines
20 ms happens to be the usual calibration time of the original CS4231 chip (so it was expected to stop after the first iteration), but there are many clones that might need a slightly different time, so I changed it to 10 ms. However, this doesn't really matter. :)
Finally, I removed the time variable because it wasn't used anymore.
Great,i
I will resend the sparc patch now.
-Nish
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
[KJ] Re: [Alsa-devel] [PATCH] sound/cs4231: replace
In reply to Clemens LadischQuoted 22 lines · Clemens Ladisch
Quoted 13 lines · Nishanth Aravamudan
(quoted diff) +2
-2+ time = 250; while (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) { spin_unlock_irqrestore(&chip->lock, flags); if (time <= 0) { snd_printk("mce_down - auto calibration time out (2)\n"); return; } - set_current_state(TASK_INTERRUPTIBLE); - time = schedule_timeout(time); + time = msleep_interruptible(time); spin_lock_irqsave(&chip->lock, flags); }Quoted 2 lines
Description: Uses
msleep_interruptible()instead ofschedule_timeout()to guarantee the task delays as expected.The SPARC driver originated as a copy of the ISA driver and still has the problem that was fixed there, i.e., it uses a single 250 ms wait (which results in a delay of several seconds if OSS programs try to enumerate sample rates).
Quoted 6 lines
Like the ISA driver, this driver should check the hardware status more often so that the wait can be aborted as soon as the calibration has finished.
And this driver doesn't expect do receive signals; using
msleep()would be just fine.
These changes have been made in the following patch. Does it look better now?
-Nish
Description: Uses msleep_interruptible() instead of schedule_timeout() to guarantee the task delays as expected. Changes the type of time to match the return value of msleep_interruptible().
sound/sparc/cs4231.c +8 -9
@@ -560,7 +560,6 @@ static void snd_cs4231_mce_down(cs4231_t {unsigned long flags;int timeout; -signed long time;spin_lock_irqsave (&chip->lock, flags);snd_cs4231_busy_wait (chip);
@@ -594,29 +593,29 @@ static void snd_cs4231_mce_down(cs4231_t#if 0 printk ("(2) timeout = %i, jiffies = %li\n" , timeout, jiffies);#endif - time =HZ /4 ; +/* in 10ms increments, check condition, up to 250ms */ + timeout =25 ;while (snd_cs4231_in (chip,CS4231_TEST_INIT ) &CS4231_CALIB_IN_PROGRESS ) {spin_unlock_irqrestore (&chip->lock, flags); -if (time <=0 ) { +if (--timeout <0 ) {snd_printk ("mce_down - auto calibration time out (2)\n" );return ; } -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); +msleep (10 );spin_lock_irqsave (&chip->lock, flags); }#if 0 printk ("(3) jiffies = %li\n" , jiffies);#endif - time =HZ /10 ; +/* in 10ms increments, check condition, up to 100ms */ + timeout =10 ;while (__cs4231_readb (chip,CS4231P (chip,REGSEL )) &CS4231_INIT ) {spin_unlock_irqrestore (&chip->lock, flags); -if (time <=0 ) { +if (--timeout <0 ) {snd_printk ("mce_down - auto calibration time out (3)\n" );return ; } -set_current_state (TASK_INTERRUPTIBLE ); - time =schedule_timeout (time); +msleep (10 );spin_lock_irqsave (&chip->lock, flags); }spin_unlock_irqrestore (&chip->lock, flags);
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
Re: [PATCH] sound/cs4231: replace schedule_timeout() with msleep_interruptible()
Quoted 3 lines · Nishanth Aravamudan
[...]
These changes have been made in the following patch. Does it look better now?
Yes. Applied.
Thanks!
Clemens
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
[KJ] Re: [Alsa-devel] [PATCH] sound/cs4231: replace
In reply to Clemens LadischQuoted 3 lines · Nishanth Aravamudan
[...]
These changes have been made in the following patch. Does it look better now?
Yes. Applied.
Thanks!
Clemens
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors