ia64/xen-unstable

changeset 9941:ad5b833122a8

Linux: upgrade patches to 2.6.16.13.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu May 04 17:44:14 2006 +0100 (2006-05-04)
parents 44e5abbf333b
children 8761333499ae
files patches/linux-2.6.16.13/device_bind.patch patches/linux-2.6.16.13/i386-mach-io-check-nmi.patch patches/linux-2.6.16.13/net-csum.patch patches/linux-2.6.16.13/pmd-shared.patch patches/linux-2.6.16.13/rename-TSS_sysenter_esp0-SYSENTER_stack_esp0.patch patches/linux-2.6.16.13/smp-alts.patch patches/linux-2.6.16.13/x86-increase-interrupt-vector-range.patch patches/linux-2.6.16.13/xenoprof-generic.patch patches/linux-2.6.16/device_bind.patch patches/linux-2.6.16/i386-mach-io-check-nmi.patch patches/linux-2.6.16/net-csum.patch patches/linux-2.6.16/pmd-shared.patch patches/linux-2.6.16/rename-TSS_sysenter_esp0-SYSENTER_stack_esp0.patch patches/linux-2.6.16/smp-alts.patch patches/linux-2.6.16/x86-increase-interrupt-vector-range.patch patches/linux-2.6.16/xenoprof-generic.patch
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/patches/linux-2.6.16.13/device_bind.patch	Thu May 04 17:44:14 2006 +0100
     1.3 @@ -0,0 +1,15 @@
     1.4 +diff -pruN ../pristine-linux-2.6.16.13/drivers/base/bus.c ./drivers/base/bus.c
     1.5 +--- ../pristine-linux-2.6.16.13/drivers/base/bus.c	2006-05-02 22:38:44.000000000 +0100
     1.6 ++++ ./drivers/base/bus.c	2006-05-04 17:41:30.000000000 +0100
     1.7 +@@ -188,6 +188,11 @@ static ssize_t driver_bind(struct device
     1.8 + 		up(&dev->sem);
     1.9 + 		if (dev->parent)
    1.10 + 			up(&dev->parent->sem);
    1.11 ++
    1.12 ++		if (err > 0) 		/* success */
    1.13 ++			err = count;
    1.14 ++		else if (err == 0)	/* driver didn't accept device */
    1.15 ++			err = -ENODEV;
    1.16 + 	}
    1.17 + 	put_device(dev);
    1.18 + 	put_bus(bus);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/patches/linux-2.6.16.13/i386-mach-io-check-nmi.patch	Thu May 04 17:44:14 2006 +0100
     2.3 @@ -0,0 +1,45 @@
     2.4 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/kernel/traps.c ./arch/i386/kernel/traps.c
     2.5 +--- ../pristine-linux-2.6.16.13/arch/i386/kernel/traps.c	2006-05-02 22:38:44.000000000 +0100
     2.6 ++++ ./arch/i386/kernel/traps.c	2006-05-04 17:41:34.000000000 +0100
     2.7 +@@ -567,18 +567,11 @@ static void mem_parity_error(unsigned ch
     2.8 + 
     2.9 + static void io_check_error(unsigned char reason, struct pt_regs * regs)
    2.10 + {
    2.11 +-	unsigned long i;
    2.12 +-
    2.13 + 	printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n");
    2.14 + 	show_registers(regs);
    2.15 + 
    2.16 + 	/* Re-enable the IOCK line, wait for a few seconds */
    2.17 +-	reason = (reason & 0xf) | 8;
    2.18 +-	outb(reason, 0x61);
    2.19 +-	i = 2000;
    2.20 +-	while (--i) udelay(1000);
    2.21 +-	reason &= ~8;
    2.22 +-	outb(reason, 0x61);
    2.23 ++	clear_io_check_error(reason);
    2.24 + }
    2.25 + 
    2.26 + static void unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
    2.27 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/mach-default/mach_traps.h ./include/asm-i386/mach-default/mach_traps.h
    2.28 +--- ../pristine-linux-2.6.16.13/include/asm-i386/mach-default/mach_traps.h	2006-05-02 22:38:44.000000000 +0100
    2.29 ++++ ./include/asm-i386/mach-default/mach_traps.h	2006-05-04 17:41:34.000000000 +0100
    2.30 +@@ -15,6 +15,18 @@ static inline void clear_mem_error(unsig
    2.31 + 	outb(reason, 0x61);
    2.32 + }
    2.33 + 
    2.34 ++static inline void clear_io_check_error(unsigned char reason)
    2.35 ++{
    2.36 ++	unsigned long i;
    2.37 ++
    2.38 ++	reason = (reason & 0xf) | 8;
    2.39 ++	outb(reason, 0x61);
    2.40 ++	i = 2000;
    2.41 ++	while (--i) udelay(1000);
    2.42 ++	reason &= ~8;
    2.43 ++	outb(reason, 0x61);
    2.44 ++}
    2.45 ++
    2.46 + static inline unsigned char get_nmi_reason(void)
    2.47 + {
    2.48 + 	return inb(0x61);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/patches/linux-2.6.16.13/net-csum.patch	Thu May 04 17:44:14 2006 +0100
     3.3 @@ -0,0 +1,64 @@
     3.4 +diff -pruN ../pristine-linux-2.6.16.13/net/ipv4/netfilter/ip_nat_proto_tcp.c ./net/ipv4/netfilter/ip_nat_proto_tcp.c
     3.5 +--- ../pristine-linux-2.6.16.13/net/ipv4/netfilter/ip_nat_proto_tcp.c	2006-05-02 22:38:44.000000000 +0100
     3.6 ++++ ./net/ipv4/netfilter/ip_nat_proto_tcp.c	2006-05-04 17:41:37.000000000 +0100
     3.7 +@@ -129,10 +129,14 @@ tcp_manip_pkt(struct sk_buff **pskb,
     3.8 + 	if (hdrsize < sizeof(*hdr))
     3.9 + 		return 1;
    3.10 + 
    3.11 +-	hdr->check = ip_nat_cheat_check(~oldip, newip,
    3.12 ++	if ((*pskb)->proto_csum_blank) {
    3.13 ++		hdr->check = ip_nat_cheat_check(oldip, ~newip, hdr->check);
    3.14 ++	} else {
    3.15 ++		hdr->check = ip_nat_cheat_check(~oldip, newip,
    3.16 + 					ip_nat_cheat_check(oldport ^ 0xFFFF,
    3.17 + 							   newport,
    3.18 + 							   hdr->check));
    3.19 ++	}
    3.20 + 	return 1;
    3.21 + }
    3.22 + 
    3.23 +diff -pruN ../pristine-linux-2.6.16.13/net/ipv4/netfilter/ip_nat_proto_udp.c ./net/ipv4/netfilter/ip_nat_proto_udp.c
    3.24 +--- ../pristine-linux-2.6.16.13/net/ipv4/netfilter/ip_nat_proto_udp.c	2006-05-02 22:38:44.000000000 +0100
    3.25 ++++ ./net/ipv4/netfilter/ip_nat_proto_udp.c	2006-05-04 17:41:37.000000000 +0100
    3.26 +@@ -113,11 +113,16 @@ udp_manip_pkt(struct sk_buff **pskb,
    3.27 + 		newport = tuple->dst.u.udp.port;
    3.28 + 		portptr = &hdr->dest;
    3.29 + 	}
    3.30 +-	if (hdr->check) /* 0 is a special case meaning no checksum */
    3.31 +-		hdr->check = ip_nat_cheat_check(~oldip, newip,
    3.32 ++	if (hdr->check) { /* 0 is a special case meaning no checksum */
    3.33 ++		if ((*pskb)->proto_csum_blank) {
    3.34 ++			hdr->check = ip_nat_cheat_check(oldip, ~newip, hdr->check);
    3.35 ++		} else {
    3.36 ++			hdr->check = ip_nat_cheat_check(~oldip, newip,
    3.37 + 					ip_nat_cheat_check(*portptr ^ 0xFFFF,
    3.38 + 							   newport,
    3.39 + 							   hdr->check));
    3.40 ++		}
    3.41 ++	}
    3.42 + 	*portptr = newport;
    3.43 + 	return 1;
    3.44 + }
    3.45 +diff -pruN ../pristine-linux-2.6.16.13/net/ipv4/xfrm4_output.c ./net/ipv4/xfrm4_output.c
    3.46 +--- ../pristine-linux-2.6.16.13/net/ipv4/xfrm4_output.c	2006-05-02 22:38:44.000000000 +0100
    3.47 ++++ ./net/ipv4/xfrm4_output.c	2006-05-04 17:41:37.000000000 +0100
    3.48 +@@ -17,6 +17,8 @@
    3.49 + #include <net/xfrm.h>
    3.50 + #include <net/icmp.h>
    3.51 + 
    3.52 ++extern int skb_checksum_setup(struct sk_buff *skb);
    3.53 ++
    3.54 + /* Add encapsulation header.
    3.55 +  *
    3.56 +  * In transport mode, the IP header will be moved forward to make space
    3.57 +@@ -103,6 +105,10 @@ static int xfrm4_output_one(struct sk_bu
    3.58 + 	struct xfrm_state *x = dst->xfrm;
    3.59 + 	int err;
    3.60 + 	
    3.61 ++	err = skb_checksum_setup(skb);
    3.62 ++	if (err)
    3.63 ++		goto error_nolock;
    3.64 ++
    3.65 + 	if (skb->ip_summed == CHECKSUM_HW) {
    3.66 + 		err = skb_checksum_help(skb, 0);
    3.67 + 		if (err)
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/patches/linux-2.6.16.13/pmd-shared.patch	Thu May 04 17:44:14 2006 +0100
     4.3 @@ -0,0 +1,111 @@
     4.4 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/mm/pageattr.c ./arch/i386/mm/pageattr.c
     4.5 +--- ../pristine-linux-2.6.16.13/arch/i386/mm/pageattr.c	2006-05-02 22:38:44.000000000 +0100
     4.6 ++++ ./arch/i386/mm/pageattr.c	2006-05-04 17:41:40.000000000 +0100
     4.7 +@@ -78,7 +78,7 @@ static void set_pmd_pte(pte_t *kpte, uns
     4.8 + 	unsigned long flags;
     4.9 + 
    4.10 + 	set_pte_atomic(kpte, pte); 	/* change init_mm */
    4.11 +-	if (PTRS_PER_PMD > 1)
    4.12 ++	if (HAVE_SHARED_KERNEL_PMD)
    4.13 + 		return;
    4.14 + 
    4.15 + 	spin_lock_irqsave(&pgd_lock, flags);
    4.16 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/mm/pgtable.c ./arch/i386/mm/pgtable.c
    4.17 +--- ../pristine-linux-2.6.16.13/arch/i386/mm/pgtable.c	2006-05-02 22:38:44.000000000 +0100
    4.18 ++++ ./arch/i386/mm/pgtable.c	2006-05-04 17:41:40.000000000 +0100
    4.19 +@@ -215,9 +215,10 @@ void pgd_ctor(void *pgd, kmem_cache_t *c
    4.20 + 		spin_lock_irqsave(&pgd_lock, flags);
    4.21 + 	}
    4.22 + 
    4.23 +-	clone_pgd_range((pgd_t *)pgd + USER_PTRS_PER_PGD,
    4.24 +-			swapper_pg_dir + USER_PTRS_PER_PGD,
    4.25 +-			KERNEL_PGD_PTRS);
    4.26 ++	if (PTRS_PER_PMD == 1 || HAVE_SHARED_KERNEL_PMD)
    4.27 ++		clone_pgd_range((pgd_t *)pgd + USER_PTRS_PER_PGD,
    4.28 ++				swapper_pg_dir + USER_PTRS_PER_PGD,
    4.29 ++				KERNEL_PGD_PTRS);
    4.30 + 	if (PTRS_PER_PMD > 1)
    4.31 + 		return;
    4.32 + 
    4.33 +@@ -249,6 +250,30 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
    4.34 + 			goto out_oom;
    4.35 + 		set_pgd(&pgd[i], __pgd(1 + __pa(pmd)));
    4.36 + 	}
    4.37 ++
    4.38 ++	if (!HAVE_SHARED_KERNEL_PMD) {
    4.39 ++		unsigned long flags;
    4.40 ++
    4.41 ++		for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
    4.42 ++			pmd_t *pmd = kmem_cache_alloc(pmd_cache, GFP_KERNEL);
    4.43 ++			if (!pmd)
    4.44 ++				goto out_oom;
    4.45 ++			set_pgd(&pgd[USER_PTRS_PER_PGD], __pgd(1 + __pa(pmd)));
    4.46 ++		}
    4.47 ++
    4.48 ++		spin_lock_irqsave(&pgd_lock, flags);
    4.49 ++		for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
    4.50 ++			unsigned long v = (unsigned long)i << PGDIR_SHIFT;
    4.51 ++			pgd_t *kpgd = pgd_offset_k(v);
    4.52 ++			pud_t *kpud = pud_offset(kpgd, v);
    4.53 ++			pmd_t *kpmd = pmd_offset(kpud, v);
    4.54 ++			pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
    4.55 ++			memcpy(pmd, kpmd, PAGE_SIZE);
    4.56 ++		}
    4.57 ++		pgd_list_add(pgd);
    4.58 ++		spin_unlock_irqrestore(&pgd_lock, flags);
    4.59 ++	}
    4.60 ++
    4.61 + 	return pgd;
    4.62 + 
    4.63 + out_oom:
    4.64 +@@ -263,9 +288,23 @@ void pgd_free(pgd_t *pgd)
    4.65 + 	int i;
    4.66 + 
    4.67 + 	/* in the PAE case user pgd entries are overwritten before usage */
    4.68 +-	if (PTRS_PER_PMD > 1)
    4.69 +-		for (i = 0; i < USER_PTRS_PER_PGD; ++i)
    4.70 +-			kmem_cache_free(pmd_cache, (void *)__va(pgd_val(pgd[i])-1));
    4.71 ++	if (PTRS_PER_PMD > 1) {
    4.72 ++		for (i = 0; i < USER_PTRS_PER_PGD; ++i) {
    4.73 ++			pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
    4.74 ++			kmem_cache_free(pmd_cache, pmd);
    4.75 ++		}
    4.76 ++		if (!HAVE_SHARED_KERNEL_PMD) {
    4.77 ++			unsigned long flags;
    4.78 ++			spin_lock_irqsave(&pgd_lock, flags);
    4.79 ++			pgd_list_del(pgd);
    4.80 ++			spin_unlock_irqrestore(&pgd_lock, flags);
    4.81 ++			for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
    4.82 ++				pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
    4.83 ++				memset(pmd, 0, PTRS_PER_PMD*sizeof(pmd_t));
    4.84 ++				kmem_cache_free(pmd_cache, pmd);
    4.85 ++			}
    4.86 ++		}
    4.87 ++	}
    4.88 + 	/* in the non-PAE case, free_pgtables() clears user pgd entries */
    4.89 + 	kmem_cache_free(pgd_cache, pgd);
    4.90 + }
    4.91 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/pgtable-2level-defs.h ./include/asm-i386/pgtable-2level-defs.h
    4.92 +--- ../pristine-linux-2.6.16.13/include/asm-i386/pgtable-2level-defs.h	2006-05-02 22:38:44.000000000 +0100
    4.93 ++++ ./include/asm-i386/pgtable-2level-defs.h	2006-05-04 17:41:40.000000000 +0100
    4.94 +@@ -1,6 +1,8 @@
    4.95 + #ifndef _I386_PGTABLE_2LEVEL_DEFS_H
    4.96 + #define _I386_PGTABLE_2LEVEL_DEFS_H
    4.97 + 
    4.98 ++#define HAVE_SHARED_KERNEL_PMD 0
    4.99 ++
   4.100 + /*
   4.101 +  * traditional i386 two-level paging structure:
   4.102 +  */
   4.103 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/pgtable-3level-defs.h ./include/asm-i386/pgtable-3level-defs.h
   4.104 +--- ../pristine-linux-2.6.16.13/include/asm-i386/pgtable-3level-defs.h	2006-05-02 22:38:44.000000000 +0100
   4.105 ++++ ./include/asm-i386/pgtable-3level-defs.h	2006-05-04 17:41:40.000000000 +0100
   4.106 +@@ -1,6 +1,8 @@
   4.107 + #ifndef _I386_PGTABLE_3LEVEL_DEFS_H
   4.108 + #define _I386_PGTABLE_3LEVEL_DEFS_H
   4.109 + 
   4.110 ++#define HAVE_SHARED_KERNEL_PMD 1
   4.111 ++
   4.112 + /*
   4.113 +  * PGDIR_SHIFT determines what a top-level page table entry can map
   4.114 +  */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/patches/linux-2.6.16.13/rename-TSS_sysenter_esp0-SYSENTER_stack_esp0.patch	Thu May 04 17:44:14 2006 +0100
     5.3 @@ -0,0 +1,30 @@
     5.4 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/kernel/entry.S ./arch/i386/kernel/entry.S
     5.5 +--- ../pristine-linux-2.6.16.13/arch/i386/kernel/entry.S	2006-05-02 22:38:44.000000000 +0100
     5.6 ++++ ./arch/i386/kernel/entry.S	2006-05-04 17:41:44.000000000 +0100
     5.7 +@@ -177,7 +177,7 @@ need_resched:
     5.8 + 
     5.9 + 	# sysenter call handler stub
    5.10 + ENTRY(sysenter_entry)
    5.11 +-	movl TSS_sysenter_esp0(%esp),%esp
    5.12 ++	movl SYSENTER_stack_esp0(%esp),%esp
    5.13 + sysenter_past_esp:
    5.14 + 	sti
    5.15 + 	pushl $(__USER_DS)
    5.16 +@@ -492,7 +492,7 @@ device_not_available_emulate:
    5.17 +  * that sets up the real kernel stack. Check here, since we can't
    5.18 +  * allow the wrong stack to be used.
    5.19 +  *
    5.20 +- * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
    5.21 ++ * "SYSENTER_stack_esp0+12" is because the NMI/debug handler will have
    5.22 +  * already pushed 3 words if it hits on the sysenter instruction:
    5.23 +  * eflags, cs and eip.
    5.24 +  *
    5.25 +@@ -504,7 +504,7 @@ device_not_available_emulate:
    5.26 + 	cmpw $__KERNEL_CS,4(%esp);		\
    5.27 + 	jne ok;					\
    5.28 + label:						\
    5.29 +-	movl TSS_sysenter_esp0+offset(%esp),%esp;	\
    5.30 ++	movl SYSENTER_stack_esp0+offset(%esp),%esp;	\
    5.31 + 	pushfl;					\
    5.32 + 	pushl $__KERNEL_CS;			\
    5.33 + 	pushl $sysenter_past_esp
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/patches/linux-2.6.16.13/smp-alts.patch	Thu May 04 17:44:14 2006 +0100
     6.3 @@ -0,0 +1,591 @@
     6.4 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/Kconfig ./arch/i386/Kconfig
     6.5 +--- ../pristine-linux-2.6.16.13/arch/i386/Kconfig	2006-05-02 22:38:44.000000000 +0100
     6.6 ++++ ./arch/i386/Kconfig	2006-05-04 17:41:45.000000000 +0100
     6.7 +@@ -202,6 +202,19 @@ config SMP
     6.8 + 
     6.9 + 	  If you don't know what to do here, say N.
    6.10 + 
    6.11 ++config SMP_ALTERNATIVES
    6.12 ++	bool "SMP alternatives support (EXPERIMENTAL)"
    6.13 ++	depends on SMP && EXPERIMENTAL
    6.14 ++	help
    6.15 ++	  Try to reduce the overhead of running an SMP kernel on a uniprocessor
    6.16 ++	  host slightly by replacing certain key instruction sequences
    6.17 ++	  according to whether we currently have more than one CPU available.
    6.18 ++	  This should provide a noticeable boost to performance when
    6.19 ++	  running SMP kernels on UP machines, and have negligible impact
    6.20 ++	  when running on an true SMP host.
    6.21 ++
    6.22 ++          If unsure, say N.
    6.23 ++	  
    6.24 + config NR_CPUS
    6.25 + 	int "Maximum number of CPUs (2-255)"
    6.26 + 	range 2 255
    6.27 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/kernel/Makefile ./arch/i386/kernel/Makefile
    6.28 +--- ../pristine-linux-2.6.16.13/arch/i386/kernel/Makefile	2006-05-02 22:38:44.000000000 +0100
    6.29 ++++ ./arch/i386/kernel/Makefile	2006-05-04 17:41:45.000000000 +0100
    6.30 +@@ -37,6 +37,7 @@ obj-$(CONFIG_EFI) 		+= efi.o efi_stub.o
    6.31 + obj-$(CONFIG_DOUBLEFAULT) 	+= doublefault.o
    6.32 + obj-$(CONFIG_VM86)		+= vm86.o
    6.33 + obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
    6.34 ++obj-$(CONFIG_SMP_ALTERNATIVES)  += smpalts.o
    6.35 + 
    6.36 + EXTRA_AFLAGS   := -traditional
    6.37 + 
    6.38 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/kernel/smpalts.c ./arch/i386/kernel/smpalts.c
    6.39 +--- ../pristine-linux-2.6.16.13/arch/i386/kernel/smpalts.c	1970-01-01 01:00:00.000000000 +0100
    6.40 ++++ ./arch/i386/kernel/smpalts.c	2006-05-04 17:41:45.000000000 +0100
    6.41 +@@ -0,0 +1,85 @@
    6.42 ++#include <linux/kernel.h>
    6.43 ++#include <asm/system.h>
    6.44 ++#include <asm/smp_alt.h>
    6.45 ++#include <asm/processor.h>
    6.46 ++#include <asm/string.h>
    6.47 ++
    6.48 ++struct smp_replacement_record {
    6.49 ++	unsigned char targ_size;
    6.50 ++	unsigned char smp1_size;
    6.51 ++	unsigned char smp2_size;
    6.52 ++	unsigned char up_size;
    6.53 ++	unsigned char feature;
    6.54 ++	unsigned char data[0];
    6.55 ++};
    6.56 ++
    6.57 ++struct smp_alternative_record {
    6.58 ++	void *targ_start;
    6.59 ++	struct smp_replacement_record *repl;
    6.60 ++};
    6.61 ++
    6.62 ++extern struct smp_alternative_record __start_smp_alternatives_table,
    6.63 ++  __stop_smp_alternatives_table;
    6.64 ++extern unsigned long __init_begin, __init_end;
    6.65 ++
    6.66 ++void prepare_for_smp(void)
    6.67 ++{
    6.68 ++	struct smp_alternative_record *r;
    6.69 ++	printk(KERN_INFO "Enabling SMP...\n");
    6.70 ++	for (r = &__start_smp_alternatives_table;
    6.71 ++	     r != &__stop_smp_alternatives_table;
    6.72 ++	     r++) {
    6.73 ++		BUG_ON(r->repl->targ_size < r->repl->smp1_size);
    6.74 ++		BUG_ON(r->repl->targ_size < r->repl->smp2_size);
    6.75 ++		BUG_ON(r->repl->targ_size < r->repl->up_size);
    6.76 ++               if (system_state == SYSTEM_RUNNING &&
    6.77 ++                   r->targ_start >= (void *)&__init_begin &&
    6.78 ++                   r->targ_start < (void *)&__init_end)
    6.79 ++                       continue;
    6.80 ++		if (r->repl->feature != (unsigned char)-1 &&
    6.81 ++		    boot_cpu_has(r->repl->feature)) {
    6.82 ++			memcpy(r->targ_start,
    6.83 ++			       r->repl->data + r->repl->smp1_size,
    6.84 ++			       r->repl->smp2_size);
    6.85 ++			memset(r->targ_start + r->repl->smp2_size,
    6.86 ++			       0x90,
    6.87 ++			       r->repl->targ_size - r->repl->smp2_size);
    6.88 ++		} else {
    6.89 ++			memcpy(r->targ_start,
    6.90 ++			       r->repl->data,
    6.91 ++			       r->repl->smp1_size);
    6.92 ++			memset(r->targ_start + r->repl->smp1_size,
    6.93 ++			       0x90,
    6.94 ++			       r->repl->targ_size - r->repl->smp1_size);
    6.95 ++		}
    6.96 ++	}
    6.97 ++	/* Paranoia */
    6.98 ++	asm volatile ("jmp 1f\n1:");
    6.99 ++	mb();
   6.100 ++}
   6.101 ++
   6.102 ++void unprepare_for_smp(void)
   6.103 ++{
   6.104 ++	struct smp_alternative_record *r;
   6.105 ++	printk(KERN_INFO "Disabling SMP...\n");
   6.106 ++	for (r = &__start_smp_alternatives_table;
   6.107 ++	     r != &__stop_smp_alternatives_table;
   6.108 ++	     r++) {
   6.109 ++		BUG_ON(r->repl->targ_size < r->repl->smp1_size);
   6.110 ++		BUG_ON(r->repl->targ_size < r->repl->smp2_size);
   6.111 ++		BUG_ON(r->repl->targ_size < r->repl->up_size);
   6.112 ++               if (system_state == SYSTEM_RUNNING &&
   6.113 ++                   r->targ_start >= (void *)&__init_begin &&
   6.114 ++                   r->targ_start < (void *)&__init_end)
   6.115 ++                       continue;
   6.116 ++		memcpy(r->targ_start,
   6.117 ++		       r->repl->data + r->repl->smp1_size + r->repl->smp2_size,
   6.118 ++		       r->repl->up_size);
   6.119 ++		memset(r->targ_start + r->repl->up_size,
   6.120 ++		       0x90,
   6.121 ++		       r->repl->targ_size - r->repl->up_size);
   6.122 ++	}
   6.123 ++	/* Paranoia */
   6.124 ++	asm volatile ("jmp 1f\n1:");
   6.125 ++	mb();
   6.126 ++}
   6.127 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/kernel/smpboot.c ./arch/i386/kernel/smpboot.c
   6.128 +--- ../pristine-linux-2.6.16.13/arch/i386/kernel/smpboot.c	2006-05-02 22:38:44.000000000 +0100
   6.129 ++++ ./arch/i386/kernel/smpboot.c	2006-05-04 17:41:45.000000000 +0100
   6.130 +@@ -1218,6 +1218,11 @@ static void __init smp_boot_cpus(unsigne
   6.131 + 		if (max_cpus <= cpucount+1)
   6.132 + 			continue;
   6.133 + 
   6.134 ++#ifdef CONFIG_SMP_ALTERNATIVES
   6.135 ++		if (kicked == 1)
   6.136 ++			prepare_for_smp();
   6.137 ++#endif
   6.138 ++
   6.139 + 		if (((cpu = alloc_cpu_id()) <= 0) || do_boot_cpu(apicid, cpu))
   6.140 + 			printk("CPU #%d not responding - cannot use it.\n",
   6.141 + 								apicid);
   6.142 +@@ -1396,6 +1401,11 @@ int __devinit __cpu_up(unsigned int cpu)
   6.143 + 		return -EIO;
   6.144 + 	}
   6.145 + 
   6.146 ++#ifdef CONFIG_SMP_ALTERNATIVES
   6.147 ++	if (num_online_cpus() == 1)
   6.148 ++		prepare_for_smp();
   6.149 ++#endif
   6.150 ++
   6.151 + 	local_irq_enable();
   6.152 + 	per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
   6.153 + 	/* Unleash the CPU! */
   6.154 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/kernel/vmlinux.lds.S ./arch/i386/kernel/vmlinux.lds.S
   6.155 +--- ../pristine-linux-2.6.16.13/arch/i386/kernel/vmlinux.lds.S	2006-05-02 22:38:44.000000000 +0100
   6.156 ++++ ./arch/i386/kernel/vmlinux.lds.S	2006-05-04 17:41:45.000000000 +0100
   6.157 +@@ -34,6 +34,13 @@ SECTIONS
   6.158 +   __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { *(__ex_table) }
   6.159 +   __stop___ex_table = .;
   6.160 + 
   6.161 ++  . = ALIGN(16);
   6.162 ++  __start_smp_alternatives_table = .;
   6.163 ++  __smp_alternatives : { *(__smp_alternatives) }
   6.164 ++  __stop_smp_alternatives_table = .;
   6.165 ++
   6.166 ++  __smp_replacements : { *(__smp_replacements) }
   6.167 ++
   6.168 +   RODATA
   6.169 + 
   6.170 +   /* writeable */
   6.171 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/atomic.h ./include/asm-i386/atomic.h
   6.172 +--- ../pristine-linux-2.6.16.13/include/asm-i386/atomic.h	2006-05-02 22:38:44.000000000 +0100
   6.173 ++++ ./include/asm-i386/atomic.h	2006-05-04 17:41:45.000000000 +0100
   6.174 +@@ -4,18 +4,13 @@
   6.175 + #include <linux/config.h>
   6.176 + #include <linux/compiler.h>
   6.177 + #include <asm/processor.h>
   6.178 ++#include <asm/smp_alt.h>
   6.179 + 
   6.180 + /*
   6.181 +  * Atomic operations that C can't guarantee us.  Useful for
   6.182 +  * resource counting etc..
   6.183 +  */
   6.184 + 
   6.185 +-#ifdef CONFIG_SMP
   6.186 +-#define LOCK "lock ; "
   6.187 +-#else
   6.188 +-#define LOCK ""
   6.189 +-#endif
   6.190 +-
   6.191 + /*
   6.192 +  * Make sure gcc doesn't try to be clever and move things around
   6.193 +  * on us. We need to use _exactly_ the address the user gave us,
   6.194 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/bitops.h ./include/asm-i386/bitops.h
   6.195 +--- ../pristine-linux-2.6.16.13/include/asm-i386/bitops.h	2006-05-02 22:38:44.000000000 +0100
   6.196 ++++ ./include/asm-i386/bitops.h	2006-05-04 17:41:45.000000000 +0100
   6.197 +@@ -7,6 +7,7 @@
   6.198 + 
   6.199 + #include <linux/config.h>
   6.200 + #include <linux/compiler.h>
   6.201 ++#include <asm/smp_alt.h>
   6.202 + 
   6.203 + /*
   6.204 +  * These have to be done with inline assembly: that way the bit-setting
   6.205 +@@ -16,12 +17,6 @@
   6.206 +  * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
   6.207 +  */
   6.208 + 
   6.209 +-#ifdef CONFIG_SMP
   6.210 +-#define LOCK_PREFIX "lock ; "
   6.211 +-#else
   6.212 +-#define LOCK_PREFIX ""
   6.213 +-#endif
   6.214 +-
   6.215 + #define ADDR (*(volatile long *) addr)
   6.216 + 
   6.217 + /**
   6.218 +@@ -41,7 +36,7 @@
   6.219 +  */
   6.220 + static inline void set_bit(int nr, volatile unsigned long * addr)
   6.221 + {
   6.222 +-	__asm__ __volatile__( LOCK_PREFIX
   6.223 ++	__asm__ __volatile__( LOCK
   6.224 + 		"btsl %1,%0"
   6.225 + 		:"+m" (ADDR)
   6.226 + 		:"Ir" (nr));
   6.227 +@@ -76,7 +71,7 @@ static inline void __set_bit(int nr, vol
   6.228 +  */
   6.229 + static inline void clear_bit(int nr, volatile unsigned long * addr)
   6.230 + {
   6.231 +-	__asm__ __volatile__( LOCK_PREFIX
   6.232 ++	__asm__ __volatile__( LOCK
   6.233 + 		"btrl %1,%0"
   6.234 + 		:"+m" (ADDR)
   6.235 + 		:"Ir" (nr));
   6.236 +@@ -121,7 +116,7 @@ static inline void __change_bit(int nr, 
   6.237 +  */
   6.238 + static inline void change_bit(int nr, volatile unsigned long * addr)
   6.239 + {
   6.240 +-	__asm__ __volatile__( LOCK_PREFIX
   6.241 ++	__asm__ __volatile__( LOCK
   6.242 + 		"btcl %1,%0"
   6.243 + 		:"+m" (ADDR)
   6.244 + 		:"Ir" (nr));
   6.245 +@@ -140,7 +135,7 @@ static inline int test_and_set_bit(int n
   6.246 + {
   6.247 + 	int oldbit;
   6.248 + 
   6.249 +-	__asm__ __volatile__( LOCK_PREFIX
   6.250 ++	__asm__ __volatile__( LOCK
   6.251 + 		"btsl %2,%1\n\tsbbl %0,%0"
   6.252 + 		:"=r" (oldbit),"+m" (ADDR)
   6.253 + 		:"Ir" (nr) : "memory");
   6.254 +@@ -180,7 +175,7 @@ static inline int test_and_clear_bit(int
   6.255 + {
   6.256 + 	int oldbit;
   6.257 + 
   6.258 +-	__asm__ __volatile__( LOCK_PREFIX
   6.259 ++	__asm__ __volatile__( LOCK
   6.260 + 		"btrl %2,%1\n\tsbbl %0,%0"
   6.261 + 		:"=r" (oldbit),"+m" (ADDR)
   6.262 + 		:"Ir" (nr) : "memory");
   6.263 +@@ -231,7 +226,7 @@ static inline int test_and_change_bit(in
   6.264 + {
   6.265 + 	int oldbit;
   6.266 + 
   6.267 +-	__asm__ __volatile__( LOCK_PREFIX
   6.268 ++	__asm__ __volatile__( LOCK
   6.269 + 		"btcl %2,%1\n\tsbbl %0,%0"
   6.270 + 		:"=r" (oldbit),"+m" (ADDR)
   6.271 + 		:"Ir" (nr) : "memory");
   6.272 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/futex.h ./include/asm-i386/futex.h
   6.273 +--- ../pristine-linux-2.6.16.13/include/asm-i386/futex.h	2006-05-02 22:38:44.000000000 +0100
   6.274 ++++ ./include/asm-i386/futex.h	2006-05-04 17:41:45.000000000 +0100
   6.275 +@@ -28,7 +28,7 @@
   6.276 + "1:	movl	%2, %0\n\
   6.277 + 	movl	%0, %3\n"					\
   6.278 + 	insn "\n"						\
   6.279 +-"2:	" LOCK_PREFIX "cmpxchgl %3, %2\n\
   6.280 ++"2:	" LOCK "cmpxchgl %3, %2\n\
   6.281 + 	jnz	1b\n\
   6.282 + 3:	.section .fixup,\"ax\"\n\
   6.283 + 4:	mov	%5, %1\n\
   6.284 +@@ -68,7 +68,7 @@ futex_atomic_op_inuser (int encoded_op, 
   6.285 + #endif
   6.286 + 		switch (op) {
   6.287 + 		case FUTEX_OP_ADD:
   6.288 +-			__futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret,
   6.289 ++			__futex_atomic_op1(LOCK "xaddl %0, %2", ret,
   6.290 + 					   oldval, uaddr, oparg);
   6.291 + 			break;
   6.292 + 		case FUTEX_OP_OR:
   6.293 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/rwsem.h ./include/asm-i386/rwsem.h
   6.294 +--- ../pristine-linux-2.6.16.13/include/asm-i386/rwsem.h	2006-05-02 22:38:44.000000000 +0100
   6.295 ++++ ./include/asm-i386/rwsem.h	2006-05-04 17:41:45.000000000 +0100
   6.296 +@@ -40,6 +40,7 @@
   6.297 + 
   6.298 + #include <linux/list.h>
   6.299 + #include <linux/spinlock.h>
   6.300 ++#include <asm/smp_alt.h>
   6.301 + 
   6.302 + struct rwsem_waiter;
   6.303 + 
   6.304 +@@ -99,7 +100,7 @@ static inline void __down_read(struct rw
   6.305 + {
   6.306 + 	__asm__ __volatile__(
   6.307 + 		"# beginning down_read\n\t"
   6.308 +-LOCK_PREFIX	"  incl      (%%eax)\n\t" /* adds 0x00000001, returns the old value */
   6.309 ++LOCK	        "  incl      (%%eax)\n\t" /* adds 0x00000001, returns the old value */
   6.310 + 		"  js        2f\n\t" /* jump if we weren't granted the lock */
   6.311 + 		"1:\n\t"
   6.312 + 		LOCK_SECTION_START("")
   6.313 +@@ -130,7 +131,7 @@ static inline int __down_read_trylock(st
   6.314 + 		"  movl	     %1,%2\n\t"
   6.315 + 		"  addl      %3,%2\n\t"
   6.316 + 		"  jle	     2f\n\t"
   6.317 +-LOCK_PREFIX	"  cmpxchgl  %2,%0\n\t"
   6.318 ++LOCK	        "  cmpxchgl  %2,%0\n\t"
   6.319 + 		"  jnz	     1b\n\t"
   6.320 + 		"2:\n\t"
   6.321 + 		"# ending __down_read_trylock\n\t"
   6.322 +@@ -150,7 +151,7 @@ static inline void __down_write(struct r
   6.323 + 	tmp = RWSEM_ACTIVE_WRITE_BIAS;
   6.324 + 	__asm__ __volatile__(
   6.325 + 		"# beginning down_write\n\t"
   6.326 +-LOCK_PREFIX	"  xadd      %%edx,(%%eax)\n\t" /* subtract 0x0000ffff, returns the old value */
   6.327 ++LOCK	        "  xadd      %%edx,(%%eax)\n\t" /* subtract 0x0000ffff, returns the old value */
   6.328 + 		"  testl     %%edx,%%edx\n\t" /* was the count 0 before? */
   6.329 + 		"  jnz       2f\n\t" /* jump if we weren't granted the lock */
   6.330 + 		"1:\n\t"
   6.331 +@@ -188,7 +189,7 @@ static inline void __up_read(struct rw_s
   6.332 + 	__s32 tmp = -RWSEM_ACTIVE_READ_BIAS;
   6.333 + 	__asm__ __volatile__(
   6.334 + 		"# beginning __up_read\n\t"
   6.335 +-LOCK_PREFIX	"  xadd      %%edx,(%%eax)\n\t" /* subtracts 1, returns the old value */
   6.336 ++LOCK	        "  xadd      %%edx,(%%eax)\n\t" /* subtracts 1, returns the old value */
   6.337 + 		"  js        2f\n\t" /* jump if the lock is being waited upon */
   6.338 + 		"1:\n\t"
   6.339 + 		LOCK_SECTION_START("")
   6.340 +@@ -214,7 +215,7 @@ static inline void __up_write(struct rw_
   6.341 + 	__asm__ __volatile__(
   6.342 + 		"# beginning __up_write\n\t"
   6.343 + 		"  movl      %2,%%edx\n\t"
   6.344 +-LOCK_PREFIX	"  xaddl     %%edx,(%%eax)\n\t" /* tries to transition 0xffff0001 -> 0x00000000 */
   6.345 ++LOCK	        "  xaddl     %%edx,(%%eax)\n\t" /* tries to transition 0xffff0001 -> 0x00000000 */
   6.346 + 		"  jnz       2f\n\t" /* jump if the lock is being waited upon */
   6.347 + 		"1:\n\t"
   6.348 + 		LOCK_SECTION_START("")
   6.349 +@@ -239,7 +240,7 @@ static inline void __downgrade_write(str
   6.350 + {
   6.351 + 	__asm__ __volatile__(
   6.352 + 		"# beginning __downgrade_write\n\t"
   6.353 +-LOCK_PREFIX	"  addl      %2,(%%eax)\n\t" /* transitions 0xZZZZ0001 -> 0xYYYY0001 */
   6.354 ++LOCK	        "  addl      %2,(%%eax)\n\t" /* transitions 0xZZZZ0001 -> 0xYYYY0001 */
   6.355 + 		"  js        2f\n\t" /* jump if the lock is being waited upon */
   6.356 + 		"1:\n\t"
   6.357 + 		LOCK_SECTION_START("")
   6.358 +@@ -263,7 +264,7 @@ LOCK_PREFIX	"  addl      %2,(%%eax)\n\t"
   6.359 + static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
   6.360 + {
   6.361 + 	__asm__ __volatile__(
   6.362 +-LOCK_PREFIX	"addl %1,%0"
   6.363 ++LOCK	          "addl %1,%0"
   6.364 + 		: "=m"(sem->count)
   6.365 + 		: "ir"(delta), "m"(sem->count));
   6.366 + }
   6.367 +@@ -276,7 +277,7 @@ static inline int rwsem_atomic_update(in
   6.368 + 	int tmp = delta;
   6.369 + 
   6.370 + 	__asm__ __volatile__(
   6.371 +-LOCK_PREFIX	"xadd %0,(%2)"
   6.372 ++LOCK  	          "xadd %0,(%2)"
   6.373 + 		: "+r"(tmp), "=m"(sem->count)
   6.374 + 		: "r"(sem), "m"(sem->count)
   6.375 + 		: "memory");
   6.376 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/smp_alt.h ./include/asm-i386/smp_alt.h
   6.377 +--- ../pristine-linux-2.6.16.13/include/asm-i386/smp_alt.h	1970-01-01 01:00:00.000000000 +0100
   6.378 ++++ ./include/asm-i386/smp_alt.h	2006-05-04 17:41:45.000000000 +0100
   6.379 +@@ -0,0 +1,32 @@
   6.380 ++#ifndef __ASM_SMP_ALT_H__
   6.381 ++#define __ASM_SMP_ALT_H__
   6.382 ++
   6.383 ++#include <linux/config.h>
   6.384 ++
   6.385 ++#ifdef CONFIG_SMP
   6.386 ++#if defined(CONFIG_SMP_ALTERNATIVES) && !defined(MODULE)
   6.387 ++#define LOCK \
   6.388 ++        "6677: nop\n" \
   6.389 ++	".section __smp_alternatives,\"a\"\n" \
   6.390 ++	".long 6677b\n" \
   6.391 ++	".long 6678f\n" \
   6.392 ++	".previous\n" \
   6.393 ++	".section __smp_replacements,\"a\"\n" \
   6.394 ++	"6678: .byte 1\n" \
   6.395 ++	".byte 1\n" \
   6.396 ++	".byte 0\n" \
   6.397 ++        ".byte 1\n" \
   6.398 ++	".byte -1\n" \
   6.399 ++	"lock\n" \
   6.400 ++	"nop\n" \
   6.401 ++	".previous\n"
   6.402 ++void prepare_for_smp(void);
   6.403 ++void unprepare_for_smp(void);
   6.404 ++#else
   6.405 ++#define LOCK "lock ; "
   6.406 ++#endif
   6.407 ++#else
   6.408 ++#define LOCK ""
   6.409 ++#endif
   6.410 ++
   6.411 ++#endif /* __ASM_SMP_ALT_H__ */
   6.412 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/spinlock.h ./include/asm-i386/spinlock.h
   6.413 +--- ../pristine-linux-2.6.16.13/include/asm-i386/spinlock.h	2006-05-02 22:38:44.000000000 +0100
   6.414 ++++ ./include/asm-i386/spinlock.h	2006-05-04 17:41:45.000000000 +0100
   6.415 +@@ -6,6 +6,7 @@
   6.416 + #include <asm/page.h>
   6.417 + #include <linux/config.h>
   6.418 + #include <linux/compiler.h>
   6.419 ++#include <asm/smp_alt.h>
   6.420 + 
   6.421 + /*
   6.422 +  * Your basic SMP spinlocks, allowing only a single CPU anywhere
   6.423 +@@ -23,7 +24,8 @@
   6.424 + 
   6.425 + #define __raw_spin_lock_string \
   6.426 + 	"\n1:\t" \
   6.427 +-	"lock ; decb %0\n\t" \
   6.428 ++	LOCK \
   6.429 ++	"decb %0\n\t" \
   6.430 + 	"jns 3f\n" \
   6.431 + 	"2:\t" \
   6.432 + 	"rep;nop\n\t" \
   6.433 +@@ -34,7 +36,8 @@
   6.434 + 
   6.435 + #define __raw_spin_lock_string_flags \
   6.436 + 	"\n1:\t" \
   6.437 +-	"lock ; decb %0\n\t" \
   6.438 ++	LOCK \
   6.439 ++	"decb %0\n\t" \
   6.440 + 	"jns 4f\n\t" \
   6.441 + 	"2:\t" \
   6.442 + 	"testl $0x200, %1\n\t" \
   6.443 +@@ -65,10 +68,34 @@ static inline void __raw_spin_lock_flags
   6.444 + static inline int __raw_spin_trylock(raw_spinlock_t *lock)
   6.445 + {
   6.446 + 	char oldval;
   6.447 ++#ifdef CONFIG_SMP_ALTERNATIVES
   6.448 + 	__asm__ __volatile__(
   6.449 +-		"xchgb %b0,%1"
   6.450 ++		"1:movb %1,%b0\n"
   6.451 ++		"movb $0,%1\n"
   6.452 ++		"2:"
   6.453 ++		".section __smp_alternatives,\"a\"\n"
   6.454 ++		".long 1b\n"
   6.455 ++		".long 3f\n"
   6.456 ++		".previous\n"
   6.457 ++		".section __smp_replacements,\"a\"\n"
   6.458 ++		"3: .byte 2b - 1b\n"
   6.459 ++		".byte 5f-4f\n"
   6.460 ++		".byte 0\n"
   6.461 ++		".byte 6f-5f\n"
   6.462 ++		".byte -1\n"
   6.463 ++		"4: xchgb %b0,%1\n"
   6.464 ++		"5: movb %1,%b0\n"
   6.465 ++		"movb $0,%1\n"
   6.466 ++		"6:\n"
   6.467 ++		".previous\n"
   6.468 + 		:"=q" (oldval), "=m" (lock->slock)
   6.469 + 		:"0" (0) : "memory");
   6.470 ++#else
   6.471 ++	__asm__ __volatile__(
   6.472 ++		"xchgb %b0,%1\n"
   6.473 ++		:"=q" (oldval), "=m" (lock->slock)
   6.474 ++		:"0" (0) : "memory");
   6.475 ++#endif
   6.476 + 	return oldval > 0;
   6.477 + }
   6.478 + 
   6.479 +@@ -178,12 +205,12 @@ static inline int __raw_write_trylock(ra
   6.480 + 
   6.481 + static inline void __raw_read_unlock(raw_rwlock_t *rw)
   6.482 + {
   6.483 +-	asm volatile("lock ; incl %0" :"=m" (rw->lock) : : "memory");
   6.484 ++	asm volatile(LOCK "incl %0" :"=m" (rw->lock) : : "memory");
   6.485 + }
   6.486 + 
   6.487 + static inline void __raw_write_unlock(raw_rwlock_t *rw)
   6.488 + {
   6.489 +-	asm volatile("lock ; addl $" RW_LOCK_BIAS_STR ", %0"
   6.490 ++	asm volatile(LOCK "addl $" RW_LOCK_BIAS_STR ", %0"
   6.491 + 				 : "=m" (rw->lock) : : "memory");
   6.492 + }
   6.493 + 
   6.494 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-i386/system.h ./include/asm-i386/system.h
   6.495 +--- ../pristine-linux-2.6.16.13/include/asm-i386/system.h	2006-05-02 22:38:44.000000000 +0100
   6.496 ++++ ./include/asm-i386/system.h	2006-05-04 17:41:45.000000000 +0100
   6.497 +@@ -5,7 +5,7 @@
   6.498 + #include <linux/kernel.h>
   6.499 + #include <asm/segment.h>
   6.500 + #include <asm/cpufeature.h>
   6.501 +-#include <linux/bitops.h> /* for LOCK_PREFIX */
   6.502 ++#include <asm/smp_alt.h>
   6.503 + 
   6.504 + #ifdef __KERNEL__
   6.505 + 
   6.506 +@@ -271,19 +271,19 @@ static inline unsigned long __cmpxchg(vo
   6.507 + 	unsigned long prev;
   6.508 + 	switch (size) {
   6.509 + 	case 1:
   6.510 +-		__asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
   6.511 ++		__asm__ __volatile__(LOCK "cmpxchgb %b1,%2"
   6.512 + 				     : "=a"(prev)
   6.513 + 				     : "q"(new), "m"(*__xg(ptr)), "0"(old)
   6.514 + 				     : "memory");
   6.515 + 		return prev;
   6.516 + 	case 2:
   6.517 +-		__asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
   6.518 ++		__asm__ __volatile__(LOCK "cmpxchgw %w1,%2"
   6.519 + 				     : "=a"(prev)
   6.520 + 				     : "r"(new), "m"(*__xg(ptr)), "0"(old)
   6.521 + 				     : "memory");
   6.522 + 		return prev;
   6.523 + 	case 4:
   6.524 +-		__asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
   6.525 ++		__asm__ __volatile__(LOCK "cmpxchgl %1,%2"
   6.526 + 				     : "=a"(prev)
   6.527 + 				     : "r"(new), "m"(*__xg(ptr)), "0"(old)
   6.528 + 				     : "memory");
   6.529 +@@ -336,7 +336,7 @@ static inline unsigned long long __cmpxc
   6.530 + 				      unsigned long long new)
   6.531 + {
   6.532 + 	unsigned long long prev;
   6.533 +-	__asm__ __volatile__(LOCK_PREFIX "cmpxchg8b %3"
   6.534 ++	__asm__ __volatile__(LOCK "cmpxchg8b %3"
   6.535 + 			     : "=A"(prev)
   6.536 + 			     : "b"((unsigned long)new),
   6.537 + 			       "c"((unsigned long)(new >> 32)),
   6.538 +@@ -503,11 +503,55 @@ struct alt_instr { 
   6.539 + #endif
   6.540 + 
   6.541 + #ifdef CONFIG_SMP
   6.542 ++#if defined(CONFIG_SMP_ALTERNATIVES) && !defined(MODULE)
   6.543 ++#define smp_alt_mb(instr)                                           \
   6.544 ++__asm__ __volatile__("6667:\nnop\nnop\nnop\nnop\nnop\nnop\n6668:\n" \
   6.545 ++		     ".section __smp_alternatives,\"a\"\n"          \
   6.546 ++		     ".long 6667b\n"                                \
   6.547 ++                     ".long 6673f\n"                                \
   6.548 ++		     ".previous\n"                                  \
   6.549 ++		     ".section __smp_replacements,\"a\"\n"          \
   6.550 ++		     "6673:.byte 6668b-6667b\n"                     \
   6.551 ++		     ".byte 6670f-6669f\n"                          \
   6.552 ++		     ".byte 6671f-6670f\n"                          \
   6.553 ++                     ".byte 0\n"                                    \
   6.554 ++		     ".byte %c0\n"                                  \
   6.555 ++		     "6669:lock;addl $0,0(%%esp)\n"                 \
   6.556 ++		     "6670:" instr "\n"                             \
   6.557 ++		     "6671:\n"                                      \
   6.558 ++		     ".previous\n"                                  \
   6.559 ++		     :                                              \
   6.560 ++		     : "i" (X86_FEATURE_XMM2)                       \
   6.561 ++		     : "memory")
   6.562 ++#define smp_rmb() smp_alt_mb("lfence")
   6.563 ++#define smp_mb()  smp_alt_mb("mfence")
   6.564 ++#define set_mb(var, value) do {                                     \
   6.565 ++unsigned long __set_mb_temp;                                        \
   6.566 ++__asm__ __volatile__("6667:movl %1, %0\n6668:\n"                    \
   6.567 ++		     ".section __smp_alternatives,\"a\"\n"          \
   6.568 ++		     ".long 6667b\n"                                \
   6.569 ++		     ".long 6673f\n"                                \
   6.570 ++		     ".previous\n"                                  \
   6.571 ++		     ".section __smp_replacements,\"a\"\n"          \
   6.572 ++		     "6673: .byte 6668b-6667b\n"                    \
   6.573 ++		     ".byte 6670f-6669f\n"                          \
   6.574 ++		     ".byte 0\n"                                    \
   6.575 ++		     ".byte 6671f-6670f\n"                          \
   6.576 ++		     ".byte -1\n"                                   \
   6.577 ++		     "6669: xchg %1, %0\n"                          \
   6.578 ++		     "6670:movl %1, %0\n"                           \
   6.579 ++		     "6671:\n"                                      \
   6.580 ++		     ".previous\n"                                  \
   6.581 ++		     : "=m" (var), "=r" (__set_mb_temp)             \
   6.582 ++		     : "1" (value)                                  \
   6.583 ++		     : "memory"); } while (0)
   6.584 ++#else
   6.585 + #define smp_mb()	mb()
   6.586 + #define smp_rmb()	rmb()
   6.587 ++#define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
   6.588 ++#endif
   6.589 + #define smp_wmb()	wmb()
   6.590 + #define smp_read_barrier_depends()	read_barrier_depends()
   6.591 +-#define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
   6.592 + #else
   6.593 + #define smp_mb()	barrier()
   6.594 + #define smp_rmb()	barrier()
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/patches/linux-2.6.16.13/x86-increase-interrupt-vector-range.patch	Thu May 04 17:44:14 2006 +0100
     7.3 @@ -0,0 +1,89 @@
     7.4 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/kernel/entry.S ./arch/i386/kernel/entry.S
     7.5 +--- ../pristine-linux-2.6.16.13/arch/i386/kernel/entry.S	2006-05-02 22:38:44.000000000 +0100
     7.6 ++++ ./arch/i386/kernel/entry.S	2006-05-04 17:41:49.000000000 +0100
     7.7 +@@ -406,7 +406,7 @@ vector=0
     7.8 + ENTRY(irq_entries_start)
     7.9 + .rept NR_IRQS
    7.10 + 	ALIGN
    7.11 +-1:	pushl $vector-256
    7.12 ++1:	pushl $~(vector)
    7.13 + 	jmp common_interrupt
    7.14 + .data
    7.15 + 	.long 1b
    7.16 +@@ -423,7 +423,7 @@ common_interrupt:
    7.17 + 
    7.18 + #define BUILD_INTERRUPT(name, nr)	\
    7.19 + ENTRY(name)				\
    7.20 +-	pushl $nr-256;			\
    7.21 ++	pushl $~(nr);			\
    7.22 + 	SAVE_ALL			\
    7.23 + 	movl %esp,%eax;			\
    7.24 + 	call smp_/**/name;		\
    7.25 +diff -pruN ../pristine-linux-2.6.16.13/arch/i386/kernel/irq.c ./arch/i386/kernel/irq.c
    7.26 +--- ../pristine-linux-2.6.16.13/arch/i386/kernel/irq.c	2006-05-02 22:38:44.000000000 +0100
    7.27 ++++ ./arch/i386/kernel/irq.c	2006-05-04 17:41:49.000000000 +0100
    7.28 +@@ -53,8 +53,8 @@ static union irq_ctx *softirq_ctx[NR_CPU
    7.29 +  */
    7.30 + fastcall unsigned int do_IRQ(struct pt_regs *regs)
    7.31 + {	
    7.32 +-	/* high bits used in ret_from_ code */
    7.33 +-	int irq = regs->orig_eax & 0xff;
    7.34 ++	/* high bit used in ret_from_ code */
    7.35 ++	int irq = ~regs->orig_eax;
    7.36 + #ifdef CONFIG_4KSTACKS
    7.37 + 	union irq_ctx *curctx, *irqctx;
    7.38 + 	u32 *isp;
    7.39 +diff -pruN ../pristine-linux-2.6.16.13/arch/x86_64/kernel/entry.S ./arch/x86_64/kernel/entry.S
    7.40 +--- ../pristine-linux-2.6.16.13/arch/x86_64/kernel/entry.S	2006-05-02 22:38:44.000000000 +0100
    7.41 ++++ ./arch/x86_64/kernel/entry.S	2006-05-04 17:41:49.000000000 +0100
    7.42 +@@ -601,7 +601,7 @@ retint_kernel:	
    7.43 +  */		
    7.44 + 	.macro apicinterrupt num,func
    7.45 + 	INTR_FRAME
    7.46 +-	pushq $\num-256
    7.47 ++	pushq $~(\num)
    7.48 + 	CFI_ADJUST_CFA_OFFSET 8
    7.49 + 	interrupt \func
    7.50 + 	jmp ret_from_intr
    7.51 +diff -pruN ../pristine-linux-2.6.16.13/arch/x86_64/kernel/irq.c ./arch/x86_64/kernel/irq.c
    7.52 +--- ../pristine-linux-2.6.16.13/arch/x86_64/kernel/irq.c	2006-05-02 22:38:44.000000000 +0100
    7.53 ++++ ./arch/x86_64/kernel/irq.c	2006-05-04 17:41:49.000000000 +0100
    7.54 +@@ -96,8 +96,8 @@ skip:
    7.55 +  */
    7.56 + asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
    7.57 + {	
    7.58 +-	/* high bits used in ret_from_ code  */
    7.59 +-	unsigned irq = regs->orig_rax & 0xff;
    7.60 ++	/* high bit used in ret_from_ code  */
    7.61 ++	unsigned irq = ~regs->orig_rax;
    7.62 + 
    7.63 + 	exit_idle();
    7.64 + 	irq_enter();
    7.65 +diff -pruN ../pristine-linux-2.6.16.13/arch/x86_64/kernel/smp.c ./arch/x86_64/kernel/smp.c
    7.66 +--- ../pristine-linux-2.6.16.13/arch/x86_64/kernel/smp.c	2006-05-02 22:38:44.000000000 +0100
    7.67 ++++ ./arch/x86_64/kernel/smp.c	2006-05-04 17:41:49.000000000 +0100
    7.68 +@@ -135,10 +135,10 @@ asmlinkage void smp_invalidate_interrupt
    7.69 + 
    7.70 + 	cpu = smp_processor_id();
    7.71 + 	/*
    7.72 +-	 * orig_rax contains the interrupt vector - 256.
    7.73 ++	 * orig_rax contains the negated interrupt vector.
    7.74 + 	 * Use that to determine where the sender put the data.
    7.75 + 	 */
    7.76 +-	sender = regs->orig_rax + 256 - INVALIDATE_TLB_VECTOR_START;
    7.77 ++	sender = ~regs->orig_rax - INVALIDATE_TLB_VECTOR_START;
    7.78 + 	f = &per_cpu(flush_state, sender);
    7.79 + 
    7.80 + 	if (!cpu_isset(cpu, f->flush_cpumask))
    7.81 +diff -pruN ../pristine-linux-2.6.16.13/include/asm-x86_64/hw_irq.h ./include/asm-x86_64/hw_irq.h
    7.82 +--- ../pristine-linux-2.6.16.13/include/asm-x86_64/hw_irq.h	2006-05-02 22:38:44.000000000 +0100
    7.83 ++++ ./include/asm-x86_64/hw_irq.h	2006-05-04 17:41:49.000000000 +0100
    7.84 +@@ -127,7 +127,7 @@ asmlinkage void IRQ_NAME(nr); \
    7.85 + __asm__( \
    7.86 + "\n.p2align\n" \
    7.87 + "IRQ" #nr "_interrupt:\n\t" \
    7.88 +-	"push $" #nr "-256 ; " \
    7.89 ++	"push $~(" #nr ") ; " \
    7.90 + 	"jmp common_interrupt");
    7.91 + 
    7.92 + #if defined(CONFIG_X86_IO_APIC)
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/patches/linux-2.6.16.13/xenoprof-generic.patch	Thu May 04 17:44:14 2006 +0100
     8.3 @@ -0,0 +1,384 @@
     8.4 +diff -pruN ../pristine-linux-2.6.16.13/drivers/oprofile/buffer_sync.c ./drivers/oprofile/buffer_sync.c
     8.5 +--- ../pristine-linux-2.6.16.13/drivers/oprofile/buffer_sync.c	2006-05-02 22:38:44.000000000 +0100
     8.6 ++++ ./drivers/oprofile/buffer_sync.c	2006-05-04 17:41:51.000000000 +0100
     8.7 +@@ -6,6 +6,10 @@
     8.8 +  *
     8.9 +  * @author John Levon <levon@movementarian.org>
    8.10 +  *
    8.11 ++ * Modified by Aravind Menon for Xen
    8.12 ++ * These modifications are:
    8.13 ++ * Copyright (C) 2005 Hewlett-Packard Co.
    8.14 ++ *
    8.15 +  * This is the core of the buffer management. Each
    8.16 +  * CPU buffer is processed and entered into the
    8.17 +  * global event buffer. Such processing is necessary
    8.18 +@@ -275,15 +279,24 @@ static void add_cpu_switch(int i)
    8.19 + 	last_cookie = INVALID_COOKIE;
    8.20 + }
    8.21 + 
    8.22 +-static void add_kernel_ctx_switch(unsigned int in_kernel)
    8.23 ++static void add_cpu_mode_switch(unsigned int cpu_mode)
    8.24 + {
    8.25 + 	add_event_entry(ESCAPE_CODE);
    8.26 +-	if (in_kernel)
    8.27 +-		add_event_entry(KERNEL_ENTER_SWITCH_CODE); 
    8.28 +-	else
    8.29 +-		add_event_entry(KERNEL_EXIT_SWITCH_CODE); 
    8.30 ++	switch (cpu_mode) {
    8.31 ++	case CPU_MODE_USER:
    8.32 ++		add_event_entry(USER_ENTER_SWITCH_CODE);
    8.33 ++		break;
    8.34 ++	case CPU_MODE_KERNEL:
    8.35 ++		add_event_entry(KERNEL_ENTER_SWITCH_CODE);
    8.36 ++		break;
    8.37 ++	case CPU_MODE_XEN:
    8.38 ++		add_event_entry(XEN_ENTER_SWITCH_CODE);
    8.39 ++		break;
    8.40 ++	default:
    8.41 ++		break;
    8.42 ++	}
    8.43 + }
    8.44 +- 
    8.45 ++
    8.46 + static void
    8.47 + add_user_ctx_switch(struct task_struct const * task, unsigned long cookie)
    8.48 + {
    8.49 +@@ -348,9 +361,9 @@ static int add_us_sample(struct mm_struc
    8.50 +  * for later lookup from userspace.
    8.51 +  */
    8.52 + static int
    8.53 +-add_sample(struct mm_struct * mm, struct op_sample * s, int in_kernel)
    8.54 ++add_sample(struct mm_struct * mm, struct op_sample * s, int cpu_mode)
    8.55 + {
    8.56 +-	if (in_kernel) {
    8.57 ++	if (cpu_mode >= CPU_MODE_KERNEL) {
    8.58 + 		add_sample_entry(s->eip, s->event);
    8.59 + 		return 1;
    8.60 + 	} else if (mm) {
    8.61 +@@ -496,7 +509,7 @@ void sync_buffer(int cpu)
    8.62 + 	struct mm_struct *mm = NULL;
    8.63 + 	struct task_struct * new;
    8.64 + 	unsigned long cookie = 0;
    8.65 +-	int in_kernel = 1;
    8.66 ++	int cpu_mode = 1;
    8.67 + 	unsigned int i;
    8.68 + 	sync_buffer_state state = sb_buffer_start;
    8.69 + 	unsigned long available;
    8.70 +@@ -513,12 +526,12 @@ void sync_buffer(int cpu)
    8.71 + 		struct op_sample * s = &cpu_buf->buffer[cpu_buf->tail_pos];
    8.72 +  
    8.73 + 		if (is_code(s->eip)) {
    8.74 +-			if (s->event <= CPU_IS_KERNEL) {
    8.75 ++			if (s->event <= CPU_MODE_XEN) {
    8.76 + 				/* kernel/userspace switch */
    8.77 +-				in_kernel = s->event;
    8.78 ++				cpu_mode = s->event;
    8.79 + 				if (state == sb_buffer_start)
    8.80 + 					state = sb_sample_start;
    8.81 +-				add_kernel_ctx_switch(s->event);
    8.82 ++				add_cpu_mode_switch(s->event);
    8.83 + 			} else if (s->event == CPU_TRACE_BEGIN) {
    8.84 + 				state = sb_bt_start;
    8.85 + 				add_trace_begin();
    8.86 +@@ -536,7 +549,7 @@ void sync_buffer(int cpu)
    8.87 + 			}
    8.88 + 		} else {
    8.89 + 			if (state >= sb_bt_start &&
    8.90 +-			    !add_sample(mm, s, in_kernel)) {
    8.91 ++			    !add_sample(mm, s, cpu_mode)) {
    8.92 + 				if (state == sb_bt_start) {
    8.93 + 					state = sb_bt_ignore;
    8.94 + 					atomic_inc(&oprofile_stats.bt_lost_no_mapping);
    8.95 +diff -pruN ../pristine-linux-2.6.16.13/drivers/oprofile/cpu_buffer.c ./drivers/oprofile/cpu_buffer.c
    8.96 +--- ../pristine-linux-2.6.16.13/drivers/oprofile/cpu_buffer.c	2006-05-02 22:38:44.000000000 +0100
    8.97 ++++ ./drivers/oprofile/cpu_buffer.c	2006-05-04 17:41:51.000000000 +0100
    8.98 +@@ -6,6 +6,10 @@
    8.99 +  *
   8.100 +  * @author John Levon <levon@movementarian.org>
   8.101 +  *
   8.102 ++ * Modified by Aravind Menon for Xen
   8.103 ++ * These modifications are:
   8.104 ++ * Copyright (C) 2005 Hewlett-Packard Co.
   8.105 ++ *
   8.106 +  * Each CPU has a local buffer that stores PC value/event
   8.107 +  * pairs. We also log context switches when we notice them.
   8.108 +  * Eventually each CPU's buffer is processed into the global
   8.109 +@@ -58,7 +62,7 @@ int alloc_cpu_buffers(void)
   8.110 + 			goto fail;
   8.111 +  
   8.112 + 		b->last_task = NULL;
   8.113 +-		b->last_is_kernel = -1;
   8.114 ++		b->last_cpu_mode = -1;
   8.115 + 		b->tracing = 0;
   8.116 + 		b->buffer_size = buffer_size;
   8.117 + 		b->tail_pos = 0;
   8.118 +@@ -114,7 +118,7 @@ void cpu_buffer_reset(struct oprofile_cp
   8.119 + 	 * collected will populate the buffer with proper
   8.120 + 	 * values to initialize the buffer
   8.121 + 	 */
   8.122 +-	cpu_buf->last_is_kernel = -1;
   8.123 ++	cpu_buf->last_cpu_mode = -1;
   8.124 + 	cpu_buf->last_task = NULL;
   8.125 + }
   8.126 + 
   8.127 +@@ -164,13 +168,13 @@ add_code(struct oprofile_cpu_buffer * bu
   8.128 +  * because of the head/tail separation of the writer and reader
   8.129 +  * of the CPU buffer.
   8.130 +  *
   8.131 +- * is_kernel is needed because on some architectures you cannot
   8.132 ++ * cpu_mode is needed because on some architectures you cannot
   8.133 +  * tell if you are in kernel or user space simply by looking at
   8.134 +- * pc. We tag this in the buffer by generating kernel enter/exit
   8.135 +- * events whenever is_kernel changes
   8.136 ++ * pc. We tag this in the buffer by generating kernel/user (and xen)
   8.137 ++ *  enter events whenever cpu_mode changes
   8.138 +  */
   8.139 + static int log_sample(struct oprofile_cpu_buffer * cpu_buf, unsigned long pc,
   8.140 +-		      int is_kernel, unsigned long event)
   8.141 ++		      int cpu_mode, unsigned long event)
   8.142 + {
   8.143 + 	struct task_struct * task;
   8.144 + 
   8.145 +@@ -181,16 +185,16 @@ static int log_sample(struct oprofile_cp
   8.146 + 		return 0;
   8.147 + 	}
   8.148 + 
   8.149 +-	is_kernel = !!is_kernel;
   8.150 ++	WARN_ON(cpu_mode > CPU_MODE_XEN);
   8.151 + 
   8.152 + 	task = current;
   8.153 + 
   8.154 + 	/* notice a switch from user->kernel or vice versa */
   8.155 +-	if (cpu_buf->last_is_kernel != is_kernel) {
   8.156 +-		cpu_buf->last_is_kernel = is_kernel;
   8.157 +-		add_code(cpu_buf, is_kernel);
   8.158 ++	if (cpu_buf->last_cpu_mode != cpu_mode) {
   8.159 ++		cpu_buf->last_cpu_mode = cpu_mode;
   8.160 ++		add_code(cpu_buf, cpu_mode);
   8.161 + 	}
   8.162 +-
   8.163 ++	
   8.164 + 	/* notice a task switch */
   8.165 + 	if (cpu_buf->last_task != task) {
   8.166 + 		cpu_buf->last_task = task;
   8.167 +diff -pruN ../pristine-linux-2.6.16.13/drivers/oprofile/cpu_buffer.h ./drivers/oprofile/cpu_buffer.h
   8.168 +--- ../pristine-linux-2.6.16.13/drivers/oprofile/cpu_buffer.h	2006-05-02 22:38:44.000000000 +0100
   8.169 ++++ ./drivers/oprofile/cpu_buffer.h	2006-05-04 17:41:51.000000000 +0100
   8.170 +@@ -36,7 +36,7 @@ struct oprofile_cpu_buffer {
   8.171 + 	volatile unsigned long tail_pos;
   8.172 + 	unsigned long buffer_size;
   8.173 + 	struct task_struct * last_task;
   8.174 +-	int last_is_kernel;
   8.175 ++	int last_cpu_mode;
   8.176 + 	int tracing;
   8.177 + 	struct op_sample * buffer;
   8.178 + 	unsigned long sample_received;
   8.179 +@@ -51,7 +51,9 @@ extern struct oprofile_cpu_buffer cpu_bu
   8.180 + void cpu_buffer_reset(struct oprofile_cpu_buffer * cpu_buf);
   8.181 + 
   8.182 + /* transient events for the CPU buffer -> event buffer */
   8.183 +-#define CPU_IS_KERNEL 1
   8.184 +-#define CPU_TRACE_BEGIN 2
   8.185 ++#define CPU_MODE_USER    0
   8.186 ++#define CPU_MODE_KERNEL  1
   8.187 ++#define CPU_MODE_XEN     2
   8.188 ++#define CPU_TRACE_BEGIN  3
   8.189 + 
   8.190 + #endif /* OPROFILE_CPU_BUFFER_H */
   8.191 +diff -pruN ../pristine-linux-2.6.16.13/drivers/oprofile/event_buffer.h ./drivers/oprofile/event_buffer.h
   8.192 +--- ../pristine-linux-2.6.16.13/drivers/oprofile/event_buffer.h	2006-05-02 22:38:44.000000000 +0100
   8.193 ++++ ./drivers/oprofile/event_buffer.h	2006-05-04 17:41:51.000000000 +0100
   8.194 +@@ -29,11 +29,12 @@ void wake_up_buffer_waiter(void);
   8.195 + #define CPU_SWITCH_CODE 		2
   8.196 + #define COOKIE_SWITCH_CODE 		3
   8.197 + #define KERNEL_ENTER_SWITCH_CODE	4
   8.198 +-#define KERNEL_EXIT_SWITCH_CODE		5
   8.199 ++#define USER_ENTER_SWITCH_CODE		5
   8.200 + #define MODULE_LOADED_CODE		6
   8.201 + #define CTX_TGID_CODE			7
   8.202 + #define TRACE_BEGIN_CODE		8
   8.203 + #define TRACE_END_CODE			9
   8.204 ++#define XEN_ENTER_SWITCH_CODE		10
   8.205 +  
   8.206 + #define INVALID_COOKIE ~0UL
   8.207 + #define NO_COOKIE 0UL
   8.208 +diff -pruN ../pristine-linux-2.6.16.13/drivers/oprofile/oprof.c ./drivers/oprofile/oprof.c
   8.209 +--- ../pristine-linux-2.6.16.13/drivers/oprofile/oprof.c	2006-05-02 22:38:44.000000000 +0100
   8.210 ++++ ./drivers/oprofile/oprof.c	2006-05-04 17:41:51.000000000 +0100
   8.211 +@@ -5,6 +5,10 @@
   8.212 +  * @remark Read the file COPYING
   8.213 +  *
   8.214 +  * @author John Levon <levon@movementarian.org>
   8.215 ++ *
   8.216 ++ * Modified by Aravind Menon for Xen
   8.217 ++ * These modifications are:
   8.218 ++ * Copyright (C) 2005 Hewlett-Packard Co.
   8.219 +  */
   8.220 + 
   8.221 + #include <linux/kernel.h>
   8.222 +@@ -19,7 +23,7 @@
   8.223 + #include "cpu_buffer.h"
   8.224 + #include "buffer_sync.h"
   8.225 + #include "oprofile_stats.h"
   8.226 +- 
   8.227 ++
   8.228 + struct oprofile_operations oprofile_ops;
   8.229 + 
   8.230 + unsigned long oprofile_started;
   8.231 +@@ -33,6 +37,17 @@ static DECLARE_MUTEX(start_sem);
   8.232 +  */
   8.233 + static int timer = 0;
   8.234 + 
   8.235 ++extern unsigned int adomains;
   8.236 ++extern int active_domains[MAX_OPROF_DOMAINS];
   8.237 ++
   8.238 ++int oprofile_set_active(void)
   8.239 ++{
   8.240 ++	if (oprofile_ops.set_active)
   8.241 ++		return oprofile_ops.set_active(active_domains, adomains);
   8.242 ++
   8.243 ++	return -EINVAL;
   8.244 ++}
   8.245 ++
   8.246 + int oprofile_setup(void)
   8.247 + {
   8.248 + 	int err;
   8.249 +diff -pruN ../pristine-linux-2.6.16.13/drivers/oprofile/oprof.h ./drivers/oprofile/oprof.h
   8.250 +--- ../pristine-linux-2.6.16.13/drivers/oprofile/oprof.h	2006-05-02 22:38:44.000000000 +0100
   8.251 ++++ ./drivers/oprofile/oprof.h	2006-05-04 17:41:51.000000000 +0100
   8.252 +@@ -35,5 +35,7 @@ void oprofile_create_files(struct super_
   8.253 + void oprofile_timer_init(struct oprofile_operations * ops);
   8.254 + 
   8.255 + int oprofile_set_backtrace(unsigned long depth);
   8.256 ++
   8.257 ++int oprofile_set_active(void);
   8.258 +  
   8.259 + #endif /* OPROF_H */
   8.260 +diff -pruN ../pristine-linux-2.6.16.13/drivers/oprofile/oprofile_files.c ./drivers/oprofile/oprofile_files.c
   8.261 +--- ../pristine-linux-2.6.16.13/drivers/oprofile/oprofile_files.c	2006-05-02 22:38:44.000000000 +0100
   8.262 ++++ ./drivers/oprofile/oprofile_files.c	2006-05-04 17:41:51.000000000 +0100
   8.263 +@@ -5,15 +5,21 @@
   8.264 +  * @remark Read the file COPYING
   8.265 +  *
   8.266 +  * @author John Levon <levon@movementarian.org>
   8.267 ++ *
   8.268 ++ * Modified by Aravind Menon for Xen
   8.269 ++ * These modifications are:
   8.270 ++ * Copyright (C) 2005 Hewlett-Packard Co.	
   8.271 +  */
   8.272 + 
   8.273 + #include <linux/fs.h>
   8.274 + #include <linux/oprofile.h>
   8.275 ++#include <asm/uaccess.h>
   8.276 ++#include <linux/ctype.h>
   8.277 + 
   8.278 + #include "event_buffer.h"
   8.279 + #include "oprofile_stats.h"
   8.280 + #include "oprof.h"
   8.281 +- 
   8.282 ++
   8.283 + unsigned long fs_buffer_size = 131072;
   8.284 + unsigned long fs_cpu_buffer_size = 8192;
   8.285 + unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
   8.286 +@@ -117,11 +123,79 @@ static ssize_t dump_write(struct file * 
   8.287 + static struct file_operations dump_fops = {
   8.288 + 	.write		= dump_write,
   8.289 + };
   8.290 +- 
   8.291 ++
   8.292 ++#define TMPBUFSIZE 512
   8.293 ++
   8.294 ++unsigned int adomains = 0;
   8.295 ++long active_domains[MAX_OPROF_DOMAINS];
   8.296 ++
   8.297 ++static ssize_t adomain_write(struct file * file, char const __user * buf, 
   8.298 ++			     size_t count, loff_t * offset)
   8.299 ++{
   8.300 ++	char tmpbuf[TMPBUFSIZE];
   8.301 ++	char * startp = tmpbuf;
   8.302 ++	char * endp = tmpbuf;
   8.303 ++	int i;
   8.304 ++	unsigned long val;
   8.305 ++	
   8.306 ++	if (*offset)
   8.307 ++		return -EINVAL;	
   8.308 ++	if (!count)
   8.309 ++		return 0;
   8.310 ++	if (count > TMPBUFSIZE - 1)
   8.311 ++		return -EINVAL;
   8.312 ++
   8.313 ++	memset(tmpbuf, 0x0, TMPBUFSIZE);
   8.314 ++
   8.315 ++	if (copy_from_user(tmpbuf, buf, count))
   8.316 ++		return -EFAULT;
   8.317 ++	
   8.318 ++	for (i = 0; i < MAX_OPROF_DOMAINS; i++)
   8.319 ++		active_domains[i] = -1;
   8.320 ++	adomains = 0;
   8.321 ++
   8.322 ++	while (1) {
   8.323 ++		val = simple_strtol(startp, &endp, 0);
   8.324 ++		if (endp == startp)
   8.325 ++			break;
   8.326 ++		while (ispunct(*endp))
   8.327 ++			endp++;
   8.328 ++		active_domains[adomains++] = val;
   8.329 ++		if (adomains >= MAX_OPROF_DOMAINS)
   8.330 ++			break;
   8.331 ++		startp = endp;
   8.332 ++	}
   8.333 ++	if (oprofile_set_active())
   8.334 ++		return -EINVAL; 
   8.335 ++	return count;
   8.336 ++}
   8.337 ++
   8.338 ++static ssize_t adomain_read(struct file * file, char __user * buf, 
   8.339 ++			    size_t count, loff_t * offset)
   8.340 ++{
   8.341 ++	char tmpbuf[TMPBUFSIZE];
   8.342 ++	size_t len = 0;
   8.343 ++	int i;
   8.344 ++	/* This is all screwed up if we run out of space */
   8.345 ++	for (i = 0; i < adomains; i++) 
   8.346 ++		len += snprintf(tmpbuf + len, TMPBUFSIZE - len, 
   8.347 ++				"%u ", (unsigned int)active_domains[i]);
   8.348 ++	len += snprintf(tmpbuf + len, TMPBUFSIZE - len, "\n");
   8.349 ++	return simple_read_from_buffer((void __user *)buf, count, 
   8.350 ++				       offset, tmpbuf, len);
   8.351 ++}
   8.352 ++
   8.353 ++
   8.354 ++static struct file_operations active_domain_ops = {
   8.355 ++	.read		= adomain_read,
   8.356 ++	.write		= adomain_write,
   8.357 ++};
   8.358 ++
   8.359 + void oprofile_create_files(struct super_block * sb, struct dentry * root)
   8.360 + {
   8.361 + 	oprofilefs_create_file(sb, root, "enable", &enable_fops);
   8.362 + 	oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
   8.363 ++	oprofilefs_create_file(sb, root, "active_domains", &active_domain_ops);
   8.364 + 	oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
   8.365 + 	oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
   8.366 + 	oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
   8.367 +diff -pruN ../pristine-linux-2.6.16.13/include/linux/oprofile.h ./include/linux/oprofile.h
   8.368 +--- ../pristine-linux-2.6.16.13/include/linux/oprofile.h	2006-05-02 22:38:44.000000000 +0100
   8.369 ++++ ./include/linux/oprofile.h	2006-05-04 17:41:51.000000000 +0100
   8.370 +@@ -16,6 +16,8 @@
   8.371 + #include <linux/types.h>
   8.372 + #include <linux/spinlock.h>
   8.373 + #include <asm/atomic.h>
   8.374 ++
   8.375 ++#include <xen/interface/xenoprof.h>
   8.376 +  
   8.377 + struct super_block;
   8.378 + struct dentry;
   8.379 +@@ -27,6 +29,8 @@ struct oprofile_operations {
   8.380 + 	/* create any necessary configuration files in the oprofile fs.
   8.381 + 	 * Optional. */
   8.382 + 	int (*create_files)(struct super_block * sb, struct dentry * root);
   8.383 ++	/* setup active domains with Xen */
   8.384 ++	int (*set_active)(int *active_domains, unsigned int adomains);
   8.385 + 	/* Do any necessary interrupt setup. Optional. */
   8.386 + 	int (*setup)(void);
   8.387 + 	/* Do any necessary interrupt shutdown. Optional. */
     9.1 --- a/patches/linux-2.6.16/device_bind.patch	Thu May 04 17:38:25 2006 +0100
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,14 +0,0 @@
     9.4 ---- linux-2.6.16/drivers/base/bus.c	2006-03-16 10:50:20.000000000 -0500
     9.5 -+++ linux-2.6.16/drivers/base/bus.c	2006-03-16 11:02:08.000000000 -0500
     9.6 -@@ -188,6 +188,11 @@ static ssize_t driver_bind(struct device
     9.7 - 		up(&dev->sem);
     9.8 - 		if (dev->parent)
     9.9 - 			up(&dev->parent->sem);
    9.10 -+
    9.11 -+		if (err > 0) 		/* success */
    9.12 -+			err = count;
    9.13 -+		else if (err == 0)	/* driver didn't accept device */
    9.14 -+			err = -ENODEV;
    9.15 - 	}
    9.16 - 	put_device(dev);
    9.17 - 	put_bus(bus);
    10.1 --- a/patches/linux-2.6.16/i386-mach-io-check-nmi.patch	Thu May 04 17:38:25 2006 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,45 +0,0 @@
    10.4 -diff -pruN ../pristine-linux-2.6.16/arch/i386/kernel/traps.c ./arch/i386/kernel/traps.c
    10.5 ---- ../pristine-linux-2.6.16/arch/i386/kernel/traps.c	2006-03-20 05:53:29.000000000 +0000
    10.6 -+++ ./arch/i386/kernel/traps.c	2006-03-20 19:38:17.000000000 +0000
    10.7 -@@ -567,18 +567,11 @@ static void mem_parity_error(unsigned ch
    10.8 - 
    10.9 - static void io_check_error(unsigned char reason, struct pt_regs * regs)
   10.10 - {
   10.11 --	unsigned long i;
   10.12 --
   10.13 - 	printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n");
   10.14 - 	show_registers(regs);
   10.15 - 
   10.16 - 	/* Re-enable the IOCK line, wait for a few seconds */
   10.17 --	reason = (reason & 0xf) | 8;
   10.18 --	outb(reason, 0x61);
   10.19 --	i = 2000;
   10.20 --	while (--i) udelay(1000);
   10.21 --	reason &= ~8;
   10.22 --	outb(reason, 0x61);
   10.23 -+	clear_io_check_error(reason);
   10.24 - }
   10.25 - 
   10.26 - static void unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
   10.27 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/mach-default/mach_traps.h ./include/asm-i386/mach-default/mach_traps.h
   10.28 ---- ../pristine-linux-2.6.16/include/asm-i386/mach-default/mach_traps.h	2006-03-20 05:53:29.000000000 +0000
   10.29 -+++ ./include/asm-i386/mach-default/mach_traps.h	2006-03-20 19:38:17.000000000 +0000
   10.30 -@@ -15,6 +15,18 @@ static inline void clear_mem_error(unsig
   10.31 - 	outb(reason, 0x61);
   10.32 - }
   10.33 - 
   10.34 -+static inline void clear_io_check_error(unsigned char reason)
   10.35 -+{
   10.36 -+	unsigned long i;
   10.37 -+
   10.38 -+	reason = (reason & 0xf) | 8;
   10.39 -+	outb(reason, 0x61);
   10.40 -+	i = 2000;
   10.41 -+	while (--i) udelay(1000);
   10.42 -+	reason &= ~8;
   10.43 -+	outb(reason, 0x61);
   10.44 -+}
   10.45 -+
   10.46 - static inline unsigned char get_nmi_reason(void)
   10.47 - {
   10.48 - 	return inb(0x61);
    11.1 --- a/patches/linux-2.6.16/net-csum.patch	Thu May 04 17:38:25 2006 +0100
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,64 +0,0 @@
    11.4 -diff -pruN ../pristine-linux-2.6.16/net/ipv4/netfilter/ip_nat_proto_tcp.c ./net/ipv4/netfilter/ip_nat_proto_tcp.c
    11.5 ---- ../pristine-linux-2.6.16/net/ipv4/netfilter/ip_nat_proto_tcp.c	2006-03-20 05:53:29.000000000 +0000
    11.6 -+++ ./net/ipv4/netfilter/ip_nat_proto_tcp.c	2006-03-20 19:38:19.000000000 +0000
    11.7 -@@ -129,10 +129,14 @@ tcp_manip_pkt(struct sk_buff **pskb,
    11.8 - 	if (hdrsize < sizeof(*hdr))
    11.9 - 		return 1;
   11.10 - 
   11.11 --	hdr->check = ip_nat_cheat_check(~oldip, newip,
   11.12 -+	if ((*pskb)->proto_csum_blank) {
   11.13 -+		hdr->check = ip_nat_cheat_check(oldip, ~newip, hdr->check);
   11.14 -+	} else {
   11.15 -+		hdr->check = ip_nat_cheat_check(~oldip, newip,
   11.16 - 					ip_nat_cheat_check(oldport ^ 0xFFFF,
   11.17 - 							   newport,
   11.18 - 							   hdr->check));
   11.19 -+	}
   11.20 - 	return 1;
   11.21 - }
   11.22 - 
   11.23 -diff -pruN ../pristine-linux-2.6.16/net/ipv4/netfilter/ip_nat_proto_udp.c ./net/ipv4/netfilter/ip_nat_proto_udp.c
   11.24 ---- ../pristine-linux-2.6.16/net/ipv4/netfilter/ip_nat_proto_udp.c	2006-03-20 05:53:29.000000000 +0000
   11.25 -+++ ./net/ipv4/netfilter/ip_nat_proto_udp.c	2006-03-20 19:38:19.000000000 +0000
   11.26 -@@ -113,11 +113,16 @@ udp_manip_pkt(struct sk_buff **pskb,
   11.27 - 		newport = tuple->dst.u.udp.port;
   11.28 - 		portptr = &hdr->dest;
   11.29 - 	}
   11.30 --	if (hdr->check) /* 0 is a special case meaning no checksum */
   11.31 --		hdr->check = ip_nat_cheat_check(~oldip, newip,
   11.32 -+	if (hdr->check) { /* 0 is a special case meaning no checksum */
   11.33 -+		if ((*pskb)->proto_csum_blank) {
   11.34 -+			hdr->check = ip_nat_cheat_check(oldip, ~newip, hdr->check);
   11.35 -+		} else {
   11.36 -+			hdr->check = ip_nat_cheat_check(~oldip, newip,
   11.37 - 					ip_nat_cheat_check(*portptr ^ 0xFFFF,
   11.38 - 							   newport,
   11.39 - 							   hdr->check));
   11.40 -+		}
   11.41 -+	}
   11.42 - 	*portptr = newport;
   11.43 - 	return 1;
   11.44 - }
   11.45 -diff -r 601fa226a761 net/ipv4/xfrm4_output.c
   11.46 ---- a/net/ipv4/xfrm4_output.c	Wed Apr 19 18:52:30 2006
   11.47 -+++ b/net/ipv4/xfrm4_output.c	Thu Apr 20 15:49:40 2006
   11.48 -@@ -16,6 +16,8 @@
   11.49 - #include <net/ip.h>
   11.50 - #include <net/xfrm.h>
   11.51 - #include <net/icmp.h>
   11.52 -+
   11.53 -+extern int skb_checksum_setup(struct sk_buff *skb);
   11.54 - 
   11.55 - /* Add encapsulation header.
   11.56 -  *
   11.57 -@@ -103,6 +105,10 @@
   11.58 - 	struct xfrm_state *x = dst->xfrm;
   11.59 - 	int err;
   11.60 - 	
   11.61 -+	err = skb_checksum_setup(skb);
   11.62 -+	if (err)
   11.63 -+		goto error_nolock;
   11.64 -+
   11.65 - 	if (skb->ip_summed == CHECKSUM_HW) {
   11.66 - 		err = skb_checksum_help(skb, 0);
   11.67 - 		if (err)
    12.1 --- a/patches/linux-2.6.16/pmd-shared.patch	Thu May 04 17:38:25 2006 +0100
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,111 +0,0 @@
    12.4 -diff -pruN ../pristine-linux-2.6.16/arch/i386/mm/pageattr.c ./arch/i386/mm/pageattr.c
    12.5 ---- ../pristine-linux-2.6.16/arch/i386/mm/pageattr.c	2006-03-20 05:53:29.000000000 +0000
    12.6 -+++ ./arch/i386/mm/pageattr.c	2006-03-20 19:38:23.000000000 +0000
    12.7 -@@ -78,7 +78,7 @@ static void set_pmd_pte(pte_t *kpte, uns
    12.8 - 	unsigned long flags;
    12.9 - 
   12.10 - 	set_pte_atomic(kpte, pte); 	/* change init_mm */
   12.11 --	if (PTRS_PER_PMD > 1)
   12.12 -+	if (HAVE_SHARED_KERNEL_PMD)
   12.13 - 		return;
   12.14 - 
   12.15 - 	spin_lock_irqsave(&pgd_lock, flags);
   12.16 -diff -pruN ../pristine-linux-2.6.16/arch/i386/mm/pgtable.c ./arch/i386/mm/pgtable.c
   12.17 ---- ../pristine-linux-2.6.16/arch/i386/mm/pgtable.c	2006-03-20 05:53:29.000000000 +0000
   12.18 -+++ ./arch/i386/mm/pgtable.c	2006-03-20 19:38:23.000000000 +0000
   12.19 -@@ -215,9 +215,10 @@ void pgd_ctor(void *pgd, kmem_cache_t *c
   12.20 - 		spin_lock_irqsave(&pgd_lock, flags);
   12.21 - 	}
   12.22 - 
   12.23 --	clone_pgd_range((pgd_t *)pgd + USER_PTRS_PER_PGD,
   12.24 --			swapper_pg_dir + USER_PTRS_PER_PGD,
   12.25 --			KERNEL_PGD_PTRS);
   12.26 -+	if (PTRS_PER_PMD == 1 || HAVE_SHARED_KERNEL_PMD)
   12.27 -+		clone_pgd_range((pgd_t *)pgd + USER_PTRS_PER_PGD,
   12.28 -+				swapper_pg_dir + USER_PTRS_PER_PGD,
   12.29 -+				KERNEL_PGD_PTRS);
   12.30 - 	if (PTRS_PER_PMD > 1)
   12.31 - 		return;
   12.32 - 
   12.33 -@@ -249,6 +250,30 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
   12.34 - 			goto out_oom;
   12.35 - 		set_pgd(&pgd[i], __pgd(1 + __pa(pmd)));
   12.36 - 	}
   12.37 -+
   12.38 -+	if (!HAVE_SHARED_KERNEL_PMD) {
   12.39 -+		unsigned long flags;
   12.40 -+
   12.41 -+		for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
   12.42 -+			pmd_t *pmd = kmem_cache_alloc(pmd_cache, GFP_KERNEL);
   12.43 -+			if (!pmd)
   12.44 -+				goto out_oom;
   12.45 -+			set_pgd(&pgd[USER_PTRS_PER_PGD], __pgd(1 + __pa(pmd)));
   12.46 -+		}
   12.47 -+
   12.48 -+		spin_lock_irqsave(&pgd_lock, flags);
   12.49 -+		for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
   12.50 -+			unsigned long v = (unsigned long)i << PGDIR_SHIFT;
   12.51 -+			pgd_t *kpgd = pgd_offset_k(v);
   12.52 -+			pud_t *kpud = pud_offset(kpgd, v);
   12.53 -+			pmd_t *kpmd = pmd_offset(kpud, v);
   12.54 -+			pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
   12.55 -+			memcpy(pmd, kpmd, PAGE_SIZE);
   12.56 -+		}
   12.57 -+		pgd_list_add(pgd);
   12.58 -+		spin_unlock_irqrestore(&pgd_lock, flags);
   12.59 -+	}
   12.60 -+
   12.61 - 	return pgd;
   12.62 - 
   12.63 - out_oom:
   12.64 -@@ -263,9 +288,23 @@ void pgd_free(pgd_t *pgd)
   12.65 - 	int i;
   12.66 - 
   12.67 - 	/* in the PAE case user pgd entries are overwritten before usage */
   12.68 --	if (PTRS_PER_PMD > 1)
   12.69 --		for (i = 0; i < USER_PTRS_PER_PGD; ++i)
   12.70 --			kmem_cache_free(pmd_cache, (void *)__va(pgd_val(pgd[i])-1));
   12.71 -+	if (PTRS_PER_PMD > 1) {
   12.72 -+		for (i = 0; i < USER_PTRS_PER_PGD; ++i) {
   12.73 -+			pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
   12.74 -+			kmem_cache_free(pmd_cache, pmd);
   12.75 -+		}
   12.76 -+		if (!HAVE_SHARED_KERNEL_PMD) {
   12.77 -+			unsigned long flags;
   12.78 -+			spin_lock_irqsave(&pgd_lock, flags);
   12.79 -+			pgd_list_del(pgd);
   12.80 -+			spin_unlock_irqrestore(&pgd_lock, flags);
   12.81 -+			for (i = USER_PTRS_PER_PGD; i < PTRS_PER_PGD; i++) {
   12.82 -+				pmd_t *pmd = (void *)__va(pgd_val(pgd[i])-1);
   12.83 -+				memset(pmd, 0, PTRS_PER_PMD*sizeof(pmd_t));
   12.84 -+				kmem_cache_free(pmd_cache, pmd);
   12.85 -+			}
   12.86 -+		}
   12.87 -+	}
   12.88 - 	/* in the non-PAE case, free_pgtables() clears user pgd entries */
   12.89 - 	kmem_cache_free(pgd_cache, pgd);
   12.90 - }
   12.91 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/pgtable-2level-defs.h ./include/asm-i386/pgtable-2level-defs.h
   12.92 ---- ../pristine-linux-2.6.16/include/asm-i386/pgtable-2level-defs.h	2006-03-20 05:53:29.000000000 +0000
   12.93 -+++ ./include/asm-i386/pgtable-2level-defs.h	2006-03-20 19:38:23.000000000 +0000
   12.94 -@@ -1,6 +1,8 @@
   12.95 - #ifndef _I386_PGTABLE_2LEVEL_DEFS_H
   12.96 - #define _I386_PGTABLE_2LEVEL_DEFS_H
   12.97 - 
   12.98 -+#define HAVE_SHARED_KERNEL_PMD 0
   12.99 -+
  12.100 - /*
  12.101 -  * traditional i386 two-level paging structure:
  12.102 -  */
  12.103 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/pgtable-3level-defs.h ./include/asm-i386/pgtable-3level-defs.h
  12.104 ---- ../pristine-linux-2.6.16/include/asm-i386/pgtable-3level-defs.h	2006-03-20 05:53:29.000000000 +0000
  12.105 -+++ ./include/asm-i386/pgtable-3level-defs.h	2006-03-20 19:38:23.000000000 +0000
  12.106 -@@ -1,6 +1,8 @@
  12.107 - #ifndef _I386_PGTABLE_3LEVEL_DEFS_H
  12.108 - #define _I386_PGTABLE_3LEVEL_DEFS_H
  12.109 - 
  12.110 -+#define HAVE_SHARED_KERNEL_PMD 1
  12.111 -+
  12.112 - /*
  12.113 -  * PGDIR_SHIFT determines what a top-level page table entry can map
  12.114 -  */
    13.1 --- a/patches/linux-2.6.16/rename-TSS_sysenter_esp0-SYSENTER_stack_esp0.patch	Thu May 04 17:38:25 2006 +0100
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,31 +0,0 @@
    13.4 -Index: sysenter/linux-2.6-xen-sparse/arch/i386/kernel/entry.S
    13.5 -===================================================================
    13.6 ---- linux-2.6.16.orig/arch/i386/kernel/entry.S	2006-04-05 11:12:51.000000000 +0100
    13.7 -+++ linux-2.6.16/arch/i386/kernel/entry.S	2006-04-05 11:12:52.000000000 +0100
    13.8 -@@ -177,7 +177,7 @@
    13.9 - 
   13.10 - 	# sysenter call handler stub
   13.11 - ENTRY(sysenter_entry)
   13.12 --	movl TSS_sysenter_esp0(%esp),%esp
   13.13 -+	movl SYSENTER_stack_esp0(%esp),%esp
   13.14 - sysenter_past_esp:
   13.15 - 	sti
   13.16 - 	pushl $(__USER_DS)
   13.17 -@@ -492,7 +492,7 @@
   13.18 -  * that sets up the real kernel stack. Check here, since we can't
   13.19 -  * allow the wrong stack to be used.
   13.20 -  *
   13.21 -- * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
   13.22 -+ * "SYSENTER_stack_esp0+12" is because the NMI/debug handler will have
   13.23 -  * already pushed 3 words if it hits on the sysenter instruction:
   13.24 -  * eflags, cs and eip.
   13.25 -  *
   13.26 -@@ -504,7 +504,7 @@
   13.27 - 	cmpw $__KERNEL_CS,4(%esp);		\
   13.28 - 	jne ok;					\
   13.29 - label:						\
   13.30 --	movl TSS_sysenter_esp0+offset(%esp),%esp;	\
   13.31 -+	movl SYSENTER_stack_esp0+offset(%esp),%esp;	\
   13.32 - 	pushfl;					\
   13.33 - 	pushl $__KERNEL_CS;			\
   13.34 - 	pushl $sysenter_past_esp
    14.1 --- a/patches/linux-2.6.16/smp-alts.patch	Thu May 04 17:38:25 2006 +0100
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,591 +0,0 @@
    14.4 -diff -pruN ../pristine-linux-2.6.16/arch/i386/Kconfig ./arch/i386/Kconfig
    14.5 ---- ../pristine-linux-2.6.16/arch/i386/Kconfig	2006-03-20 05:53:29.000000000 +0000
    14.6 -+++ ./arch/i386/Kconfig	2006-03-20 19:38:27.000000000 +0000
    14.7 -@@ -202,6 +202,19 @@ config SMP
    14.8 - 
    14.9 - 	  If you don't know what to do here, say N.
   14.10 - 
   14.11 -+config SMP_ALTERNATIVES
   14.12 -+	bool "SMP alternatives support (EXPERIMENTAL)"
   14.13 -+	depends on SMP && EXPERIMENTAL
   14.14 -+	help
   14.15 -+	  Try to reduce the overhead of running an SMP kernel on a uniprocessor
   14.16 -+	  host slightly by replacing certain key instruction sequences
   14.17 -+	  according to whether we currently have more than one CPU available.
   14.18 -+	  This should provide a noticeable boost to performance when
   14.19 -+	  running SMP kernels on UP machines, and have negligible impact
   14.20 -+	  when running on an true SMP host.
   14.21 -+
   14.22 -+          If unsure, say N.
   14.23 -+	  
   14.24 - config NR_CPUS
   14.25 - 	int "Maximum number of CPUs (2-255)"
   14.26 - 	range 2 255
   14.27 -diff -pruN ../pristine-linux-2.6.16/arch/i386/kernel/Makefile ./arch/i386/kernel/Makefile
   14.28 ---- ../pristine-linux-2.6.16/arch/i386/kernel/Makefile	2006-03-20 05:53:29.000000000 +0000
   14.29 -+++ ./arch/i386/kernel/Makefile	2006-03-20 19:38:27.000000000 +0000
   14.30 -@@ -37,6 +37,7 @@ obj-$(CONFIG_EFI) 		+= efi.o efi_stub.o
   14.31 - obj-$(CONFIG_DOUBLEFAULT) 	+= doublefault.o
   14.32 - obj-$(CONFIG_VM86)		+= vm86.o
   14.33 - obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
   14.34 -+obj-$(CONFIG_SMP_ALTERNATIVES)  += smpalts.o
   14.35 - 
   14.36 - EXTRA_AFLAGS   := -traditional
   14.37 - 
   14.38 -diff -pruN ../pristine-linux-2.6.16/arch/i386/kernel/smpalts.c ./arch/i386/kernel/smpalts.c
   14.39 ---- ../pristine-linux-2.6.16/arch/i386/kernel/smpalts.c	1970-01-01 01:00:00.000000000 +0100
   14.40 -+++ ./arch/i386/kernel/smpalts.c	2006-03-20 19:38:27.000000000 +0000
   14.41 -@@ -0,0 +1,85 @@
   14.42 -+#include <linux/kernel.h>
   14.43 -+#include <asm/system.h>
   14.44 -+#include <asm/smp_alt.h>
   14.45 -+#include <asm/processor.h>
   14.46 -+#include <asm/string.h>
   14.47 -+
   14.48 -+struct smp_replacement_record {
   14.49 -+	unsigned char targ_size;
   14.50 -+	unsigned char smp1_size;
   14.51 -+	unsigned char smp2_size;
   14.52 -+	unsigned char up_size;
   14.53 -+	unsigned char feature;
   14.54 -+	unsigned char data[0];
   14.55 -+};
   14.56 -+
   14.57 -+struct smp_alternative_record {
   14.58 -+	void *targ_start;
   14.59 -+	struct smp_replacement_record *repl;
   14.60 -+};
   14.61 -+
   14.62 -+extern struct smp_alternative_record __start_smp_alternatives_table,
   14.63 -+  __stop_smp_alternatives_table;
   14.64 -+extern unsigned long __init_begin, __init_end;
   14.65 -+
   14.66 -+void prepare_for_smp(void)
   14.67 -+{
   14.68 -+	struct smp_alternative_record *r;
   14.69 -+	printk(KERN_INFO "Enabling SMP...\n");
   14.70 -+	for (r = &__start_smp_alternatives_table;
   14.71 -+	     r != &__stop_smp_alternatives_table;
   14.72 -+	     r++) {
   14.73 -+		BUG_ON(r->repl->targ_size < r->repl->smp1_size);
   14.74 -+		BUG_ON(r->repl->targ_size < r->repl->smp2_size);
   14.75 -+		BUG_ON(r->repl->targ_size < r->repl->up_size);
   14.76 -+               if (system_state == SYSTEM_RUNNING &&
   14.77 -+                   r->targ_start >= (void *)&__init_begin &&
   14.78 -+                   r->targ_start < (void *)&__init_end)
   14.79 -+                       continue;
   14.80 -+		if (r->repl->feature != (unsigned char)-1 &&
   14.81 -+		    boot_cpu_has(r->repl->feature)) {
   14.82 -+			memcpy(r->targ_start,
   14.83 -+			       r->repl->data + r->repl->smp1_size,
   14.84 -+			       r->repl->smp2_size);
   14.85 -+			memset(r->targ_start + r->repl->smp2_size,
   14.86 -+			       0x90,
   14.87 -+			       r->repl->targ_size - r->repl->smp2_size);
   14.88 -+		} else {
   14.89 -+			memcpy(r->targ_start,
   14.90 -+			       r->repl->data,
   14.91 -+			       r->repl->smp1_size);
   14.92 -+			memset(r->targ_start + r->repl->smp1_size,
   14.93 -+			       0x90,
   14.94 -+			       r->repl->targ_size - r->repl->smp1_size);
   14.95 -+		}
   14.96 -+	}
   14.97 -+	/* Paranoia */
   14.98 -+	asm volatile ("jmp 1f\n1:");
   14.99 -+	mb();
  14.100 -+}
  14.101 -+
  14.102 -+void unprepare_for_smp(void)
  14.103 -+{
  14.104 -+	struct smp_alternative_record *r;
  14.105 -+	printk(KERN_INFO "Disabling SMP...\n");
  14.106 -+	for (r = &__start_smp_alternatives_table;
  14.107 -+	     r != &__stop_smp_alternatives_table;
  14.108 -+	     r++) {
  14.109 -+		BUG_ON(r->repl->targ_size < r->repl->smp1_size);
  14.110 -+		BUG_ON(r->repl->targ_size < r->repl->smp2_size);
  14.111 -+		BUG_ON(r->repl->targ_size < r->repl->up_size);
  14.112 -+               if (system_state == SYSTEM_RUNNING &&
  14.113 -+                   r->targ_start >= (void *)&__init_begin &&
  14.114 -+                   r->targ_start < (void *)&__init_end)
  14.115 -+                       continue;
  14.116 -+		memcpy(r->targ_start,
  14.117 -+		       r->repl->data + r->repl->smp1_size + r->repl->smp2_size,
  14.118 -+		       r->repl->up_size);
  14.119 -+		memset(r->targ_start + r->repl->up_size,
  14.120 -+		       0x90,
  14.121 -+		       r->repl->targ_size - r->repl->up_size);
  14.122 -+	}
  14.123 -+	/* Paranoia */
  14.124 -+	asm volatile ("jmp 1f\n1:");
  14.125 -+	mb();
  14.126 -+}
  14.127 -diff -pruN ../pristine-linux-2.6.16/arch/i386/kernel/smpboot.c ./arch/i386/kernel/smpboot.c
  14.128 ---- ../pristine-linux-2.6.16/arch/i386/kernel/smpboot.c	2006-03-20 05:53:29.000000000 +0000
  14.129 -+++ ./arch/i386/kernel/smpboot.c	2006-03-20 19:38:27.000000000 +0000
  14.130 -@@ -1218,6 +1218,11 @@ static void __init smp_boot_cpus(unsigne
  14.131 - 		if (max_cpus <= cpucount+1)
  14.132 - 			continue;
  14.133 - 
  14.134 -+#ifdef CONFIG_SMP_ALTERNATIVES
  14.135 -+		if (kicked == 1)
  14.136 -+			prepare_for_smp();
  14.137 -+#endif
  14.138 -+
  14.139 - 		if (((cpu = alloc_cpu_id()) <= 0) || do_boot_cpu(apicid, cpu))
  14.140 - 			printk("CPU #%d not responding - cannot use it.\n",
  14.141 - 								apicid);
  14.142 -@@ -1396,6 +1401,11 @@ int __devinit __cpu_up(unsigned int cpu)
  14.143 - 		return -EIO;
  14.144 - 	}
  14.145 - 
  14.146 -+#ifdef CONFIG_SMP_ALTERNATIVES
  14.147 -+	if (num_online_cpus() == 1)
  14.148 -+		prepare_for_smp();
  14.149 -+#endif
  14.150 -+
  14.151 - 	local_irq_enable();
  14.152 - 	per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  14.153 - 	/* Unleash the CPU! */
  14.154 -diff -pruN ../pristine-linux-2.6.16/arch/i386/kernel/vmlinux.lds.S ./arch/i386/kernel/vmlinux.lds.S
  14.155 ---- ../pristine-linux-2.6.16/arch/i386/kernel/vmlinux.lds.S	2006-03-20 05:53:29.000000000 +0000
  14.156 -+++ ./arch/i386/kernel/vmlinux.lds.S	2006-03-20 19:38:27.000000000 +0000
  14.157 -@@ -34,6 +34,13 @@ SECTIONS
  14.158 -   __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { *(__ex_table) }
  14.159 -   __stop___ex_table = .;
  14.160 - 
  14.161 -+  . = ALIGN(16);
  14.162 -+  __start_smp_alternatives_table = .;
  14.163 -+  __smp_alternatives : { *(__smp_alternatives) }
  14.164 -+  __stop_smp_alternatives_table = .;
  14.165 -+
  14.166 -+  __smp_replacements : { *(__smp_replacements) }
  14.167 -+
  14.168 -   RODATA
  14.169 - 
  14.170 -   /* writeable */
  14.171 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/atomic.h ./include/asm-i386/atomic.h
  14.172 ---- ../pristine-linux-2.6.16/include/asm-i386/atomic.h	2006-03-20 05:53:29.000000000 +0000
  14.173 -+++ ./include/asm-i386/atomic.h	2006-03-20 19:38:27.000000000 +0000
  14.174 -@@ -4,18 +4,13 @@
  14.175 - #include <linux/config.h>
  14.176 - #include <linux/compiler.h>
  14.177 - #include <asm/processor.h>
  14.178 -+#include <asm/smp_alt.h>
  14.179 - 
  14.180 - /*
  14.181 -  * Atomic operations that C can't guarantee us.  Useful for
  14.182 -  * resource counting etc..
  14.183 -  */
  14.184 - 
  14.185 --#ifdef CONFIG_SMP
  14.186 --#define LOCK "lock ; "
  14.187 --#else
  14.188 --#define LOCK ""
  14.189 --#endif
  14.190 --
  14.191 - /*
  14.192 -  * Make sure gcc doesn't try to be clever and move things around
  14.193 -  * on us. We need to use _exactly_ the address the user gave us,
  14.194 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/bitops.h ./include/asm-i386/bitops.h
  14.195 ---- ../pristine-linux-2.6.16/include/asm-i386/bitops.h	2006-03-20 05:53:29.000000000 +0000
  14.196 -+++ ./include/asm-i386/bitops.h	2006-03-20 19:38:27.000000000 +0000
  14.197 -@@ -7,6 +7,7 @@
  14.198 - 
  14.199 - #include <linux/config.h>
  14.200 - #include <linux/compiler.h>
  14.201 -+#include <asm/smp_alt.h>
  14.202 - 
  14.203 - /*
  14.204 -  * These have to be done with inline assembly: that way the bit-setting
  14.205 -@@ -16,12 +17,6 @@
  14.206 -  * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
  14.207 -  */
  14.208 - 
  14.209 --#ifdef CONFIG_SMP
  14.210 --#define LOCK_PREFIX "lock ; "
  14.211 --#else
  14.212 --#define LOCK_PREFIX ""
  14.213 --#endif
  14.214 --
  14.215 - #define ADDR (*(volatile long *) addr)
  14.216 - 
  14.217 - /**
  14.218 -@@ -41,7 +36,7 @@
  14.219 -  */
  14.220 - static inline void set_bit(int nr, volatile unsigned long * addr)
  14.221 - {
  14.222 --	__asm__ __volatile__( LOCK_PREFIX
  14.223 -+	__asm__ __volatile__( LOCK
  14.224 - 		"btsl %1,%0"
  14.225 - 		:"+m" (ADDR)
  14.226 - 		:"Ir" (nr));
  14.227 -@@ -76,7 +71,7 @@ static inline void __set_bit(int nr, vol
  14.228 -  */
  14.229 - static inline void clear_bit(int nr, volatile unsigned long * addr)
  14.230 - {
  14.231 --	__asm__ __volatile__( LOCK_PREFIX
  14.232 -+	__asm__ __volatile__( LOCK
  14.233 - 		"btrl %1,%0"
  14.234 - 		:"+m" (ADDR)
  14.235 - 		:"Ir" (nr));
  14.236 -@@ -121,7 +116,7 @@ static inline void __change_bit(int nr, 
  14.237 -  */
  14.238 - static inline void change_bit(int nr, volatile unsigned long * addr)
  14.239 - {
  14.240 --	__asm__ __volatile__( LOCK_PREFIX
  14.241 -+	__asm__ __volatile__( LOCK
  14.242 - 		"btcl %1,%0"
  14.243 - 		:"+m" (ADDR)
  14.244 - 		:"Ir" (nr));
  14.245 -@@ -140,7 +135,7 @@ static inline int test_and_set_bit(int n
  14.246 - {
  14.247 - 	int oldbit;
  14.248 - 
  14.249 --	__asm__ __volatile__( LOCK_PREFIX
  14.250 -+	__asm__ __volatile__( LOCK
  14.251 - 		"btsl %2,%1\n\tsbbl %0,%0"
  14.252 - 		:"=r" (oldbit),"+m" (ADDR)
  14.253 - 		:"Ir" (nr) : "memory");
  14.254 -@@ -180,7 +175,7 @@ static inline int test_and_clear_bit(int
  14.255 - {
  14.256 - 	int oldbit;
  14.257 - 
  14.258 --	__asm__ __volatile__( LOCK_PREFIX
  14.259 -+	__asm__ __volatile__( LOCK
  14.260 - 		"btrl %2,%1\n\tsbbl %0,%0"
  14.261 - 		:"=r" (oldbit),"+m" (ADDR)
  14.262 - 		:"Ir" (nr) : "memory");
  14.263 -@@ -231,7 +226,7 @@ static inline int test_and_change_bit(in
  14.264 - {
  14.265 - 	int oldbit;
  14.266 - 
  14.267 --	__asm__ __volatile__( LOCK_PREFIX
  14.268 -+	__asm__ __volatile__( LOCK
  14.269 - 		"btcl %2,%1\n\tsbbl %0,%0"
  14.270 - 		:"=r" (oldbit),"+m" (ADDR)
  14.271 - 		:"Ir" (nr) : "memory");
  14.272 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/futex.h ./include/asm-i386/futex.h
  14.273 ---- ../pristine-linux-2.6.16/include/asm-i386/futex.h	2006-03-20 05:53:29.000000000 +0000
  14.274 -+++ ./include/asm-i386/futex.h	2006-03-20 19:38:27.000000000 +0000
  14.275 -@@ -28,7 +28,7 @@
  14.276 - "1:	movl	%2, %0\n\
  14.277 - 	movl	%0, %3\n"					\
  14.278 - 	insn "\n"						\
  14.279 --"2:	" LOCK_PREFIX "cmpxchgl %3, %2\n\
  14.280 -+"2:	" LOCK "cmpxchgl %3, %2\n\
  14.281 - 	jnz	1b\n\
  14.282 - 3:	.section .fixup,\"ax\"\n\
  14.283 - 4:	mov	%5, %1\n\
  14.284 -@@ -68,7 +68,7 @@ futex_atomic_op_inuser (int encoded_op, 
  14.285 - #endif
  14.286 - 		switch (op) {
  14.287 - 		case FUTEX_OP_ADD:
  14.288 --			__futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret,
  14.289 -+			__futex_atomic_op1(LOCK "xaddl %0, %2", ret,
  14.290 - 					   oldval, uaddr, oparg);
  14.291 - 			break;
  14.292 - 		case FUTEX_OP_OR:
  14.293 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/rwsem.h ./include/asm-i386/rwsem.h
  14.294 ---- ../pristine-linux-2.6.16/include/asm-i386/rwsem.h	2006-03-20 05:53:29.000000000 +0000
  14.295 -+++ ./include/asm-i386/rwsem.h	2006-03-20 19:38:27.000000000 +0000
  14.296 -@@ -40,6 +40,7 @@
  14.297 - 
  14.298 - #include <linux/list.h>
  14.299 - #include <linux/spinlock.h>
  14.300 -+#include <asm/smp_alt.h>
  14.301 - 
  14.302 - struct rwsem_waiter;
  14.303 - 
  14.304 -@@ -99,7 +100,7 @@ static inline void __down_read(struct rw
  14.305 - {
  14.306 - 	__asm__ __volatile__(
  14.307 - 		"# beginning down_read\n\t"
  14.308 --LOCK_PREFIX	"  incl      (%%eax)\n\t" /* adds 0x00000001, returns the old value */
  14.309 -+LOCK	        "  incl      (%%eax)\n\t" /* adds 0x00000001, returns the old value */
  14.310 - 		"  js        2f\n\t" /* jump if we weren't granted the lock */
  14.311 - 		"1:\n\t"
  14.312 - 		LOCK_SECTION_START("")
  14.313 -@@ -130,7 +131,7 @@ static inline int __down_read_trylock(st
  14.314 - 		"  movl	     %1,%2\n\t"
  14.315 - 		"  addl      %3,%2\n\t"
  14.316 - 		"  jle	     2f\n\t"
  14.317 --LOCK_PREFIX	"  cmpxchgl  %2,%0\n\t"
  14.318 -+LOCK	        "  cmpxchgl  %2,%0\n\t"
  14.319 - 		"  jnz	     1b\n\t"
  14.320 - 		"2:\n\t"
  14.321 - 		"# ending __down_read_trylock\n\t"
  14.322 -@@ -150,7 +151,7 @@ static inline void __down_write(struct r
  14.323 - 	tmp = RWSEM_ACTIVE_WRITE_BIAS;
  14.324 - 	__asm__ __volatile__(
  14.325 - 		"# beginning down_write\n\t"
  14.326 --LOCK_PREFIX	"  xadd      %%edx,(%%eax)\n\t" /* subtract 0x0000ffff, returns the old value */
  14.327 -+LOCK	        "  xadd      %%edx,(%%eax)\n\t" /* subtract 0x0000ffff, returns the old value */
  14.328 - 		"  testl     %%edx,%%edx\n\t" /* was the count 0 before? */
  14.329 - 		"  jnz       2f\n\t" /* jump if we weren't granted the lock */
  14.330 - 		"1:\n\t"
  14.331 -@@ -188,7 +189,7 @@ static inline void __up_read(struct rw_s
  14.332 - 	__s32 tmp = -RWSEM_ACTIVE_READ_BIAS;
  14.333 - 	__asm__ __volatile__(
  14.334 - 		"# beginning __up_read\n\t"
  14.335 --LOCK_PREFIX	"  xadd      %%edx,(%%eax)\n\t" /* subtracts 1, returns the old value */
  14.336 -+LOCK	        "  xadd      %%edx,(%%eax)\n\t" /* subtracts 1, returns the old value */
  14.337 - 		"  js        2f\n\t" /* jump if the lock is being waited upon */
  14.338 - 		"1:\n\t"
  14.339 - 		LOCK_SECTION_START("")
  14.340 -@@ -214,7 +215,7 @@ static inline void __up_write(struct rw_
  14.341 - 	__asm__ __volatile__(
  14.342 - 		"# beginning __up_write\n\t"
  14.343 - 		"  movl      %2,%%edx\n\t"
  14.344 --LOCK_PREFIX	"  xaddl     %%edx,(%%eax)\n\t" /* tries to transition 0xffff0001 -> 0x00000000 */
  14.345 -+LOCK	        "  xaddl     %%edx,(%%eax)\n\t" /* tries to transition 0xffff0001 -> 0x00000000 */
  14.346 - 		"  jnz       2f\n\t" /* jump if the lock is being waited upon */
  14.347 - 		"1:\n\t"
  14.348 - 		LOCK_SECTION_START("")
  14.349 -@@ -239,7 +240,7 @@ static inline void __downgrade_write(str
  14.350 - {
  14.351 - 	__asm__ __volatile__(
  14.352 - 		"# beginning __downgrade_write\n\t"
  14.353 --LOCK_PREFIX	"  addl      %2,(%%eax)\n\t" /* transitions 0xZZZZ0001 -> 0xYYYY0001 */
  14.354 -+LOCK	        "  addl      %2,(%%eax)\n\t" /* transitions 0xZZZZ0001 -> 0xYYYY0001 */
  14.355 - 		"  js        2f\n\t" /* jump if the lock is being waited upon */
  14.356 - 		"1:\n\t"
  14.357 - 		LOCK_SECTION_START("")
  14.358 -@@ -263,7 +264,7 @@ LOCK_PREFIX	"  addl      %2,(%%eax)\n\t"
  14.359 - static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
  14.360 - {
  14.361 - 	__asm__ __volatile__(
  14.362 --LOCK_PREFIX	"addl %1,%0"
  14.363 -+LOCK	          "addl %1,%0"
  14.364 - 		: "=m"(sem->count)
  14.365 - 		: "ir"(delta), "m"(sem->count));
  14.366 - }
  14.367 -@@ -276,7 +277,7 @@ static inline int rwsem_atomic_update(in
  14.368 - 	int tmp = delta;
  14.369 - 
  14.370 - 	__asm__ __volatile__(
  14.371 --LOCK_PREFIX	"xadd %0,(%2)"
  14.372 -+LOCK  	          "xadd %0,(%2)"
  14.373 - 		: "+r"(tmp), "=m"(sem->count)
  14.374 - 		: "r"(sem), "m"(sem->count)
  14.375 - 		: "memory");
  14.376 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/smp_alt.h ./include/asm-i386/smp_alt.h
  14.377 ---- ../pristine-linux-2.6.16/include/asm-i386/smp_alt.h	1970-01-01 01:00:00.000000000 +0100
  14.378 -+++ ./include/asm-i386/smp_alt.h	2006-03-20 19:38:27.000000000 +0000
  14.379 -@@ -0,0 +1,32 @@
  14.380 -+#ifndef __ASM_SMP_ALT_H__
  14.381 -+#define __ASM_SMP_ALT_H__
  14.382 -+
  14.383 -+#include <linux/config.h>
  14.384 -+
  14.385 -+#ifdef CONFIG_SMP
  14.386 -+#if defined(CONFIG_SMP_ALTERNATIVES) && !defined(MODULE)
  14.387 -+#define LOCK \
  14.388 -+        "6677: nop\n" \
  14.389 -+	".section __smp_alternatives,\"a\"\n" \
  14.390 -+	".long 6677b\n" \
  14.391 -+	".long 6678f\n" \
  14.392 -+	".previous\n" \
  14.393 -+	".section __smp_replacements,\"a\"\n" \
  14.394 -+	"6678: .byte 1\n" \
  14.395 -+	".byte 1\n" \
  14.396 -+	".byte 0\n" \
  14.397 -+        ".byte 1\n" \
  14.398 -+	".byte -1\n" \
  14.399 -+	"lock\n" \
  14.400 -+	"nop\n" \
  14.401 -+	".previous\n"
  14.402 -+void prepare_for_smp(void);
  14.403 -+void unprepare_for_smp(void);
  14.404 -+#else
  14.405 -+#define LOCK "lock ; "
  14.406 -+#endif
  14.407 -+#else
  14.408 -+#define LOCK ""
  14.409 -+#endif
  14.410 -+
  14.411 -+#endif /* __ASM_SMP_ALT_H__ */
  14.412 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/spinlock.h ./include/asm-i386/spinlock.h
  14.413 ---- ../pristine-linux-2.6.16/include/asm-i386/spinlock.h	2006-03-20 05:53:29.000000000 +0000
  14.414 -+++ ./include/asm-i386/spinlock.h	2006-03-20 19:38:27.000000000 +0000
  14.415 -@@ -6,6 +6,7 @@
  14.416 - #include <asm/page.h>
  14.417 - #include <linux/config.h>
  14.418 - #include <linux/compiler.h>
  14.419 -+#include <asm/smp_alt.h>
  14.420 - 
  14.421 - /*
  14.422 -  * Your basic SMP spinlocks, allowing only a single CPU anywhere
  14.423 -@@ -23,7 +24,8 @@
  14.424 - 
  14.425 - #define __raw_spin_lock_string \
  14.426 - 	"\n1:\t" \
  14.427 --	"lock ; decb %0\n\t" \
  14.428 -+	LOCK \
  14.429 -+	"decb %0\n\t" \
  14.430 - 	"jns 3f\n" \
  14.431 - 	"2:\t" \
  14.432 - 	"rep;nop\n\t" \
  14.433 -@@ -34,7 +36,8 @@
  14.434 - 
  14.435 - #define __raw_spin_lock_string_flags \
  14.436 - 	"\n1:\t" \
  14.437 --	"lock ; decb %0\n\t" \
  14.438 -+	LOCK \
  14.439 -+	"decb %0\n\t" \
  14.440 - 	"jns 4f\n\t" \
  14.441 - 	"2:\t" \
  14.442 - 	"testl $0x200, %1\n\t" \
  14.443 -@@ -65,10 +68,34 @@ static inline void __raw_spin_lock_flags
  14.444 - static inline int __raw_spin_trylock(raw_spinlock_t *lock)
  14.445 - {
  14.446 - 	char oldval;
  14.447 -+#ifdef CONFIG_SMP_ALTERNATIVES
  14.448 - 	__asm__ __volatile__(
  14.449 --		"xchgb %b0,%1"
  14.450 -+		"1:movb %1,%b0\n"
  14.451 -+		"movb $0,%1\n"
  14.452 -+		"2:"
  14.453 -+		".section __smp_alternatives,\"a\"\n"
  14.454 -+		".long 1b\n"
  14.455 -+		".long 3f\n"
  14.456 -+		".previous\n"
  14.457 -+		".section __smp_replacements,\"a\"\n"
  14.458 -+		"3: .byte 2b - 1b\n"
  14.459 -+		".byte 5f-4f\n"
  14.460 -+		".byte 0\n"
  14.461 -+		".byte 6f-5f\n"
  14.462 -+		".byte -1\n"
  14.463 -+		"4: xchgb %b0,%1\n"
  14.464 -+		"5: movb %1,%b0\n"
  14.465 -+		"movb $0,%1\n"
  14.466 -+		"6:\n"
  14.467 -+		".previous\n"
  14.468 - 		:"=q" (oldval), "=m" (lock->slock)
  14.469 - 		:"0" (0) : "memory");
  14.470 -+#else
  14.471 -+	__asm__ __volatile__(
  14.472 -+		"xchgb %b0,%1\n"
  14.473 -+		:"=q" (oldval), "=m" (lock->slock)
  14.474 -+		:"0" (0) : "memory");
  14.475 -+#endif
  14.476 - 	return oldval > 0;
  14.477 - }
  14.478 - 
  14.479 -@@ -178,12 +205,12 @@ static inline int __raw_write_trylock(ra
  14.480 - 
  14.481 - static inline void __raw_read_unlock(raw_rwlock_t *rw)
  14.482 - {
  14.483 --	asm volatile("lock ; incl %0" :"=m" (rw->lock) : : "memory");
  14.484 -+	asm volatile(LOCK "incl %0" :"=m" (rw->lock) : : "memory");
  14.485 - }
  14.486 - 
  14.487 - static inline void __raw_write_unlock(raw_rwlock_t *rw)
  14.488 - {
  14.489 --	asm volatile("lock ; addl $" RW_LOCK_BIAS_STR ", %0"
  14.490 -+	asm volatile(LOCK "addl $" RW_LOCK_BIAS_STR ", %0"
  14.491 - 				 : "=m" (rw->lock) : : "memory");
  14.492 - }
  14.493 - 
  14.494 -diff -pruN ../pristine-linux-2.6.16/include/asm-i386/system.h ./include/asm-i386/system.h
  14.495 ---- ../pristine-linux-2.6.16/include/asm-i386/system.h	2006-03-20 05:53:29.000000000 +0000
  14.496 -+++ ./include/asm-i386/system.h	2006-03-20 19:38:27.000000000 +0000
  14.497 -@@ -5,7 +5,7 @@
  14.498 - #include <linux/kernel.h>
  14.499 - #include <asm/segment.h>
  14.500 - #include <asm/cpufeature.h>
  14.501 --#include <linux/bitops.h> /* for LOCK_PREFIX */
  14.502 -+#include <asm/smp_alt.h>
  14.503 - 
  14.504 - #ifdef __KERNEL__
  14.505 - 
  14.506 -@@ -271,19 +271,19 @@ static inline unsigned long __cmpxchg(vo
  14.507 - 	unsigned long prev;
  14.508 - 	switch (size) {
  14.509 - 	case 1:
  14.510 --		__asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
  14.511 -+		__asm__ __volatile__(LOCK "cmpxchgb %b1,%2"
  14.512 - 				     : "=a"(prev)
  14.513 - 				     : "q"(new), "m"(*__xg(ptr)), "0"(old)
  14.514 - 				     : "memory");
  14.515 - 		return prev;
  14.516 - 	case 2:
  14.517 --		__asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
  14.518 -+		__asm__ __volatile__(LOCK "cmpxchgw %w1,%2"
  14.519 - 				     : "=a"(prev)
  14.520 - 				     : "r"(new), "m"(*__xg(ptr)), "0"(old)
  14.521 - 				     : "memory");
  14.522 - 		return prev;
  14.523 - 	case 4:
  14.524 --		__asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
  14.525 -+		__asm__ __volatile__(LOCK "cmpxchgl %1,%2"
  14.526 - 				     : "=a"(prev)
  14.527 - 				     : "r"(new), "m"(*__xg(ptr)), "0"(old)
  14.528 - 				     : "memory");
  14.529 -@@ -336,7 +336,7 @@ static inline unsigned long long __cmpxc
  14.530 - 				      unsigned long long new)
  14.531 - {
  14.532 - 	unsigned long long prev;
  14.533 --	__asm__ __volatile__(LOCK_PREFIX "cmpxchg8b %3"
  14.534 -+	__asm__ __volatile__(LOCK "cmpxchg8b %3"
  14.535 - 			     : "=A"(prev)
  14.536 - 			     : "b"((unsigned long)new),
  14.537 - 			       "c"((unsigned long)(new >> 32)),
  14.538 -@@ -503,11 +503,55 @@ struct alt_instr { 
  14.539 - #endif
  14.540 - 
  14.541 - #ifdef CONFIG_SMP
  14.542 -+#if defined(CONFIG_SMP_ALTERNATIVES) && !defined(MODULE)
  14.543 -+#define smp_alt_mb(instr)                                           \
  14.544 -+__asm__ __volatile__("6667:\nnop\nnop\nnop\nnop\nnop\nnop\n6668:\n" \
  14.545 -+		     ".section __smp_alternatives,\"a\"\n"          \
  14.546 -+		     ".long 6667b\n"                                \
  14.547 -+                     ".long 6673f\n"                                \
  14.548 -+		     ".previous\n"                                  \
  14.549 -+		     ".section __smp_replacements,\"a\"\n"          \
  14.550 -+		     "6673:.byte 6668b-6667b\n"                     \
  14.551 -+		     ".byte 6670f-6669f\n"                          \
  14.552 -+		     ".byte 6671f-6670f\n"                          \
  14.553 -+                     ".byte 0\n"                                    \
  14.554 -+		     ".byte %c0\n"                                  \
  14.555 -+		     "6669:lock;addl $0,0(%%esp)\n"                 \
  14.556 -+		     "6670:" instr "\n"                             \
  14.557 -+		     "6671:\n"                                      \
  14.558 -+		     ".previous\n"                                  \
  14.559 -+		     :                                              \
  14.560 -+		     : "i" (X86_FEATURE_XMM2)                       \
  14.561 -+		     : "memory")
  14.562 -+#define smp_rmb() smp_alt_mb("lfence")
  14.563 -+#define smp_mb()  smp_alt_mb("mfence")
  14.564 -+#define set_mb(var, value) do {                                     \
  14.565 -+unsigned long __set_mb_temp;                                        \
  14.566 -+__asm__ __volatile__("6667:movl %1, %0\n6668:\n"                    \
  14.567 -+		     ".section __smp_alternatives,\"a\"\n"          \
  14.568 -+		     ".long 6667b\n"                                \
  14.569 -+		     ".long 6673f\n"                                \
  14.570 -+		     ".previous\n"                                  \
  14.571 -+		     ".section __smp_replacements,\"a\"\n"          \
  14.572 -+		     "6673: .byte 6668b-6667b\n"                    \
  14.573 -+		     ".byte 6670f-6669f\n"                          \
  14.574 -+		     ".byte 0\n"                                    \
  14.575 -+		     ".byte 6671f-6670f\n"                          \
  14.576 -+		     ".byte -1\n"                                   \
  14.577 -+		     "6669: xchg %1, %0\n"                          \
  14.578 -+		     "6670:movl %1, %0\n"                           \
  14.579 -+		     "6671:\n"                                      \
  14.580 -+		     ".previous\n"                                  \
  14.581 -+		     : "=m" (var), "=r" (__set_mb_temp)             \
  14.582 -+		     : "1" (value)                                  \
  14.583 -+		     : "memory"); } while (0)
  14.584 -+#else
  14.585 - #define smp_mb()	mb()
  14.586 - #define smp_rmb()	rmb()
  14.587 -+#define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
  14.588 -+#endif
  14.589 - #define smp_wmb()	wmb()
  14.590 - #define smp_read_barrier_depends()	read_barrier_depends()
  14.591 --#define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
  14.592 - #else
  14.593 - #define smp_mb()	barrier()
  14.594 - #define smp_rmb()	barrier()
    15.1 --- a/patches/linux-2.6.16/x86-increase-interrupt-vector-range.patch	Thu May 04 17:38:25 2006 +0100
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,107 +0,0 @@
    15.4 -Subject: Increase x86 interrupt vector range
    15.5 -
    15.6 -Remove the limit of 256 interrupt vectors by changing the value
    15.7 -stored in orig_{e,r}ax to be the negated interrupt vector.
    15.8 -The orig_{e,r}ax needs to be < 0 to allow the signal code to
    15.9 -distinguish between return from interrupt and return from syscall.
   15.10 -With this change applied, NR_IRQS can be > 256.
   15.11 -
   15.12 -Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
   15.13 ----
   15.14 - arch/i386/kernel/entry.S    |    4 ++--
   15.15 - arch/i386/kernel/irq.c      |    4 ++--
   15.16 - arch/x86_64/kernel/entry.S  |    2 +-
   15.17 - arch/x86_64/kernel/irq.c    |    4 ++--
   15.18 - arch/x86_64/kernel/smp.c    |    4 ++--
   15.19 - include/asm-x86_64/hw_irq.h |    2 +-
   15.20 - 6 files changed, 10 insertions(+), 10 deletions(-)
   15.21 -
   15.22 -diff -r 7d239c83edea arch/i386/kernel/entry.S
   15.23 ---- a/arch/i386/kernel/entry.S	Mon Mar 20 06:00:20 2006 +0000
   15.24 -+++ b/arch/i386/kernel/entry.S	Fri Mar 31 17:01:35 2006 +0100
   15.25 -@@ -406,7 +406,7 @@ ENTRY(irq_entries_start)
   15.26 - ENTRY(irq_entries_start)
   15.27 - .rept NR_IRQS
   15.28 - 	ALIGN
   15.29 --1:	pushl $vector-256
   15.30 -+1:	pushl $~(vector)
   15.31 - 	jmp common_interrupt
   15.32 - .data
   15.33 - 	.long 1b
   15.34 -@@ -423,7 +423,7 @@ common_interrupt:
   15.35 - 
   15.36 - #define BUILD_INTERRUPT(name, nr)	\
   15.37 - ENTRY(name)				\
   15.38 --	pushl $nr-256;			\
   15.39 -+	pushl $~(nr);			\
   15.40 - 	SAVE_ALL			\
   15.41 - 	movl %esp,%eax;			\
   15.42 - 	call smp_/**/name;		\
   15.43 -diff -r 7d239c83edea arch/i386/kernel/irq.c
   15.44 ---- a/arch/i386/kernel/irq.c	Mon Mar 20 06:00:20 2006 +0000
   15.45 -+++ b/arch/i386/kernel/irq.c	Fri Mar 31 17:01:35 2006 +0100
   15.46 -@@ -53,8 +53,8 @@ static union irq_ctx *softirq_ctx[NR_CPU
   15.47 -  */
   15.48 - fastcall unsigned int do_IRQ(struct pt_regs *regs)
   15.49 - {	
   15.50 --	/* high bits used in ret_from_ code */
   15.51 --	int irq = regs->orig_eax & 0xff;
   15.52 -+	/* high bit used in ret_from_ code */
   15.53 -+	int irq = ~regs->orig_eax;
   15.54 - #ifdef CONFIG_4KSTACKS
   15.55 - 	union irq_ctx *curctx, *irqctx;
   15.56 - 	u32 *isp;
   15.57 -diff -r 7d239c83edea arch/x86_64/kernel/entry.S
   15.58 ---- a/arch/x86_64/kernel/entry.S	Mon Mar 20 06:00:20 2006 +0000
   15.59 -+++ b/arch/x86_64/kernel/entry.S	Fri Mar 31 17:01:35 2006 +0100
   15.60 -@@ -609,7 +609,7 @@ retint_kernel:
   15.61 -  */		
   15.62 - 	.macro apicinterrupt num,func
   15.63 - 	INTR_FRAME
   15.64 --	pushq $\num-256
   15.65 -+	pushq $~(\num)
   15.66 - 	CFI_ADJUST_CFA_OFFSET 8
   15.67 - 	interrupt \func
   15.68 - 	jmp ret_from_intr
   15.69 -diff -r 7d239c83edea arch/x86_64/kernel/irq.c
   15.70 ---- a/arch/x86_64/kernel/irq.c	Mon Mar 20 06:00:20 2006 +0000
   15.71 -+++ b/arch/x86_64/kernel/irq.c	Fri Mar 31 17:01:35 2006 +0100
   15.72 -@@ -96,8 +96,8 @@ skip:
   15.73 -  */
   15.74 - asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
   15.75 - {	
   15.76 --	/* high bits used in ret_from_ code  */
   15.77 --	unsigned irq = regs->orig_rax & 0xff;
   15.78 -+	/* high bit used in ret_from_ code  */
   15.79 -+	unsigned irq = ~regs->orig_rax;
   15.80 - 
   15.81 - 	exit_idle();
   15.82 - 	irq_enter();
   15.83 -diff -r 7d239c83edea arch/x86_64/kernel/smp.c
   15.84 ---- a/arch/x86_64/kernel/smp.c	Mon Mar 20 06:00:20 2006 +0000
   15.85 -+++ b/arch/x86_64/kernel/smp.c	Fri Mar 31 17:01:35 2006 +0100
   15.86 -@@ -135,10 +135,10 @@ asmlinkage void smp_invalidate_interrupt
   15.87 - 
   15.88 - 	cpu = smp_processor_id();
   15.89 - 	/*
   15.90 --	 * orig_rax contains the interrupt vector - 256.
   15.91 -+	 * orig_rax contains the negated interrupt vector.
   15.92 - 	 * Use that to determine where the sender put the data.
   15.93 - 	 */
   15.94 --	sender = regs->orig_rax + 256 - INVALIDATE_TLB_VECTOR_START;
   15.95 -+	sender = ~regs->orig_rax - INVALIDATE_TLB_VECTOR_START;
   15.96 - 	f = &per_cpu(flush_state, sender);
   15.97 - 
   15.98 - 	if (!cpu_isset(cpu, f->flush_cpumask))
   15.99 -diff -r 7d239c83edea include/asm-x86_64/hw_irq.h
  15.100 ---- a/include/asm-x86_64/hw_irq.h	Mon Mar 20 06:00:20 2006 +0000
  15.101 -+++ b/include/asm-x86_64/hw_irq.h	Fri Mar 31 17:01:35 2006 +0100
  15.102 -@@ -127,7 +127,7 @@ __asm__( \
  15.103 - __asm__( \
  15.104 - "\n.p2align\n" \
  15.105 - "IRQ" #nr "_interrupt:\n\t" \
  15.106 --	"push $" #nr "-256 ; " \
  15.107 -+	"push $~(" #nr ") ; " \
  15.108 - 	"jmp common_interrupt");
  15.109 - 
  15.110 - #if defined(CONFIG_X86_IO_APIC)
    16.1 --- a/patches/linux-2.6.16/xenoprof-generic.patch	Thu May 04 17:38:25 2006 +0100
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,384 +0,0 @@
    16.4 -diff -pruN ../pristine-linux-2.6.16/drivers/oprofile/buffer_sync.c ./drivers/oprofile/buffer_sync.c
    16.5 ---- ../pristine-linux-2.6.16/drivers/oprofile/buffer_sync.c	2006-03-20 05:53:29.000000000 +0000
    16.6 -+++ ./drivers/oprofile/buffer_sync.c	2006-04-03 15:53:05.000000000 +0100
    16.7 -@@ -6,6 +6,10 @@
    16.8 -  *
    16.9 -  * @author John Levon <levon@movementarian.org>
   16.10 -  *
   16.11 -+ * Modified by Aravind Menon for Xen
   16.12 -+ * These modifications are:
   16.13 -+ * Copyright (C) 2005 Hewlett-Packard Co.
   16.14 -+ *
   16.15 -  * This is the core of the buffer management. Each
   16.16 -  * CPU buffer is processed and entered into the
   16.17 -  * global event buffer. Such processing is necessary
   16.18 -@@ -275,15 +279,24 @@ static void add_cpu_switch(int i)
   16.19 - 	last_cookie = INVALID_COOKIE;
   16.20 - }
   16.21 - 
   16.22 --static void add_kernel_ctx_switch(unsigned int in_kernel)
   16.23 -+static void add_cpu_mode_switch(unsigned int cpu_mode)
   16.24 - {
   16.25 - 	add_event_entry(ESCAPE_CODE);
   16.26 --	if (in_kernel)
   16.27 --		add_event_entry(KERNEL_ENTER_SWITCH_CODE); 
   16.28 --	else
   16.29 --		add_event_entry(KERNEL_EXIT_SWITCH_CODE); 
   16.30 -+	switch (cpu_mode) {
   16.31 -+	case CPU_MODE_USER:
   16.32 -+		add_event_entry(USER_ENTER_SWITCH_CODE);
   16.33 -+		break;
   16.34 -+	case CPU_MODE_KERNEL:
   16.35 -+		add_event_entry(KERNEL_ENTER_SWITCH_CODE);
   16.36 -+		break;
   16.37 -+	case CPU_MODE_XEN:
   16.38 -+		add_event_entry(XEN_ENTER_SWITCH_CODE);
   16.39 -+		break;
   16.40 -+	default:
   16.41 -+		break;
   16.42 -+	}
   16.43 - }
   16.44 -- 
   16.45 -+
   16.46 - static void
   16.47 - add_user_ctx_switch(struct task_struct const * task, unsigned long cookie)
   16.48 - {
   16.49 -@@ -348,9 +361,9 @@ static int add_us_sample(struct mm_struc
   16.50 -  * for later lookup from userspace.
   16.51 -  */
   16.52 - static int
   16.53 --add_sample(struct mm_struct * mm, struct op_sample * s, int in_kernel)
   16.54 -+add_sample(struct mm_struct * mm, struct op_sample * s, int cpu_mode)
   16.55 - {
   16.56 --	if (in_kernel) {
   16.57 -+	if (cpu_mode >= CPU_MODE_KERNEL) {
   16.58 - 		add_sample_entry(s->eip, s->event);
   16.59 - 		return 1;
   16.60 - 	} else if (mm) {
   16.61 -@@ -496,7 +509,7 @@ void sync_buffer(int cpu)
   16.62 - 	struct mm_struct *mm = NULL;
   16.63 - 	struct task_struct * new;
   16.64 - 	unsigned long cookie = 0;
   16.65 --	int in_kernel = 1;
   16.66 -+	int cpu_mode = 1;
   16.67 - 	unsigned int i;
   16.68 - 	sync_buffer_state state = sb_buffer_start;
   16.69 - 	unsigned long available;
   16.70 -@@ -513,12 +526,12 @@ void sync_buffer(int cpu)
   16.71 - 		struct op_sample * s = &cpu_buf->buffer[cpu_buf->tail_pos];
   16.72 -  
   16.73 - 		if (is_code(s->eip)) {
   16.74 --			if (s->event <= CPU_IS_KERNEL) {
   16.75 -+			if (s->event <= CPU_MODE_XEN) {
   16.76 - 				/* kernel/userspace switch */
   16.77 --				in_kernel = s->event;
   16.78 -+				cpu_mode = s->event;
   16.79 - 				if (state == sb_buffer_start)
   16.80 - 					state = sb_sample_start;
   16.81 --				add_kernel_ctx_switch(s->event);
   16.82 -+				add_cpu_mode_switch(s->event);
   16.83 - 			} else if (s->event == CPU_TRACE_BEGIN) {
   16.84 - 				state = sb_bt_start;
   16.85 - 				add_trace_begin();
   16.86 -@@ -536,7 +549,7 @@ void sync_buffer(int cpu)
   16.87 - 			}
   16.88 - 		} else {
   16.89 - 			if (state >= sb_bt_start &&
   16.90 --			    !add_sample(mm, s, in_kernel)) {
   16.91 -+			    !add_sample(mm, s, cpu_mode)) {
   16.92 - 				if (state == sb_bt_start) {
   16.93 - 					state = sb_bt_ignore;
   16.94 - 					atomic_inc(&oprofile_stats.bt_lost_no_mapping);
   16.95 -diff -pruN ../pristine-linux-2.6.16/drivers/oprofile/cpu_buffer.c ./drivers/oprofile/cpu_buffer.c
   16.96 ---- ../pristine-linux-2.6.16/drivers/oprofile/cpu_buffer.c	2006-03-20 05:53:29.000000000 +0000
   16.97 -+++ ./drivers/oprofile/cpu_buffer.c	2006-04-03 15:53:05.000000000 +0100
   16.98 -@@ -6,6 +6,10 @@
   16.99 -  *
  16.100 -  * @author John Levon <levon@movementarian.org>
  16.101 -  *
  16.102 -+ * Modified by Aravind Menon for Xen
  16.103 -+ * These modifications are:
  16.104 -+ * Copyright (C) 2005 Hewlett-Packard Co.
  16.105 -+ *
  16.106 -  * Each CPU has a local buffer that stores PC value/event
  16.107 -  * pairs. We also log context switches when we notice them.
  16.108 -  * Eventually each CPU's buffer is processed into the global
  16.109 -@@ -58,7 +62,7 @@ int alloc_cpu_buffers(void)
  16.110 - 			goto fail;
  16.111 -  
  16.112 - 		b->last_task = NULL;
  16.113 --		b->last_is_kernel = -1;
  16.114 -+		b->last_cpu_mode = -1;
  16.115 - 		b->tracing = 0;
  16.116 - 		b->buffer_size = buffer_size;
  16.117 - 		b->tail_pos = 0;
  16.118 -@@ -114,7 +118,7 @@ void cpu_buffer_reset(struct oprofile_cp
  16.119 - 	 * collected will populate the buffer with proper
  16.120 - 	 * values to initialize the buffer
  16.121 - 	 */
  16.122 --	cpu_buf->last_is_kernel = -1;
  16.123 -+	cpu_buf->last_cpu_mode = -1;
  16.124 - 	cpu_buf->last_task = NULL;
  16.125 - }
  16.126 - 
  16.127 -@@ -164,13 +168,13 @@ add_code(struct oprofile_cpu_buffer * bu
  16.128 -  * because of the head/tail separation of the writer and reader
  16.129 -  * of the CPU buffer.
  16.130 -  *
  16.131 -- * is_kernel is needed because on some architectures you cannot
  16.132 -+ * cpu_mode is needed because on some architectures you cannot
  16.133 -  * tell if you are in kernel or user space simply by looking at
  16.134 -- * pc. We tag this in the buffer by generating kernel enter/exit
  16.135 -- * events whenever is_kernel changes
  16.136 -+ * pc. We tag this in the buffer by generating kernel/user (and xen)
  16.137 -+ *  enter events whenever cpu_mode changes
  16.138 -  */
  16.139 - static int log_sample(struct oprofile_cpu_buffer * cpu_buf, unsigned long pc,
  16.140 --		      int is_kernel, unsigned long event)
  16.141 -+		      int cpu_mode, unsigned long event)
  16.142 - {
  16.143 - 	struct task_struct * task;
  16.144 - 
  16.145 -@@ -181,16 +185,16 @@ static int log_sample(struct oprofile_cp
  16.146 - 		return 0;
  16.147 - 	}
  16.148 - 
  16.149 --	is_kernel = !!is_kernel;
  16.150 -+	WARN_ON(cpu_mode > CPU_MODE_XEN);
  16.151 - 
  16.152 - 	task = current;
  16.153 - 
  16.154 - 	/* notice a switch from user->kernel or vice versa */
  16.155 --	if (cpu_buf->last_is_kernel != is_kernel) {
  16.156 --		cpu_buf->last_is_kernel = is_kernel;
  16.157 --		add_code(cpu_buf, is_kernel);
  16.158 -+	if (cpu_buf->last_cpu_mode != cpu_mode) {
  16.159 -+		cpu_buf->last_cpu_mode = cpu_mode;
  16.160 -+		add_code(cpu_buf, cpu_mode);
  16.161 - 	}
  16.162 --
  16.163 -+	
  16.164 - 	/* notice a task switch */
  16.165 - 	if (cpu_buf->last_task != task) {
  16.166 - 		cpu_buf->last_task = task;
  16.167 -diff -pruN ../pristine-linux-2.6.16/drivers/oprofile/cpu_buffer.h ./drivers/oprofile/cpu_buffer.h
  16.168 ---- ../pristine-linux-2.6.16/drivers/oprofile/cpu_buffer.h	2006-03-20 05:53:29.000000000 +0000
  16.169 -+++ ./drivers/oprofile/cpu_buffer.h	2006-04-03 15:53:05.000000000 +0100
  16.170 -@@ -36,7 +36,7 @@ struct oprofile_cpu_buffer {
  16.171 - 	volatile unsigned long tail_pos;
  16.172 - 	unsigned long buffer_size;
  16.173 - 	struct task_struct * last_task;
  16.174 --	int last_is_kernel;
  16.175 -+	int last_cpu_mode;
  16.176 - 	int tracing;
  16.177 - 	struct op_sample * buffer;
  16.178 - 	unsigned long sample_received;
  16.179 -@@ -51,7 +51,9 @@ extern struct oprofile_cpu_buffer cpu_bu
  16.180 - void cpu_buffer_reset(struct oprofile_cpu_buffer * cpu_buf);
  16.181 - 
  16.182 - /* transient events for the CPU buffer -> event buffer */
  16.183 --#define CPU_IS_KERNEL 1
  16.184 --#define CPU_TRACE_BEGIN 2
  16.185 -+#define CPU_MODE_USER    0
  16.186 -+#define CPU_MODE_KERNEL  1
  16.187 -+#define CPU_MODE_XEN     2
  16.188 -+#define CPU_TRACE_BEGIN  3
  16.189 - 
  16.190 - #endif /* OPROFILE_CPU_BUFFER_H */
  16.191 -diff -pruN ../pristine-linux-2.6.16/drivers/oprofile/event_buffer.h ./drivers/oprofile/event_buffer.h
  16.192 ---- ../pristine-linux-2.6.16/drivers/oprofile/event_buffer.h	2006-03-20 05:53:29.000000000 +0000
  16.193 -+++ ./drivers/oprofile/event_buffer.h	2006-04-03 15:53:05.000000000 +0100
  16.194 -@@ -29,11 +29,12 @@ void wake_up_buffer_waiter(void);
  16.195 - #define CPU_SWITCH_CODE 		2
  16.196 - #define COOKIE_SWITCH_CODE 		3
  16.197 - #define KERNEL_ENTER_SWITCH_CODE	4
  16.198 --#define KERNEL_EXIT_SWITCH_CODE		5
  16.199 -+#define USER_ENTER_SWITCH_CODE		5
  16.200 - #define MODULE_LOADED_CODE		6
  16.201 - #define CTX_TGID_CODE			7
  16.202 - #define TRACE_BEGIN_CODE		8
  16.203 - #define TRACE_END_CODE			9
  16.204 -+#define XEN_ENTER_SWITCH_CODE		10
  16.205 -  
  16.206 - #define INVALID_COOKIE ~0UL
  16.207 - #define NO_COOKIE 0UL
  16.208 -diff -pruN ../pristine-linux-2.6.16/drivers/oprofile/oprof.c ./drivers/oprofile/oprof.c
  16.209 ---- ../pristine-linux-2.6.16/drivers/oprofile/oprof.c	2006-03-20 05:53:29.000000000 +0000
  16.210 -+++ ./drivers/oprofile/oprof.c	2006-04-03 15:53:05.000000000 +0100
  16.211 -@@ -5,6 +5,10 @@
  16.212 -  * @remark Read the file COPYING
  16.213 -  *
  16.214 -  * @author John Levon <levon@movementarian.org>
  16.215 -+ *
  16.216 -+ * Modified by Aravind Menon for Xen
  16.217 -+ * These modifications are:
  16.218 -+ * Copyright (C) 2005 Hewlett-Packard Co.
  16.219 -  */
  16.220 - 
  16.221 - #include <linux/kernel.h>
  16.222 -@@ -19,7 +23,7 @@
  16.223 - #include "cpu_buffer.h"
  16.224 - #include "buffer_sync.h"
  16.225 - #include "oprofile_stats.h"
  16.226 -- 
  16.227 -+
  16.228 - struct oprofile_operations oprofile_ops;
  16.229 - 
  16.230 - unsigned long oprofile_started;
  16.231 -@@ -33,6 +37,17 @@ static DECLARE_MUTEX(start_sem);
  16.232 -  */
  16.233 - static int timer = 0;
  16.234 - 
  16.235 -+extern unsigned int adomains;
  16.236 -+extern int active_domains[MAX_OPROF_DOMAINS];
  16.237 -+
  16.238 -+int oprofile_set_active(void)
  16.239 -+{
  16.240 -+	if (oprofile_ops.set_active)
  16.241 -+		return oprofile_ops.set_active(active_domains, adomains);
  16.242 -+
  16.243 -+	return -EINVAL;
  16.244 -+}
  16.245 -+
  16.246 - int oprofile_setup(void)
  16.247 - {
  16.248 - 	int err;
  16.249 -diff -pruN ../pristine-linux-2.6.16/drivers/oprofile/oprof.h ./drivers/oprofile/oprof.h
  16.250 ---- ../pristine-linux-2.6.16/drivers/oprofile/oprof.h	2006-03-20 05:53:29.000000000 +0000
  16.251 -+++ ./drivers/oprofile/oprof.h	2006-04-03 15:53:05.000000000 +0100
  16.252 -@@ -35,5 +35,7 @@ void oprofile_create_files(struct super_
  16.253 - void oprofile_timer_init(struct oprofile_operations * ops);
  16.254 - 
  16.255 - int oprofile_set_backtrace(unsigned long depth);
  16.256 -+
  16.257 -+int oprofile_set_active(void);
  16.258 -  
  16.259 - #endif /* OPROF_H */
  16.260 -diff -pruN ../pristine-linux-2.6.16/drivers/oprofile/oprofile_files.c ./drivers/oprofile/oprofile_files.c
  16.261 ---- ../pristine-linux-2.6.16/drivers/oprofile/oprofile_files.c	2006-03-20 05:53:29.000000000 +0000
  16.262 -+++ ./drivers/oprofile/oprofile_files.c	2006-04-03 15:53:05.000000000 +0100
  16.263 -@@ -5,15 +5,21 @@
  16.264 -  * @remark Read the file COPYING
  16.265 -  *
  16.266 -  * @author John Levon <levon@movementarian.org>
  16.267 -+ *
  16.268 -+ * Modified by Aravind Menon for Xen
  16.269 -+ * These modifications are:
  16.270 -+ * Copyright (C) 2005 Hewlett-Packard Co.	
  16.271 -  */
  16.272 - 
  16.273 - #include <linux/fs.h>
  16.274 - #include <linux/oprofile.h>
  16.275 -+#include <asm/uaccess.h>
  16.276 -+#include <linux/ctype.h>
  16.277 - 
  16.278 - #include "event_buffer.h"
  16.279 - #include "oprofile_stats.h"
  16.280 - #include "oprof.h"
  16.281 -- 
  16.282 -+
  16.283 - unsigned long fs_buffer_size = 131072;
  16.284 - unsigned long fs_cpu_buffer_size = 8192;
  16.285 - unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
  16.286 -@@ -117,11 +123,79 @@ static ssize_t dump_write(struct file * 
  16.287 - static struct file_operations dump_fops = {
  16.288 - 	.write		= dump_write,
  16.289 - };
  16.290 -- 
  16.291 -+
  16.292 -+#define TMPBUFSIZE 512
  16.293 -+
  16.294 -+unsigned int adomains = 0;
  16.295 -+long active_domains[MAX_OPROF_DOMAINS];
  16.296 -+
  16.297 -+static ssize_t adomain_write(struct file * file, char const __user * buf, 
  16.298 -+			     size_t count, loff_t * offset)
  16.299 -+{
  16.300 -+	char tmpbuf[TMPBUFSIZE];
  16.301 -+	char * startp = tmpbuf;
  16.302 -+	char * endp = tmpbuf;
  16.303 -+	int i;
  16.304 -+	unsigned long val;
  16.305 -+	
  16.306 -+	if (*offset)
  16.307 -+		return -EINVAL;	
  16.308 -+	if (!count)
  16.309 -+		return 0;
  16.310 -+	if (count > TMPBUFSIZE - 1)
  16.311 -+		return -EINVAL;
  16.312 -+
  16.313 -+	memset(tmpbuf, 0x0, TMPBUFSIZE);
  16.314 -+
  16.315 -+	if (copy_from_user(tmpbuf, buf, count))
  16.316 -+		return -EFAULT;
  16.317 -+	
  16.318 -+	for (i = 0; i < MAX_OPROF_DOMAINS; i++)
  16.319 -+		active_domains[i] = -1;
  16.320 -+	adomains = 0;
  16.321 -+
  16.322 -+	while (1) {
  16.323 -+		val = simple_strtol(startp, &endp, 0);
  16.324 -+		if (endp == startp)
  16.325 -+			break;
  16.326 -+		while (ispunct(*endp))
  16.327 -+			endp++;
  16.328 -+		active_domains[adomains++] = val;
  16.329 -+		if (adomains >= MAX_OPROF_DOMAINS)
  16.330 -+			break;
  16.331 -+		startp = endp;
  16.332 -+	}
  16.333 -+	if (oprofile_set_active())
  16.334 -+		return -EINVAL; 
  16.335 -+	return count;
  16.336 -+}
  16.337 -+
  16.338 -+static ssize_t adomain_read(struct file * file, char __user * buf, 
  16.339 -+			    size_t count, loff_t * offset)
  16.340 -+{
  16.341 -+	char tmpbuf[TMPBUFSIZE];
  16.342 -+	size_t len = 0;
  16.343 -+	int i;
  16.344 -+	/* This is all screwed up if we run out of space */
  16.345 -+	for (i = 0; i < adomains; i++) 
  16.346 -+		len += snprintf(tmpbuf + len, TMPBUFSIZE - len, 
  16.347 -+				"%u ", (unsigned int)active_domains[i]);
  16.348 -+	len += snprintf(tmpbuf + len, TMPBUFSIZE - len, "\n");
  16.349 -+	return simple_read_from_buffer((void __user *)buf, count, 
  16.350 -+				       offset, tmpbuf, len);
  16.351 -+}
  16.352 -+
  16.353 -+
  16.354 -+static struct file_operations active_domain_ops = {
  16.355 -+	.read		= adomain_read,
  16.356 -+	.write		= adomain_write,
  16.357 -+};
  16.358 -+
  16.359 - void oprofile_create_files(struct super_block * sb, struct dentry * root)
  16.360 - {
  16.361 - 	oprofilefs_create_file(sb, root, "enable", &enable_fops);
  16.362 - 	oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
  16.363 -+	oprofilefs_create_file(sb, root, "active_domains", &active_domain_ops);
  16.364 - 	oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
  16.365 - 	oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
  16.366 - 	oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
  16.367 -diff -pruN ../pristine-linux-2.6.16/include/linux/oprofile.h ./include/linux/oprofile.h
  16.368 ---- ../pristine-linux-2.6.16/include/linux/oprofile.h	2006-03-20 05:53:29.000000000 +0000
  16.369 -+++ ./include/linux/oprofile.h	2006-04-03 15:53:05.000000000 +0100
  16.370 -@@ -16,6 +16,8 @@
  16.371 - #include <linux/types.h>
  16.372 - #include <linux/spinlock.h>
  16.373 - #include <asm/atomic.h>
  16.374 -+
  16.375 -+#include <xen/interface/xenoprof.h>
  16.376 -  
  16.377 - struct super_block;
  16.378 - struct dentry;
  16.379 -@@ -27,6 +29,8 @@ struct oprofile_operations {
  16.380 - 	/* create any necessary configuration files in the oprofile fs.
  16.381 - 	 * Optional. */
  16.382 - 	int (*create_files)(struct super_block * sb, struct dentry * root);
  16.383 -+	/* setup active domains with Xen */
  16.384 -+	int (*set_active)(int *active_domains, unsigned int adomains);
  16.385 - 	/* Do any necessary interrupt setup. Optional. */
  16.386 - 	int (*setup)(void);
  16.387 - 	/* Do any necessary interrupt shutdown. Optional. */