From: Mikael Pettersson <mikpe@csd.uu.se>

- x86_64 arch changes

Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/x86_64/Kconfig              |    2 ++
 25-akpm/arch/x86_64/ia32/ia32entry.S     |    6 ++++++
 25-akpm/arch/x86_64/kernel/entry.S       |    5 +++++
 25-akpm/arch/x86_64/kernel/i8259.c       |    3 +++
 25-akpm/arch/x86_64/kernel/process.c     |    8 ++++++++
 25-akpm/include/asm-x86_64/hw_irq.h      |    5 +++--
 25-akpm/include/asm-x86_64/ia32_unistd.h |    8 +++++++-
 25-akpm/include/asm-x86_64/irq.h         |    2 +-
 25-akpm/include/asm-x86_64/perfctr.h     |    1 +
 25-akpm/include/asm-x86_64/processor.h   |    2 ++
 25-akpm/include/asm-x86_64/unistd.h      |   14 +++++++++++++-
 11 files changed, 51 insertions(+), 5 deletions(-)

diff -puN arch/x86_64/ia32/ia32entry.S~perfctr-x86_64 arch/x86_64/ia32/ia32entry.S
--- 25/arch/x86_64/ia32/ia32entry.S~perfctr-x86_64	2005-01-09 23:23:05.406890632 -0800
+++ 25-akpm/arch/x86_64/ia32/ia32entry.S	2005-01-09 23:23:05.423888048 -0800
@@ -591,6 +591,12 @@ ia32_sys_call_table:
 	.quad sys_add_key
 	.quad sys_request_key
 	.quad sys_keyctl
+	.quad sys_perfctr_info
+	.quad sys_vperfctr_open
+	.quad sys_vperfctr_control
+	.quad sys_vperfctr_unlink
+	.quad sys_vperfctr_iresume
+	.quad sys_vperfctr_read
 	/* don't forget to change IA32_NR_syscalls */
 ia32_syscall_end:		
 	.rept IA32_NR_syscalls-(ia32_syscall_end-ia32_sys_call_table)/8
diff -puN arch/x86_64/Kconfig~perfctr-x86_64 arch/x86_64/Kconfig
--- 25/arch/x86_64/Kconfig~perfctr-x86_64	2005-01-09 23:23:05.407890480 -0800
+++ 25-akpm/arch/x86_64/Kconfig	2005-01-09 23:23:05.424887896 -0800
@@ -449,6 +449,8 @@ config UID16
 	depends on IA32_EMULATION
 	default y
 
+source "drivers/perfctr/Kconfig"
+
 endmenu
 
 source drivers/Kconfig
diff -puN arch/x86_64/kernel/entry.S~perfctr-x86_64 arch/x86_64/kernel/entry.S
--- 25/arch/x86_64/kernel/entry.S~perfctr-x86_64	2005-01-09 23:23:05.409890176 -0800
+++ 25-akpm/arch/x86_64/kernel/entry.S	2005-01-09 23:23:05.425887744 -0800
@@ -563,6 +563,11 @@ ENTRY(spurious_interrupt)
 	apicinterrupt SPURIOUS_APIC_VECTOR,smp_spurious_interrupt
 #endif
 				
+#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_PERFCTR)
+ENTRY(perfctr_interrupt)
+	apicinterrupt LOCAL_PERFCTR_VECTOR,smp_perfctr_interrupt
+#endif
+
 /*
  * Exception entry points.
  */ 		
diff -puN arch/x86_64/kernel/i8259.c~perfctr-x86_64 arch/x86_64/kernel/i8259.c
--- 25/arch/x86_64/kernel/i8259.c~perfctr-x86_64	2005-01-09 23:23:05.410890024 -0800
+++ 25-akpm/arch/x86_64/kernel/i8259.c	2005-01-09 23:23:05.426887592 -0800
@@ -24,6 +24,7 @@
 #include <asm/delay.h>
 #include <asm/desc.h>
 #include <asm/apic.h>
+#include <asm/perfctr.h>
 
 #include <linux/irq.h>
 
@@ -562,6 +563,8 @@ void __init init_IRQ(void)
 	set_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
 #endif
 
