From patchwork Mon Dec 28 12:46:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 352744 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp10017545ejs; Mon, 28 Dec 2020 08:13:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwobRn5zS67bN3BrBcCFJgVYBk+SRxoxRD868ETDIp/gqEuUWHD5iA195e08JPjj0dGg+cr X-Received: by 2002:a17:906:73d8:: with SMTP id n24mr41591902ejl.14.1609171988439; Mon, 28 Dec 2020 08:13:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609171988; cv=none; d=google.com; s=arc-20160816; b=cE3gf2zQ7Mlqf8Jwoj1GhDNyKdgGI1AYOm7vwgKINRdkKgfBGnMAeYdlxaGK82/n7Z INU/0Clvhtqj+5wKnDbOQtyG73oeK3ENkZaaya0fvsMJjGPmUQ2HOtjtivw8KlyudWKG zj7dh/xCBVq0VoSzg3mBxcAhd/W+dklzyhwaOUv33ImFCDSG85qp5sFo/tNkZHWxAEb7 00LxkR3kNd89lWszgMlcTiZkYex92XDtVl9dVhoLiqioGWhaMG054l6WcKUc7plqh8nP 4K2WWaHQjKwTDIFjOd1mrsAMkM3chRCLi4d8yl/1AEAsmZA1BfdrxavJkW2ufLmeH3Nm jyUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b+OAaBCQ4zRC4mkzJS57guKsKGfEWKjiZ0x67I7aJvU=; b=fAmH8q5ZD8KFO4TbGVN/L1M8gwVGDopqZEIC2V7gCGVw3oHo5rQ9vuJ2ZgC9L+6Grn Zc9t9PntYM4+8sCNvLtbzd8/g8r1ApJmvYTWxMefpCzJ+KR3enSEQr+RMJIIRA9q5JBc IbeishqGFTJvthZgXxhHaBUWVoPw/ddES0iTIC9okZzzlR1BLjzwFws2y9Q3AyEewHHY hDIFaqS/8ZDDj4xxzbbH/nIHCmb6Nv00qfprwztRKvtaabuqpLlzeNzMukLKFcXZGXM8 VihxHtHOB1QbXCDZe+DOHGlF0Edfn/wWKBMyvMSlV0dtxYxjWiwEN+nN22CR22cAjVzn /Xmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UgZbuJNs; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m7si20973349eji.682.2020.12.28.08.13.08; Mon, 28 Dec 2020 08:13:08 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UgZbuJNs; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388725AbgL1NY3 (ORCPT + 14 others); Mon, 28 Dec 2020 08:24:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:53020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388721AbgL1NY2 (ORCPT ); Mon, 28 Dec 2020 08:24:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D07B9207CF; Mon, 28 Dec 2020 13:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161827; bh=xQZzOKXdTP2mrsRRfw4ZTRq5unwnpnLPpQdgxceI5JY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UgZbuJNsyRH2PUGFYYo6/qggMSLugOJxPAgTd624av4yZFxMIUb1pxpkiyulklxZA xqtfn4CrDaj5CAfg32V3Y6vwf8BeTlbbmlGWz0WkOv1rjmp5Vkbs+DQmK1Re0ZpQcD F8hCMjDD2T01KTLxlcvz1zK2CiZLAJr2+ZeFizdU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Mike Leach , Namhyung Kim , Robert Walker , Suzuki K Poulouse , coresight ml , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo , Salvatore Bonaccorso Subject: [PATCH 4.19 096/346] perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata Date: Mon, 28 Dec 2020 13:46:55 +0100 Message-Id: <20201228124924.430787678@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124919.745526410@linuxfoundation.org> References: <20201228124919.745526410@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Leo Yan commit 95c6fe970a0160cb770c5dce9f80311b42d030c0 upstream. 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 [Salvatore Bonaccorso: Adjust for context changes in tools/perf/util/cs-etm-decoder/cs-etm-decoder.c] Signed-off-by: Salvatore Bonaccorso Signed-off-by: Greg Kroah-Hartman --- 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(-) --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -278,14 +278,12 @@ cs_etm_decoder__buffer_packet(struct cs_ 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; @@ -296,7 +294,7 @@ cs_etm_decoder__buffer_packet(struct cs_ decoder->packet_buffer[et].sample_type = sample_type; decoder->packet_buffer[et].exc = false; decoder->packet_buffer[et].exc_ret = false; - 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; --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -91,6 +91,20 @@ static int cs_etm__update_queues(struct static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm, pid_t tid, u64 time_); +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; @@ -230,7 +244,7 @@ static void cs_etm__free(struct perf_ses 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 */ @@ -1316,9 +1330,9 @@ int cs_etm__process_auxtrace_info(union 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) { @@ -1384,8 +1398,8 @@ int cs_etm__process_auxtrace_info(union 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]; } /* --- 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 #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 { return -1; } + +static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused, + int *cpu __maybe_unused) +{ + return -1; +} #endif #endif