From nobody Fri Jan 2 06:47:41 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1EDDCDB47E for ; Sat, 14 Oct 2023 01:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233122AbjJNByW (ORCPT ); Fri, 13 Oct 2023 21:54:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233039AbjJNBxo (ORCPT ); Fri, 13 Oct 2023 21:53:44 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A744E3; Fri, 13 Oct 2023 18:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697248397; x=1728784397; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Dp5/KruilQ9oVO0UatjNLb9jKGIJP0G6bCTahKja4Zo=; b=fiorwB/O+3h7MO8QXxAvXkkI9r54HlKhlhhdEieT0I36lyKUUg2lAbPa ftR6wP3npHcUTIIKs5WSjCC4211Yrqynhsh3VAgbf/n4eYZOjTQxoC9Mr +6DVwMTjIl3FQ5+HBbJQg5QvMdpkJbfrpU9CMpC3YvJ68LaZqZG99rgKZ 6u0YnPSVhy7hpgAbV0KhUg8OzL2kCrj3i4eCD/RamfF9e5W4iWWPRy/oB FYFUTzBT0Rp55Prd5u6NUBe+bZQkXR1c6j0B5MGSmKkN/6sL8qj/AcDYr YZiZIJ0fPvEkZzy2JQs4XBiAU2M0bj5vczUDzeabqOPKboGs9/VugrGmN w==; X-IronPort-AV: E=McAfee;i="6600,9927,10862"; a="389154774" X-IronPort-AV: E=Sophos;i="6.03,223,1694761200"; d="scan'208";a="389154774" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 18:52:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10862"; a="731565703" X-IronPort-AV: E=Sophos;i="6.03,223,1694761200"; d="scan'208";a="731565703" Received: from b49691a75598.jf.intel.com ([10.54.34.22]) by orsmga006.jf.intel.com with ESMTP; 13 Oct 2023 18:52:20 -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 , Yang Jihong Subject: [RFC PATCH v2 15/17] perf stat: Code refactoring in hardware-grouping Date: Fri, 13 Oct 2023 18:52:00 -0700 Message-Id: <20231014015202.1175377-16-weilin.wang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231014015202.1175377-1-weilin.wang@intel.com> References: <20231014015202.1175377-1-weilin.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 7da91cbd3..1222cff8d 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 =3D 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, =20 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 =3D 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 =3D 0; struct metricgroup__event_info *e; - LIST_HEAD(groups); char *bit_buf =3D malloc(NR_COUNTERS); =20 - //TODO: for each new core group, we should consider to add events that us= es 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]=3D%s, [counters]=3D%s, [taken_alone]=3D%d= \n", e->name, e->pmu_name, bit_buf, e->taken_alone); - ret =3D assign_event_grouping(e, pmu_info_list, &groups); + ret =3D assign_event_grouping(e, pmu_info_list, grouping); if (ret) - goto out; + return ret; } - ret =3D hw_aware_metricgroup__build_event_string(groupings, modifier, &gr= oups); -out: - metricgroup__free_group_list(&groups); return ret; }; =20 @@ -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_unus= ed, - 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 =3D 0; struct hashmap_entry *cur; @@ -2125,8 +2122,7 @@ static int hw_aware_build_grouping(struct expr_parse_= ctx *ctx __maybe_unused, ret =3D get_pmu_counter_layouts(&pmu_info_list, ltable); if (ret) goto err_out; - ret =3D create_grouping(&pmu_info_list, &event_info_list, groupings, - modifier); + ret =3D create_grouping(&pmu_info_list, &event_info_list, grouping); =20 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; =20 *out_evlist =3D NULL; - ret =3D hw_aware_build_grouping(ids, &groupings, modifier); - if (ret) { - metricgroup__free_grouping_strs(&groupings); - return ret; - } + ret =3D hw_aware_build_grouping(ids, &grouping); + if (ret) + goto out; + ret =3D hw_aware_metricgroup__build_event_string(&grouping_str, modifier,= &grouping); + if (ret) + goto out; =20 parsed_evlist =3D evlist__new(); if (!parsed_evlist) { ret =3D -ENOMEM; goto err_out; } - list_for_each_entry(group, &groupings, nd) { + list_for_each_entry(group, &grouping_str, nd) { struct strbuf *events =3D &group->grouping_str; =20 pr_debug("Parsing metric events '%s'\n", events->buf); @@ -2208,7 +2206,9 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_p= mu, 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; } =20 --=20 2.39.3