diff -urN linux-2.5.15/arch/i386/config.in linux-2.5.15-ltt/arch/i386/config.in
--- linux-2.5.15/arch/i386/config.in	Thu May  9 18:23:23 2002
+++ linux-2.5.15-ltt/arch/i386/config.in	Fri May 10 12:42:52 2002
@@ -394,6 +394,8 @@
 
 source net/bluetooth/Config.in
 
+source drivers/trace/Config.in
+
 mainmenu_option next_comment
 comment 'Kernel hacking'
 
diff -urN linux-2.5.15/arch/i386/kernel/entry.S linux-2.5.15-ltt/arch/i386/kernel/entry.S
--- linux-2.5.15/arch/i386/kernel/entry.S	Thu May  9 18:22:56 2002
+++ linux-2.5.15-ltt/arch/i386/kernel/entry.S	Fri May 10 14:02:11 2002
@@ -258,12 +258,22 @@
 	testb $_TIF_SYSCALL_TRACE,TI_FLAGS(%ebx)
 	jnz syscall_trace_entry
 syscall_call:
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+  	movl %esp, %eax                 # copy the stack pointer
+  	pushl %eax                      # pass the stack pointer copy
+  	call trace_real_syscall_entry
+  	addl $4,%esp                    # return stack to state before pass
+  	movl ORIG_EAX(%esp),%eax	# restore eax to it's original content
+#endif
 	call *sys_call_table(,%eax,4)
 	movl %eax,EAX(%esp)		# store the return value
 syscall_exit:
 	cli				# make sure we don't miss an interrupt
 					# setting need_resched or sigpending
 					# between sampling and the iret
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+ 	call trace_real_syscall_exit
+#endif
 	movl TI_FLAGS(%ebx), %ecx
 	testw $_TIF_ALLWORK_MASK, %cx	# current->work
 	jne syscall_exit_work
diff -urN linux-2.5.15/arch/i386/kernel/irq.c linux-2.5.15-ltt/arch/i386/kernel/irq.c
--- linux-2.5.15/arch/i386/kernel/irq.c	Thu May  9 18:21:47 2002
+++ linux-2.5.15-ltt/arch/i386/kernel/irq.c	Fri May 10 12:42:52 2002
@@ -34,6 +34,8 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 
+#include <linux/trace.h>
+
 #include <asm/atomic.h>
 #include <asm/io.h>
 #include <asm/smp.h>
@@ -438,6 +440,8 @@
 
 	irq_enter(cpu, irq);
 
+	TRACE_IRQ_ENTRY(irq, !(user_mode(regs)));
+
 	status = 1;	/* Force the "do bottom halves" bit */
 
 	if (!(action->flags & SA_INTERRUPT))
@@ -453,6 +457,8 @@
 	__cli();
 
 	irq_exit(cpu, irq);
+
+	TRACE_IRQ_EXIT();
 
 	return status;
 }
diff -urN linux-2.5.15/arch/i386/kernel/process.c linux-2.5.15-ltt/arch/i386/kernel/process.c
--- linux-2.5.15/arch/i386/kernel/process.c	Thu May  9 18:21:24 2002
+++ linux-2.5.15-ltt/arch/i386/kernel/process.c	Fri May 10 12:42:52 2002
@@ -35,6 +35,8 @@
 #include <linux/init.h>
 #include <linux/mc146818rtc.h>
 
+#include <linux/trace.h>
+
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
 #include <asm/system.h>
@@ -501,6 +503,10 @@
 		 "r" (arg), "r" (fn),
 		 "b" (flags | CLONE_VM)
 		: "memory");
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+	if (retval > 0)
+	  TRACE_PROCESS(TRACE_EV_PROCESS_KTHREAD, retval, (int) fn);
+#endif
 	return retval;
 }
 
diff -urN linux-2.5.15/arch/i386/kernel/sys_i386.c linux-2.5.15-ltt/arch/i386/kernel/sys_i386.c
--- linux-2.5.15/arch/i386/kernel/sys_i386.c	Thu May  9 18:24:13 2002
+++ linux-2.5.15-ltt/arch/i386/kernel/sys_i386.c	Fri May 10 12:42:52 2002
@@ -19,6 +19,8 @@
 #include <linux/file.h>
 #include <linux/utsname.h>
 
+#include <linux/trace.h>
+
 #include <asm/uaccess.h>
 #include <asm/ipc.h>
 
@@ -136,6 +138,8 @@
 
 	version = call >> 16; /* hack for backward compatibility */
 	call &= 0xffff;
+
+	TRACE_IPC(TRACE_EV_IPC_CALL, call, first);
 
 	switch (call) {
 	case SEMOP:
diff -urN linux-2.5.15/arch/i386/kernel/traps.c linux-2.5.15-ltt/arch/i386/kernel/traps.c
--- linux-2.5.15/arch/i386/kernel/traps.c	Thu May  9 18:22:36 2002
+++ linux-2.5.15-ltt/arch/i386/kernel/traps.c	Fri May 10 12:42:52 2002
@@ -29,6 +29,8 @@
 #include <linux/ioport.h>
 #endif
 
+#include <linux/trace.h>
+
 #ifdef CONFIG_MCA
 #include <linux/mca.h>
 #include <asm/processor.h>
@@ -276,6 +278,82 @@
 	printk("Kernel BUG\n");
 }
 
+/* Trace related code */
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+asmlinkage void trace_real_syscall_entry(struct pt_regs * regs)
+{
+        int                 use_depth;
+	int                 use_bounds;
+	int                 depth = 0;
+        int                 seek_depth;
+        unsigned long       lower_bound;
+        unsigned long       upper_bound;
+	unsigned long       addr;
+	unsigned long*      stack;
+	trace_syscall_entry trace_syscall_event;
+
+        /* Set the syscall ID */
+        trace_syscall_event.syscall_id = (uint8_t) regs->orig_eax;
+
+	/* Set the address in any case */
+	trace_syscall_event.address  = regs->eip;
+
+	/* Are we in the kernel (This is a kernel thread)? */
+	if(!(regs->xcs & 3))
+	  /* Don't go digining anywhere */
+	  goto trace_syscall_end;
+
+	/* Get the trace configuration */
+	if(trace_get_config(&use_depth,
+			    &use_bounds,
+			    &seek_depth,
+			    (void*)&lower_bound,
+			    (void*)&upper_bound) < 0)
+	  goto trace_syscall_end;
+
+	/* Do we have to search for an eip address range */
+	if((use_depth == 1) || (use_bounds == 1))
+	  {
+	  /* Start at the top of the stack (bottom address since stacks grow downward) */
+	  stack = (unsigned long*) regs->esp;
+
+	  /* Keep on going until we reach the end of the process' stack limit (wherever it may be) */
+	  while(!get_user(addr, stack))
+	    {
+	    /* Does this LOOK LIKE an address in the program */
+	    if((addr > current->mm->start_code)
+             &&(addr < current->mm->end_code))
+	      {
+	      /* Does this address fit the description */
+	      if(((use_depth == 1) && (depth == seek_depth))
+               ||((use_bounds == 1) && (addr > lower_bound) && (addr < upper_bound)))
+		{
+		/* Set the address */
+		trace_syscall_event.address = addr;
+
+		/* We're done */
+		goto trace_syscall_end;
+		}
+	      else
+		/* We're one depth more */
+		depth++;
+	      }
+	    /* Go on to the next address */
+	    stack++;
+	    }
+	  }
+
+trace_syscall_end:
+	/* Trace the event */
+	trace_event(TRACE_EV_SYSCALL_ENTRY, &trace_syscall_event);
+}
+
+asmlinkage void trace_real_syscall_exit(void)
+{
+        trace_event(TRACE_EV_SYSCALL_EXIT, NULL);
+}
+#endif /* (CONFIG_TRACE || CONFIG_TRACE_MODULE) */
+
 spinlock_t die_lock = SPIN_LOCK_UNLOCKED;
 
 void die(const char * str, struct pt_regs * regs, long err)
@@ -309,6 +387,8 @@
 static void inline do_trap(int trapnr, int signr, char *str, int vm86,
 			   struct pt_regs * regs, long error_code, siginfo_t *info)
 {
+        TRACE_TRAP_ENTRY(trapnr, regs->eip);
+
 	if (vm86 && regs->eflags & VM_MASK)
 		goto vm86_trap;
 
@@ -338,6 +418,7 @@
 			force_sig_info(signr, info, tsk);
 		else
 			force_sig(signr, tsk);
+		TRACE_TRAP_EXIT();
 		return;
 	}
 
@@ -347,14 +428,17 @@
 			regs->eip = fixup;
 		else	
 			die(str, regs, error_code);
+		TRACE_TRAP_EXIT();
 		return;
 	}
 
 	vm86_trap: {
 		int ret = handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, trapnr);
 		if (ret) goto trap_signal;
+		TRACE_TRAP_EXIT();
 		return;
 	}
+	TRACE_TRAP_EXIT();
 }
 
 #define DO_ERROR(trapnr, signr, str, name) \
@@ -414,11 +498,15 @@
 
 	current->thread.error_code = error_code;
 	current->thread.trap_no = 13;
+        TRACE_TRAP_ENTRY(13, regs->eip);
 	force_sig(SIGSEGV, current);
+        TRACE_TRAP_EXIT();
 	return;
 
 gp_in_vm86:
+        TRACE_TRAP_ENTRY(13, regs->eip);
 	handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
+        TRACE_TRAP_EXIT();
 	return;
 
 gp_in_kernel:
@@ -478,6 +566,11 @@
 {
 	unsigned char reason = inb(0x61);
 
+#ifndef CONFIG_SMP /* On an SMP machine NMIs are used to implement a watchdog and will hang
+                      the machine if traced. */
+        TRACE_TRAP_ENTRY(2, regs->eip);
+#endif
+
 	++nmi_count(smp_processor_id());
 
 	if (!(reason & 0xc0)) {
@@ -488,10 +581,12 @@
 		 */
 		if (nmi_watchdog) {
 			nmi_watchdog_tick(regs);
+			TRACE_TRAP_EXIT();
 			return;
 		}
 #endif
 		unknown_nmi_error(reason, regs);
+	        TRACE_TRAP_EXIT();
 		return;
 	}
 	if (reason & 0x80)
@@ -506,6 +601,8 @@
 	inb(0x71);		/* dummy */
 	outb(0x0f, 0x70);
 	inb(0x71);		/* dummy */
+
+        TRACE_TRAP_EXIT();
 }
 
 /*
@@ -579,7 +676,9 @@
 	 */
 	info.si_addr = ((regs->xcs & 3) == 0) ? (void *)tsk->thread.eip : 
 	                                        (void *)regs->eip;
+        TRACE_TRAP_ENTRY(1, regs->eip);
 	force_sig_info(SIGTRAP, &info, tsk);
+        TRACE_TRAP_EXIT();
 
 	/* Disable additional traps. They'll be re-enabled when
 	 * the signal is delivered.
@@ -591,7 +690,9 @@
 	return;
 
 debug_vm86:
+        TRACE_TRAP_ENTRY(1, regs->eip);
 	handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1);
+        TRACE_TRAP_EXIT();
 	return;
 
 clear_TF:
@@ -740,10 +841,12 @@
 asmlinkage void do_spurious_interrupt_bug(struct pt_regs * regs,
 					  long error_code)
 {
+        TRACE_TRAP_ENTRY(16, regs->eip);
 #if 0
 	/* No need to warn about this any longer. */
 	printk("Ignoring P6 Local APIC Spurious Interrupt Bug...\n");
 #endif
