From patchwork Wed May 12 14:50:23 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: 435584 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp4977652jao; Wed, 12 May 2021 09:17:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzKTuUdfnrRHmavd6v0Zwp1hplsfDymsnno/edsDuDBVud7WejBIraWGtxW9Le3RZbMmiM X-Received: by 2002:a02:91c1:: with SMTP id s1mr32706698jag.61.1620836274211; Wed, 12 May 2021 09:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836274; cv=none; d=google.com; s=arc-20160816; b=eAKwNI1Xv1TXcol/yDDGPinrTUrYFI7/ygWmlxHYaDr/9ZfaSSoDPrZNGPCxbuvrtO knVr5Y5dLMMu1yUmv9X9MLAO5eOn0iyS3cMLEJTEC+KvwW7jCpTW5Lex0O0aJWsykB2w aTcET0jV1vLOIsBcrzOSR29rtCGYTfIFhVKNCpbZd+yXFkvB9nx5hvj0wZQE7U9ulUBo EYhnya/EbDtUeLqFkB8ypjWmUsg9/sVEBuvXURIsPDY6qR6H2UJaUjslWHrvGv1mIsZR Q1tMcDXPreQm6EWhC7YbGTEEI1K0mOGnBMDNr5FABQKGG0q7gMjzDERp1Mu21eXxMb+B xwNg== 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=EhuM3+pMUqAdoXJ6rm8s9std6CIN4vkrsmmaj+aosuvbtiYsxjdjXi2uqa27ImuFsX 4cCENxTnvQ7d4kGJNcj2sm1tZR79z+f8BzmFxQ8HvrjyHvL5v5YPsxsoSPAA8IerzK85 N66Z3pFV+KFa2l2C0NQgijzRnM1C8EmJJKO5rDy7nd7HRgomYyzz8+SiciBHfXLeX1ko stp1LJ+bk4qHXxBKGEYwH1Okkp/o/jD5FbdYk3Cbi+egxk1LgmTOSaPN+rDHeXWzr5Bb YQdVcK4/uqQN/rO75KLxXenjSSFlR65V7PrEr2LmZDFF3Md8pLae+3qsA8Deg9rGKAOX cYaw== 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 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.09.17.53; Wed, 12 May 2021 09:17:54 -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=1Y1NCQI9; 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 S234176AbhELPvS (ORCPT + 12 others); Wed, 12 May 2021 11:51:18 -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 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); }