diff -urN linux_lttng/arch/x86_64/ia32/ipc32.c linux_lttng_working_clean/arch/x86_64/ia32/ipc32.c
--- linux_lttng/arch/x86_64/ia32/ipc32.c	2005-11-25 15:23:49.000000000 -0500
+++ linux_lttng_working_clean/arch/x86_64/ia32/ipc32.c	2005-12-01 09:52:27.000000000 -0500
@@ -8,6 +8,7 @@
 #include <linux/shm.h>
 #include <linux/ipc.h>
 #include <linux/compat.h>
+#include <linux/ltt/ltt-facility-ipc.h>
 
 #include <asm-i386/ipc.h>
 
@@ -20,6 +21,8 @@
 	version = call >> 16; /* hack for backward compatibility */
 	call &= 0xffff;
 
+	trace_ipc_call(call, first);
+
 	switch (call) {
 	      case SEMOP:
 		/* struct sembuf is the same on 32 and 64bit :)) */
diff -urN linux_lttng/arch/x86_64/kernel/entry.S linux_lttng_working_clean/arch/x86_64/kernel/entry.S
--- linux_lttng/arch/x86_64/kernel/entry.S	2005-11-25 17:39:50.000000000 -0500
+++ linux_lttng_working_clean/arch/x86_64/kernel/entry.S	2005-12-01 09:51:42.000000000 -0500
@@ -189,9 +189,38 @@
 	jnz tracesys
 	cmpq $__NR_syscall_max,%rax
 	ja badsys
+syscall_call:
+
+#if (CONFIG_LTT)
+//	movl syscall_entry_trace_active, %eax
+//	cmpl $1, %eax                   # are we tracing system call entries
+//	jne no_syscall_entry_trace
+        SAVE_REST
+        FIXUP_TOP_OF_STACK %rdi
+	movq %rsp, %rdi                 # pass the stack pointer
+	call trace_real_syscall_entry
+	LOAD_ARGS ARGOFFSET             # reload args from stack in case
+                                        # trace_real_syscal_entry changed it
+        RESTORE_TOP_OF_STACK %rbx
+        RESTORE_REST
+no_syscall_entry_trace:
+	movq ORIG_RAX-ARGOFFSET(%rsp),%rax # restore rax to it's original content
+#endif
+
 	movq %r10,%rcx
 	call *sys_call_table(,%rax,8)  # XXX:	 rip relative
 	movq %rax,RAX-ARGOFFSET(%rsp)
+
+#if (CONFIG_LTT)
+//	movl syscall_exit_trace_active, %eax
+//	cmpl $1, %eax				#are we tracing system call exits
+//	jne  no_syscall_exit_trace
+        SAVE_REST
+	call trace_real_syscall_exit
+        RESTORE_REST
+no_syscall_exit_trace:
+#endif
+
 /*
  * Syscall return path ending with SYSRET (fast path)
  * Has incomplete stack frame and undefined top of stack. 
@@ -732,5 +761,15 @@
 	
 	# clone now
 	call do_fork
+
+#if (CONFIG_LTT)
+	cmp  $0, %rax	#if pid >=0 call trace_process_kernel_thread
+	jl   no_trace_thread
+	push %rdi	#push fn as argument
+	push %rax	#push pid as argument
+	call trace_process_kernel_thread__
+	add  $16, %rsp  #restore the stack as it was before the call
+no_trace_thread:
+#endif
 	movq %rax,RAX(%rsp)
 	xorl %edi,%edi

diff -urN linux_lttng/arch/x86_64/kernel/traps.c linux_lttng_working_clean/arch/x86_64/kernel/traps.c
--- linux_lttng/arch/x86_64/kernel/traps.c	2005-11-25 15:23:49.000000000 -0500
+++ linux_lttng_working_clean/arch/x86_64/kernel/traps.c	2005-12-01 09:51:55.000000000 -0500
@@ -14,6 +14,10 @@
  * 'Traps.c' handles hardware traps and faults after we have saved some
  * state in 'entry.S'.
  */
+ 
+#include <linux/ltt/ltt-facility-kernel.h>
+#include <linux/ltt/ltt-facility-process.h>
+#include <linux/ltt-core.h>
 #include <linux/config.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
@@ -377,6 +381,87 @@
 	printk(" RSP <%016lx>\n", regs->rsp); 
 }
 
