Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp68757ybg; Sun, 31 May 2020 17:07:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcGTYaSn2mg6RHIbn26F7n0nIxIT55/tdeWMVVKPc4E/bz3gHsO7KHxqoQu7hSWGRTHyTp X-Received: by 2002:a50:e607:: with SMTP id y7mr19449839edm.71.1590970030650; Sun, 31 May 2020 17:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590970030; cv=none; d=google.com; s=arc-20160816; b=FQIPTfRMIQMfdY8eJWKYxBX3ExLOvntUCPK2DSlAAbWCkTkt8JR8GXEbx4nhJNKTfx 1+nit345kRLd75F6EdyxgZy6xxIdCbpOY1NvX4o6LGdIUYXvcrI6gz74tITkCGc44KYK nbPtpIs5LztC76epI9/UFOqWzBm2KsDnchwrP5ls1sf5lrJlWOkhQ2HAlE6NKR9lod+Q dzusJyiCGg9KOteLI1AMA4c3h/Pg0otRaNJnmQUJaEBP9xt/8aYavOYznSpnwDuRzeu3 FtjEyL7s/Ti57NbjgUOkB+KXDpYzkWiLP9+m3uqhouDttgU7jvWas4aocpMz5wIswbbt Sjwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Jjj6eWvS7e1mj+eJam5N+2rvoKgDVsk9FDt9PbhoqpY=; b=T6KBf91Pj2CNVFS4jBimrzZkaHoSjeyID03fohub6NvOVU46MhkooKNDHmlyD0itc1 YPPuadZVYE4FLHZ1x8JQ1eM2vBSDphOOti7XBVZgFpzqQFA0q83fGR5xwm2kQ69cLWlr NJLATvac1W/ele2iMCGIqSrPJRVNEzVip8ozzZ9EgH7g1yToNmdm7/9NosRx3AuJyyJ4 nEST4w38nJjHeB6xGwZIhvqpgcJxbWFK21ilzpCNFJyFdwmFPqljseloHoGLpmOR7wJD 3B1EJIBKNdwy0yXpI257f9fS+NxhSsCiPrh6iQft94Ygbd9u0DC36aZp7jTvgiRJn2El nHOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=aDA2GwNK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si2258418ejt.712.2020.05.31.17.06.47; Sun, 31 May 2020 17:07:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=aDA2GwNK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728409AbgFAAFA (ORCPT + 99 others); Sun, 31 May 2020 20:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbgFAAE7 (ORCPT ); Sun, 31 May 2020 20:04:59 -0400 Received: from mail-yb1-xb43.google.com (mail-yb1-xb43.google.com [IPv6:2607:f8b0:4864:20::b43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BDF6C061A0E for ; Sun, 31 May 2020 17:04:59 -0700 (PDT) Received: by mail-yb1-xb43.google.com with SMTP id p123so4319282yba.6 for ; Sun, 31 May 2020 17:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Jjj6eWvS7e1mj+eJam5N+2rvoKgDVsk9FDt9PbhoqpY=; b=aDA2GwNKefW0b0673a1OSraFtu3qnzx/a02mNNikuBNMHd0y4zKy9t3UjzcSOoDITy se32lqZ+qFW4raVgkryWrgaeMvhzByfDcURBVy53mNA+Fgtc2Gl++KQnrwEdUmehyFob 5dqWy1EXCHCyTAhoTNZPnTvYsO10fnDjTC7a1ZV+mxhWC7ShPZDY+VyoVRLHnemmP5sL D3D3KZu5vN74hSh8fRXIWo7/mz0OvzOj3vyOKF8QWoAKN1ap/1Kcscs0BSSp/Y+uP6at vueTCOwM2fY2TkZBcpG0FOsvUQzM/pQOYGplIBxCoMDPcTc7KliD7MGa3aCwDcDu9Nr0 7CWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Jjj6eWvS7e1mj+eJam5N+2rvoKgDVsk9FDt9PbhoqpY=; b=OdPxiUyFtx7noAexZ5krNshFxlrmIhRN2bOM6A0B1KW1wyvQFSmUPqWzj8qC/ibFvQ S1mwCeGOfMSrD8q99GUIP4h13VjfhL+G2g3jWZGyTVxUFGGgTtzdg8d4qXWrMHPNV7nt 2I/4Jhc5czcwWuLSExBBE+8/Bdu4AYRVKI3i0kwWFhmF3KO3BXxU4HsylXf2PkbUtCgu /QDxjqlaD4Ep6wVdl68sSM0fs1r0j2lO/h/6azMvNxR9GH5WuvZ19pXqrqY4Jl8AH4h2 zaiLPwRU9w4gNe2b+mP/hHNOXcNLDWz6hGC/qYQRMHiT7wKseagO/QQGqi1z98PPuRSN N0DA== X-Gm-Message-State: AOAM531UPErWsNdS1POYfKrcFnnwMKfsvmF5nLNIUBVDgRht7g9LuRXV DTSVjl6G7bX41QDJRcbc5+5pClAW01IW+sIuTHLkVy+O X-Received: by 2002:a25:c08b:: with SMTP id c133mr30227264ybf.286.1590969898250; Sun, 31 May 2020 17:04:58 -0700 (PDT) MIME-Version: 1.0 References: <20200531162206.911168-1-jolsa@kernel.org> In-Reply-To: <20200531162206.911168-1-jolsa@kernel.org> From: Ian Rogers Date: Sun, 31 May 2020 17:04:47 -0700 Message-ID: Subject: Re: [PATCH] perf stat: Ensure group is defined on top of the same cpu mask To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , Jin Yao , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Stephane Eranian , Andi Kleen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 31, 2020 at 9:22 AM Jiri Olsa wrote: > > Jin Yao reported the issue (and posted first versions of this change) > with groups being defined over events with different cpu mask. > > This causes assert aborts in get_group_fd, like: > > # perf stat -M "C2_Pkg_Residency" -a -- sleep 1 > perf: util/evsel.c:1464: get_group_fd: Assertion `!(fd == -1)' failed. > Aborted > > All the events in the group have to be defined over the same > cpus so the group_fd can be found for every leader/member pair. > > Adding check to ensure this condition is met and removing the > group (with warning) if we detect mixed cpus, like: > > $ sudo perf stat -e '{power/energy-cores/,cycles},{instructions,power/energy-cores/}' > WARNING: event cpu maps do not match, disabling group: > anon group { power/energy-cores/, cycles } > anon group { instructions, power/energy-cores/ } This is really cool! I wonder if there is a better wording for 'event cpu maps' ? It may be useful to list what the cpu maps are for the events as a diagnostic aid. Thanks, Ian > Fixes: 6a4bb04caacc8 ("perf tools: Enable grouping logic for parsed events") > Co-developed-by: Jin Yao > Signed-off-by: Jin Yao > Signed-off-by: Jiri Olsa > --- > tools/perf/builtin-stat.c | 51 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 51 insertions(+) > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index b2b79aa161dd..512a41363d07 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -190,6 +190,55 @@ static struct perf_stat_config stat_config = { > .big_num = true, > }; > > +static bool cpus_map_matched(struct evsel *a, struct evsel *b) > +{ > + if (!a->core.cpus && !b->core.cpus) > + return true; > + > + if (!a->core.cpus || !b->core.cpus) > + return false; > + > + if (a->core.cpus->nr != b->core.cpus->nr) > + return false; > + > + for (int i = 0; i < a->core.cpus->nr; i++) { > + if (a->core.cpus->map[i] != b->core.cpus->map[i]) > + return false; > + } > + > + return true; > +} > + > +static void evlist__check_cpu_maps(struct evlist *evlist) > +{ > + struct evsel *evsel, *pos, *leader; > + char buf[1024]; > + > + evlist__for_each_entry(evlist, evsel) { > + leader = evsel->leader; > + > + /* Check that leader matches cpus with each member. */ > + if (leader == evsel) > + continue; > + if (cpus_map_matched(leader, evsel)) > + continue; > + > + /* > + * If there's mismatch display dismantle the > + * group and warn user. > + */ > + WARN_ONCE(1, "WARNING: group events cpu maps do not match, disabling group:\n"); > + evsel__group_desc(leader, buf, sizeof(buf)); > + pr_warning(" %s\n", buf); > + > + for_each_group_evsel(pos, leader) { > + pos->leader = pos; > + pos->core.nr_members = 0; > + } > + evsel->leader->core.nr_members = 0; > + } > +} > + > static inline void diff_timespec(struct timespec *r, struct timespec *a, > struct timespec *b) > { > @@ -1962,6 +2011,8 @@ int cmd_stat(int argc, const char **argv) > } else if (argc && !strncmp(argv[0], "rep", 3)) > return __cmd_report(argc, argv); > > + evlist__check_cpu_maps(evsel_list); > + > interval = stat_config.interval; > timeout = stat_config.timeout; > > -- > 2.25.4 >