Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4970089rdb; Tue, 12 Dec 2023 15:05:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgFuzFje4FYMMISY9wxfdVECaEt+/TJxrqEjfMoKvKFaBSksbc12c4hp9mMichwt/UN6IX X-Received: by 2002:a17:902:d54c:b0:1d3:3952:8885 with SMTP id z12-20020a170902d54c00b001d339528885mr2080840plf.11.1702422346872; Tue, 12 Dec 2023 15:05:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702422346; cv=none; d=google.com; s=arc-20160816; b=fw70R8BlkDR3QsY4p//kIR2qr7PRLOwQGoJZpDZYtuY68QsUMy1foLhKfeRI3+6tJo HGFocQGSVwgUd7ts08S5flrxhIyX77lUz5Dog+26CCVcpzyNG2VFxH5DvVkJRKGBPJBx SWPUhWFny3+A4d6az4u3ODPph5rNBmYNb99tsjXQl7hNGAHWdg5AtePtySL2YcQOOwAz xXOPZwih3F+Vpm0HfH17ohBl/jorKCjOaVot5JKWbkhqXfCUBnKnZruxsoJcBL2m3RcC EvUrJo/lwFar6o4lANdnfjmHm9FW1jeUvPpQN+T+wnkW3APhW78aTWWMh0349/3g0b7x unRQ== 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=cx1ZqpeoJxSt1tFlZ2JOg+Agn8C2bbZdLfuoXWvtWJA=; fh=fjecWn2tsXHKF5pPtw+gI2dQE/iSXdFsWSc8KUP/zmc=; b=yJX90shbBRC06REsC9gzbq6WdJ10bF2TZErp0gh4w+ZYtIh8+V1vf4cVK2bfYwAo2D zwV3pAVY7SWCMgwjpBUKxQzYHg+IFhCZ9e/tSLm7q+2lIJbgmQoSXKdKAObvcrvHPl4l 5uL84eafxgTfMLda+jnwW8wZ+87lAYUO+Odmtrx5aKmR7C8NlVAqcgu3KZ1QTNInp81z y2k0sGlgJagA8vHKftW4zdt5+s9T1CWoPFPyVdPvd3uw8uqS7lnjICCHXx7hSPYLS6A9 9OX0Gj9LdR+oQ0+mfneQpeHNcUNzrbmEJsi89XtRAAenHjceP0T+VaJekbJ4CZeXSgL1 0rmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WuytAoLv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id m10-20020a170902db0a00b001cf8e9e8813si8564316plx.315.2023.12.12.15.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 15:05:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WuytAoLv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id EBCA6804B13E; Tue, 12 Dec 2023 15:05:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377964AbjLLXEx (ORCPT + 99 others); Tue, 12 Dec 2023 18:04:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235322AbjLLXEX (ORCPT ); Tue, 12 Dec 2023 18:04:23 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EEE410FF; Tue, 12 Dec 2023 15:04:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702422243; x=1733958243; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NDQRlSFja+26nRaijwaZ1XVDslKm6YUyEUuwUoijWyc=; b=WuytAoLvti72TMsn8181fy/EL5Zq+OXhwlqvkfyFcdctLpIvNgD/o1aC m6f0v/8a0gIYHJDvV0OG8gyFLn327Mv9JSKktaMovbo+LN7szBJyiCeSp yDf88QxYwQBsLa97lYJ4QtQdlDc6xT82/Lw+t0QNPTsRkuWOpbZvNolI8 +brr4os6wTATsPcEscr0pWbsTnaySehifj3kMylV9Hxq05eKOjX/9/vqJ 1GMrSBUQIh4vhw9aUXOxjXzJZNCb1OLmJzp7PiY7m6PAILDCD2/ZblWEO +iH4+KFeeJnmFVNSujcAyxFiF4sN3pn4i83hnNlrn7w1DAg3GNTjXUjTk w==; X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="392056033" X-IronPort-AV: E=Sophos;i="6.04,271,1695711600"; d="scan'208";a="392056033" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 15:02:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="864392035" X-IronPort-AV: E=Sophos;i="6.04,271,1695711600"; d="scan'208";a="864392035" Received: from node-10329.jf.intel.com ([10.54.34.22]) by FMSMGA003.fm.intel.com with ESMTP; 12 Dec 2023 15:02:57 -0800 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 , Yang Jihong Subject: [RFC PATCH v3 15/18] perf stat: Code refactoring in hardware-grouping Date: Tue, 12 Dec 2023 15:02:21 -0800 Message-Id: <20231212230224.1473300-17-weilin.wang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231212230224.1473300-1-weilin.wang@intel.com> References: <20231212230224.1473300-1-weilin.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Tue, 12 Dec 2023 15:05:44 -0800 (PST) From: Weilin Wang Decouple the step to generate final grouping strings out from the build_grouping step so that we could do single metric grouping and then merge groups if needed later. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 4df04d14d602..f0ef0c2ed860 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1801,9 +1801,10 @@ static int find_and_set_counters(struct metricgroup__event_info *e, { int ret; unsigned long find_bit = 0; - - if (e->taken_alone && current_group->taken_alone) + if (e->taken_alone && current_group->taken_alone) { + pr_debug("current group with taken alone event already\n"); return -ENOSPC; + } if (e->free_counter) return 0; if (e->fixed_counter) { @@ -1922,7 +1923,8 @@ static int assign_event_grouping(struct metricgroup__event_info *e, list_for_each_entry(g, groups, nd) { if (!strcasecmp(g->pmu_name, e->pmu_name)) { - pr_debug("found group for event %s in pmu %s\n", e->name, g->pmu_name); + pr_debug("found group header for event %s in pmu %s\n", + e->name, g->pmu_name); pmu_group_head = g; break; } @@ -2051,26 +2053,22 @@ static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs */ static int create_grouping(struct list_head *pmu_info_list, struct list_head *event_info_list, - struct list_head *groupings, - const char *modifier) + struct list_head *grouping) { int ret = 0; struct metricgroup__event_info *e; - LIST_HEAD(groups); char *bit_buf = malloc(NR_COUNTERS); - //TODO: for each new core group, we should consider to add events that uses fixed counters + //TODO: for each new core group, we could consider to add events that + //uses fixed counters list_for_each_entry(e, event_info_list, nd) { bitmap_scnprintf(e->counters, NR_COUNTERS, bit_buf, NR_COUNTERS); pr_debug("Event name %s, [pmu]=%s, [counters]=%s, [taken_alone]=%d\n", e->name, e->pmu_name, bit_buf, e->taken_alone); - ret = assign_event_grouping(e, pmu_info_list, &groups); + ret = assign_event_grouping(e, pmu_info_list, grouping); if (ret) - goto out; + return ret; } - ret = hw_aware_metricgroup__build_event_string(groupings, modifier, &groups); -out: - metricgroup__free_group_list(&groups); return ret; }; @@ -2091,9 +2089,8 @@ static bool is_special_event(const char *id) * @groupings: header to the list of final event grouping. * @modifier: any modifiers added to the events. */ -static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, - struct list_head *groupings __maybe_unused, - const char *modifier __maybe_unused) +static int hw_aware_build_grouping(struct expr_parse_ctx *ctx, + struct list_head *grouping) { int ret = 0; struct hashmap_entry *cur; @@ -2125,8 +2122,7 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, ret = get_pmu_counter_layouts(&pmu_info_list, ltable); if (ret) goto err_out; - ret = create_grouping(&pmu_info_list, &event_info_list, groupings, - modifier); + ret = create_grouping(&pmu_info_list, &event_info_list, grouping); err_out: metricgroup__free_event_info(&event_info_list); @@ -2172,23 +2168,25 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, { struct parse_events_error parse_error; struct evlist *parsed_evlist; - LIST_HEAD(groupings); + LIST_HEAD(grouping_str); + LIST_HEAD(grouping); struct metricgroup__group_strs *group; int ret; *out_evlist = NULL; - ret = hw_aware_build_grouping(ids, &groupings, modifier); - if (ret) { - metricgroup__free_grouping_strs(&groupings); - return ret; - } + ret = hw_aware_build_grouping(ids, &grouping); + if (ret) + goto out; + ret = hw_aware_metricgroup__build_event_string(&grouping_str, modifier, &grouping); + if (ret) + goto out; parsed_evlist = evlist__new(); if (!parsed_evlist) { ret = -ENOMEM; goto err_out; } - list_for_each_entry(group, &groupings, nd) { + list_for_each_entry(group, &grouping_str, nd) { struct strbuf *events = &group->grouping_str; pr_debug("Parsing metric events '%s'\n", events->buf); @@ -2208,7 +2206,9 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, err_out: parse_events_error__exit(&parse_error); evlist__delete(parsed_evlist); - metricgroup__free_grouping_strs(&groupings); +out: + metricgroup__free_group_list(&grouping); + metricgroup__free_grouping_strs(&grouping_str); return ret; } -- 2.39.3