+        TRACE_TRAP_EXIT();	
 }
 
 /*
@@ -772,8 +875,10 @@
 {
 	printk("math-emulation not enabled and no coprocessor found.\n");
 	printk("killing %s.\n",current->comm);
+        TRACE_TRAP_ENTRY(7, 0);
 	force_sig(SIGFPE,current);
 	schedule();
+        TRACE_TRAP_EXIT();
 }
 
 #endif /* CONFIG_MATH_EMULATION */
@@ -805,7 +910,6 @@
 	:"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
 	 "3" ((char *) (addr)),"2" (__KERNEL_CS << 16)); \
 } while (0)
-
 
 /*
  * This needs to use 'idt_table' rather than 'idt', and
diff -urN linux-2.5.15/arch/i386/mm/fault.c linux-2.5.15-ltt/arch/i386/mm/fault.c
--- linux-2.5.15/arch/i386/mm/fault.c	Thu May  9 18:21:29 2002
+++ linux-2.5.15-ltt/arch/i386/mm/fault.c	Fri May 10 12:42:52 2002
@@ -20,6 +20,8 @@
 #include <linux/tty.h>
 #include <linux/vt_kern.h>		/* For unblank_screen() */
 
+#include <linux/trace.h>
+
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
@@ -178,6 +180,8 @@
 	mm = tsk->mm;
 	info.si_code = SEGV_MAPERR;
 
+	TRACE_TRAP_ENTRY(14, regs->eip);
+
 	/*
 	 * If we're in an interrupt or have no user
 	 * context, we must not take the fault..
@@ -260,6 +264,7 @@
 			tsk->thread.screen_bitmap |= 1 << bit;
 	}
 	up_read(&mm->mmap_sem);
+        TRACE_TRAP_EXIT();
 	return;
 
 /*
@@ -279,6 +284,7 @@
 		/* info.si_code has been set above */
 		info.si_addr = (void *)address;
 		force_sig_info(SIGSEGV, &info, tsk);
+		TRACE_TRAP_EXIT();
 		return;
 	}
 
@@ -293,6 +299,7 @@
 
 		if (nr == 6) {
 			do_invalid_op(regs, 0);
+			TRACE_TRAP_EXIT();
 			return;
 		}
 	}
@@ -302,6 +309,7 @@
 	/* Are we prepared to handle this kernel fault?  */
 	if ((fixup = search_exception_table(regs->eip)) != 0) {
 		regs->eip = fixup;
+		TRACE_TRAP_EXIT();
 		return;
 	}
 
@@ -375,6 +383,7 @@
 	/* Kernel mode? Handle exceptions or die */
 	if (!(error_code & 4))
 		goto no_context;
+        TRACE_TRAP_EXIT();
 	return;
 
 vmalloc_fault:
@@ -408,6 +417,8 @@
 		pte_k = pte_offset_kernel(pmd_k, address);
 		if (!pte_present(*pte_k))
 			goto no_context;
+		TRACE_TRAP_EXIT();
 		return;
 	}
+	TRACE_TRAP_EXIT();
 }
diff -urN linux-2.5.15/arch/mips/config.in linux-2.5.15-ltt/arch/mips/config.in
--- linux-2.5.15/arch/mips/config.in	Thu May  9 18:25:03 2002
+++ linux-2.5.15-ltt/arch/mips/config.in	Fri May 10 12:42:52 2002
@@ -486,6 +486,8 @@
 source drivers/usb/Config.in
 source drivers/input/Config.in
 
+source drivers/trace/Config.in
+
 mainmenu_option next_comment
 comment 'Kernel hacking'
 
diff -urN linux-2.5.15/arch/mips/ddb5476/irq.c linux-2.5.15-ltt/arch/mips/ddb5476/irq.c
--- linux-2.5.15/arch/mips/ddb5476/irq.c	Thu May  9 18:23:13 2002
+++ linux-2.5.15-ltt/arch/mips/ddb5476/irq.c	Fri May 10 12:42:52 2002
@@ -3,6 +3,10 @@
  *
  *  Copyright (C) 2000 Geert Uytterhoeven <geert@sonycom.com>
  *                     Sony Software Development Center Europe (SDCE), Brussels
+ *
+ *  ---- for LTT patch ----
+ * Copyright (C) 2001 Takuzo O'Hara (takuzo@sm.sony.co.jp).
+ *
  */
 #include <linux/config.h>
 #include <linux/init.h>
@@ -12,6 +16,8 @@
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 
+#include <linux/trace.h>
+
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/ptrace.h>
@@ -184,6 +190,7 @@
 	/* Handle the timer interrupt first */
 	if (mask & (1 << NILE4_INT_GPT)) {
 		nile4_disable_irq(NILE4_INT_GPT);
+		TRACE_IRQ_ENTRY(nile4_to_irq(NILE4_INT_GPT), ((regs->cp0_status & ST0_KSU) == KSU_KERNEL));
 		do_IRQ(nile4_to_irq(NILE4_INT_GPT), regs);
 		nile4_enable_irq(NILE4_INT_GPT);
 		mask &= ~(1 << NILE4_INT_GPT);
@@ -193,8 +200,10 @@
 			nile4_disable_irq(nile4_irq);
 			if (nile4_irq == NILE4_INT_INTC) {
 				int i8259_irq = nile4_i8259_iack();
+				TRACE_IRQ_ENTRY(i8259_irq, ((regs->cp0_status & ST0_KSU) == KSU_KERNEL));
 				i8259_do_irq(i8259_irq, regs);
 			} else {
+			        TRACE_IRQ_ENTRY(nile4_to_irq(nile4_irq), ((regs->cp0_status & ST0_KSU) == KSU_KERNEL));
 				do_IRQ(nile4_to_irq(nile4_irq), regs);
 			}
 			nile4_enable_irq(nile4_irq);
@@ -204,6 +213,7 @@
 		ddb5476_led_d3(0);
 	ddb5476_led_hex(nesting < 16 ? nesting : 15);
 #endif
+        TRACE_IRQ_EXIT();
 }
 
 void ddb_local1_irqdispatch(void)
diff -urN linux-2.5.15/arch/mips/kernel/irq.c linux-2.5.15-ltt/arch/mips/kernel/irq.c
--- linux-2.5.15/arch/mips/kernel/irq.c	Thu May  9 18:22:02 2002
+++ linux-2.5.15-ltt/arch/mips/kernel/irq.c	Fri May 10 12:42:52 2002
@@ -7,6 +7,10 @@
  *
  * Copyright (C) 1992 Linus Torvalds
  * Copyright (C) 1994 - 2000 Ralf Baechle
+ *
+ *  ---- for LTT patch ----
+ * Copyright (C) 2001 Takuzo O'Hara (takuzo@sm.sony.co.jp).
+ *
  */
 #include <linux/kernel.h>
 #include <linux/irq.h>
@@ -19,6 +23,8 @@
 #include <linux/sched.h>
 #include <linux/seq_file.h>
 
+#include <linux/trace.h>
+
 #include <asm/system.h>
 
 /*
@@ -244,6 +250,8 @@
 	struct irqaction * action;
 	unsigned int status;
 
+	TRACE_IRQ_ENTRY(irq, ((regs->cp0_status & ST0_KSU) == KSU_KERNEL));
+
 	kstat.irqs[cpu][irq]++;
 	spin_lock(&desc->lock);
 	desc->handler->ack(irq);
@@ -302,6 +310,8 @@
 	 */
 	desc->handler->end(irq);
 	spin_unlock(&desc->lock);
+
+        TRACE_IRQ_EXIT();
 
 	if (softirq_pending(cpu))
 		do_softirq();
diff -urN linux-2.5.15/arch/mips/kernel/scall_o32.S linux-2.5.15-ltt/arch/mips/kernel/scall_o32.S
--- linux-2.5.15/arch/mips/kernel/scall_o32.S	Thu May  9 18:25:26 2002
+++ linux-2.5.15-ltt/arch/mips/kernel/scall_o32.S	Fri May 10 12:42:52 2002
@@ -4,7 +4,12 @@
  * for more details.
  *
  * Copyright (C) 1997, 1998, 1999, 2000 by Ralf Baechle
+ *
+ *  ---- for LTT patch ----
+ * Copyright (C) 2001 Takuzo O'Hara (takuzo@sm.sony.co.jp).
+ *
  */
+	
 #include <asm/asm.h>
 #include <linux/errno.h>
 #include <asm/current.h>
@@ -48,6 +53,10 @@
 	bgez	t0, stackargs
 
 stack_done:
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+        sw      a3, PT_R26(sp)          # save for syscall restart
+	b	ltt_trace_a_syscall
+#endif /* (CONFIG_TRACE || CONFIG_TRACE_MODULE) */ 
         sw      a3, PT_R26(sp)          # save for syscall restart
 #error	lw	t0, TASK_PTRACE($28)	# syscall tracing enabled?
 	andi	t0, PT_TRACESYS
@@ -95,6 +104,35 @@
 	SAVE_STATIC
 	jal	schedule
 	b	o32_ret_from_sys_call
+
+/* ------------------------------------------------------------------------ */
+
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+ltt_trace_a_syscall:
+	SAVE_STATIC
+	sw	t2, PT_R1(sp)
+	move	a0, sp
+	jal	trace_real_syscall_entry
+	lw	t2, PT_R1(sp)
+
+	lw	a0, PT_R4(sp)		# Restore argument registers
+	lw	a1, PT_R5(sp)
+	lw	a2, PT_R6(sp)
+	lw	a3, PT_R7(sp)
+	jalr	t2
+
+	li	t0, -EMAXERRNO - 1	# error?
+	sltu	t0, t0, v0
+	sw	t0, PT_R7(sp)		# set error flag
+	beqz	t0, 1f
+
+	negu	v0			# error
+	sw	v0, PT_R0(sp)		# set flag for syscall restarting
+1:	sw	v0, PT_R2(sp)		# result
+
+	jal	trace_real_syscall_exit
+	j	o32_ret_from_sys_call
+#endif /* (CONFIG_TRACE || CONFIG_TRACE_MODULE) */	
 
 /* ------------------------------------------------------------------------ */
 
