diff options
| author | Jeremy Fitzhardinge <jeremy@goop.org> | 2009-01-28 17:35:02 -0500 |
|---|---|---|
| committer | H. Peter Anvin <hpa@linux.intel.com> | 2009-01-30 17:51:44 -0500 |
| commit | 41edafdb78feac1d1f8823846209975fde990633 (patch) | |
| tree | 00bb95195332962916be365c6119f17a22770758 | |
| parent | 319f3ba52c71630865b10ac3b99dd020440d681d (diff) | |
x86/pvops: add a paravirt_ident functions to allow special patching
Impact: Optimization
Several paravirt ops implementations simply return their arguments,
the most obvious being the make_pte/pte_val class of operations on
native.
On 32-bit, the identity function is literally a no-op, as the calling
convention uses the same registers for the first argument and return.
On 64-bit, it can be implemented with a single "mov".
This patch adds special identity functions for 32 and 64 bit argument,
and machinery to recognize them and replace them with either nops or a
mov as appropriate.
At the moment, the only users for the identity functions are the
pagetable entry conversion functions.
The result is a measureable improvement on pagetable-heavy benchmarks
(2-3%, reducing the pvops overhead from 5 to 2%).
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
| -rw-r--r-- | arch/x86/include/asm/paravirt.h | 5 | ||||
| -rw-r--r-- | arch/x86/kernel/paravirt.c | 75 | ||||
| -rw-r--r-- | arch/x86/kernel/paravirt_patch_32.c | 12 | ||||
| -rw-r--r-- | arch/x86/kernel/paravirt_patch_64.c | 15 |
4 files changed, 98 insertions, 9 deletions
diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index 175778887090..961d10c12f16 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h | |||
| @@ -388,6 +388,8 @@ extern struct pv_lock_ops pv_lock_ops; | |||
| 388 | asm("start_" #ops "_" #name ": " code "; end_" #ops "_" #name ":") | 388 | asm("start_" #ops "_" #name ": " code "; end_" #ops "_" #name ":") |
| 389 | 389 | ||
| 390 | unsigned paravirt_patch_nop(void); | 390 | unsigned paravirt_patch_nop(void); |
| 391 | unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len); | ||
| 392 | unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len); | ||
| 391 | unsigned paravirt_patch_ignore(unsigned len); | 393 | unsigned paravirt_patch_ignore(unsigned len); |
| 392 | unsigned paravirt_patch_call(void *insnbuf, | 394 | unsigned paravirt_patch_call(void *insnbuf, |
| 393 | const void *target, u16 tgt_clobbers, | 395 | const void *target, u16 tgt_clobbers, |
| @@ -1371,6 +1373,9 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, | |||
| 1371 | } | 1373 | } |
| 1372 | 1374 | ||
| 1373 | void _paravirt_nop(void); | 1375 | void _paravirt_nop(void); |
| 1376 | u32 _paravirt_ident_32(u32); | ||
| 1377 | u64 _paravirt_ident_64(u64); | ||
| 1378 | |||
| 1374 | #define paravirt_nop ((void *)_paravirt_nop) | 1379 | #define paravirt_nop ((void *)_paravirt_nop) |
| 1375 | 1380 | ||
| 1376 | void paravirt_use_bytelocks(void); | 1381 | void paravirt_use_bytelocks(void); |
diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index 202514be5923..dd25e2b1593b 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c | |||
| @@ -44,6 +44,17 @@ void _paravirt_nop(void) | |||
| 44 | { | 44 | { |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | /* identity function, which can be inlined */ | ||
| 48 | u32 _paravirt_ident_32(u32 x) | ||
| 49 | { | ||
| 50 | return x; | ||
| 51 | } | ||
| 52 | |||
| 53 | u64 _paravirt_ident_64(u64 x) | ||
| 54 | { | ||
| 55 | return x; | ||
| 56 | } | ||
| 57 | |||
| 47 | static void __init default_banner(void) | 58 | static void __init default_banner(void) |
| 48 | { | 59 | { |
| 49 | printk(KERN_INFO "Booting paravirtualized kernel on %s\n", | 60 | printk(KERN_INFO "Booting paravirtualized kernel on %s\n", |
| @@ -138,9 +149,16 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf, | |||
| 138 | if (opfunc == NULL) | 149 | if (opfunc == NULL) |
| 139 | /* If there's no function, patch it with a ud2a (BUG) */ | 150 | /* If there's no function, patch it with a ud2a (BUG) */ |
| 140 | ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a)); | 151 | ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a)); |
| 141 | else if (opfunc == paravirt_nop) | 152 | else if (opfunc == _paravirt_nop) |
| 142 | /* If the operation is a nop, then nop the callsite */ | 153 | /* If the operation is a nop, then nop the callsite */ |
| 143 | ret = paravirt_patch_nop(); | 154 | ret = paravirt_patch_nop(); |
| 155 | |||
| 156 | /* identity functions just return their single argument */ | ||
| 157 | else if (opfunc == _paravirt_ident_32) | ||
| 158 | ret = paravirt_patch_ident_32(insnbuf, len); | ||
| 159 | else if (opfunc == _paravirt_ident_64) | ||
| 160 | ret = paravirt_patch_ident_64(insnbuf, len); | ||
| 161 | |||
| 144 | else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) || | 162 | else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) || |
| 145 | type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) || | 163 | type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) || |
| 146 | type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) || | 164 | type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) || |
| @@ -373,6 +391,45 @@ struct pv_apic_ops pv_apic_ops = { | |||
| 373 | #endif | 391 | #endif |
| 374 | }; | 392 | }; |
| 375 | 393 | ||
| 394 | typedef pte_t make_pte_t(pteval_t); | ||
| 395 | typedef pmd_t make_pmd_t(pmdval_t); | ||
| 396 | typedef pud_t make_pud_t(pudval_t); | ||
| 397 | typedef pgd_t make_pgd_t(pgdval_t); | ||
| 398 | |||
| 399 | typedef pteval_t pte_val_t(pte_t); | ||
| 400 | typedef pmdval_t pmd_val_t(pmd_t); | ||
| 401 | typedef pudval_t pud_val_t(pud_t); | ||
| 402 | typedef pgdval_t pgd_val_t(pgd_t); | ||
| 403 | |||
| 404 | |||
| 405 | #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE) | ||
| 406 | /* 32-bit pagetable entries */ | ||
| 407 | #define paravirt_native_make_pte (make_pte_t *)_paravirt_ident_32 | ||
| 408 | #define paravirt_native_pte_val (pte_val_t *)_paravirt_ident_32 | ||
| 409 | |||
| 410 | #define paravirt_native_make_pmd (make_pmd_t *)_paravirt_ident_32 | ||
| 411 | #define paravirt_native_pmd_val (pmd_val_t *)_paravirt_ident_32 | ||
| 412 | |||
| 413 | #define paravirt_native_make_pud (make_pud_t *)_paravirt_ident_32 | ||
| 414 | #define paravirt_native_pud_val (pud_val_t *)_paravirt_ident_32 | ||
| 415 | |||
| 416 | #define paravirt_native_make_pgd (make_pgd_t *)_paravirt_ident_32 | ||
| 417 | #define paravirt_native_pgd_val (pgd_val_t *)_paravirt_ident_32 | ||
| 418 | #else | ||
| 419 | /* 64-bit pagetable entries */ | ||
| 420 | #define paravirt_native_make_pte (make_pte_t *)_paravirt_ident_64 | ||
| 421 | #define paravirt_native_pte_val (pte_val_t *)_paravirt_ident_64 | ||
| 422 | |||
| 423 | #define paravirt_native_make_pmd (make_pmd_t *)_paravirt_ident_64 | ||
| 424 | #define paravirt_native_pmd_val (pmd_val_t *)_paravirt_ident_64 | ||
| 425 | |||
| 426 | #define paravirt_native_make_pud (make_pud_t *)_paravirt_ident_64 | ||
| 427 | #define paravirt_native_pud_val (pud_val_t *)_paravirt_ident_64 | ||
| 428 | |||
| 429 | #define paravirt_native_make_pgd (make_pgd_t *)_paravirt_ident_64 | ||
| 430 | #define paravirt_native_pgd_val (pgd_val_t *)_paravirt_ident_64 | ||
| 431 | #endif | ||
| 432 | |||
| 376 | struct pv_mmu_ops pv_mmu_ops = { | 433 | struct pv_mmu_ops pv_mmu_ops = { |
| 377 | #ifndef CONFIG_X86_64 | 434 | #ifndef CONFIG_X86_64 |
| 378 | .pagetable_setup_start = native_pagetable_setup_start, | 435 | .pagetable_setup_start = native_pagetable_setup_start, |
| @@ -424,21 +481,21 @@ struct pv_mmu_ops pv_mmu_ops = { | |||
| 424 | .pmd_clear = native_pmd_clear, | 481 | .pmd_clear = native_pmd_clear, |
| 425 | #endif | 482 | #endif |
| 426 | .set_pud = native_set_pud, | 483 | .set_pud = native_set_pud, |
| 427 | .pmd_val = native_pmd_val, | 484 | .pmd_val = paravirt_native_pmd_val, |
| 428 | .make_pmd = native_make_pmd, | 485 | .make_pmd = paravirt_native_make_pmd, |
| 429 | 486 | ||
| 430 | #if PAGETABLE_LEVELS == 4 | 487 | #if PAGETABLE_LEVELS == 4 |
| 431 | .pud_val = native_pud_val, | 488 | .pud_val = paravirt_native_pud_val, |
| 432 | .make_pud = native_make_pud, | 489 | .make_pud = paravirt_native_make_pud, |
| 433 | .set_pgd = native_set_pgd, | 490 | .set_pgd = native_set_pgd, |
| 434 | #endif | 491 | #endif |
| 435 | #endif /* PAGETABLE_LEVELS >= 3 */ | 492 | #endif /* PAGETABLE_LEVELS >= 3 */ |
| 436 | 493 | ||
| 437 | .pte_val = native_pte_val, | 494 | .pte_val = paravirt_native_pte_val, |
| 438 | .pgd_val = native_pgd_val, | 495 | .pgd_val = paravirt_native_pgd_val, |
| 439 | 496 | ||
| 440 | .make_pte = native_make_pte, | 497 | .make_pte = paravirt_native_make_pte, |
| 441 | .make_pgd = native_make_pgd, | 498 | .make_pgd = paravirt_native_make_pgd, |
| 442 | 499 | ||
| 443 | .dup_mmap = paravirt_nop, | 500 | .dup_mmap = paravirt_nop, |
| 444 | .exit_mmap = paravirt_nop, | 501 | .exit_mmap = paravirt_nop, |
diff --git a/arch/x86/kernel/paravirt_patch_32.c b/arch/x86/kernel/paravirt_patch_32.c index 9fe644f4861d..d9f32e6d6ab6 100644 --- a/arch/x86/kernel/paravirt_patch_32.c +++ b/arch/x86/kernel/paravirt_patch_32.c | |||
| @@ -12,6 +12,18 @@ DEF_NATIVE(pv_mmu_ops, read_cr3, "mov %cr3, %eax"); | |||
| 12 | DEF_NATIVE(pv_cpu_ops, clts, "clts"); | 12 | DEF_NATIVE(pv_cpu_ops, clts, "clts"); |
| 13 | DEF_NATIVE(pv_cpu_ops, read_tsc, "rdtsc"); | 13 | DEF_NATIVE(pv_cpu_ops, read_tsc, "rdtsc"); |
| 14 | 14 | ||
| 15 | unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len) | ||
| 16 | { | ||
| 17 | /* arg in %eax, return in %eax */ | ||
| 18 | return 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len) | ||
| 22 | { | ||
| 23 | /* arg in %edx:%eax, return in %edx:%eax */ | ||
| 24 | return 0; | ||
| 25 | } | ||
| 26 | |||
| 15 | unsigned native_patch(u8 type, u16 clobbers, void *ibuf, | 27 | unsigned native_patch(u8 type, u16 clobbers, void *ibuf, |
| 16 | unsigned long addr, unsigned len) | 28 | unsigned long addr, unsigned len) |
| 17 | { | 29 | { |
diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c index 061d01df9ae6..3f08f34f93eb 100644 --- a/arch/x86/kernel/paravirt_patch_64.c +++ b/arch/x86/kernel/paravirt_patch_64.c | |||
| @@ -19,6 +19,21 @@ DEF_NATIVE(pv_cpu_ops, usergs_sysret64, "swapgs; sysretq"); | |||
| 19 | DEF_NATIVE(pv_cpu_ops, usergs_sysret32, "swapgs; sysretl"); | 19 | DEF_NATIVE(pv_cpu_ops, usergs_sysret32, "swapgs; sysretl"); |
| 20 | DEF_NATIVE(pv_cpu_ops, swapgs, "swapgs"); | 20 | DEF_NATIVE(pv_cpu_ops, swapgs, "swapgs"); |
| 21 | 21 | ||
| 22 | DEF_NATIVE(, mov32, "mov %edi, %eax"); | ||
| 23 | DEF_NATIVE(, mov64, "mov %rdi, %rax"); | ||
| 24 | |||
| 25 | unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len) | ||
| 26 | { | ||
| 27 | return paravirt_patch_insns(insnbuf, len, | ||
| 28 | start__mov32, end__mov32); | ||
| 29 | } | ||
| 30 | |||
| 31 | unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len) | ||
| 32 | { | ||
| 33 | return paravirt_patch_insns(insnbuf, len, | ||
| 34 | start__mov64, end__mov64); | ||
| 35 | } | ||
| 36 | |||
| 22 | unsigned native_patch(u8 type, u16 clobbers, void *ibuf, | 37 | unsigned native_patch(u8 type, u16 clobbers, void *ibuf, |
| 23 | unsigned long addr, unsigned len) | 38 | unsigned long addr, unsigned len) |
| 24 | { | 39 | { |
