Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1079440rdh; Mon, 25 Sep 2023 02:36:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3eUiyUZ2AciHUaEEWPqorRXjqPeeXGurwVO+tA9jGYrXhCi+XIwpSTR2a6k5TTzE/4+6O X-Received: by 2002:a05:6a00:194a:b0:68f:b015:ea99 with SMTP id s10-20020a056a00194a00b0068fb015ea99mr10151435pfk.10.1695634586354; Mon, 25 Sep 2023 02:36:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695634586; cv=none; d=google.com; s=arc-20160816; b=Hp1az6i9lz6K8DV7kgY8XavXyVT8BsB0letJJgMi2iAckLkGlpsFhYFRnuBI8gYVKl NqGNjlgj0M65xIcGopEO1R6uI/h7HovpxkGsECXQR5JngijwgUhfMCycPyzgWLkJnqI2 tE8c+o+T560pcvtKO2ewW/qngVxLMhHxCIYHx0mtor6Za9QLY2GqPJFQjp2+S/NIx4fT pZkLfCkkuD6mc4/FafvRFB6wdo3qEC2/NIWCr87Siae0t6bDPPgcZOktwZXWaMM1rETe Fopq1PX1FTpMJiqnMpP1LZentdhqUHCzlXSNQlnNrzkMAI7yP/A865tLyfo6s5qXqruW JloA== 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=QigPZM4CEf+4gzCxVPWztYEOZDFwlZbAvNGjchZbvRk=; fh=aicQXd2sVDKynU70/92qv+8AnsPgYK5pq7fTzS41MP4=; b=mXTP9v1+rQP14Didt8ynbRrVYGINRglIvWePD3HSVdPLB18jsiS3WECc1ny8QRoZN7 wKFkErDoNamWwBSCRithRbMPsiefBf/+LDVDuaq3Cy7tkJNV7HfnwS2CIt6/23wGVNN7 6Jz0Th87xbN8hu6212UYxwYvY7dWLB1OP69FfgJT5Yp56cNaBorlVFTP/4mOPQiUybi5 x7mmYF+QMj4mEU+FYppT5QW7dVsDCyQ7LvIQf4qp9ASh1fgrvPEw/eTrzKE4NcaN4AV+ b4InDr6EIUWtdjQIBAkx6fzvl+v2bqZboG1OqE43PP+ZUU3xrHilCG5IftFMxcqyHZri S+xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GWfDtBcv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l7-20020a632507000000b00578b63123desi10077074pgl.789.2023.09.25.02.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 02:36:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GWfDtBcv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 1A8ED80707BF; Sun, 24 Sep 2023 23:20:38 -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 S232209AbjIYGUd (ORCPT + 99 others); Mon, 25 Sep 2023 02:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232119AbjIYGUN (ORCPT ); Mon, 25 Sep 2023 02:20:13 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63A1DCD1; Sun, 24 Sep 2023 23:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695622798; x=1727158798; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+aubAkzZ9fM27xEp4GwOouz7KCLea9GS4cMIVbkPI8s=; b=GWfDtBcvwEEirs/X3/MmYnrT35QSomXJCr+plBdWyBUE3kkB+Wji+ZJ1 tiPLZ8D7bvJleBNJrUa1HjKIxUvYlObxbl+rtO3T6O/z0yZz7ZWKeLB9V 23B3NqF/9CERxWnaUdfSzoJVH/fkqhfegu5j/R9WzvO5/OBwbx2w6Ilb4 yJVWEaMbdUiAK4Zw4NwQLNiADFLJeKuRduehJ6ZIqRDFigBn08K3cCtf9 nLLUAKxfyYOXoTQi4G16WTVGu9TpEOrgG1EJACxrBJW63ja+XjE2+tvJ2 3PTWDRRB4j4NgUVT0xhPmhmFB0bYVjpZrPltcPfL0y3121KsZRpLaNV19 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="445279470" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="445279470" 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:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="818494366" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="818494366" Received: from b49691a75598.jf.intel.com ([10.54.34.22]) by fmsmga004.fm.intel.com with ESMTP; 24 Sep 2023 23:19:17 -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 12/25] perf stat: Add more functions for hardware-grouping method Date: Sun, 24 Sep 2023 23:18:11 -0700 Message-Id: <20230925061824.3818631-13-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:20:38 -0700 (PDT) From: Weilin Wang Add function to fill all bits of one counter bitmap. Add functions to create new groups when no counter is available in all the existing groups. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 39 ++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 68d56087b..8d54e71bf 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1702,6 +1702,19 @@ static int get_pmu_counter_layouts(struct list_head *pmu_info_list, return ret; } +static int fill_counter_bitmap(unsigned long *bitmap, int start, int size) +{ + int ret; + bitmap_zero(bitmap, NR_COUNTERS); + + for (int pos = start; pos < start + size; pos++) { + ret = set_counter_bitmap(pos, bitmap); + if (ret) + return ret; + } + return 0; +} + /** * Find if there is a counter available for event e in current_group. If a * counter is available, use this counter by fill the bit in the correct counter @@ -1750,6 +1763,21 @@ static int _insert_event(struct metricgroup__event_info *e, return 0; } +/** + * Insert the new_group node at the end of the group list. + */ +static int insert_new_group(struct list_head *head, + struct metricgroup__group *new_group, + size_t size, + size_t fixed_size) +{ + INIT_LIST_HEAD(&new_group->event_head); + fill_counter_bitmap(new_group->gp_counters, 0, size); + fill_counter_bitmap(new_group->fixed_counters, 0, fixed_size); + list_add_tail(&new_group->nd, head); + return 0; +} + /** * Insert event e into a group capable to include it * @@ -1759,7 +1787,7 @@ static int insert_event_to_group(struct metricgroup__event_info *e, { struct metricgroup__group *g; int ret; - //struct list_head *head; + struct list_head *head; list_for_each_entry(g, &pmu_group_head->group_head, nd) { ret = find_and_set_counters(e, g); @@ -1774,13 +1802,14 @@ static int insert_event_to_group(struct metricgroup__event_info *e, */ { struct metricgroup__group *current_group = malloc(sizeof(struct metricgroup__group)); + if (!current_group) return -ENOMEM; pr_debug("create_new_group for [event] %s\n", e->name); - //head = &pmu_group_head->group_head; - //ret = create_new_group(head, current_group, pmu_group_head->size, - // pmu_group_head->fixed_size); + head = &pmu_group_head->group_head; + ret = insert_new_group(head, current_group, pmu_group_head->size, + pmu_group_head->fixed_size); if (ret) return ret; ret = find_and_set_counters(e, current_group); @@ -1817,7 +1846,7 @@ static int assign_event_grouping(struct metricgroup__event_info *e, pmu_group_head = malloc(sizeof(struct metricgroup__pmu_group_list)); INIT_LIST_HEAD(&pmu_group_head->group_head); - pr_debug("create new group for event %s in pmu %s ", e->name, e->pmu_name); + pr_debug("create new group for event %s in pmu %s\n", e->name, e->pmu_name); pmu_group_head->pmu_name = e->pmu_name; list_for_each_entry(p, pmu_info_list, nd) { if (!strcasecmp(p->name, e->pmu_name)) { -- 2.39.3