Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp628513imj; Sat, 9 Feb 2019 04:55:06 -0800 (PST) X-Google-Smtp-Source: AHgI3IZdLbPHYAuSL6lucEvVkv7dE0guaCo6wTkf7MdFKULkCaeyfwXcTFjSABY4l0Cp5Hp+zcKc X-Received: by 2002:a63:1753:: with SMTP id 19mr9973471pgx.439.1549716905970; Sat, 09 Feb 2019 04:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549716905; cv=none; d=google.com; s=arc-20160816; b=t9oTUe3PucPNCKYEOzMH5IPIziOPPux6a60w9zCswz9y4kvSa+aYfQh41gdnF9xpZQ s33BmYEEH5q+xjWq4H/zA2sTLJ5iXAcNsyrT/Ny1HKSElrzIgxw9WPrfugCQYv215L2M D6YD/3SfYvJlElSVzVA22HVS18vIhpmq9lFyTYHGMkrzhCS9TUlYztWEfKecc8PJE8iC OQE8Ck5p0MFJhQ4453IJHTqCYGfW3ap9ABsF1bd1aBrQybQ8buZLDe8zDU9jqmjI0Q5K ysaZoxyq8whEZzCt+9ZRAYFGCMvUng81Eciz/73Gw2FdntEYljqs9vodVmbHhMU/AU0n X3/A== 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=b/ngqoi+U//nStAastr+EZQNz0HjPptuH31AtnRqJi0=; b=MzGqfx7LMKAEChqDGNoV2LD75mahM0ztqO43Q0YBPIy/3igdzDSOdaamnvHtKT6rfW vR5Zcv168AuGAWQh7zAvi6Iof//oAaUt1iv0KkKlLckdCwetScDUJeGJ+lVz+9p1Zv0t NeoGhlTkBwdvzUKK5pn7WvyVkI6raKszTu/fDFE4ZTVXdc1n8mCAMSvkaBgy/1qnoQYO dnyh0/+iiyosbR64HNSGPfnif6U5ZKO2WVNMl9jHeo0BKpmYvWTDOdIRVuYwEPnCVzoQ iGhcpppVqxBnjH8KOzUtlqYO7pjO3Ur3dAIhwo3zNtyracTjEpIZeWb1TxPPev+aYqcO sTbA== 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 q8si4574069pgv.516.2019.02.09.04.54.50; Sat, 09 Feb 2019 04:55:05 -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 S1726979AbfBIMyY (ORCPT + 99 others); Sat, 9 Feb 2019 07:54:24 -0500 Received: from terminus.zytor.com ([198.137.202.136]:41587 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726703AbfBIMyY (ORCPT ); Sat, 9 Feb 2019 07:54: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 x19CsBQZ2633273 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 9 Feb 2019 04:54:11 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x19CsANl2633268; Sat, 9 Feb 2019 04:54:10 -0800 Date: Sat, 9 Feb 2019 04:54:10 -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: acme@redhat.com, coresight@lists.linaro.org, linux-kernel@vger.kernel.org, jolsa@redhat.com, mathieu.poirier@linaro.org, alexander.shishkin@linux.intel.com, namhyung@kernel.org, leo.yan@linaro.org, hpa@zytor.com, suzuki.poulose@arm.com, mingo@kernel.org, tglx@linutronix.de, robert.walker@arm.com, mike.leach@linaro.org Reply-To: mingo@kernel.org, tglx@linutronix.de, mike.leach@linaro.org, robert.walker@arm.com, acme@redhat.com, coresight@lists.linaro.org, hpa@zytor.com, suzuki.poulose@arm.com, jolsa@redhat.com, linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org, alexander.shishkin@linux.intel.com, namhyung@kernel.org, leo.yan@linaro.org In-Reply-To: <20190129122842.32041-6-leo.yan@linaro.org> References: <20190129122842.32041-6-leo.yan@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata Git-Commit-ID: 95c6fe970a0160cb770c5dce9f80311b42d030c0 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: 95c6fe970a0160cb770c5dce9f80311b42d030c0 Gitweb: https://git.kernel.org/tip/95c6fe970a0160cb770c5dce9f80311b42d030c0 Author: Leo Yan AuthorDate: Tue, 29 Jan 2019 20:28:39 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 6 Feb 2019 10:00:40 -0300 perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata If packet processing wants to know the packet is bound with which ETM version, it needs to access metadata to decide that based on metadata magic number; but we cannot simply to use CPU logic ID number as index to access metadata sequential array, especially when system have hotplugged off CPUs, the metadata array are only allocated for online CPUs but not offline CPUs, so the CPU logic number doesn't match with its index in the array. This patch is to change tuple from traceID-CPU# to traceID-metadata, thus it can use the tuple to retrieve metadata pointer according to traceID. For safe accessing metadata fields, this patch provides helper function cs_etm__get_cpu() which is used to return CPU number according to traceID; cs_etm_decoder__buffer_packet() is the first consumer for this helper function. 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-6-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 8 +++----- tools/perf/util/cs-etm.c | 26 +++++++++++++++++++------ tools/perf/util/cs-etm.h | 9 ++++++++- 3 files changed, 31 insertions(+), 12 deletions(-) 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 294efa76c9e3..cdd38ffd10d2 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -305,14 +305,12 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, enum cs_etm_sample_type sample_type) { u32 et = 0; - struct int_node *inode = NULL; + int cpu; if (decoder->packet_count >= MAX_BUFFER - 1) return OCSD_RESP_FATAL_SYS_ERR; - /* Search the RB tree for the cpu associated with this traceID */ - inode = intlist__find(traceid_list, trace_chan_id); - if (!inode) + if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0) return OCSD_RESP_FATAL_SYS_ERR; et = decoder->tail; @@ -322,7 +320,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, decoder->packet_buffer[et].sample_type = sample_type; decoder->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN; - decoder->packet_buffer[et].cpu = *((int *)inode->priv); + decoder->packet_buffer[et].cpu = cpu; decoder->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR; decoder->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR; decoder->packet_buffer[et].instr_count = 0; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 1aa29633ce77..a5497a761db7 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -97,6 +97,20 @@ static u32 cs_etm__get_v7_protocol_version(u32 etmidr) return CS_ETM_PROTO_ETMV3; } +int cs_etm__get_cpu(u8 trace_chan_id, int *cpu) +{ + struct int_node *inode; + u64 *metadata; + + inode = intlist__find(traceid_list, trace_chan_id); + if (!inode) + return -EINVAL; + + metadata = inode->priv; + *cpu = (int)metadata[CS_ETM_CPU]; + return 0; +} + static void cs_etm__packet_dump(const char *pkt_string) { const char *color = PERF_COLOR_BLUE; @@ -252,7 +266,7 @@ static void cs_etm__free(struct perf_session *session) cs_etm__free_events(session); session->auxtrace = NULL; - /* First remove all traceID/CPU# nodes for the RB tree */ + /* First remove all traceID/metadata nodes for the RB tree */ intlist__for_each_entry_safe(inode, tmp, traceid_list) intlist__remove(traceid_list, inode); /* Then the RB tree itself */ @@ -1519,9 +1533,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event, 0xffffffff); /* - * Create an RB tree for traceID-CPU# tuple. Since the conversion has - * to be made for each packet that gets decoded, optimizing access in - * anything other than a sequential array is worth doing. + * Create an RB tree for traceID-metadata tuple. Since the conversion + * has to be made for each packet that gets decoded, optimizing access + * in anything other than a sequential array is worth doing. */ traceid_list = intlist__new(NULL); if (!traceid_list) { @@ -1587,8 +1601,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, err = -EINVAL; goto err_free_metadata; } - /* All good, associate the traceID with the CPU# */ - inode->priv = &metadata[j][CS_ETM_CPU]; + /* All good, associate the traceID with the metadata pointer */ + inode->priv = metadata[j]; } /* diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 37f8d48179ca..fb5fc6538b7f 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -53,7 +53,7 @@ enum { CS_ETMV4_PRIV_MAX, }; -/* RB tree for quick conversion between traceID and CPUs */ +/* RB tree for quick conversion between traceID and metadata pointers */ struct intlist *traceid_list; #define KiB(x) ((x) * 1024) @@ -69,6 +69,7 @@ static const u64 __perf_cs_etmv4_magic = 0x4040404040404040ULL; #ifdef HAVE_CSTRACE_SUPPORT int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session); +int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); #else static inline int cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, @@ -76,6 +77,12 @@ cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, { return -1; } + +static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused, + int *cpu __maybe_unused) +{ + return -1; +} #endif #endif