From patchwork Wed May 12 14:51:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 435615 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp5066095jao; Wed, 12 May 2021 11:12:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwk5mSgYscP0DO2jaR5KfrPFzI0woSU5abvafsNPWipCRBRLBEb7fZEcSANpEYwiBq0rMD7 X-Received: by 2002:a6b:d11a:: with SMTP id l26mr27418957iob.88.1620843146040; Wed, 12 May 2021 11:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620843146; cv=none; d=google.com; s=arc-20160816; b=avlS6RBzYwQU6UdtXpqqhbe9+WV7p3GvihSXQi4TbsodbIzgDiulS1ekqwT1v972Of G6IIs36keEcGW39vYRyOPmRk+qNhvqHre4wd5btx3iVs6rIEdOfMQ3ScfHHYOvSidiVc g6GHMP1uae+uK+SrmrpiVS8i93Ok77ju/OKcD3QiY/P86OUPdfjddy4ds2XDBGp9L3iw OXDq6yLnZuOMUWFlTfVPwoR4oj+YgbOzD8jr/6HoOQb4LRSJ/KQnlK1+kORC/LtZW0tp oCXSdyA3QDcCFPDH2cMB7FDi8BhQ6PXMDn1gZyeaRBZa4M7YuPt1Kmj8H0eRH7qNmuf8 BI3Q== 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=5neOmNyZ8O0jt2VoE2M+xRI1GPWa3DaTJrC6OUOupd8=; b=jn9mHkr6Gk+qdRJDBthaLtxdLXxSQE8V1//7HxG6HpJeN7B+NGcegB5DFkg/2jUfol M241PjbCW1zirNW+cwII/dbfmSI8iqaelR6h/v4UMd3vGlXSZ0NSFjANNUJ6RFlEt7HB DWpr6XbLQwf3RTh/L95usPT/M4i4zFeuXIN9GrcLqr+NU3KV/8wEI2c7TcDR+Q6zbiA1 /x5ZnHFLZntkuhcXrQZnQPnna7oB/g6QxKqXRaeoCYoFnh36kvKzq1ydzEn9R1b0OjuU GdKeTzLYd2VOAVK6pHBx+Y0J7Uxsz33WFN1NsWq7kmbTmHMhq5NvI7rzdB8hRDQuj2iM tzuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XgOCsqjL; 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 q8si330223ior.12.2021.05.12.11.12.25; Wed, 12 May 2021 11:12:26 -0700 (PDT) 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=XgOCsqjL; 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 S241872AbhELQbC (ORCPT + 12 others); Wed, 12 May 2021 12:31:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:43414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240937AbhELQ0G (ORCPT ); Wed, 12 May 2021 12:26:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D45D661DA4; Wed, 12 May 2021 15:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834542; bh=HI8PZYpivXGOrPfhoR3n8GLzXt+BodvnNHaGtbtSxnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XgOCsqjL2XrObz5Xto48n3AOimLm0TdPQBjD/SPC7RZPi6UsHs/lf8cbJyT+SjCj2 4RYt6qL4fkoJYApFoVYv1Vj4PCNPySwY1JMrB9uEc57+7Rwext5zwrAB6sn4QCG4JP ceezlCnE5f2fqhRSIWVfaTO1XWCzmXvcSvnAHFOc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Adrian Hunter , Alexander Shishkin , "Gustavo A. R. Silva" , Ingo Molnar , Jiri Olsa , Kan Liang , Mark Rutland , Namhyung Kim , Peter Zijlstra , Steve MacLean , Yonatan Goldschmidt , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.11 585/601] perf jit: Let convert_timestamp() to be backwards-compatible Date: Wed, 12 May 2021 16:51:02 +0200 Message-Id: <20210512144847.108795520@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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 [ Upstream commit aa616f5a8a2d22a179d5502ebd85045af66fa656 ] Commit d110162cafc80dad ("perf tsc: Support cap_user_time_short for event TIME_CONV") supports the extended parameters for event TIME_CONV, but it broke the backwards compatibility, so any perf data file with old event format fails to convert timestamp. This patch introduces a helper event_contains() to check if an event contains a specific member or not. For the backwards-compatibility, if the event size confirms the extended parameters are supported in the event TIME_CONV, then copies these parameters. Committer notes: To make this compiler backwards compatible add this patch: - struct perf_tsc_conversion tc = { 0 }; + struct perf_tsc_conversion tc = { .time_shift = 0, }; Fixes: d110162cafc8 ("perf tsc: Support cap_user_time_short for event TIME_CONV") Signed-off-by: Leo Yan Acked-by: Adrian Hunter Cc: Alexander Shishkin Cc: Gustavo A. R. Silva Cc: Ingo Molnar Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Steve MacLean Cc: Yonatan Goldschmidt Link: https://lore.kernel.org/r/20210428120915.7123-3-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/lib/perf/include/perf/event.h | 2 ++ tools/perf/util/jitdump.c | 30 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) -- 2.30.2 diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h index baf64ea74e10..4a24b855d3ce 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -8,6 +8,8 @@ #include #include /* pid_t */ +#define event_contains(obj, mem) ((obj).header.size > offsetof(typeof(obj), mem)) + struct perf_record_mmap { struct perf_event_header header; __u32 pid, tid; diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c index 055bab7a92b3..64d8f9ba8c03 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -369,21 +369,31 @@ jit_inject_event(struct jit_buf_desc *jd, union perf_event *event) static uint64_t convert_timestamp(struct jit_buf_desc *jd, uint64_t timestamp) { - struct perf_tsc_conversion tc; + struct perf_tsc_conversion tc = { .time_shift = 0, }; + struct perf_record_time_conv *time_conv = &jd->session->time_conv; if (!jd->use_arch_timestamp) return timestamp; - tc.time_shift = jd->session->time_conv.time_shift; - tc.time_mult = jd->session->time_conv.time_mult; - tc.time_zero = jd->session->time_conv.time_zero; - tc.time_cycles = jd->session->time_conv.time_cycles; - tc.time_mask = jd->session->time_conv.time_mask; - tc.cap_user_time_zero = jd->session->time_conv.cap_user_time_zero; - tc.cap_user_time_short = jd->session->time_conv.cap_user_time_short; + tc.time_shift = time_conv->time_shift; + tc.time_mult = time_conv->time_mult; + tc.time_zero = time_conv->time_zero; - if (!tc.cap_user_time_zero) - return 0; + /* + * The event TIME_CONV was extended for the fields from "time_cycles" + * when supported cap_user_time_short, for backward compatibility, + * checks the event size and assigns these extended fields if these + * fields are contained in the event. + */ + if (event_contains(*time_conv, time_cycles)) { + tc.time_cycles = time_conv->time_cycles; + tc.time_mask = time_conv->time_mask; + tc.cap_user_time_zero = time_conv->cap_user_time_zero; + tc.cap_user_time_short = time_conv->cap_user_time_short; + + if (!tc.cap_user_time_zero) + return 0; + } return tsc_to_perf_time(timestamp, &tc); }