+/* Trace related code */
+#if (CONFIG_LTT)
+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;
+	//ltt_syscall_entry trace_syscall_event;
+	unsigned long address;
+
+	/* Set the syscall ID */
+	//trace_syscall_event.syscall_id = (uint8_t) regs->orig_rax;
+
+	/* Set the address in any case */
+	address = regs->rip;
+
+	/* Are we in the kernel (This is a kernel thread)? */
+	if (!(regs->cs & 3))
+		/* Don't go digining anywhere */
+		goto trace_syscall_end;
+#if 0
+	/* Get the trace configuration */
+	//FIXME : need to take configuration from trace info.
+	//if (ltt_get_trace_config(&use_depth, &use_bounds, &seek_depth,
+	//			(void *) &lower_bound, (void *) &upper_bound) < 0)
+	if(1)
+		goto trace_syscall_end;
+
+	/* Do we have to search for an rip 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->rsp;
+
+		/* 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 */
+					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 */
+	//ltt_log_event(LTT_EV_SYSCALL_ENTRY, &trace_syscall_event);
+	trace_kernel_syscall_entry((uint8_t) regs->orig_rax, (void*)address);
+}
+
+asmlinkage void trace_real_syscall_exit(void)
+{
+	//ltt_log_event(LTT_EV_SYSCALL_EXIT, NULL);
+	trace_kernel_syscall_exit();
+}
+
+
+asmlinkage void trace_process_kernel_thread__(uint32_t pid, void * function)
+{
+	trace_process_kernel_thread(pid, function);
+}
+
+#endif				/* (CONFIG_LTT) */
+
+
 void die(const char * str, struct pt_regs * regs, long err)
 {
 	oops_begin();
@@ -420,6 +505,7 @@
 static void do_trap(int trapnr, int signr, char *str, 
 			   struct pt_regs * regs, long error_code, siginfo_t *info)
 {
+	trace_kernel_trap_entry(trapnr, (void*)regs->rip);
 	conditional_sti(regs);
 
 #ifdef CONFIG_CHECKING
@@ -450,6 +536,7 @@
 			force_sig_info(signr, info, tsk);
 		else
 			force_sig(signr, tsk);
+		trace_kernel_trap_exit();
 		return;
 	}
 
@@ -462,8 +549,10 @@
 			regs->rip = fixup->fixup;
 		} else	
 			die(str, regs, error_code);
+		trace_kernel_trap_exit();
 		return;
 	}
+	trace_kernel_trap_exit();
 }
 
 #define DO_ERROR(trapnr, signr, str, name) \
@@ -547,7 +636,9 @@
 
 		tsk->thread.error_code = error_code;
 		tsk->thread.trap_no = 13;
+		trace_kernel_trap_entry(13, (void*)regs->rip);
 		force_sig(SIGSEGV, tsk);
+		trace_kernel_trap_exit();
 		return;
 	} 
 
@@ -598,7 +689,11 @@
 asmlinkage void default_do_nmi(struct pt_regs * regs)
 {
 	unsigned char reason = get_nmi_reason();
-
+#ifndef CONFIG_X86_LOCAL_APIC
+  /* On machines with APIC enabled, NMIs are used to implement a watchdog
+      and will hang the machine if traced. */
+        trace_kernel_trap_entry(2, (void*)regs->eip);
+#endif  
 	if (!(reason & 0xc0)) {
 		if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 0, SIGINT)
 								== NOTIFY_STOP)
@@ -614,6 +709,9 @@
 		}
 #endif
 		unknown_nmi_error(reason, regs);
+#ifndef CONFIG_X86_LOCAL_APIC
+		trace_kernel_trap_exit();
+#endif
 		return;
 	}
 	if (notify_die(DIE_NMI, "nmi", regs, reason, 0, SIGINT) == NOTIFY_STOP)
@@ -634,6 +732,9 @@
 	inb(0x71);		/* dummy */
 	outb(0x0f, 0x70);
 	inb(0x71);		/* dummy */
