Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1315598rdg; Fri, 13 Oct 2023 18:54:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgVlfj8hEWBNl+xPx6W2KGjLNx+vVz0thH2E0SZmid6XbSs5gTvfzpS5pFEAU0KLrLpCbU X-Received: by 2002:a17:902:c112:b0:1b8:8ff5:2cee with SMTP id 18-20020a170902c11200b001b88ff52ceemr22228844pli.64.1697248477648; Fri, 13 Oct 2023 18:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697248477; cv=none; d=google.com; s=arc-20160816; b=M3tjdUyzRRVlJOQYxVpTJbPOzi+2uzVa12PmTjKPZD9fsNlB2Tyvdifxkho4xT5CD3 i2hZnXA2vFg5Ndl0X/tDRurTvnCOskfuBBeT9awQ1bBqSqs9UxwfUKbm45duY9jbAesG vA5lx827p1vtluCjuFGVGi+SYAvdZFlYXOKsNB5rgaw5MmVW2Y0Sm7frnAHID6Q6erLA xOh/+LDqtt3vD768nRnI6Vsz+Dsmwpmu4w/emAfX8Xd/t/HgDquQTYKk53gGvg7TZoiD uDkOkuzWvEJVOLqobFB3n8DYuXLkIe/wGchQJg03V8iszUc+Ks7mIKe6gGiA+eweZPnf TkdA== 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=uEFAHCghA30DSQmfSG+hPF7rdT/OSX//7dxRREyrO7Q=; fh=fjecWn2tsXHKF5pPtw+gI2dQE/iSXdFsWSc8KUP/zmc=; b=ds2J+sdAen2Lt6G/ByNNmrPNYHh1ZOUGan1auGV+Wq4ks0alelKSg+P4zGJsGge/V2 uodeA1boQZXu3a6eQvVwEY6yyMEZ1n+Wmvzwrp4NNRYVrZO+S2WXcjarku5Lr+qZPUPX 8OrXUFKgaPmdP9fh4IQdNBFJcmg8Ryrmj7aCIOtd1/K68dIAHROOYMBdHkK0TVyCFdLN BxNnXvIqKhz4dSW+71PVT3Xv+pIKGIAUf1QEdpGG8vgTDOufX2SI/wlDFk2x5Am16BK9 JhWZUqp3IAo9PV4pohRnCNKZH67jy8OM+A7G6nzjw6BmJxCHctHefiy2fCfFv6eQ/+e4 1igg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="fiorwB/O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id h5-20020a170902f2c500b001c9d4f08c3asi5277881plc.277.2023.10.13.18.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 18:54:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="fiorwB/O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id ABE258023992; Fri, 13 Oct 2023 18:54:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233104AbjJNByV (ORCPT + 99 others); Fri, 13 Oct 2023 21:54:21 -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: 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 pete.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 (pete.vger.email [0.0.0.0]); Fri, 13 Oct 2023 18:54:34 -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 | 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 = 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