Re: cli/sti in char/vt.c [patch] (Was Re: Sources of jiffy inconsistencies.)

Andrew Derrick Balsa (andrebalsa@altern.org)
Fri, 29 May 1998 01:29:53 -0100


This is a multi-part message in MIME format.

--------------581BCC7A5635A143223E2F22
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Hi Rafael,

Rafael R. Reilova wrote:
>
...
> The following patch (against 2.1.103) attempts to fix that. I believe it
> also makes it SMP safe, but I only have a UP, so can't test.
>
> For those about to yell that a race exists for port 0x43, between the vt
> driver and the timer interrupt, don't. Timer accesses may be interleaved
> (as long as it is to different timers!).
>
> Spinlocks seemed to be a monstruous overkill, so I used test_and_set
> instead. Interrupts are no longer disabled.
>
> The changes are few, but the identation makes the patch long :-(
> Any Comments?
>
Just one: neat :)

Here is the same patch, against 2.0.33. Please direct any flames to
Rafael ;-)

Cheers,
------------------------
André Balsa
andrebalsa@altern.org

--------------581BCC7A5635A143223E2F22
Content-Type: text/plain; charset=us-ascii; name="vt.c.2-0.33.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="vt.c.2-0.33.patch"

--- ./linux/drivers/char/vt.c.orig Mon May 13 06:36:19 1996
+++ ./linux/drivers/char/vt.c Fri May 29 01:09:04 1998
@@ -23,6 +23,7 @@

#include <asm/io.h>
#include <asm/segment.h>
+#include <asm/bitops.h>

#include "kbd_kern.h"
#include "vt_kern.h"
@@ -147,11 +148,16 @@
* We also return immediately, which is what was implied within the X
* comments - KDMKTONE doesn't put the process to sleep.
*/
+
+static volatile unsigned mksound_lock = 0;
+
static void
kd_nosound(unsigned long ignored)
{
- /* disable counter 2 */
- outb(inb_p(0x61)&0xFC, 0x61);
+ /* if sound is being set up, don't turn it off */
+ if (!mksound_lock)
+ /* disable counter 2 */
+ outb(inb_p(0x61)&0xFC, 0x61);
return;
}

@@ -165,25 +171,29 @@

if (hz > 20 && hz < 32767)
count = 1193180 / hz;
-
- cli();
- del_timer(&sound_timer);
- if (count) {
- /* enable counter 2 */
- outb_p(inb_p(0x61)|3, 0x61);
- /* set command for counter 2, 2 byte write */
- outb_p(0xB6, 0x43);
- /* select desired HZ */
- outb_p(count & 0xff, 0x42);
- outb((count >> 8) & 0xff, 0x42);
-
- if (ticks) {
- sound_timer.expires = jiffies+ticks;
- add_timer(&sound_timer);
- }
- } else
- kd_nosound(0);
- sti();
+
+ /* ignore multiple simultaneous requests for sound */
+ if (!set_bit(0, &mksound_lock)) {
+ /* set_bit in 2.0.x is same as test-and-set in 2.1.x */
+ del_timer(&sound_timer);
+ if (count) {
+ /* enable counter 2 */
+ outb_p(inb_p(0x61)|3, 0x61);
+ /* set command for counter 2, 2 byte write */
+ outb_p(0xB6, 0x43);
+ /* select desired HZ */
+ outb_p(count & 0xff, 0x42);
+ outb((count >> 8) & 0xff, 0x42);
+
+ if (ticks) {
+ sound_timer.expires = jiffies+ticks;
+ add_timer(&sound_timer);
+ }
+ } else
+ kd_nosound(0);
+
+ mksound_lock = 0;
+ }
return;
}

--------------581BCC7A5635A143223E2F22--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu