sysenter support
I've added sysenter/sysexit support for all syscalls with up to 4 parameters.
The syscalls with 5 or 6 parameters must continue to use int $0x80, I need 2 registers to pass the user space stack and instruction pointer values. The sysenter instruction destroys them.
sysenter is supported by AMD K7 and Intel Pentium II and later.
Result: simple syscall (getpid()) more than 35% faster.
before: 295 cpu ticks
now: 186 cpu ticks.
patch attached, sample code on
http://colorfullife.com/~manfred/sysenter
syscall support for K6/2 is not planned :-(
--
Manfred
// $Header$
// Kernel Version:
// VERSION = 2 // PATCHLEVEL = 4 // SUBLEVEL = 14 // EXTRAVERSION =-pre3
include/asm-i386/msr.h +4 -0
@@ -53,6 +53,10 @@#define MSR_IA32_BBL_CR_CTL 0x119 +#define MSR_IA32_SYSENTER_CS 0x174 +#define MSR_IA32_SYSENTER_ESP 0x175 +#define MSR_IA32_SYSENTER_EIP 0x176 +#define MSR_IA32_MCG_CAP 0x179#define MSR_IA32_MCG_STATUS 0x17a#define MSR_IA32_MCG_CTL 0x17b
include/asm-i386/processor.h +1 -0
@@ -90,6 +90,7 @@#define cpu_has_xmm (test_bit(X86_FEATURE_XMM, boot_cpu_data.x86_capability))#define cpu_has_fpu (test_bit(X86_FEATURE_FPU, boot_cpu_data.x86_capability))#define cpu_has_apic (test_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability)) +#define cpu_has_sep (test_bit(X86_FEATURE_SEP, boot_cpu_data.x86_capability))extern char ignore_irq13;
include/asm-i386/syscall.h +128 -0
128 lines not on this page · raw message
arch/i386/kernel/setup.c +8 -0
@@ -108,6 +108,7 @@#include <asm/dma.h> #include <asm/mpspec.h> #include <asm/mmu_context.h> +#include <asm/syscall.h> /* * Machine setup.. */
@@ -2771,6 +2772,7 @@* and IDT. We reload them nevertheless, this function acts as a * 'CPU state barrier', nothing should get across. */ +extern void system_call_SYSENTER (void );void __init cpu_init (void ) {int nr =smp_processor_id ();
@@ -2832,6 +2834,12 @@ current->flags &= ~PF_USEDFPU ; current->used_math =0 ;stts (); + +if (cpu_has_sep) { +wrmsr (MSR_IA32_SYSENTER_CS ,0x10 ,0 ); +wrmsr (MSR_IA32_SYSENTER_ESP , &sysenter_data[nr].u.cur_tsk,0 ); +wrmsr (MSR_IA32_SYSENTER_EIP , system_call_SYSENTER,0 ); + } }/*
arch/i386/kernel/process.c +4 -0
@@ -43,6 +43,7 @@#include <asm/i387.h> #include <asm/desc.h> #include <asm/mmu_context.h> +#include <asm/syscall.h> #ifdef CONFIG_MATH_EMULATION #include <asm/math_emu.h> #endif
@@ -650,6 +651,8 @@ : /* no output */ \ :"r" (thread->debugreg[register])) +union sysenter_struct sysenter_data[NR_CPUS ]; +/* * switch_to(x,yn) should switch tasks from x to y. *
@@ -679,6 +682,7 @@ *next = &next_p->thread;struct tss_struct *tss = init_tss +smp_processor_id (); + sysenter_data[smp_processor_id ()].u.cur_tsk = current;unlazy_fpu (prev_p);/*
arch/i386/kernel/traps.c +1 -1
@@ -921,7 +921,7 @@#endif set_trap_gate (0 ,÷_error); -set_trap_gate (1 ,&debug); +set_intr_gate (1 ,&debug);set_intr_gate (2 ,&nmi);set_system_gate (3 ,&int3);/* int3-5 can be called from all */ set_system_gate (4 ,&overflow);
arch/i386/kernel/entry.S +111 -10
162 lines not on this page · raw message
Quoted 2 lines · Manfred Spraul
I've added sysenter/sysexit support for all syscalls with up to 4 parameters.
[...]
Quoted 1 line
sysenter is supported by AMD K7 and Intel Pentium II and later.
How will glibc/random executable know? Keep both around forever?
Quoted 4 lines
Result: simple syscall (
getpid()) more than 35% faster.before: 295 cpu ticks
now: 186 cpu ticks.
IMVHO, the difference will be swamped by "real" work in the relevant cases. We'd need a _clean_ upgrade path (there are _still_ i386s around; on an Installfest yesterday a couple of i486s finally saw the light... and they are ample machines for their intended uses BTW). AFAIKS you will need to be able to run an i686 glibc on an i386 (install!) kernel of a random distribution for quite some time to come.
Signature · 2 lines
Horst von Brand [email protected] Casilla 9G, Vin~a del Mar, Chile +56 32 672616