Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4753560pxj; Wed, 12 May 2021 12:27:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtpdIOKp7Ri7QYTz4564stTD6P7VANzzVFdxDmwA9jFkTX/mVihfu5L0huAeVwTf8QOe7w X-Received: by 2002:a17:907:209b:: with SMTP id pv27mr39678276ejb.475.1620847643523; Wed, 12 May 2021 12:27:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620847643; cv=none; d=google.com; s=arc-20160816; b=DnRPC4oqUzYi/PC4gBX5ow5iqCoHyE/omWFTZ6mgPE/KIz5erFCB9RuTQYietEhh7m 364IslCXpVwiRlbunNH7GS5uLgDZnhuLeSDzYFCq7OMQqNkLaOI/tPgY/iAownNNCN3c bOGttQAhnE0pl9o7FWDcV7E67mFMArKkelKJAhfzcKWQYDz6PLp0tJoi5CxNoKXQ8IoY h8h/FtzwjZxo/pkaba3OwvKEwCwK6oOrY45a6VHpsZdaRj/N1z93Pr11JrqquT9s3WiZ BTP/i+BFTvyj3HbC1YC30TSCV8h5gd5hwaxiv+5q28ejEIQ1yVFO8fU6GKgx+FEWJzc9 gbIw== 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=BkqXHxCUq+mawY+J6kwRvp79fcKZRZLdJFWDJXfJSV8=; b=zlPDTURNAOwu/Dx1G5NWimTi71CZvwZ5c59zrE/GMVQJVNRTa7pKWC59piFARnUii0 i4m1jrvy1LORGisJLHafVy7Hu5jNWFtWfIODHnEO4s9UvQWPWpCj3koOhdFhFwJvHC5Z rUqP1fzMZEVVFOD9kf12WC2aZOGBPupDZEqKU4RR2EuosIxOz9lLb3wVwZkQ73dDv35g Toe59j7I4DKmmWbHRzJ+6/ynFvU5P68iy5nAdYR6VHv6VZZSoqxfshTcvjtB+aQe1FEm g0FOymuskR8ST3YMCETRLiLD9KQx+tMQhXT8xYLy8vNDpY5p4BPqnx0OhM6aIk0ABkFn 6u0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="OcsKXL/e"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 bl1si705407ejb.408.2021.05.12.12.27.00; Wed, 12 May 2021 12:27:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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="OcsKXL/e"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S1379575AbhELTUB (ORCPT + 99 others); Wed, 12 May 2021 15:20:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:46180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244603AbhELQuz (ORCPT ); Wed, 12 May 2021 12:50:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4B84861C76; Wed, 12 May 2021 16:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620836225; bh=lya4Eis2gaA2HHKEgyY1VtTilRUWD6mcSu/7R90kPQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OcsKXL/eTA8BzJFvrydrHpaINryg9e7/tKB1BOMlWZAD7a72VB+FN0zXFAOzLMwxY MZ5cPZmt9SVNMZXI7q7X8c4LL+U8A1tMjrQ+/WRnC5aWa1T6uMKJgN4dl0UT9+K3kS PvWJQhaT4pVu8BucsP0+SiWuYWJLkpuqRRZ4Bny4= 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.12 661/677] perf jit: Let convert_timestamp() to be backwards-compatible Date: Wed, 12 May 2021 16:51:47 +0200 Message-Id: <20210512144859.323487981@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h index 48583e441d9b..4d0c02ba3f7d 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 9760d8e7b386..917a9c707371 100644 --- a/tools/perf/util/jitdump.c +++ b/tools/perf/util/jitdump.c @@ -396,21 +396,31 @@ static pid_t jr_entry_tid(struct jit_buf_desc *jd, union jr_entry *jr) 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); } -- 2.30.2