From: Julien Grall Subject: [RFC 04/10] xen/arm64: Add an assembly macro for perf counter Date: Tue, 15 Dec 2015 17:52:02 +0000 Message-ID: <1450201928-4928-5-git-send-email-julien.grall@citrix.com> References: <1450201928-4928-1-git-send-email-julien.grall@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1a8tnk-0003EX-7j for xen-devel@lists.xenproject.org; Tue, 15 Dec 2015 17:54:16 +0000 In-Reply-To: <1450201928-4928-1-git-send-email-julien.grall@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Julien Grall , ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com List-Id: xen-devel@lists.xenproject.org Allow assembly code to use performance counter. Signed-off-by: Julien Grall --- xen/include/asm-arm/arm64/asm_defns.h | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/xen/include/asm-arm/arm64/asm_defns.h b/xen/include/asm-arm/arm64/asm_defns.h index 7085c26..36442b8 100644 --- a/xen/include/asm-arm/arm64/asm_defns.h +++ b/xen/include/asm-arm/arm64/asm_defns.h @@ -20,6 +20,42 @@ stp \xreg1, \xreg2, [sp, #-16]! ldp \xreg1, \xreg2, [sp], #16 .endm +#ifdef PERF_COUNTERS + +.macro perfc_incr, name, idx +push x0, x1 /* x0 and x1 are used by the macro -> save them */ + +/* + * Compute the address of the perf counters + * + * Note that each perf counters are 4 bytes and stored percpu. + */ +mov x0, \idx /* x0 <- index from ASM_PERFC_* */ +add x0, x0, #\name /* x0 <- index in the percpu array */ +lsl x0, x0, 2 /* x0 <- offset from per_cpu__perfcounters. */ +ldr x1, =per_cpu__perfcounters +add x0, x0, x1 /* x0 <- offset in the percpu area */ +mrs x1, TPIDR_EL2 /* x1 <- per cpu offset */ +add x0, x0, x1 /* x0 <- address of the perf counter for this cpu */ + +/* + * Increment the perf counters. + * + * Note it's not atomic so does the C version. + */ +ldr x1, [x0] /* x1 <- current value of the counter */ +add x1, x1, 1 /* x1 <- increment the counter */ +str x1, [x0] /* Store the counters incremented */ + +pop x0, x1 /* Restore x0, x1 */ +.endm + +#define PERFC_INCR(_name, _idx) perfc_incr ASM_PERFC_##_name, _idx + +#else +#define PERFC_INCR(_name, _idx) +#endif + #endif /* !__ASSEMBLY__ */ -- 2.1.4