diff -urN linux-2.5.15/arch/mips/kernel/time.c linux-2.5.15-ltt/arch/mips/kernel/time.c
--- linux-2.5.15/arch/mips/kernel/time.c	Thu May  9 18:24:12 2002
+++ linux-2.5.15-ltt/arch/mips/kernel/time.c	Fri May 10 12:42:52 2002
@@ -366,6 +366,8 @@
 {
 	int cpu = smp_processor_id();
 
+	TRACE_IRQ_ENTRY(irq, ((regs->cp0_status & ST0_KSU) == KSU_KERNEL));
+
 	irq_enter(cpu, irq);
 	kstat.irqs[cpu][irq]++;
 
@@ -373,6 +375,8 @@
 	timer_interrupt(irq, NULL, regs);
 	
 	irq_exit(cpu, irq);
+
+	TRACE_IRQ_EXIT();
 
 	if (softirq_pending(cpu))
 		do_softirq();
diff -urN linux-2.5.15/arch/mips/kernel/traps.c linux-2.5.15-ltt/arch/mips/kernel/traps.c
--- linux-2.5.15/arch/mips/kernel/traps.c	Thu May  9 18:24:07 2002
+++ linux-2.5.15-ltt/arch/mips/kernel/traps.c	Fri May 10 12:42:52 2002
@@ -10,6 +10,10 @@
  *
  * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  * Copyright (C) 2000, 01 MIPS Technologies, Inc.
+ *
+ *  ---- for LTT patch ----
+ * Copyright (C) 2001 Takuzo O'Hara (takuzo@sm.sony.co.jp).
+ *
  */
 #include <linux/config.h>
 #include <linux/init.h>
@@ -20,6 +24,8 @@
 #include <linux/smp_lock.h>
 #include <linux/spinlock.h>
 
+#include <linux/trace.h>
+
 #include <asm/bootinfo.h>
 #include <asm/branch.h>
 #include <asm/cpu.h>
@@ -34,6 +40,7 @@
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
+#include <asm/unistd.h>
 
 /*
  * Machine specific interrupt handlers
@@ -188,6 +195,86 @@
 	}
 }
 
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+asmlinkage void trace_real_syscall_entry(struct pt_regs * regs)
+{
+#if 0
+        int                 use_depth;
+	int                 use_bounds;
+	int                 depth = 0;
+        int                 seek_depth;
+        unsigned long       lower_bound;
+        unsigned long       upper_bound;
+	unsigned long       addr;
+	unsigned long*      stack;
+#endif
+	trace_syscall_entry trace_syscall_event;
+
+        /* Set the syscall ID */
+        trace_syscall_event.syscall_id = (uint8_t) (regs->regs[2] - __NR_Linux); /* v0 */
+
+	/* Set the address in any case */
+	trace_syscall_event.address  = regs->cp0_epc;
+
+	/* Are we in the kernel (This is a kernel thread)? */
+	if((regs->cp0_status & ST0_KSU) == KSU_KERNEL)
+	  /* Don't go digining anywhere */
+	    goto trace_syscall_end; // takuzo: why? noone wants to monitor kernel threads?
+
+#if 0   // takuzo: I'll just do it later
+	/* Get the trace configuration */
+	if(trace_get_config(&use_depth,
+			    &use_bounds,
+			    &seek_depth,
+			    (void*)&lower_bound,
+			    (void*)&upper_bound) < 0)
+	  goto trace_syscall_end;
+
+	/* Do we have to search for an eip address range */
+	if((use_depth == 1) || (use_bounds == 1))
+	  {
+	  /* Start at the top of the stack (bottom address since stacks grow downward) */
+	  stack = (unsigned long*) regs->esp;
+
+	  /* Keep on going until we reach the end of the process' stack limit (wherever it may be) */
+	  while(!get_user(addr, stack))
+	    {
+	    /* Does this LOOK LIKE an address in the program */
+	    if((addr > current->mm->start_code)
+             &&(addr < current->mm->end_code))
+	      {
+	      /* Does this address fit the description */
+              if(((use_depth == 1) && (depth == seek_depth))
+               ||((use_bounds == 1) && (addr > lower_bound) && (addr < upper_bound)))
+		{
+		/* Set the address */
+		trace_syscall_event.address = addr;
+
+		/* We're done */
+		goto trace_syscall_end;
+		}
+	      else
+		/* We're one depth more */
+		depth++;
+	      }
+	    /* Go on to the next address */
+	    stack++;
+    }
+	  }
+#endif /* 0 */
+
+trace_syscall_end:
+	/* Trace the event */
+	trace_event(TRACE_EV_SYSCALL_ENTRY, &trace_syscall_event);
+}
+
+asmlinkage void trace_real_syscall_exit(void)
+{
+        trace_event(TRACE_EV_SYSCALL_EXIT, NULL);
+}
+
+#endif /* (CONFIG_TRACE || CONFIG_TRACE_MODULE) */
+
 spinlock_t die_lock;
 
 extern void __die(const char * str, struct pt_regs * regs, const char *where,
@@ -314,20 +401,28 @@
 
 asmlinkage void do_ibe(struct pt_regs *regs)
 {
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
 	ibe_board_handler(regs);
+//	TRACE_TRAP_EXIT();
 }
 
 asmlinkage void do_dbe(struct pt_regs *regs)
 {
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
 	dbe_board_handler(regs);
+//	TRACE_TRAP_EXIT();
 }
 
 asmlinkage void do_ov(struct pt_regs *regs)
 {
-	if (compute_return_epc(regs))
-		return;
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
+        if (compute_return_epc(regs)) {
+//       	TRACE_TRAP_EXIT();
+	        return;
+	}
 
 	force_sig(SIGFPE, current);
+//	TRACE_TRAP_EXIT();
 }
 
 /*
@@ -335,6 +430,7 @@
  */
 asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
 {
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
 	if (fcr31 & FPU_CSR_UNI_X) {
 		extern void save_fp(struct task_struct *);
 		extern void restore_fp(struct task_struct *);
@@ -368,14 +464,18 @@
 		if (sig)
 			force_sig(sig, current);
 
+//       	TRACE_TRAP_EXIT();
 		return;
 	}
 
-	if (compute_return_epc(regs))
+	if (compute_return_epc(regs)){
+//       	TRACE_TRAP_EXIT();
 		return;
+	}
 
 	force_sig(SIGFPE, current);
 	printk(KERN_DEBUG "Sent send SIGFPE to %s\n", current->comm);
+//     	TRACE_TRAP_EXIT();
 }
 
 static inline int get_insn_opcode(struct pt_regs *regs, unsigned int *opcode)
@@ -397,6 +497,8 @@
 	unsigned int opcode, bcode;
 	unsigned int *epc;
 
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
+
 	epc = (unsigned int *) regs->cp0_epc +
 	      ((regs->cp0_cause & CAUSEF_BD) != 0);
 	if (get_user(opcode, epc))
@@ -430,10 +532,12 @@
 	default:
 		force_sig(SIGTRAP, current);
 	}
+//	TRACE_TRAP_EXIT();
 	return;
 
 sigsegv:
 	force_sig(SIGSEGV, current);
+//	TRACE_TRAP_EXIT();
 }
 
 asmlinkage void do_tr(struct pt_regs *regs)
@@ -495,21 +599,27 @@
 
 	if (!user_mode(regs))
 		BUG();
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
 
 	if (!get_insn_opcode(regs, &opcode)) {
 		if ((opcode & OPCODE) == LL) {
 			simulate_ll(regs, opcode);
+			//	TRACE_TRAP_EXIT();
 			return;
 		}
 		if ((opcode & OPCODE) == SC) {
 			simulate_sc(regs, opcode);
+			//	TRACE_TRAP_EXIT();
 			return;
 		}
 	}
 
-	if (compute_return_epc(regs))
+	if (compute_return_epc(regs)) {
+	  //	TRACE_TRAP_EXIT();
 		return;
+	}
 	force_sig(SIGILL, current);
+//	TRACE_TRAP_EXIT();
 }
 
 /*
@@ -625,6 +735,8 @@
 	void fpu_emulator_init_fpu(void);
 	int sig;
 
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
+
 	cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
 	if (cpid != 1)
 		goto bad_cid;
@@ -633,8 +745,10 @@
 		goto fp_emul;
 
 	regs->cp0_status |= ST0_CU1;
-	if (last_task_used_math == current)
+	if (last_task_used_math == current) {
+	  //	TRACE_TRAP_EXIT();
 		return;
+	}
 
 	if (current->used_math) {		/* Using the FPU again.  */
 		lazy_fpu_switch(last_task_used_math);
@@ -643,6 +757,7 @@
 		current->used_math = 1;
 	}
 	last_task_used_math = current;
+//	TRACE_TRAP_EXIT();
 	return;
 
 fp_emul:
@@ -656,10 +771,12 @@
 	last_task_used_math = current;
 	if (sig)
 		force_sig(sig, current);
+//	TRACE_TRAP_EXIT();
 	return;
 
 bad_cid:
 	force_sig(SIGILL, current);
+//	TRACE_TRAP_EXIT();
 }
 
 asmlinkage void do_watch(struct pt_regs *regs)
@@ -668,7 +785,9 @@
 	 * We use the watch exception where available to detect stack
 	 * overflows.
 	 */
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
 	show_regs(regs);
+//      TRACE_TRACE_EXIT();
 	panic("Caught WATCH exception - probably caused by stack overflow.");
 }
 
@@ -686,7 +805,9 @@
 	 * caused by a new unknown cpu type or after another deadly
 	 * hard/software error.
 	 */
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
 	show_regs(regs);
+//      TRACE_TRACE_EXIT();
 	panic("Caught reserved exception - should not happen.");
 }
 
diff -urN linux-2.5.15/arch/mips/kernel/unaligned.c linux-2.5.15-ltt/arch/mips/kernel/unaligned.c
--- linux-2.5.15/arch/mips/kernel/unaligned.c	Thu May  9 18:21:40 2002
+++ linux-2.5.15-ltt/arch/mips/kernel/unaligned.c	Fri May 10 12:42:52 2002
@@ -8,6 +8,9 @@
  * Copyright (C) 1996, 1998 by Ralf Baechle
  * Copyright (C) 1999 Silicon Graphics, Inc.
  *
+ *  ---- for LTT patch ----
+ * Copyright (C) 2001 Takuzo O'Hara (takuzo@sm.sony.co.jp).
+ *
  * This file contains exception handler for address error exception with the
  * special capability to execute faulting instructions in software.  The
  * handler does not try to handle the case when the program counter points
@@ -78,6 +81,8 @@
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
 
+#include <linux/trace.h>
+
 #include <asm/asm.h>
 #include <asm/branch.h>
 #include <asm/byteorder.h>
@@ -400,6 +405,8 @@
 		return;
 	}
 
+//	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
+
 	/*
 	 * Did we catch a fault trying to load an instruction?
 	 * This also catches attempts to activate MIPS16 code on
@@ -409,8 +416,10 @@
 		goto sigbus;
 
 	pc = regs->cp0_epc + ((regs->cp0_cause & CAUSEF_BD) ? 4 : 0);
-	if (compute_return_epc(regs))
+	if (compute_return_epc(regs)){
+	  //    TRACE_TRAP_EXIT();
 		return;
+	}
 	if ((current->thread.mflags & MF_FIXADE) == 0)
 		goto sigbus;
 
@@ -419,11 +428,13 @@
 	unaligned_instructions++;
 #endif
 
+//      TRACE_TRAP_EXIT();
 	return;
 
 sigbus:
 	die_if_kernel ("Kernel unaligned instruction access", regs);
 	force_sig(SIGBUS, current);
 
+//      TRACE_TRAP_EXIT();
 	return;
 }
diff -urN linux-2.5.15/arch/mips/mm/fault.c linux-2.5.15-ltt/arch/mips/mm/fault.c
--- linux-2.5.15/arch/mips/mm/fault.c	Thu May  9 18:22:57 2002
+++ linux-2.5.15-ltt/arch/mips/mm/fault.c	Fri May 10 12:42:52 2002
@@ -4,6 +4,10 @@
  * for more details.
  *
  * Copyright (C) 1995 - 2000 by Ralf Baechle
+ *
+ *  ---- for LTT patch ----
+ * Copyright (C) 2001 Takuzo O'Hara (takuzo@sm.sony.co.jp).
+ *
  */
 #include <linux/signal.h>
 #include <linux/sched.h>
