Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1113114rdh; Mon, 25 Sep 2023 03:51:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1IyT/QxES6rL5bJMR5TDX6bB7hJrN05G5wVZbjVi6/jbLVxif1Km10E66OeU9+JxTuapM X-Received: by 2002:a17:902:ab5b:b0:1c3:f745:1cd5 with SMTP id ij27-20020a170902ab5b00b001c3f7451cd5mr8079480plb.34.1695639074130; Mon, 25 Sep 2023 03:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695639074; cv=none; d=google.com; s=arc-20160816; b=HiHiEF0dZdp0IWz/+2hM6zV2HUYIyxe4z+KfI0SsyEuNYalKA1HVeZ5bbdrD7JHKKc bIj6xeIVMQxulH45qjxxftH1toE/quKUmz2kOimDz9IjaXntqd5vqFqgCtNMwC5ZHiJR +MbLVUUFeiy0lvWaxJC1O2+CjrHcdrs7BDx/RvyymNzSyX43jsXWocvZ7e8tvmhKaI9D hti0Y5eilONawAjn4EQvpVdh9JpWkCJ1qYZOuoQaTulcnRvUIAtwcJwzS3FSTByAnuXD PW3Y1Hbg+7+uml6Bsn08yy1EutsFgwCBMboLX7RoWwaUXodpz0g0U8wfx9P7QkuS6FbM oMsg== 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=tEgMVbBCwMp+SLvdBHcmGLib5hwgbifpq29eLZ44RAQ=; fh=aicQXd2sVDKynU70/92qv+8AnsPgYK5pq7fTzS41MP4=; b=0fHjYm8zNv3/AH47b0X4bsWe17OYiuPOgX+jeIFvgKWKrYaWoR6hbVIF+i0wdxBPb8 e3dwWYK2rJNBtcP0cvcsJYqodiU5tavh0CHmM63LX9oEI66eCWlXmA1+N91gLs7vwqwi OiZ4hdABgT2SHYKmTcGaqkCf3vKmsemCcsFRzblZSiQCjAiPq0oA8x02XMS0a+82B9bm mMAon83DEbgvm+dgsOpwYeMBTexi/4gTSy0PNS1vBI0fGYDXII9yMfJY2KM3+1oksjHt 3XTZZ9Mfw+zmQDB6SRena4EJnYg27KZORaQemLZIqTupWwyhaYbjOriqxQyxJZ/lGsHu dfow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eJ0Gylxg; 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 l5-20020a170903120500b001bb9d6794d3si11082545plh.72.2023.09.25.03.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 03:51:14 -0700 (PDT) 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=eJ0Gylxg; 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 75E5E819D712; Sun, 24 Sep 2023 23:21:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232301AbjIYGVX (ORCPT + 99 others); Mon, 25 Sep 2023 02:21:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232191AbjIYGUR (ORCPT ); Mon, 25 Sep 2023 02:20:17 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E29E120; 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=efXWrTzJnuX21IoXyjVBzf+uIVRK9N90p2tyWHMS/Os=; b=eJ0Gylxg0otU+RQzpzaa+7fKdgvAqs2zhMpKXbjXqQaLSC6eCp0d7Ttr Ldo8wm7do9SWGzAe3xTslEgQo/y14vtzx7CchKylYAmmLEiFqtT4KtIhj Z4lBGT0F5mqCGDICv6Wn0OjKTeGBp3uSgejCgs/09q/aPdJPWLFba0fpr UbqJGx9xAu2ILj9bVek4gluZ5rq3GMnvp4fa8OchyZP2KrVB4n8yrltSJ MzVrhkgBRMn10tvZMaaRISEhZ9VBgA9Hao+/dklVptePunPw9U78lYa1c QlLJueX3Mw22pLhzcWWDpB8lZQ7xmlf0R5O1dAak3Ip+Q5r3IXMcAsz8E Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="445279545" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="445279545" 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="818494414" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="818494414" Received: from b49691a75598.jf.intel.com ([10.54.34.22]) by fmsmga004.fm.intel.com with ESMTP; 24 Sep 2023 23:19:22 -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 20/25] perf stat: Code refactoring in hardware-grouping Date: Sun, 24 Sep 2023 23:18:19 -0700 Message-Id: <20230925061824.3818631-21-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=-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 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]); Sun, 24 Sep 2023 23:21:51 -0700 (PDT) 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 | 49 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index c027c0351..3c569d838 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1799,9 +1799,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) { @@ -1919,7 +1920,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; } @@ -2046,26 +2048,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 could 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; }; @@ -2077,9 +2075,8 @@ static int create_grouping(struct list_head *pmu_info_list, * @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; @@ -2112,8 +2109,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); @@ -2159,23 +2155,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 err_out; + ret = hw_aware_metricgroup__build_event_string(&grouping_str, modifier, &grouping); + if (ret) + goto err_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); @@ -2193,9 +2191,10 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, *out_evlist = parsed_evlist; parsed_evlist = NULL; err_out: + metricgroup__free_group_list(&grouping); + metricgroup__free_grouping_strs(&grouping_str); parse_events_error__exit(&parse_error); evlist__delete(parsed_evlist); - metricgroup__free_grouping_strs(&groupings); return ret; } -- 2.39.3