Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp629672imj; Sat, 9 Feb 2019 04:56:56 -0800 (PST) X-Google-Smtp-Source: AHgI3IY4eMi0jdCHL0izNEm4tsmW47v8gtV5fQfNXqHx/T004j+ua4wgm+GQjjfe3lCZbsDRsOD1 X-Received: by 2002:a62:138f:: with SMTP id 15mr3247930pft.219.1549717016519; Sat, 09 Feb 2019 04:56:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549717016; cv=none; d=google.com; s=arc-20160816; b=In/Xk3wJ/tNi+U8dLcFV9UpPsFqsOlFm3oY0ue4WHT7fBgY51q3BkDVW7cRzu8tpNV 7Ff/PE0GHV0EHRUPsR68a+x9RTPvL/KGtcMXkXRhcaDKXVbVoIVGf9PZ4+N4HnSuzaRo gvNaZhFFYVK5KTQvEkZ7Z1McBO7VeH9Km+95h1kQfvAtUubuCQpXLC9DyjebP9qds3yt YLC5VT9GPHOlM6QnvFDn1l5nln3EMvFxCa1d32VQRtzViSstM6bSzPQh56p3HtWlyFy9 eF+M58M2m/QwSYVBkPs/Z0ZzGTNW3EAeBHozLAfbx4JF/X35NXKtFuJCO9YUfBOdpH1p OUuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=40+dBfPSpPK5vfRMuAyy/8Xvx6QhWfhVvLsup9r1Uk0=; b=h7B6nrLCFo5u3kLkWMan5/C1Nu0nEwfbCguL0tMQWmUMx6m/rq91HoF8HhvgjrmFKa VKTeKz+YhguqtHpJ9HlnkEJjMw6vsCOkH03badTUroKjb08yvNmRou+aBbh9/VGBriWl Ryw4LaLsZUDslkIB55mGI9IFjC17qifsGHqlMHZFh5eCL6YZCpnMk+OX2IEzkNQKJ9P1 W+ej09+KKHGQglWy+i3/qP275+5U3yFgIlseKU5P6FcEfnYfWcU/RpJX/oW5BWnqAGu0 IXJfoVQIzTy+1Jufet4T0p/5HmYTP6272caqwnnXSgsuFt/IsiB+3v2DJkSN68JhLMNH C9Bg== 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 v11si5386403plo.377.2019.02.09.04.56.41; Sat, 09 Feb 2019 04:56:56 -0800 (PST) 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 S1727074AbfBIM4Y (ORCPT + 99 others); Sat, 9 Feb 2019 07:56:24 -0500 Received: from terminus.zytor.com ([198.137.202.136]:48869 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726703AbfBIM4Y (ORCPT ); Sat, 9 Feb 2019 07:56:24 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x19CuCgs2633496 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 9 Feb 2019 04:56:12 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x19CuB062633493; Sat, 9 Feb 2019 04:56:11 -0800 Date: Sat, 9 Feb 2019 04:56:11 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Leo Yan Message-ID: Cc: mike.leach@linaro.org, coresight@lists.linaro.org, tglx@linutronix.de, leo.yan@linaro.org, suzuki.poulose@arm.com, acme@redhat.com, linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org, namhyung@kernel.org, hpa@zytor.com, jolsa@redhat.com, mingo@kernel.org, alexander.shishkin@linux.intel.com, robert.walker@arm.com Reply-To: linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org, namhyung@kernel.org, hpa@zytor.com, jolsa@redhat.com, alexander.shishkin@linux.intel.com, mingo@kernel.org, robert.walker@arm.com, mike.leach@linaro.org, coresight@lists.linaro.org, tglx@linutronix.de, leo.yan@linaro.org, suzuki.poulose@arm.com, acme@redhat.com In-Reply-To: <20190129122842.32041-9-leo.yan@linaro.org> References: <20190129122842.32041-9-leo.yan@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf cs-etm: Set sample flags for exception return packet Git-Commit-ID: 173e65f6bc354dc07c6be399727a8a48335bccf2 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 173e65f6bc354dc07c6be399727a8a48335bccf2 Gitweb: https://git.kernel.org/tip/173e65f6bc354dc07c6be399727a8a48335bccf2 Author: Leo Yan AuthorDate: Tue, 29 Jan 2019 20:28:42 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 6 Feb 2019 10:00:40 -0300 perf cs-etm: Set sample flags for exception return packet When return from exception, we need to distinguish if it's system call return or for other type exceptions for setting sample flags. Due to the exception return packet doesn't contain exception number, so we cannot decide sample flags based on exception number. On the other hand, the exception return packet is followed by an instruction range packet; this range packet deliveries the start address after exception handling, we can check if it is a SVC instruction just before the start address. If there has one SVC instruction is found ahead the return address, this means it's an exception return for system call; otherwise it is an normal return for other exceptions. This patch is to set sample flags for exception return packet, firstly it simply set sample flags as PERF_IP_FLAG_INTERRUPT for all exception returns since at this point it doesn't know what's exactly the exception type. We will defer to decide if it's an exception return for system call when the next instruction range packet comes, it checks if there has one SVC instruction prior to the start address and if so we will change sample flags to PERF_IP_FLAG_SYSCALLRET for system call return. Signed-off-by: Leo Yan Reviewed-by: Mathieu Poirier Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Mike Leach Cc: Namhyung Kim Cc: Robert Walker Cc: Suzuki K Poulouse Cc: coresight ml Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190129122842.32041-9-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index a714b31656ea..8b3f882d6e2f 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1372,6 +1372,20 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) if (prev_packet->sample_type == CS_ETM_DISCONTINUITY) prev_packet->flags |= PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN; + + /* + * If the previous packet is an exception return packet + * and the return address just follows SVC instuction, + * it needs to calibrate the previous packet sample flags + * as PERF_IP_FLAG_SYSCALLRET. + */ + if (prev_packet->flags == (PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_INTERRUPT) && + cs_etm__is_svc_instr(etmq, packet, packet->start_addr)) + prev_packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_SYSCALLRET; break; case CS_ETM_DISCONTINUITY: /* @@ -1422,6 +1436,36 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) prev_packet->flags = packet->flags; break; case CS_ETM_EXCEPTION_RET: + /* + * When the exception return packet is inserted, since + * exception return packet is not used standalone for + * generating samples and it's affiliation to the previous + * instruction range packet; so set previous range packet + * flags to tell perf it is an exception return branch. + * + * The exception return can be for either system call or + * other exception types; unfortunately the packet doesn't + * contain exception type related info so we cannot decide + * the exception type purely based on exception return packet. + * If we record the exception number from exception packet and + * reuse it for excpetion return packet, this is not reliable + * due the trace can be discontinuity or the interrupt can + * be nested, thus the recorded exception number cannot be + * used for exception return packet for these two cases. + * + * For exception return packet, we only need to distinguish the + * packet is for system call or for other types. Thus the + * decision can be deferred when receive the next packet which + * contains the return address, based on the return address we + * can read out the previous instruction and check if it's a + * system call instruction and then calibrate the sample flag + * as needed. + */ + if (prev_packet->sample_type == CS_ETM_RANGE) + prev_packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_INTERRUPT; + break; case CS_ETM_EMPTY: default: break;