@@ -19,12 +23,18 @@
 #include <linux/smp_lock.h>
 #include <linux/version.h>
 
+#include <linux/trace.h>
+
 #include <asm/hardirq.h>
 #include <asm/pgalloc.h>
 #include <asm/mmu_context.h>
 #include <asm/softirq.h>
 #include <asm/system.h>
 #include <asm/uaccess.h>
+#include <asm/mipsregs.h>
+#include <asm/unistd.h>
+
+#define EXC_CODE(x)     ((CAUSEF_EXCCODE & (x)) >> CAUSEB_EXCCODE)
 
 #define development_version (LINUX_VERSION_CODE & 0x100)
 
@@ -87,6 +97,10 @@
  * we can handle it..
  */
 good_area:
+	// takuzo: 
+	// I only made this to log page faults for reasonable usermode context.
+	// page faults in kernel, fixups, sigbuses are siliently ignored...
+	TRACE_TRAP_ENTRY(EXC_CODE(regs->cp0_cause), regs->cp0_epc);
 	info.si_code = SEGV_ACCERR;
 
 	if (write) {
@@ -116,6 +130,7 @@
 	}
 
 	up_read(&mm->mmap_sem);
+//      TRACE_TRAP_EXIT();
 	return;
 
 /*
diff -urN linux-2.5.15/arch/ppc/config.in linux-2.5.15-ltt/arch/ppc/config.in
--- linux-2.5.15/arch/ppc/config.in	Thu May  9 18:21:29 2002
+++ linux-2.5.15-ltt/arch/ppc/config.in	Fri May 10 12:42:52 2002
@@ -594,6 +594,8 @@
 
 source lib/Config.in
 
+source drivers/trace/Config.in
+
 mainmenu_option next_comment
 comment 'Kernel hacking'
 
diff -urN linux-2.5.15/arch/ppc/kernel/entry.S linux-2.5.15-ltt/arch/ppc/kernel/entry.S
--- linux-2.5.15/arch/ppc/kernel/entry.S	Thu May  9 18:23:30 2002
+++ linux-2.5.15-ltt/arch/ppc/kernel/entry.S	Fri May 10 12:59:31 2002
@@ -106,6 +106,32 @@
 	RFI
 #endif /* CONFIG_PPC_ISERIES */
 
+/* LTT stuff */
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+#define TRACE_REAL_ASM_SYSCALL_ENTRY	\
+	addi	r3,r1,STACK_FRAME_OVERHEAD;  	/* Put pointer to registers into r3 */	\
+	mflr	r29;				/* Save LR */ \
+	bl	trace_real_syscall_entry;	/* Call real trace function */ \
+	mtlr	r29;				/* Restore LR */ \
+	lwz	r0,GPR0(r1);			/* Restore original registers */ \
+	lwz	r3,GPR3(r1);	\
+	lwz	r4,GPR4(r1);	\
+	lwz	r5,GPR5(r1);	\
+	lwz	r6,GPR6(r1);	\
+	lwz	r7,GPR7(r1);	\
+	lwz	r8,GPR8(r1);
+#define TRACE_REAL_ASM_SYSCALL_EXIT \
+	bl	trace_real_syscall_exit;	/* Call real trace function */ \
+	lwz	r0,GPR0(r1);			/* Restore original registers */ \
+	lwz	r3,RESULT(r1); \
+	lwz	r4,GPR4(r1); \
+	lwz	r5,GPR5(r1); \
+	lwz	r6,GPR6(r1); \
+	lwz	r7,GPR7(r1); \
+	lwz	r8,GPR8(r1); \
+	addi	r9,r1,STACK_FRAME_OVERHEAD;
+#endif
+
 /*
  * Handle a system call.
  */
@@ -136,12 +162,19 @@
 	slwi	r0,r0,2
 	lwzx	r10,r10,r0	/* Fetch system call handler [ptr] */
 	mtlr	r10
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+ 	TRACE_REAL_ASM_SYSCALL_ENTRY ;
+#endif
 	addi	r9,r1,STACK_FRAME_OVERHEAD
 	blrl			/* Call handler */
 	.globl	ret_from_syscall
 ret_from_syscall:
 #ifdef SHOW_SYSCALLS
 	bl	do_show_syscall_exit
+#endif
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+	stw	r3,RESULT(r1)	/* Save result */
+ 	TRACE_REAL_ASM_SYSCALL_EXIT ; 
 #endif
 	mr	r6,r3
 	li	r11,-_LAST_ERRNO
diff -urN linux-2.5.15/arch/ppc/kernel/irq.c linux-2.5.15-ltt/arch/ppc/kernel/irq.c
--- linux-2.5.15/arch/ppc/kernel/irq.c	Thu May  9 18:23:06 2002
+++ linux-2.5.15-ltt/arch/ppc/kernel/irq.c	Fri May 10 12:42:52 2002
@@ -49,6 +49,8 @@
 #include <linux/random.h>
 #include <linux/seq_file.h>
 
+#include <linux/trace.h>
+
 #include <asm/uaccess.h>
 #include <asm/bitops.h>
 #include <asm/system.h>
@@ -442,6 +444,8 @@
 	int cpu = smp_processor_id();
 	irq_desc_t *desc = irq_desc + irq;
 
+	TRACE_IRQ_ENTRY(irq, !(user_mode(regs)));
+
 	kstat.irqs[cpu][irq]++;
 	spin_lock(&desc->lock);
 	ack_irq(irq);	
@@ -519,6 +523,8 @@
 			irq_desc[irq].handler->enable(irq);
 	}
 	spin_unlock(&desc->lock);
+
+	TRACE_IRQ_EXIT();
 }
 
 #ifndef CONFIG_PPC_ISERIES	/* iSeries version is in iSeries_pic.c */
diff -urN linux-2.5.15/arch/ppc/kernel/misc.S linux-2.5.15-ltt/arch/ppc/kernel/misc.S
--- linux-2.5.15/arch/ppc/kernel/misc.S	Thu May  9 18:23:36 2002
+++ linux-2.5.15-ltt/arch/ppc/kernel/misc.S	Fri May 10 13:10:28 2002
@@ -1016,7 +1016,11 @@
  * Create a kernel thread
  *   kernel_thread(fn, arg, flags)
  */
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+_GLOBAL(original_kernel_thread)
+#else
 _GLOBAL(kernel_thread)
+#endif /* (CONFIG_TRACE || CONFIG_TRACE_MODULE) */
 	stwu	r1,-16(r1)
 	stw	r30,8(r1)
 	stw	r31,12(r1)
diff -urN linux-2.5.15/arch/ppc/kernel/process.c linux-2.5.15-ltt/arch/ppc/kernel/process.c
--- linux-2.5.15/arch/ppc/kernel/process.c	Thu May  9 18:24:21 2002
+++ linux-2.5.15-ltt/arch/ppc/kernel/process.c	Fri May 10 12:42:52 2002
@@ -37,6 +37,8 @@
 #include <linux/prctl.h>
 #include <linux/init_task.h>
 
+#include <linux/trace.h>
+
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
@@ -296,6 +298,19 @@
 	printk("\n");
 	print_backtrace((unsigned long *)regs->gpr[1]);
 }
+
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+long original_kernel_thread(int (*fn) (void *), void* arg, unsigned long flags);
+long kernel_thread(int (*fn) (void *), void* arg, unsigned long flags)
+{
+        long   retval;
+
+	retval = original_kernel_thread(fn, arg, flags);
+	if (retval > 0)
+	        TRACE_PROCESS(TRACE_EV_PROCESS_KTHREAD, retval, (int) fn);
+	return retval;
+}
+#endif /* (CONFIG_TRACE || CONFIG_TRACE_MODULE) */
 
 void exit_thread(void)
 {
diff -urN linux-2.5.15/arch/ppc/kernel/syscalls.c linux-2.5.15-ltt/arch/ppc/kernel/syscalls.c
--- linux-2.5.15/arch/ppc/kernel/syscalls.c	Thu May  9 18:24:01 2002
+++ linux-2.5.15-ltt/arch/ppc/kernel/syscalls.c	Fri May 10 12:42:52 2002
@@ -39,6 +39,8 @@
 #include <linux/utsname.h>
 #include <linux/file.h>
 
+#include <linux/trace.h>
+
 #include <asm/uaccess.h>
 #include <asm/ipc.h>
 #include <asm/semaphore.h>
@@ -84,6 +86,8 @@
 
 	version = call >> 16; /* hack for backward compatibility */
 	call &= 0xffff;
+
+	TRACE_IPC(TRACE_EV_IPC_CALL, call, first);
 
 	ret = -EINVAL;
 	switch (call) {
diff -urN linux-2.5.15/arch/ppc/kernel/time.c linux-2.5.15-ltt/arch/ppc/kernel/time.c
--- linux-2.5.15/arch/ppc/kernel/time.c	Thu May  9 18:22:49 2002
+++ linux-2.5.15-ltt/arch/ppc/kernel/time.c	Fri May 10 12:42:52 2002
@@ -60,6 +60,8 @@
 #include <linux/time.h>
 #include <linux/init.h>
 
+#include <linux/trace.h>
+
 #include <asm/segment.h>
 #include <asm/io.h>
 #include <asm/processor.h>
@@ -158,6 +160,8 @@
 	if (atomic_read(&ppc_n_lost_interrupts) != 0)
 		do_IRQ(regs);
 
+	TRACE_TRAP_ENTRY(regs->trap, instruction_pointer(regs));
+
 	hardirq_enter(cpu);
 	
 	while ((next_dec = tb_ticks_per_jiffy - tb_delta(&jiffy_stamp)) < 0) {
@@ -215,6 +219,8 @@
 
 	if (softirq_pending(cpu))
 		do_softirq();
+
+	TRACE_TRAP_EXIT();
 
 	return 1; /* lets ret_from_int know we can do checks */
 }
diff -urN linux-2.5.15/arch/ppc/kernel/traps.c linux-2.5.15-ltt/arch/ppc/kernel/traps.c
--- linux-2.5.15/arch/ppc/kernel/traps.c	Thu May  9 18:22:46 2002
+++ linux-2.5.15-ltt/arch/ppc/kernel/traps.c	Fri May 10 12:42:52 2002
@@ -33,6 +33,8 @@
 #include <linux/config.h>
 #include <linux/init.h>
 
+#include <linux/trace.h>
+
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
@@ -111,7 +113,9 @@
 		debugger(regs);
 		die("Exception in kernel mode", regs, signr);
 	}
+	TRACE_TRAP_ENTRY(regs->trap, instruction_pointer(regs));
 	force_sig(signr, current);
+	TRACE_TRAP_EXIT();
 }
 
 void
@@ -367,6 +371,89 @@
 	show_regs(regs);
 	panic("kernel stack overflow");
 }
