Skip to contentSkip to conversation

PMU and timer interrupts

DISCUSSION Stephane Eranian 6 participants 22 messages Feb 9, 2006 – Feb 13, 2006

lore
Share & tools
lore
#0 lore raw

Hello,

It was recently pointed out to me that the PMU interrupt vector is set to 0xee just below the timer interrupt at 0xef. As such, the timer interrupt has higher priority than the PMU interrupt. This would make sense except that a side effect is that it is not possible to collect samples from within the timer interrupt, i.e. we have a blind spot. Another side effect is that events happening during the timer handler, may be falsely attributed to the point where we write the EOI register.

I looked at the timer_interrupt() path, and I did not see anything special that would prevent us from swapping the interrupt vectors thereby removing the blind spot we have.

Does anybody see a problem with this?

Signature · 1 line
-Stephane
#1 lore raw
Quoted 10 lines · Stephane Eranian

Hello,

It was recently pointed out to me that the PMU interrupt vector is set to 0xee just below the timer interrupt at 0xef. As such, the timer interrupt has higher priority than the PMU interrupt. This would make sense except that a side effect is that it is not possible to collect samples from within the timer interrupt, i.e. we have a blind spot. Another side effect is that events happening during the timer handler, may be falsely attributed to the point where we write the EOI register.

If your intent is to allow a PMU interrupt to interrupt the timer interrupt code, don't you need to put the PMU interrupt into a higher priority class than the timer interrupt? Interrupt vectors are grouped into 16 interrupt classes. An in-service interrupt masks all other interrupts in the same class. (See the TPR register).

For example, PMU = 0xe0 & timer = 0xdf?
(This obviously ripples thu additional interrupt numbers....)

Quoted 12 lines

I looked at the timer_interrupt() path, and I did not see anything special that would prevent us from swapping the interrupt vectors thereby removing the blind spot we have.

Does anybody see a problem with this?

(quoted diff) +0 -2
-Stephane
-

To unsubscribe from this list: send the line "unsubscribe linux-ia64" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 4 lines
Thanks

Jack Steiner ([email protected])          651-683-5302
Principal Engineer                      SGI - Silicon Graphics, Inc.
#2 lore raw
In reply to Stephane Eranian
Quoted 9 lines

It was recently pointed out to me that the PMU interrupt vector is set to 0xee just below the timer interrupt at 0xef. As such, the timer interrupt has higher priority than the PMU interrupt. This would make sense except that a side effect is that it is not possible to collect samples from within the timer interrupt, i.e. we have a blind spot. Another side effect is that events happening during the timer handler, may be falsely attributed to the point where we write the EOI register.

Quoted 5 lines

I looked at the timer_interrupt() path, and I did not see anything special that would prevent us from swapping the interrupt vectors thereby removing the blind spot we have.

Does anybody see a problem with this?

How much would this help? Both 0xEF and 0xEE are part of the same priority class (see table 5-8 on p. 2-112 of SDM).

-Tony

#3 lore raw
In reply to Stephane Eranian

Tony, Jack,

Quoted 9 lines · Tony
Quoted 9 lines

It was recently pointed out to me that the PMU interrupt vector is set to 0xee just below the timer interrupt at 0xef. As such, the timer interrupt has higher priority than the PMU interrupt. This would make sense except that a side effect is that it is not possible to collect samples from within the timer interrupt, i.e. we have a blind spot. Another side effect is that events happening during the timer handler, may be falsely attributed to the point where we write the EOI register.

Quoted 9 lines
Quoted 5 lines

I looked at the timer_interrupt() path, and I did not see anything special that would prevent us from swapping the interrupt vectors thereby removing the blind spot we have.

Does anybody see a problem with this?

How much would this help? Both 0xEF and 0xEE are part of the same priority class (see table 5-8 on p. 2-112 of SDM).

Correct me if I am wrong, but the class masking happens only with TPR masking. So if we had timer=0xee, PMU=0xef and if the kernel does not raise the TPR class masking to the priority class of 0xef/0xee, then we could still get a PMU interrupt while executing the timer handler.

Signature · 1 line
-Stephane
#4 lore raw
In reply to Stephane Eranian
Quoted 18 lines · Stephane Eranian

Tony, Jack,

Quoted 15 lines · Tony
Quoted 14 lines