+	perfctr_vector_init();
+
 	/*
 	 * Set the clock to HZ Hz, we already have a valid
 	 * vector now:
diff -puN arch/x86_64/kernel/process.c~perfctr-x86_64 arch/x86_64/kernel/process.c
--- 25/arch/x86_64/kernel/process.c~perfctr-x86_64	2005-01-09 23:23:05.412889720 -0800
+++ 25-akpm/arch/x86_64/kernel/process.c	2005-01-09 23:23:05.427887440 -0800
@@ -32,6 +32,7 @@
 #include <linux/delay.h>
 #include <linux/irq.h>
 #include <linux/ptrace.h>
+#include <linux/perfctr.h>
 #include <linux/version.h>
 
 #include <asm/uaccess.h>
@@ -293,6 +294,7 @@ void exit_thread(void)
 		t->io_bitmap_max = 0;
 		put_cpu();
 	}
+	perfctr_exit_thread(&me->thread);
 }
 
 void flush_thread(void)
@@ -395,6 +397,8 @@ int copy_thread(int nr, unsigned long cl
 	asm("movl %%es,%0" : "=m" (p->thread.es));
 	asm("movl %%ds,%0" : "=m" (p->thread.ds));
 
+	perfctr_copy_thread(&p->thread);
+
 	if (unlikely(me->thread.io_bitmap_ptr != NULL)) { 
 		p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
 		if (!p->thread.io_bitmap_ptr) {
@@ -445,6 +449,8 @@ struct task_struct *__switch_to(struct t
 	int cpu = smp_processor_id();  
 	struct tss_struct *tss = &per_cpu(init_tss, cpu);
 
+	perfctr_suspend_thread(prev);
+
 	unlazy_fpu(prev_p);
 
 	/*
@@ -544,6 +550,8 @@ struct task_struct *__switch_to(struct t
 		}
 	}
 
+	perfctr_resume_thread(next);
+
 	return prev_p;
 }
 
diff -puN include/asm-x86_64/hw_irq.h~perfctr-x86_64 include/asm-x86_64/hw_irq.h
--- 25/include/asm-x86_64/hw_irq.h~perfctr-x86_64	2005-01-09 23:23:05.413889568 -0800
+++ 25-akpm/include/asm-x86_64/hw_irq.h	2005-01-09 23:23:05.427887440 -0800
@@ -65,14 +65,15 @@ struct hw_interrupt_type;
  * sources per level' errata.
  */
 #define LOCAL_TIMER_VECTOR	0xef
+#define LOCAL_PERFCTR_VECTOR	0xee
 
 /*
- * First APIC vector available to drivers: (vectors 0x30-0xee)
+ * First APIC vector available to drivers: (vectors 0x30-0xed)
  * we start at 0x31 to spread out vectors evenly between priority
  * levels. (0x80 is the syscall vector)
  */
 #define FIRST_DEVICE_VECTOR	0x31
-#define FIRST_SYSTEM_VECTOR	0xef   /* duplicated in irq.h */
+#define FIRST_SYSTEM_VECTOR	0xee   /* duplicated in irq.h */
 
 
 #ifndef __ASSEMBLY__
diff -puN include/asm-x86_64/ia32_unistd.h~perfctr-x86_64 include/asm-x86_64/ia32_unistd.h
--- 25/include/asm-x86_64/ia32_unistd.h~perfctr-x86_64	2005-01-09 23:23:05.414889416 -0800
+++ 25-akpm/include/asm-x86_64/ia32_unistd.h	2005-01-09 23:23:05.428887288 -0800
@@ -294,7 +294,13 @@
 #define __NR_ia32_add_key		286
 #define __NR_ia32_request_key	287
 #define __NR_ia32_keyctl		288
+#define __NR_ia32_perfctr_info		289
+#define __NR_ia32_vperfctr_open		(__NR_ia32_perfctr_info+1)
+#define __NR_ia32_vperfctr_control	(__NR_ia32_perfctr_info+2)
+#define __NR_ia32_vperfctr_unlink	(__NR_ia32_perfctr_info+3)
+#define __NR_ia32_vperfctr_iresume	(__NR_ia32_perfctr_info+4)
+#define __NR_ia32_vperfctr_read		(__NR_ia32_perfctr_info+5)
 
-#define IA32_NR_syscalls 290	/* must be > than biggest syscall! */
+#define IA32_NR_syscalls 295	/* must be > than biggest syscall! */
 
 #endif /* _ASM_X86_64_IA32_UNISTD_H_ */
diff -puN include/asm-x86_64/irq.h~perfctr-x86_64 include/asm-x86_64/irq.h
--- 25/include/asm-x86_64/irq.h~perfctr-x86_64	2005-01-09 23:23:05.416889112 -0800
+++ 25-akpm/include/asm-x86_64/irq.h	2005-01-09 23:23:05.428887288 -0800
@@ -29,7 +29,7 @@
  */
 #define NR_VECTORS 256
 
-#define FIRST_SYSTEM_VECTOR	0xef   /* duplicated in hw_irq.h */
+#define FIRST_SYSTEM_VECTOR	0xee   /* duplicated in hw_irq.h */
 
 #ifdef CONFIG_PCI_MSI
 #define NR_IRQS FIRST_SYSTEM_VECTOR
diff -puN /dev/null include/asm-x86_64/perfctr.h
--- /dev/null	2003-09-15 06:40:47.000000000 -0700
+++ 25-akpm/include/asm-x86_64/perfctr.h	2005-01-09 23:23:05.428887288 -0800
@@ -0,0 +1 @@
+#include <asm-i386/perfctr.h>
diff -puN include/asm-x86_64/processor.h~perfctr-x86_64 include/asm-x86_64/processor.h
--- 25/include/asm-x86_64/processor.h~perfctr-x86_64	2005-01-09 23:23:05.417888960 -0800
+++ 25-akpm/include/asm-x86_64/processor.h	2005-01-09 23:23:05.429887136 -0800
@@ -252,6 +252,8 @@ struct thread_struct {
 	unsigned io_bitmap_max;
 /* cached TLS descriptors. */
 	u64 tls_array[GDT_ENTRY_TLS_ENTRIES];
+/* performance counters */
+	struct vperfctr *perfctr;
 } __attribute__((aligned(16)));
 
 #define INIT_THREAD  {}
diff -puN include/asm-x86_64/unistd.h~perfctr-x86_64 include/asm-x86_64/unistd.h
--- 25/include/asm-x86_64/unistd.h~perfctr-x86_64	2005-01-09 23:23:05.419888656 -0800
+++ 25-akpm/include/asm-x86_64/unistd.h	2005-01-09 23:23:05.430886984 -0800
@@ -562,8 +562,20 @@ __SYSCALL(__NR_add_key, sys_add_key)
 __SYSCALL(__NR_request_key, sys_request_key)
 #define __NR_keyctl		250
 __SYSCALL(__NR_keyctl, sys_keyctl)
+#define __NR_perfctr_info	251
+__SYSCALL(__NR_perfctr_info, sys_perfctr_info)
+#define __NR_vperfctr_open	(__NR_perfctr_info+1)
+__SYSCALL(__NR_vperfctr_open, sys_vperfctr_open)
+#define __NR_vperfctr_control	(__NR_perfctr_info+2)
+__SYSCALL(__NR_vperfctr_control, sys_vperfctr_control)
+#define __NR_vperfctr_unlink	(__NR_perfctr_info+3)
+__SYSCALL(__NR_vperfctr_unlink, sys_vperfctr_unlink)
+#define __NR_vperfctr_iresume	(__NR_perfctr_info+4)
+__SYSCALL(__NR_vperfctr_iresume, sys_vperfctr_iresume)
+#define __NR_vperfctr_read	(__NR_perfctr_info+5)
+__SYSCALL(__NR_vperfctr_read, sys_vperfctr_read)
 
-#define __NR_syscall_max __NR_keyctl
+#define __NR_syscall_max __NR_vperfctr_read
 #ifndef __NO_STUBS
 
 /* user-visible error numbers are in the range -1 - -4095 */
_