Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4634727pxj; Wed, 12 May 2021 09:42:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7Eydih4PYNFwueXN654nRGDrfxqh8QC7smg4ofEu3uLfPlDPQap0GlSobTj/gfeUY/hsk X-Received: by 2002:aa7:c44b:: with SMTP id n11mr43767022edr.214.1620837773629; Wed, 12 May 2021 09:42:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837773; cv=none; d=google.com; s=arc-20160816; b=eyaFIIQBMgx4mLaBFlVJbzYGJtzZ+dmevBX0at9waDq3uvNHaynNMiaPSuMBa7PvGB vJMB0dPZ/ffGXY+INJUDtvCtgwtcj6tHdfWuceVhHfowweHxUEfakq+xhVXLMxcgOj+Z F3mjLySkl9bXe1C3lnC4B9KF3bNBL6pnFAaa8RhRsCWcYovMIDpqiWZGK3508xw5yKp0 eLSjHm95zfaCxsbuxNfKHIKNGUjqWe0Vwe/Qs8jR3Ngsj/ygcTF4X0oZmeFzJc0Olwpg 5XpFGYS0HEvYVlqITxqpnF70xP0QMh8XiPEMDDnWeyaJReg4bJyaWB19UKTpxdmheMnH Lo2Q== 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=yvS358aB4NAJYC39vpRpl4I19jUkRtM/m3OyRRzHs5je10oeJiQAFk1C/eoi4zvWd4 +k4PQYgEhrqkpmkiQOJErWvVxsDu7RlHdQwVQB7WTCtyH83321Z9I5chhPng5YJIII5n rl96Xiiq5FdzIp+7WQgSI+3Ij6UpOoL98MnI9BWx68grMQN2a8/a1DVugPu+EOPVmqL5 SANZREOHapvZES8zhWCbL2tbXYG2up4EyrrsY8UUURRNuyTkSnbgmlvl6Ockgxbb+1Bq V+c39SY77oRasORvUTvJX4f+Bv6tU1Hsykn740RZBPlppDZ/h+hT+Q9a9VrztAiCUAJV 79vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1Y1NCQI9; 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 n24si256928ejd.654.2021.05.12.09.42.29; Wed, 12 May 2021 09:42:53 -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=1Y1NCQI9; 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 S236100AbhELQim (ORCPT + 99 others); Wed, 12 May 2021 12:38:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:46968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236746AbhELPqC (ORCPT ); Wed, 12 May 2021 11:46:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 68434619B3; Wed, 12 May 2021 15:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833014; bh=HI8PZYpivXGOrPfhoR3n8GLzXt+BodvnNHaGtbtSxnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Y1NCQI9B2Y/UDKeU4m4HzxEiMdyoV87HuNzl0RQpM5A28JXuMVT4c5PpyYjrGpW/ Sym9BspK0MfU9HmJrT/J+rC08mJ51eM0eoRcB4c3q9WYk4crH9OCqjIuR+cpfSgdER 2pscfiwIISLR3rD3E8XhihEqwVt51fHG7cestQjs= 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.10 513/530] perf jit: Let convert_timestamp() to be backwards-compatible Date: Wed, 12 May 2021 16:50:23 +0200 Message-Id: <20210512144836.618689991@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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