Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp13329459rwl; Wed, 4 Jan 2023 06:47:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXs2xL8VUNm2ZVVGXJO/0Zsd2cZspsXzSeYF0o0b0UFbQXu41fnk4KSSHEdRZQCDEMgmy9ZM X-Received: by 2002:a05:6a20:7d85:b0:a4:6eeb:91ae with SMTP id v5-20020a056a207d8500b000a46eeb91aemr73882121pzj.49.1672843652628; Wed, 04 Jan 2023 06:47:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672843652; cv=none; d=google.com; s=arc-20160816; b=KHhfSbld+a/ov5n+EoSkSTv/5AvchynQpZdySRbaEz5gi45hPkEkaGp7ifGgR9XZ7i TbS6uvUnXypQUI99n3j9f4+38m7zR/82zxM7lgLeFvfSN4yKdetiiLx3qAIyVFbWPwHv aWnL7LU0P9AAK7qPBO7OnpKyJHaEe78/1O7+/In0SPRNhIfkBjpFtOFw3YaTAg68hMIQ R890Ff2sW6XlC9l0GEeh+5YHo8bX1QLPMsTM6z1lWNK6Zl5alit1k3PYkNT7/I0ey7iU luYztkbPWma+2uPKg2m9Jz9dUNw3ZQrjLWZ7dcuo9ufDFD9eR/3PMqt/lJtqQyeFfmsl RtSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=zOaWkxWA0HTGLXowm4QdNHL+9BcgHLO1ofNUCedfN2o=; b=HggV88DAjLDaNnTjSKZ1r3fPZEMf2SpCg/mLkWrVFQOUJE32k7JG6fJsO+LbDqbMTP tO9Ff/cG5OuEhFJ7xSjg2IfNuK2JhEbazqCiE+OaSM6+urtZzANT6u0aorT6XrCtxDoy 9Sn/MeHXSf2yW35IySwFWvzCRALDLwlhXC3q5I4dWgFnRF4NwrR8LcDFnvHj6dJzOits CD7wsv/rZykjYbU4HS1PpmIS/UQCsQGp2xGlmZYZhYFi1NoCfYpX9vby/pfxZmpqazbh 7shK1VOj9wWHeua0smgdexfyszy7VUYO+QVKDjwIIVyoTTZJpdU8gx3qZs5zw7jO/ERd L9eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WTowqK06; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f4-20020a170902860400b00189b7f50e78si2905449plo.134.2023.01.04.06.47.24; Wed, 04 Jan 2023 06:47:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WTowqK06; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239462AbjADOV2 (ORCPT + 57 others); Wed, 4 Jan 2023 09:21:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239410AbjADOVY (ORCPT ); Wed, 4 Jan 2023 09:21:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51D9D38A; Wed, 4 Jan 2023 06:21:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E31EB6174E; Wed, 4 Jan 2023 14:21:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31743C433EF; Wed, 4 Jan 2023 14:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672842083; bh=VGhv39M7ZvdZ4R6rSSfVY15QnkI8S72J/pfHLmLDaGY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WTowqK06nFDvlyL3xR8NjzFU7r4BInoCdFJr5/oGad+uE4y+aMOvr7k8DSJs4GwGg LKD7X8+xR288oMO4I8vQ1QgTmmj/MfgdaTBzj5kfB3yd5fXnAc9Dz1BvlKOD3GlCUy gT66rmqcLpXsYRvyR/AHyqD01GHMOQlZ/fQXpkvvprpmshfPL0YLwucfH5El0dHdKz oXHG/+WTsHFGeUzbuQH+IWTUGLm3ECQG1PjMX/eTwD104cGdMc07vJiVHl2A3ZxJKK 4Gd06BWRfL2VWVDEEgjAQ7IFxYpuGqNpLPxz0lrZhBoRjWtnv8taKy8ksfCOHfinIF SUzyHpGyVkHOg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 964B240468; Wed, 4 Jan 2023 11:21:19 -0300 (-03) Date: Wed, 4 Jan 2023 11:21:19 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Jiri Olsa , Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , bpf@vger.kernel.org Subject: Re: [PATCH 4/4] perf stat: Do not use the same cgroup more than once Message-ID: References: <20230104064402.1551516-1-namhyung@kernel.org> <20230104064402.1551516-5-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230104064402.1551516-5-namhyung@kernel.org> X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Em Tue, Jan 03, 2023 at 10:44:02PM -0800, Namhyung Kim escreveu: > The --for-each-cgroup can have the same cgroup multiple times, but it makes > bpf counters confused (since they have the same cgroup id), and the last > cgroup events are counted only. Let's check the cgroup name before adding > a new entry. > > Before: > $ sudo ./perf stat -a --bpf-counters --for-each-cgroup /,/ sleep 1 > > Performance counter stats for 'system wide': > > msec cpu-clock / > context-switches / > cpu-migrations / > page-faults / > cycles / > instructions / > branches / > branch-misses / > 8,016.04 msec cpu-clock / # 7.998 CPUs utilized > 6,152 context-switches / # 767.461 /sec > 250 cpu-migrations / # 31.187 /sec > 442 page-faults / # 55.139 /sec > 613,111,487 cycles / # 0.076 GHz > 280,599,604 instructions / # 0.46 insn per cycle > 57,692,724 branches / # 7.197 M/sec > 3,385,168 branch-misses / # 5.87% of all branches > > 1.002220125 seconds time elapsed > > After: > $ sudo ./perf stat -a --bpf-counters --for-each-cgroup /,/ sleep 1 > > Performance counter stats for 'system wide': > > 8,013.38 msec cpu-clock / # 7.998 CPUs utilized > 6,859 context-switches / # 855.944 /sec > 334 cpu-migrations / # 41.680 /sec > 345 page-faults / # 43.053 /sec > 782,326,119 cycles / # 0.098 GHz > 471,645,724 instructions / # 0.60 insn per cycle > 94,963,430 branches / # 11.851 M/sec > 3,685,511 branch-misses / # 3.88% of all branches > > 1.001864539 seconds time elapsed > > Fixes: bb1c15b60b981 ("perf stat: Support regex pattern in --for-each-cgroup") > Signed-off-by: Namhyung Kim Tested and appied. - Arnaldo > --- > tools/perf/util/cgroup.c | 23 ++++++++++++++++++----- > 1 file changed, 18 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c > index e99b41f9be45..cd978c240e0d 100644 > --- a/tools/perf/util/cgroup.c > +++ b/tools/perf/util/cgroup.c > @@ -224,6 +224,19 @@ static int add_cgroup_name(const char *fpath, const struct stat *sb __maybe_unus > return 0; > } > > +static int check_and_add_cgroup_name(const char *fpath) > +{ > + struct cgroup_name *cn; > + > + list_for_each_entry(cn, &cgroup_list, list) { > + if (!strcmp(cn->name, fpath)) > + return 0; > + } > + > + /* pretend if it's added by ftw() */ > + return add_cgroup_name(fpath, NULL, FTW_D, NULL); > +} > + > static void release_cgroup_list(void) > { > struct cgroup_name *cn; > @@ -242,7 +255,7 @@ static int list_cgroups(const char *str) > struct cgroup_name *cn; > char *s; > > - /* use given name as is - for testing purpose */ > + /* use given name as is when no regex is given */ > for (;;) { > p = strchr(str, ','); > e = p ? p : eos; > @@ -253,13 +266,13 @@ static int list_cgroups(const char *str) > s = strndup(str, e - str); > if (!s) > return -1; > - /* pretend if it's added by ftw() */ > - ret = add_cgroup_name(s, NULL, FTW_D, NULL); > + > + ret = check_and_add_cgroup_name(s); > free(s); > - if (ret) > + if (ret < 0) > return -1; > } else { > - if (add_cgroup_name("", NULL, FTW_D, NULL) < 0) > + if (check_and_add_cgroup_name("/") < 0) > return -1; > } > > -- > 2.39.0.314.g84b9a713c41-goog -- - Arnaldo