Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3111363pxp; Mon, 14 Mar 2022 11:03:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2rrgqmXltqZ5hViffF/owG/lbrjMEHl3Dm3//HBUCjMU2Q+XMNLib6G1GaFtIoj/mMt3Q X-Received: by 2002:a17:907:94c4:b0:6da:c28c:3f44 with SMTP id dn4-20020a17090794c400b006dac28c3f44mr21005263ejc.722.1647281012991; Mon, 14 Mar 2022 11:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647281012; cv=none; d=google.com; s=arc-20160816; b=raLHqUtYNDjz/T3E8vgaC5qR12HJKeQMlvWbV8liR5skk6G/8PoBepJ/5xGEm6lRgz ZB6KmxBkdkRxOfRd4y+K7eKCPts7Leoc3iG4s7rOHWbsd1/FI2E77f7nmCZ1ZYeV3h4Z PrID7n7UcGXMFy5ylGOBlBm+STHXYYUxXrH6AuLlqZImU9rZiGXUZc7j8si57tAhLjvH WCqpi9qBC6lJPSz6u7ag/whKhGNs9ZLysPOMgZ0jPTCylJ9Po+pC6GTK6g+XAjlTwT5d JTrgFoE9go9j3vkdeEkl3Ep5ey5nUQfsfPoDdD2/zU21Q/ZaSpV81cdxsd/3lMy3bWnq LsSg== 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=+Xf66omRS/7G5zp3cLFr6ZqhJDHWI5p6ygUGyrZF/F0=; b=F4qCpXyLI0aucVpHGGo5N06ZcsLX7Pth3PVc/Cwyoz/NMut5D5TSl3pfqRIfm+XpTc Tpxw2YccAYxG4bDyXAtPWvMkE0GaWLYxPrisC9LC9plLNMRKMPDqE61xY5TnE9XFq8ZS t5KAmS/jjfG4n0XAMeFdlNKaaVGvaSScPd70v11ChZIngyp3IBFB5RmS9WJo4uw9Z/Cs eLt1M/R7BDWkpZGW2OSfvG+2xSpbIRtx8+BQeYt1oR2Rbdm1tPSWGaSFjtwjvRGb7Vli wWQFPr/QdIFxslL0g1HpHyituREOXbPWZn8eXCeIFuePXdDRi4LEFyfX9tyvOSkZ9bOp bMoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aF1H9cm0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn16-20020a17090794d000b006db2de6ee60si10471892ejc.257.2022.03.14.11.03.03; Mon, 14 Mar 2022 11:03:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aF1H9cm0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S244787AbiCNMcW (ORCPT + 99 others); Mon, 14 Mar 2022 08:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243940AbiCNMVZ (ORCPT ); Mon, 14 Mar 2022 08:21:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7F3D13D05; Mon, 14 Mar 2022 05:18:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6D74F608C4; Mon, 14 Mar 2022 12:18:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 406E1C340E9; Mon, 14 Mar 2022 12:18:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647260337; bh=YCeyHF403XWmfv0m5fpr7Hxca6frcdIOMmZB/BHBqK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aF1H9cm0KBCvW1Zi5Tdj4P5ypzhL8Bu9QRBn6WsBI3ghvCsHLPa0STKH9Obi9BUrv dJSIaJ6c3bKymzkOt11lH3NMBg7PzfYDmbmzGJKwlQf78XBseAT76j4y7uNt71lgJ7 HkdoHJV8NB3LrehTN9bZSShHLko2q6RKip9rvjt4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kan Liang , Zhengjun Xing , Adrian Hunter , Alexander Shishkin , Andi Kleen , Ian Rogers , Ingo Molnar , Jiri Olsa , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH 5.16 119/121] perf parse: Fix event parser error for hybrid systems Date: Mon, 14 Mar 2022 12:55:02 +0100 Message-Id: <20220314112747.433395731@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112744.120491875@linuxfoundation.org> References: <20220314112744.120491875@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhengjun Xing commit 91c9923a473a694eb1c5c01ab778a77114969707 upstream. This bug happened on hybrid systems when both cpu_core and cpu_atom have the same event name such as "UOPS_RETIRED.MS" while their event terms are different, then during perf stat, the event for cpu_atom will parse fail and then no output for cpu_atom. UOPS_RETIRED.MS -> cpu_core/period=0x1e8483,umask=0x4,event=0xc2,frontend=0x8/ UOPS_RETIRED.MS -> cpu_atom/period=0x1e8483,umask=0x1,event=0xc2/ It is because event terms in the "head" of parse_events_multi_pmu_add will be changed to event terms for cpu_core after parsing UOPS_RETIRED.MS for cpu_core, then when parsing the same event for cpu_atom, it still uses the event terms for cpu_core, but event terms for cpu_atom are different with cpu_core, the event parses for cpu_atom will fail. This patch fixes it, the event terms should be parsed from the original event. This patch can work for the hybrid systems that have the same event in more than 2 PMUs. It also can work in non-hybrid systems. Before: # perf stat -v -e UOPS_RETIRED.MS -a sleep 1 Using CPUID GenuineIntel-6-97-1 UOPS_RETIRED.MS -> cpu_core/period=0x1e8483,umask=0x4,event=0xc2,frontend=0x8/ Control descriptor is not initialized UOPS_RETIRED.MS: 2737845 16068518485 16068518485 Performance counter stats for 'system wide': 2,737,845 cpu_core/UOPS_RETIRED.MS/ 1.002553850 seconds time elapsed After: # perf stat -v -e UOPS_RETIRED.MS -a sleep 1 Using CPUID GenuineIntel-6-97-1 UOPS_RETIRED.MS -> cpu_core/period=0x1e8483,umask=0x4,event=0xc2,frontend=0x8/ UOPS_RETIRED.MS -> cpu_atom/period=0x1e8483,umask=0x1,event=0xc2/ Control descriptor is not initialized UOPS_RETIRED.MS: 1977555 16076950711 16076950711 UOPS_RETIRED.MS: 568684 8038694234 8038694234 Performance counter stats for 'system wide': 1,977,555 cpu_core/UOPS_RETIRED.MS/ 568,684 cpu_atom/UOPS_RETIRED.MS/ 1.004758259 seconds time elapsed Fixes: fb0811535e92c6c1 ("perf parse-events: Allow config on kernel PMU events") Reviewed-by: Kan Liang Signed-off-by: Zhengjun Xing Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20220307151627.30049-1-zhengjun.xing@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/parse-events.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1648,6 +1648,7 @@ int parse_events_multi_pmu_add(struct pa { struct parse_events_term *term; struct list_head *list = NULL; + struct list_head *orig_head = NULL; struct perf_pmu *pmu = NULL; int ok = 0; char *config; @@ -1674,7 +1675,6 @@ int parse_events_multi_pmu_add(struct pa } list_add_tail(&term->list, head); - /* Add it for all PMUs that support the alias */ list = malloc(sizeof(struct list_head)); if (!list) @@ -1687,13 +1687,15 @@ int parse_events_multi_pmu_add(struct pa list_for_each_entry(alias, &pmu->aliases, list) { if (!strcasecmp(alias->name, str)) { + parse_events_copy_term_list(head, &orig_head); if (!parse_events_add_pmu(parse_state, list, - pmu->name, head, + pmu->name, orig_head, true, true)) { pr_debug("%s -> %s/%s/\n", str, pmu->name, alias->str); ok++; } + parse_events_terms__delete(orig_head); } } }