From 4bc55d3b64fdf0af17f4777013a74fbef7f40ced Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Wed, 30 May 2012 10:16:32 +0200 Subject: Update to improved x86 Feather-Trace triggers This patch imports recent upstream changes in Feather-Trace that reduce register pressure around Feather-Trace triggers. References: Commits 00713b8 and 225d734 in Feather-Trace. https://github.com/brandenburg/feather-trace/commit/00713b878636867ce07291c588509b38fa5bf152 https://github.com/brandenburg/feather-trace/commit/225d7348a08682cd87f72b127142bdfd6c0c7890 --- arch/x86/include/asm/feather_trace_32.h | 96 ++++++++++++++++++++---------- arch/x86/include/asm/feather_trace_64.h | 101 +++++++++++++++++++++++++------- 2 files changed, 145 insertions(+), 52 deletions(-) (limited to 'arch') diff --git a/arch/x86/include/asm/feather_trace_32.h b/arch/x86/include/asm/feather_trace_32.h index 70202f90f169..75e81a9f9382 100644 --- a/arch/x86/include/asm/feather_trace_32.h +++ b/arch/x86/include/asm/feather_trace_32.h @@ -1,12 +1,45 @@ +/* Copyright (c) 2007-2012 Björn Brandenburg, + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + /* Do not directly include this file. Include feather_trace.h instead */ -#define feather_callback __attribute__((regparm(0))) +#define feather_callback __attribute__((regparm(3))) __attribute__((used)) /* - * make the compiler reload any register that is not saved in - * a cdecl function call + * Make the compiler reload any register that is not saved in a cdecl function + * call (minus the registers that we explicitly clobber as output registers). */ -#define CLOBBER_LIST "memory", "cc", "eax", "ecx", "edx" +#define __FT_CLOBBER_LIST0 "memory", "cc", "eax", "edx", "ecx" +#define __FT_CLOBBER_LIST1 "memory", "cc", "eax", "ecx" +#define __FT_CLOBBER_LIST2 "memory", "cc", "eax" +#define __FT_CLOBBER_LIST3 "memory", "cc", "eax" + +#define __FT_TMP1(x) "=d" (x) +#define __FT_ARG1(x) "0" ((long) (x)) +#define __FT_TMP2(x) "=c" (x) +#define __FT_ARG2(x) "1" ((long) (x)) + +#define __FT_ARG3(x) "r" ((long) (x)) #define ft_event(id, callback) \ __asm__ __volatile__( \ @@ -16,64 +49,67 @@ ".long " #id ", 0, 1b, 2f \n\t" \ ".previous \n\t" \ "2: \n\t" \ - : : : CLOBBER_LIST) + : : : __FT_CLOBBER_LIST0) #define ft_event0(id, callback) \ __asm__ __volatile__( \ "1: jmp 2f \n\t" \ - " subl $4, %%esp \n\t" \ - " movl $" #id ", (%%esp) \n\t" \ + " movl $" #id ", %%eax \n\t" \ " call " #callback " \n\t" \ - " addl $4, %%esp \n\t" \ ".section __event_table, \"aw\" \n\t" \ ".long " #id ", 0, 1b, 2f \n\t" \ ".previous \n\t" \ "2: \n\t" \ - : : : CLOBBER_LIST) + : : : __FT_CLOBBER_LIST0) -#define ft_event1(id, callback, param) \ +#define ft_event1(id, callback, param) \ + do { \ + long __ft_tmp1; \ __asm__ __volatile__( \ "1: jmp 2f \n\t" \ - " subl $8, %%esp \n\t" \ - " movl %0, 4(%%esp) \n\t" \ - " movl $" #id ", (%%esp) \n\t" \ + " movl $" #id ", %%eax \n\t" \ " call " #callback " \n\t" \ - " addl $8, %%esp \n\t" \ ".section __event_table, \"aw\" \n\t" \ ".long " #id ", 0, 1b, 2f \n\t" \ ".previous \n\t" \ "2: \n\t" \ - : : "r" (param) : CLOBBER_LIST) + : __FT_TMP1(__ft_tmp1) \ + : __FT_ARG1(param) \ + : __FT_CLOBBER_LIST1); \ + } while (0); #define ft_event2(id, callback, param, param2) \ + do { \ + long __ft_tmp1, __ft_tmp2; \ __asm__ __volatile__( \ "1: jmp 2f \n\t" \ - " subl $12, %%esp \n\t" \ - " movl %1, 8(%%esp) \n\t" \ - " movl %0, 4(%%esp) \n\t" \ - " movl $" #id ", (%%esp) \n\t" \ + " movl $" #id ", %%eax \n\t" \ " call " #callback " \n\t" \ - " addl $12, %%esp \n\t" \ ".section __event_table, \"aw\" \n\t" \ ".long " #id ", 0, 1b, 2f \n\t" \ ".previous \n\t" \ "2: \n\t" \ - : : "r" (param), "r" (param2) : CLOBBER_LIST) + : __FT_TMP1(__ft_tmp1), __FT_TMP2(__ft_tmp2) \ + : __FT_ARG1(param), __FT_ARG2(param2) \ + : __FT_CLOBBER_LIST2); \ + } while (0); -#define ft_event3(id, callback, p, p2, p3) \ +#define ft_event3(id, callback, param, param2, param3) \ + do { \ + long __ft_tmp1, __ft_tmp2; \ __asm__ __volatile__( \ "1: jmp 2f \n\t" \ - " subl $16, %%esp \n\t" \ - " movl %2, 12(%%esp) \n\t" \ - " movl %1, 8(%%esp) \n\t" \ - " movl %0, 4(%%esp) \n\t" \ - " movl $" #id ", (%%esp) \n\t" \ + " subl $4, %%esp \n\t" \ + " movl $" #id ", %%eax \n\t" \ + " movl %2, (%%esp) \n\t" \ " call " #callback " \n\t" \ - " addl $16, %%esp \n\t" \ + " addl $4, %%esp \n\t" \ ".section __event_table, \"aw\" \n\t" \ ".long " #id ", 0, 1b, 2f \n\t" \ ".previous \n\t" \ "2: \n\t" \ - : : "r" (p), "r" (p2), "r" (p3) : CLOBBER_LIST) - + : __FT_TMP1(__ft_tmp1), __FT_TMP2(__ft_tmp2) \ + : __FT_ARG1(param), __FT_ARG2(param2), __FT_ARG3(param3) \ + : __FT_CLOBBER_LIST3); \ + } while (0); diff --git a/arch/x86/include/asm/feather_trace_64.h b/arch/x86/include/asm/feather_trace_64.h index 54ac2aeb3a28..5ce49e2eebba 100644 --- a/arch/x86/include/asm/feather_trace_64.h +++ b/arch/x86/include/asm/feather_trace_64.h @@ -1,67 +1,124 @@ +/* Copyright (c) 2010 Andrea Bastoni, + * Copyright (c) 2012 Björn Brandenburg, + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + /* Do not directly include this file. Include feather_trace.h instead */ /* regparm is the default on x86_64 */ -#define feather_callback +#define feather_callback __attribute__((used)) -# define _EVENT_TABLE(id,from,to) \ +#define __FT_EVENT_TABLE(id,from,to) \ ".section __event_table, \"aw\"\n\t" \ ".balign 8\n\t" \ ".quad " #id ", 0, " #from ", " #to " \n\t" \ ".previous \n\t" /* - * x86_64 callee only owns rbp, rbx, r12 -> r15 - * the called can freely modify the others + * x86_64 caller only owns rbp, rbx, r12-r15; + * the callee can freely modify the others. */ -#define CLOBBER_LIST "memory", "cc", "rdi", "rsi", "rdx", "rcx", \ +#define __FT_CLOBBER_LIST0 "memory", "cc", "rdi", "rsi", "rdx", "rcx", \ + "r8", "r9", "r10", "r11", "rax" + +#define __FT_CLOBBER_LIST1 "memory", "cc", "rdi", "rdx", "rcx", \ + "r8", "r9", "r10", "r11", "rax" + +#define __FT_CLOBBER_LIST2 "memory", "cc", "rdi", "rcx", \ "r8", "r9", "r10", "r11", "rax" +#define __FT_CLOBBER_LIST3 "memory", "cc", "rdi", \ + "r8", "r9", "r10", "r11", "rax" + +/* The registers RDI, RSI, RDX, RCX, R8 and R9 are used for integer and pointer + * arguments. */ + +/* RSI */ +#define __FT_TMP1(x) "=S" (x) +#define __FT_ARG1(x) "0" ((long) (x)) + +/* RDX */ +#define __FT_TMP2(x) "=d" (x) +#define __FT_ARG2(x) "1" ((long) (x)) + +/* RCX */ +#define __FT_TMP3(x) "=c" (x) +#define __FT_ARG3(x) "2" ((long) (x)) + #define ft_event(id, callback) \ __asm__ __volatile__( \ "1: jmp 2f \n\t" \ " call " #callback " \n\t" \ - _EVENT_TABLE(id,1b,2f) \ + __FT_EVENT_TABLE(id,1b,2f) \ "2: \n\t" \ - : : : CLOBBER_LIST) + : : : __FT_CLOBBER_LIST0) #define ft_event0(id, callback) \ __asm__ __volatile__( \ "1: jmp 2f \n\t" \ " movq $" #id ", %%rdi \n\t" \ " call " #callback " \n\t" \ - _EVENT_TABLE(id,1b,2f) \ + __FT_EVENT_TABLE(id,1b,2f) \ "2: \n\t" \ - : : : CLOBBER_LIST) + : : : __FT_CLOBBER_LIST0) #define ft_event1(id, callback, param) \ + do { \ + long __ft_tmp1; \ __asm__ __volatile__( \ "1: jmp 2f \n\t" \ - " movq %0, %%rsi \n\t" \ " movq $" #id ", %%rdi \n\t" \ " call " #callback " \n\t" \ - _EVENT_TABLE(id,1b,2f) \ + __FT_EVENT_TABLE(id,1b,2f) \ "2: \n\t" \ - : : "r" (param) : CLOBBER_LIST) + : __FT_TMP1(__ft_tmp1) \ + : __FT_ARG1(param) \ + : __FT_CLOBBER_LIST1); \ + } while (0); #define ft_event2(id, callback, param, param2) \ + do { \ + long __ft_tmp1, __ft_tmp2; \ __asm__ __volatile__( \ "1: jmp 2f \n\t" \ - " movq %1, %%rdx \n\t" \ - " movq %0, %%rsi \n\t" \ " movq $" #id ", %%rdi \n\t" \ " call " #callback " \n\t" \ - _EVENT_TABLE(id,1b,2f) \ + __FT_EVENT_TABLE(id,1b,2f) \ "2: \n\t" \ - : : "r" (param), "r" (param2) : CLOBBER_LIST) + : __FT_TMP1(__ft_tmp1), __FT_TMP2(__ft_tmp2) \ + : __FT_ARG1(param), __FT_ARG2(param2) \ + : __FT_CLOBBER_LIST2); \ + } while (0); -#define ft_event3(id, callback, p, p2, p3) \ +#define ft_event3(id, callback, param, param2, param3) \ + do { \ + long __ft_tmp1, __ft_tmp2, __ft_tmp3; \ __asm__ __volatile__( \ "1: jmp 2f \n\t" \ - " movq %2, %%rcx \n\t" \ - " movq %1, %%rdx \n\t" \ - " movq %0, %%rsi \n\t" \ " movq $" #id ", %%rdi \n\t" \ " call " #callback " \n\t" \ - _EVENT_TABLE(id,1b,2f) \ + __FT_EVENT_TABLE(id,1b,2f) \ "2: \n\t" \ - : : "r" (p), "r" (p2), "r" (p3) : CLOBBER_LIST) + : __FT_TMP1(__ft_tmp1), __FT_TMP2(__ft_tmp2), __FT_TMP3(__ft_tmp3) \ + : __FT_ARG1(param), __FT_ARG2(param2), __FT_ARG3(param3) \ + : __FT_CLOBBER_LIST3); \ + } while (0); -- cgit v1.2.2