Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1003876yba; Mon, 1 Apr 2019 23:41:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZNd2GYpwi6zGrSkGvZSdbb0nx0+ncb1jI/8N7K0GA3IYhHEo8LaMADsNOC5l3TPoFfqvV X-Received: by 2002:a63:7885:: with SMTP id t127mr14741020pgc.338.1554187296832; Mon, 01 Apr 2019 23:41:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554187296; cv=none; d=google.com; s=arc-20160816; b=RooQlkGboc71UWSEa2DmelX4X6vevuFngGWIU21Av3cq1j6ImfQUj6YODdL1QeN29U 5BdEcIFw6ENAkOyeMIbu3TQ5GaQZYYsHxQhyJx8KLQC/zopR6Fk3wtt9sZErRD9+uJ7P H2RzdYdD2CVx9CmJqUbTx+YdQRxh+EdPR+DaWHqF96Nnm6CcLwbEIXOIdHvHSo/5OkOB Xprrn2nyAZA9REi6pVCtw5eZoVQS3J9+vKyAloo+JYQ0ZUg5wPBgLpQ8OTCNOr7wXkvR 79073HBn9ZTUKA1FOTE9u4sRJA5Ukkd4vOPF8bE+VynhIzcqGLJ3gW1j9AaPdlwjRuT5 yeQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from; bh=MajXxYffWf7o6jVXn8Z9JaP852yw1VfBTNOe32CVM/U=; b=OM+ta6mbopGh2rQGP0AGIe+qJk13pGVQ5OXiiAJoPEA8rxkOX7CllH5C+3MUB4Lnod G135aVA0Sr3YFEJR6GcqyhAXZAH8+VQoTBaTmKYO53snI1FFBVhg+W+6h9S2coWCsahO rvWqDMMwxePVtfl39EenxfybbNfMrxcGusr8NqnMJ5xBg09XK9XKIPiSXlT14sFMqMH/ 3X5Yrnu7aqJj5cbWVIjlBMy4ErUHpiMcwKgRiHOoMSfbDCjQzUNAasIa5rjh0NESq3Kv laaCDSNp1uJkD94RGLLFN4D+n2vbdWIAUU6gjU/bKt8vMW/vigx/JaC9sTi9yE+V3k8B PtyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n15si10417709pff.144.2019.04.01.23.41.21; Mon, 01 Apr 2019 23:41:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729194AbfDBGko (ORCPT + 99 others); Tue, 2 Apr 2019 02:40:44 -0400 Received: from smtp2200-217.mail.aliyun.com ([121.197.200.217]:59715 "EHLO smtp2200-217.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728768AbfDBGko (ORCPT ); Tue, 2 Apr 2019 02:40:44 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.0743722|-1;CH=green;DM=CONTINUE|CONTINUE|true|0.375491-0.016038-0.608471;FP=0|0|0|0|0|-1|-1|-1;HT=e02c03308;MF=han_mao@c-sky.com;NM=1;PH=DS;RN=3;RT=3;SR=0;TI=SMTPD_---.EFvbW3d_1554187239; Received: from localhost(mailfrom:han_mao@c-sky.com fp:SMTPD_---.EFvbW3d_1554187239) by smtp.aliyun-inc.com(10.147.40.26); Tue, 02 Apr 2019 14:40:39 +0800 From: Mao Han To: linux-kernel@vger.kernel.org Cc: Mao Han , Guo Ren Subject: [PATCH v2 1/2] csky: Add support for perf registers sampling Date: Tue, 2 Apr 2019 14:35:41 +0800 Message-Id: <20c1eb16f0a4fa59ea8479cc5bff54871413ac86.1554186270.git.han_mao@c-sky.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch implements the perf registers sampling and validation API for csky arch. The valid registers and their register ID are defined in perf_regs.h. Perf tool can backtrace in userspace with unwind library and the registers/user stack dump support. CC: Guo Ren Signed-off-by: Mao Han --- arch/csky/Kconfig | 2 ++ arch/csky/include/uapi/asm/perf_regs.h | 48 ++++++++++++++++++++++++++++++++++ arch/csky/kernel/Makefile | 1 + arch/csky/kernel/perf_regs.c | 40 ++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 arch/csky/include/uapi/asm/perf_regs.h create mode 100644 arch/csky/kernel/perf_regs.c diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig index c4974cf..8e45c7a 100644 --- a/arch/csky/Kconfig +++ b/arch/csky/Kconfig @@ -38,6 +38,8 @@ config CSKY select HAVE_KERNEL_LZO select HAVE_KERNEL_LZMA select HAVE_PERF_EVENTS + select HAVE_PERF_REGS + select HAVE_PERF_USER_STACK_DUMP select HAVE_DMA_API_DEBUG select HAVE_DMA_CONTIGUOUS select HAVE_SYSCALL_TRACEPOINTS diff --git a/arch/csky/include/uapi/asm/perf_regs.h b/arch/csky/include/uapi/asm/perf_regs.h new file mode 100644 index 0000000..337d8fa --- /dev/null +++ b/arch/csky/include/uapi/asm/perf_regs.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. + +#ifndef _ASM_CSKY_PERF_REGS_H +#define _ASM_CSKY_PERF_REGS_H + +enum perf_event_csky_regs { + PERF_REG_CSKY_TLS, + PERF_REG_CSKY_LR, + PERF_REG_CSKY_PC, + PERF_REG_CSKY_SR, + PERF_REG_CSKY_SP, + PERF_REG_CSKY_ORIG_A0, + PERF_REG_CSKY_R0, + PERF_REG_CSKY_R1, + PERF_REG_CSKY_R2, + PERF_REG_CSKY_R3, + PERF_REG_CSKY_R4, + PERF_REG_CSKY_R5, + PERF_REG_CSKY_R6, + PERF_REG_CSKY_R7, + PERF_REG_CSKY_R8, + PERF_REG_CSKY_R9, + PERF_REG_CSKY_R10, + PERF_REG_CSKY_R11, + PERF_REG_CSKY_R12, + PERF_REG_CSKY_R13, + PERF_REG_CSKY_R16, + PERF_REG_CSKY_R17, + PERF_REG_CSKY_R18, + PERF_REG_CSKY_R19, + PERF_REG_CSKY_R20, + PERF_REG_CSKY_R21, + PERF_REG_CSKY_R22, + PERF_REG_CSKY_R23, + PERF_REG_CSKY_R24, + PERF_REG_CSKY_R25, + PERF_REG_CSKY_R26, + PERF_REG_CSKY_R27, + PERF_REG_CSKY_R28, + PERF_REG_CSKY_R29, + PERF_REG_CSKY_R30, + PERF_REG_CSKY_HI, + PERF_REG_CSKY_LO, + PERF_REG_CSKY_DCSR, + PERF_REG_CSKY_MAX, +}; +#endif /* _ASM_CSKY_PERF_REGS_H */ diff --git a/arch/csky/kernel/Makefile b/arch/csky/kernel/Makefile index 4c462f5..1624b04 100644 --- a/arch/csky/kernel/Makefile +++ b/arch/csky/kernel/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_CSKY_PMU_V1) += perf_event.o obj-$(CONFIG_PERF_EVENTS) += perf_callchain.o +obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) diff --git a/arch/csky/kernel/perf_regs.c b/arch/csky/kernel/perf_regs.c new file mode 100644 index 0000000..153c8f6 --- /dev/null +++ b/arch/csky/kernel/perf_regs.c @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. + +#include +#include +#include +#include +#include +#include + +u64 perf_reg_value(struct pt_regs *regs, int idx) +{ + if (WARN_ON_ONCE((u32)idx >= PERF_REG_CSKY_MAX)) + return 0; + + return ((long *)regs)[idx]; +} + +#define REG_RESERVED (~((1ULL << PERF_REG_CSKY_MAX) - 1)) + +int perf_reg_validate(u64 mask) +{ + if (!mask || mask & REG_RESERVED) + return -EINVAL; + + return 0; +} + +u64 perf_reg_abi(struct task_struct *task) +{ + return PERF_SAMPLE_REGS_ABI_32; +} + +void perf_get_regs_user(struct perf_regs *regs_user, + struct pt_regs *regs, + struct pt_regs *regs_user_copy) +{ + regs_user->regs = task_pt_regs(current); + regs_user->abi = perf_reg_abi(current); +} -- 2.7.4