From patchwork Wed May 12 14:51:47 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: 435680 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp5232945jao; Wed, 12 May 2021 15:03:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLYb4P5/BSyJGjSs+Nx43m+Vl5YzoOTH/buqmvssXc235G+GEBguJUvXGT2QJHAgu2quFX X-Received: by 2002:a17:906:ce42:: with SMTP id se2mr10699658ejb.359.1620857000061; Wed, 12 May 2021 15:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620857000; cv=none; d=google.com; s=arc-20160816; b=q5pvWOpx7lGi/BrKIPhjL7HXR1zI7ynPpDmU4LO5uocZRMA6+8l/7A08B5Kke+RfvO SzfOFvpJTS9Sm/jJNSnmNkkRRHG7rXgui0eyUubEJYVo/vo3g2fs7zYCbDgS/hUmzmq2 BwcC8bJseMSuOaDxIGe3usLy2iQqRrSiWDUihzreOvLX7hCyF1X+zDJQ6EcqmYHiN808 ipk2gcWlk4BdXCwfRH90/qSerVfLAzse6wvnYrbBAtwhxPtEL156kQFq3trjowS+0Xqw 8iKQzBleT9nUHcvlmGjtPbd0IvT9yrnjbmlJwo1TLaQyySbgS0gdibRkybeVx118cgkS ILrw== 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=O4QfocUElZcyOUWU2GcEFEux1TrsJpC/SU2GjZjy3HnCK2ZaXF3IkrgfvdXaUkTPbO WzEQFKy4PVoRXzcnnhkUAXrjsnpI/lQ3oh5fbuvZC/UHL+yu2ANoZgkTypot/O0QC7J8 lULAjOovKsrZkqSkT7q0AdLY2wvslWseDntTDl6JC7wwbtwazmhC/b5dyDK3xjeGYHqP gLwRaxOwp82ZTkrcmqD/ot+nZKIMbgAPhoXPdR6CwudHEhnu/JHmBL2PIcWXlCkkt2/l nu/wVNpM8uRCQ9SZACW47gfkDs7ogqqtH2LtdRtGvcYUU+qRGbXoDudtxCc/S+2x6jpt TF6w== 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 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 u19si859013ejx.176.2021.05.12.15.03.19; Wed, 12 May 2021 15:03:20 -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="OcsKXL/e"; 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 S234770AbhELRHD (ORCPT + 12 others); Wed, 12 May 2021 13:07:03 -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 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 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); }