Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1786656yba; Sun, 14 Apr 2019 20:55:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMZkqrxWAOIZLuUjFOi1Gsgg3JNmDYf4u/a/JGsJuXOUIjURrtN8FmWRtGXv5A9/z0GQCP X-Received: by 2002:a65:64c9:: with SMTP id t9mr67144817pgv.221.1555300513642; Sun, 14 Apr 2019 20:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555300513; cv=none; d=google.com; s=arc-20160816; b=b/a8U4KWfXfgu819i7fCiBl0EQl4Mb0xLBkkrM2dALiem0Rk6E+Up6/wGDoEvOVjMW AaU6czpuie4OB7l+N3G5KL83WvzuW7DtVdHVAxHOVhHhTDbvTV8dfPlTvQYgZbRmeZFS d6My/b0jZ9jT3vJXzIfGfo4xfp67Kb7eKPc4Px1qYBU+3dPzJGZF3SIHxBQZ/tvvQ+lw zE0oNF9DcpoQeqdGyUJB1tS/elU1poTT6NKkN59nklZuIidD9BgAXpXSYKDz1+oqDXWx KAmEgKFozBpi7oXgtpYoBAk+Drgil2MRGsR+f/E/KQ7NJZhErT/f4jIeGb4cwzBjlcy5 z/pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aYWXx9wbzeeHtzHRWAY82GZFtVOfAe1wSL6TMTlf/eU=; b=sutH/O/KBhDE9HczZCU8VhGUMDmxoGyx6mIzgFpXlXuGvyXzENu3D3Px6DlyEjj85D RaJJ/JwY8b2aiTL6v6ux9QDT5tGV/pwEZ++cdZuMAlBhL3i06bBhTmLomSOBVI04Wuz+ mbRbfkoJR7/v+sEtmxdHXzAsA2ZWqzgsdYTWfM78INB+FUd4wgHmCYky/MuOc+VuNqfH Z90g7EY536jG5IVMhZu94A+vqR9wjaupLRacII7CoAn7YlwwsA4B947vDbS0bA4HVCeD ecbUutn8pAYfwX5Di16FvDC9Gfo2zQiI5XVuE5uyBvdRPS0NZ7cnI3izXihqXPwua3z/ 5+4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YsNpcdoA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11si44029010pff.201.2019.04.14.20.54.29; Sun, 14 Apr 2019 20:55:13 -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; dkim=pass header.i=@kernel.org header.s=default header.b=YsNpcdoA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726417AbfDODtS (ORCPT + 99 others); Sun, 14 Apr 2019 23:49:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:33528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725775AbfDODtR (ORCPT ); Sun, 14 Apr 2019 23:49:17 -0400 Received: from guoren-Inspiron-7460 (23.83.240.247.16clouds.com [23.83.240.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 84A8B2075B; Mon, 15 Apr 2019 03:49:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555300156; bh=64XmQf7nCf0y0YDJqs15vyxfpTggg8ygj+mwvoRyJmo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YsNpcdoA1NBQtV0A+kpNGHhoUc6XdhxNRvcxB1A2mkw7FEf53ocxPGJOvCmH/qEKX ykeh6DK6B1GIKOfdp/2hiNgtrBRpXNBwtnlAZaFwPrNAGzU11U9fvAvqm76QOYkJWq XiTgfxcmftvDK1VNPXPUUCOjWscGb+SpBzedsg/M= Date: Mon, 15 Apr 2019 11:49:01 +0800 From: Guo Ren To: Mao Han Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/3] csky: Add support for perf registers sampling Message-ID: <20190415034901.GA958@guoren-Inspiron-7460> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mao, On Thu, Apr 11, 2019 at 03:45:00PM +0800, Mao Han wrote: > 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 | 51 ++++++++++++++++++++++++++++++++++ > arch/csky/kernel/Makefile | 1 + > arch/csky/kernel/perf_regs.c | 40 ++++++++++++++++++++++++++ > 4 files changed, 94 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..ee323d8 > --- /dev/null > +++ b/arch/csky/include/uapi/asm/perf_regs.h > @@ -0,0 +1,51 @@ > +/* 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 > + > +/* Index of struct pt_regs */ > +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_A0, > + PERF_REG_CSKY_A1, > + PERF_REG_CSKY_A2, > + PERF_REG_CSKY_A3, > + PERF_REG_CSKY_REGS0, > + PERF_REG_CSKY_REGS1, > + PERF_REG_CSKY_REGS2, > + PERF_REG_CSKY_REGS3, > + PERF_REG_CSKY_REGS4, > + PERF_REG_CSKY_REGS5, > + PERF_REG_CSKY_REGS6, > + PERF_REG_CSKY_REGS7, > + PERF_REG_CSKY_REGS8, > + PERF_REG_CSKY_REGS9, > +#if defined(__CSKYABIV2__) > + PERF_REG_CSKY_EXREGS0, > + PERF_REG_CSKY_EXREGS1, > + PERF_REG_CSKY_EXREGS2, > + PERF_REG_CSKY_EXREGS3, > + PERF_REG_CSKY_EXREGS4, > + PERF_REG_CSKY_EXREGS5, > + PERF_REG_CSKY_EXREGS6, > + PERF_REG_CSKY_EXREGS7, > + PERF_REG_CSKY_EXREGS8, > + PERF_REG_CSKY_EXREGS9, > + PERF_REG_CSKY_EXREGS10, > + PERF_REG_CSKY_EXREGS11, > + PERF_REG_CSKY_EXREGS12, > + PERF_REG_CSKY_EXREGS13, > + PERF_REG_CSKY_EXREGS14, > + PERF_REG_CSKY_HI, > + PERF_REG_CSKY_LO, > + PERF_REG_CSKY_DCSR, > +#endif > + 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..88f1875 > --- /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]; Please use: return (u64)((u32 *)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); > +} Best Regards Guo Ren