From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 360BEC433E9 for ; Sat, 9 Jan 2021 07:47:02 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D6C3523A5B for ; Sat, 9 Jan 2021 07:47:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6C3523A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PQZXiwQVk13gbhIMR8Jt7c2RPCdBwTeN4WuHj19ofuE=; b=ISZUazgqudBqBWFt38ytqhtOp A1hx9ViwvrFq8YrY1yBf/k26v7Mnmc4P15ptb041OhWR9qhDqhXtY+9g9TIIMDUj34+xuBOhT2qLM O6afuAER82w2sax9+LWu3c+eUi2rUQ2ZcY3IChMx1xh9MDzvUdRG6pnv8DltfapxlTOlSZ2v/otOx hc8JB97nkRVMiUzhaP/Tu2CYrpvJj55sGnNtdiGrj0n2E6ZOwEI3Iu9OrFW1mC0FIZAsrF0D67ZXu hs7aNNe0B4/wZxBRsdgFupPfFkXdvkBBaZWmmiBkd9+cDAaLZ4EfiqHGiSPhJFlCyUKaR9JbGRjQT j2vfVFBRA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vz-00006z-Tn; Sat, 09 Jan 2021 07:45:15 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vp-0008V2-E6 for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 07:45:08 +0000 Received: by mail-pl1-x62a.google.com with SMTP id v3so6874396plz.13 for ; Fri, 08 Jan 2021 23:45:05 -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=Ur+i5mnXVMoiLpNfSuPbVvw5IIiW/Rm/SXsCiDAi43M=; b=DR0seVr8sXp6H3nk/nzWCyYbPkQz/Tq3x6qlgDrW+0tLUk6RgRd8089mjP2r+xAcuh 5Q0opjHzngmvlXI9NttaXeb28QUUY3UtDHRpyM1Oxfyvtje8fpGw2CBXlCnqcNYWY0jW hdj+zKqGJv655lAVyKqOmcBuvRDzxK173X+w3+OHo/8XkYoDC8Cxw0WdelDW2ErM6sym Fkf5wNSmCk5Hsfz9+TyVjx+YU6MPbmR7gXvpiKM6PcUu+lzTN8h8SCE5mH0jaxYmbcsu nadx/gLunFxRhE9qbPrlRhUJvXQMWBr6GjQiilQtaFSQnnI7QZMel69qRGIdbRKqsPCL wi6A== 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=Ur+i5mnXVMoiLpNfSuPbVvw5IIiW/Rm/SXsCiDAi43M=; b=RS0Fdgpq3Tpu8GdU8bApKsnPNxjN7ZF8PZkAJBqZsBtuFbBO6U+8Tqs46N6DAdrdOI vSiIJzFxZRWDpuY55LF+6zdanVLLQPzUG7RDTP42kVfBZWbLVptKGEdlTmSBZifz5GD3 iSbes8msoZrJBZjDOFf+j9Yrhl9bIxWA8eFr5WIfiNyzrOuvx8Tav4rIcm2z58/9L3yt HYQcGBcyxqBhRbhychZ0D9tNmI4ZYPo5evA2HoYAukF/krYTpXzcFVfEt8wgElzA2DJK UUk3EerXF5Bk5etyjjGvdhDTwH01b/gFkZyyDBjhtd67FQniwaAzwhnnmJHFhX6Qw5tm GNkA== X-Gm-Message-State: AOAM532ysM+1vBpl7/fBBA2h9M3y9WLHtnlxom8ndLH4Y+y9myv1tU9l YV0J3kvBXnUgeTPa7xNkenB+bw== X-Google-Smtp-Source: ABdhPJwMeGp+OT+EQHGNAS2ppjZBBcNAneyegbBDDUcJJFrAzQIDYJ4KXHZGH97MQZ+yfsIyw5wGgQ== X-Received: by 2002:a17:90a:31c3:: with SMTP id j3mr7483579pjf.25.1610178303366; Fri, 08 Jan 2021 23:45:03 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id t22sm12873711pgm.18.2021.01.08.23.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:45:02 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/7] perf cs-etm: Calculate per CPU metadata array size Date: Sat, 9 Jan 2021 15:44:31 +0800 Message-Id: <20210109074435.626855-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_024505_534871_2C8D8B48 X-CRM114-Status: GOOD ( 17.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The metadata array can be extended over time and the tool, if using the predefined macro (like CS_ETMV4_PRIV_MAX for ETMv4) as metadata array size to copy data, it can cause compatible issue within different versions of perf tool. E.g. we recorded a data file with an old version tool, afterwards if use the new version perf tool to parse the file, since the metadata array has been extended and the macro CS_ETMV4_PRIV_MAX has been altered, if use it to parse the perf data with old format, this will lead to mismatch. To maintain backward compatibility, this patch calculates per CPU metadata array size on the runtime, the calculation is based on the info stored in the data file so that it's reliable. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index a2a369e2fbb6..5e284725dceb 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2497,6 +2497,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, int i, j, k; u64 *ptr, *hdr = NULL; u64 **metadata = NULL; + int metadata_cpu_array_size; /* * sizeof(auxtrace_info_event::type) + @@ -2544,6 +2545,19 @@ int cs_etm__process_auxtrace_info(union perf_event *event, goto err_free_traceid_list; } + /* + * The metadata is a two dimensional array, the first dimension uses CPU + * number as index and the second dimension is the metadata array per + * CPU. Since the metadata array can be extended over time, the + * predefined macros (CS_ETM_PRIV_MAX or CS_ETMV4_PRIV_MAX) might + * mismatch within different versions of tool, this can lead to copy + * wrong data. To maintain backward compatibility, calculate CPU's + * metadata array size on the runtime. + */ + metadata_cpu_array_size = + (auxtrace_info->header.size - + sizeof(struct perf_record_auxtrace_info)) / num_cpu / sizeof(u64); + /* * The metadata is stored in the auxtrace_info section and encodes * the configuration of the ARM embedded trace macrocell which is @@ -2558,12 +2572,12 @@ int cs_etm__process_auxtrace_info(union perf_event *event, err = -ENOMEM; goto err_free_metadata; } - for (k = 0; k < CS_ETM_PRIV_MAX; k++) + for (k = 0; k < metadata_cpu_array_size; k++) metadata[j][k] = ptr[i + k]; /* The traceID is our handle */ idx = metadata[j][CS_ETM_ETMTRACEIDR]; - i += CS_ETM_PRIV_MAX; + i += metadata_cpu_array_size; } else if (ptr[i] == __perf_cs_etmv4_magic) { metadata[j] = zalloc(sizeof(*metadata[j]) * CS_ETMV4_PRIV_MAX); @@ -2571,12 +2585,12 @@ int cs_etm__process_auxtrace_info(union perf_event *event, err = -ENOMEM; goto err_free_metadata; } - for (k = 0; k < CS_ETMV4_PRIV_MAX; k++) + for (k = 0; k < metadata_cpu_array_size; k++) metadata[j][k] = ptr[i + k]; /* The traceID is our handle */ idx = metadata[j][CS_ETMV4_TRCTRACEIDR]; - i += CS_ETMV4_PRIV_MAX; + i += metadata_cpu_array_size; } /* Get an RB node for this CPU */ -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel