Skip to contentSkip to conversation

User Level Interrupts

PATCH In review Michael Raymond 2 participants 4 messages Mar 23, 2005 – Mar 24, 2005 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 User Level Interrupts

Allow fast (1+us) user notification of device interrupts. This allows
more powerful user I/O applications to be written. The process of porting to other architectures is straight forward and fully documented. More information can be found at http://oss.sgi.com/projects/uli/.

Signature · 2 lines
Michael A. Raymond              Office: (651) 683-3434
Core OS Group                   Real-Time System Software
arch/ia64/kernel/asm-offsets.c +16 -0
diff -urN linux-2.6.11/arch/ia64/kernel/asm-offsets.c linux-2.6.11-uli/arch/ia64/kernel/asm-offsets.c
@@ -7,6 +7,7 @@
 #include <linux/config.h>
 
 #include <linux/sched.h>
+#include <linux/uli.h>
 
 #include <asm-ia64/processor.h>
 #include <asm-ia64/ptrace.h>
@@ -236,4 +237,19 @@
 	DEFINE(IA64_TIME_SOURCE_MMIO64, TIME_SOURCE_MMIO64);
 	DEFINE(IA64_TIME_SOURCE_MMIO32, TIME_SOURCE_MMIO32);
 	DEFINE(IA64_TIMESPEC_TV_NSEC_OFFSET, offsetof (struct timespec, tv_nsec));
+
+#ifdef CONFIG_ULI
+	BLANK();
+	DEFINE(ULI_GP_OFFSET, offsetof(struct uli, uli_gp));
+	DEFINE(ULI_SP_OFFSET, offsetof(struct uli, uli_sp));
+	DEFINE(ULI_BSPSTORE_OFFSET, offsetof(struct uli, uli_arch0));
+	DEFINE(ULI_TP_OFFSET, offsetof(struct uli, uli_arch1));
+	DEFINE(ULI_PC_OFFSET, offsetof(struct uli, uli_pc));
+	DEFINE(ULI_ARG_OFFSET, offsetof(struct uli, uli_funcarg));
+	DEFINE(ULI_TSTAMP_OFFSET, offsetof(struct uli, uli_tstamp));
+	DEFINE(ULI_DOUBLE_OFFSET, offsetof(struct uli, uli_double));
+	DEFINE(ULI_INTR_SP_OFFSET, offsetof(struct uli, uli_intr_sp));
+	DEFINE(ULI_INTR_BSPSTORE_OFFSET, offsetof(struct uli, uli_intr_arch0));
+	DEFINE(ULI_SAVED_EPC_OFFSET, offsetof(struct uli, uli_saved_epc));
+#endif /* CONFIG_ULI */
 }
arch/ia64/kernel/entry.S +51 -2

90 lines not on this page · raw message

arch/ia64/kernel/fsys.S +17 -0
diff -urN linux-2.6.11/arch/ia64/kernel/fsys.S linux-2.6.11-uli/arch/ia64/kernel/fsys.S
@@ -579,6 +579,9 @@
 	mov psr.l=r9			// slam the door (17 cyc to srlz.i)
 	or r29=r8,r29			// construct cr.ipsr value to save
 	addl r22=IA64_RBS_OFFSET,r2	// compute base of RBS
+#ifdef CONFIG_ULI
+	addl r17 = THIS_CPU(uli_cur),r0 // &uli_cur[this cpu]
+#endif /* CONFIG_ULI */
 	;;
 	// GAS reports a spurious RAW hazard on the read of ar.rnat because it thinks
 	// we may be reading ar.itc after writing to psr.l.  Avoid that message with
@@ -587,6 +590,9 @@
 	mov.m r24=ar.rnat		// read ar.rnat (5 cyc lat)
 	lfetch.fault.excl.nt1 [r22]
 	adds r16=IA64_TASK_THREAD_ON_USTACK_OFFSET,r2
+#ifdef CONFIG_ULI
+	ld8 r3 = [r17] // Get the address of the current ULI
+#endif /* CONFIG_ULI */
 
 	// ensure previous insn group is issued before we stall for srlz.i:
 	;;
@@ -595,6 +601,14 @@
 	////////// from this point on, execution is not interruptible anymore
 	/////////////////////////////////////////////////////////////////////////////
 	addl r1=IA64_STK_OFFSET-IA64_PT_REGS_SIZE,r2	// compute base of memory stack
+#ifdef CONFIG_ULI
+	cmp.eq p7,p20=r0,r3      // ULI?
+	add r17 = ULI_INTR_SP_OFFSET, r3 // Former stack pointer
+	add r30 = ULI_INTR_BSPSTORE_OFFSET, r3   // Former BSP
+	;;
+(p20)	ld8 r1 = [r17] // sp
+(p20)	ld8 r22 = [r30] // bspstore
+#endif /* CONFIG_ULI */
 	cmp.ne pKStk,pUStk=r0,r0	// set pKStk <- 0, pUStk <- 1
 	;;
 	st1 [r16]=r0			// clear current->thread.on_ustack flag
@@ -613,6 +627,9 @@
 	mov rp=r2				// set the real return addr
 	tbit.z p8,p0=r3,TIF_SYSCALL_TRACE
 	;;
+#ifdef CONFIG_ULI
+(p20)	br.call.spnt.few b6=uli_syscall
+#endif /* CONFIG_ULI */
 (p10)	br.cond.spnt.many ia64_ret_from_syscall	// p10==true means out registers are more than 8
 (p8)	br.call.sptk.many b6=b6		// ignore this return addr
 	br.cond.sptk ia64_trace_syscall
arch/ia64/kernel/ivt.S +18 -0
diff -urN linux-2.6.11/arch/ia64/kernel/ivt.S linux-2.6.11-uli/arch/ia64/kernel/ivt.S
@@ -704,7 +704,21 @@
 	cmp.eq p0,p7=r18,r17			// is this a system call? (p7 <- false, if so)
 (p7)	br.cond.spnt non_syscall
 	;;
+#ifdef CONFIG_ULI
+       /*
+        * If we're in a ULI doing a system call, we need to start on the stack
+        * where we switched out to handle the ULI.
+        */
+	addl r17 = THIS_CPU(uli_cur),r0  // &uli_cur[this cpu]
+	;;
+	ld8 r22 = [r17]                  // r22 = current ULI, MINSTATE expects r22
+	;;
+	cmp.eq pUStk,pLvSys=r0,r22          // ULI?  MINSTATE expects a valid pLvSys
+	;;
+(pUStk) ld1 r17=[r16]           // load current->thread.on_ustack flag
+#else /* CONFIG_ULI */
 	ld1 r17=[r16]				// load current->thread.on_ustack flag
+#endif /* CONFIG_ULI */
 	st1 [r16]=r0				// clear current->thread.on_ustack flag
 	add r1=-IA64_TASK_THREAD_ON_USTACK_OFFSET,r16	// set r1 for MINSTATE_START_SAVE_MIN_VIRT
 	;;
@@ -721,6 +735,7 @@
 (p6)	adds r28=16,r28				// switch cr.iip to next bundle cr.ipsr.ei wrapped
 (p7)	adds r8=1,r8				// increment ei to next slot
 	;;
+	/* If we're in a ULI then r17 will be non-zero and we'll get pUStk */
 	cmp.eq pKStk,pUStk=r0,r17		// are we in kernel mode already?
 	dep r29=r8,r29,41,2			// insert new ei into cr.ipsr
 	;;
@@ -760,6 +775,9 @@
 	cmp.eq p8,p0=r2,r0
 	mov b6=r20
 	;;
+#ifdef CONFIG_ULI
+(pLvSys) br.call.spnt.few b6=uli_syscall
+#endif /* CONFIG_ULI */
 (p8)	br.call.sptk.many b6=b6			// ignore this return addr
 	br.cond.sptk ia64_trace_syscall
 	// NOT REACHED
