Skip to contentSkip to conversation

Debug shared irqs.

PATCH In review David Woodhouse 5 participants 11 messages Dec 22, 2005 – Jan 6, 2006

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Debug shared irqs.

Drivers registering IRQ handlers with SA_SHIRQ really ought to be able to handle an interrupt happening before request_irq() returns. They also ought to be able to handle an interrupt happening during the start of their call to free_irq(). Let's test that hypothesis....

I'm not wonderfully happy with the faked pt_regs, but I think it ought to be OK like that.

lib//Kconfig.debug renamed from lib//Kconfig.debug~ +9 -0
@@ -176,6 +176,15 @@ config DEBUG_VM
 
 	  If unsure, say N.
 
+config SHARE_ME_HARDER
+       bool "Debug shared IRQ handlers"
+       depends on GENERIC_HARDIRQS
+       help
+         Enable this to generate a spurious interrupt as soon as a shared interrupt
+	 handler is registered, and just before one is deregistered. Drivers ought
+	 to be able to handle interrupts coming in at those some; some don't and
+	 need to be caught.
+
 config FRAME_POINTER
 	bool "Compile the kernel with frame pointers"
 	depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML)
kernel/irq/manage.c renamed from kernel/irq/manage.c~ +26 -0
@@ -238,6 +238,10 @@ int setup_irq(unsigned int irq, struct i
 	return 0;
 }
 
+#ifdef CONFIG_SHARE_ME_HARDER
+static struct pt_regs shirq_fakeregs;
+#endif
+
 /**
  *	free_irq - free an interrupt
  *	@irq: Interrupt line to free
@@ -257,6 +261,7 @@ void free_irq(unsigned int irq, void *de
 	struct irq_desc *desc;
 	struct irqaction **p;
 	unsigned long flags;
+	irqreturn_t (*handler)(int, void *, struct pt_regs *) = NULL;
 
 	if (irq >= NR_IRQS)
 		return;
@@ -295,6 +300,8 @@ void free_irq(unsigned int irq, void *de
 
 			/* Make sure it's not being used on another CPU */
 			synchronize_irq(irq);
+			if (action->flags & SA_SHIRQ)
+				handler = action->handler;
 			kfree(action);
 			return;
 		}
@@ -302,6 +309,15 @@ void free_irq(unsigned int irq, void *de
 		spin_unlock_irqrestore(&desc->lock,flags);
 		return;
 	}
+#ifdef CONFIG_SHARE_ME_HARDER
+	if (handler) {
+		/* It's a shared IRQ -- the driver ought to be prepared for it to happen
+		   even now it's being freed, so let's make sure.... 
+		   We do this after actually deregistering it, to make sure that a 'real'
+		   IRQ doesn't run in parallel with our fake. */
+		handler(irq, dev_id, &shirq_fakeregs);
+	}
+#endif
 }
 
 EXPORT_SYMBOL(free_irq);