+#ifndef CONFIG_X86_LOCAL_APIC
+	trace_kernel_trap_exit();
+#endif
 }
 
 asmlinkage void do_int3(struct pt_regs * regs, long error_code)
@@ -716,7 +817,9 @@
 		goto clear_dr7; 
 
 	info.si_addr = (void __user *)regs->rip;
+	trace_kernel_trap_entry(1, (void*)regs->rip);
 	force_sig_info(SIGTRAP, &info, tsk);	
+	trace_kernel_trap_exit();
 clear_dr7:
 	asm volatile("movq %0,%%db7"::"r"(0UL));
 	notify_die(DIE_DEBUG, "debug", regs, condition, 1, SIGTRAP);
@@ -880,6 +983,9 @@
 
 asmlinkage void do_spurious_interrupt_bug(struct pt_regs * regs)
 {
+	trace_kernel_trap_entry(16, (void*)regs->rip);
+
+	trace_kernel_trap_exit();
 }
 
 /*
diff -urN linux_lttng/arch/x86_64/kernel/irq.c linux_lttng_working_clean/arch/x86_64/kernel/irq.c
--- linux_lttng/arch/x86_64/kernel/irq.c	2005-12-01 11:48:22.000000000 -0500
+++ linux_lttng_working_clean/arch/x86_64/kernel/irq.c	2005-11-25 16:36:07.000000000 -0500
@@ -33,6 +33,7 @@
 #include <linux/irq.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/ltt/ltt-facility-kernel.h>
 
 #include <asm/atomic.h>
 #include <asm/io.h>
@@ -214,7 +215,9 @@ int handle_IRQ_event(unsigned int irq, s
 {
 	int status = 1; /* Force the "do bottom halves" bit */
 	int ret;
-
+        
+        trace_kernel_irq_entry(irq, !(user_mode(regs)));
+        
 	if (!(action->flags & SA_INTERRUPT))
 		local_irq_enable();
 
@@ -228,6 +231,8 @@ int handle_IRQ_event(unsigned int irq, s
 		add_interrupt_randomness(irq);
 	local_irq_disable();
 
+        trace_kernel_irq_exit();
+        
 	return status;
 }
 
diff -urN linux_lttng/arch/x86_64/mm/fault.c linux_lttng_working_clean/arch/x86_64/mm/fault.c
--- linux_lttng/arch/x86_64/mm/fault.c	2005-11-25 15:23:49.000000000 -0500
+++ linux_lttng_working_clean/arch/x86_64/mm/fault.c	2005-12-01 09:52:41.000000000 -0500
@@ -5,6 +5,7 @@
  *  Copyright (C) 2001,2002 Andi Kleen, SuSE Labs.
  */
 
+#include <linux/ltt/ltt-facility-kernel.h>
 #include <linux/config.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
@@ -320,7 +321,9 @@
 	if (unlikely(in_atomic() || !mm))
 		goto bad_area_nosemaphore;
 
+ 	trace_kernel_trap_entry(14, (void*)regs->rip);
  again:
+	
 	/* When running in the kernel we expect faults to occur only to
 	 * addresses in user space.  All other faults represent errors in the
 	 * kernel and should generate an OOPS.  Unfortunatly, in the case of an
@@ -398,6 +401,7 @@
 	}
 
 	up_read(&mm->mmap_sem);
+	trace_kernel_trap_exit();
 	return;
 
 /*
@@ -415,6 +419,7 @@
 	    address >= VSYSCALL32_BASE && address < VSYSCALL32_END) {
 		if (map_syscall32(mm, address) < 0)
 			goto out_of_memory2;
+		trace_kernel_trap_exit();
 		return;
 	}
 #endif
@@ -431,8 +436,10 @@
 		   case and return.  Any code segment in LDT is
 		   compatibility mode. */
 		if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) &&