arch/ia64/kernel/Makefile +1 -0
diff -urN linux-2.6.11/arch/ia64/kernel/Makefile linux-2.6.11-uli/arch/ia64/kernel/Makefile
@@ -21,6 +21,7 @@
 obj-$(CONFIG_IA64_CYCLONE)	+= cyclone.o
 obj-$(CONFIG_IA64_MCA_RECOVERY)	+= mca_recovery.o
 mca_recovery-y			+= mca_drv.o mca_drv_asm.o
+obj-$(CONFIG_ULI)		+= uli_asm.o
 
 # The gate DSO image is built using a special linker script.
 targets += gate.so gate-syms.o
arch/ia64/kernel/minstate.h +71 -1

112 lines not on this page · raw message

arch/ia64/kernel/traps.c +10 -0
diff -urN linux-2.6.11/arch/ia64/kernel/traps.c linux-2.6.11-uli/arch/ia64/kernel/traps.c
@@ -15,6 +15,7 @@
 #include <linux/vt_kern.h>		/* For unblank_screen() */
 #include <linux/module.h>       /* for EXPORT_SYMBOL */
 #include <linux/hardirq.h>
+#include <linux/uli.h>
 
 #include <asm/fpswa.h>
 #include <asm/ia32.h>
@@ -181,6 +182,10 @@
 			sig = SIGTRAP; code = TRAP_BRKPT;
 		}
 	}
+
+	/* If a ULI caused this, abort it */
+	uli_trap(sig, regs);
+
 	siginfo.si_signo = sig;
 	siginfo.si_errno = 0;
 	siginfo.si_code = code;
@@ -375,6 +380,8 @@
 			return rv;
 	}
 #endif
+	/* If a ULI caused this abort it */
+	uli_trap(SIGILL, &regs);
 
 	sprintf(buf, "IA-64 Illegal operation fault");
 	die_if_kernel(buf, &regs, 0);
@@ -408,6 +415,9 @@
 		"Unknown fault 13", "Unknown fault 14", "Unknown fault 15"
 	};
 
