From patchwork Sun Nov 11 05:07:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 150761 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1711934ljp; Sat, 10 Nov 2018 21:09:25 -0800 (PST) X-Google-Smtp-Source: AJdET5dgzNup0k2eSmq4v2qzpmt/h4oeXYerhcq/bHY5nrlItVo1BsKgr8++wOx0zPdf18Wn7Ztr X-Received: by 2002:a63:164d:: with SMTP id 13-v6mr13170663pgw.103.1541912965114; Sat, 10 Nov 2018 21:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541912965; cv=none; d=google.com; s=arc-20160816; b=XJTUqy1m+GH0j9k6Zed6FHfKwR6wBnRNwMiZODZgYbGZ2xPe1smmZBW+Deqt3upixc eYoCXM4cTe/+uhuARu93+ECMyB3bjRCLh5QmNVtlcwrLhrQhyDyU66o65wFSbXy4hY7p sRlADl81v/rJcviaCDd1SAA9+rSJx7fuZ/W+mlkjyLhfGc2BI2XHvFVHRSqx2WYDFtjV sqq5hvEu0Lsfv173KQ2fgUnFwvePmhqxTpErOlrpt7jz5qMwaWiolxl3TdQyIqWthnpA mxLx0ywp/FrX5Kt8Vp+GpXv/4Y79MC3jn+lIXiBujMb2EK1Gth4lElJjstlDkYVmErvv XBeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IpysccI4tiar+JnEcil+VyAiAvlJ0KJWiSPDxFKq5/g=; b=UnvQXpAfOoL9eLUXdlFmkTYgYwPLntAAozoZAHpCBWzR7X65eJoiTiagURtLetstZh DE7m3kubbi7j/sOgPXcD0TILujt64stdAfj/2vTx9CrphncHAkv35ejLDfBhAa80IbQe ag606YJX4jGk2KH5ty4xVM9y5DIA6284RSIruy2j1qwLuNqW8suV/jyxHtNtdtls15wl 5/Vf/L7kRBUu/na306ouUSrSETVUwcwel7Qzeq+/3ohlIKPu7/0tIbi/bNGHlwrtyW1Z T28jDTYQweMFQKaXBhTywDvvxvh6e+Y7CmTdCTfa82/yndXbyF3eYCGYe+BgwM1Pi9Ut RscQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gbl26GSr; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e11si6553348pgf.450.2018.11.10.21.09.24; Sat, 10 Nov 2018 21:09:25 -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; dkim=pass header.i=@linaro.org header.s=google header.b=gbl26GSr; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727520AbeKKO4G (ORCPT + 32 others); Sun, 11 Nov 2018 09:56:06 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35189 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbeKKO4G (ORCPT ); Sun, 11 Nov 2018 09:56:06 -0500 Received: by mail-wm1-f68.google.com with SMTP id t15-v6so5242232wmt.0 for ; Sat, 10 Nov 2018 21:08:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IpysccI4tiar+JnEcil+VyAiAvlJ0KJWiSPDxFKq5/g=; b=gbl26GSr86Ktyv4GnLNigzAgCGBmDDL1Sg4aOP6qg+7Pjs+qFvdMYabXyelK5wGTW3 Z8SQh21XkpOTqQz9kIste4Pcy+CEuaVyRxqOo2rGSUZxgg26E0qb/zLpBv27/BmdAqTE LxrcsRLQ2erCdqGMMwHn3NBLvcMKxfN04oruE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IpysccI4tiar+JnEcil+VyAiAvlJ0KJWiSPDxFKq5/g=; b=TGDu3GkJ4l5WD2x0CHUvKF/5suWulGMdg/T8LNTPtvcBQHHyh3sdET/M+xMq5DSQGH hGQ9JKi8hthLrkV8eTnLrVLex1xLCgievcdmGRIsS6MUMQcX2Qyeji/GGXDGLuaWf+kX Q0Q3julN+Pz9VDduKRnO3UKuqDJDZQ0LQX+sMiM3GhPoIwrN7K6iACBwEKw7VuEQiuLc pfxWP+heWraW6EsnaDamWoG9L4NclRkc7W/AFSf9GdOBnQQo47T34S1PooeMwf1tux2X mh7H/wSpu6rTgo2FOp5QaJ6CGXv11x8j4r82LDq9GIxo3bg7cGIDSSouWYVtcmRJYH8U 0ACg== X-Gm-Message-State: AGRZ1gKBYL7zjwC0O2mGrkViYYulhu+TD/IoLw1Q8wbZgkxIrDZlmcCp LD3jF0TtQpnuwA9aw7E0YXBH9nITfmhrPQ== X-Received: by 2002:a1c:3c83:: with SMTP id j125-v6mr3785373wma.65.1541912915586; Sat, 10 Nov 2018 21:08:35 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id b66-v6sm4471045wmb.21.2018.11.10.21.08.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Nov 2018 21:08:34 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Robert Walker , Al Grant , Coresight ML Cc: Leo Yan , Andi Kleen , Adrian Hunter , Arnaldo Carvalho de Melo Subject: [PATCH v2 1/2] perf cs-etm: Set branch instruction flags in packet Date: Sun, 11 Nov 2018 13:07:55 +0800 Message-Id: <1541912876-20967-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541912876-20967-1-git-send-email-leo.yan@linaro.org> References: <1541912876-20967-1-git-send-email-leo.yan@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The perf sample data contains flags to indicate the hardware trace data is belonging to which type branch instruction, thus this can be used to print out the human readable string. Arm CoreSight ETM sample data is missed to set flags and it is always set to zeros, this results in perf tool skips to print string for instruction types. Arm CoreSight ETM supports different kinds instruction of A64, A32 and T32; this patch is to set branch instruction flags in packet for these ISAs. The brief idea for patch implementation is describe as below: - For element with OCSD_GEN_TRC_ELEM_TRACE_ON type, it is taken as trace beginning packet; for element with OCSD_GEN_TRC_ELEM_NO_SYNC or OCSD_GEN_TRC_ELEM_EO_TRACE, these two kinds elements are used to set for trace end; As Mike suggested the packet stream might have more than one two TRACE_ON packets, the first one TRACE_ON packet indicates trace end and the second one is taken as trace restarting. We will handle this special case in the upper layer with packet queue handling, which has more context so it's more suitable fix up for it. This will be accomplished in the sequential patch. - For instruction range packet, mainly base on three factors to decide the branch instruction types: elem->last_i_type elem->last_i_subtype elem->last_instr_cond If the instruction is immediate branch but without link and return flag, we consider it as function internal branch; in fact the immediate branch also can be used to invoke the function entry, usually this is only used in assembly code to directly call a symbol and don't expect to return back; after reviewing kernel normal functions and user space programs, both of them are very seldom to use immediate branch for function call. On the other hand, if we want to decide the immediate branch is for function branch jumping or for function calling, we need to rely on the start address of next packet and check the symbol offset for the start address, this will introduce much complexity in the implementation. So for this version we simply consider immediate branch as function internal branch. Moreover, we rely on 'elem->last_instr_cond' to decide if the branch instruction is a conditional branch or not. If the instruction is immediate branch with link, it's instruction 'BL' and which is used for function call. If the instruction is indirect branch and with subtype OCSD_S_INSTR_V7_IMPLIED_RET, the decoders gives the hint the function return for below cases related with A32/T32 instruction; set this branch flag as function return (Thanks for Al's suggestion). BX R14 MOV PC, LR POP {…, PC} LDR PC, [SP], #offset If the instruction is indirect branch without link, this is corresponding to instruction 'BR', this instruction usually is used for dynamic link lib with below usage; so we think it's a return instruction. 0000000000000680 <.plt>: 680: a9bf7bf0 stp x16, x30, [sp, #-16]! 684: 90000090 adrp x16, 10000 <__FRAME_END__+0xf630> 688: f947fe11 ldr x17, [x16, #4088] 68c: 913fe210 add x16, x16, #0xff8 690: d61f0220 br x17 If the instruction is indirect branch with link, e.g BLR, we think it's a function call. For function return, ARMv8 introduces a dedicated instruction 'ret', which has flag of OCSD_S_INSTR_V8_RET. - For exception packets, this patch divides into three types: The first type of exception is caused by external logics like bus, interrupt controller, debug module or PE reset or halt; this is corresponding to flags "bcyi" which defined in doc perf-script.txt; The second type is for system call, this is set as "bcs" by following definition in the doc; The third type is for CPU trap, data and instruction prefetch abort, alignment abort; usually these exceptions are synchronous for CPU, so set them as "bci" type. Cc: Mathieu Poirier Cc: Mike Leach Cc: Robert Walker Cc: Al Grant Cc: Andi Kleen Cc: Adrian Hunter Cc: Arnaldo Carvalho de Melo Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 168 ++++++++++++++++++++++++ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 1 + 2 files changed, 169 insertions(+) -- 2.7.4 diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index d1a6cbc..0e50c52 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -303,6 +303,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, decoder->packet_buffer[et].instr_count = 0; decoder->packet_buffer[et].last_instr_taken_branch = false; decoder->packet_buffer[et].last_instr_size = 0; + decoder->packet_buffer[et].flags = 0; if (decoder->packet_count == MAX_BUFFER - 1) return OCSD_RESP_WAIT; @@ -437,6 +438,171 @@ cs_etm_decoder__buffer_exception_ret(struct cs_etm_decoder *decoder, CS_ETM_EXCEPTION_RET); } +static void cs_etm_decoder__set_sample_flags( + const void *context, + const ocsd_generic_trace_elem *elem) +{ + struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context; + struct cs_etm_packet *packet; + u32 exc_num; + + packet = &decoder->packet_buffer[decoder->tail]; + + switch (elem->elem_type) { + case OCSD_GEN_TRC_ELEM_TRACE_ON: + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_TRACE_BEGIN; + break; + + case OCSD_GEN_TRC_ELEM_NO_SYNC: + case OCSD_GEN_TRC_ELEM_EO_TRACE: + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_TRACE_END; + break; + + case OCSD_GEN_TRC_ELEM_INSTR_RANGE: + /* + * Immediate branch instruction without neither link nor + * return flag, it's normal branch instruction within + * the function. + */ + if (elem->last_i_type == OCSD_INSTR_BR && + elem->last_i_subtype == OCSD_S_INSTR_NONE) { + packet->flags = PERF_IP_FLAG_BRANCH; + + if (elem->last_instr_cond) + packet->flags |= PERF_IP_FLAG_CONDITIONAL; + } + + /* + * Immediate branch instruction with link (e.g. BL), this is + * branch instruction for function call. + */ + if (elem->last_i_type == OCSD_INSTR_BR && + elem->last_i_subtype == OCSD_S_INSTR_BR_LINK) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL; + + /* + * Indirect branch instruction with subtype of + * OCSD_S_INSTR_V7_IMPLIED_RET, this is explicit hint for + * function return for A32/T32. + */ + if (elem->last_i_type == OCSD_INSTR_BR_INDIRECT && + elem->last_i_subtype == OCSD_S_INSTR_V7_IMPLIED_RET) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN; + + /* + * Indirect branch instruction without link (e.g. BR), usually + * this is used for function return, especially for functions + * within dynamic link lib. + */ + if (elem->last_i_type == OCSD_INSTR_BR_INDIRECT && + elem->last_i_subtype == OCSD_S_INSTR_NONE) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN; + + /* + * Indirect branch instruction with link (e.g. BLR), this is + * branch instruction for function call. + */ + if (elem->last_i_type == OCSD_INSTR_BR_INDIRECT && + elem->last_i_subtype == OCSD_S_INSTR_BR_LINK) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL; + + /* Return instruction for function return. */ + if (elem->last_i_type == OCSD_INSTR_BR_INDIRECT && + elem->last_i_subtype == OCSD_S_INSTR_V8_RET) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN; + + break; + + case OCSD_GEN_TRC_ELEM_EXCEPTION: + +#define OCSD_EXC_RESET 0 +#define OCSD_EXC_DEBUG_HALT 1 +#define OCSD_EXC_CALL 2 +#define OCSD_EXC_TRAP 3 +#define OCSD_EXC_SYSTEM_ERROR 4 +#define OCSD_EXC_INST_DEBUG 6 +#define OCSD_EXC_DATA_DEBUG 7 +#define OCSD_EXC_ALIGNMENT 10 +#define OCSD_EXC_INST_FAULT 11 +#define OCSD_EXC_DATA_FAULT 12 +#define OCSD_EXC_IRQ 14 +#define OCSD_EXC_FIQ 15 + + exc_num = decoder->exc_num[packet->cpu]; + + /* + * The exceptions are triggered by external signals + * from bus, interrupt controller, debug module, + * PE reset or halt. + */ + if (exc_num == OCSD_EXC_RESET || + exc_num == OCSD_EXC_DEBUG_HALT || + exc_num == OCSD_EXC_SYSTEM_ERROR || + exc_num == OCSD_EXC_INST_DEBUG || + exc_num == OCSD_EXC_DATA_DEBUG || + exc_num == OCSD_EXC_IRQ || + exc_num == OCSD_EXC_FIQ) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL | + PERF_IP_FLAG_ASYNC | + PERF_IP_FLAG_INTERRUPT; + + /* The exception is for system call. */ + if (exc_num == OCSD_EXC_CALL) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL | + PERF_IP_FLAG_SYSCALLRET; + + /* + * The exception is introduced by trap, instruction & + * data fault or alignment errors. + */ + if (exc_num == OCSD_EXC_TRAP || + exc_num == OCSD_EXC_ALIGNMENT || + exc_num == OCSD_EXC_INST_FAULT || + exc_num == OCSD_EXC_DATA_FAULT) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL | + PERF_IP_FLAG_INTERRUPT; + + break; + + case OCSD_GEN_TRC_ELEM_EXCEPTION_RET: + + exc_num = decoder->exc_num[packet->cpu]; + + if (exc_num == OCSD_EXC_CALL) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_SYSCALLRET; + else + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_INTERRUPT; + + break; + + case OCSD_GEN_TRC_ELEM_UNKNOWN: + case OCSD_GEN_TRC_ELEM_PE_CONTEXT: + case OCSD_GEN_TRC_ELEM_ADDR_NACC: + case OCSD_GEN_TRC_ELEM_TIMESTAMP: + case OCSD_GEN_TRC_ELEM_CYCLE_COUNT: + case OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN: + case OCSD_GEN_TRC_ELEM_EVENT: + case OCSD_GEN_TRC_ELEM_SWTRACE: + case OCSD_GEN_TRC_ELEM_CUSTOM: + default: + break; + } +} + static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( const void *context, const ocsd_trc_index_t indx __maybe_unused, @@ -484,6 +650,8 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( break; } + cs_etm_decoder__set_sample_flags(context, elem); + return resp; } diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h index 0d1c18d..71df908 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -47,6 +47,7 @@ struct cs_etm_packet { u8 last_instr_taken_branch; u8 last_instr_size; int cpu; + u32 flags; }; struct cs_etm_queue; From patchwork Sun Nov 11 05:07:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 150762 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1711939ljp; Sat, 10 Nov 2018 21:09:25 -0800 (PST) X-Google-Smtp-Source: AJdET5fPkZbC1GC5a30whtBAArlnd+Qhr15fqdY4XfctRfxX9t9CDhCBGsttaE+4XzrIX6OPnWqv X-Received: by 2002:aa7:8685:: with SMTP id d5-v6mr15070773pfo.58.1541912965444; Sat, 10 Nov 2018 21:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541912965; cv=none; d=google.com; s=arc-20160816; b=bfpXj6WTBDz2QeuLloxYcqiPoKtoVUltmoqWIJc1N66u2O8u4NWaTmvFpNkuRd38hL qTp0TIGg1nAldtOwTlC4JAFXmZ5ptGmISTDo734B7mWXQb9RHO4qrORi9C2nsTrHMuIm fNDnAtL7IDWHvuPHkgUXRBPZXBbDzuchTQ3f7qhIMvw+AiY3RgzhNieozcd8iPfj3h6q il5igAK2UcyapW/+JXqebX9vKwrT4f3ablw0+NrC9A5ap0SWbZVuOGIR4r619hePhvub nKNk9pq2mgy0ZdQYuZWQZIe4FHh6Afm6LkyyKwkrbLDwjb3ewW0ALnpDAHVjaj60Y1ge 43jA== 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:message-id:date :subject:cc:to:from:dkim-signature; bh=pL2xknDZRwx/bgQqRwh/znrlZfSxh+MEAgrn8ZwKjac=; b=O2n3+7IQfnuZxmSH+vi+LV+jDbjilvDgIBT19UjOzILg+4aJlBtaM6FvoRg7CoPbcK zt3oYh5C+DAH9Fu7oLlGeP7wVO9IOMA6fcN7oMbc5NKeK0u1IfP1rq/Y4zzJctcLjb0O E8osooAVJEuJ2rWklXqSaX/LmtBQsRQTvqAJIcB2dsSr5lgNSFvLCaKGo9bIa5viArj2 myTEkoEcYejNIeJBojhW9rIr0oageUeb4CdeUqiKaztm5WL86bvJPbPtghAYfNiw4f9l c3WYSshdbsymyvSntEh6CYIYjefOMKbHVSekAe94qvaDOeF1fDg6lHJS22hwfbckGH9E 4IAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kQgyYqdQ; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e11si6553348pgf.450.2018.11.10.21.09.25; Sat, 10 Nov 2018 21:09:25 -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; dkim=pass header.i=@linaro.org header.s=google header.b=kQgyYqdQ; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727564AbeKKO4L (ORCPT + 32 others); Sun, 11 Nov 2018 09:56:11 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:54138 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbeKKO4K (ORCPT ); Sun, 11 Nov 2018 09:56:10 -0500 Received: by mail-wm1-f66.google.com with SMTP id f10-v6so5386255wme.3 for ; Sat, 10 Nov 2018 21:08:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pL2xknDZRwx/bgQqRwh/znrlZfSxh+MEAgrn8ZwKjac=; b=kQgyYqdQSKpbnqwzWAvdB/oKD3LzuVUyZUN0jf65YU7d65DqRtXR1tqf9objsH0bWn h5bsPDarwmSjDUILJSqluaLGlL2x7c+tk2BS2Uvf+bd2Bqfb2CpG2uLR17mj0cmH66ns /LPm3OxoxSGB/QDvKDyOWonsbd1qp9lsGOyRU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pL2xknDZRwx/bgQqRwh/znrlZfSxh+MEAgrn8ZwKjac=; b=PXJkx2EehxVRQxp06XOYUvi+DlZ/NTYl/JdlYbcsxXbUkz0sEfl57v61BF7hO56+9U 0s9s4K++Dme8cJpinW+OZnaO5ht8qfeP+dhMemHILoShDVW7yKo/g0VQACMLL05ac6HB MsT6vMwzKCfrBAUatrYZdbnqpff+pKuomWPskPS/Rr0JIxta45N5+EKo8XueMjdPhsPS q5zrhMq946rUPNY/Aqz5IgiG1Z/aidyOzjhskT3leM35Py5EaX2RYweTsClTUGVMuADT sZqiw/kcxmb6mvp/K+WzWCCe/2NyHwI23gRyQ1DNmjLxHlrMqPqSKO3qILH9ZNbYP28U 0wBA== X-Gm-Message-State: AGRZ1gLb2yuAkYG/WvGNCBdXGTVfVFAIzbZ5MVwFuWBee6vB6fyiSX/j C7ZoARi2ichROwvChZL/QWO3y8XEAZP79w== X-Received: by 2002:a1c:6754:: with SMTP id b81-v6mr4118328wmc.104.1541912919839; Sat, 10 Nov 2018 21:08:39 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id b66-v6sm4471045wmb.21.2018.11.10.21.08.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Nov 2018 21:08:39 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Robert Walker , Al Grant , Coresight ML Cc: Leo Yan Subject: [PATCH v2 2/2] perf cs-etm: Add support sample flags Date: Sun, 11 Nov 2018 13:07:56 +0800 Message-Id: <1541912876-20967-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541912876-20967-1-git-send-email-leo.yan@linaro.org> References: <1541912876-20967-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have prepared the flags in the packet structure, so need to copy the related value into sample structure thus perf tool can facilitate sample flags. The PREV_PACKET contains the branch instruction flags and PACKET actually contains the flags for next branch instruction. So this patch is to set sample flags with 'etmq->prev_packet->flags'. This patch includes three fixing up for sample flags based on the packets context: - If the packet is exception packet or exception return packet, update the previous packet for exception specific flags; - If there has TRACE_ON or TRACE_OFF packet in the middle of instruction packets, this indicates the trace is discontinuous, so append the flag PERF_IP_FLAG_TRACE_END to the previous packet to indicate the trace has been ended; - If one instruction packet is behind TRACE_OFF packet, this instruction is restarting trace packet. So set flag PERF_IP_FLAG_TRACE_START to TRACE_OFF packet if one, this flag isn't used by TRACE_OFF packet but used to indicate trace restarting when generate sample. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 455f132..afca6f3 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -676,7 +676,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, sample.stream_id = etmq->etm->instructions_id; sample.period = period; sample.cpu = etmq->packet->cpu; - sample.flags = 0; + sample.flags = etmq->prev_packet->flags; sample.insn_len = 1; sample.cpumode = event->sample.header.misc; @@ -735,7 +735,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq) sample.stream_id = etmq->etm->branches_id; sample.period = 1; sample.cpu = etmq->packet->cpu; - sample.flags = 0; + sample.flags = etmq->prev_packet->flags; sample.cpumode = event->sample.header.misc; /* @@ -878,6 +878,43 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, return 0; } +static void cs_etm__fixup_flags(struct cs_etm_queue *etmq) +{ + /* + * Decoding stream might insert one TRACE_OFF packet in the + * middle of instruction packets, this means it doesn't + * contain the pair packets with TRACE_OFF and TRACE_ON. + * For this case, the instruction packet follows with + * TRACE_OFF packet so we need to fixup prev_packet with flag + * PERF_IP_FLAG_TRACE_BEGIN, this flag finally is used by the + * instruction packet to generate samples. + */ + if (etmq->prev_packet->sample_type == CS_ETM_TRACE_OFF && + etmq->packet->sample_type == CS_ETM_RANGE) + etmq->prev_packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_TRACE_BEGIN; + + if (etmq->prev_packet->sample_type == CS_ETM_RANGE) { + /* + * When the exception packet is inserted, update flags + * so tell perf it is exception related branches. + */ + if (etmq->packet->sample_type == CS_ETM_EXCEPTION || + etmq->packet->sample_type == CS_ETM_EXCEPTION_RET) + etmq->prev_packet->flags = etmq->packet->flags; + + /* + * The trace is discontinuous, weather this is caused by + * TRACE_ON packet or TRACE_OFF packet is coming, if the + * previous packet is instruction packet, simply set flag + * PERF_IP_FLAG_TRACE_END for previous packet. + */ + if (etmq->packet->sample_type == CS_ETM_TRACE_ON || + etmq->packet->sample_type == CS_ETM_TRACE_OFF) + etmq->prev_packet->flags |= PERF_IP_FLAG_TRACE_END; + } +} + static int cs_etm__sample(struct cs_etm_queue *etmq) { struct cs_etm_auxtrace *etm = etmq->etm; @@ -1100,6 +1137,8 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) */ break; + cs_etm__fixup_flags(etmq); + switch (etmq->packet->sample_type) { case CS_ETM_RANGE: /*