+
+/* Trace related code */
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+asmlinkage void trace_real_syscall_entry(struct pt_regs * regs)
+{
+        int                 use_depth;
+	int                 use_bounds;
+	int                 depth = 0;
+        int                 seek_depth;
+        unsigned long       lower_bound;
+        unsigned long       upper_bound;
+	unsigned long       addr;
+	unsigned long*      stack;
+	trace_syscall_entry trace_syscall_event;
+
+        /* Set the syscall ID */
+	trace_syscall_event.syscall_id = (uint8_t) regs->gpr[0];
+
+	/* Set the address in any case */
+	trace_syscall_event.address  = instruction_pointer(regs);
+
+	/* Are we in the kernel (This is a kernel thread)? */
+	if(!user_mode(regs))
+	  /* Don't go digining anywhere */
+	  goto trace_syscall_end;
+
+	/* Get the trace configuration */
+	if(trace_get_config(&use_depth,
+			    &use_bounds,
+			    &seek_depth,
+			    (void*)&lower_bound,
+			    (void*)&upper_bound) < 0)
+	  goto trace_syscall_end;
+
+	/* Do we have to search for an eip address range */
+	if((use_depth == 1) || (use_bounds == 1))
+	  {
+	  /* Start at the top of the stack (bottom address since stacks grow downward) */
+	  stack = (unsigned long*) regs->gpr[1];
+
+	  /* Skip over first stack frame as the return address isn't valid */
+	  if(get_user(addr, stack))
+	    goto trace_syscall_end;
+	  stack = (unsigned long*) addr;
+
+	  /* Keep on going until we reach the end of the process' stack limit (wherever it may be) */
+	  while(!get_user(addr, stack + 1)) /* "stack + 1", since this is where the IP is */
+	    {
+	    /* Does this LOOK LIKE an address in the program */
+	    if((addr > current->mm->start_code)
+             &&(addr < current->mm->end_code))
+	      {
+	      /* Does this address fit the description */
+	      if(((use_depth == 1) && (depth == seek_depth))
+               ||((use_bounds == 1) && (addr > lower_bound) && (addr < upper_bound)))
+		{
+		/* Set the address */
+		trace_syscall_event.address = addr;
+
+		/* We're done */
+		goto trace_syscall_end;
+		}
+	      else
+		/* We're one depth more */
+		depth++;
+	      }
+	    /* Go on to the next address */
+	    if(get_user(addr, stack))
+	      goto trace_syscall_end;
+	    stack = (unsigned long*) addr;
+	    }
+	  }
+
+trace_syscall_end:
+	/* Trace the event */
+	trace_event(TRACE_EV_SYSCALL_ENTRY, &trace_syscall_event);
+}
+
+asmlinkage void trace_real_syscall_exit(void)
+{
+        trace_event(TRACE_EV_SYSCALL_EXIT, NULL);
+}
+#endif /* (CONFIG_TRACE || CONFIG_TRACE_MODULE) */
 
 void nonrecoverable_exception(struct pt_regs *regs)
 {
diff -urN linux-2.5.15/arch/ppc/mm/fault.c linux-2.5.15-ltt/arch/ppc/mm/fault.c
--- linux-2.5.15/arch/ppc/mm/fault.c	Thu May  9 18:23:12 2002
+++ linux-2.5.15-ltt/arch/ppc/mm/fault.c	Fri May 10 13:14:49 2002
@@ -31,6 +31,8 @@
 #include <linux/interrupt.h>
 #include <linux/highmem.h>
 
+#include <linux/trace.h>
+
 #include <asm/page.h>
 #include <asm/pgtable.h>
 #include <asm/mmu.h>
@@ -88,22 +90,28 @@
 		is_write = error_code & 0x02000000;
 #endif /* CONFIG_4xx */
 
+	TRACE_TRAP_ENTRY(regs->trap, instruction_pointer(regs));
+
 #if defined(CONFIG_XMON) || defined(CONFIG_KGDB)
 	if (debugger_fault_handler && TRAP(regs) == 0x300) {
 		debugger_fault_handler(regs);
+		TRACE_TRAP_EXIT();
 		return;
 	}
 #if !defined(CONFIG_4xx)
 	if (error_code & 0x00400000) {
 		/* DABR match */
-		if (debugger_dabr_match(regs))
+		if (debugger_dabr_match(regs)){
+			TRACE_TRAP_EXIT();
 			return;
+		}
 	}
 #endif /* !CONFIG_4xx */
 #endif /* CONFIG_XMON || CONFIG_KGDB */
 
 	if (in_interrupt() || mm == NULL) {
 		bad_page_fault(regs, address, SIGSEGV);
+		TRACE_TRAP_EXIT();
 		return;
 	}
 	down_read(&mm->mmap_sem);
@@ -168,6 +176,7 @@
 			_tlbie(address);
 			pte_unmap(ptep);
 			up_read(&mm->mmap_sem);
+			TRACE_TRAP_EXIT();
 			return;
 		}
 		if (ptep != NULL)
@@ -208,6 +217,7 @@
 	 * -- Cort
 	 */
 	pte_misses++;
+	TRACE_TRAP_EXIT();
 	return;
 
 bad_area:
@@ -221,10 +231,12 @@
 		info.si_code = code;
 		info.si_addr = (void *) address;
 		force_sig_info(SIGSEGV, &info, current);
+		TRACE_TRAP_EXIT();
 		return;
 	}
 
 	bad_page_fault(regs, address, SIGSEGV);
+	TRACE_TRAP_EXIT();
 	return;
 
 /*
@@ -242,6 +254,7 @@
 	if (user_mode(regs))
 		do_exit(SIGKILL);
 	bad_page_fault(regs, address, SIGKILL);
+	TRACE_TRAP_EXIT();
 	return;
 
 do_sigbus:
@@ -253,6 +266,7 @@
 	force_sig_info (SIGBUS, &info, current);
 	if (!user_mode(regs))
 		bad_page_fault(regs, address, SIGBUS);
+	TRACE_TRAP_EXIT();
 }
 
 /*
diff -urN linux-2.5.15/arch/s390/config.in linux-2.5.15-ltt/arch/s390/config.in
--- linux-2.5.15/arch/s390/config.in	Thu May  9 18:22:54 2002
+++ linux-2.5.15-ltt/arch/s390/config.in	Fri May 10 12:42:52 2002
@@ -47,6 +47,8 @@
 
 source fs/Config.in
 
+source drivers/trace/Config.in
+
 mainmenu_option next_comment
 comment 'Kernel hacking'
 
diff -urN linux-2.5.15/arch/s390/kernel/entry.S linux-2.5.15-ltt/arch/s390/kernel/entry.S
--- linux-2.5.15/arch/s390/kernel/entry.S	Thu May  9 18:22:37 2002
+++ linux-2.5.15-ltt/arch/s390/kernel/entry.S	Fri May 10 12:42:52 2002
@@ -7,6 +7,7 @@
  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  *               Hartmut Penner (hp@de.ibm.com),
  *               Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
+ *  Portions added by T. Halloran: (C) Copyright 2002 IBM Poughkeepsie, IBM Corporation
  */
 
 #include <linux/sys.h>
@@ -216,6 +217,14 @@
         slr     %r8,%r8           # gpr 8 is call save (-> tracesys)
         ic      %r8,0x8B          # get svc number from lowcore
         stosm   24(%r15),0x03     # reenable interrupts
+/* call to ltt trace done here.  R8 has the syscall (svc) number to trace */
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE) /* tjh - ltt port */              
+        /* add call to trace_real_syscall_entry */                          
+        la      %r2,SP_PTREGS(%r15)   # load pt_regs as first parameter     
+        l       %r1,BASED(.Ltracesysent)                                    
+        basr    %r14,%r1                                                    
+        lm      %r0,%r6,SP_R0(%r15) /* restore call clobbered regs tjh */   
+#endif
         sll     %r8,2
         l       %r8,sys_call_table-entry_base(8,%r13) # get address of system call
 #error        tm      tsk_ptrace+3(%r9),0x02 # PT_TRACESYS
@@ -225,6 +234,13 @@
                                   # ATTENTION: check sys_execve_glue before
                                   # changing anything here !!
 
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE) /* tjh - ltt port *            
+        /* add call to trace_real_syscall_exit */ 
+        la      %r2,SP_PTREGS(%r15)   # load pt_regs as first parameter  
+        l       %r1,BASED(.Ltracesysext)                                 
+        basr    %r14,%r1                                                 
+        lm      %r0,%r6,SP_R0(%r15) /* restore call clobbered regs */
+#endif                                                                   
 sysc_return:
         tm      SP_PSW+1(%r15),0x01 # returning to user ?
         bno     BASED(sysc_leave) # no-> skip resched & signal
@@ -895,6 +911,8 @@
 .Lsigaltstack: .long  sys_sigaltstack
 #error .Ltrace:       .long  syscall_trace
 .Lvfork:       .long  sys_vfork
+.Ltracesysent: .long  trace_real_syscall_entry
+.Ltracesysext: .long  trace_real_syscall_exit 
 
 #if CONFIG_SMP || CONFIG_PREEMPT
 .Lschedtail:   .long  schedule_tail
diff -urN linux-2.5.15/arch/s390/kernel/process.c linux-2.5.15-ltt/arch/s390/kernel/process.c
--- linux-2.5.15/arch/s390/kernel/process.c	Thu May  9 18:25:27 2002
+++ linux-2.5.15-ltt/arch/s390/kernel/process.c	Fri May 10 12:42:52 2002
@@ -36,6 +36,7 @@
 #include <linux/delay.h>
 #include <linux/reboot.h>
 #include <linux/init.h>
+#include <linux/trace.h>
 
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -265,6 +266,10 @@
                 : "d" (clone_arg), "i" (__NR_clone), "i" (__NR_exit),
                   "d" (arg), "d" (fn), "i" (__LC_KERNEL_STACK) , "i" (-STACK_FRAME_OVERHEAD)
                 : "2", "3", "4" );
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)                           
+        if (retval > 0)                                             
+          TRACE_PROCESS(TRACE_EV_PROCESS_KTHREAD, retval, (int) fn);
+#endif
         return retval;
 }
 
diff -urN linux-2.5.15/arch/s390/kernel/sys_s390.c linux-2.5.15-ltt/arch/s390/kernel/sys_s390.c
--- linux-2.5.15/arch/s390/kernel/sys_s390.c	Thu May  9 18:23:58 2002
+++ linux-2.5.15-ltt/arch/s390/kernel/sys_s390.c	Fri May 10 12:42:52 2002
@@ -24,6 +24,7 @@
 #include <linux/mman.h>
 #include <linux/file.h>
 #include <linux/utsname.h>
+#include <linux/trace.h>
 
 #include <asm/uaccess.h>
 #include <asm/ipc.h>
