From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0926C433F5 for ; Tue, 28 Sep 2021 21:35:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 919AA6135F for ; Tue, 28 Sep 2021 21:35:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242933AbhI1Vhe (ORCPT ); Tue, 28 Sep 2021 17:37:34 -0400 Received: from mga01.intel.com ([192.55.52.88]:43298 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbhI1Vhe (ORCPT ); Tue, 28 Sep 2021 17:37:34 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10121"; a="247327323" X-IronPort-AV: E=Sophos;i="5.85,330,1624345200"; d="scan'208";a="247327323" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 14:35:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,330,1624345200"; d="scan'208";a="655268423" Received: from linux.intel.com ([10.54.29.200]) by orsmga005.jf.intel.com with ESMTP; 28 Sep 2021 14:35:53 -0700 Received: from [10.212.232.62] (kliang2-MOBL.ccr.corp.intel.com [10.212.232.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTPS id D6C7458097E; Tue, 28 Sep 2021 14:35:52 -0700 (PDT) Subject: Re: problem with 'perf script -F weight' To: Jiri Olsa Cc: linux-perf-users@vger.kernel.org, Peter Zijlstra , Joe Mario , Andi Kleen , Jin Yao , Arnaldo Carvalho de Melo References: From: "Liang, Kan" Message-ID: <732928be-f438-120f-7c9f-685630147495@linux.intel.com> Date: Tue, 28 Sep 2021 17:35:51 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org On 9/28/2021 3:20 PM, Jiri Olsa wrote: > Joe reported broken -F weight in perf script with (on x86): > > # ./perf mem record > # ./perf script -F weight > Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field. > > the problem seems to be introduced with the WEIGHT_STRUCT change: > ea8d0ed6eae3 perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT > > which enables WEIGHT_STRUCT sample_type on x86 instead of WEIGHT, > and leaves 'perf script -F weight' in the dark Right, I missed the support for the perf script. Because the default perf script worked. It didn't ring the bell. :( > > I'm not sure what the fix should look like.. should we allow user > to use just 'WEIGHT' sample type? or is there a way to get original > weight from 'WEIGHT_STRUCT' data, so we could fix just perf script? Just fix the perf script is enough. Could you please try the below patch? (I probably need to split the patch into two patches, since it fixed two issues, one is this error, the other is to print the instruction latency. Anyway, let's try it first.) From 99443f49a6236ef6e3bea3930792967a7863f753 Mon Sep 17 00:00:00 2001 From: Kan Liang Date: Tue, 28 Sep 2021 13:57:18 -0700 Subject: [PATCH] perf script: Fix PERF_SAMPLE_WEIGHT_STRUCT support -F weight in perf script is broken. # ./perf mem record # ./perf script -F weight Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field. The sample type, PERF_SAMPLE_WEIGHT_STRUCT, is an alternative of the PERF_SAMPLE_WEIGHT sample type. They share the same space, weight. The lower 32 bits are exactly the same for both sample type. The higher 32 bits may be different for different architecture. For a new kernel on x86, the PERF_SAMPLE_WEIGHT_STRUCT is used. For an old kernel or other ARCHs, the PERF_SAMPLE_WEIGHT is used. With -F weight, current perf script will check the input string "weight" with the corresponding sample type. However, the commit ID ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT") didn't update the sample type for perf script. The check fails with a new kernel on x86. Use PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to replace PERF_SAMPLE_WEIGHT. Also, print the instruction latency for PERF_SAMPLE_WEIGHT_STRUCT type. Reported-by: Joe Mario Fixes: ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT") Signed-off-by: Kan Liang --- tools/perf/builtin-script.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 6211d0b..fd73bbc 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -459,7 +459,7 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session) return -EINVAL; if (PRINT_FIELD(WEIGHT) && - evsel__check_stype(evsel, PERF_SAMPLE_WEIGHT, "WEIGHT", PERF_OUTPUT_WEIGHT)) + evsel__check_stype(evsel, PERF_SAMPLE_WEIGHT_TYPE, "WEIGHT", PERF_OUTPUT_WEIGHT)) return -EINVAL; if (PRINT_FIELD(SYM) && @@ -2036,8 +2036,11 @@ static void process_event(struct perf_script *script, if (PRINT_FIELD(DATA_SRC)) data_src__fprintf(sample->data_src, fp); - if (PRINT_FIELD(WEIGHT)) + if (PRINT_FIELD(WEIGHT)) { fprintf(fp, "%16" PRIu64, sample->weight); + if (attr->sample_type & PERF_SAMPLE_WEIGHT_STRUCT) + fprintf(fp, ",0x%" PRIx16, sample->ins_lat); + } if (PRINT_FIELD(IP)) { struct callchain_cursor *cursor = NULL; -- 2.7.4 Thanks, Kan