-		    (address >> 32))
+		    (address >> 32)) {
+		        trace_kernel_trap_exit();
 			return;
+		    }
 
 		if (exception_trace && unhandled_signal(tsk, SIGSEGV)) {
 			printk(KERN_INFO
@@ -450,6 +457,7 @@
 		/* info.si_code has been set above */
 		info.si_addr = (void __user *)address;
 		force_sig_info(SIGSEGV, &info, tsk);
+		trace_kernel_trap_exit();
 		return;
 	}
 
@@ -459,6 +467,7 @@
 	fixup = search_exception_tables(regs->rip);
 	if (fixup) {
 		regs->rip = fixup->fixup;
+		trace_kernel_trap_exit();
 		return;
 	}
 
@@ -466,11 +475,15 @@
 	 * Hall of shame of CPU/BIOS bugs.
 	 */
 
- 	if (is_prefetch(regs, address, error_code))
+ 	if (is_prefetch(regs, address, error_code)) {
+		trace_kernel_trap_exit();
  		return;
+	}
 
-	if (is_errata93(regs, address))
-		return; 
+	if (is_errata93(regs, address)) {
+		trace_kernel_trap_exit();
+		return;
+	}
 
 /*
  * Oops. The kernel tried to access some bad page. We'll have to
@@ -525,6 +538,7 @@
 	info.si_code = BUS_ADRERR;
 	info.si_addr = (void __user *)address;
 	force_sig_info(SIGBUS, &info, tsk);
+	trace_kernel_trap_exit();
 	return;
 
 vmalloc_fault:
@@ -550,10 +564,12 @@
 		if (!pte_present(*pte))
 			goto bad_area_nosemaphore;
 
-		__flush_tlb_all();		
+		__flush_tlb_all();
+		trace_kernel_trap_exit();
 		return;
 	}
 
 page_table_corruption:
 	pgtable_bad(address, regs, error_code);
+	trace_kernel_trap_exit();
 }
diff -urN linux_lttng/include/asm-x86_64/ltt.h linux_lttng_working_clean/include/asm-x86_64/ltt.h
--- linux_lttng/include/asm-x86_64/ltt.h	2005-11-25 15:35:43.000000000 -0500
+++ linux_lttng_working_clean/include/asm-x86_64/ltt.h	2005-12-01 09:53:14.000000000 -0500
@@ -1,6 +1,10 @@
 #ifndef _ASM_X86_64_LTT_H
 #define _ASM_X86_64_LTT_H
 
+#define LTT_ARCH_TYPE LTT_ARCH_TYPE_X86_64
+#define LTT_ARCH_VARIANT LTT_ARCH_VARIANT_NONE
+
 #define LTT_HAS_TSC
 
+
 #endif
diff -urN linux_lttng/include/linux/ltt-core.h linux_lttng_working_clean/include/linux/ltt-core.h
--- linux_lttng/include/linux/ltt-core.h	2005-11-25 15:35:43.000000000 -0500
+++ linux_lttng_working_clean/include/linux/ltt-core.h	2005-12-01 09:53:33.000000000 -0500
@@ -399,6 +399,7 @@
 #define LTT_ARCH_TYPE_S390					4
 #define LTT_ARCH_TYPE_MIPS					5
 #define LTT_ARCH_TYPE_ARM						6
+#define LTT_ARCH_TYPE_X86_64					7
 
 /* Standard definitions for variants */
 #define LTT_ARCH_VARIANT_NONE				0	 /* Main architecture implementation */
diff -urN linux_lttng/init/Kconfig linux_lttng_working_clean/init/Kconfig
--- linux_lttng/init/Kconfig	2005-11-25 15:35:43.000000000 -0500
+++ linux_lttng_working_clean/init/Kconfig	2005-12-01 09:54:00.000000000 -0500
@@ -306,7 +306,7 @@
 config LTT
 	bool "Linux Trace Toolkit Instrumentation Support"
 	select RELAYFS_FS
-	depends on !X86_64 && EXPERIMENTAL
+	depends on EXPERIMENTAL
 	default n
 	help
 	  It is possible for the kernel to log important events to a trace
diff -urN linux_lttng/kernel/ltt-core.c linux_lttng_working_clean/kernel/ltt-core.c
--- linux_lttng/kernel/ltt-core.c	2005-11-25 15:35:43.000000000 -0500
+++ linux_lttng_working_clean/kernel/ltt-core.c	2005-12-01 10:02:16.000000000 -0500
@@ -63,7 +63,6 @@
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/ltt-facilities.h>
-#include <asm/timer.h>
 
 static struct dentry *ltt_root_dentry;
 

