Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1628432rdh; Mon, 25 Sep 2023 20:48:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGy2JdDuHHkhTT+MHp0dbpNc5k1fNi7L72GgvMEAJVHKPAGvFtnyQfU2z+fMc2U5kA3I/jS X-Received: by 2002:a17:90a:ad82:b0:268:e5db:6e19 with SMTP id s2-20020a17090aad8200b00268e5db6e19mr5980222pjq.20.1695700113291; Mon, 25 Sep 2023 20:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695700113; cv=none; d=google.com; s=arc-20160816; b=wOQuvV86yrHCFahLiJp6tFBGZx5NRqJ0cR5Jge69hL7WivifHejgdnXD3lba7pU2Y1 wLWh1EK/937PBMnQqzjUHYs9D2vy6dKJlwAwyy7y/k9KP25lXcpiz8yL6qLhc47z36Zd evqDSl5mzWytsoZr5OEz9es4mr0pGLhMjb0/G8cwzg1OIlGDIQp+V+13fKjIo0KQXEdT 233QPrfjlkp660lvXg8QtNDqJ4gW7gMdIZpAfWRR26r3lKFHgLWE3qWfR1tqH/cT0iWj RKyATKzdSSEtrhRqOLUNqdYp05ij7HAACYIwgDLJKUl9q65xuIK2H0sQ0hVcoPkkM4Bm Kpkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=Xt4CsNdfwsJaQ/hNtHH9ICzpctO8yDEiPPtkZQTb8og=; fh=txG0yjwlB5lWwS0lNDJ4GbL1kaW6w8REh6nOQZMyd4g=; b=NTQ+x9BB+7zANsnKl0Y7fXFgPWVZywZ0MmTvH0XquleQAQcCn+G9azSRevhLDuSBO9 8DDreG32dmSVOSCtAdBf1xZUtIfcyTBft0t1qrjaNk9uck1X/cHvaefNguU9rorxfZkl Bt08+A59nrzip1Gl1VVKWgqkZQlbt5LcrSH+vzW8+wBuc/JOCd41VwVY/npf7fxlqyRx x68ElMKjU3egkmQI1HBoNgLWbeAl93+4MUxwJ4nzyoyd55x46TCPApT78A5MLZniEKlw 9RdQ3tSsFKp4txjaZTsdO8EyQcyMub4vRtFZKcZXhcy1FRAF94GGIwd5TVUzRBBDK7nu d3kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id k7-20020a634b47000000b00578ca217740si11742674pgl.711.2023.09.25.20.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 20:48:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 2EC3A80984B1; Mon, 25 Sep 2023 20:45:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbjIZDpJ (ORCPT + 99 others); Mon, 25 Sep 2023 23:45:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjIZDpH (ORCPT ); Mon, 25 Sep 2023 23:45:07 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9006D7; Mon, 25 Sep 2023 20:44:59 -0700 (PDT) Received: from kwepemm000003.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Rvlsp4Z09zTm2F; Tue, 26 Sep 2023 11:41:50 +0800 (CST) Received: from [10.67.111.205] (10.67.111.205) by kwepemm000003.china.huawei.com (7.193.23.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 26 Sep 2023 11:44:56 +0800 Subject: Re: [RFC PATCH 10/25] perf stat: Add helper functions to hardware-grouping method To: , Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang CC: , , Perry Taylor , Samantha Alt , Caleb Biggers , Mark Rutland References: <20230925061824.3818631-1-weilin.wang@intel.com> <20230925061824.3818631-11-weilin.wang@intel.com> From: Yang Jihong Message-ID: <7751b63e-d8cf-85b0-b64e-5f656244a2c9@huawei.com> Date: Tue, 26 Sep 2023 11:44:56 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20230925061824.3818631-11-weilin.wang@intel.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000003.china.huawei.com (7.193.23.66) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.2 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 25 Sep 2023 20:45:35 -0700 (PDT) Hello, On 2023/9/25 14:18, weilin.wang@intel.com wrote: > From: Weilin Wang > > Add struct metricgroup__pmu_group_list to hold the lists of groups from > different PMUs. Each PMU has one separate list. > > Add struct metricgroup__group as one node (one group in the grouping > result) of the metricgroup__pmu_group_list. It uses two bitmaps to log > counter availabilities(gp counters and fixed counters). > > Add functions to create group and assign event into the groups based on the > event restrictions (struct metricgroup__event_info) and counter > availability (pmu_info_list and bitmaps). New group is inserted into the > list groups. > > Signed-off-by: Weilin Wang > --- > tools/perf/util/metricgroup.c | 72 +++++++++++++++++++++++++++++++++++ > tools/perf/util/metricgroup.h | 37 ++++++++++++++++++ > 2 files changed, 109 insertions(+) > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c > index 0ca885a42..de6a6a1d7 100644 > --- a/tools/perf/util/metricgroup.c > +++ b/tools/perf/util/metricgroup.c > @@ -1681,6 +1681,76 @@ static int get_pmu_counter_layouts(struct list_head *pmu_info_list, > return ret; > } > > +/** > + * assign_event_grouping - Assign an event into a group. If existing group > + * cannot include it, create a new group and insert the event to it. > + */ > +static int assign_event_grouping(struct metricgroup__event_info *e, > + struct list_head *pmu_info_list __maybe_unused, > + struct list_head *groups) > +{ > + int ret = 0; > + > + struct metricgroup__pmu_group_list *g = NULL; > + struct metricgroup__pmu_group_list *pmu_group_head = NULL; > + > + 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); > + pmu_group_head = g; > + break; > + } > + } > + if (!pmu_group_head) { > + struct metricgroup__pmu_counters *p; > + > + pmu_group_head = malloc(sizeof(struct metricgroup__pmu_group_list)); Here may need to check the return value of malloc. > + INIT_LIST_HEAD(&pmu_group_head->group_head); > + pr_debug("create new group for event %s in pmu %s ", 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)) { > + pmu_group_head->size = p->size; > + pmu_group_head->fixed_size = p->fixed_size; > + } > + } > + list_add_tail(&pmu_group_head->nd, groups); > + } > + > + //ret = insert_event_to_group(e, pmu_group_head, pmu_info_list); This is also the commented out code. Can it delete? > + return ret; > +} > + > +/** > + * create_grouping - Create a list of groups and place all the events of > + * event_info_list into these groups. > + * @pmu_info_list: the list of PMU units info based on pmu-events data, used for > + * creating new groups. > + * @event_info_list: the list of events to be grouped. > + * @groupings: the list of groups with events placed in. > + * @modifier: any modifiers added to the events. > + */ > +static int create_grouping(struct list_head *pmu_info_list, > + struct list_head *event_info_list, > + struct list_head *groupings __maybe_unused, > + const char *modifier __maybe_unused) > +{ > + int ret = 0; > + struct metricgroup__event_info *e; > + LIST_HEAD(groups); > + char *bit_buf = malloc(NR_COUNTERS); Similar to the above, may need to check the malloc return value. Thanks, Yang