@@ -144,6 +145,8 @@
 {
         struct ipc_kludge tmp;
 	int ret;
+
+        TRACE_IPC(TRACE_EV_IPC_CALL, call, first);
 
         switch (call) {
         case SEMOP:
diff -urN linux-2.5.15/arch/s390/kernel/traps.c linux-2.5.15-ltt/arch/s390/kernel/traps.c
--- linux-2.5.15/arch/s390/kernel/traps.c	Thu May  9 18:23:33 2002
+++ linux-2.5.15-ltt/arch/s390/kernel/traps.c	Fri May 10 12:42:53 2002
@@ -5,6 +5,7 @@
  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  *               Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
+ *  Portions added by T. Halloran: (C) Copyright 2002 IBM Poughkeepsie, IBM Corporation
  *
  *  Derived from "arch/i386/kernel/traps.c"
  *    Copyright (C) 1991, 1992 Linus Torvalds
@@ -26,6 +27,7 @@
 #include <linux/smp_lock.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/trace.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -94,12 +96,18 @@
 static void inline do_trap(long interruption_code, int signr, char *str,
                            struct pt_regs *regs, siginfo_t *info)
 {
+        trapid_t ltt_interruption_code; 
+        char * ic_ptr = (char *) &ltt_interruption_code;
+
 	/*
 	 * We got all needed information from the lowcore and can
 	 * now safely switch on interrupts.
 	 */
         if (regs->psw.mask & PSW_PROBLEM_STATE)
 		__sti();
+        memset(&ltt_interruption_code,0,sizeof(ltt_interruption_code));
+        memcpy(ic_ptr+4,&interruption_code,sizeof(interruption_code));
+        TRACE_TRAP_ENTRY(ltt_interruption_code, (regs->psw.addr & PSW_ADDR_MASK));
 
         if (regs->psw.mask & PSW_PROBLEM_STATE) {
                 struct task_struct *tsk = current;
@@ -129,6 +137,7 @@
                 else
                         die(str, regs, interruption_code);
         }
+	TRACE_TRAP_EXIT();
 }
 
 int do_debugger_trap(struct pt_regs *regs,int signal)
@@ -167,6 +176,8 @@
 {
         __u8 opcode[6];
 	__u16 *location;
+        trapid_t ltt_interruption_code;
+        char * ic_ptr = (char *) &ltt_interruption_code;
 	int signal = 0;
 
 	location = (__u16 *)(regs->psw.addr-S390_lowcore.pgm_ilc);
@@ -177,6 +188,9 @@
 	 */
 	if (regs->psw.mask & PSW_PROBLEM_STATE)
 		__sti();
+        memset(&ltt_interruption_code,0,sizeof(ltt_interruption_code));
+        memcpy(ic_ptr+4,&interruption_code,sizeof(interruption_code));
+        TRACE_TRAP_ENTRY(ltt_interruption_code, (regs->psw.addr & PSW_ADDR_MASK));
 
 	if (regs->psw.mask & PSW_PROBLEM_STATE)
 		get_user(*((__u16 *) opcode), location);
@@ -219,6 +233,7 @@
         } else if (signal)
 		do_trap(interruption_code, signal,
 			"illegal operation", regs, NULL);
+        TRACE_TRAP_EXIT();
 }
 
 
@@ -229,6 +244,8 @@
 {
         __u8 opcode[6];
 	__u16 *location = NULL;
+        trapid_t ltt_interruption_code;
+        char * ic_ptr = (char *) &ltt_interruption_code;
 	int signal = 0;
 
 	location = (__u16 *)(regs->psw.addr-S390_lowcore.pgm_ilc);
@@ -239,6 +256,9 @@
 	 */
 	if (regs->psw.mask & PSW_PROBLEM_STATE)
 		__sti();
+        memset(&ltt_interruption_code,0,sizeof(ltt_interruption_code));
+        memcpy(ic_ptr+4,&interruption_code,sizeof(interruption_code));
+        TRACE_TRAP_ENTRY(ltt_interruption_code, (regs->psw.addr & PSW_ADDR_MASK));
 		
         if (regs->psw.mask & PSW_PROBLEM_STATE) {
 		get_user(*((__u16 *) opcode), location);
@@ -278,6 +298,7 @@
         } else if (signal)
                 do_trap(interruption_code, signal,
 			"specification exception", regs, NULL);
+        TRACE_TRAP_EXIT();
 }
 #else
 DO_ERROR(SIGILL, "specification exception", specification_exception)
@@ -287,6 +308,8 @@
 {
         __u8 opcode[6];
 	__u16 *location;
+        trapid_t ltt_interruption_code;
+        char * ic_ptr = (char *) &ltt_interruption_code;
 	int signal = 0;
 
 	location = (__u16 *)(regs->psw.addr-S390_lowcore.pgm_ilc);
@@ -297,6 +320,9 @@
 	 */
 	if (regs->psw.mask & PSW_PROBLEM_STATE)
 		__sti();
+        memset(&ltt_interruption_code,0,sizeof(ltt_interruption_code));
+        memcpy(ic_ptr+4,&interruption_code,sizeof(interruption_code));
+        TRACE_TRAP_ENTRY(ltt_interruption_code, (regs->psw.addr & PSW_ADDR_MASK));
 
 	if (MACHINE_HAS_IEEE)
 		__asm__ volatile ("stfpc %0\n\t" 
@@ -367,6 +393,7 @@
 	} else if (signal) 
                 do_trap(interruption_code, signal,
 			"data exception", regs, NULL);
+        TRACE_TRAP_EXIT();
 }
 
 
@@ -419,6 +446,11 @@
 
 void handle_per_exception(struct pt_regs *regs)
 {
+        trapid_t ltt_interruption_code;
+        char * ic_ptr = (char *) &ltt_interruption_code;
+        memset(&ltt_interruption_code,0,sizeof(ltt_interruption_code));
+        memcpy(ic_ptr+6,&S390_lowcore.pgm_code,2); /* copy the interrupt code */
+        TRACE_TRAP_ENTRY(ltt_interruption_code,(regs->psw.addr & PSW_ADDR_MASK));
 	if(regs->psw.mask&PSW_PROBLEM_STATE)
 	{
 		per_struct *per_info=&current->thread.per_info;
@@ -435,5 +467,91 @@
 		/* Hopefully switching off per tracing will help us survive */
 		regs->psw.mask &= ~PSW_PER_MASK;
 	}
+        TRACE_TRAP_EXIT();
 }
 
+/* ltt - Trace related code  */                                
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)                      
+asmlinkage void trace_real_syscall_entry(struct pt_regs * regs)
+{                                                              
+        int                 use_depth;                         
+        int                 use_bounds;                        
+        int                 depth = 0;                         
+        int                 seek_depth;                        
+        unsigned long       lower_bound;                       
+        unsigned long       upper_bound;                       
+        unsigned long       addr;                              
+        unsigned long*      stack;
+        unsigned long       temp_stack;
+        trace_syscall_entry trace_syscall_event;               
+        /* Set the syscall ID                               */ 
+        /* Register 8 is setup just prior to the call       */ 
+        /* This instruction is just following linkage       */ 
+        /* so it's ok.  If moved and chance of R8 being     */ 
+        /* clobbered, would need to dig it out of the stack */ 
+        __asm__ volatile(                                      
+        "  stc  8,%0\n\t"                                      
+        : "=m" (trace_syscall_event.syscall_id));              
+        /* get the psw address */                              
+        trace_syscall_event.address  = regs->psw.addr;         
+        /* and off the hi-order bit */                                          
+        trace_syscall_event.address &= PSW_ADDR_MASK;                           
+        if(!(user_mode(regs))) /* if kernel mode, return */                     
+           goto trace_syscall_end;                                              
+        /* Get the trace configuration - if none, return */                     
+        if(trace_get_config(&use_depth,                                         
+                            &use_bounds,                                        
+                            &seek_depth,                                        
+                            (void*)&lower_bound,                                
+                            (void*)&upper_bound) < 0)                           
+          goto trace_syscall_end;                                               
+        /* Do we have to search for an instruction pointer address range */     
+        if((use_depth == 1) || (use_bounds == 1))                               
+        {                                                                       
+          /* Start at the top of the stack */                                   
+          /* stack pointer is register 15 */                                    
+          stack = (unsigned long*) regs->gprs[15]; /* stack pointer */      
+          /* Keep on going until we reach the end of the process' stack limit */
+          do
+          {
+            get_user(addr,stack+14);  /* get the program address +0x38 */ 
+            /* and off the hi-order bit */
+            addr &= PSW_ADDR_MASK;                                
+            /* Does this LOOK LIKE an address in the program */
+            if ((addr > current->mm->start_code)               
+               &&(addr < current->mm->end_code))               
+            { 
+              /* Does this address fit the description */      
+              if(((use_depth == 1) && (depth == seek_depth))   
+                ||((use_bounds == 1) && (addr > lower_bound)   
+                && (addr < upper_bound)))
+                {
+                  /* Set the address */   
+                  trace_syscall_event.address = addr; 
+                  /* We're done */                             
+                  goto trace_syscall_end;                      
+                }                                              
+              else                                             
+                /* We're one depth more */                     
+                depth++; 
+            }
+            /* Go on to the next address */
+            get_user(temp_stack,stack); /* get contents of stack */
+            temp_stack &= PSW_ADDR_MASK; /* and off hi order bit */
+            stack = (unsigned long *)temp_stack; /* move into stack */
+            /* stack may or may not go to zero when end hit               */
+            /* using 0x7fffffff-_STK_LIM to validate that the address is  */
+            /* within the range of a valid stack address                  */
+            /* If outside that range, exit the loop, stack end must have  */
+            /* been hit.                                                  */
+          } while (stack >= (unsigned long *)(0x7fffffff-_STK_LIM));
+        }                                                         
+trace_syscall_end:                                                
+        /* Trace the event */                                     
+        trace_event(TRACE_EV_SYSCALL_ENTRY, &trace_syscall_event);
+}                                                                 
+asmlinkage void trace_real_syscall_exit(void)                     
+{                                                                 
+  trace_event(TRACE_EV_SYSCALL_EXIT, NULL);                       
+}                                                                 
+#endif /* (CONFIG_TRACE || CONFIG_TRACE_MODULE) */                
diff -urN linux-2.5.15/arch/s390/mm/fault.c linux-2.5.15-ltt/arch/s390/mm/fault.c
--- linux-2.5.15/arch/s390/mm/fault.c	Thu May  9 18:25:28 2002
+++ linux-2.5.15-ltt/arch/s390/mm/fault.c	Fri May 10 12:42:53 2002
@@ -5,6 +5,7 @@
  *    Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
  *    Author(s): Hartmut Penner (hp@de.ibm.com)
  *               Ulrich Weigand (uweigand@de.ibm.com)
+ *  Portions added by T. Halloran: (C) Copyright 2002 IBM Poughkeepsie, IBM Corporation
  *
  *  Derived from "arch/i386/mm/fault.c"
  *    Copyright (C) 1995  Linus Torvalds
@@ -25,6 +26,7 @@
 #include <linux/compatmac.h>
 #include <linux/init.h>
 #include <linux/console.h>
+#include <linux/trace.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -85,6 +87,8 @@
         int write;
 	int si_code = SEGV_MAPERR;
 	int kernel_address = 0;
+        trapid_t ltt_interruption_code;                 
+        char * ic_ptr = (char *) &ltt_interruption_code; 
 
         tsk = current;
         mm = tsk->mm;
@@ -170,6 +174,9 @@
 
 	__sti();
 
+        memset(&ltt_interruption_code,0,sizeof(ltt_interruption_code));
+        memcpy(ic_ptr+4,&error_code,sizeof(error_code));
+        TRACE_TRAP_ENTRY(ltt_interruption_code,(regs->psw.addr & PSW_ADDR_MASK));
         down_read(&mm->mmap_sem);
 
         vma = find_vma(mm, address);
@@ -223,6 +230,7 @@
 	}
 
         up_read(&mm->mmap_sem);
+        TRACE_TRAP_EXIT();
         return;
 
 /*
@@ -252,6 +260,7 @@
 #endif
 
 		force_sigsegv(tsk, si_code, (void *)address);
+                TRACE_TRAP_EXIT();
                 return;
 	}
 
@@ -259,6 +268,7 @@
         /* Are we prepared to handle this kernel fault?  */
         if ((fixup = search_exception_table(regs->psw.addr)) != 0) {
                 regs->psw.addr = fixup;
+                TRACE_TRAP_EXIT();
                 return;
         }
 
@@ -309,6 +319,8 @@
 	/* Kernel mode? Handle exceptions or die */
 	if (!(regs->psw.mask & PSW_PROBLEM_STATE))
 		goto no_context;
+
+	TRACE_TRAP_EXIT();
 }
 
 /*
diff -urN linux-2.5.15/arch/sh/config.in linux-2.5.15-ltt/arch/sh/config.in
--- linux-2.5.15/arch/sh/config.in	Thu May  9 18:24:45 2002
+++ linux-2.5.15-ltt/arch/sh/config.in	Fri May 10 12:42:53 2002
@@ -367,6 +367,9 @@
 if [ "$CONFIG_SH_STANDARD_BIOS" = "y" ]; then
    bool 'Early printk support' CONFIG_SH_EARLY_PRINTK
 fi
+
+source drivers/trace/Config.in
+
 endmenu
 
 source lib/Config.in
diff -urN linux-2.5.15/arch/sh/kernel/entry.S linux-2.5.15-ltt/arch/sh/kernel/entry.S
--- linux-2.5.15/arch/sh/kernel/entry.S	Thu May  9 18:23:52 2002
+++ linux-2.5.15-ltt/arch/sh/kernel/entry.S	Fri May 10 13:21:27 2002
@@ -370,6 +370,20 @@
 	mov.l	r10, @r14		! set syscall_nr
 	STI()
 	!
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+	! TODO: for i386 this code only happens when not ptrace'd
+	mov 	r15, r4     	    	! pass pt_regs* as first arg
+	mov.l	__trsen, r11 	    	! Call trace_real_syscall_entry()
+	jsr	@r11	    	    	! (will chomp R[0-7])
+	 nop
+	!   	    	    	    	Reload R4-R7 from kernel stack
+	mov.l	@(OFF_R4,r15), r4   ! arg0
+	mov.l	@(OFF_R5,r15), r5
+	mov.l	@(OFF_R6,r15), r6
+	mov.l	@(OFF_R7,r15), r7   ! arg3
+	mov.l	@(OFF_R3,r15), r3   ! syscall_nr
+#endif
+
 	stc	k_current, r11
 #error	mov.l	@(tsk_ptrace,r11), r10	! Is current PTRACE_SYSCALL'd?
 #error	mov	#PT_TRACESYS, r11
@@ -421,6 +435,14 @@
 	! In case of trace
 syscall_ret_trace:
 	mov.l	r0, @(OFF_R0,r15)		! save the return value
+
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+    	! TODO: for i386 this code only happens when not ptrace'd
+	mov.l	__trsex, r1 	    	! Call trace_real_syscall_exit()
+	jsr	@r1
+	 nop
+#endif
+
 	mov.l	__syscall_trace, r1
 	mova	ret_from_syscall, r0
 	jmp	@r1    	! Call syscall_trace() which notifies superior
@@ -504,6 +526,14 @@
 	.long	syscall_ret_trace
 __syscall_ret:
 	.long	syscall_ret
+	
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+__trsen:
+	.long	trace_real_syscall_entry
+__trsex:
+	.long	trace_real_syscall_exit
+#endif
+
 __INV_IMASK:
 	.long	0xffffff0f	! ~(IMASK)
 
@@ -536,6 +566,14 @@
 #endif
 syscall_ret:
 	mov.l	r0, @(OFF_R0,r15)	! save the return value
+
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+	! TODO: for i386 this code only happens when not ptrace'd
+	mov.l	__trsex2, r1 	    	! Call trace_real_syscall_exit()
+	jsr	@r1
+	 nop
+#endif
+
 	/* fall through */
 
 ENTRY(ret_from_syscall)
@@ -563,6 +601,11 @@
 #error	.long	do_signal
 __irq_stat:
 	.long	irq_stat
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+__trsex2:
+ 	.long	trace_real_syscall_exit
+#endif
+
 
 	.align 2
 restore_all:
diff -urN linux-2.5.15/arch/sh/kernel/irq.c linux-2.5.15-ltt/arch/sh/kernel/irq.c
--- linux-2.5.15/arch/sh/kernel/irq.c	Thu May  9 18:23:35 2002
+++ linux-2.5.15-ltt/arch/sh/kernel/irq.c	Fri May 10 12:42:53 2002
@@ -30,6 +30,8 @@
 #include <linux/init.h>
 #include <linux/seq_file.h>
 
+#include <linux/trace.h>
+
 #include <asm/system.h>
 #include <asm/io.h>
 #include <asm/bitops.h>
@@ -127,6 +129,12 @@
 
 	irq_enter(cpu, irq);
 
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+    	if (irq != TIMER_IRQ) { /* avoid double-reporting the timer IRQ */
+		TRACE_IRQ_ENTRY(irq, !(user_mode(regs)));
+	}
+#endif
+
 	status = 1;	/* Force the "do bottom halves" bit */
 
 	if (!(action->flags & SA_INTERRUPT))
@@ -142,6 +150,12 @@
 	__cli();
 
 	irq_exit(cpu, irq);
+
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+    	if (irq != TIMER_IRQ) { /* avoid double-reporting the timer IRQ */
+		TRACE_IRQ_EXIT();
+	}
+#endif
 
 	return status;
 }
diff -urN linux-2.5.15/arch/sh/kernel/process.c linux-2.5.15-ltt/arch/sh/kernel/process.c
--- linux-2.5.15/arch/sh/kernel/process.c	Thu May  9 18:25:22 2002
+++ linux-2.5.15-ltt/arch/sh/kernel/process.c	Fri May 10 12:42:53 2002
@@ -16,6 +16,8 @@
 #include <linux/slab.h>
 #include <linux/a.out.h>
 
+#include <linux/trace.h>
+
 #include <asm/io.h>
 #include <asm/uaccess.h>
 #include <asm/mmu_context.h>
@@ -138,7 +140,16 @@
 		: "i" (__NR_exit), "r" (__sc3), "r" (__sc4), "r" (__sc5), 
 		  "r" (__sc8), "r" (__sc9)
 		: "memory", "t");
-	return __sc0;
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+	{
+		volatile unsigned long retval = __sc0;
+		if (retval > 0)
+			TRACE_PROCESS(TRACE_EV_PROCESS_KTHREAD, retval, (int) fn);
+		return retval;
+	}
+#else
+ 	return __sc0;
+#endif
 }
 
 /*
diff -urN linux-2.5.15/arch/sh/kernel/sys_sh.c linux-2.5.15-ltt/arch/sh/kernel/sys_sh.c
--- linux-2.5.15/arch/sh/kernel/sys_sh.c	Thu May  9 18:24:47 2002
+++ linux-2.5.15-ltt/arch/sh/kernel/sys_sh.c	Fri May 10 12:42:53 2002
@@ -21,6 +21,8 @@
 #include <linux/file.h>
 #include <linux/utsname.h>
 
+#include <linux/trace.h>
+
 #include <asm/uaccess.h>
 #include <asm/ipc.h>
 
@@ -138,6 +140,8 @@
 
 	version = call >> 16; /* hack for backward compatibility */
 	call &= 0xffff;
+
+	TRACE_IPC(TRACE_EV_IPC_CALL, call, first);
 
 	if (call <= SEMCTL)
 		switch (call) {
diff -urN linux-2.5.15/arch/sh/kernel/traps.c linux-2.5.15-ltt/arch/sh/kernel/traps.c
--- linux-2.5.15/arch/sh/kernel/traps.c	Thu May  9 18:21:41 2002
+++ linux-2.5.15-ltt/arch/sh/kernel/traps.c	Fri May 10 12:42:53 2002
@@ -25,6 +25,8 @@
 #include <linux/delay.h>
 #include <linux/spinlock.h>
 
+#include <linux/trace.h>
+
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -42,7 +44,9 @@
 	sti(); \
 	tsk->thread.error_code = error_code; \
 	tsk->thread.trap_no = trapnr; \
+	TRACE_TRAP_ENTRY(trapnr, regs.pc); \
 	force_sig(signr, tsk); \
+	TRACE_TRAP_EXIT(); \
 	die_if_no_fixup(str,&regs,error_code); \
 }
 
@@ -464,6 +468,8 @@
 
 	asm volatile("stc       r2_bank,%0": "=r" (error_code));
 
+	TRACE_TRAP_ENTRY(error_code >> 5, regs->pc);
+
 	oldfs = get_fs();
 
 	if (user_mode(regs)) {
@@ -487,8 +493,10 @@
 		tmp = handle_unaligned_access(instruction, regs);
 		set_fs(oldfs);
 
-		if (tmp==0)
-			return; /* sorted */
+		if (tmp==0) {
+			TRACE_TRAP_EXIT();
+ 			return; /* sorted */
+		}
 
 	uspace_segv:
 		printk(KERN_NOTICE "Killing process \"%s\" due to unaligned access\n", current->comm);
@@ -509,6 +517,7 @@
 		handle_unaligned_access(instruction, regs);
 		set_fs(oldfs);
 	}
+	TRACE_TRAP_EXIT();
 }
 
 DO_ERROR(12, SIGILL,  "reserved instruction", reserved_inst, current)
@@ -586,3 +595,78 @@
 {
 	printk("Backtrace not yet implemented for SH.\n");
 }
+
+/* Trace related code */
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+asmlinkage void trace_real_syscall_entry(struct pt_regs * regs)
+{
+	int                 use_depth;
+	int                 use_bounds;
+	int                 depth = 0;
+	int                 seek_depth;
+	unsigned long       lower_bound;
+	unsigned long       upper_bound;
+	unsigned long       addr;
+	unsigned long*      stack;
+	trace_syscall_entry trace_syscall_event;
+
+	/* Set the syscall ID */
+	trace_syscall_event.syscall_id = (uint8_t) regs->regs[REG_REG0+3];
+
+	/* Set the address in any case */
+	trace_syscall_event.address  = regs->pc;
+
+	/* Are we in the kernel (This is a kernel thread)? */
+	if(!user_mode(regs))
+		/* Don't go digining anywhere */
+		goto trace_syscall_end;
+
+	/* Get the trace configuration */
+	if(trace_get_config(&use_depth, &use_bounds, &seek_depth,
+	   (void*)&lower_bound, (void*)&upper_bound) < 0)
+		goto trace_syscall_end;
+
+	/* Do we have to search for an eip address range */
+	if((use_depth == 1) || (use_bounds == 1))
+	{
+		/* Start at the top of the stack (bottom address since stacks grow downward) */
+		stack = (unsigned long*) regs->regs[REG_REG15];
+
+		/* Keep on going until we reach the end of the process' stack limit (wherever it may be) */
+		while(!get_user(addr, stack))
+		{
+			/* Does this LOOK LIKE an address in the program */
+			/* TODO: does this work with shared libraries?? - Greg Banks */
+			if((addr > current->mm->start_code) &&(addr < current->mm->end_code))
+			{
+				/* Does this address fit the description */
+				if(((use_depth == 1) && (depth == seek_depth))
+				   ||((use_bounds == 1) && (addr > lower_bound)
+				   && (addr < upper_bound)))
+				{
+					/* Set the address */
+					trace_syscall_event.address = addr;
+
+					/* We're done */
+					goto trace_syscall_end;
+				}
+				else
+					/* We're one depth more */
+					depth++;
+			}
+			/* Go on to the next address */
+			stack++;
+		}
+	}
+
+trace_syscall_end:
+	/* Trace the event */
+	trace_event(TRACE_EV_SYSCALL_ENTRY, &trace_syscall_event);
+}
+
+asmlinkage void trace_real_syscall_exit(void)
+{
+	trace_event(TRACE_EV_SYSCALL_EXIT, NULL);
+}
+#endif /* (CONFIG_TRACE || CONFIG_TRACE_MODULE) */
+
diff -urN linux-2.5.15/arch/sh/lib/checksum.S linux-2.5.15-ltt/arch/sh/lib/checksum.S
--- linux-2.5.15/arch/sh/lib/checksum.S	Thu May  9 18:21:44 2002
+++ linux-2.5.15-ltt/arch/sh/lib/checksum.S	Fri May 10 12:42:53 2002
@@ -172,7 +172,6 @@
 	.long 9999b, 6002f	;	\
 	.previous
 