+	/* If a ULI caused this abort it */
+	uli_trap(SIGILL, &regs);
+
 	if ((isr & IA64_ISR_NA) && ((isr & IA64_ISR_CODE_MASK) == IA64_ISR_CODE_LFETCH)) {
 		/*
 		 * This fault was due to lfetch.fault, set "ed" bit in the psr to cancel
arch/ia64/kernel/uli_asm.S +244 -0

244 lines not on this page · raw message

arch/ia64/mm/fault.c +4 -0
diff -urN linux-2.6.11/arch/ia64/mm/fault.c linux-2.6.11-uli/arch/ia64/mm/fault.c
@@ -9,6 +9,7 @@
 #include <linux/mm.h>
 #include <linux/smp_lock.h>
 #include <linux/interrupt.h>
+#include <linux/uli.h>
 
 #include <asm/pgtable.h>
 #include <asm/processor.h>
@@ -84,6 +85,9 @@
 	struct siginfo si;
 	unsigned long mask;
 
+	/* If a ULI caused this abort it */
+	uli_trap(SIGSEGV, regs);
+
 	/*
 	 * If we're in an interrupt or have no user context, we must not take the fault..
 	 */
drivers/base/Kconfig +10 -0
diff -urN linux-2.6.11/drivers/base/Kconfig linux-2.6.11-uli/drivers/base/Kconfig
@@ -37,4 +37,14 @@
 
 	  If you are unsure about this, say N here.
 
+config ULI
+	bool "User Level Interrupt Support"
+	depends on IA64 && EXPERIMENTAL
+	default n
+	help
+	  This enables hardware interrupts to be handled by software in
+	  user space.  This gives user processes more control over hardware
+	  and can enable driver development with reduced risk to system
+	  stability.
+
 endmenu
drivers/base/Makefile +1 -0
diff -urN linux-2.6.11/drivers/base/Makefile linux-2.6.11-uli/drivers/base/Makefile
@@ -7,6 +7,7 @@
 obj-y			+= power/
 obj-$(CONFIG_FW_LOADER)	+= firmware_class.o
 obj-$(CONFIG_NUMA)	+= node.o
+obj-$(CONFIG_ULI)	+= uli.o
 
 ifeq ($(CONFIG_DEBUG_DRIVER),y)
 EXTRA_CFLAGS += -DDEBUG
drivers/base/uli.c +687 -0

687 lines not on this page · raw message

include/asm-ia64/uli_plat.h +92 -0

92 lines not on this page · raw message

include/linux/uli.h +167 -0

167 lines not on this page · raw message

#1 lore raw

Hi Michael

have you thought about how this infrastructure would play well with existing CPU hotplug code for ia64?

Once you return to user mode via the iret, is it possible that user mode thread could get switched due to a pending cpu quiese attempt to remove a cpu? (Current cpu removal code would bring the entire system to knees by scheduling a high priority thread and looping with intr disabled, until the target cpu is removed)

the cpu removal code would also attempt to migrate user process to another cpu, retarget interrupts to another existing cpu etc. I havent tested the hotplug code on sgi boxes so far. (only tested on some hp boxes by Alex Williamson and on tiger4 boxes so far)

Cheers,
ashok

Quoted 9 lines · Michael Raymond

Allow fast (1+us) user notification of device interrupts. This
allows
more powerful user I/O applications to be written. The process of porting
to other architectures is straight forward and fully documented. More information can be found at [1]http://oss.sgi.com/projects/uli/.

#2 lore raw

Once the ULI code has taken over a CPU, it should not be rescheduable
until the ULI completes. The goal is a very fast jump in and out of user space. Primitives are provided for the waking of another thread / process if the applications needs to do a lot of work.
If I've left open the possibility of a reschedule, then it was a design
error. As I think about it though everything should still work fine, but it's purely by accident. :)
If you have test code for hotplug I'd be happy to test it for you.
Thanks,
Michael

Quoted 18 lines · Ashok Raj

Hi Michael

have you thought about how this infrastructure would play well with existing CPU hotplug code for ia64?

Once you return to user mode via the iret, is it possible that user mode thread could get switched due to a pending cpu quiese attempt to remove a cpu? (Current cpu removal code would bring the entire system to knees by scheduling a high priority thread and looping with intr disabled, until the target cpu is removed)

the cpu removal code would also attempt to migrate user process to another cpu, retarget interrupts to another existing cpu etc. I havent tested the hotplug code on sgi boxes so far. (only tested on some hp boxes by Alex Williamson and on tiger4 boxes so far)

Cheers,
ashok

Signature · 2 lines
Michael A. Raymond              Office: (651) 683-3434
Core OS Group                   Real-Time System Software
#3 lore raw
In reply to Ashok Raj

I did the test you suggested. The turning-on and turning-off appeared
to work but our SN Hub ASIC still sent interrupts to the specific CPU.
I looked at my code again and from your description of Hotplug I do not
see any conflicts.
Thanks,
Michael

Quoted 18 lines · Ashok Raj

Hi Michael

have you thought about how this infrastructure would play well with existing CPU hotplug code for ia64?

Once you return to user mode via the iret, is it possible that user mode thread could get switched due to a pending cpu quiese attempt to remove a cpu? (Current cpu removal code would bring the entire system to knees by scheduling a high priority thread and looping with intr disabled, until the target cpu is removed)

the cpu removal code would also attempt to migrate user process to another cpu, retarget interrupts to another existing cpu etc. I havent tested the hotplug code on sgi boxes so far. (only tested on some hp boxes by Alex Williamson and on tiger4 boxes so far)

Cheers,
ashok

Signature · 2 lines
Michael A. Raymond              Office: (651) 683-3434
Core OS Group                   Real-Time System Software