Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4696351pxj; Wed, 12 May 2021 11:06:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4cTg1UM2yAmooL0zTJpJyssPwCS99TIFbxbGPNi2KqcrHJ6tRvX+dTarRkomKHcu5tqYO X-Received: by 2002:a17:906:5952:: with SMTP id g18mr38368726ejr.313.1620842789213; Wed, 12 May 2021 11:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620842789; cv=none; d=google.com; s=arc-20160816; b=DULO+K472swQVvhJA+sT7THSl0vF2dJijWHprCgX1K4LrpuH9guLqzGCQu+Z97JpQ1 geT9Lfd7T8+IxFkIIHSFH2vVjk/ypy1mMaVM3BpbmcjF5naf3WzqHHspLgbuLh3i5AJV O3Qp5eCCnsfIiqF7lcX2eya+OPbsjf48k9xuOcWhxY0lJliNtxSTcxBDgSjYJ3Nb3iHB 4C3G1IrzaE1jmret3kde4ZWHJiy2g41m/Uu1D6b1xpWzzoxiSpF8Mj2Avzndj4sU5YYT gmDK4+UIiawktV500uZ2ghydC44le7wsH8xTUVEbTmWZu8gFLn9yGyPwAoKDs0eiCX0M jeTA== 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=Hlu1E+oZbM3ZqUoVmME2kXdsFWM+mwhMCCh3i9tAeUElId2WNrjgTQc1JQq3Vs7BNc OyvwZzNbGXMfTh1xfXn85ZNZmyw3jmNL3lqfxOXn7JZMa6deGtBVjZQloWu/8xSfqXWe tN/f6mNaKyRdhX/F1op9O4kQmwvvaoFC+hXWmNbWdJxygEgXHuFNHeo2+XdiyOTsL77m 9MaPyibbNPmR+aU64SkhJlIA19bc/Z7vc7+ctyr9rommRQIC9E7HKNTsuoQqeM6btp0h 8ZCgsBES6d87TtqpfAEbNpmWdfDpUHYt+J9ES35dw7jY0pyRkasMXE2/0X8+WhVXMDfW dFGg== 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 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 r9si414638ejr.730.2021.05.12.11.06.04; Wed, 12 May 2021 11:06:29 -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=XgOCsqjL; 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 S1349256AbhELR76 (ORCPT + 99 others); Wed, 12 May 2021 13:59:58 -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 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 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); } -- 2.30.2