-!
 ! r4:	const char *SRC
 ! r5:	char *DST
 ! r6:	int LEN
diff -urN linux-2.5.15/arch/sh/mm/fault.c linux-2.5.15-ltt/arch/sh/mm/fault.c
--- linux-2.5.15/arch/sh/mm/fault.c	Thu May  9 18:23:06 2002
+++ linux-2.5.15-ltt/arch/sh/mm/fault.c	Fri May 10 12:42:53 2002
@@ -20,6 +20,8 @@
 #include <linux/smp_lock.h>
 #include <linux/interrupt.h>
 
+#include <linux/trace.h>
+
 #include <asm/system.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
@@ -98,6 +100,14 @@
 	tsk = current;
 	mm = tsk->mm;
 
+#if (CONFIG_TRACE || CONFIG_TRACE_MODULE)
+	{
+		unsigned long trapnr;
+		asm volatile("stc       r2_bank,%0": "=r" (trapnr));
+		TRACE_TRAP_ENTRY(trapnr >> 5, regs->pc);  /* trap 4,5 or 6 */
+	}
+#endif
+
 	/*
 	 * If we're in an interrupt or have no user
 	 * context, we must not take the fault..
@@ -149,6 +159,7 @@
 	}
 
 	up_read(&mm->mmap_sem);
+	TRACE_TRAP_EXIT();
 	return;
 
 /*
@@ -162,6 +173,7 @@
 		tsk->thread.address = address;
 		tsk->thread.error_code = writeaccess;
 		force_sig(SIGSEGV, tsk);
+		TRACE_TRAP_EXIT();
 		return;
 	}
 
@@ -170,6 +182,7 @@
 	fixup = search_exception_table(regs->pc);
 	if (fixup != 0) {
 		regs->pc = fixup;
+		TRACE_TRAP_EXIT();
 		return;
 	}
 
@@ -231,6 +244,8 @@
 	/* Kernel mode? Handle exceptions or die */
 	if (!user_mode(regs))
 		goto no_context;
+
+	TRACE_TRAP_EXIT();
 }
 
 /*
diff -urN linux-2.5.15/drivers/s390/s390io.c linux-2.5.15-ltt/drivers/s390/s390io.c
--- linux-2.5.15/drivers/s390/s390io.c	Thu May  9 18:22:50 2002
+++ linux-2.5.15-ltt/drivers/s390/s390io.c	Fri May 10 12:42:53 2002
@@ -41,6 +41,7 @@
 #include <linux/smp_lock.h>
 #include <linux/init.h>
 #include <linux/bootmem.h>
+#include <linux/trace.h>
 #ifdef CONFIG_PROC_FS
 #include <linux/proc_fs.h>
 #endif 
@@ -2497,9 +2498,11 @@
 			}
 	
 			irq_enter(cpu, irq);
+                        TRACE_IRQ_ENTRY(irq, !(((regs).psw.mask&PSW_PROBLEM_STATE) != 0));
 			s390irq_spin_lock( irq );
 			s390_process_IRQ( irq );
 			s390irq_spin_unlock( irq );
+                        TRACE_IRQ_EXIT();
 			irq_exit(cpu, irq);
 		}
 
diff -urN linux-2.5.15/drivers/s390/s390mach.c linux-2.5.15-ltt/drivers/s390/s390mach.c
--- linux-2.5.15/drivers/s390/s390mach.c	Thu May  9 18:24:18 2002
+++ linux-2.5.15-ltt/drivers/s390/s390mach.c	Fri May 10 12:42:53 2002
@@ -6,12 +6,14 @@
  *  S390 version
  *    Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  *    Author(s): Ingo Adlung (adlung@de.ibm.com)
+ *  Portions added by T. Halloran: (C) Copyright 2002 IBM Poughkeepsie, IBM Corporation
  */
 
 #include <linux/config.h>
 #include <linux/spinlock.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/trace.h>
 #ifdef CONFIG_SMP
 #include <linux/smp.h>
 #endif
@@ -133,6 +135,8 @@
 {
 	int      crw_count;
 	mcic_t   mcic;
+        trapid_t ltt_interruption_code;
+        uint32_t ltt_old_psw;
 
 #ifdef S390_MACHCHK_DEBUG
 	printk( "s390_do_machine_check : starting ...\n");
@@ -141,6 +145,14 @@
 	memcpy( &mcic,
 	        &S390_lowcore.mcck_interruption_code,
 	        sizeof(__u64));
+	memcpy( &ltt_interruption_code,
+	        &S390_lowcore.mcck_interruption_code,
+	        sizeof(__u64));
+	memcpy( &ltt_old_psw,
+	        &S390_lowcore.mcck_old_psw,
+	        sizeof(uint32_t));
+        ltt_old_psw &=  PSW_ADDR_MASK;
+        TRACE_TRAP_ENTRY(ltt_interruption_code,ltt_old_psw);
  		
 	if ( mcic.mcc.mcd.cp )	// CRW pending ?
 	{
diff -urN linux-2.5.15/include/asm-i386/trace.h linux-2.5.15-ltt/include/asm-i386/trace.h
--- linux-2.5.15/include/asm-i386/trace.h	Wed Dec 31 19:00:00 1969
+++ linux-2.5.15-ltt/include/asm-i386/trace.h	Fri May 10 15:31:26 2002
@@ -0,0 +1,15 @@
+/*
+ * linux/include/asm-i386/trace.h
+ *
+ * Copyright (C) 2002, Karim Yaghmour
+ *
+ * i386 definitions for tracing system
+ */
+
+#include <linux/trace.h>
+
+/* Current arch type */
+#define TRACE_ARCH_TYPE TRACE_ARCH_TYPE_I386
+
+/* Current variant type */
+#define TRACE_ARCH_VARIANT TRACE_ARCH_VARIANT_NONE
diff -urN linux-2.5.15/include/asm-mips/trace.h linux-2.5.15-ltt/include/asm-mips/trace.h
--- linux-2.5.15/include/asm-mips/trace.h	Wed Dec 31 19:00:00 1969
+++ linux-2.5.15-ltt/include/asm-mips/trace.h	Fri May 10 15:31:18 2002
@@ -0,0 +1,15 @@
+/*
+ * linux/include/asm-mips/trace.h
+ *
+ * Copyright (C) 2002, Karim Yaghmour
+ *
+ * MIPS definitions for tracing system
+ */
+
+#include <linux/trace.h>
+
+/* Current arch type */
+#define TRACE_ARCH_TYPE TRACE_ARCH_TYPE_MIPS
+
+/* Current variant type */
+#define TRACE_ARCH_VARIANT TRACE_ARCH_VARIANT_NONE
diff -urN linux-2.5.15/include/asm-ppc/trace.h linux-2.5.15-ltt/include/asm-ppc/trace.h
--- linux-2.5.15/include/asm-ppc/trace.h	Wed Dec 31 19:00:00 1969
+++ linux-2.5.15-ltt/include/asm-ppc/trace.h	Fri May 10 15:31:09 2002
@@ -0,0 +1,30 @@
+/*
+ * linux/include/asm-ppc/trace.h
+ *
+ * Copyright (C) 2002, Karim Yaghmour
+ *
+ * PowerPC definitions for tracing system
+ */
+
+#include <linux/config.h>
+#include <linux/trace.h>
+
+/* Current arch type */
+#define TRACE_ARCH_TYPE TRACE_ARCH_TYPE_PPC
+
+/* PowerPC variants */
+#define TRACE_ARCH_VARIANT_PPC_4xx          1   /* 4xx systems (IBM embedded series) */
+#define TRACE_ARCH_VARIANT_PPC_6xx          2   /* 6xx/7xx/74xx/8260/POWER3 systems (desktop flavor) */
+#define TRACE_ARCH_VARIANT_PPC_8xx          3   /* 8xx system (Motoral embedded series) */
+#define TRACE_ARCH_VARIANT_PPC_ISERIES      4   /* 8xx system (iSeries) */
+
+/* Current variant type */
+#if defined(CONFIG_4xx)
+#define TRACE_ARCH_VARIANT TRACE_ARCH_VARIANT_PPC_4xx
+#elif defined(CONFIG_6xx)
+#define TRACE_ARCH_VARIANT TRACE_ARCH_VARIANT_PPC_6xx
+#elif defined(CONFIG_8xx)
+#define TRACE_ARCH_VARIANT TRACE_ARCH_VARIANT_PPC_8xx
+#elif defined(CONFIG_PPC_ISERIES)
+#define TRACE_ARCH_VARIANT TRACE_ARCH_VARIANT_PPC_ISERIES
+#endif
diff -urN linux-2.5.15/include/asm-s390/trace.h linux-2.5.15-ltt/include/asm-s390/trace.h
--- linux-2.5.15/include/asm-s390/trace.h	Wed Dec 31 19:00:00 1969
+++ linux-2.5.15-ltt/include/asm-s390/trace.h	Fri May 10 15:30:41 2002
@@ -0,0 +1,15 @@
+/*
+ * linux/include/asm-s390/trace.h
+ *
+ * Copyright (C) 2002, Karim Yaghmour
+ *
+ * S/390 definitions for tracing system
+ */
+
+#include <linux/trace.h>
+
+/* Current arch type */
+#define TRACE_ARCH_TYPE TRACE_ARCH_TYPE_S390
+
+/* Current variant type */
+#define TRACE_ARCH_VARIANT TRACE_ARCH_VARIANT_NONE
diff -urN linux-2.5.15/include/asm-sh/trace.h linux-2.5.15-ltt/include/asm-sh/trace.h
--- linux-2.5.15/include/asm-sh/trace.h	Wed Dec 31 19:00:00 1969
+++ linux-2.5.15-ltt/include/asm-sh/trace.h	Fri May 10 15:30:58 2002
@@ -0,0 +1,15 @@
+/*
+ * linux/include/asm-sh/trace.h
+ *
+ * Copyright (C) 2002, Karim Yaghmour
+ *
+ * SuperH definitions for tracing system
+ */
+
+#include <linux/trace.h>
+
+/* Current arch type */
+#define TRACE_ARCH_TYPE TRACE_ARCH_TYPE_SH
+
+/* Current variant type */
+#define TRACE_ARCH_VARIANT TRACE_ARCH_VARIANT_NONE
