Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1085299rdh; Mon, 25 Sep 2023 02:51:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQMVKk0Lo5gRnw7jJ3JWntFM//RMTOUTzpW89a8m1VESoFTeI9FZTcOLs4pYXX+Az5AZEU X-Received: by 2002:a17:902:82c4:b0:1bc:6799:3f6c with SMTP id u4-20020a17090282c400b001bc67993f6cmr7144985plz.35.1695635489348; Mon, 25 Sep 2023 02:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695635489; cv=none; d=google.com; s=arc-20160816; b=J0XUytHNcMX1gcbPvUht6PrsTafs2dlmyVQJFM+a/R/SfuD7YjcCHiJz9CtQTqsY5R fUHL8oAyAtnZKA9HBw4JPRCnksJgTp5+Gwalp+s/pngdb4mwXs/BlLwTMsuUFRHrxe9o IlxWTW0f9y1pPrsVR4JzGE5IzSmMnxvCyNnhvkUSeKhaRM5h8+xq36P4UftzDTSjqkGC xpvnOrByCXuDvFe2/qesISwrx9e6PZEFsboYZaYbgGizwR/eeDsDJ+NSDYO0PpNHScxa llYrFP21iklzYf7KnXegB9Mckq6RPfX7NmfxnYVXqq4bnazXHzKfMf5UG7NyyzW3pDTu CX3w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MJeUYJSUgjlfpRdBJA1hE+CbvJpbsbi3ht8Ra2S4Rtg=; fh=aicQXd2sVDKynU70/92qv+8AnsPgYK5pq7fTzS41MP4=; b=ZW/DOG6djsSKKnuVGRiHXMbjfEDuqCcq5/kdLpFVboY8nCHaf9g12++EpfcSVVWAEC jenrZx1sWEg3NTzSdxL9XGU/+Qv6xCn/7ulU2OjIPs6QCrM2x357GBqX94KvM8SG1byV s4zOPyItYlS6atE9TDSK9T6Xn/9PrDEokNT01ISmtEC8E4wwumL3B3Yj6CbT9RPdPPcG xiS5vE6OZCDwIE+8qaXBg/GD/+nME9NEAB+seDpZejQMt1a1ESvs0ZcwtRGaa+KbUg8J E2tv1E8ERuoQq5DNJKxOtahy8buzseRKiWg3sMMjuioWRt/lmpXQY96p2MLdSApXuVNQ RcHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J0V0t5AY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x14-20020a170902a38e00b001c3e40dfff0si2502602pla.359.2023.09.25.02.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 02:51:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=J0V0t5AY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B8636805F640; Sun, 24 Sep 2023 23:21:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232196AbjIYGVS (ORCPT + 99 others); Mon, 25 Sep 2023 02:21:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232185AbjIYGUQ (ORCPT ); Mon, 25 Sep 2023 02:20:16 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BEFD11D; Sun, 24 Sep 2023 23:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695622809; x=1727158809; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r7XoFu9otGkGBXjSMYltLA2yk70i52Up8v53Cp2OC/8=; b=J0V0t5AY2NU9CyFyc7MqXPHIBlXSp9t42am9Ah+W1h5xWWezbLSgkRnv 67CfCxKvY3rNlRnGZLAq18TZm9hx42wC5UhRvkJDV/hXQt0G/hMWq+Hb7 LR1Tpygh/+9GV4OdKFQbYLv0ZZ3dW4G/yHDDsoz+fujcOmnJu1V6L96sp ayHO67eNdeNnl30/f2kEn8tTnFvrIWJGtPTOWNtzwB019G0PhpJhi0IA1 obzCOi/vKO2twd8iZmmeKnHculeoQidFp/awZqstWAcDHWP+QllfYm+qp XaBz7OeO4ysanv7WItLEhhOvzrDMwKBcUYSVAEKv1xzk8yI9ZwUN2O93G A==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="445279546" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="445279546" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2023 23:19:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="818494420" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="818494420" Received: from b49691a75598.jf.intel.com ([10.54.34.22]) by fmsmga004.fm.intel.com with ESMTP; 24 Sep 2023 23:19:23 -0700 From: weilin.wang@intel.com To: weilin.wang@intel.com, Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers , Mark Rutland Subject: [RFC PATCH 21/25] perf stat: Add tool events support in hardware-grouping Date: Sun, 24 Sep 2023 23:18:20 -0700 Message-Id: <20230925061824.3818631-22-weilin.wang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230925061824.3818631-1-weilin.wang@intel.com> References: <20230925061824.3818631-1-weilin.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 24 Sep 2023 23:21:23 -0700 (PDT) From: Weilin Wang Add tool events into default_core grouping strings if find tool events so that metrics use tool events could be correctly calculated. Need this step to support TopdownL4-L5. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 3c569d838..d10f6afb0 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1950,6 +1950,7 @@ static int assign_event_grouping(struct metricgroup__event_info *e, static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs, const char *modifier, + const bool tool_events[PERF_TOOL_MAX], struct list_head *groups) { struct metricgroup__pmu_group_list *p; @@ -2029,6 +2030,22 @@ static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs } ret = strbuf_addf(events, "}:W"); RETURN_IF_NON_ZERO(ret); + if (!strcmp(p->pmu_name, "default_core")) { + int i = 0; + + perf_tool_event__for_each_event(i) { + if (tool_events[i]) { + const char *tmp = strdup(perf_tool_event__to_str(i)); + + if (!tmp) + return -ENOMEM; + ret = strbuf_addstr(events, ","); + RETURN_IF_NON_ZERO(ret); + ret = strbuf_addstr(events, tmp); + RETURN_IF_NON_ZERO(ret); + } + } + } pr_debug("events-buf: %s\n", events->buf); list_add_tail(&new_group_str->nd, group_strs); } @@ -2094,7 +2111,8 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx, pr_debug("found event %s\n", id); if (!strncmp(id, special_pattern, strlen(special_pattern))) { struct metricgroup__event_info *event; - event = event_info__new(id, "default_core", "0", false, true); + event = event_info__new(id, "default_core", "0", false, + /*free_counter=*/true); if (!event) { ret = -ENOMEM; goto err_out; @@ -2106,6 +2124,7 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx, if (ret) goto err_out; } + ret = get_pmu_counter_layouts(&pmu_info_list, ltable); if (ret) goto err_out; @@ -2151,6 +2170,7 @@ static void metricgroup__free_grouping_strs(struct list_head */ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, struct expr_parse_ctx *ids, const char *modifier, + const bool tool_events[PERF_TOOL_MAX], struct evlist **out_evlist) { struct parse_events_error parse_error; @@ -2164,7 +2184,8 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, ret = hw_aware_build_grouping(ids, &grouping); if (ret) goto err_out; - ret = hw_aware_metricgroup__build_event_string(&grouping_str, modifier, &grouping); + ret = hw_aware_metricgroup__build_event_string(&grouping_str, modifier, + tool_events, &grouping); if (ret) goto err_out; @@ -2298,6 +2319,7 @@ static int hw_aware_parse_groups(struct evlist *perf_evlist, struct evlist *combined_evlist = NULL; LIST_HEAD(metric_list); struct metric *m; + bool tool_events[PERF_TOOL_MAX] = {false}; int ret; bool metric_no_group = false; bool metric_no_merge = false; @@ -2316,11 +2338,14 @@ static int hw_aware_parse_groups(struct evlist *perf_evlist, if (!metric_no_merge) { struct expr_parse_ctx *combined = NULL; + find_tool_events(&metric_list, tool_events); + ret = hw_aware_build_combined_expr_ctx(&metric_list, &combined); if (!ret && combined && hashmap__size(combined->ids)) { ret = hw_aware_parse_ids(fake_pmu, combined, /*modifier=*/NULL, + tool_events, &combined_evlist); } -- 2.39.3