@@ -366,6 +382,16 @@ int request_irq(unsigned int irq,
 	action->next = NULL;
 	action->dev_id = dev_id;
 
+#ifdef CONFIG_SHARE_ME_HARDER
+	if (irqflags & SA_SHIRQ) {
+		/* It's a shared IRQ -- the driver ought to be prepared for it to happen
+		   immediately, so let's make sure.... 
+		   We do this before actually registering it, to make sure that a 'real'
+		   IRQ doesn't run in parallel with our fake. */
+		handler(irq, dev_id, &shirq_fakeregs);
+	}
+#endif
+
 	retval = setup_irq(irq, action);
 	if (retval)
 		kfree(action);
Signature · 1 line
dwmw2
#1 lore raw
Quoted 5 lines · David Woodhouse

Drivers registering IRQ handlers with SA_SHIRQ really ought to be able to handle an interrupt happening before request_irq() returns. They also ought to be able to handle an interrupt happening during the start of their call to free_irq(). Let's test that hypothesis....

I don't think I like this patch.

sound/oss/i810_audio.c renamed from sound/oss/i810_audio.c~i810_audio-request_irq-fix +8 -10
diff -puN sound/oss/i810_audio.c~i810_audio-request_irq-fix sound/oss/i810_audio.c
@@ -3360,12 +3360,6 @@ static int __devinit i810_probe(struct p
 		goto out_region2;
 	}
 
-	if (request_irq(card->irq, &i810_interrupt, SA_SHIRQ,
-			card_names[pci_id->driver_data], card)) {
-		printk(KERN_ERR "i810_audio: unable to allocate irq %d\n", card->irq);
-		goto out_pio;
-	}
-
 	if (card->use_mmio) {
 		if (request_mem_region(card->ac97base_mmio_phys, 512, "ich_audio MMBAR")) {
 			if ((card->ac97base_mmio = ioremap(card->ac97base_mmio_phys, 512))) { /*@FIXME can ioremap fail? don't know (jsaw) */
@@ -3396,10 +3390,8 @@ static int __devinit i810_probe(struct p
 	}
 
 	/* initialize AC97 codec and register /dev/mixer */
-	if (i810_ac97_init(card) <= 0) {
-		free_irq(card->irq, card);
+	if (i810_ac97_init(card) <= 0)
 		goto out_iospace;
-	}
 	pci_set_drvdata(pci_dev, card);
 
 	if(clocking == 0) {
@@ -3411,7 +3403,6 @@ static int __devinit i810_probe(struct p
 	if ((card->dev_audio = register_sound_dsp(&i810_audio_fops, -1)) < 0) {
 		int i;
 		printk(KERN_ERR "i810_audio: couldn't register DSP device!\n");
-		free_irq(card->irq, card);
 		for (i = 0; i < NR_AC97; i++)
 		if (card->ac97_codec[i] != NULL) {
 			unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
@@ -3420,6 +3411,13 @@ static int __devinit i810_probe(struct p
 		goto out_iospace;
 	}
 
+	if (request_irq(card->irq, &i810_interrupt, SA_SHIRQ,
+			card_names[pci_id->driver_data], card)) {
+		printk(KERN_ERR "i810_audio: unable to allocate irq %d\n", card->irq);
+		goto out_iospace;
+	}
+
+
  	card->initializing = 0;
 	return 0;
 

_

This is going to cause me a ton of grief. How's about you put it in Fedora for a few weeks, get all the drivers debugged first ;)

#2 lore raw
Quoted 2 lines · Andrew Morton

This is going to cause me a ton of grief. How's about you put it in Fedora for a few weeks, get all the drivers debugged first ;)

I'd do that normally, but it's the wrong point in the cycle -- we're getting ready for Fedora Core 5 at the moment; it's not the time to be doing such things. We can apply the patch... but we'd have to turn the config option off :)

What you're seeing is the whole point of the patch, surely? And it _is_ a config option -- people aren't forced to turn it on.

Would it help if we added a printk to make it more obvious what's happening, which gives the naïve user the opportunity to turn off the config option just to get things working again? Somethign along the lines of "Faking irq %d due to CONFIG_DEBUG_SHIRQ. If your machine crashes now, don't blame akpm"?

Out of interest, does your i810 patch fix the problem which was reported in November by Eyal Lebedinsky ("2.6.14.2: repeated oops in i810 init")?

Signature · 1 line
dwmw2
#3 lore raw
Quoted 5 lines · David Woodhouse
Quoted 2 lines · Andrew Morton

This is going to cause me a ton of grief. How's about you put it in Fedora for a few weeks, get all the drivers debugged first ;)

Quoted 7 lines

I'd do that normally, but it's the wrong point in the cycle -- we're getting ready for Fedora Core 5 at the moment; it's not the time to be doing such things. We can apply the patch... but we'd have to turn the config option off :)

What you're seeing is the whole point of the patch, surely? And it _is_ a config option -- people aren't forced to turn it on.

Sure. I was just regretting being the sucker again.

Quoted 5 lines

Would it help if we added a printk to make it more obvious what's happening, which gives the naïve user the opportunity to turn off the config option just to get things working again? Somethign along the lines of "Faking irq %d due to CONFIG_DEBUG_SHIRQ. If your machine crashes now, don't blame akpm"?

Nah, that's all right. I'm skilled at sending maintainers new bug reports to ignore.

Quoted 2 lines

Out of interest, does your i810 patch fix the problem which was reported in November by Eyal Lebedinsky ("2.6.14.2: repeated oops in i810 init")?

Looks like it. I was oopsing at 0x00000030 too, although on x86_64, not x86.

#4 lore raw
In reply to Andrew Morton
Quoted 3 lines · Andrew Morton

This is going to cause me a ton of grief. How's about you put it in Fedora for a few weeks, get all the drivers debugged first ;)

well it's a config option for a reason :)
Also it's something driver writers now can turn on so that THEY can debug their driver as well.... -mm or even mainline is better for that than fedora.

#5 lore raw

PATCH 1/1 reduce sizeof(percpu_data) and removes dependance against NR_CPUS

In reply to Andrew Morton

Hi Andrew

Current sizeof(percpu_data) is NR_CPUS*sizeof(void *)

This trivial patch makes percpu_data real size depends on highest_possible_processor_id() instead of NR_CPUS

percpu_data allocations are not performance critical, we can spend few CPU cycles and save some ram.

This patch should replace remove-unused-blkp-field-in-percpu_data.patch in mm tree

Thank you

include/linux/percpu.h +1 -2
@@ -18,8 +18,7 @@
 #ifdef CONFIG_SMP
 
 struct percpu_data {
-	void *ptrs[NR_CPUS];
-	void *blkp;
+	void *ptrs[1]; /* real size depends on highest_possible_processor_id() */
 };
 
 /* 
mm/slab.c +2 -1
@@ -2949,7 +2949,8 @@
 void *__alloc_percpu(size_t size, size_t align)
 {
 	int i;
-	struct percpu_data *pdata = kmalloc(sizeof (*pdata), GFP_KERNEL);
+	size_t pdsize = highest_possible_processor_id() * sizeof(void *);
+	struct percpu_data *pdata = kmalloc(pdsize, GFP_KERNEL);
 
 	if (!pdata)
 		return NULL;
#6 lore raw

Re: [PATCH] reduce sizeof(percpu_data) and removes dependance against NR_CPUS

Quoted 8 lines · Eric Dumazet

Current sizeof(percpu_data) is NR_CPUS*sizeof(void *)

This trivial patch makes percpu_data real size depends on highest_possible_processor_id() instead of NR_CPUS

percpu_data allocations are not performance critical, we can spend few CPU cycles and save some ram.

hm, highest_possible_processor_id() isn't very efficient. And it's quite dopey that it's a macro. We should turn it into a real function which caches its return result and goes BUG if it's called before cpu_possible_map is initialised.

#7 lore raw

Re: [PATCH] reduce sizeof(percpu_data) and removes dependance against NR_CPUS

Quoted 6 lines · Andrew Morton
Quoted 5 lines · Eric Dumazet

Current sizeof(percpu_data) is NR_CPUS*sizeof(void *)

This trivial patch makes percpu_data real size depends on highest_possible_processor_id() instead of NR_CPUS

Quoted 7 lines
Quoted 2 lines

percpu_data allocations are not performance critical, we can spend few CPU cycles and save some ram.

hm, highest_possible_processor_id() isn't very efficient. And it's quite dopey that it's a macro. We should turn it into a real function which caches its return result and goes BUG if it's called before cpu_possible_map is initialised.

I agree, I will see if I can do that without poking in every arch :(

More over, my patch has an error on pdsize computation, it should be :

size_t pdsize = (highest_possible_processor_id() + 1) * sizeof(void *);

Eric

#8 lore raw

Re: [PATCH] reduce sizeof(percpu_data) and removes dependance against NR_CPUS

In reply to Eric Dumazet
include/linux/percpu.h +1 -2
@@ -18,8 +18,7 @@
 #ifdef CONFIG_SMP
 
 struct percpu_data {
-	void *ptrs[NR_CPUS];
-	void *blkp;
+	void *ptrs[1]; /* real size depends on highest_possible_processor_id() */
 };
 
 /* 

I think we can use *ptrs[0] here.

Jan Engelhardt

Signature · 2 lines
| Alphagate Systems, http://alphagate.hopto.org/
| jengelh's site, http://jengelh.hopto.org/
#9 lore raw

Re: [PATCH] reduce sizeof(percpu_data) and removes dependance against NR_CPUS

Quoted 17 lines · Jan Engelhardt
include/linux/percpu.h +1 -2
@@ -18,8 +18,7 @@
 #ifdef CONFIG_SMP
 
 struct percpu_data {
-	void *ptrs[NR_CPUS];
-	void *blkp;
+	void *ptrs[1]; /* real size depends on highest_possible_processor_id() */
 };
 
 /* 
Quoted 2 lines

I think we can use *ptrs[0] here.

We can. In fact with the gcc-2.95 abandonment I think we can use ptrs[].

But it doesn't matter.

#10 lore raw

Re: [PATCH] reduce sizeof(percpu_data) and removes dependance against NR_CPUS

In reply to Jan Engelhardt
Quoted 15 lines · Jan Engelhardt
include/linux/percpu.h +1 -2
@@ -18,8 +18,7 @@
 #ifdef CONFIG_SMP
 
 struct percpu_data {
-	void *ptrs[NR_CPUS];
-	void *blkp;
+	void *ptrs[1]; /* real size depends on highest_possible_processor_id() */
 };
 
 /* 
Quoted 2 lines

I think we can use *ptrs[0] here.

Or even dont change percpu.h, or else some guys will assume percpu_data cost nothing...

Eric