Skip to contentSkip to conversation

sparc32 irq clearing (guest Solaris performance+NetBSD) fix

PATCH In review Artyom Tarasenko 3 participants 16 messages Nov 14, 2009 – Jan 15, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc32 irq clearing (guest Solaris performance+NetBSD) fix

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:
- NetBSD 1.3.3 - 1.5.3 boots successfully
- Solaris 2.5.1 - 7 boots ~1500 times faster (~20 seconds instead of ~8 hours)

---

hw/slavio_intctl.c +0 -0
index 9680392..779c661 100644
@@ -177,19 +177,19 @@ static void slavio_intctlm_mem_writel(void

*opaque, target_phys_addr_t addr,

     saddr = addr >> 2;
     DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
     switch (saddr) {
-    case 2: // clear (enable)
+    case 2: // clear (enable, clear formerly disabled pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
+        s->intregm_pending &= (s->intregm_disabled & val);
         s->intregm_disabled &= ~val;
         DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
         slavio_check_interrupts(s, 1);
         break;
-    case 3: // set (disable, clear pending)
+    case 3: // set (disable, do not clear pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
         s->intregm_disabled |= val;
-        s->intregm_pending &= ~val;
         slavio_check_interrupts(s, 1);
         DPRINTF("Disabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);

---

hw/slavio_intctl.c +3 -3
index 9680392..779c661 100644
@@ -177,19 +177,19 @@ static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr,
     saddr = addr >> 2;
     DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
     switch (saddr) {
-    case 2: // clear (enable)
+    case 2: // clear (enable, clear formerly disabled pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
+        s->intregm_pending &= (s->intregm_disabled & val);
         s->intregm_disabled &= ~val;
         DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
         slavio_check_interrupts(s, 1);
         break;
-    case 3: // set (disable, clear pending)
+    case 3: // set (disable, do not clear pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
         s->intregm_disabled |= val;
-        s->intregm_pending &= ~val;
         slavio_check_interrupts(s, 1);
         DPRINTF("Disabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
#1 lore raw
Quoted 5 lines · Artyom Tarasenko

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:

I think the current version also implements this behaviour. The difference is that now we clear on disable, with your version, the interrupts are cleared when re-enabling them.

With the current version, the interrupts which arrived after getting cleared during disable but before re-enabling become visible after re-enabling. It looks like esp driver in Aurora 1.0, 2.0 and 2.1 depend on this.

Quoted 1 line

- NetBSD 1.3.3 - 1.5.3 boots successfully

I didn't find those even on ftp.netbsd.org, the first I have is 1.6. Thus I could not test if any of the changes I did had any positive effect except if some test failed.

Quoted 9 lines

- Solaris 2.5.1 - 7 boots ~1500 times faster (~20 seconds instead of ~8 hours)

---

hw/slavio_intctl.c +0 -0
index 9680392..779c661 100644

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void · line 184

Quoted 9 lines
hw/slavio_intctl.c +2 -1
@@ -177,19 +177,19 @@ static void slavio_intctlm_mem_writel(void
 *opaque, target_phys_addr_t addr,
     saddr = addr >> 2;
     DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
     switch (saddr) {
-    case 2: // clear (enable)
+    case 2: // clear (enable, clear formerly disabled pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
+        s->intregm_pending &= (s->intregm_disabled & val);

This looks buggy, the AND operation will clear a lot of bits unrelated to val. I think you are missing a ~ here. I tried a few combinations, but none of them passed my tests.

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 192

Quoted 11 lines
hw/slavio_intctl.c +1 -2
         s->intregm_disabled &= ~val;
         DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
         slavio_check_interrupts(s, 1);
         break;
-    case 3: // set (disable, clear pending)
+    case 3: // set (disable, do not clear pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
         s->intregm_disabled |= val;
-        s->intregm_pending &= ~val;

Here
s->intregm_pending &= ~s->intregm_disabled; would also pass my tests. Does that change anything?

Quoted 4 lines
hw/slavio_intctl.c +0 -0
         slavio_check_interrupts(s, 1);
         DPRINTF("Disabled master irq mask %x, curmask %x\n", val,

                s->intregm_disabled);

#2 lore raw

2009/11/14 Blue Swirl <[email protected]>:

Quoted 11 lines
Quoted 5 lines · Artyom Tarasenko

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:

I think the current version also implements this behaviour. The difference is that now we clear on disable, with your version, the interrupts are cleared when re-enabling them.

Doesn't this imply that the current version does not implement this ("Interrupts are cleared by disabling and then re-enabling them") behavior? ;-)

Quoted 4 lines

With the current version, the interrupts which arrived after getting cleared during disable but before re-enabling become visible after re-enabling. It looks like esp driver in Aurora 1.0, 2.0 and 2.1 depend on this.

Hm. It certainly makes sense. But I don't see how does it agree with the NCR89C105 docs. Can it be the documentation is not precise?

Quoted 5 lines
Quoted 1 line

- NetBSD 1.3.3 - 1.5.3 boots successfully

I didn't find those even on ftp.netbsd.org, the first I have is 1.6. Thus I could not test if any of the changes I did had any positive effect except if some test failed.

Have you looked in the NetBSD-archive at ftp.netbsd.org? ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-archive/

Quoted 14 lines
Quoted 14 lines

- Solaris 2.5.1 - 7 boots ~1500 times faster (~20 seconds instead of ~8 hours)

---

hw/slavio_intctl.c +0 -1
index 9680392..779c661 100644
@@ -177,19 +177,19 @@ static void slavio_intctlm_mem_writel(void
 *opaque, target_phys_addr_t addr,
     saddr = addr >> 2;
     DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
     switch (saddr) {
-    case 2: // clear (enable)
Quoted 8 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 183

Quoted 4 lines
hw/slavio_intctl.c +2 -0
+    case 2: // clear (enable, clear formerly disabled pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
+        s->intregm_pending &= (s->intregm_disabled & val);

This looks buggy, the AND operation will clear a lot of bits unrelated to val. I think you are missing a ~ here. I tried a few combinations, but none of them passed my tests.

My bad. It had to be s->intregm_pending &= ~(s->intregm_disabled & val) . But unfortunately it doesn't work.

Quoted 12 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 192

Quoted 11 lines
hw/slavio_intctl.c +1 -2
         s->intregm_disabled &= ~val;
         DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
         slavio_check_interrupts(s, 1);
         break;
-    case 3: // set (disable, clear pending)
+    case 3: // set (disable, do not clear pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
         s->intregm_disabled |= val;
-        s->intregm_pending &= ~val;
Quoted 3 lines

Here
s->intregm_pending &= ~s->intregm_disabled; would also pass my tests. Does that change anything?

No, doesn't work for me either.

Also I put some additional printfs into sun4m.c and see that interrupts are both set while being already set, and reset while not being set. Looks like a bug?

static void cpu_set_irq(void *opaque, int irq, int level)

{
    CPUState *env = opaque;

    if (level) {
        DPRINTF("Raise CPU IRQ %d\n", irq);
        env->halted = 0;
        if(env->pil_in & (1 << irq)) {printf("already set: %d\n",irq);return;}
        env->pil_in |= 1 << irq;
        cpu_check_irqs(env);
    } else {
        DPRINTF("Lower CPU IRQ %d\n", irq);
        if(~(env->pil_in & (1 << irq))) {printf("already low:
%d\n",irq);return;}
        env->pil_in &= ~(1 << irq);
        cpu_check_irqs(env);
    }
}
#3 lore raw
Quoted 9 lines · Artyom Tarasenko

2009/11/14 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 5 lines · Artyom Tarasenko

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:

Quoted 6 lines
Quoted 3 lines

I think the current version also implements this behaviour. The difference is that now we clear on disable, with your version, the interrupts are cleared when re-enabling them.

Doesn't this imply that the current version does not implement this ("Interrupts are cleared by disabling and then re-enabling them") behavior? ;-)

The specification only says that the sequence disable-enable clears interrupts, but not which of these is true:
- clearing happens in the moment of disabling (and interrupts after that are not cleared, current version)
- clearing happens in the moment of re-enabling (your version, sort of)
- clearing happens in both cases (lose interrupts)

It's also interesting to think what happens between the interrupt controller and the devices. Clearing an interrupt at controller level does not clear the interrupt condition at the device. Aren't the interrupts level triggered on Sparc, so the interrupt is still posted? Is the interrupt actually masked by clearing until the level is deactivated?

Or maybe the controller latches the interrupt so that even after the device releases the interrupt line, interrupt is still active towards the CPU. Then the clearing would make sense. This does not match current code.

Quoted 8 lines
Quoted 4 lines

With the current version, the interrupts which arrived after getting cleared during disable but before re-enabling become visible after re-enabling. It looks like esp driver in Aurora 1.0, 2.0 and 2.1 depend on this.

Hm. It certainly makes sense. But I don't see how does it agree with the NCR89C105 docs. Can it be the documentation is not precise?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

- NetBSD 1.3.3 - 1.5.3 boots successfully

I didn't find those even on ftp.netbsd.org, the first I have is 1.6. Thus I could not test if any of the changes I did had any positive effect except if some test failed.

Have you looked in the NetBSD-archive at ftp.netbsd.org? ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-archive/

Yes, but there are no ISOs.

Quoted 52 lines
Quoted 14 lines
Quoted 14 lines

- Solaris 2.5.1 - 7 boots ~1500 times faster (~20 seconds instead of ~8 hours)

---

hw/slavio_intctl.c +0 -1
index 9680392..779c661 100644
@@ -177,19 +177,19 @@ static void slavio_intctlm_mem_writel(void
 *opaque, target_phys_addr_t addr,
     saddr = addr >> 2;
     DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
     switch (saddr) {
-    case 2: // clear (enable)
Quoted 8 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 183

Quoted 4 lines
hw/slavio_intctl.c +2 -0
+    case 2: // clear (enable, clear formerly disabled pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
+        s->intregm_pending &= (s->intregm_disabled & val);

This looks buggy, the AND operation will clear a lot of bits unrelated to val. I think you are missing a ~ here. I tried a few combinations, but none of them passed my tests.

My bad. It had to be s->intregm_pending &= ~(s->intregm_disabled & val) . But unfortunately it doesn't work.

Quoted 12 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 192

Quoted 11 lines
hw/slavio_intctl.c +1 -2
         s->intregm_disabled &= ~val;
         DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
         slavio_check_interrupts(s, 1);
         break;
-    case 3: // set (disable, clear pending)
+    case 3: // set (disable, do not clear pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
         s->intregm_disabled |= val;
-        s->intregm_pending &= ~val;
Quoted 3 lines

Here
s->intregm_pending &= ~s->intregm_disabled; would also pass my tests. Does that change anything?

No, doesn't work for me either.

Also I put some additional printfs into sun4m.c and see that interrupts are both set while being already set, and reset while not being set. Looks like a bug?

static void cpu_set_irq(void *opaque, int irq, int level) {
   CPUState *env = opaque;

Quoted 15 lines

   if (level) {
       DPRINTF("Raise CPU IRQ %d\n", irq);
       env->halted = 0;
       if(env->pil_in & (1 << irq)) {printf("already set: %d\n",irq);return;} env->pil_in |= 1 << irq;
       cpu_check_irqs(env);
   } else {
       DPRINTF("Lower CPU IRQ %d\n", irq);
       if(~(env->pil_in & (1 << irq))) {printf("already low:
%d\n",irq);return;}
       env->pil_in &= ~(1 << irq);
       cpu_check_irqs(env);
   }
}

It should be harmless, though it may suck performance.

#4 lore raw

2009/11/15 Blue Swirl <[email protected]>:

Quoted 18 lines
Quoted 9 lines · Artyom Tarasenko

2009/11/14 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 5 lines · Artyom Tarasenko

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:

Quoted 6 lines
Quoted 3 lines

I think the current version also implements this behaviour. The difference is that now we clear on disable, with your version, the interrupts are cleared when re-enabling them.

Doesn't this imply that the current version does not implement this ("Interrupts are cleared by disabling and then re-enabling them") behavior? ;-)

Quoted 6 lines

The specification only says that the sequence disable-enable clears interrupts, but not which of these is true:
- clearing happens in the moment of disabling (and interrupts after that are not cleared, current version)
- clearing happens  in the moment of re-enabling (your version, sort of)
- clearing happens in both cases (lose interrupts)

English is not my native language, but fwiw I think "and then re-enabling" can only be the second variant. Without "then" it could be either one or three. And if the first variant is what they really meant, the part with "and then" is totally redundant and misleading.

Quoted 6 lines

It's also interesting to think what happens between the interrupt controller and the devices. Clearing an interrupt at controller level does not clear the interrupt condition at the device. Aren't the interrupts level triggered on Sparc, so the interrupt is still posted? Is the interrupt actually masked by clearing until the level is deactivated?

Looks unlikely to me. In the book "Panic! Unix system crash dump analysis" the authors write that the first thing interrupt handler has to do is disable the interrupt, and yes wrting "unix" they mean "SunOS/Solaris".

That's also what I observe debugging the Solaris kernel code (Solaris kernel debugger is a really powerful tool).
Looks like interrupts can be shared between devices, so the general handler disables the interrupt and then calls multiple device-specific handlers sequentially and checks if any of then claims the interrupt. If no one does it writes the message "Spurious interrupt %d\n".

Quoted 3 lines

Or maybe the controller latches the interrupt so that even after the device releases the interrupt line, interrupt is still active towards the CPU. Then the clearing would make sense.

Looks very realistic to me. I think that's the way the interrupts are handled at least under x86.

Quoted 12 lines

This does not match current code.

Quoted 10 lines
Quoted 4 lines

With the current version, the interrupts which arrived after getting cleared during disable but before re-enabling become visible after re-enabling. It looks like esp driver in Aurora 1.0, 2.0 and 2.1 depend on this.

Hm. It certainly makes sense. But I don't see how does it agree with the NCR89C105 docs. Can it be the documentation is not precise?

Quoted 2 lines
Quoted 1 line

- NetBSD 1.3.3 - 1.5.3 boots successfully

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I didn't find those even on ftp.netbsd.org, the first I have is 1.6. Thus I could not test if any of the changes I did had any positive effect except if some test failed.

Have you looked in the NetBSD-archive at ftp.netbsd.org? ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-archive/

Yes, but there are no ISOs.

Don't have ISOs either. I think they did never exist for the early versions. Miniroots can be used.
One nice [missing] feature of OpenBIOS is that it doesn't check whether a disk label is valid.
The disk labels of NetBSD miniroots are invalid, so it's not possible to boot them on a real hw,
or under OBP (it drove me crazy when I was fixing the scsi layer to work with OBP because
I thought miniroots were hdd images).
But, under OpenBIOS it works like a charm:

qemu-system-sparc -nographic -hda miniroot-133.fs -m 64

Quoted 68 lines
Quoted 52 lines
Quoted 14 lines
Quoted 14 lines

- Solaris 2.5.1 - 7 boots ~1500 times faster (~20 seconds instead of ~8 hours)

---

hw/slavio_intctl.c +0 -1
index 9680392..779c661 100644
@@ -177,19 +177,19 @@ static void slavio_intctlm_mem_writel(void
 *opaque, target_phys_addr_t addr,
     saddr = addr >> 2;
     DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
     switch (saddr) {
-    case 2: // clear (enable)
Quoted 8 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 183

Quoted 4 lines
hw/slavio_intctl.c +2 -0
+    case 2: // clear (enable, clear formerly disabled pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
+        s->intregm_pending &= (s->intregm_disabled & val);

This looks buggy, the AND operation will clear a lot of bits unrelated to val. I think you are missing a ~ here. I tried a few combinations, but none of them passed my tests.

My bad. It had to be s->intregm_pending &= ~(s->intregm_disabled & val) . But unfortunately it doesn't work.

Quoted 12 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 192

Quoted 11 lines
hw/slavio_intctl.c +1 -2
         s->intregm_disabled &= ~val;
         DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
         slavio_check_interrupts(s, 1);
         break;
-    case 3: // set (disable, clear pending)
+    case 3: // set (disable, do not clear pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
         s->intregm_disabled |= val;
-        s->intregm_pending &= ~val;
Quoted 3 lines

Here
s->intregm_pending &= ~s->intregm_disabled; would also pass my tests. Does that change anything?

No, doesn't work for me either.

Also I put some additional printfs into sun4m.c and see that interrupts are both set while being already set, and reset while not being set. Looks like a bug?

static void cpu_set_irq(void *opaque, int irq, int level) {
   CPUState *env = opaque;

Quoted 15 lines

   if (level) {
       DPRINTF("Raise CPU IRQ %d\n", irq);
       env->halted = 0;
       if(env->pil_in & (1 << irq)) {printf("already set: %d\n",irq);return;} env->pil_in |= 1 << irq;
       cpu_check_irqs(env);
   } else {
       DPRINTF("Lower CPU IRQ %d\n", irq);
       if(~(env->pil_in & (1 << irq))) {printf("already low:
%d\n",irq);return;}
       env->pil_in &= ~(1 << irq);
       cpu_check_irqs(env);
   }
}

Quoted 1 line

It should be harmless, though it may suck performance.

Do you mean the check against old_interrupt in the cpu_check_irqs()? To me it looks harmless only in the case when we have screaming interrupts of the same level. Or do you mean something else?

The problem is, with "return" after "pritnf" above at least Linux, NetBSD and OBP
hang (or booting so slow that it looks like they hang).

It looks like something is depending on this broken behaviour.

#5 lore raw
Quoted 26 lines · Artyom Tarasenko

2009/11/15 Blue Swirl <[email protected]>:

Quoted 18 lines
Quoted 9 lines · Artyom Tarasenko

2009/11/14 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 5 lines · Artyom Tarasenko

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:

Quoted 6 lines
Quoted 3 lines

I think the current version also implements this behaviour. The difference is that now we clear on disable, with your version, the interrupts are cleared when re-enabling them.

Doesn't this imply that the current version does not implement this ("Interrupts are cleared by disabling and then re-enabling them") behavior? ;-)

Quoted 6 lines

The specification only says that the sequence disable-enable clears interrupts, but not which of these is true:
- clearing happens in the moment of disabling (and interrupts after that are not cleared, current version)
- clearing happens  in the moment of re-enabling (your version, sort of)
- clearing happens in both cases (lose interrupts)

Quoted 4 lines

English is not my native language, but fwiw I think "and then re-enabling" can only be the second variant. Without "then" it could be either one or three. And if the first variant is what they really meant, the part with "and then" is totally redundant and misleading.

Still, this is user documentation, not implementation specification. I'm open to both versions, if they work.

Quoted 20 lines
Quoted 6 lines

It's also interesting to think what happens between the interrupt controller and the devices. Clearing an interrupt at controller level does not clear the interrupt condition at the device. Aren't the interrupts level triggered on Sparc, so the interrupt is still posted? Is the interrupt actually masked by clearing until the level is deactivated?

Looks unlikely to me. In the book "Panic! Unix system crash dump analysis" the authors write that the first thing interrupt handler has to do is disable the interrupt, and yes wrting "unix" they mean "SunOS/Solaris".

That's also what I observe debugging the Solaris kernel code (Solaris kernel debugger is a really powerful tool).
Looks like interrupts can be shared between devices, so the general handler disables the interrupt and then calls multiple device-specific handlers sequentially and checks if any of then claims the interrupt. If no one does it writes the message "Spurious interrupt %d\n".

Quoted 6 lines
Quoted 3 lines

Or maybe the controller latches the interrupt so that even after the device releases the interrupt line, interrupt is still active towards the CPU. Then the clearing would make sense.

Looks very realistic to me. I think that's the way the interrupts are handled at least under x86.

It's a must on x86, because the interrupts are edge triggered.

Quoted 32 lines
Quoted 12 lines

This does not match current code.

Quoted 10 lines
Quoted 4 lines

With the current version, the interrupts which arrived after getting cleared during disable but before re-enabling become visible after re-enabling. It looks like esp driver in Aurora 1.0, 2.0 and 2.1 depend on this.

Hm. It certainly makes sense. But I don't see how does it agree with the NCR89C105 docs. Can it be the documentation is not precise?

Quoted 2 lines
Quoted 1 line

- NetBSD 1.3.3 - 1.5.3 boots successfully

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I didn't find those even on ftp.netbsd.org, the first I have is 1.6. Thus I could not test if any of the changes I did had any positive effect except if some test failed.

Have you looked in the NetBSD-archive at ftp.netbsd.org? ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-archive/

Yes, but there are no ISOs.

Don't have ISOs either. I think they did never exist for the early versions. Miniroots can be used.
One nice [missing] feature of OpenBIOS is that it doesn't check whether a disk label is valid.
The disk labels of NetBSD miniroots are invalid, so it's not possible to boot them on a real hw,
or under OBP (it drove me crazy when I was fixing the scsi layer to work with OBP because
I thought miniroots were hdd images).
But, under OpenBIOS it works like a charm:

Quoted 1 line

qemu-system-sparc -nographic  -hda miniroot-133.fs -m 64

Thanks, now I can try something.

Quoted 68 lines
Quoted 68 lines
Quoted 67 lines
Quoted 14 lines
Quoted 14 lines

- Solaris 2.5.1 - 7 boots ~1500 times faster (~20 seconds instead of ~8 hours)

---

hw/slavio_intctl.c +0 -1
index 9680392..779c661 100644
@@ -177,19 +177,19 @@ static void slavio_intctlm_mem_writel(void
 *opaque, target_phys_addr_t addr,
     saddr = addr >> 2;
     DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
     switch (saddr) {
-    case 2: // clear (enable)
Quoted 8 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 183

Quoted 4 lines
hw/slavio_intctl.c +2 -0
+    case 2: // clear (enable, clear formerly disabled pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
+        s->intregm_pending &= (s->intregm_disabled & val);

This looks buggy, the AND operation will clear a lot of bits unrelated to val. I think you are missing a ~ here. I tried a few combinations, but none of them passed my tests.

My bad. It had to be s->intregm_pending &= ~(s->intregm_disabled & val) . But unfortunately it doesn't work.

Quoted 12 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 192

Quoted 11 lines
hw/slavio_intctl.c +1 -2
         s->intregm_disabled &= ~val;
         DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
         slavio_check_interrupts(s, 1);
         break;
-    case 3: // set (disable, clear pending)
+    case 3: // set (disable, do not clear pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
         s->intregm_disabled |= val;
-        s->intregm_pending &= ~val;
Quoted 3 lines

Here
s->intregm_pending &= ~s->intregm_disabled; would also pass my tests. Does that change anything?

No, doesn't work for me either.

Also I put some additional printfs into sun4m.c and see that interrupts are both set while being already set, and reset while not being set. Looks like a bug?

static void cpu_set_irq(void *opaque, int irq, int level) {
   CPUState *env = opaque;

   if (level) {
       DPRINTF("Raise CPU IRQ %d\n", irq);
       env->halted = 0;
       if(env->pil_in & (1 << irq)) {printf("already set: %d\n",irq);return;} env->pil_in |= 1 << irq;
       cpu_check_irqs(env);
   } else {
       DPRINTF("Lower CPU IRQ %d\n", irq);
       if(~(env->pil_in & (1 << irq))) {printf("already low:
%d\n",irq);return;}
       env->pil_in &= ~(1 << irq);
       cpu_check_irqs(env);
   }
}

Quoted 5 lines
Quoted 1 line

It should be harmless, though it may suck performance.

Do you mean the check against old_interrupt in the cpu_check_irqs()? To me it looks harmless only in the case when we have screaming interrupts of the same level. Or do you mean something else?

If the old level is unchanged, there should be no action. What's the case where you see problems?

Quoted 5 lines

The problem is, with "return" after "pritnf" above at least Linux, NetBSD and OBP
hang (or booting so slow that it looks like they hang).

It looks like something is depending on this broken behaviour.

#6 lore raw

2009/11/16 Blue Swirl <[email protected]>:

Quoted 56 lines
Quoted 26 lines · Artyom Tarasenko

2009/11/15 Blue Swirl <[email protected]>:

Quoted 18 lines
Quoted 9 lines · Artyom Tarasenko

2009/11/14 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 5 lines · Artyom Tarasenko

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:

Quoted 6 lines
Quoted 3 lines

I think the current version also implements this behaviour. The difference is that now we clear on disable, with your version, the interrupts are cleared when re-enabling them.

Doesn't this imply that the current version does not implement this ("Interrupts are cleared by disabling and then re-enabling them") behavior? ;-)

Quoted 6 lines

The specification only says that the sequence disable-enable clears interrupts, but not which of these is true:
- clearing happens in the moment of disabling (and interrupts after that are not cleared, current version)
- clearing happens  in the moment of re-enabling (your version, sort of)
- clearing happens in both cases (lose interrupts)

Quoted 4 lines

English is not my native language, but fwiw I think "and then re-enabling" can only be the second variant. Without "then" it could be either one or three. And if the first variant is what they really meant, the part with "and then" is totally redundant and misleading.

Still, this is user documentation, not implementation specification. I'm open to both versions, if they work.

Quoted 20 lines
Quoted 6 lines

It's also interesting to think what happens between the interrupt controller and the devices. Clearing an interrupt at controller level does not clear the interrupt condition at the device. Aren't the interrupts level triggered on Sparc, so the interrupt is still posted? Is the interrupt actually masked by clearing until the level is deactivated?

Looks unlikely to me. In the book "Panic! Unix system crash dump analysis" the authors write that the first thing interrupt handler has to do is disable the interrupt, and yes wrting "unix" they mean "SunOS/Solaris".

That's also what I observe debugging the Solaris kernel code (Solaris kernel debugger is a really powerful tool).
Looks like interrupts can be shared between devices, so the general handler disables the interrupt and then calls multiple device-specific handlers sequentially and checks if any of then claims the interrupt. If no one does it writes the message "Spurious interrupt %d\n".

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Or maybe the controller latches the interrupt so that even after the device releases the interrupt line, interrupt is still active towards the CPU. Then the clearing would make sense.

Looks very realistic to me. I think that's the way the interrupts are handled at least under x86.

It's a must on x86, because the interrupts are edge triggered.

I don't know, how the real sun4m reacts in the case where irq stays on, not being cleared.
It can not be though that it would try to process irq for every next tick. The CPU must have some time to clear the pending irq, so it must be edge triggered too, at least in a way.

Quoted 104 lines
Quoted 32 lines
Quoted 12 lines

This does not match current code.

Quoted 10 lines
Quoted 4 lines

With the current version, the interrupts which arrived after getting cleared during disable but before re-enabling become visible after re-enabling. It looks like esp driver in Aurora 1.0, 2.0 and 2.1 depend on this.

Hm. It certainly makes sense. But I don't see how does it agree with the NCR89C105 docs. Can it be the documentation is not precise?

Quoted 2 lines
Quoted 1 line

- NetBSD 1.3.3 - 1.5.3 boots successfully

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I didn't find those even on ftp.netbsd.org, the first I have is 1.6. Thus I could not test if any of the changes I did had any positive effect except if some test failed.

Have you looked in the NetBSD-archive at ftp.netbsd.org? ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-archive/

Yes, but there are no ISOs.

Don't have ISOs either. I think they did never exist for the early versions. Miniroots can be used.
One nice [missing] feature of OpenBIOS is that it doesn't check whether a disk label is valid.
The disk labels of NetBSD miniroots are invalid, so it's not possible to boot them on a real hw,
or under OBP (it drove me crazy when I was fixing the scsi layer to work with OBP because
I thought miniroots were hdd images).
But, under OpenBIOS it works like a charm:

Quoted 1 line

qemu-system-sparc -nographic  -hda miniroot-133.fs -m 64

Thanks, now I can try something.

Quoted 68 lines
Quoted 68 lines
Quoted 67 lines
Quoted 14 lines
Quoted 14 lines

- Solaris 2.5.1 - 7 boots ~1500 times faster (~20 seconds instead of ~8 hours)

---

hw/slavio_intctl.c +0 -1
index 9680392..779c661 100644
@@ -177,19 +177,19 @@ static void slavio_intctlm_mem_writel(void
 *opaque, target_phys_addr_t addr,
     saddr = addr >> 2;
     DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
     switch (saddr) {
-    case 2: // clear (enable)
Quoted 8 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 183

Quoted 4 lines
hw/slavio_intctl.c +2 -0
+    case 2: // clear (enable, clear formerly disabled pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
+        s->intregm_pending &= (s->intregm_disabled & val);

This looks buggy, the AND operation will clear a lot of bits unrelated to val. I think you are missing a ~ here. I tried a few combinations, but none of them passed my tests.

My bad. It had to be s->intregm_pending &= ~(s->intregm_disabled & val) . But unfortunately it doesn't work.

Quoted 12 lines

hw/slavio_intctl.c static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr, · line 192

Quoted 11 lines
hw/slavio_intctl.c +1 -2
         s->intregm_disabled &= ~val;
         DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
         slavio_check_interrupts(s, 1);
         break;
-    case 3: // set (disable, clear pending)
+    case 3: // set (disable, do not clear pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
         s->intregm_disabled |= val;
-        s->intregm_pending &= ~val;
Quoted 3 lines

Here
s->intregm_pending &= ~s->intregm_disabled; would also pass my tests. Does that change anything?

No, doesn't work for me either.

Also I put some additional printfs into sun4m.c and see that interrupts are both set while being already set, and reset while not being set. Looks like a bug?

static void cpu_set_irq(void *opaque, int irq, int level) {
   CPUState *env = opaque;

   if (level) {
       DPRINTF("Raise CPU IRQ %d\n", irq);
       env->halted = 0;
       if(env->pil_in & (1 << irq)) {printf("already set: %d\n",irq);return;} env->pil_in |= 1 << irq;
       cpu_check_irqs(env);
   } else {
       DPRINTF("Lower CPU IRQ %d\n", irq);
       if(~(env->pil_in & (1 << irq))) {printf("already low:
%d\n",irq);return;}
       env->pil_in &= ~(1 << irq);
       cpu_check_irqs(env);
   }
}

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

It should be harmless, though it may suck performance.

Do you mean the check against old_interrupt in the cpu_check_irqs()? To me it looks harmless only in the case when we have screaming interrupts of the same level. Or do you mean something else?

If the old level is unchanged, there should be no action. What's the case where you see problems?

In the case where irq 10 and 14 are both being set it can happen that old_interrupt==14 and another call cpu_set_irq(10) would call do_interrupt() ?

#7 lore raw
Quoted 64 lines · Artyom Tarasenko

2009/11/16 Blue Swirl <[email protected]>:

Quoted 63 lines
Quoted 26 lines · Artyom Tarasenko

2009/11/15 Blue Swirl <[email protected]>:

Quoted 18 lines
Quoted 9 lines · Artyom Tarasenko

2009/11/14 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 5 lines · Artyom Tarasenko

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:

Quoted 6 lines
Quoted 3 lines

I think the current version also implements this behaviour. The difference is that now we clear on disable, with your version, the interrupts are cleared when re-enabling them.

Doesn't this imply that the current version does not implement this ("Interrupts are cleared by disabling and then re-enabling them") behavior? ;-)

Quoted 6 lines

The specification only says that the sequence disable-enable clears interrupts, but not which of these is true:
- clearing happens in the moment of disabling (and interrupts after that are not cleared, current version)
- clearing happens  in the moment of re-enabling (your version, sort of)
- clearing happens in both cases (lose interrupts)

Quoted 4 lines

English is not my native language, but fwiw I think "and then re-enabling" can only be the second variant. Without "then" it could be either one or three. And if the first variant is what they really meant, the part with "and then" is totally redundant and misleading.

Still, this is user documentation, not implementation specification. I'm open to both versions, if they work.

Quoted 26 lines
Quoted 6 lines

It's also interesting to think what happens between the interrupt controller and the devices. Clearing an interrupt at controller level does not clear the interrupt condition at the device. Aren't the interrupts level triggered on Sparc, so the interrupt is still posted? Is the interrupt actually masked by clearing until the level is deactivated?

Looks unlikely to me. In the book "Panic! Unix system crash dump analysis" the authors write that the first thing interrupt handler has to do is disable the interrupt, and yes wrting "unix" they mean "SunOS/Solaris".

That's also what I observe debugging the Solaris kernel code (Solaris kernel debugger is a really powerful tool).
Looks like interrupts can be shared between devices, so the general handler disables the interrupt and then calls multiple device-specific handlers sequentially and checks if any of then claims the interrupt. If no one does it writes the message "Spurious interrupt %d\n".

Quoted 3 lines

Or maybe the controller latches the interrupt so that even after the device releases the interrupt line, interrupt is still active towards the CPU. Then the clearing would make sense.

Looks very realistic to me. I think that's the way the interrupts are handled at least under x86.

Quoted 7 lines
Quoted 1 line

It's a must on x86, because the interrupts are edge triggered.

I don't know, how the real sun4m reacts in the case where irq stays on, not being cleared.
It can not be though that it would try to process irq for every next tick. The CPU must have some time to clear the pending irq, so it must be edge triggered too, at least in a way.

This patch makes the interrupts latch: ignore source clearing the interrupt. It seems be ~okay for my usual test setup, but does not help NetBSD 1.3.3. Some other NetBSD tests are changed, but they crashed before.

From bf8c381c4c6f7140ddc73865eba64640f4c75352 Mon Sep 17 00:00:00 2001
From: Blue Swirl <[email protected]>
Date: Mon, 16 Nov 2009 21:48:53 +0000
Subject: [PATCH] Sparc32: latch incoming interrupts

---
 hw/slavio_intctl.c |   11 ++---------
 1 files changed, 2 insertions(+), 9 deletions(-)
hw/slavio_intctl.c +2 -9
index 9aff892..a67d5c9 100644
@@ -188,8 +188,8 @@ static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr,
     case 3: // set (disable, clear pending)
         // Force clear unused bits
         val &= MASTER_IRQ_MASK;
-        s->intregm_disabled |= val;
         s->intregm_pending &= ~val;
+        s->intregm_disabled |= val;
         slavio_check_interrupts(s, 1);
         DPRINTF("Disabled master irq mask %x, curmask %x\n", val,
                 s->intregm_disabled);
@@ -338,15 +338,8 @@ static void slavio_set_irq(void *opaque, int irq, int level)
                     s->slaves[i].intreg_pending |= 1 << pil;
                 }
             }
-        } else {
-            s->intregm_pending &= ~mask;
-            if (pil == 15) {
-                for (i = 0; i < MAX_CPUS; i++) {
-                    s->slaves[i].intreg_pending &= ~(1 << pil);
-                }
-            }
+            slavio_check_interrupts(s, 1);
         }
-        slavio_check_interrupts(s, 1);
     }
 }
 
Signature · 1 line
1.5.6.5
#8 lore raw
Quoted 4 lines · Blue Swirl

This patch makes the interrupts latch: ignore source clearing the interrupt. It seems be ~okay for my usual test setup, but does not help NetBSD 1.3.3. Some other NetBSD tests are changed, but they crashed before.

I'd expect the worst that would happen is "spurious interrupt" messages under some kernel, according to the earlier description of how Solaris handles interrupts (which is quite usual).

At least you'd expect the behaviour to be fine because no interrupts are lost.

Drivers which go wrong because their interrupt handler is called unnecessarily (or at least the "test device has condition pending" function) tend to be rather fragile, because it's expected when interrupt lines are shared between devices.

Then again, some old devices never did shared interrupt lines much.

-- Jamie

#9 lore raw
In reply to Blue Swirl

2009/11/16 Blue Swirl <[email protected]>:

Quoted 74 lines
Quoted 64 lines · Artyom Tarasenko

2009/11/16 Blue Swirl <[email protected]>:

Quoted 63 lines
Quoted 26 lines · Artyom Tarasenko

2009/11/15 Blue Swirl <[email protected]>:

Quoted 18 lines
Quoted 9 lines · Artyom Tarasenko

2009/11/14 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 5 lines · Artyom Tarasenko

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:

Quoted 6 lines
Quoted 3 lines

I think the current version also implements this behaviour. The difference is that now we clear on disable, with your version, the interrupts are cleared when re-enabling them.

Doesn't this imply that the current version does not implement this ("Interrupts are cleared by disabling and then re-enabling them") behavior? ;-)

Quoted 6 lines

The specification only says that the sequence disable-enable clears interrupts, but not which of these is true:
- clearing happens in the moment of disabling (and interrupts after that are not cleared, current version)
- clearing happens  in the moment of re-enabling (your version, sort of)
- clearing happens in both cases (lose interrupts)

Quoted 4 lines

English is not my native language, but fwiw I think "and then re-enabling" can only be the second variant. Without "then" it could be either one or three. And if the first variant is what they really meant, the part with "and then" is totally redundant and misleading.

Still, this is user documentation, not implementation specification. I'm open to both versions, if they work.

Quoted 26 lines
Quoted 6 lines

It's also interesting to think what happens between the interrupt controller and the devices. Clearing an interrupt at controller level does not clear the interrupt condition at the device. Aren't the interrupts level triggered on Sparc, so the interrupt is still posted? Is the interrupt actually masked by clearing until the level is deactivated?

Looks unlikely to me. In the book "Panic! Unix system crash dump analysis" the authors write that the first thing interrupt handler has to do is disable the interrupt, and yes wrting "unix" they mean "SunOS/Solaris".

That's also what I observe debugging the Solaris kernel code (Solaris kernel debugger is a really powerful tool).
Looks like interrupts can be shared between devices, so the general handler disables the interrupt and then calls multiple device-specific handlers sequentially and checks if any of then claims the interrupt. If no one does it writes the message "Spurious interrupt %d\n".

Quoted 3 lines

Or maybe the controller latches the interrupt so that even after the device releases the interrupt line, interrupt is still active towards the CPU. Then the clearing would make sense.

Looks very realistic to me. I think that's the way the interrupts are handled at least under x86.

Quoted 7 lines
Quoted 1 line

It's a must on x86, because the interrupts are edge triggered.

I don't know, how the real sun4m reacts in the case where irq stays on, not being cleared.
It can not be though that it would try to process irq for every next tick. The CPU must have some time to clear the pending irq, so it must be edge triggered too, at least in a way.

Quoted 4 lines

This patch makes the interrupts latch: ignore source clearing the interrupt. It seems be ~okay for my usual test setup, but does not help NetBSD 1.3.3. Some other NetBSD tests are changed, but they crashed before.

Makes no difference in my tests. Except that my broken patch really clears too many interrupts when combined with it. Will play with it further.

#10 lore raw
In reply to Artyom Tarasenko
Quoted 5 lines · Artyom Tarasenko

I don't know, how the real sun4m reacts in the case where irq stays on, not being cleared.
It can not be though that it would try to process irq for every next tick. The CPU must have some time to clear the pending irq, so it must be edge triggered too, at least in a way.

In general, most CPUs have a "disable interrupts" flag which is set at the same time as calling the irq handler.

That's enough, even if everything about interrupts is level triggered, so you can't assume anything is edge triggered just from that alone.

However if a CPU doesn't have an "disable interrupts" flag, then of course the triggering must be edge triggered somewhere.

-- Jamie

#11 lore raw

2009/11/16 Jamie Lokier <[email protected]>:

Quoted 9 lines
Quoted 5 lines · Artyom Tarasenko

I don't know, how the real sun4m reacts in the case where irq stays on, not being cleared.
It can not be though that it would try to process irq for every next tick. The CPU must have some time to clear the pending irq, so it must be edge triggered too, at least in a way.

In general, most CPUs have a "disable interrupts" flag which is set at the same time as calling the irq handler.

I see. The handler has enough time to clear pending irq then. Maybe there is really no latch.

#12 lore raw
In reply to Jamie Lokier
Quoted 7 lines · Jamie Lokier
Quoted 5 lines · Artyom Tarasenko

I don't know, how the real sun4m reacts in the case where irq stays on, not being cleared.
It can not be though that it would try to process irq for every next tick. The CPU must have some time to clear the pending irq, so it must be edge triggered too, at least in a way.

Quoted 8 lines

In general, most CPUs have a "disable interrupts" flag which is set at the same time as calling the irq handler.

That's enough, even if everything about interrupts is level triggered, so you can't assume anything is edge triggered just from that alone.

However if a CPU doesn't have an "disable interrupts" flag, then of course the triggering must be edge triggered somewhere.

Sparc has a flag for disabling all traps. Also the minimum allowed interrupt level (PIL) can be selected from 0 to 14, level 15 is non-maskable from CPU point of view. This level allows interrupt handlers to be interrupted by a higher priority interrupt, if the traps are enabled.

#13 lore raw

after running some OBP/forth tests on a real SS-20 I must say that most of our (especially my) speculations were wrong, as well as what is written in
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt :

1. SS-20 may loose interrupts. At least if a timer interrupt was lowered while still being masked, it is not triggered when enabled.

2. Neither masking, nor unmasking interrupt clears pending bits in the status register. NCR89C105.txt claims it should, but Sun4M_SystemArchitecture_edited2.pdf doesn't. I guess the later one is more reliable.

Signature · 4 lines
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/
#14 lore raw
In reply to Artyom Tarasenko
Quoted 1 line

It looks like something is depending on this broken behaviour.

Or that I shouldn't have used bitwise "not" where boolean "not" were actually meant. cpu_set_irq() is not the source of spurious interrupts, sorry for the noise.

#15 lore raw
In reply to Artyom Tarasenko
Quoted 26 lines · Artyom Tarasenko

2009/11/15 Blue Swirl <[email protected]>:

Quoted 18 lines
Quoted 9 lines · Artyom Tarasenko

2009/11/14 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 5 lines · Artyom Tarasenko

According to NCR89C105 documentation
http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt

Interrupts are cleared by disabling and then re-enabling them. This patch implements the specified behaviour. The most visible effects:

Quoted 6 lines
Quoted 3 lines

I think the current version also implements this behaviour. The difference is that now we clear on disable, with your version, the interrupts are cleared when re-enabling them.

Doesn't this imply that the current version does not implement this ("Interrupts are cleared by disabling and then re-enabling them") behavior? ;-)

Quoted 6 lines

The specification only says that the sequence disable-enable clears interrupts, but not which of these is true:
- clearing happens in the moment of disabling (and interrupts after that are not cleared, current version)
- clearing happens  in the moment of re-enabling (your version, sort of)
- clearing happens in both cases (lose interrupts)

Quoted 4 lines

English is not my native language, but fwiw I think "and then re-enabling" can only be the second variant. Without "then" it could be either one or three. And if the first variant is what they really meant, the part with "and then" is totally redundant and misleading.

It could also be a fourth:

- Clearing happens continuously _during_ the time the interrupt is disabled.

Note that neither this, nor the third possibility, have to cause lost interrupts - that depends on whether the code which enables interrupts checks for them being pending after enabling them, or checks the devices generating them.

Quoted 12 lines
Quoted 6 lines

It's also interesting to think what happens between the interrupt controller and the devices. Clearing an interrupt at controller level does not clear the interrupt condition at the device. Aren't the interrupts level triggered on Sparc, so the interrupt is still posted? Is the interrupt actually masked by clearing until the level is deactivated?

Looks unlikely to me. In the book "Panic! Unix system crash dump analysis" the authors write that the first thing interrupt handler has to do is disable the interrupt, and yes wrting "unix" they mean "SunOS/Solaris".

Quoted 6 lines

That's also what I observe debugging the Solaris kernel code (Solaris kernel debugger is a really powerful tool).
Looks like interrupts can be shared between devices, so the general handler disables the interrupt and then calls multiple device-specific handlers sequentially and checks if any of then claims the interrupt. If no one does it writes the message "Spurious interrupt %d\n".

That's consistent with level triggered interrupts, and may require the interrupt to be cleared at the device before it is re-enabled at the interrupt controller.

Quoted 7 lines
Quoted 3 lines

Or maybe the controller latches the interrupt so that even after the device releases the interrupt line, interrupt is still active towards the CPU. Then the clearing would make sense.

Looks very realistic to me.

From what you said above about Solaris, I don't think you can

distinguish between interrupts being asserted only while a device continues to assert it, and interrupts remaining asserted after the device stops.

-- Jamie