Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp248486yba; Fri, 12 Apr 2019 02:48:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqw42eRdMJGfIj+wnt+cshMdkyrisVpo3cjQUo58rYm+YXjakrzAVZfVdWJcWYxW3lcCGGWb X-Received: by 2002:a17:902:ab91:: with SMTP id f17mr52094901plr.151.1555062489824; Fri, 12 Apr 2019 02:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555062489; cv=none; d=google.com; s=arc-20160816; b=caYUl/1EEffBdiSUybnG3l1DKxH+6N9NlB/6GvgmcZaZEY7Rznt7mIESRLAaMKuSiS CQ3QMkDxVpdWLQdjj57N0Bp0HM8fS8Pw28+HiR+C4KSTPgWIVLE3CDk9MxvCDGzcKrr5 MzWM57OKi5F19WHy6DXZ1ewh1pICvZmfVj0yksn1tI9c/SOQhyCuw3CVMxVye7dxoUGx i1EUcke6CoAPW/xGtfSLtoBhgvNv/aquVO7yzqdtgW5RxK++JL0cmKyBzBBd0j2/XPF+ JkiJWfzPnHQbIMt76mdaY7st45pI2riAZ5ttc+iVQnwGsN7gasuNRSNFxs6eKq5clp6+ umwg== 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; bh=lOY1S7FtP1EckhfO9/2tkjwnWKl3CFE8ATFU5aSFr8k=; b=rXPXXxpdCaldtIZG6O2fKQZXI/4uT9fP6atWaOmG6ZyMrFjxA5u/SIIZt7OAUw/DFX 4xWHEI+EtxTmmk29Krapy02u8+VPABTWmoaRlfe5Ui104dJrVRnTjrfmOLEJt0HPwSYo WYV5lR1g9Zz9iVn6ZCI1GOMCSplW/GpgYF6Y01ZkLebpBCZCxYhdTLXmZ9PYjn2OI+h6 gZnu0TvkmK+iUR3UiN4PzmqtERYXCynqgDL0NQOYKkfykonOjyxboIJPoYYhOUaUGJcL +HhIItQuwU55gdJ7u7zDoXzHQ/xt67S2timiacrMz/FJXsVv419b1+qF9tHXht2iPxBx kNmg== 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 h22si31014733pfn.238.2019.04.12.02.47.53; Fri, 12 Apr 2019 02:48:09 -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 S1726827AbfDLJp4 (ORCPT + 99 others); Fri, 12 Apr 2019 05:45:56 -0400 Received: from smtp2200-217.mail.aliyun.com ([121.197.200.217]:39739 "EHLO smtp2200-217.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726706AbfDLJpz (ORCPT ); Fri, 12 Apr 2019 05:45:55 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07436637|-1;CH=green;DM=CONTINUE|CONTINUE|true|0.382202-0.0130681-0.60473;FP=0|0|0|0|0|-1|-1|-1;HT=e02c03309;MF=han_mao@c-sky.com;NM=1;PH=DS;RN=3;RT=3;SR=0;TI=SMTPD_---.EKKGL1c_1555062352; Received: from localhost(mailfrom:han_mao@c-sky.com fp:SMTPD_---.EKKGL1c_1555062352) by smtp.aliyun-inc.com(10.147.42.253); Fri, 12 Apr 2019 17:45:52 +0800 Date: Fri, 12 Apr 2019 17:38:53 +0800 From: Mao Han To: Christoph Hellwig Cc: linux-kernel@vger.kernel.org, guoren@kernel.org Subject: Re: [PATCH 2/3] riscv: Add support for perf registers sampling Message-ID: <20190412093851.GA4961@vmh-VirtualBox> References: <20190411141435.GA8343@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190411141435.GA8343@infradead.org> 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 On Thu, Apr 11, 2019 at 07:24:32AM -0700, Christoph Hellwig wrote: > > --- /dev/null > > +++ b/arch/riscv/kernel/perf_callchain.c > > @@ -0,0 +1,122 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. > > Please use normal /* */ Style comment for everything but the SPDX > tags. > OK > Please do early exists for all the error conditions. Also no casts > are needed for using ->fp as a scalar value, and we should probably > just do a struct copy instead of copying both values individually. > > The function should look something like: > > static int unwind_frame_kernel(struct stackframe *frame) > { > if (!kstack_end((void *)frame->fp)) > return -EPERM; > if ((frame->fp & 0x3 || frame->fp >= TASK_SIZE) > return -EPERM; > > *frame = *((struct stackframe *)frame->fp - 1); > if (__kernel_text_address(frame->ra)) { > int graph = 0; > > frame->ra = ftrace_graph_ret_addr(NULL, &graph, frame->ra, > NULL); > } > return 0; > } > Thanks for suggestion. It looks much better with the modification. > > Why not: > > do { > perf_callchain_store(entry, fr->ra); > } while (unwind_frame_kernel(fr) >= 0); > Yes, it's much simpler. > > +/* > > + * Get the return address for a single stackframe and return a pointer to the > > + * next frame tail. > > + */ > > +static unsigned long user_backtrace(struct perf_callchain_entry_ctx *entry, > > + unsigned long fp, unsigned long reg_ra) > > +{ > > + struct stackframe buftail; > > + unsigned long ra = 0; > > + unsigned long *user_frame_tail = (unsigned long *)(fp - sizeof(struct stackframe)); > > Overly long line. Will fix the style. > > > + fp = user_backtrace(entry, fp, regs->ra); > > + while ((entry->nr < entry->max_stack) && > > + fp && !((unsigned long)fp & 0x3)) > > + fp = user_backtrace(entry, fp, 0); > > Please don't indent the condition continuation and the loop body > by the same amount. Like this? while ((entry->nr < entry->max_stack) && fp && !((unsigned long)fp & 0x3)) fp = user_backtrace(entry, fp, 0); Thanks, Mao Han