It was recently pointed out to me that the PMU interrupt vector is set to 0xee just below the timer interrupt at 0xef. As such, the timer interrupt has higher priority than the PMU interrupt. This would make sense except that a side effect is that it is not possible to collect samples from within the timer interrupt, i.e. we have a blind spot. Another side effect is that events happening during the timer handler, may be falsely attributed to the point where we write the EOI register.

I looked at the timer_interrupt() path, and I did not see anything special that would prevent us from swapping the interrupt vectors thereby removing the blind spot we have.

Does anybody see a problem with this?

Quoted 8 lines
Quoted 3 lines

How much would this help? Both 0xEF and 0xEE are part of the same priority class (see table 5-8 on p. 2-112 of SDM).

Correct me if I am wrong, but the class masking happens only with TPR masking. So if we had timer=0xee, PMU=0xef and if the kernel does not raise the TPR class masking to the priority class of 0xef/0xee, then we could still get a PMU interrupt while executing the timer handler.

What you say is true. However, the kernel does use the TPR to enforce priority classes:

	void
	ia64_handle_irq (ia64_vector vector, struct pt_regs *regs)
	{
		...
		saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
		while (vector != IA64_SPURIOUS_INT_VECTOR) {
			if (!IS_RESCHEDULE(vector)) {
				ia64_setreg(_IA64_REG_CR_TPR, vector);
				__do_IRQ(local_vector_to_irq(vector), regs);
		....
	}

Use of priority classes prevents excessive recursion. Without it, as a worse case,
- a priority 16 interrupt could be interrupted by a priority 17
- which is interrupted by an 18
- which is interrupted by an 19
- which is interrupted by an 20
- etc. and the kernel stack goes BOOM :-)

Priority classes limits the recursion to 15 levels at most.

#5 lore raw
In reply to Stephane Eranian

Jack,

Quoted 31 lines · Jack Steiner
Quoted 18 lines · Stephane Eranian

Tony, Jack,

Quoted 15 lines · Tony
Quoted 14 lines

It was recently pointed out to me that the PMU interrupt vector is set to 0xee just below the timer interrupt at 0xef. As such, the timer interrupt has higher priority than the PMU interrupt. This would make sense except that a side effect is that it is not possible to collect samples from within the timer interrupt, i.e. we have a blind spot. Another side effect is that events happening during the timer handler, may be falsely attributed to the point where we write the EOI register.

I looked at the timer_interrupt() path, and I did not see anything special that would prevent us from swapping the interrupt vectors thereby removing the blind spot we have.

Does anybody see a problem with this?

Quoted 8 lines
Quoted 3 lines

How much would this help? Both 0xEF and 0xEE are part of the same priority class (see table 5-8 on p. 2-112 of SDM).

Correct me if I am wrong, but the class masking happens only with TPR masking. So if we had timer=0xee, PMU=0xef and if the kernel does not raise the TPR class masking to the priority class of 0xef/0xee, then we could still get a PMU interrupt while executing the timer handler.

What you say is true. However, the kernel does use the TPR to enforce priority classes:

Quoted 9 lines
	void
	ia64_handle_irq (ia64_vector vector, struct pt_regs *regs)
	{
		...
		saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
		while (vector != IA64_SPURIOUS_INT_VECTOR) {
			if (!IS_RESCHEDULE(vector)) {
				ia64_setreg(_IA64_REG_CR_TPR, vector);
				__do_IRQ(local_vector_to_irq(vector), regs);

Ok, now I understand better where you were coming from. So what would be the problem in push PMU interrupt in the next class up?

#6 lore raw
In reply to Stephane Eranian

Jack, Tony,

Suposing I move up the PERFMON_VECTOR to 0xf1, it will be in the top priority class (15) with the following vectors:

Quoted 3 lines
	#define IA64_MCA_WAKEUP_VECTOR          0xf0    /* MCA wakeup (must be >MCA_RENDEZ_VECTOR) */
	#define IA64_IPI_RESCHEDULE             0xfd    /* SMP reschedule */
	#define IA64_IPI_VECTOR                 0xfe    /* inter-processor interrupt vector */

The impact will be that, while servicing a PMU interrupt, I will not be able to get:

	-  an MCA interrupt
	-  a reschedule IPI
	-  a generic IPI

Today, the PMU interrupt handler runs with interrupts disabled, as such the situation would not be different. In fact, we could skip masking/unmasking because we would be in the top class + TPR masking done by the kernel on interrupt.

Anybody, has a problem with this?

Signature · 1 line
-Stephane
#7 lore raw
In reply to Stephane Eranian
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Stephane" = Stephane Eranian <[email protected]> writes:

Stephane> Jack, Tony, Suposing I move up the PERFMON_VECTOR to 0xf1, Stephane> it will be in the top priority class (15) with the following Stephane> vectors:

Hi Stephane,

I admit I don't know much about how this works, but would it be possible to move IA64_MCA_RENDEZ_VECTOR and IA64_TIMER_VECTOR to the 0xdX group? I looked quickly at a 64-way box internally and it only had stuff assigned up to irq 70 (70 decimal that is) even with quit a lot of storage attached.

Cheers,
Jes

#8 lore raw
In reply to Stephane Eranian

Stephane Eranian wrote on Friday, February 10, 2006 5:35 AM

Quoted 9 lines

Suposing I move up the PERFMON_VECTOR to 0xf1, it will be in the top priority class (15) with the following vectors:

Today, the PMU interrupt handler runs with interrupts disabled, as such the situation would not be different. In fact, we could skip masking/unmasking because we would be in the top class + TPR masking done by the kernel on interrupt.

Anybody, has a problem with this?

If your goal is to be able to sample timer interrupt with PMU, you won't get it even after you move PMU vector one class up. Because just like PMU vector, timer interrupt handler is run with interrupt off all the through.

- Ken

#9 lore raw
In reply to Stephane Eranian

Ken,

Quoted 9 lines · Kenneth W

Stephane Eranian wrote on Friday, February 10, 2006 5:35 AM

Quoted 8 lines

Suposing I move up the PERFMON_VECTOR to 0xf1, it will be in the top priority class (15) with the following vectors:

Today, the PMU interrupt handler runs with interrupts disabled, as such the situation would not be different. In fact, we could skip masking/unmasking because we would be in the top class + TPR masking done by the kernel on interrupt.

Quoted 7 lines
Quoted 1 line

Anybody, has a problem with this?

If your goal is to be able to sample timer interrupt with PMU, you won't get it even after you move PMU vector one class up. Because just like PMU vector, timer interrupt handler is run with interrupt off all the through.

Are you talking about timer_interrupt()? Where is the masking happening exactly?

Signature · 1 line
-Stephane
#10 lore raw
In reply to Stephane Eranian

Stephane Eranian wrote on Friday, February 10, 2006 1:23 PM

Quoted 6 lines
Quoted 5 lines

If your goal is to be able to sample timer interrupt with PMU, you won't get it even after you move PMU vector one class up. Because just like PMU vector, timer interrupt handler is run with interrupt off all the through.

Are you talking about timer_interrupt()?

Yes.

Quoted 1 line

Where is the masking happening exactly?

By hardware, upon an interrupt, both psr.i and psr.ic bit are off when the control goes into the ivt:interrupt(). In there, pt_regs is saved and only psr.ic bit is turned on. It eventually calls down to handle_IRQ_event(). Since SA_INTERRUPT flag is on for timer interrupt, kernel doesn't enable irq when invoking the handler.

In fact, most of the interrupts having SA_INTERRUPT flag set. So the blind spots you worried about for PMU is a lot wider. For example, on my system, serial, e1000, mpt fusion, qla2300 interrupts all have that flag set. Looks like kernel executes these handlers with irq disabled all the way through.

- Ken

#11 lore raw
In reply to Stephane Eranian

Ken,

Quoted 9 lines · Kenneth W
Quoted 2 lines

Where is the masking happening exactly?

By hardware, upon an interrupt, both psr.i and psr.ic bit are off when the control goes into the ivt:interrupt(). In there, pt_regs is saved and only psr.ic bit is turned on. It eventually calls down to handle_IRQ_event(). Since SA_INTERRUPT flag is on for timer interrupt, kernel doesn't enable irq when invoking the handler.

Quoted 6 lines

In fact, most of the interrupts having SA_INTERRUPT flag set. So the blind spots you worried about for PMU is a lot wider. For example, on my system, serial, e1000, mpt fusion, qla2300 interrupts all have that flag set. Looks like kernel executes these handlers with irq disabled all the way through.

Yes, it is coded that way. The definition of SA_INTERRUPT is far from clear because it is obsolete when used by applications for signal handlers. Yet the flag is overloaded for irq handlers, apparently where it takes a completely different meaning.

Does it make sense to have the handlers run while interrupts mask during their entire execution?

I need to correct the PMU interrupt handler because it is using this flag while also explcitely masking interrupts again.

You are right that this creates very large blind spots when monitoring, at least with the regular interrupt-based approach.

By construction, I would not expect those in the top class (15) to have this flag set.

Signature · 1 line
-Stephane
#12 lore raw
In reply to Stephane Eranian
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Ken" = Chen, Kenneth W <[email protected]> writes:

Ken> By hardware, upon an interrupt, both psr.i and psr.ic bit are off Ken> when the control goes into the ivt:interrupt(). In there, Ken> pt_regs is saved and only psr.ic bit is turned on. It eventually Ken> calls down to handle_IRQ_event(). Since SA_INTERRUPT flag is on Ken> for timer interrupt, kernel doesn't enable irq when invoking the Ken> handler.

Ken> In fact, most of the interrupts having SA_INTERRUPT flag set. So Ken> the blind spots you worried about for PMU is a lot wider. For Ken> example, on my system, serial, e1000, mpt fusion, qla2300 Ken> interrupts all have that flag set. Looks like kernel executes Ken> these handlers with irq disabled all the way through.

Ken,

I wonder if that isn't mostly bugs on the driver authors side? SA_INTERRUPT was really introduced to handle UART interrupts, whereas I think all the other drivers you mention ought to be able to handle it correctly.

Cheers,
Jes

#13 lore raw
In reply to Stephane Eranian

Jes,

Quoted 15 lines · Jes Sorensen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Ken" = Chen, Kenneth W <[email protected]> writes:

Ken> By hardware, upon an interrupt, both psr.i and psr.ic bit are off Ken> when the control goes into the ivt:interrupt(). In there, Ken> pt_regs is saved and only psr.ic bit is turned on. It eventually Ken> calls down to handle_IRQ_event(). Since SA_INTERRUPT flag is on Ken> for timer interrupt, kernel doesn't enable irq when invoking the Ken> handler.

Ken> In fact, most of the interrupts having SA_INTERRUPT flag set. So Ken> the blind spots you worried about for PMU is a lot wider. For Ken> example, on my system, serial, e1000, mpt fusion, qla2300 Ken> interrupts all have that flag set. Looks like kernel executes Ken> these handlers with irq disabled all the way through.

Quoted 7 lines

Ken,

I wonder if that isn't mostly bugs on the driver authors side? SA_INTERRUPT was really introduced to handle UART interrupts, whereas I think all the other drivers you mention ought to be able to handle it correctly.

Who would know for sure wether interrupt masking is really needed on those drivers?

Signature · 1 line
-Stephane
#14 lore raw
In reply to Stephane Eranian
Quoted 8 lines · Stephane Eranian

Jes,

Quoted 4 lines

I wonder if that isn't mostly bugs on the driver authors side? SA_INTERRUPT was really introduced to handle UART interrupts, whereas I think all the other drivers you mention ought to be able to handle it correctly.

Who would know for sure wether interrupt masking is really needed on those drivers?

Hi Stephane,

I would start with the driver maintainers and maybe CC the subsystem list, like linux-scsi.

I know the qla2xxx driver is very similar to the qla1280 driver which I maintain, and that no longer uses SA_INTERRUPT. I am guessing the qla2xxx should be able to do so as well, but check with [email protected]

Cheers,
Jes

#15 lore raw
In reply to Stephane Eranian

Ken,

Quoted 6 lines · Kenneth W

In fact, most of the interrupts having SA_INTERRUPT flag set. So the blind spots you worried about for PMU is a lot wider. For example, on my system, serial, e1000, mpt fusion, qla2300 interrupts all have that flag set. Looks like kernel executes these handlers with irq disabled all the way through.

Looking at my 2.6.16-rc1, it appears that neither e1000 nor mpt fusion are using SA_INTERRUPT anymore. The qla2xxx still does, though.

Signature · 1 line
-Stephane
#16 lore raw
In reply to Stephane Eranian
Quoted 8 lines · Kenneth W

Stephane Eranian wrote on Monday, February 13, 2006 12:02 PM

Quoted 7 lines · Kenneth W
Quoted 6 lines

In fact, most of the interrupts having SA_INTERRUPT flag set. So the blind spots you worried about for PMU is a lot wider. For example, on my system, serial, e1000, mpt fusion, qla2300 interrupts all have that flag set. Looks like kernel executes these handlers with irq disabled all the way through.

Quoted 4 lines
Quoted 2 lines

Looking at my 2.6.16-rc1, it appears that neither e1000 nor mpt fusion are using SA_INTERRUPT anymore. The qla2xxx still does, though.

Yeah, I think you are correct.

Jes seems to believe than this is more historical than anything for qla2xxx. Now what about the timer interrupt, why does it really need SA_INTERRUPT especially given that it is so high priority and with the TPR mechanism. IT seems to be a protection against MCA, IPI, IPI_RESCHEDULE based on the current layout.

Signature · 1 line
-Stephane
#17 lore raw
In reply to Stephane Eranian

Stephane Eranian wrote on Monday, February 13, 2006 12:02 PM

Quoted 9 lines · Kenneth W
Quoted 6 lines

In fact, most of the interrupts having SA_INTERRUPT flag set. So the blind spots you worried about for PMU is a lot wider. For example, on my system, serial, e1000, mpt fusion, qla2300 interrupts all have that flag set. Looks like kernel executes these handlers with irq disabled all the way through.

Looking at my 2.6.16-rc1, it appears that neither e1000 nor mpt fusion are using SA_INTERRUPT anymore. The qla2xxx still does, though.

Yeah, I think you are correct.

- Ken

#18 lore raw
In reply to Stephane Eranian

Stephane Eranian wrote on Monday, February 13, 2006 12:13 PM

Quoted 4 lines

Jes seems to believe than this is more historical than anything for qla2xxx. Now what about the timer interrupt, why does it really need SA_INTERRUPT especially given that it is so high priority and with the TPR mechanism. IT seems to be a protection against MCA, IPI, IPI_RESCHEDULE based on the current layout.

scheduler_tick function expects irq off because it calls load_balance and will muck around with runqueue list. Won't that race with resched IPI if irq is not masked?

- Ken

#19 lore raw
In reply to Stephane Eranian
Quoted 4 lines · Stephane Eranian (on Mon, 13 Feb 2006 12:12:39 -0800) wrote:

Jes seems to believe than this is more historical than anything for qla2xxx. Now what about the timer interrupt, why does it really need SA_INTERRUPT especially given that it is so high priority and with the TPR mechanism. IT seems to be a protection against MCA, IPI, IPI_RESCHEDULE based on the current layout.

Nit pick, the time interrupt will hold off any MCA slave rendezvous, but not the MCA monarch event. The latter is not masked by the kernel, except where it is already processing an MCA monarch or INIT monarch/slave event.

#20 lore raw
In reply to Stephane Eranian

Chen, Kenneth W wrote on Monday, February 13, 2006 12:32 PM

Quoted 9 lines

Stephane Eranian wrote on Monday, February 13, 2006 12:13 PM

Quoted 4 lines

Jes seems to believe than this is more historical than anything for qla2xxx. Now what about the timer interrupt, why does it really need SA_INTERRUPT especially given that it is so high priority and with the TPR mechanism. IT seems to be a protection against MCA, IPI, IPI_RESCHEDULE based on the current layout.

scheduler_tick function expects irq off because it calls load_balance and will muck around with runqueue list. Won't that race with resched IPI if irq is not masked?

NO! Ken needs more coffee Monday morning ....

I forgot that we don't check TIF_ flag when we are still on kernel stack. So resched IPI should be safe w.r.t timer interrupt because schedule is called after timer_interrupt finishes.

- Ken

#21 lore raw
In reply to Stephane Eranian

Ken,

Quoted 11 lines · Kenneth W

Chen, Kenneth W wrote on Monday, February 13, 2006 12:32 PM

Quoted 9 lines

Stephane Eranian wrote on Monday, February 13, 2006 12:13 PM

Quoted 4 lines

Jes seems to believe than this is more historical than anything for qla2xxx. Now what about the timer interrupt, why does it really need SA_INTERRUPT especially given that it is so high priority and with the TPR mechanism. IT seems to be a protection against MCA, IPI, IPI_RESCHEDULE based on the current layout.

scheduler_tick function expects irq off because it calls load_balance and will muck around with runqueue list. Won't that race with resched IPI if irq is not masked?

Quoted 6 lines

NO! Ken needs more coffee Monday morning ....

I forgot that we don't check TIF_ flag when we are still on kernel stack. So resched IPI should be safe w.r.t timer interrupt because schedule is called after timer_interrupt finishes.

Thanks for checking on this. That leaves us with regular IPI which is can be quite vast and MCA.

Signature · 1 line
-Stephane